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 Feb 8, 2017
1 parent 826cf80 commit b3ded44
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 1 deletion.
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
--withTags <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
```

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:
"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
17 changes: 16 additions & 1 deletion bin/citgm-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var reporter = require('../lib/reporter');
var getLookup = require('../lib/lookup').get;
var commonArgs = require('../lib/common-args');
var isMatch = require('../lib/match-conditions');
var checkTag = require('../lib/check-tag');

yargs = commonArgs(yargs)
.usage('citgm-all [options]')
Expand All @@ -30,6 +31,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('excludeTags', {
type: 'string',
description: 'define which tags from the lookup to skip'
});

var app = yargs.argv;
Expand All @@ -56,7 +65,9 @@ var options = {
level: app.verbose,
npmLevel: app.npmLoglevel,
timeoutLength: app.timeout,
tmpDir: app.tmpDir
tmpDir: app.tmpDir,
withTags: app.withTags,
excludeTags: app.excludeTags
};

var lookup = getLookup(options);
Expand Down Expand Up @@ -94,6 +105,10 @@ function runCitgm (mod, name, next) {
return next();
}

if (checkTag(app, mod, name)) {
return next();
}

var start = new Date();
var runner = citgm.Tester(name, options);
var bailed = false;
Expand Down
51 changes: 51 additions & 0 deletions lib/check-tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
var logger = require('./out');

var log = logger({
});

function checkTag(app, mod, name) {
if (mod.tag && mod.tag !== '' && typeof mod.tag === 'string') {
mod.tag = mod.tag.split(',');
}
if (app.withTags && typeof app.withTags === 'string') {
app.withTags = app.withTags.split(',');
}
if (app.excludeTags && typeof app.excludeTags === 'string') {
app.excludeTags = app.excludeTags.split(',');
}

function intersection (A, B) {
var m = A.reduce(function(m, v) {
m[v] = 1; return m;
}, {});
return B.filter(function(v) {
return m[v];
});
}

function checkMatch (A, B) {
var result = intersection(A, B);
if (result.length !== 0) {
return true;
} else {
return false;
}
}

if ((app.withTags && mod.tag && !checkMatch(mod.tag, app.withTags)) ||
(app.withTags && !mod.tag)) {
log.info(name, 'no matching tag found');
return true;
} else if (app.withTags && mod.tag && checkMatch(mod.tag, app.withTags)) {
log.info(name, 'the following tag was matched: ' + app.withTags);
return false;
} else if (app.excludeTags && mod.tag && checkMatch(mod.tag,
app.excludeTags)) {
log.info(name, 'skipped because of tag: ' + app.excludeTags);
return true;
} else {
return false;
}
}

module.exports = checkTag;
3 changes: 3 additions & 0 deletions lib/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ function resolve(context, next) {
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 ?
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 \-\-withTags " " \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

.SH SEE ALSO
citgm
Expand Down
24 changes: 24 additions & 0 deletions test/bin/test-citgm-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,30 @@ 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);
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-too": {
"npm": true
}
}
114 changes: 114 additions & 0 deletions test/test-check-tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
'use strict';

var test = require('tap').test;
var rewire = require('rewire');

var checkTag = rewire('../lib/check-tag');

test('test withTags and matching tag', function (t) {
var app = {
withTags: 'test'
};
var mod = {
tag: 'test'
};
t.plan(1);
var result = checkTag(app, mod, 'test');
t.false(result, 'should return false');
});

test('test several withTags and matching tag', function (t) {
var app = {
withTags: 'test,this,should,still,pass'
};
var mod = {
tag: 'test'
};
t.plan(1);
var result = checkTag(app, mod, 'test');
t.false(result, 'should return false');
});

test('test several withTags and multiple tags', function (t) {
var app = {
withTags: 'test,this,should,still,pass'
};
var mod = {
tag: ['test', 'this', 'is']
};
t.plan(1);
var result = checkTag(app, mod, 'test');
t.false(result, 'should return false');
});


test('test withTags and multiple tags', function (t) {
var app = {
withTags: 'test'
};
var mod = {
tag: ['test', 'noTest']
};
t.plan(1);
var result = checkTag(app, mod, 'test');
t.false(result, 'should return false');
});


test('test withTags and no matching tag', function (t) {
var app = {
withTags: 'test'
};
var mod = {
};
t.plan(1);
var result = checkTag(app, mod, 'test');
t.true(result, 'should return true');
});

test('test withTags and different tag', function (t) {
var app = {
withTags: 'test'
};
var mod = {
tag: 'noMatch'
};
t.plan(1);
var result = checkTag(app, mod, 'test');
t.true(result, 'should return true');
});

test('test excludeTags and matching tag', function (t) {
var app = {
excludeTags: 'test'
};
var mod = {
tag: 'test'
};
t.plan(1);
var result = checkTag(app, mod, 'test');
t.true(result, 'should return true');
});

test('test excludeTags and no matching tag', function (t) {
var app = {
excludeTags: 'test'
};
var mod = {
};
t.plan(1);
var result = checkTag(app, mod, 'test');
t.false(result, 'should return false');
});

test('test excludeTags and different tag', function (t) {
var app = {
excludeTags: 'test'
};
var mod = {
tag: 'noMatch'
};
t.plan(1);
var result = checkTag(app, mod, 'test');
t.false(result, 'should return false');
});

0 comments on commit b3ded44

Please sign in to comment.