-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
cli.test.js
139 lines (119 loc) · 3.51 KB
/
cli.test.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
import { test } from 'node:test'
import { execa } from 'execa'
import { join } from 'desm'
import { rejects, strictEqual } from 'node:assert'
import { rm } from 'node:fs/promises'
import path from 'node:path'
const borp = join(import.meta.url, '..', 'borp.js')
delete process.env.GITHUB_ACTION
test('limit concurrency', async () => {
await execa('node', [
borp,
'--concurrency',
'1'
], {
cwd: join(import.meta.url, '..', 'fixtures', 'ts-esm')
})
})
test('failing test set correct status code', async () => {
// execa rejects if status code is not 0
await rejects(execa('node', [
borp
], {
cwd: join(import.meta.url, '..', 'fixtures', 'fails')
}))
})
test('--expose-gc flag enables garbage collection in tests', async () => {
await execa('node', [
borp,
'--expose-gc'
], {
cwd: join(import.meta.url, '..', 'fixtures', 'gc')
})
})
test('failing test with --expose-gc flag sets correct status code', async () => {
// execa rejects if status code is not 0
await rejects(execa('node', [
borp,
'--expose-gc'
], {
cwd: join(import.meta.url, '..', 'fixtures', 'fails')
}))
})
test('disable ts and run no tests', async () => {
const cwd = join(import.meta.url, '..', 'fixtures', 'ts-esm2')
await rm(path.join(cwd, 'dist'), { recursive: true, force: true })
const { stdout } = await execa('node', [
borp,
'--reporter=spec',
'--no-typescript'
], {
cwd
})
strictEqual(stdout.indexOf('tests 0') >= 0, true)
})
test('reporter from node_modules', async () => {
const cwd = join(import.meta.url, '..', 'fixtures', 'ts-esm')
const { stdout } = await execa('node', [
borp,
'--reporter=spec',
'--reporter=@reporters/silent'
], {
cwd
})
strictEqual(stdout.indexOf('tests 2') >= 0, true)
})
test('reporter from relative path', async () => {
const cwd = join(import.meta.url, '..', 'fixtures', 'relative-reporter')
const { stdout } = await execa('node', [
borp,
'--reporter=./fixtures/relative-reporter/reporter.js'
], {
cwd
})
strictEqual(/passed:.+add\.test\.js/.test(stdout), true)
strictEqual(/passed:.+add2\.test\.js/.test(stdout), true)
})
test('gh reporter', async () => {
const cwd = join(import.meta.url, '..', 'fixtures', 'js-esm')
const { stdout } = await execa('node', [
borp,
'--reporter=gh'
], {
cwd,
env: {
GITHUB_ACTIONS: '1'
}
})
strictEqual(stdout.indexOf('::notice') >= 0, true)
})
test('interprets globs for files', async () => {
const cwd = join(import.meta.url, '..', 'fixtures', 'files-glob')
const { stdout } = await execa('node', [
borp,
'\'test1/*.test.js\'',
'\'test2/**/*.test.js\''
], {
cwd
})
strictEqual(stdout.indexOf('tests 2') >= 0, true)
})
test('Post compile script should be executed when --post-compile is sent with esm', async () => {
const cwd = join(import.meta.url, '..', 'fixtures', 'ts-esm-post-compile')
const { stdout } = await execa('node', [
borp,
'--post-compile=postCompile.ts'
], {
cwd
})
strictEqual(stdout.indexOf('Post compile hook complete') >= 0, true, 'Post compile message should be found in stdout')
})
test('Post compile script should be executed when --post-compile is sent with cjs', async () => {
const { stdout } = await execa('node', [
borp,
'--post-compile=postCompile.ts'
], {
cwd: join(import.meta.url, '..', 'fixtures', 'ts-cjs-post-compile')
})
strictEqual(stdout.indexOf('Post compile hook complete') >= 0, true, 'Post compile message should be found in stdout')
})