diff --git a/README.md b/README.md index b4b544bd5..c8782ac62 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,8 @@ Options: -a, --append Turns on append results to file mode rather than replace -j, --parallel Run tests in parallel -J, --autoParallel Run tests in parallel (automatically detect core count) + --withTags Only test modules from the lookup that contain a matching tag field + --excludeTags Specify which tags to skip from the lookup ``` When using a JSON config file, the properties need to be the same as the @@ -120,6 +122,7 @@ For syntax, see [lookup.json](./lib/lookup.json), the available attributes are: "sha": "" Test against a specific commit "envVar" Pass an environment variable before running "install": ["--param1", "--param2"] - Array of extra command line parameters passed to 'npm install' +"tag": ["tag1", "tag2"] Specify which tags the module comes under ``` If you want to pass options to npm, eg `--registry`, you can usually define an diff --git a/bin/citgm-all.js b/bin/citgm-all.js index 60d46135a..322732033 100755 --- a/bin/citgm-all.js +++ b/bin/citgm-all.js @@ -30,6 +30,14 @@ yargs = commonArgs(yargs) alias: 'J', type: 'boolean', description: 'Auto detect number of cores to use to run tests in parallel' + }) + .option('withTags', { + type: 'string', + description: 'define which tags from the lookup to run' + }) + .option('exludeTags', { + type: 'string', + description: 'define which tags from the lookup to skip' }); var app = yargs.argv; @@ -55,7 +63,9 @@ var options = { failFlaky: app.failFlaky, level: app.verbose, npmLevel: app.npmLoglevel, - timeoutLength: app.timeout + timeoutLength: app.timeout, + withTags: app.withTags, + excludeTags: app.excludeTags }; var lookup = getLookup(options); @@ -93,6 +103,17 @@ function runCitgm (mod, name, next) { return next(); } + if ((app.excludeTags && mod.tag && mod.tag.includes(app.excludeTags)) || + (app.withTags && mod.tag && !mod.tag.includes(app.withTags)) || + (app.withTags && !mod.tag)) { + log.info(name, 'no matching tag found'); + return next(); + } + + if (app.withTags && mod.tag && mod.tag.includes(app.withTags)) { + log.info(name, 'the following tag was matched: ' + app.withTags); + } + var start = new Date(); var runner = citgm.Tester(name, options); var bailed = false; diff --git a/lib/lookup.js b/lib/lookup.js index feade4f3c..3b286b81f 100644 --- a/lib/lookup.js +++ b/lib/lookup.js @@ -102,6 +102,9 @@ function resolve(context, next) { context.emit('data', 'info', context.module.name + ' lookup-script', rep.script); context.module.script = rep.script; } + if (rep.tag) { + context.module.tag = rep.tag; + } context.module.flaky = context.options.failFlaky ? false : isMatch(rep.flaky); } else { context.emit('data', 'info', 'lookup-notfound', detail.name); diff --git a/test/bin/test-citgm-all.js b/test/bin/test-citgm-all.js index b339d848a..aa1a588f9 100644 --- a/test/bin/test-citgm-all.js +++ b/test/bin/test-citgm-all.js @@ -94,6 +94,28 @@ test('citgm-all: flaky-fail ignoring flakyness', function (t) { }); }); +test('citgm-all: withTags', function (t) { + t.plan(1); + var proc = spawn(citgmAllPath, ['--withTags' , 'tag1', '-l', 'test/fixtures/custom-lookup-tag.json']); + proc.on('error', function(err) { + t.error(err); + }); + proc.on('close', function (code) { + t.equals(code, 0, 'citgm-all should only run omg-i-pass'); + }); +}); + +test('citgm-all: excludeTags', function (t) { + t.plan(1); + var proc = spawn(citgmAllPath, ['--excludeTags', 'tag2', '-l', 'test/fixtures/custom-lookup-tag.json']); + proc.on('error', function(err) { + t.error(err); + }); + proc.on('close', function (code) { + t.equals(code, 0, 'citgm-all should not run omg-i-fail'); + }); +}); + test('citgm-all: skip /w rootcheck /w tap to fs /w junit to fs /w append', function (t) { t.plan(1); var proc = spawn(citgmAllPath, ['-l', 'test/fixtures/custom-lookup-skip.json', '-s', '--tap', '/dev/null', '--junit', '/dev/null', '-a']); diff --git a/test/fixtures/custom-lookup-tag.json b/test/fixtures/custom-lookup-tag.json new file mode 100644 index 000000000..f6ed0a68e --- /dev/null +++ b/test/fixtures/custom-lookup-tag.json @@ -0,0 +1,13 @@ +{ + "omg-i-pass": { + "npm": true, + "tag": "tag1" + }, + "omg-i-fail": { + "npm": true, + "tag": "tag2" + }, + "omg-i-pass": { + "npm": true + } +}