Skip to content

Commit

Permalink
chore(www): add a --watch flag for local test debugging (#1712)
Browse files Browse the repository at this point in the history
* Add a `--ci` flag to the test action for easier local testing.

* Remove Karma config log.

* Kill Karma web server on `SIGINT` so there's no straggler processes.

* Invert `--ci` to a `--watch` flag instead.
  • Loading branch information
sbruens authored Sep 20, 2023
1 parent a89eb6c commit 8307952
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/www/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
23 changes: 17 additions & 6 deletions src/www/test.action.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import minimist from 'minimist';
import url from 'url';
import karma from 'karma';
import puppeteer from 'puppeteer';
Expand All @@ -25,10 +26,17 @@ const KARMA_CONFIG_PATH = ['src', 'www', 'karma.conf.js'];
*
* @param {string[]} parameters
*/
export async function main() {
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 {watch = false} = minimist(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);
}
Expand All @@ -39,11 +47,14 @@ 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: !watch},
{
promiseConfig: true,
throwErrors: true,
}
);
await runKarma(config);
}

Expand Down

0 comments on commit 8307952

Please sign in to comment.