Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(www): add a --watch flag for local test debugging #1712

Merged
merged 4 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading