Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

Commit

Permalink
only try to run tests for configuration groups with tests specified
Browse files Browse the repository at this point in the history
  • Loading branch information
dkl-ppi committed Dec 10, 2014
1 parent f2b264d commit a1b74d0
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 33 deletions.
21 changes: 13 additions & 8 deletions lib/run-analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,19 @@ exports.create = function (logger, options) {
analyzer.run = function (runner, config, cb) {
var callback = once(cb);
config.runExtensionHook("analyze", analyzer);
var run = runner.run(config, options, callback);
run.cacheable = options.cacheResources;

analyzer.on("fail", function (stats) {
var err = analyzerError(stats);
run.abort(err);
callback(err);
});

if (config.tests && config.tests.length > 0) {
var run = runner.run(config, options, callback);
run.cacheable = options.cacheResources;

analyzer.on("fail", function (stats) {
var err = analyzerError(stats);
run.abort(err);
callback(err);
});
} else {
callback();
}
};

return analyzer;
Expand Down
5 changes: 1 addition & 4 deletions lib/runners/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,7 @@ var testRun = {
startSession: function (client, callback) {
return function (resourceSet) {
if (this.aborted) { return callback(); }
// less than 3 files means, no test files were found
if (resourceSet.loadPath.paths().length === 3) {
return this.done();
}

this.logger.info("Creating browser session");

resourceSet.addResource({
Expand Down
17 changes: 16 additions & 1 deletion test/run-analyzer-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var buster = require("buster-node");
var assert = buster.assert;
var refute = buster.refute;
var runAnalyzer = require("../lib/run-analyzer");
var cliHelper = require("buster-cli/test/test-helper");
var streamLogger = require("stream-logger");
Expand Down Expand Up @@ -31,7 +32,7 @@ buster.testCase("Analyzer helper", {
this.analyzer = runAnalyzer.create(this.logger, {});
this.run = { abort: this.spy() };
this.runner = { run: this.stub().returns(this.run) };
this.config = { runExtensionHook: this.spy() };
this.config = { runExtensionHook: this.spy(), tests: ["test.js"] };
},

"triggers analyze extension hook": function () {
Expand All @@ -49,6 +50,20 @@ buster.testCase("Analyzer helper", {
assert.calledWith(this.runner.run, this.config, {});
},

"not starts run if config.tests isn't defined": function () {
this.config.tests = undefined;
this.analyzer.run(this.runner, this.config);

refute.called(this.runner.run);
},

"not starts run if config.tests is empty array": function () {
this.config.tests = [];
this.analyzer.run(this.runner, this.config);

refute.called(this.runner.run);
},

"aborts run if analyzer fails": function () {
this.analyzer.run(this.runner, this.config);
this.analyzer.emit("fail", { errors: 42 });
Expand Down
57 changes: 37 additions & 20 deletions test/test-cli-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ buster.testCase("Test CLI", {
"node runs": {
setUp: function () {
cliHelper.writeFile("buster.js", "var config = module.exports;" +
"config.server = { environment: 'node' }");
"config.server = { environment: 'node', " +
"tests: ['test.js'] }");
},

"loads node runner": function (done) {
Expand Down Expand Up @@ -165,7 +166,8 @@ buster.testCase("Test CLI", {
this.config = cliHelper.writeFile(
"buster2.js",
"var config = module.exports;" +
"config.server = { environment: 'browser' }"
"config.server = { environment: 'browser', " +
"tests: ['test.js'] }"
);
this.cli = testCli.create(this.stdout, this.stderr, {
runners: this.runners,
Expand Down Expand Up @@ -259,7 +261,8 @@ buster.testCase("Test CLI", {
this.config = cliHelper.writeFile(
"buster2.js",
"var config = module.exports;" +
"config.server = { environment: 'browser' }"
"config.server = { environment: 'browser', " +
"tests: ['test.js'] }"
);
},

Expand Down Expand Up @@ -438,8 +441,10 @@ buster.testCase("Test CLI", {
this.config = cliHelper.writeFile(
"buster2.js",
"var config = module.exports;" +
"config['browser tests'] = { environment: 'browser' };" +
"config['node tests'] = { environment: 'node' };"
"config['browser tests'] = { environment: 'browser', " +
"tests: ['test.js'] };" +
"config['node tests'] = { environment: 'node', " +
"tests: ['test.js'] };"
);
},

Expand Down Expand Up @@ -475,8 +480,14 @@ buster.testCase("Test CLI", {
var callback = this.spy();
this.runners.fake = { run: this.stub().returns({}) };
this.cli.runConfigGroups([
{ environment: "fake", id: 1, runExtensionHook: this.spy() },
{ environment: "fake", id: 2, runExtensionHook: this.spy() }
{ environment: "fake",
id: 1,
runExtensionHook: this.spy(),
tests: ['test.js'] },
{ environment: "fake",
id: 2,
runExtensionHook: this.spy(),
tests: ['test.js'] }
], {}, callback);

assert.calledOnce(this.runners.fake.run);
Expand All @@ -487,8 +498,14 @@ buster.testCase("Test CLI", {
var callback = this.spy();
this.runners.fake = { run: this.stub().yields().returns({}) };
this.cli.runConfigGroups([
{ environment: "fake", id: 1, runExtensionHook: this.spy() },
{ environment: "fake", id: 2, runExtensionHook: this.spy() }
{ environment: "fake",
id: 1,
runExtensionHook: this.spy(),
tests: ['test.js'] },
{ environment: "fake",
id: 2,
runExtensionHook: this.spy(),
tests: ['test.js'] }
], {}, callback);

assert.calledTwice(this.runners.fake.run);
Expand All @@ -501,7 +518,8 @@ buster.testCase("Test CLI", {
this.config = cliHelper.writeFile(
"buster2.js",
"var config = module.exports;" +
"config.server = { environment: 'node' }"
"config.server = { environment: 'node', " +
"tests: ['test.js'] }"
);
},

Expand All @@ -528,7 +546,8 @@ buster.testCase("Test CLI", {
};
this.fakeConfig = {
environment: "fake",
runExtensionHook: this.spy()
runExtensionHook: this.spy(),
tests: ["test.js"]
};
},

Expand All @@ -541,10 +560,8 @@ buster.testCase("Test CLI", {
"with code 0 when two test configurations pass": function () {
this.results = [[null, { ok: true, tests: 1 }],
[null, { ok: true, tests: 1 }]];
this.cli.runConfigGroups([this.fakeConfig, {
environment: "fake",
runExtensionHook: this.spy()
}], {}, this.done);
this.cli.runConfigGroups([this.fakeConfig,
this.fakeConfig], {}, this.done);
assert.calledOnceWith(this.exit, 0);
},

Expand All @@ -563,10 +580,8 @@ buster.testCase("Test CLI", {
"with code 1 when one of several test configus fails": function () {
this.results = [[null, { ok: true, tests: 1 }],
[null, { ok: false, tests: 1 }]];
this.cli.runConfigGroups([this.fakeConfig, {
environment: "fake",
runExtensionHook: this.spy()
}], {}, this.done);
this.cli.runConfigGroups([this.fakeConfig,
this.fakeConfig], {}, this.done);
assert.calledOnceWith(this.exit, 1);
},

Expand Down Expand Up @@ -611,7 +626,9 @@ buster.testCase("Test CLI", {
node: { run: this.stub().returns({}) },
browser: { run: this.stub().returns({}) }
};
this.config = { environment: "node", runExtensionHook: this.spy() };
this.config = { environment: "node",
runExtensionHook: this.spy(),
tests: ['test.js'] };
},

"are preloaded for environment": function () {
Expand Down

0 comments on commit a1b74d0

Please sign in to comment.