From f9b2f3e87d082d30ef3d04bbcc49edf840d4864e Mon Sep 17 00:00:00 2001 From: kumaran-14 Date: Sat, 11 Apr 2020 11:54:58 +0530 Subject: [PATCH 1/4] Add api-test script to log poll result on passing --debug flag --- bin/test.js | 10 +++++++++ bin/test_api.js | 49 +++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- test/api/TestUtils.ts | 5 +++++ 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 bin/test_api.js diff --git a/bin/test.js b/bin/test.js index 1380a5122..e19a2ad92 100644 --- a/bin/test.js +++ b/bin/test.js @@ -51,6 +51,16 @@ if (checkCoverage) { process.exit(run.status); } +const checkDebug = flagArgs.indexOf('--debug') >= 0; + +if (checkDebug) { + env.DEBUG = 'debug'; +} + +if (env.DEBUG) { + console.log('poll result', result); +} + const run = cp.spawnSync( npmBinScript('mocha'), [...testFiles, ...flagArgs], diff --git a/bin/test_api.js b/bin/test_api.js new file mode 100644 index 000000000..2eb3fc3e1 --- /dev/null +++ b/bin/test_api.js @@ -0,0 +1,49 @@ +/** + * 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('--')); + // 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 956cdbb11..192d8ca10 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "lint": "tslint 'src/**/*.ts' 'addons/*/src/**/*.ts'", "test": "npm run test-unit", "posttest": "npm run lint", - "test-api": "mocha \"**/*.api.js\"", + "test-api": "node ./bin/test_api.js", "test-unit": "node ./bin/test.js", "test-unit-coverage": "node ./bin/test.js --coverage", "build": "tsc -b ./tsconfig.all.json", diff --git a/test/api/TestUtils.ts b/test/api/TestUtils.ts index d36748122..ba2c43fd9 100644 --- a/test/api/TestUtils.ts +++ b/test/api/TestUtils.ts @@ -11,6 +11,11 @@ export async function pollFor(page: puppeteer.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); From ae72994cfb8ab915ae23df107ae7845c3b584798 Mon Sep 17 00:00:00 2001 From: kumaran-14 Date: Sat, 11 Apr 2020 12:02:27 +0530 Subject: [PATCH 2/4] Undo changes on ./bin/test.js --- bin/test.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/bin/test.js b/bin/test.js index e19a2ad92..1380a5122 100644 --- a/bin/test.js +++ b/bin/test.js @@ -51,16 +51,6 @@ if (checkCoverage) { process.exit(run.status); } -const checkDebug = flagArgs.indexOf('--debug') >= 0; - -if (checkDebug) { - env.DEBUG = 'debug'; -} - -if (env.DEBUG) { - console.log('poll result', result); -} - const run = cp.spawnSync( npmBinScript('mocha'), [...testFiles, ...flagArgs], From df7ba37d57a5a4a548a1fec627eb9f8147d77473 Mon Sep 17 00:00:00 2001 From: kumaran-14 Date: Sat, 11 Apr 2020 21:15:24 +0530 Subject: [PATCH 3/4] Update args parser to allow flag values --- bin/test_api.js | 5 ++++- package.json | 7 +++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bin/test_api.js b/bin/test_api.js index 2eb3fc3e1..38e9af3e8 100644 --- a/bin/test_api.js +++ b/bin/test_api.js @@ -21,7 +21,8 @@ let flagArgs = []; if (process.argv.length > 2) { const args = process.argv.slice(2); - flagArgs = args.filter(e => e.startsWith('--')); + flagArgs = args.filter(e => e.startsWith('--')).flatMap(arg => arg.split('=')); + console.info(flagArgs); // ability to inject particular test files via // yarn test [testFileA testFileB ...] files = args.filter(e => !e.startsWith('--')); @@ -30,6 +31,8 @@ if (process.argv.length > 2) { } } + + env.DEBUG = flagArgs.indexOf('--debug') >= 0 ? 'debug' : ''; const run = cp.spawnSync( diff --git a/package.json b/package.json index 535712dbf..31771a888 100644 --- a/package.json +++ b/package.json @@ -14,11 +14,10 @@ "lint": "eslint -c .eslintrc.json --ext .ts src/ addons/", "test": "npm run test-unit", "posttest": "npm run lint", - "api-test": "node ./bin/test_api.js", "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", From 1f4b2607cca815ffb72f3e6e37af06202c6facc2 Mon Sep 17 00:00:00 2001 From: kumaran-14 Date: Mon, 13 Apr 2020 22:36:33 +0530 Subject: [PATCH 4/4] Replace flatMap method with reduce and map --- bin/test_api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/test_api.js b/bin/test_api.js index 38e9af3e8..1f40363f7 100644 --- a/bin/test_api.js +++ b/bin/test_api.js @@ -21,7 +21,7 @@ let flagArgs = []; if (process.argv.length > 2) { const args = process.argv.slice(2); - flagArgs = args.filter(e => e.startsWith('--')).flatMap(arg => arg.split('=')); + 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 ...]