Skip to content

Commit 2c683b9

Browse files
novemberbornsindresorhus
authored andcommitted
Clean up API tests (#1258)
* Remove double space in generated API test titles * Improve test management in API tests Tests don't need to be ended when a promise is returned. Test plans are not necessary if all assertions occur within the returned promise chain. Exceptions will still fail the test.
1 parent 8a8669c commit 2c683b9

File tree

1 file changed

+3
-55
lines changed

1 file changed

+3
-55
lines changed

test/api.js

+3-55
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ function apiCreator(options) {
2121
return instance;
2222
}
2323

24-
generateTests('Without Pool: ', options => apiCreator(options || {}));
24+
generateTests('Without Pool:', options => apiCreator(options || {}));
2525

2626
// The following two tests are only run against "Without Pool" behavior as they test the exclusive test features. These features are currently not expected to work correctly in the limited process pool. When the limited process pool behavior is finalized this test file will be updated. See: https://github.com/avajs/ava/pull/791#issuecomment-216293302
2727
test('Without Pool: test file with exclusive tests causes non-exclusive tests in other files to be ignored', t => {
28-
t.plan(4);
29-
3028
const files = [
3129
path.join(__dirname, 'fixture/exclusive.js'),
3230
path.join(__dirname, 'fixture/exclusive-nonexclusive.js'),
@@ -45,8 +43,6 @@ test('Without Pool: test file with exclusive tests causes non-exclusive tests in
4543
});
4644

4745
test('Without Pool: test files can be forced to run in exclusive mode', t => {
48-
t.plan(4);
49-
5046
const api = apiCreator();
5147
return api.run(
5248
[path.join(__dirname, 'fixture/es2015.js')],
@@ -59,16 +55,14 @@ test('Without Pool: test files can be forced to run in exclusive mode', t => {
5955
});
6056
});
6157

62-
generateTests('With Pool: ', options => {
58+
generateTests('With Pool:', options => {
6359
options = options || {};
6460
options.concurrency = 2;
6561
return apiCreator(options);
6662
});
6763

6864
function generateTests(prefix, apiCreator) {
6965
test(`${prefix} ES2015 support`, t => {
70-
t.plan(1);
71-
7266
const api = apiCreator();
7367

7468
return api.run([path.join(__dirname, 'fixture/es2015.js')])
@@ -78,8 +72,6 @@ function generateTests(prefix, apiCreator) {
7872
});
7973

8074
test(`${prefix} precompile helpers`, t => {
81-
t.plan(1);
82-
8375
const api = apiCreator({
8476
precompileHelpers: true,
8577
resolveTestsFrom: path.join(__dirname, 'fixture/precompile-helpers')
@@ -92,8 +84,6 @@ function generateTests(prefix, apiCreator) {
9284
});
9385

9486
test(`${prefix} generators support`, t => {
95-
t.plan(1);
96-
9787
const api = apiCreator();
9888

9989
return api.run([path.join(__dirname, 'fixture/generators.js')])
@@ -103,8 +93,6 @@ function generateTests(prefix, apiCreator) {
10393
});
10494

10595
test(`${prefix} async/await support`, t => {
106-
t.plan(1);
107-
10896
const api = apiCreator();
10997

11098
return api.run([path.join(__dirname, 'fixture/async-await.js')])
@@ -222,8 +210,6 @@ function generateTests(prefix, apiCreator) {
222210
});
223211

224212
test(`${prefix} display filename prefixes for failed test stack traces`, t => {
225-
t.plan(3);
226-
227213
const files = [
228214
path.join(__dirname, 'fixture/es2015.js'),
229215
path.join(__dirname, 'fixture/one-pass-one-fail.js')
@@ -242,8 +228,6 @@ function generateTests(prefix, apiCreator) {
242228
// This is a seperate test because we can't ensure the order of the errors (to match them), and this is easier than
243229
// sorting.
244230
test(`${prefix} display filename prefixes for failed test stack traces in subdirs`, t => {
245-
t.plan(3);
246-
247231
const files = [
248232
path.join(__dirname, 'fixture/es2015.js'),
249233
path.join(__dirname, 'fixture/subdir/failing-subdir.js')
@@ -260,8 +244,6 @@ function generateTests(prefix, apiCreator) {
260244
});
261245

262246
test(`${prefix} fail-fast mode`, t => {
263-
t.plan(5);
264-
265247
const api = apiCreator({
266248
failFast: true
267249
});
@@ -294,8 +276,6 @@ function generateTests(prefix, apiCreator) {
294276
});
295277

296278
test(`${prefix} serial execution mode`, t => {
297-
t.plan(3);
298-
299279
const api = apiCreator({
300280
serial: true
301281
});
@@ -309,8 +289,6 @@ function generateTests(prefix, apiCreator) {
309289
});
310290

311291
test(`${prefix} circular references on assertions do not break process.send`, t => {
312-
t.plan(1);
313-
314292
const api = apiCreator();
315293

316294
return api.run([path.join(__dirname, 'fixture/circular-reference-on-assertion.js')])
@@ -320,7 +298,6 @@ function generateTests(prefix, apiCreator) {
320298
});
321299

322300
test(`${prefix} run from package.json folder by default`, t => {
323-
t.plan(1);
324301
const api = apiCreator();
325302

326303
return api.run([path.join(__dirname, 'fixture/process-cwd-default.js')])
@@ -330,8 +307,6 @@ function generateTests(prefix, apiCreator) {
330307
});
331308

332309
test(`${prefix} control worker's process.cwd() with projectDir option`, t => {
333-
t.plan(1);
334-
335310
const fullPath = path.join(__dirname, 'fixture/process-cwd-pkgdir.js');
336311
const api = apiCreator({projectDir: path.dirname(fullPath)});
337312

@@ -378,8 +353,6 @@ function generateTests(prefix, apiCreator) {
378353
});
379354

380355
test(`${prefix} errors can occur without messages`, t => {
381-
t.plan(2);
382-
383356
const api = apiCreator();
384357

385358
return api.run([path.join(__dirname, 'fixture/error-without-message.js')])
@@ -495,8 +468,6 @@ function generateTests(prefix, apiCreator) {
495468
});
496469

497470
test(`${prefix} absolute paths`, t => {
498-
t.plan(1);
499-
500471
const api = apiCreator();
501472

502473
return api.run([path.resolve('test/fixture/es2015.js')])
@@ -506,8 +477,6 @@ function generateTests(prefix, apiCreator) {
506477
});
507478

508479
test(`${prefix} symlink to directory containing test files`, t => {
509-
t.plan(1);
510-
511480
const api = apiCreator();
512481

513482
return api.run([path.join(__dirname, 'fixture/symlink')])
@@ -517,8 +486,6 @@ function generateTests(prefix, apiCreator) {
517486
});
518487

519488
test(`${prefix} symlink to test file directly`, t => {
520-
t.plan(1);
521-
522489
const api = apiCreator();
523490

524491
return api.run([path.join(__dirname, 'fixture/symlinkfile.js')])
@@ -528,8 +495,6 @@ function generateTests(prefix, apiCreator) {
528495
});
529496

530497
test(`${prefix} search directories recursively for files`, t => {
531-
t.plan(2);
532-
533498
const api = apiCreator();
534499

535500
return api.run([path.join(__dirname, 'fixture/subdir')])
@@ -540,8 +505,6 @@ function generateTests(prefix, apiCreator) {
540505
});
541506

542507
test(`${prefix} titles of both passing and failing tests and AssertionErrors are returned`, t => {
543-
t.plan(3);
544-
545508
const api = apiCreator();
546509

547510
return api.run([path.join(__dirname, 'fixture/one-pass-one-fail.js')])
@@ -674,8 +637,6 @@ function generateTests(prefix, apiCreator) {
674637
});
675638

676639
test(`${prefix} Node.js-style --require CLI argument`, t => {
677-
t.plan(1);
678-
679640
const requirePath = './' + path.relative('.', path.join(__dirname, 'fixture/install-global.js')).replace(/\\/g, '/');
680641

681642
const api = apiCreator({
@@ -689,16 +650,14 @@ function generateTests(prefix, apiCreator) {
689650
});
690651

691652
test(`${prefix} Node.js-style --require CLI argument module not found`, t => {
692-
t.plan(1);
693-
694653
t.throws(() => {
695654
/* eslint no-new: 0 */
696655
apiCreator({require: ['foo-bar']});
697656
}, /^Could not resolve required module 'foo-bar'$/);
657+
t.end();
698658
});
699659

700660
test(`${prefix} caching is enabled by default`, t => {
701-
t.plan(3);
702661
rimraf.sync(path.join(__dirname, 'fixture/caching/node_modules'));
703662

704663
const api = apiCreator({
@@ -711,7 +670,6 @@ function generateTests(prefix, apiCreator) {
711670
t.is(files.length, 2);
712671
t.is(files.filter(endsWithJs).length, 1);
713672
t.is(files.filter(endsWithMap).length, 1);
714-
t.end();
715673
});
716674

717675
function endsWithJs(filename) {
@@ -724,7 +682,6 @@ function generateTests(prefix, apiCreator) {
724682
});
725683

726684
test(`${prefix} caching can be disabled`, t => {
727-
t.plan(1);
728685
rimraf.sync(path.join(__dirname, 'fixture/caching/node_modules'));
729686

730687
const api = apiCreator({
@@ -735,13 +692,10 @@ function generateTests(prefix, apiCreator) {
735692
return api.run([path.join(__dirname, 'fixture/caching/test.js')])
736693
.then(() => {
737694
t.false(fs.existsSync(path.join(__dirname, 'fixture/caching/node_modules/.cache/ava')));
738-
t.end();
739695
});
740696
});
741697

742698
test(`${prefix} test file with only skipped tests does not create a failure`, t => {
743-
t.plan(2);
744-
745699
const api = apiCreator();
746700

747701
return api.run([path.join(__dirname, 'fixture/skip-only.js')])
@@ -752,8 +706,6 @@ function generateTests(prefix, apiCreator) {
752706
});
753707

754708
test(`${prefix} resets state before running`, t => {
755-
t.plan(2);
756-
757709
const api = apiCreator();
758710

759711
return api.run([path.resolve('test/fixture/es2015.js')]).then(result => {
@@ -1044,8 +996,6 @@ function generateTests(prefix, apiCreator) {
1044996

1045997
function generatePassDebugTests(execArgv, expectedInspectIndex) {
1046998
test(`pass ${execArgv.join(' ')} to fork`, t => {
1047-
t.plan(expectedInspectIndex === -1 ? 3 : 2);
1048-
1049999
const api = apiCreator({testOnlyExecArgv: execArgv});
10501000
return api._computeForkExecArgs(['foo.js'])
10511001
.then(result => {
@@ -1062,8 +1012,6 @@ function generatePassDebugTests(execArgv, expectedInspectIndex) {
10621012

10631013
function generatePassDebugIntegrationTests(execArgv) {
10641014
test(`pass ${execArgv.join(' ')} to fork`, t => {
1065-
t.plan(1);
1066-
10671015
const api = apiCreator({testOnlyExecArgv: execArgv});
10681016
return api.run([path.join(__dirname, 'fixture/debug-arg.js')])
10691017
.then(result => {

0 commit comments

Comments
 (0)