Setting the timeout in my tests via the suggested API's just didn't work. Its far from ideal but I ended up modifying Test.js directly and hard coding in the timeout I wnated. I did notice when looking through the source that there was a comment on the timeout code saying something like // TODO timeouts not working correctly yet
Question
I am writing some functional tests with Intern and came across the following section of text...
"The test will also fail if the promise is not fulfilled within the timeout of the test (the default is 30 seconds; set this.timeout to change the value)."
at...
https://github.com/theintern/intern/wiki/Writing-Tests-with-Intern#asynchronous-testing
How do I set the promise timeout for functional tests? I have tried calling timeout() directly on the promise but it isn't a valid method.
I have already set the various WD timeout (page load timeout, implicit wait etc...) but I am having issues with promises timing out.
La solution
Autres conseils
It seems to be working okay on the latest version:
define([
'intern!object',
'intern/chai!assert',
'require',
'intern/dojo/node!leadfoot/helpers/pollUntil'
], function (registerSuite, assert, require, pollUntil) {
registerSuite(function(){
return {
name: 'index',
setup: function() {
},
'Test timeout': function () {
this.timeout = 90000;
return this.remote.sleep(45000);
}
}
});
});
You can also add defaultTimeout: 90000
to your configuration file (tests/intern.js
in the default tutorial codebase) to globally set the timeout. This works well for me.
A timeout for a test is either set by passing the timeout as the first argument to this.async
, or by setting this.timeout
(it is a property, not a method).
For anyone who found their way here while using InternJS 4 and utilizing async
/await
for functional testing: timeout
and executeAsync
just wouldn't work for me, but the pattern below did. Basically I just executed some logic and used the sleep
method at a longer interval than the setTimeout
. Keep in mind that the javascript
run inside of execute
is block scoped so you will want to cache anything you want to reference later on the window
object. Hopefully this saves someone else some time and frustration...
test(`timer test`, async ({remote}) => {
await remote.execute(`
// run setup logic, keep in mind this is scoped and if you want to reference anything it should be window scoped
window.val = "foo";
window.setTimeout(function(){
window.val = "bar";
}, 50);
return true;
`);
await remote.sleep(51); // remote will chill for 51 ms
let data = await remote.execute(`
// now you can call the reference and the timeout has run
return window.val;
`);
assert.strictEqual(
data,
'bar',
`remote.sleep(51) should wait until the setTimeout has run, converting window.val from "foo" to "bar"`
);
});