diff --git a/api.js b/api.js index f19a51803..3033c7f7d 100644 --- a/api.js +++ b/api.js @@ -119,7 +119,7 @@ Api.prototype._run = function (files, _options) { })) || uniqueTempDir(); self.options.cacheDir = cacheDir; - self.precompiler = new CachingPrecompiler(cacheDir, self.options.babelConfig); + self.precompiler = new CachingPrecompiler(cacheDir, self.options.babelConfig, self.options.powerAssert); self.fileCount = files.length; var overwatch; diff --git a/cli.js b/cli.js index b8da1a24d..26a0571a2 100755 --- a/cli.js +++ b/cli.js @@ -64,6 +64,7 @@ var cli = meow([ ' --tap, -t Generate TAP output', ' --verbose, -v Enable verbose output', ' --no-cache Disable the transpiler cache', + ' --no-power-assert Disable Power Assert', ' --match, -m Only run tests with matching title (Can be repeated)', ' --watch, -w Re-run tests when tests and source files change', ' --source, -S Pattern to match source files so tests can be re-run (Can be repeated)', @@ -130,6 +131,7 @@ var api = new Api({ serial: cli.flags.serial, require: arrify(cli.flags.require), cacheEnabled: cli.flags.cache !== false, + powerAssert: cli.flags.powerAssert !== false, explicitTitles: cli.flags.watch, match: arrify(cli.flags.match), babelConfig: conf.babel, diff --git a/lib/babel-config.js b/lib/babel-config.js index 0f3a138a0..dbfddf546 100644 --- a/lib/babel-config.js +++ b/lib/babel-config.js @@ -77,14 +77,13 @@ var espowerPlugin = lazy(function () { var defaultPlugins = lazy(function () { return [ - espowerPlugin(), require('babel-plugin-ava-throws-helper'), rewritePlugin(), require('babel-plugin-transform-runtime') ]; }); -function build(babelConfig, filePath, code) { +function build(babelConfig, powerAssert, filePath, code) { babelConfig = validate(babelConfig); var options; @@ -115,7 +114,9 @@ function build(babelConfig, filePath, code) { ast: false }); - options.plugins = (options.plugins || []).concat(defaultPlugins()); + options.plugins = (options.plugins || []) + .concat(powerAssert ? espowerPlugin() : []) + .concat(defaultPlugins()); return options; } diff --git a/lib/caching-precompiler.js b/lib/caching-precompiler.js index 7ecd6485b..67298bb3b 100644 --- a/lib/caching-precompiler.js +++ b/lib/caching-precompiler.js @@ -9,12 +9,13 @@ var packageHash = require('package-hash'); var autoBind = require('auto-bind'); var babelConfigHelper = require('./babel-config'); -function CachingPrecompiler(cacheDirPath, babelConfig) { +function CachingPrecompiler(cacheDirPath, babelConfig, powerAssert) { if (!(this instanceof CachingPrecompiler)) { throw new TypeError('Class constructor CachingPrecompiler cannot be invoked without \'new\''); } this.babelConfig = babelConfigHelper.validate(babelConfig); + this.powerAssert = powerAssert; this.cacheDirPath = cacheDirPath; this.fileHashes = {}; @@ -49,7 +50,7 @@ CachingPrecompiler.prototype._init = function () { CachingPrecompiler.prototype._transform = function (code, filePath, hash) { code = code.toString(); - var options = babelConfigHelper.build(this.babelConfig, filePath, code); + var options = babelConfigHelper.build(this.babelConfig, this.powerAssert, filePath, code); var result = this.babel.transform(code, options); // save source map diff --git a/readme.md b/readme.md index 12246e4ff..9ebe07715 100644 --- a/readme.md +++ b/readme.md @@ -144,6 +144,7 @@ $ ava --help --tap, -t Generate TAP output --verbose, -v Enable verbose output --no-cache Disable the transpiler cache + --no-power-assert Disable Power Assert --match, -m Only run tests with matching title (Can be repeated) --watch, -w Re-run tests when tests and source files change --source, -S Pattern to match source files so tests can be re-run (Can be repeated) @@ -223,6 +224,7 @@ All of the CLI options can be configured in the `ava` section of your `package.j "concurrency": 5, "failFast": true, "tap": true, + "powerAssert": false, "require": [ "babel-register" ], diff --git a/test/api.js b/test/api.js index 99a43fd8d..c3bcb0795 100644 --- a/test/api.js +++ b/test/api.js @@ -16,6 +16,8 @@ test('must be called with new', function (t) { }); generateTests('Without Pool: ', function (options) { + options = options || {}; + options.powerAssert = true; return new Api(options); }); @@ -60,6 +62,7 @@ test('Without Pool: test files can be forced to run in exclusive mode', function generateTests('With Pool: ', function (options) { options = options || {}; options.concurrency = 2; + options.powerAssert = true; return new Api(options); }); diff --git a/test/babel-config.js b/test/babel-config.js index ee2a9ec24..9649f562e 100644 --- a/test/babel-config.js +++ b/test/babel-config.js @@ -50,7 +50,8 @@ test('uses babelConfig for babel options when babelConfig is an object', functio var fixturePath = fixture('es2015.js'); var fixtureSource = fs.readFileSync(fixturePath, 'utf8'); - var options = babelConfigHelper.build(babelConfig, fixturePath, fixtureSource); + var powerAssert = true; + var options = babelConfigHelper.build(babelConfig, powerAssert, fixturePath, fixtureSource); t.true('filename' in options); t.true(options.sourceMaps); @@ -79,7 +80,8 @@ test('should reuse existing source maps', function (t) { var fixturePath = fixture('es2015-source-maps.js'); var fixtureSource = fs.readFileSync(fixturePath, 'utf8'); - var options = babelConfigHelper.build(babelConfig, fixturePath, fixtureSource); + var powerAssert = true; + var options = babelConfigHelper.build(babelConfig, powerAssert, fixturePath, fixtureSource); t.true('filename' in options); t.true(options.sourceMaps); @@ -89,3 +91,27 @@ test('should reuse existing source maps', function (t) { t.strictDeepEqual(options.plugins, [customPlugin, setup.powerAssert, throwsHelper, setup.rewrite, transformRuntime]); t.end(); }); + +test('should disable power-assert when powerAssert is false', function (t) { + var setup = setUp(); + var customPlugin = setup.customPlugin; + + var babelConfigHelper = proxyquire('../lib/babel-config', { + 'babel-plugin-espower/create': setup.createEspowerPlugin, + 'babel-plugin-detective/wrap-listener': setup.babelDetectiveWrap + }); + + var babelConfig = { + presets: ['stage-2', 'es2015'], + plugins: [customPlugin] + }; + + var fixturePath = fixture('es2015.js'); + var fixtureSource = fs.readFileSync(fixturePath, 'utf8'); + + var powerAssert = false; + var options = babelConfigHelper.build(babelConfig, powerAssert, fixturePath, fixtureSource); + + t.strictDeepEqual(options.plugins, [customPlugin, throwsHelper, setup.rewrite, transformRuntime]); + t.end(); +});