diff --git a/lib/run-analyzer.js b/lib/run-analyzer.js index 8697242..032b571 100644 --- a/lib/run-analyzer.js +++ b/lib/run-analyzer.js @@ -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; diff --git a/lib/runners/browser.js b/lib/runners/browser.js index 0b2c24c..8252cb3 100644 --- a/lib/runners/browser.js +++ b/lib/runners/browser.js @@ -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({ diff --git a/test/run-analyzer-test.js b/test/run-analyzer-test.js index a4e00af..aa76175 100644 --- a/test/run-analyzer-test.js +++ b/test/run-analyzer-test.js @@ -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"); @@ -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 () { @@ -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 }); diff --git a/test/test-cli-test.js b/test/test-cli-test.js index 269d610..204bdf3 100644 --- a/test/test-cli-test.js +++ b/test/test-cli-test.js @@ -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) { @@ -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, @@ -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'] }" ); }, @@ -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'] };" ); }, @@ -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); @@ -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); @@ -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'] }" ); }, @@ -528,7 +546,8 @@ buster.testCase("Test CLI", { }; this.fakeConfig = { environment: "fake", - runExtensionHook: this.spy() + runExtensionHook: this.spy(), + tests: ["test.js"] }; }, @@ -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); }, @@ -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); }, @@ -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 () {