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

Emit event when all tests are done #175

Closed
tsironis opened this issue Aug 14, 2015 · 25 comments
Closed

Emit event when all tests are done #175

tsironis opened this issue Aug 14, 2015 · 25 comments

Comments

@tsironis
Copy link

I've been trying to run a mock API server that I wrote and use it with tape, but it seems that when the mock API server is running, tape cannot exit. Although I get the usual message,

1..39
# tests 39
# pass  39

# ok

the suite never really ends.

Is there a way to know when all tests are done? I've read the docs and couldn't find anything relevant.

@webthusiast
Copy link

I have the same problem. My use case: I have a web page which runs tape in the browser, and I have a phantomjs-script that loads that page. When the tests are done (and all results have been written), I want to exit the phantomjs process.

A workaround seems be:

var test = require('tape');

test('timing test', function (t) {
    ...
});

test.createStream().on('end', function () { ... });  # <---

But +1 for a more official API.

@Pajk
Copy link

Pajk commented Oct 31, 2015

👍

This is my quick&dirty solution as the one @webthusiast mentioned did not work for me.

https://github.com/Pajk/tape/commit/a4355d8466a0894855c470164f9f7c2e5d227af5

It's called only when all tests pass but that's enough for my case. I use it to disconnect node-postgres connection pool.

@rhys-vdw
Copy link

Also interested in this feature. I tried @webthusiast's method, but the 'end' event never fires.

@rhys-vdw
Copy link

Or perhaps my problem is different - there is no summary printed at the end of the tests... It looks like the tests are simply not ending.

@Raynos
Copy link
Collaborator

Raynos commented Nov 11, 2015

+1

I've decided this is now a useful feature >_>;

@rhys-vdw
Copy link

@Raynos How does tape know when to emit the end event if there are async tests? Do all calls to test need to occur synchronously?

@Raynos
Copy link
Collaborator

Raynos commented Nov 11, 2015

At some point the program exits and prints the number of oks. Thats a good place to hook into.

Have to read more code.

I think it's simply reference counting.

@rhys-vdw
Copy link

My asyc test just hangs indefinitely.

@akiva
Copy link

akiva commented Nov 12, 2015

I was initially encountering this issue only to discover the real culprit was my MySQL connection not closing (remained hanging) after the tests. I have yet to encounter this problem with only static or local files and processes. Figured that insight may or may not be of use to others.

@webthusiast
Copy link

I think different people might be looking at this issue from different angles. I think the OP describes a problem which could be investigated/solved if a new feature is added (@tsironis please correct me if I'm wrong). The name of the issue also suggests it's a feature request. I think related bugs might best be put in their own issues.

@Raynos: I'd like to start with writing a test, so it's probably a good start to agree on an interface. I'm thinking of making tape a promise, so that the following is possible:

test = require('tape');
test(...).then(onEnd);

Or:

test = require('tape');
Promise.all([
    test(...),
    test(...),
    ...
]).then(onEnd);

Maybe an additional event/callback-based implementation would be desired later, but I don't immediately see an obvious implementation for that. Agree? Or suggestions?

@Raynos
Copy link
Collaborator

Raynos commented Nov 12, 2015

@webthusiast no promises.

The cleanest thing to do is:

var test = require('tape');

test.on('end', onEnd);

@yoshuawuyts
Copy link

+1 on

test.on('end', onEnd)`

Having this hook available would probably be useful for cuke-tap, or any other module that wraps around tape.

@webthusiast
Copy link

The problem with that is that tape is a function. So it can't also inherit from EventEmitter. It could maybe use it as a mixin, but that seems a bit hacky. What about tape.tearDown(cb)?

@Raynos
Copy link
Collaborator

Raynos commented Nov 13, 2015

Tear down is reasonable.

@ghost
Copy link

ghost commented Nov 13, 2015

tearDown() sounds like a command that will tear apart the test, not registering a listener that fires when all the tests are finished

@Raynos
Copy link
Collaborator

Raynos commented Nov 13, 2015

Let's rename to

tape.onFinish(cb);

@ljharb
Copy link
Collaborator

ljharb commented Nov 13, 2015

no 🚲 🏠 here, onFinish SGTM

webthusiast pushed a commit to webthusiast/tape that referenced this issue Nov 13, 2015
@webthusiast
Copy link

I hope this workflow is workable: both b09c92e and b01c08b should be pulled.

@Raynos
Copy link
Collaborator

Raynos commented Nov 13, 2015

@webthusiast do you want to open a pull request ? :)

@webthusiast webthusiast mentioned this issue Nov 14, 2015
@sospedra
Copy link

+1

@webthusiast
Copy link

Hi @Raynos @substack, is this pull request still on your radar?

@rhys-vdw
Copy link

I was initially encountering this issue only to discover the real culprit was my MySQL connection not closing (remained hanging) after the tests.

This is ended up being my problem also, I think. I wrapped certain test files in a promise handler and cleaned up my DB connections in the finally handler.

@jbcpollak
Copy link

+1: I'm writing a custom test runner that seems to be working perfectly, except it exits before any tests are run because the tests are asynchronous. I'm writing the custom running so I can configure and maintain output formatter and output stream (and other resources) inside JS code.

@Raynos Raynos closed this as completed in b09c92e Dec 26, 2015
@blakeembrey
Copy link
Contributor

@Raynos I'm not sure this feature entirely works. Since globbing happens asynchronously, you can't guarantee the onFinish hook is correct (E.g. it'll call onFinish before any tests even run). I think switching to synchronous globs would correct this.

@frantz
Copy link

frantz commented Aug 2, 2016

I'm agree with @blakeembrey, I was trying to setup an onFinish hook in a preloaded module without any success because of asynchronous glob in tape cli.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests