diff --git a/bin/test_api.js b/bin/test_api.js new file mode 100644 index 000000000..1f40363f7 --- /dev/null +++ b/bin/test_api.js @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2019 The xterm.js authors. All rights reserved. + * @license MIT + */ + +const cp = require('child_process'); +const path = require('path'); + + +// Add `out` to the NODE_PATH so absolute paths can be resolved. +const env = { ...process.env }; +env.NODE_PATH = path.resolve(__dirname, '../out'); + +let testFiles = [ + './addons/**/out/*api.js', + './out-test/**/*api.js', +]; + + +let flagArgs = []; + +if (process.argv.length > 2) { + const args = process.argv.slice(2); + flagArgs = args.filter(e => e.startsWith('--')).map(arg => arg.split('=')).reduce((arr, val) => arr.concat([...val], [])); + console.info(flagArgs); + // ability to inject particular test files via + // yarn test [testFileA testFileB ...] + files = args.filter(e => !e.startsWith('--')); + if (files.length) { + testFiles = files; + } +} + + + +env.DEBUG = flagArgs.indexOf('--debug') >= 0 ? 'debug' : ''; + +const run = cp.spawnSync( + npmBinScript('mocha'), + [...testFiles, ...flagArgs], + { + cwd: path.resolve(__dirname, '..'), + env, + stdio: 'inherit' + } +); + +function npmBinScript(script) { + return path.resolve(__dirname, `../node_modules/.bin/` + (process.platform === 'win32' ? `${script}.cmd` : script)); +} + +process.exit(run.status); diff --git a/package.json b/package.json index 8548e41f8..cfd83fc98 100644 --- a/package.json +++ b/package.json @@ -15,9 +15,9 @@ "test": "npm run test-unit", "posttest": "npm run lint", "test-api": "npm run test-api-chromium", - "test-api-chromium": "mocha \"**/*.api.js\" --browser chromium --timeout 20000", - "test-api-firefox": "mocha \"**/*.api.js\" --browser firefox --timeout 20000", - "test-api-webkit": "mocha \"**/*.api.js\" --browser webkit --timeout 20000", + "test-api-chromium": "node ./bin/test_api.js --browser=chromium --timeout=20000", + "test-api-firefox": "node ./bin/test_api.js --browser=firefox --timeout=20000", + "test-api-webkit": "node ./bin/test_api.js --browser=webkit --timeout=20000", "pretest-api-chromium": "node ./bin/download_browser.js --browser chromium", "pretest-api-firefox": "node ./bin/download_browser.js --browser firefox", "pretest-api-webkit": "node ./bin/download_browser.js --browser webkit", diff --git a/test/api/TestUtils.ts b/test/api/TestUtils.ts index 987940d03..9a3af1932 100644 --- a/test/api/TestUtils.ts +++ b/test/api/TestUtils.ts @@ -12,6 +12,11 @@ export async function pollFor(page: playwright.Page, evalOrFn: string | (() = await preFn(); } const result = typeof evalOrFn === 'string' ? await page.evaluate(evalOrFn) : await evalOrFn(); + + if (process.env.DEBUG) { + console.log('pollFor result: ', result); + } + if (!deepEqual(result, val)) { return new Promise(r => { setTimeout(() => r(pollFor(page, evalOrFn, val, preFn)), 1);