nathanboktae / mocha-casperjs

Write CasperJS tests using Mocha
MIT License
120 stars 29 forks source link

Tests timing out before they're completed? #32

Closed KingScooty closed 10 years ago

KingScooty commented 10 years ago

I'm running several tests across a few pages. I've got the casper steps setup properly to get mocha to wait until all the steps are completed, however i'm noticing a weird timeout issue where the test times out, but casper is still accessing the page, then a test further down the line casper catches up and runs previous steps in with future steps resulting in the next test failing.

I've got the timeout set to 10000ms, but it seems to only give the latter tests less than a few seconds before timing out, as if the timeout counter is starting when the tests start?

If i make the timeout really big with --casper-timeout=250000, the issue seems to go away.

nathanboktae commented 10 years ago

depends on how you wrote your tests. Are you doing casper.open multiple times? The raw timeout setting mainly only applies to open calls as waitFor* timeouts are determined by separate values.

As a general rule of thumb, you should create a step for each test so mocha-casperjs knows to make that test async and wait for casper to run them. Make sure that you also don't do any casper stuff outside of a test or hook too.

KingScooty commented 10 years ago

I'm doing a casper.start(url), then a bunch of describes and it's (all with casper.then steps inside), then a casper.thenOpen to test the next page.

nathanboktae commented 10 years ago

Looking into the casper source, it's one overall timeout:

    // timeout handling
    if (utils.isNumber(this.options.timeout) && this.options.timeout > 0) {
        this.log(f("Execution timeout set to %dms", this.options.timeout), "info");
        setTimeout(function _check(self) {
            self.emit('timeout');
            if (utils.isFunction(self.options.onTimeout)) {
                self.options.onTimeout.call(self, self.options.timeout);
            }
        }, this.options.timeout, this);
    }

It is one overall timeout. Considering it's only set if opted in to, mocha-casperjs. shouldn't provide a default come to think of it.

nathanboktae commented 10 years ago

Forgot to tag it but fixed by c5dd1e1