Skip to content

Commit

Permalink
bin: allow testing subsystems
Browse files Browse the repository at this point in the history
this PR adds the functionality to run `citgm-all` on specific tags in
the lookup by passing in the `includeTags` or `excludeTags` option.
fixes #72
  • Loading branch information
George Adams committed Feb 28, 2017
1 parent 1820757 commit 0865bea
Show file tree
Hide file tree
Showing 9 changed files with 441 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ Options:
-j, --parallel <number> Run tests in parallel
-J, --autoParallel Run tests in parallel (automatically detect core count)
--tmpDir <path> Directory to test modules in
--includeTags tag1 tag2 Only test modules from the lookup that contain a matching tag field
--excludeTags tag1 tag2 Specify which tags to skip from the lookup (takes priority over includeTags)
```

When using a JSON config file, the properties need to be the same as the
Expand All @@ -133,6 +135,7 @@ For syntax, see [lookup.json](./lib/lookup.json), the available attributes are:
"envVar" Pass an environment variable before running
"install": ["--param1", "--param2"] - Array of extra command line parameters passed to 'npm install'
"maintainers": ["user1", "user2"] - List of module maintainers to be contacted with issues
"tags": ["tag1", "tag2"] Specify which tags apply to the module
```

If you want to pass options to npm, eg `--registry`, you can usually define an
Expand Down
26 changes: 25 additions & 1 deletion bin/citgm-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const os = require('os');
const _ = require('lodash');
const async = require('async');

const checkTags = require('../lib/check-tags');
const citgm = require('../lib/citgm');
const commonArgs = require('../lib/common-args');
const getLookup = require('../lib/lookup').get;
Expand All @@ -29,6 +30,14 @@ const yargs = commonArgs(require('yargs'))
alias: 'J',
type: 'boolean',
description: 'Auto detect number of cores to use to run tests in parallel'
})
.option('includeTags', {
type: 'array',
description: 'Define which tags from the lookup to run'
})
.option('excludeTags', {
type: 'array',
description: 'Define which tags from the lookup to skip'
});

const app = yargs.argv;
Expand All @@ -47,6 +56,15 @@ if (!app.su) {
log.warn('root', 'Running as root! Use caution!');
}

if (app.includeTags){
log.info('includeTags', 'Only running tests matching these tags: '
+ app.includeTags);
}
if (app.excludeTags){
log.info('excludeTags', 'Not running tests matching these tags: '
+ app.excludeTags);
}

const options = {
lookup: app.lookup,
nodedir: app.nodedir,
Expand All @@ -55,7 +73,9 @@ const options = {
level: app.verbose,
npmLevel: app.npmLoglevel,
timeoutLength: app.timeout,
tmpDir: app.tmpDir
tmpDir: app.tmpDir,
includeTags: app.includeTags,
excludeTags: app.excludeTags
};

const lookup = getLookup(options);
Expand Down Expand Up @@ -97,6 +117,10 @@ function runCitgm (mod, name, next) {
const runner = citgm.Tester(name, options);
let bailed = false;

if (checkTags(app, mod, name, log)) {
return next(); // Skip this module
}

function cleanup() {
bailed = true;
runner.cleanup();
Expand Down
45 changes: 45 additions & 0 deletions lib/check-tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict';
const _ = require('lodash');

function checkTags(app, mod, name, log) {
// Returns true if the module should be skipped.

if ((app.excludeTags && !app.includeTags && !mod.tags) ||
(!app.includeTags && !app.excludeTags)) {
return false; // No checks to run.
} else if (app.includeTags && !app.excludeTags && !mod.tags) {
return true; // No tags for this module.
}

if (typeof mod.tags === 'string') {
mod.tags = [mod.tags]; // If mod.tags is a single string, convert to array.
}

let excludeTagMatches = _.intersection(app.excludeTags, mod.tags);

if (excludeTagMatches.length) {
log.info(name,
`skipped as these excludeTags matched: ${excludeTagMatches}`);
return true; // We matched an excludeTag.
}

let includeTagMatches = _.intersection(app.includeTags, mod.tags);

if (includeTagMatches.length) {
log.info(name,
`will run as these includeTags matched: ${includeTagMatches}`);
return false; // We matched an includeTag.
}

if (app.includeTags) {
log.info(`${name} skipped as no includeTags matched`);
return true; // We did not match an includeTag.
} else {
log.info(`${name} will run as no excludeTags matched`);
return false; // We did not match an excludeTag.
}


}

module.exports = checkTags;
3 changes: 3 additions & 0 deletions lib/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ function resolve(context, next) {
' lookup-install', rep.install);
context.module.install = rep.install;
}
if (rep.tags) {
context.module.tags = rep.tags;
}
context.module.flaky = context.options.failFlaky ?
false : isMatch(rep.flaky);
context.module.expectFail = context.options.expectFail ?
Expand Down
2 changes: 1 addition & 1 deletion lib/lookup.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"lodash": {
"expectFail": "fips",
"maintainers": "jdalton"
"maintainers": "jdalton",
},
"underscore": {
"flaky": ["aix", "s390"],
Expand Down
6 changes: 6 additions & 0 deletions man/citgm-all.1
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ Run tests in parallel (automatically detect core count)
.TP
.BR \-\-tmpDir " " \fI<path>\fR
Directory to test modules in
.TP
.BR \-\-includeTags " " \fI<tag1 tag2>\fR
Only test modules from the lookup that contain a matching tag field
.TP
.BR \-\-excludeTags " " \fI<tag1 tag2>\fR
Specify which tags to skip from the lookup (takes priority over includeTags)

.SH SEE ALSO
citgm
Expand Down
48 changes: 48 additions & 0 deletions test/bin/test-citgm-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,54 @@ test('citgm-all: flaky-fail ignoring flakyness', function (t) {
});
});

test('citgm-all: includeTags', function (t) {
t.plan(1);
const proc = spawn(citgmAllPath, ['--includeTags', 'tag1', '-l',
'test/fixtures/custom-lookup-tags.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);
const proc = spawn(citgmAllPath, ['--excludeTags', 'tag2', '-l',
'test/fixtures/custom-lookup-tags.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: includeTags multiple', function (t) {
t.plan(1);
const proc = spawn(citgmAllPath, ['--includeTags', 'tag1 noTag1 NoTag2', '-l',
'test/fixtures/custom-lookup-tags.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: includeTags and excludeTags', function (t) {
t.plan(1);
const proc = spawn(citgmAllPath, ['--includeTags', 'tag1', '--excludeTags',
'tag4', '-l', 'test/fixtures/custom-lookup-tags.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: skip /w rootcheck /w tap to fs /w junit to fs /w append',
function (t) {
t.plan(1);
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/custom-lookup-tags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"omg-i-pass": {
"npm": true,
"tags": "tag1"
},
"omg-i-fail": {
"npm": true,
"tags": ["tag2", "tagNotUsed"]
},
"omg-i-pass-too": {
"npm": true
}
}
Loading

0 comments on commit 0865bea

Please sign in to comment.