From f87bb014327be7322d4c5efe5a22a2e5966b5bc3 Mon Sep 17 00:00:00 2001 From: George Adams Date: Mon, 9 Jan 2017 10:00:25 +0000 Subject: [PATCH] bin: allow testing subsystems this PR adds the functionality to run `citgm-all` on specific tags in the lookup by passing in the `withTags` or `excludeTags` option. fixes https://github.com/nodejs/citgm/issues/72 --- README.md | 3 +++ bin/citgm-all.js | 23 ++++++++++++++++++++++- lib/lookup.js | 3 +++ test/bin/test-citgm-all.js | 22 ++++++++++++++++++++++ test/fixtures/custom-lookup-tag.json | 13 +++++++++++++ 5 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/custom-lookup-tag.json diff --git a/README.md b/README.md index b9a2b5a5e..c67d46268 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 @@ -121,6 +123,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 9e2fed8f4..4e513c317 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); context.module.expectFail = context.options.expectFail ? false : isMatch(rep.expectFail); } else { diff --git a/test/bin/test-citgm-all.js b/test/bin/test-citgm-all.js index 9f7d4c700..92ef64740 100644 --- a/test/bin/test-citgm-all.js +++ b/test/bin/test-citgm-all.js @@ -116,6 +116,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..6634be5f2 --- /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-too": { + "npm": true + } +}