Skip to content

Commit d20c18a

Browse files
committed
Replace powerAssert option by compileEnhancements
This new option controls whether the @ava/transform-test-files preset is used at all. Disabling will be one of the things necessary to side-step Babel altogether. Removes support for the `--no-power-assert` CLI flag, without a replacement. Refs #1556.
1 parent 5a4c58a commit d20c18a

File tree

6 files changed

+29
-32
lines changed

6 files changed

+29
-32
lines changed

api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ class Api extends EventEmitter {
117117

118118
this.options.cacheDir = cacheDir;
119119

120-
const isPowerAssertEnabled = this.options.powerAssert !== false;
121-
return babelConfigHelper.build(this.options.projectDir, cacheDir, this.options.babelConfig, isPowerAssertEnabled)
120+
const compileEnhancements = this.options.compileEnhancements !== false;
121+
return babelConfigHelper.build(this.options.projectDir, cacheDir, this.options.babelConfig, compileEnhancements)
122122
.then(result => {
123123
this.precompiler = new CachingPrecompiler({
124124
path: cacheDir,

lib/babel-config.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function resolveOptions(baseConfig, cache, envName, optionsFile, verifierFile) {
8282
});
8383
}
8484

85-
function build(projectDir, cacheDir, userOptions, powerAssert) {
85+
function build(projectDir, cacheDir, userOptions, compileEnhancements) {
8686
// Note that Babel ignores empty string values, even for NODE_ENV. Here
8787
// default to 'test' unless NODE_ENV is defined, in which case fall back to
8888
// Babel's default of 'development' if it's empty.
@@ -108,10 +108,11 @@ function build(projectDir, cacheDir, userOptions, powerAssert) {
108108
const baseOptions = {
109109
babelrc: false,
110110
plugins: [],
111-
presets: [
112-
['@ava/transform-test-files', {powerAssert}]
113-
]
111+
presets: []
114112
};
113+
if (compileEnhancements) {
114+
baseOptions.presets.push(['@ava/transform-test-files', {powerAssert: true}]);
115+
}
115116
if (userOptions === 'default') {
116117
baseOptions.presets.unshift('@ava/stage-4');
117118
}

lib/cli.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ exports.run = () => {
3737
--tap, -t Generate TAP output
3838
--verbose, -v Enable verbose output
3939
--no-cache Disable the transpiler cache
40-
--no-power-assert Disable Power Assert
4140
--color Force color output
4241
--no-color Disable color output
4342
--match, -m Only run tests with matching title (Can be repeated)
@@ -80,7 +79,6 @@ exports.run = () => {
8079
failFast: conf.failFast,
8180
init: conf.init,
8281
match: conf.match,
83-
powerAssert: conf.powerAssert,
8482
serial: conf.serial,
8583
tap: conf.tap,
8684
timeout: conf.timeout,
@@ -140,7 +138,7 @@ exports.run = () => {
140138
serial: conf.serial,
141139
require: arrify(conf.require),
142140
cacheEnabled: conf.cache !== false,
143-
powerAssert: conf.powerAssert !== false,
141+
compileEnhancements: conf.compileEnhancements !== false,
144142
explicitTitles: conf.watch,
145143
match: arrify(conf.match),
146144
babelConfig: babelConfigHelper.validate(conf.babel),

readme.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ $ ava --help
163163
--tap, -t Generate TAP output
164164
--verbose, -v Enable verbose output
165165
--no-cache Disable the transpiler cache
166-
--no-power-assert Disable Power Assert
167166
--color Force color output
168167
--no-color Disable color output
169168
--match, -m Only run tests with matching title (Can be repeated)
@@ -266,7 +265,7 @@ All of the CLI options can be configured in the `ava` section of your `package.j
266265
"failFast": true,
267266
"failWithoutAssertions": false,
268267
"tap": true,
269-
"powerAssert": false,
268+
"compileEnhancements": false,
270269
"require": [
271270
"babel-register"
272271
],
@@ -286,7 +285,7 @@ Arguments passed to the CLI will always take precedence over the configuration i
286285
- `failWithoutAssertions`: if `false`, does not fail a test if it doesn't run [assertions](#assertions)
287286
- `tap`: if `true`, enables the [TAP reporter](#tap-reporter)
288287
- `snapshotDir`: specifies a fixed location for storing snapshot files. Use this if your snapshots are ending up in the wrong location
289-
- `powerAssert`: if `false`, disables [power-assert](https://github.com/power-assert-js/power-assert) which otherwise helps provide more descriptive error messages
288+
- `compileEnhancements`: if `false`, disables [power-assert](https://github.com/power-assert-js/power-assert) which otherwise helps provide more descriptive error messages — and detection of improper use of the `t.throws()` assertion
290289
- `require`: extra modules to require before tests are run. Modules are required in the [worker processes](#process-isolation)
291290
- `babel`: test file specific Babel options. See [ES2017 support](#es2017-support) for more details
292291

test/api.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const ROOT_DIR = path.join(__dirname, '..');
1313
function apiCreator(options) {
1414
options = options || {};
1515
options.babelConfig = options.babelConfig || 'default';
16-
options.powerAssert = true;
1716
options.projectDir = options.projectDir || ROOT_DIR;
1817
options.resolveTestsFrom = options.resolveTestsFrom || options.projectDir;
1918
const instance = new Api(options);

test/babel-config.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,36 +38,36 @@ function withNodeEnv(value, run) {
3838

3939
test('uses default presets when userOptions is "default"', t => {
4040
const userOptions = 'default';
41-
const powerAssert = true;
41+
const compileEnhancements = true;
4242

4343
const projectDir = uniqueTempDir();
4444
const cacheDir = path.join(projectDir, 'cache');
45-
return babelConfigHelper.build(projectDir, cacheDir, userOptions, powerAssert)
45+
return babelConfigHelper.build(projectDir, cacheDir, userOptions, compileEnhancements)
4646
.then(result => {
4747
const options = result.getOptions();
4848

4949
t.false(options.babelrc);
5050
t.is(options.presets[0][0].wrapped, require('@ava/babel-preset-stage-4'));
5151
t.is(options.presets[1][0].wrapped, require('@ava/babel-preset-transform-test-files'));
52-
t.same(options.presets[1][1], {powerAssert});
52+
t.same(options.presets[1][1], {powerAssert: true});
5353
});
5454
});
5555

5656
test('uses options from babelrc when userOptions is "inherit"', t => {
5757
const userOptions = 'inherit';
58-
const powerAssert = true;
58+
const compileEnhancements = true;
5959

6060
const projectDir = fixture('babelrc');
6161
const cacheDir = path.join(uniqueTempDir(), 'cache');
62-
return babelConfigHelper.build(projectDir, cacheDir, userOptions, powerAssert)
62+
return babelConfigHelper.build(projectDir, cacheDir, userOptions, compileEnhancements)
6363
.then(result => {
6464
const options = result.getOptions();
6565

6666
t.false(options.babelrc);
6767
t.is(options.plugins[0][0].wrapped, require(fixture('babel-plugin-test-doubler')));
6868
t.is(options.presets[0][0].wrapped, require('@ava/babel-preset-stage-4'));
6969
t.is(options.presets[1][0].wrapped, require('@ava/babel-preset-transform-test-files'));
70-
t.same(options.presets[1][1], {powerAssert});
70+
t.same(options.presets[1][1], {powerAssert: true});
7171
});
7272
});
7373

@@ -78,54 +78,54 @@ test('uses userOptions for babel options when userOptions is an object', t => {
7878
plugins: [customFile],
7979
presets: [customFile]
8080
};
81-
const powerAssert = true;
81+
const compileEnhancements = true;
8282

8383
const projectDir = uniqueTempDir();
8484
const cacheDir = path.join(projectDir, 'cache');
85-
return babelConfigHelper.build(projectDir, cacheDir, userOptions, powerAssert)
85+
return babelConfigHelper.build(projectDir, cacheDir, userOptions, compileEnhancements)
8686
.then(result => {
8787
const options = result.getOptions();
8888
t.false(options.babelrc);
8989
t.is(options.plugins[0][0].wrapped, custom);
9090
t.is(options.presets[0][0].wrapped, custom);
9191
t.is(options.presets[1][0].wrapped, require('@ava/babel-preset-transform-test-files'));
92-
t.same(options.presets[1][1], {powerAssert});
92+
t.same(options.presets[1][1], {powerAssert: true});
9393
});
9494
});
9595

9696
test('uses "development" environment if NODE_ENV is the empty string', t => {
9797
const userOptions = 'inherit';
98-
const powerAssert = true;
98+
const compileEnhancements = true;
9999

100100
const projectDir = fixture('babelrc');
101101
const cacheDir = path.join(uniqueTempDir(), 'cache');
102-
return withNodeEnv('', () => babelConfigHelper.build(projectDir, cacheDir, userOptions, powerAssert))
102+
return withNodeEnv('', () => babelConfigHelper.build(projectDir, cacheDir, userOptions, compileEnhancements))
103103
.then(result => {
104104
const options = result.getOptions();
105105

106106
t.false(options.babelrc);
107107
t.is(options.plugins[0][0].wrapped, require(fixture('babel-plugin-test-capitalizer')));
108108
t.is(options.presets[0][0].wrapped, require('@ava/babel-preset-stage-4'));
109109
t.is(options.presets[1][0].wrapped, require('@ava/babel-preset-transform-test-files'));
110-
t.same(options.presets[1][1], {powerAssert});
110+
t.same(options.presets[1][1], {powerAssert: true});
111111
});
112112
});
113113

114114
test('supports .babelrc.js files', t => {
115115
const userOptions = 'inherit';
116-
const powerAssert = true;
116+
const compileEnhancements = true;
117117

118118
const projectDir = fixture('babelrc-js');
119119
const cacheDir = path.join(uniqueTempDir(), 'cache');
120-
return babelConfigHelper.build(projectDir, cacheDir, userOptions, powerAssert)
120+
return babelConfigHelper.build(projectDir, cacheDir, userOptions, compileEnhancements)
121121
.then(result => {
122122
const options = result.getOptions();
123123

124124
t.false(options.babelrc);
125125
t.is(options.plugins[0][0].wrapped, require(fixture('babel-plugin-test-doubler')));
126126
t.is(options.presets[0][0].wrapped, require('@ava/babel-preset-stage-4'));
127127
t.is(options.presets[1][0].wrapped, require('@ava/babel-preset-transform-test-files'));
128-
t.same(options.presets[1][1], {powerAssert});
128+
t.same(options.presets[1][1], {powerAssert: true});
129129
});
130130
});
131131

@@ -162,18 +162,18 @@ test('does not add babel-plugin-syntax-object-rest-spread for node versions < 8.
162162
});
163163
});
164164

165-
test('should disable power-assert when powerAssert is false', t => {
165+
test('should not include transform-test-files when compileEnhancements is false', t => {
166166
const userOptions = 'default';
167-
const powerAssert = false;
167+
const compileEnhancements = false;
168168

169169
const projectDir = uniqueTempDir();
170170
const cacheDir = path.join(projectDir, 'cache');
171-
return babelConfigHelper.build(projectDir, cacheDir, userOptions, powerAssert)
171+
return babelConfigHelper.build(projectDir, cacheDir, userOptions, compileEnhancements)
172172
.then(result => {
173173
const options = result.getOptions();
174174

175175
t.false(options.babelrc);
176-
t.same(options.presets[1][1], {powerAssert});
176+
t.is(options.presets.length, 1);
177177
});
178178
});
179179

0 commit comments

Comments
 (0)