test(devtools): Fix intermittent DevTools API test timeout (#177)

This commit is contained in:
ExE Boss 2019-03-20 12:27:09 +01:00 committed by Rob Wu
parent 949f08cc7d
commit 3aad2418d8
3 changed files with 33 additions and 7 deletions

View File

@ -1,4 +1,6 @@
test("devtools.inspectedWindow.eval resolved with an error result", async (t) => { test("devtools.inspectedWindow.eval resolved with an error result", {
timeout: 5000,
}, async (t) => {
const {evalResult} = await browser.runtime.sendMessage({ const {evalResult} = await browser.runtime.sendMessage({
apiMethod: "devtools.inspectedWindow.eval", apiMethod: "devtools.inspectedWindow.eval",
params: ["throw new Error('fake error');"], params: ["throw new Error('fake error');"],
@ -14,7 +16,9 @@ test("devtools.inspectedWindow.eval resolved with an error result", async (t) =>
"the second element value property should include the expected error message"); "the second element value property should include the expected error message");
}); });
test("devtools.inspectedWindow.eval resolved without an error result", async (t) => { test("devtools.inspectedWindow.eval resolved without an error result", {
timeout: 5000,
}, async (t) => {
const {evalResult} = await browser.runtime.sendMessage({ const {evalResult} = await browser.runtime.sendMessage({
apiMethod: "devtools.inspectedWindow.eval", apiMethod: "devtools.inspectedWindow.eval",
params: ["[document.documentElement.localName]"], params: ["[document.documentElement.localName]"],

View File

@ -10,9 +10,30 @@ if (navigator.userAgent.includes("Chrome/")) {
} }
// Export as a global a wrapped test function which enforces a timeout by default. // Export as a global a wrapped test function which enforces a timeout by default.
window.test = (desc, fn) => { /**
tape(`${desc} (${browser})`, async (t) => { * @param {string} desc
t.timeoutAfter(DEFAULT_TIMEOUT); * The test description
* @param {object} [options]
* The test options, can be omitted.
* @param {number} [options.timeout=DEFAULT_TIMEOUT]
* The time after which the test fails automatically, unless it has already passed.
* @param {boolean} [options.skip]
* Whether the test case should be skipped.
* @param {function(tape.Test):(void|Promise<void>)} fn
* The test case function, takes the test object as a callback.
*/
window.test = (desc, options, fn) => {
if (typeof options === "function") {
// Allow swapping options with fn
[fn, options] = [options, fn];
}
options = {
timeout: DEFAULT_TIMEOUT,
...options,
};
tape(`${desc} (${browser})`, options, async (t) => {
await fn(t); await fn(t);
}); });
}; };

View File

@ -165,6 +165,7 @@ test.onFailure(() => {
* @param {string} parameters.description * @param {string} parameters.description
* @param {string[]} parameters.extensions * @param {string[]} parameters.extensions
* @param {boolean|string|string[]} [parameters.skip] * @param {boolean|string|string[]} [parameters.skip]
* @param {boolean} [parameters.openDevTools]
*/ */
const defineExtensionTests = ({description, extensions, skip, openDevTools}) => { const defineExtensionTests = ({description, extensions, skip, openDevTools}) => {
for (const extensionDirName of extensions) { for (const extensionDirName of extensions) {
@ -192,8 +193,8 @@ const defineExtensionTests = ({description, extensions, skip, openDevTools}) =>
path.join(__dirname, "..", "fixtures", extensionDirName)); path.join(__dirname, "..", "fixtures", extensionDirName));
const srcPolyfill = path.join(__dirname, "..", "..", "dist", "browser-polyfill.js"); const srcPolyfill = path.join(__dirname, "..", "..", "dist", "browser-polyfill.js");
const tmpDir = tmp.dirSync({unsafeCleanup: true}); tempDir = tmp.dirSync({unsafeCleanup: true});
const extensionPath = path.join(tmpDir.name, extensionDirName); const extensionPath = path.join(tempDir.name, extensionDirName);
cp("-rf", srcExtensionPath, extensionPath); cp("-rf", srcExtensionPath, extensionPath);
cp("-f", srcPolyfill, extensionPath); cp("-f", srcPolyfill, extensionPath);