forked from mochajs/mocha
/
require.spec.js
166 lines (158 loc) · 6.39 KB
/
require.spec.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
163
164
165
166
'use strict';
var invokeMochaAsync = require('../helpers').invokeMochaAsync;
var utils = require('../../../lib/utils');
describe('--require', function() {
describe('when mocha run in serial mode', function() {
it('should run root hooks when provided via mochaHooks object export', function() {
return expect(
invokeMochaAsync([
'--require=' +
require.resolve(
'../fixtures/options/require/root-hook-defs-a.fixture.js'
),
'--require=' +
require.resolve(
'../fixtures/options/require/root-hook-defs-b.fixture.js'
),
require.resolve(
'../fixtures/options/require/root-hook-test.fixture.js'
)
])[1],
'when fulfilled',
'to contain output',
/beforeAll[\s\S]+?beforeAll array 1[\s\S]+?beforeAll array 2[\s\S]+?beforeEach[\s\S]+?beforeEach array 1[\s\S]+?beforeEach array 2[\s\S]+?afterEach[\s\S]+?afterEach array 1[\s\S]+?afterEach array 2[\s\S]+?afterAll[\s\S]+?afterAll array 1[\s\S]+?afterAll array 2/
);
});
it('should run root hooks when provided via mochaHooks function export', function() {
return expect(
invokeMochaAsync([
'--require=' +
require.resolve(
'../fixtures/options/require/root-hook-defs-c.fixture.js'
),
'--require=' +
require.resolve(
'../fixtures/options/require/root-hook-defs-d.fixture.js'
),
require.resolve(
'../fixtures/options/require/root-hook-test.fixture.js'
)
])[1],
'when fulfilled',
'to contain output',
/beforeAll[\s\S]+?beforeAll array 1[\s\S]+?beforeAll array 2[\s\S]+?beforeEach[\s\S]+?beforeEach array 1[\s\S]+?beforeEach array 2[\s\S]+?afterEach[\s\S]+?afterEach array 1[\s\S]+?afterEach array 2[\s\S]+?afterAll[\s\S]+?afterAll array 1[\s\S]+?afterAll array 2/
);
});
describe('support ESM when style=module or .mjs extension', function() {
before(function() {
if (!utils.supportsEsModules()) this.skip();
});
it('should run root hooks when provided via mochaHooks', function() {
return expect(
invokeMochaAsync(
[
'--require=' +
require.resolve(
// as object
'../fixtures/options/require/root-hook-defs-esm.fixture.mjs'
),
'--require=' +
require.resolve(
// as function
'../fixtures/options/require/esm/root-hook-defs-esm.fixture.js'
),
'--require=' +
require.resolve(
// mixed with commonjs
'../fixtures/options/require/root-hook-defs-a.fixture.js'
),
require.resolve(
'../fixtures/options/require/root-hook-test.fixture.js'
)
].concat(
+process.versions.node.split('.')[0] >= 13
? []
: '--experimental-modules'
)
)[1],
'when fulfilled',
'to contain output',
/mjs beforeAll[\s\S]+?beforeAll[\s\S]+?esm beforeEach[\s\S]+?beforeEach[\s\S]+?esm afterEach[\s\S]+?afterEach[\s\S]+?mjs afterAll[\s\S]+?afterAll/
);
});
});
});
describe('when mocha in parallel mode', function() {
before(function() {
this.skip(); // TODO: remove when #4245 lands
});
it('should run root hooks when provided via mochaHooks object exports', function() {
return expect(
invokeMochaAsync([
'--require=' +
require.resolve(
'../fixtures/options/require/root-hook-defs-a.fixture.js'
),
'--require=' +
require.resolve(
'../fixtures/options/require/root-hook-defs-b.fixture.js'
),
'--parallel',
require.resolve(
'../fixtures/options/require/root-hook-test.fixture.js'
)
])[1],
'when fulfilled',
'to contain output',
/beforeAll[\s\S]+?beforeAll array 1[\s\S]+?beforeAll array 2[\s\S]+?beforeEach[\s\S]+?beforeEach array 1[\s\S]+?beforeEach array 2[\s\S]+?afterEach[\s\S]+?afterEach array 1[\s\S]+?afterEach array 2[\s\S]+?afterAll[\s\S]+?afterAll array 1[\s\S]+?afterAll array 2/
);
});
it('should run root hooks when provided via mochaHooks function export', function() {
return expect(
invokeMochaAsync([
'--require=' +
require.resolve(
'../fixtures/options/require/root-hook-defs-c.fixture.js'
),
'--require=' +
require.resolve(
'../fixtures/options/require/root-hook-defs-d.fixture.js'
),
'--parallel',
require.resolve(
'../fixtures/options/require/root-hook-test.fixture.js'
)
])[1],
'when fulfilled',
'to contain output',
/beforeAll[\s\S]+?beforeAll array 1[\s\S]+?beforeAll array 2[\s\S]+?beforeEach[\s\S]+?beforeEach array 1[\s\S]+?beforeEach array 2[\s\S]+?afterEach[\s\S]+?afterEach array 1[\s\S]+?afterEach array 2[\s\S]+?afterAll[\s\S]+?afterAll array 1[\s\S]+?afterAll array 2/
);
});
describe('when running multiple jobs', function() {
it('should run root hooks when provided via mochaHooks object exports for each job', function() {
return expect(
invokeMochaAsync([
'--require=' +
require.resolve(
'../fixtures/options/require/root-hook-defs-a.fixture.js'
),
'--require=' +
require.resolve(
'../fixtures/options/require/root-hook-defs-b.fixture.js'
),
'--parallel',
require.resolve(
'../fixtures/options/require/root-hook-test.fixture.js'
),
require.resolve(
'../fixtures/options/require/root-hook-test-2.fixture.js'
)
])[1],
'when fulfilled',
'to contain output',
/(?:beforeAll[\s\S]+?beforeAll array 1[\s\S]+?beforeAll array 2[\s\S]+?beforeEach[\s\S]+?beforeEach array 1[\s\S]+?beforeEach array 2[\s\S]+?afterEach[\s\S]+?afterEach array 1[\s\S]+?afterEach array 2[\s\S]+?afterAll[\s\S]+?afterAll array 1[\s\S]+?afterAll array 2[\s\S]+?){2}/
);
});
});
});
});