Commit 0c1673bd authored by Eduardo Sanz García's avatar Eduardo Sanz García Committed by Eduardo

Added option browser launching for the test command

The purpose of this PR is to be able to easily run karma tests in other
browsers without manually editing the karma configuration or making
local copies of the karma configuration.

Additions:

- `yarn test --no-browser` to avoid launching the default browser.
  It is up to the developer to run the tests in whatever browser she/he
  chooses by navigating to http://localhost:9876/.

- `yarn test --browser <browser>` run the tests in a different
  browser/s instead of the default browser. Chrome launcher comes by
  default with karma. Firefox, Safari and others can be installed
  independently.

Modifications:

- `yarn gulp test-watch` has been substituted by `yarn test --watch` for consistency.
parent f99c7121
......@@ -23,18 +23,18 @@ dev: node_modules/.uptodate
.PHONY: test
test: node_modules/.uptodate
ifdef FILTER
yarn test --grep $(FILTER)
ifdef ARGS
yarn test $(ARGS)
else
yarn test
endif
.PHONY: servetests
servetests: node_modules/.uptodate
ifdef FILTER
node_modules/.bin/gulp test-watch --grep $(FILTER)
ifdef ARGS
node_modules/.bin/gulp --watch $(ARGS)
else
node_modules/.bin/gulp test-watch
node_modules/.bin/gulp --watch
endif
.PHONY: lint
......
......@@ -34,17 +34,34 @@ const IMAGES_DIR = 'build/images';
function parseCommandLine() {
commander
.option(
'--grep [pattern]',
'Run only tests where filename matches a pattern'
'--grep <pattern>',
'Run only tests where filename matches a regex pattern'
)
.option('--watch', 'Continuously run tests (default: false)', false)
.option('--browser <browser>', 'Run tests in browser of choice.')
.option(
'--no-browser',
"Don't launch default browser. Instead, navigate to http://localhost:9876/ to run the tests."
)
.parse(process.argv);
return {
grep: commander.opts().grep,
const { grep, watch, browser } = commander.opts();
const karmaOptions = {
grep: grep,
singleRun: !watch,
};
// browser option can be either false | undefined | string
if (browser === false) {
karmaOptions.browsers = null;
} else if (browser) {
karmaOptions.browsers = [browser];
}
return karmaOptions;
}
const taskArgs = parseCommandLine();
const karmaOptions = parseCommandLine();
/** A list of all modules included in vendor bundles. */
const vendorModules = Object.keys(vendorBundles.bundles).reduce(function (
......@@ -361,13 +378,12 @@ gulp.task(
)
);
function runKarma({ singleRun }, done) {
function runKarma(done) {
const karma = require('karma');
new karma.Server(
{
configFile: path.resolve(__dirname, './src/karma.config.js'),
grep: taskArgs.grep,
singleRun,
...karmaOptions,
},
done
).start();
......@@ -377,9 +393,5 @@ function runKarma({ singleRun }, done) {
// Some (eg. a11y) tests rely on CSS bundles, so build these first.
gulp.task(
'test',
gulp.series('build-css', done => runKarma({ singleRun: true }, done))
);
gulp.task(
'test-watch',
gulp.series('build-css', done => runKarma({ singleRun: false }, done))
gulp.series('build-css', done => runKarma(done))
);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment