/
assorted.js
162 lines (139 loc) 路 4.11 KB
/
assorted.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import childProcess from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import ciInfo from 'ci-info';
import stripAnsi from 'strip-ansi';
import {test} from 'tap';
import {execCli} from '../helper/cli.js';
const __dirname = fileURLToPath(new URL('.', import.meta.url));
test('timeout', {skip: ciInfo.isCI}, t => {
execCli(['long-running.cjs', '-T', '1s'], (error, stdout) => {
t.ok(error);
t.match(stdout, /Timed out/);
t.end();
});
});
test('interrupt', {skip: ciInfo.isCI}, t => {
const proc = execCli(['long-running.cjs'], (_, stdout) => {
t.match(stdout, /SIGINT/);
t.end();
});
setTimeout(() => {
proc.kill('SIGINT');
}, 2000);
});
test('include anonymous functions in error reports', t => {
execCli('error-in-anonymous-function.cjs', (error, stdout) => {
t.ok(error);
t.match(stdout, /error-in-anonymous-function\.cjs:4:8/);
t.end();
});
});
test('--match works', t => {
execCli(['-m=foo', '-m=bar', '-m=!baz', '-m=t* a* f*', '-m=!t* a* n* f*', 'matcher-skip.cjs'], error => {
t.error(error);
t.end();
});
});
for (const tapFlag of ['--tap', '-t']) {
test(`${tapFlag} should produce TAP output`, t => {
execCli([tapFlag, 'test.cjs'], {dirname: 'fixture/watcher'}, error => {
t.ok(!error);
t.end();
});
});
}
test('works when no files are found', t => {
execCli([], {dirname: 'fixture/globs/no-files'}, (error, stdout) => {
t.equal(error.code, 1);
t.match(stdout, 'Couldn鈥檛 find any files to test');
t.end();
});
});
test('should warn ava is required without the cli', t => {
childProcess.execFile(process.execPath, [path.resolve(__dirname, '../../entrypoints/main.cjs')], error => {
t.ok(error);
t.match(error.message, /Test files must be run with the AVA CLI/);
t.end();
});
});
test('tests without assertions do not fail if failWithoutAssertions option is set to false', t => {
execCli([], {dirname: 'fixture/pkg-conf/fail-without-assertions'}, error => {
t.error(error);
t.end();
});
});
test('--no-color disables formatting colors', t => {
execCli(['--no-color', 'formatting-color.cjs'], (error, stdout) => {
t.ok(error);
t.equal(stripAnsi(stdout), stdout);
t.end();
});
});
test('--color enables formatting colors', t => {
execCli(['--color', 'formatting-color.cjs'], (error, stdout) => {
t.ok(error);
t.not(stripAnsi(stdout), stdout);
t.end();
});
});
test('sets NODE_ENV to test when it is not set', t => {
execCli('node-env-test.cjs', {env: {}}, (error, stdout) => {
t.error(error);
t.match(stdout, /1 test passed/);
t.end();
});
});
test('doesn鈥檛 set NODE_ENV when it is set', t => {
execCli('node-env-foo.cjs', {env: {NODE_ENV: 'foo'}}, (error, stdout) => {
t.error(error);
t.match(stdout, /1 test passed/);
t.end();
});
});
test('additional arguments are forwarded to the worker', t => {
execCli(['worker-argv.cjs', '--serial', '--', '--hello', 'world'], error => {
t.error(error);
t.end();
});
});
test('reset-cache resets cache', t => {
const cacheDir = path.join(__dirname, '..', 'fixture', 'reset-cache', 'node_modules', '.cache', 'ava');
fs.mkdirSync(cacheDir, {recursive: true});
fs.writeFileSync(path.join(cacheDir, 'file'), '');
t.ok(fs.readdirSync(cacheDir).length > 0);
execCli(['reset-cache'], {dirname: 'fixture/reset-cache'}, error => {
t.error(error);
t.ok(fs.readdirSync(cacheDir).length === 0);
t.end();
});
});
test('selects .cjs test files', t => {
execCli('cjs.cjs', (error, stdout) => {
t.error(error);
t.match(stdout, /1 test passed/);
t.end();
});
});
test('load .mjs test files', t => {
execCli('mjs.mjs', (error, stdout) => {
t.error(error);
t.match(stdout, /1 test passed/);
t.end();
});
});
test('load .js test files as ESM modules', t => {
execCli('test.js', {dirname: 'fixture/pkg-type-module'}, (error, stdout) => {
t.error(error);
t.match(stdout, /1 test passed/);
t.end();
});
});
test('uses sortTestFiles to sort test files', t => {
execCli([], {dirname: 'fixture/sort-tests'}, (error, stdout) => {
t.error(error);
t.match(stdout, /should run first[\s\S]+?should run second[\s\S]+?should run third/);
t.end();
});
});