Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop createStream for creating additional test runner loops #361

Merged
merged 1 commit into from
Jan 28, 2019
Merged

Stop createStream for creating additional test runner loops #361

merged 1 commit into from
Jan 28, 2019

Conversation

billti
Copy link
Contributor

@billti billti commented Apr 27, 2017

Without this change, every call to createStream starts an additional loop of test execution in the Results instance. Only the first stream creation should start test execution.

This was tricky to track down, but in my scenario it was causing the self.emit('done') in the loop to fire early (as the additional loop would find no tests waiting, while the prior loop was still executing the last test), which kills the stream (due to the output.queue(null) in the done handler), which meant the detection of unfinished tests on the process.on('exit'... handler couldn't write to the stream.

The below simple repro shows the problem. Without this change the console.log in the stream event handler will never fire. With this change, it does.

I couldn't figure out how to turn this into a test case, as it depends on the handling of the process exit event. (As noted below, even adding another handler for this doesn't work, as Tape stop the process from running additional handlers in its exit handler).

This was found working on improvements to the Tape test running in Visual Studio, which depends on an object stream to report results (microsoft/nodejstools#1524).

var tape = require('tape');

var harness = tape.getHarness();
var objStream = harness.createStream({objectMode: true});

objStream.on('data', function(evt){
    if (evt.type === "assert" && evt.name === "test exited without ending") {
        console.log("Successfully got the test failure events");
    }
});

tape('is ok', function(t){
    t.ok(true, 'value is true');
    t.end();
});

tape('no end', function(t){
    t.ok(true, 'another sucessful test!');
    // oops... didn't end.
});

process.on('exit', function(code){
    // Unfortunately can't check here, as this will never run.
    // The process.on('exit'...) handler in tape's createExitHarness method
    // calls process.exit(), which causes Node.js to exit immediately, and
    // not run further 'exit' event handlers (not sure if this is by design,
    // the Node.js docs don't mention this behavior).
});

Copy link
Collaborator

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - could you add a regression test that would have prevented this?

@billti
Copy link
Contributor Author

billti commented Jan 28, 2019

It took over a year and a half just to get a response. I don't even remember what this is now.

@billti billti closed this Jan 28, 2019
@ljharb
Copy link
Collaborator

ljharb commented Jan 28, 2019

Apologies that sometimes things slip through the cracks.

Your OP seems to have lots of context; it’d be a shame to lose this fix if there’s a way we can get a regression test out of it.

@billti
Copy link
Contributor Author

billti commented Jan 28, 2019

Looks like the linked #404 (mentioned above) fixes the same issue and has a test.

@ljharb
Copy link
Collaborator

ljharb commented Jan 28, 2019

Ah, thanks! I’ll try to incorporate these two together then.

@ljharb ljharb merged commit b494b18 into tape-testing:master Jan 28, 2019
ljharb added a commit that referenced this pull request Feb 9, 2019
[New] Implements TAP TODO directive (#254)
[New] add alias 'notDeepEquals' to 'notDeepEqual' function (#411)

[Fix] fix premature end of tests (and running sibling tests) when test includes subtests (#403, #222)
[Fix] only use one test runner for results, even if multiple streams are created (#404, #361, #105)
[Fix] windows: Show failure location even if driver letter is lowercase (#329)

[Docs] link to mixed tape (#445)
[Docs] Add electron-tap (#240)
[Docs] Add tape-promise into 'other' (#210)
[Docs] Mention [`flip-tape`](https://github.com/pguth/flip-tape/blob/master/README.md) in the section "other". (#359)
[Docs] Add an alternative ES6 tape runner (#328)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants