From de254acac0fd184fbfdbdab0d3c93c393a67d33e Mon Sep 17 00:00:00 2001 From: Sander Bruens Date: Fri, 15 Sep 2023 14:21:43 -0400 Subject: [PATCH 1/4] Add a `--ci` flag to the test action for easier local testing. --- .github/workflows/build_and_test_debug.yml | 2 +- src/www/karma.conf.js | 2 +- src/www/test.action.mjs | 30 +++++++++++++++++----- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build_and_test_debug.yml b/.github/workflows/build_and_test_debug.yml index e028a99bd4..11656fd4c8 100644 --- a/.github/workflows/build_and_test_debug.yml +++ b/.github/workflows/build_and_test_debug.yml @@ -38,7 +38,7 @@ jobs: run: npm run action www/build - name: Test Web App - run: npm run action www/test + run: npm run action www/test -- --ci - uses: codecov/codecov-action@v3 with: diff --git a/src/www/karma.conf.js b/src/www/karma.conf.js index ecbcea7bbc..5e17bc1bf8 100644 --- a/src/www/karma.conf.js +++ b/src/www/karma.conf.js @@ -26,7 +26,7 @@ module.exports = async function(config) { '**/*.spec.ts': ['webpack'], }, reporters: ['progress', 'coverage-istanbul'], - singleRun: true, + restartOnFileChange: true, webpack: testConfig.default, coverageIstanbulReporter: { reports: ['html', 'json', 'text-summary'], diff --git a/src/www/test.action.mjs b/src/www/test.action.mjs index 4761af6b6c..4f0a877ff6 100644 --- a/src/www/test.action.mjs +++ b/src/www/test.action.mjs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +import chalk from 'chalk'; +import minimist from 'minimist'; import url from 'url'; import karma from 'karma'; import puppeteer from 'puppeteer'; @@ -20,12 +22,24 @@ import {getRootDir} from '../build/get_root_dir.mjs'; const KARMA_CONFIG_PATH = ['src', 'www', 'karma.conf.js']; +/** + * Parses the action parameters and returns whether to run as part of CI. + * @param {string[]} parameters The list of action arguments passed in. + * @returns {Object} Object containing whether to run as part of CI. + */ +function getActionParameters(cliArguments) { + const {ci = false} = minimist(cliArguments); + return {ci}; +} + /** * @description Runs the Karma tests against the web UI. * * @param {string[]} parameters */ -export async function main() { +export async function main(...parameters) { + const {ci} = getActionParameters(parameters); + const runKarma = config => new Promise((resolve, reject) => { new karma.Server(config, exitCode => { @@ -39,11 +53,15 @@ export async function main() { process.env.CHROMIUM_BIN = puppeteer.executablePath(); - const config = await karma.config.parseConfig(path.resolve(getRootDir(), ...KARMA_CONFIG_PATH), null, { - promiseConfig: true, - throwErrors: true, - }); - + const config = await karma.config.parseConfig( + path.resolve(getRootDir(), ...KARMA_CONFIG_PATH), + {singleRun: ci}, + { + promiseConfig: true, + throwErrors: true, + } + ); + console.log(chalk.gray('▶ running karma with config:\n'), config); await runKarma(config); } From 56308babe15046828f396605111012d0f02728f2 Mon Sep 17 00:00:00 2001 From: Sander Bruens Date: Fri, 15 Sep 2023 18:33:52 -0400 Subject: [PATCH 2/4] Remove Karma config log. --- src/www/test.action.mjs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/www/test.action.mjs b/src/www/test.action.mjs index 4f0a877ff6..8a82bf8bb4 100644 --- a/src/www/test.action.mjs +++ b/src/www/test.action.mjs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -import chalk from 'chalk'; import minimist from 'minimist'; import url from 'url'; import karma from 'karma'; @@ -61,7 +60,6 @@ export async function main(...parameters) { throwErrors: true, } ); - console.log(chalk.gray('▶ running karma with config:\n'), config); await runKarma(config); } From 352f49eb4ab19eaf0b4518dc20bbde1ede17e4b9 Mon Sep 17 00:00:00 2001 From: Sander Bruens Date: Mon, 18 Sep 2023 12:24:33 -0400 Subject: [PATCH 3/4] Kill Karma web server on `SIGINT` so there's no straggler processes. --- src/www/test.action.mjs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/www/test.action.mjs b/src/www/test.action.mjs index 8a82bf8bb4..ccd549a1c7 100644 --- a/src/www/test.action.mjs +++ b/src/www/test.action.mjs @@ -37,11 +37,16 @@ function getActionParameters(cliArguments) { * @param {string[]} parameters */ export async function main(...parameters) { + // We need to manually kill the process on SIGINT, otherwise the web server + // stays alive in the background. + process.on('SIGINT', process.exit); + const {ci} = getActionParameters(parameters); const runKarma = config => new Promise((resolve, reject) => { new karma.Server(config, exitCode => { + console.log('Karma exited with code:', exitCode); if (exitCode !== 0) { reject(exitCode); } From d6dd6a44c16eec017db1d7f9d07c03e756e2c4d5 Mon Sep 17 00:00:00 2001 From: Sander Bruens Date: Wed, 20 Sep 2023 16:11:37 -0400 Subject: [PATCH 4/4] Invert `--ci` to a `--watch` flag instead. --- .github/workflows/build_and_test_debug.yml | 2 +- src/www/test.action.mjs | 14 ++------------ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build_and_test_debug.yml b/.github/workflows/build_and_test_debug.yml index 11656fd4c8..e028a99bd4 100644 --- a/.github/workflows/build_and_test_debug.yml +++ b/.github/workflows/build_and_test_debug.yml @@ -38,7 +38,7 @@ jobs: run: npm run action www/build - name: Test Web App - run: npm run action www/test -- --ci + run: npm run action www/test - uses: codecov/codecov-action@v3 with: diff --git a/src/www/test.action.mjs b/src/www/test.action.mjs index ccd549a1c7..2d68cd48e9 100644 --- a/src/www/test.action.mjs +++ b/src/www/test.action.mjs @@ -21,16 +21,6 @@ import {getRootDir} from '../build/get_root_dir.mjs'; const KARMA_CONFIG_PATH = ['src', 'www', 'karma.conf.js']; -/** - * Parses the action parameters and returns whether to run as part of CI. - * @param {string[]} parameters The list of action arguments passed in. - * @returns {Object} Object containing whether to run as part of CI. - */ -function getActionParameters(cliArguments) { - const {ci = false} = minimist(cliArguments); - return {ci}; -} - /** * @description Runs the Karma tests against the web UI. * @@ -41,7 +31,7 @@ export async function main(...parameters) { // stays alive in the background. process.on('SIGINT', process.exit); - const {ci} = getActionParameters(parameters); + const {watch = false} = minimist(parameters); const runKarma = config => new Promise((resolve, reject) => { @@ -59,7 +49,7 @@ export async function main(...parameters) { const config = await karma.config.parseConfig( path.resolve(getRootDir(), ...KARMA_CONFIG_PATH), - {singleRun: ci}, + {singleRun: !watch}, { promiseConfig: true, throwErrors: true,