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 `withTags` or `excludeTags` option.
fixes #72
  • Loading branch information
George Adams committed Jan 10, 2017
1 parent 7299c33 commit d25595d
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ Options:
-a, --append Turns on append results to file mode rather than replace
-j, --parallel <number> Run tests in parallel
-J, --autoParallel Run tests in parallel (automatically detect core count)
--withTags <tag> Only test modules from the lookup that contain a matching tag field
--excludeTags <tag> Specify which tags to skip from the lookup
```

When using a JSON config file, the properties need to be the same as the
Expand All @@ -120,6 +122,7 @@ For syntax, see [lookup.json](./lib/lookup.json), the available attributes are:
"sha": "<git-commit-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
Expand Down
23 changes: 22 additions & 1 deletion bin/citgm-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions lib/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 22 additions & 0 deletions test/bin/test-citgm-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/custom-lookup-tag.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"omg-i-pass": {
"npm": true,
"tag": "tag1"
},
"omg-i-fail": {
"npm": true,
"tag": "tag2"
},
"omg-i-pass": {
"npm": true
}
}

0 comments on commit d25595d

Please sign in to comment.