Skip to content

Commit 12ba7bc

Browse files
committed
Ship t.try() without requiring opt-in
This removes the tryAssertion experiment.
1 parent f4d4edd commit 12ba7bc

File tree

7 files changed

+39
-55
lines changed

7 files changed

+39
-55
lines changed

docs/03-assertions.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,6 @@ Snapshot assertions cannot be skipped when snapshots are being updated.
307307

308308
`.try()` allows you to *try* assertions without causing the test to fail.
309309

310-
*This assertion is experimental. [Enable the `tryAssertion` experiment](./06-configuration.md#experiments) to use it.*
311-
312310
The implementation function behaves the same as any other test function. You can even use macros. The first title argument is always optional. Additional arguments are passed to the implemetation or macro function.
313311

314312
`.try()` is an asynchronous function. You must `await` it. The result object has `commit()` and `discard()` methods. You must decide whether to commit or discard the result. If you commit a failed result, your test will fail.

docs/06-configuration.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,6 @@ export default {
213213
};
214214
```
215215

216-
You can opt in to the new `t.try()` assertion by specifying `tryAssertion`:
217-
218-
`ava.config.js`:
219-
```js
220-
export default {
221-
nonSemVerExperiments: {
222-
tryAssertion: true
223-
}
224-
};
225-
```
226-
227216
## Node arguments
228217

229218
The `nodeArguments` configuration may be used to specify additional arguments for launching worker processes. These are combined with `--node-arguments` passed on the CLI and any arguments passed to the `node` binary when starting AVA.

lib/load-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const pkgConf = require('pkg-conf');
77

88
const NO_SUCH_FILE = Symbol('no ava.config.js file');
99
const MISSING_DEFAULT_EXPORT = Symbol('missing default export');
10-
const EXPERIMENTS = new Set(['tryAssertion']);
10+
const EXPERIMENTS = new Set();
1111

1212
// *Very* rudimentary support for loading ava.config.js files containing an `export default` statement.
1313
const evaluateJsConfig = configFile => {

lib/test.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ class ExecutionContext extends assert.Assertions {
6969
};
7070

7171
this.try = async (...attemptArgs) => {
72-
if (test.experiments.tryAssertion !== true) {
73-
throw new Error('t.try() is currently an experiment. Opt in by setting `nonSemVerExperiments.tryAssertion` to `true`.');
74-
}
75-
7672
const {args, buildTitle, implementations, receivedImplementationArray} = parseTestArgs(attemptArgs);
7773

7874
if (implementations.length === 0) {

test/helper/ava-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,4 @@ function withExperiments(experiments = {}) {
6565

6666
exports.ava = withExperiments();
6767
exports.withExperiments = withExperiments;
68+
exports.newAva = () => withExperiments();

test/test-try-commit.js

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ require('../lib/worker/options').set({chalkOptions: {level: 0}});
55
const {test} = require('tap');
66
const delay = require('delay');
77
const ContextRef = require('../lib/context-ref');
8-
const {withExperiments} = require('./helper/ava-test');
8+
const {newAva} = require('./helper/ava-test');
99

1010
test('try-commit works', async t => {
11-
const ava = withExperiments({tryAssertion: true});
11+
const ava = newAva();
1212
const instance = ava(async a => {
1313
const res = await a.try(b => b.pass());
1414
t.true(res.passed);
@@ -22,7 +22,7 @@ test('try-commit works', async t => {
2222
});
2323

2424
test('try-commit is bound', async t => {
25-
const ava = withExperiments({tryAssertion: true});
25+
const ava = newAva();
2626
const result = await ava(async a => {
2727
const {try: tryFn} = a;
2828
const res = await tryFn(b => b.pass());
@@ -33,7 +33,7 @@ test('try-commit is bound', async t => {
3333
});
3434

3535
test('try-commit discards failed attempt', async t => {
36-
const ava = withExperiments({tryAssertion: true});
36+
const ava = newAva();
3737
const result = await ava(async a => {
3838
const res = await a.try(b => b.fail());
3939
await res.discard();
@@ -44,7 +44,7 @@ test('try-commit discards failed attempt', async t => {
4444
});
4545

4646
test('try-commit can discard produced result', async t => {
47-
const ava = withExperiments({tryAssertion: true});
47+
const ava = newAva();
4848
const result = await ava(async a => {
4949
const res = await a.try(b => b.pass());
5050
res.discard();
@@ -57,7 +57,7 @@ test('try-commit can discard produced result', async t => {
5757
});
5858

5959
test('try-commit fails when not all assertions were committed/discarded', async t => {
60-
const ava = withExperiments({tryAssertion: true});
60+
const ava = newAva();
6161
const result = await ava(async a => {
6262
a.pass();
6363
await a.try(b => b.pass());
@@ -73,7 +73,7 @@ test('try-commit works with values', async t => {
7373
const testValue1 = 123;
7474
const testValue2 = 123;
7575

76-
const ava = withExperiments({tryAssertion: true});
76+
const ava = newAva();
7777
const result = await ava(async a => {
7878
const res = await a.try((b, val1, val2) => {
7979
b.is(val1, val2);
@@ -86,7 +86,7 @@ test('try-commit works with values', async t => {
8686
});
8787

8888
test('try-commit is properly counted', async t => {
89-
const ava = withExperiments({tryAssertion: true});
89+
const ava = newAva();
9090
const instance = ava(async a => {
9191
const res = await a.try(b => {
9292
b.is(1, 1);
@@ -107,7 +107,7 @@ test('try-commit is properly counted', async t => {
107107
});
108108

109109
test('try-commit is properly counted multiple', async t => {
110-
const ava = withExperiments({tryAssertion: true});
110+
const ava = newAva();
111111
const instance = ava(async a => {
112112
const [res1, res2, res3] = await Promise.all([
113113
a.try(b => b.pass()),
@@ -130,7 +130,7 @@ test('try-commit is properly counted multiple', async t => {
130130

131131
test('try-commit goes as many levels', async t => {
132132
t.plan(5);
133-
const ava = withExperiments({tryAssertion: true});
133+
const ava = newAva();
134134
const instance = ava(async a => {
135135
t.ok(a.try);
136136
const res1 = await a.try(async b => {
@@ -151,7 +151,7 @@ test('try-commit goes as many levels', async t => {
151151
});
152152

153153
test('try-commit fails when not committed', async t => {
154-
const ava = withExperiments({tryAssertion: true});
154+
const ava = newAva();
155155
const result = await ava(async a => {
156156
const res = await a.try(b => b.pass());
157157
t.true(res.passed);
@@ -164,7 +164,7 @@ test('try-commit fails when not committed', async t => {
164164
});
165165

166166
test('try-commit fails when no assertions inside try', async t => {
167-
const ava = withExperiments({tryAssertion: true});
167+
const ava = newAva();
168168
const result = await ava(async a => {
169169
const res = await a.try(() => {});
170170
t.false(res.passed);
@@ -180,7 +180,7 @@ test('try-commit fails when no assertions inside try', async t => {
180180
});
181181

182182
test('try-commit fails when no assertions inside multiple try', async t => {
183-
const ava = withExperiments({tryAssertion: true});
183+
const ava = newAva();
184184
const result = await ava(async a => {
185185
const [res1, res2] = await Promise.all([
186186
a.try(b => b.pass()),
@@ -203,7 +203,7 @@ test('try-commit fails when no assertions inside multiple try', async t => {
203203
});
204204

205205
test('test fails when try-commit committed to failed state', async t => {
206-
const ava = withExperiments({tryAssertion: true});
206+
const ava = newAva();
207207
const result = await ava(async a => {
208208
const res = await a.try(b => b.fail());
209209
t.false(res.passed);
@@ -215,7 +215,7 @@ test('test fails when try-commit committed to failed state', async t => {
215215

216216
test('try-commit has proper titles, when going in depth and width', async t => {
217217
t.plan(6);
218-
const ava = withExperiments({tryAssertion: true});
218+
const ava = newAva();
219219
await ava(async a => {
220220
t.is(a.title, 'test');
221221

@@ -235,7 +235,7 @@ test('try-commit has proper titles, when going in depth and width', async t => {
235235
});
236236

237237
test('try-commit does not fail when calling commit twice', async t => {
238-
const ava = withExperiments({tryAssertion: true});
238+
const ava = newAva();
239239
const result = await ava(async a => {
240240
const res = await a.try(b => b.pass());
241241
res.commit();
@@ -247,7 +247,7 @@ test('try-commit does not fail when calling commit twice', async t => {
247247
});
248248

249249
test('try-commit does not fail when calling discard twice', async t => {
250-
const ava = withExperiments({tryAssertion: true});
250+
const ava = newAva();
251251
const result = await ava(async a => {
252252
const res = await a.try(b => b.pass());
253253
res.discard();
@@ -261,7 +261,7 @@ test('try-commit does not fail when calling discard twice', async t => {
261261
});
262262

263263
test('try-commit allows planning inside the try', async t => {
264-
const ava = withExperiments({tryAssertion: true});
264+
const ava = newAva();
265265
const result = await ava(async a => {
266266
const res = await a.try(b => {
267267
b.plan(3);
@@ -278,7 +278,7 @@ test('try-commit allows planning inside the try', async t => {
278278
});
279279

280280
test('try-commit fails when plan is not reached inside the try', async t => {
281-
const ava = withExperiments({tryAssertion: true});
281+
const ava = newAva();
282282
const result = await ava(async a => {
283283
const res = await a.try(b => {
284284
b.plan(3);
@@ -294,7 +294,7 @@ test('try-commit fails when plan is not reached inside the try', async t => {
294294
});
295295

296296
test('plan within try-commit is not affected by assertions outside', async t => {
297-
const ava = withExperiments({tryAssertion: true});
297+
const ava = newAva();
298298
const result = await ava(async a => {
299299
a.is(1, 1);
300300
a.is(2, 2);
@@ -314,7 +314,7 @@ test('plan within try-commit is not affected by assertions outside', async t =>
314314
});
315315

316316
test('assertions within try-commit do not affect plan in the parent test', async t => {
317-
const ava = withExperiments({tryAssertion: true});
317+
const ava = newAva();
318318
const result = await ava(async a => {
319319
a.plan(2);
320320

@@ -335,7 +335,7 @@ test('assertions within try-commit do not affect plan in the parent test', async
335335
});
336336

337337
test('test expected to fail will pass with failing try-commit within the test', async t => {
338-
const ava = withExperiments({tryAssertion: true});
338+
const ava = newAva();
339339
const result = await ava.failing(async a => {
340340
const res = await a.try(b => b.fail());
341341
t.false(res.passed);
@@ -351,7 +351,7 @@ test('test expected to fail will pass with failing try-commit within the test',
351351
});
352352

353353
test('try-commit works with callback test', async t => {
354-
const ava = withExperiments({tryAssertion: true});
354+
const ava = newAva();
355355
const result = await ava.cb(a => {
356356
a
357357
.try(b => b.pass())
@@ -365,7 +365,7 @@ test('try-commit works with callback test', async t => {
365365
});
366366

367367
test('try-commit works with failing callback test', async t => {
368-
const ava = withExperiments({tryAssertion: true});
368+
const ava = newAva();
369369
const result = await ava.cb.failing(a => {
370370
a
371371
.try(b => b.fail())
@@ -387,7 +387,7 @@ test('try-commit works with failing callback test', async t => {
387387
});
388388

389389
test('try-commit does not allow to use .end() in attempt when parent is callback test', async t => {
390-
const ava = withExperiments({tryAssertion: true});
390+
const ava = newAva();
391391
const result = await ava.cb(a => {
392392
a
393393
.try(b => {
@@ -408,7 +408,7 @@ test('try-commit does not allow to use .end() in attempt when parent is callback
408408
});
409409

410410
test('try-commit does not allow to use .end() in attempt when parent is regular test', async t => {
411-
const ava = withExperiments({tryAssertion: true});
411+
const ava = newAva();
412412
const result = await ava(async a => {
413413
const res = await a.try(b => {
414414
b.pass();
@@ -433,7 +433,7 @@ test('try-commit accepts macros', async t => {
433433

434434
macro.title = (providedTitle = '') => `${providedTitle} Title`.trim();
435435

436-
const ava = withExperiments({tryAssertion: true});
436+
const ava = newAva();
437437
const result = await ava(async a => {
438438
const res = await a.try(macro);
439439
t.true(res.passed);
@@ -444,7 +444,7 @@ test('try-commit accepts macros', async t => {
444444
});
445445

446446
test('try-commit accepts multiple macros', async t => {
447-
const ava = withExperiments({tryAssertion: true});
447+
const ava = newAva();
448448
const result = await ava(async a => {
449449
const [res1, res2] = await a.try([
450450
b => {
@@ -481,7 +481,7 @@ test('try-commit accepts multiple macros', async t => {
481481
});
482482

483483
test('try-commit returns results in the same shape as when implementations are passed', async t => {
484-
const ava = withExperiments({tryAssertion: true});
484+
const ava = newAva();
485485
const result = await ava(async a => {
486486
const [res1, res2, res3] = await Promise.all([
487487
a.try(b => b.pass()),
@@ -506,7 +506,7 @@ test('try-commit returns results in the same shape as when implementations are p
506506
});
507507

508508
test('try-commit abides timeout', async t => {
509-
const ava = withExperiments({tryAssertion: true});
509+
const ava = newAva();
510510
const result1 = await ava(async a => {
511511
a.timeout(10);
512512
const result = await a.try(async b => {
@@ -521,7 +521,7 @@ test('try-commit abides timeout', async t => {
521521
});
522522

523523
test('try-commit fails when it exceeds its own timeout', async t => {
524-
const ava = withExperiments({tryAssertion: true});
524+
const ava = newAva();
525525
const result = await ava(async a => {
526526
a.timeout(200);
527527
const result = await a.try(async b => {
@@ -545,7 +545,7 @@ test('try-commit fails when it exceeds its own timeout', async t => {
545545
});
546546

547547
test('try-commit refreshes the timeout on commit/discard', async t => {
548-
const ava = withExperiments({tryAssertion: true});
548+
const ava = newAva();
549549
const result1 = await ava.cb(a => {
550550
a.timeout(100);
551551
a.plan(3);
@@ -559,7 +559,7 @@ test('try-commit refreshes the timeout on commit/discard', async t => {
559559
});
560560

561561
test('assertions within try-commit do not refresh the timeout', async t => {
562-
const ava = withExperiments({tryAssertion: true});
562+
const ava = newAva();
563563
const result = await ava(async a => {
564564
a.timeout(15);
565565
a.pass();
@@ -587,7 +587,7 @@ test('try-commit inherits the test context', async t => {
587587
const context = new ContextRef();
588588
const data = {foo: 'bar'};
589589
context.set(data);
590-
const ava = withExperiments({tryAssertion: true});
590+
const ava = newAva();
591591
const result = await ava(async a => {
592592
const res = await a.try(b => {
593593
b.pass();
@@ -603,7 +603,7 @@ test('assigning context in try-commit does not affect parent', async t => {
603603
const context = new ContextRef();
604604
const data = {foo: 'bar'};
605605
context.set(data);
606-
const ava = withExperiments({tryAssertion: true});
606+
const ava = newAva();
607607
const result = await ava(async a => {
608608
t.strictDeepEqual(a.context, data);
609609
const res = await a.try(b => {
@@ -618,7 +618,7 @@ test('assigning context in try-commit does not affect parent', async t => {
618618
});
619619

620620
test('do not run assertions outside of an active attempt', async t => {
621-
const ava = withExperiments({tryAssertion: true});
621+
const ava = newAva();
622622
const passing = await ava(async a => {
623623
await a.try(() => {});
624624
a.pass();

test/try-snapshot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const ContextRef = require('../lib/context-ref');
1010

1111
function setup(title, manager, fn) {
1212
return new Test({
13-
experiments: {tryAssertion: true},
13+
experiments: {},
1414
fn,
1515
failWithoutAssertions: true,
1616
metadata: {type: 'test', callback: false},

0 commit comments

Comments
 (0)