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

Added and unified options for the gulp test command #2989

Merged
merged 1 commit into from
Mar 1, 2021
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
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 25 additions & 13 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -352,13 +369,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();
Expand All @@ -368,9 +384,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))
);