Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

Should tearDown be queued on process.nextTick?

Aberta
#188 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
25/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Estagnada
Stack de tecnologia
javascript
Domínio
testing

Direção de pesquisa

Reproduza o problema com os fixtures de async.auto e async.parallel mostrados no relatório e, em seguida, inspecione nodeunit/lib/core.js em torno de wrapTest e do tratamento de teardown. Verifique a ordem de tearDown em relação aos callbacks assíncronos e confirme que os testes concluídos não acessam mais o estado limpo antes que tearDown termine.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

I've encountered an issue that's reproducible with async.parallel/auto and nodeunit.

var async = require('async');
var str;

exports.setUp = function(cb){
    console.log('setup');
    str = "This is a test";
    cb();
}

exports.tearDown = function(cb){
    //process.nextTick(function(){
        console.log('teardown');
        str = undefined;
        cb();
    //});
}

exports["testA"] = function(test){
    async.auto({
        test1:function(cb, results){
            console.log('test1');
            cb(new Error("test"));
        },
        test2:function(cb, results){
            console.log('test2');
            console.log(str, str.length);
            cb();
        }
    }, function(err, results){
        if(err) console.error(err);
        test.done();
    });
}

exports["testB"] = function(test){
    async.parallel({
        test1:function(cb, results){
            console.log('test1');
            cb(new Error("test"));
        },
        test2:function(cb, results){
            console.log('test2');
            console.log(str, str.length);
            cb();
        }
    }, function(err, results){
        if(err) console.error(err);
        test.done();
    });
}

This produces the output:

setup
test1
[Error: test]
teardown
test2
teardown
✖ testA

TypeError: Cannot read property 'length' of undefined
at Array.exports.testA.async.auto.test2 as 0
at async.auto (/Users/davefenster/node_modules/async/lib/async.js:406:38)
at Array.forEach (native)
at _forEach (/Users/davefenster/node_modules/async/lib/async.js:26:24)
at Object.async.auto (/Users/davefenster/node_modules/async/lib/async.js:382:9)
at Object.exports.testA (/Users/davefenster/temp/testnodeunitbug/test.js:19:8)
at wrapTest (/Users/davefenster/node_modules/nodeunit/lib/core.js:231:20)
at _asyncMap (/Users/davefenster/node_modules/nodeunit/deps/async.js:163:13)
at async.forEachSeries.iterate (/Users/davefenster/node_modules/nodeunit/deps/async.js:126:25)
at _asyncMap (/Users/davefenster/node_modules/nodeunit/deps/async.js:160:17)

setup
test1
[Error: test]
teardown
test2
teardown
✖ testA

TypeError: Cannot read property 'length' of undefined
at Array.exports.testA.async.auto.test2 as 0
at async.auto (/Users/davefenster/node_modules/async/lib/async.js:406:38)
at Array.forEach (native)
at _forEach (/Users/davefenster/node_modules/async/lib/async.js:26:24)
at Object.async.auto (/Users/davefenster/node_modules/async/lib/async.js:382:9)
at Object.exports.testA (/Users/davefenster/temp/testnodeunitbug/test.js:19:8)
at wrapTest (/Users/davefenster/node_modules/nodeunit/lib/core.js:231:20)
at _asyncMap (/Users/davefenster/node_modules/nodeunit/deps/async.js:163:13)
at async.forEachSeries.iterate (/Users/davefenster/node_modules/nodeunit/deps/async.js:126:25)
at _asyncMap (/Users/davefenster/node_modules/nodeunit/deps/async.js:160:17)

FAILURES: 2/2 assertions failed (12ms)

FAILURES: Undone tests (or their setups/teardowns):

  • testB

To fix this, make sure all tests call test.done()

The error manifests itself because tearDown runs before all the async.auto and async.parallel functions have executed. Ideally, what I'd want is the tearDown to run only after async.auto/parallel are complete.
To make the tests pass, uncomment the process.nextTick line in the tearDown function.

Should nodeunit be putting tearDown on the nextTick queue all the time?

Linguagem predominante
JavaScript
Estrelas
1.9k
Forks
359
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

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de caolan/nodeunit

Todas as issues de caolan/nodeunit

Issues semelhantes

Mais issues de JavaScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.