Isolated DB throws this error `TypeError: The "eventTargets" argument must be an instance of EventEmitter or EventTarget. Received an instance of AbortSignal` with `npx vitest`
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 35/100
- Tipo de issue
- Bug
- Clareza
- Razoavelmente clara
- Status de atividade
- Estagnada
- Stack de tecnologia
- node.js, typescript
- Domínio
- databases, testing-qa
Direção de pesquisa
Comece executando npx vitest e lendo db-setup.ts para reproduzir a falha isolada do DB. Revise a issue vinculada do execa para entender o contexto de AbortSignal e setMaxListeners e, em seguida, verifique se a correção escolhida permite executar a suíte de testes sem este TypeError no ambiente jsdom.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
npx vitest throws the following error "TypeError: The "eventTargets" argument must be an instance of EventEmitter or EventTarget. Received an instance of AbortSignal" with Isolated DB for testing.
A little bit of google searching landed me here, which is the root cause of the problem. You can check out the link for more context. Apparently, execa version 9 which is the current version of the package in the project relies on setMaxListeners export from node:events which throws error in jsdom environment because the AbortSignal from jsdom's AbortController is not node.js EventTarget.
I'm not exactly sure the best way to fix this problem. Of course, one option would be to downgrade execa to version 8 but not sure if that's a good idea based on this comment. However, I added this hack in the db-setup.ts file and it does work for me:
const kEventTarget = Symbol.for('nodejs.event_target') // https://github.com/nodejs/node/blob/68c9f554ffa2fab1ef3b6466c51491371f0dd158/lib/internal/event_target.js#L50
if (globalThis.window !== undefined) {
const JSDOMAbortController = window.AbortController
window.AbortController = class extends JSDOMAbortController {
get signal() {
const signal = super.signal
if ('constructor' in signal) {
// @ts-expect-error
signal.constructor[kEventTarget] = true //
} else {
// @ts-expect-error
signal.constructor = { [kEventTarget]: true } //https://github.com/nodejs/node/blob/68c9f554ffa2fab1ef3b6466c51491371f0dd158/lib/internal/event_target.js#L1070
}
return signal
}
}
}
- Linguagem predominante
- TypeScript
- Estrelas
- 221
- Forks
- 61
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Preparar o ambiente
Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
microsoft/playwright#43327 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
microsoft/TypeScript#64758 ·
Mantenedores costumam responder em até 1 dia
-
enhancement
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
opensearch-project/OpenSearch-Dashboards#12937 ·
Mantenedores costumam responder em até 2 dias
-
Liveness marks block-included attesters live in the block's epoch instead of the attestation's epochAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
Mantenedores costumam responder em até 1 dia
-
status: needs-triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 83/100
a2ui-project/a2ui#3158 ·
Mantenedores costumam responder em até 2 dias