@ricsam/isolate-test-environment 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +91 -0
- package/dist/cjs/index.cjs +643 -0
- package/dist/cjs/index.cjs.map +10 -0
- package/dist/cjs/package.json +5 -0
- package/{src/index.ts → dist/mjs/index.mjs} +14 -57
- package/dist/mjs/index.mjs.map +10 -0
- package/dist/mjs/package.json +5 -0
- package/dist/types/index.d.ts +41 -0
- package/dist/types/isolate.d.ts +280 -0
- package/package.json +40 -13
- package/CHANGELOG.md +0 -9
- package/src/expect.test.ts +0 -319
- package/src/hooks.test.ts +0 -303
- package/src/integration.test.ts +0 -343
- package/tsconfig.json +0 -8
package/src/expect.test.ts
DELETED
|
@@ -1,319 +0,0 @@
|
|
|
1
|
-
import { test, describe, beforeEach, afterEach } from "node:test";
|
|
2
|
-
import assert from "node:assert";
|
|
3
|
-
import ivm from "isolated-vm";
|
|
4
|
-
import { setupTestEnvironment, runTests } from "./index.ts";
|
|
5
|
-
|
|
6
|
-
describe("expect matchers", () => {
|
|
7
|
-
let isolate: ivm.Isolate;
|
|
8
|
-
let context: ivm.Context;
|
|
9
|
-
|
|
10
|
-
beforeEach(async () => {
|
|
11
|
-
isolate = new ivm.Isolate();
|
|
12
|
-
context = await isolate.createContext();
|
|
13
|
-
await setupTestEnvironment(context);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
afterEach(() => {
|
|
17
|
-
context.release();
|
|
18
|
-
isolate.dispose();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe("toBe", () => {
|
|
22
|
-
test("passes for equal primitives", async () => {
|
|
23
|
-
context.evalSync(`
|
|
24
|
-
test("toBe test", () => {
|
|
25
|
-
expect(1).toBe(1);
|
|
26
|
-
expect("hello").toBe("hello");
|
|
27
|
-
expect(true).toBe(true);
|
|
28
|
-
});
|
|
29
|
-
`);
|
|
30
|
-
const results = await runTests(context);
|
|
31
|
-
assert.strictEqual(results.passed, 1);
|
|
32
|
-
assert.strictEqual(results.failed, 0);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test("fails for different primitives", async () => {
|
|
36
|
-
context.evalSync(`
|
|
37
|
-
test("toBe fails", () => {
|
|
38
|
-
expect(1).toBe(2);
|
|
39
|
-
});
|
|
40
|
-
`);
|
|
41
|
-
const results = await runTests(context);
|
|
42
|
-
assert.strictEqual(results.passed, 0);
|
|
43
|
-
assert.strictEqual(results.failed, 1);
|
|
44
|
-
assert.ok(results.results[0].error?.includes("Expected 1 to be 2"));
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
describe("toEqual", () => {
|
|
49
|
-
test("passes for equal objects", async () => {
|
|
50
|
-
context.evalSync(`
|
|
51
|
-
test("toEqual objects", () => {
|
|
52
|
-
expect({ a: 1, b: 2 }).toEqual({ a: 1, b: 2 });
|
|
53
|
-
expect({ nested: { value: 42 } }).toEqual({ nested: { value: 42 } });
|
|
54
|
-
});
|
|
55
|
-
`);
|
|
56
|
-
const results = await runTests(context);
|
|
57
|
-
assert.strictEqual(results.passed, 1);
|
|
58
|
-
assert.strictEqual(results.failed, 0);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test("passes for equal arrays", async () => {
|
|
62
|
-
context.evalSync(`
|
|
63
|
-
test("toEqual arrays", () => {
|
|
64
|
-
expect([1, 2, 3]).toEqual([1, 2, 3]);
|
|
65
|
-
expect([{ a: 1 }, { b: 2 }]).toEqual([{ a: 1 }, { b: 2 }]);
|
|
66
|
-
});
|
|
67
|
-
`);
|
|
68
|
-
const results = await runTests(context);
|
|
69
|
-
assert.strictEqual(results.passed, 1);
|
|
70
|
-
assert.strictEqual(results.failed, 0);
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
describe("toStrictEqual", () => {
|
|
75
|
-
test("checks for strict equality", async () => {
|
|
76
|
-
context.evalSync(`
|
|
77
|
-
test("toStrictEqual", () => {
|
|
78
|
-
expect({ a: 1 }).toStrictEqual({ a: 1 });
|
|
79
|
-
});
|
|
80
|
-
`);
|
|
81
|
-
const results = await runTests(context);
|
|
82
|
-
assert.strictEqual(results.passed, 1);
|
|
83
|
-
assert.strictEqual(results.failed, 0);
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
describe("not modifier", () => {
|
|
88
|
-
test("not.toBe inverts the check", async () => {
|
|
89
|
-
context.evalSync(`
|
|
90
|
-
test("not.toBe", () => {
|
|
91
|
-
expect(1).not.toBe(2);
|
|
92
|
-
expect("hello").not.toBe("world");
|
|
93
|
-
});
|
|
94
|
-
`);
|
|
95
|
-
const results = await runTests(context);
|
|
96
|
-
assert.strictEqual(results.passed, 1);
|
|
97
|
-
assert.strictEqual(results.failed, 0);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
describe("toBeTruthy", () => {
|
|
102
|
-
test("passes for truthy values", async () => {
|
|
103
|
-
context.evalSync(`
|
|
104
|
-
test("toBeTruthy", () => {
|
|
105
|
-
expect(1).toBeTruthy();
|
|
106
|
-
expect("hello").toBeTruthy();
|
|
107
|
-
expect([]).toBeTruthy();
|
|
108
|
-
expect({}).toBeTruthy();
|
|
109
|
-
});
|
|
110
|
-
`);
|
|
111
|
-
const results = await runTests(context);
|
|
112
|
-
assert.strictEqual(results.passed, 1);
|
|
113
|
-
assert.strictEqual(results.failed, 0);
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
describe("toBeFalsy", () => {
|
|
118
|
-
test("passes for falsy values", async () => {
|
|
119
|
-
context.evalSync(`
|
|
120
|
-
test("toBeFalsy", () => {
|
|
121
|
-
expect(0).toBeFalsy();
|
|
122
|
-
expect("").toBeFalsy();
|
|
123
|
-
expect(null).toBeFalsy();
|
|
124
|
-
expect(undefined).toBeFalsy();
|
|
125
|
-
expect(false).toBeFalsy();
|
|
126
|
-
});
|
|
127
|
-
`);
|
|
128
|
-
const results = await runTests(context);
|
|
129
|
-
assert.strictEqual(results.passed, 1);
|
|
130
|
-
assert.strictEqual(results.failed, 0);
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
describe("toBeNull", () => {
|
|
135
|
-
test("passes for null", async () => {
|
|
136
|
-
context.evalSync(`
|
|
137
|
-
test("toBeNull", () => {
|
|
138
|
-
expect(null).toBeNull();
|
|
139
|
-
});
|
|
140
|
-
`);
|
|
141
|
-
const results = await runTests(context);
|
|
142
|
-
assert.strictEqual(results.passed, 1);
|
|
143
|
-
assert.strictEqual(results.failed, 0);
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
describe("toBeUndefined", () => {
|
|
148
|
-
test("passes for undefined", async () => {
|
|
149
|
-
context.evalSync(`
|
|
150
|
-
test("toBeUndefined", () => {
|
|
151
|
-
expect(undefined).toBeUndefined();
|
|
152
|
-
let x;
|
|
153
|
-
expect(x).toBeUndefined();
|
|
154
|
-
});
|
|
155
|
-
`);
|
|
156
|
-
const results = await runTests(context);
|
|
157
|
-
assert.strictEqual(results.passed, 1);
|
|
158
|
-
assert.strictEqual(results.failed, 0);
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
describe("toBeDefined", () => {
|
|
163
|
-
test("passes for defined values", async () => {
|
|
164
|
-
context.evalSync(`
|
|
165
|
-
test("toBeDefined", () => {
|
|
166
|
-
expect(1).toBeDefined();
|
|
167
|
-
expect("").toBeDefined();
|
|
168
|
-
expect(null).toBeDefined();
|
|
169
|
-
expect(0).toBeDefined();
|
|
170
|
-
});
|
|
171
|
-
`);
|
|
172
|
-
const results = await runTests(context);
|
|
173
|
-
assert.strictEqual(results.passed, 1);
|
|
174
|
-
assert.strictEqual(results.failed, 0);
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
describe("toContain", () => {
|
|
179
|
-
test("passes when array contains item", async () => {
|
|
180
|
-
context.evalSync(`
|
|
181
|
-
test("toContain array", () => {
|
|
182
|
-
expect([1, 2, 3]).toContain(2);
|
|
183
|
-
expect(["a", "b", "c"]).toContain("b");
|
|
184
|
-
});
|
|
185
|
-
`);
|
|
186
|
-
const results = await runTests(context);
|
|
187
|
-
assert.strictEqual(results.passed, 1);
|
|
188
|
-
assert.strictEqual(results.failed, 0);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
test("passes when string contains substring", async () => {
|
|
192
|
-
context.evalSync(`
|
|
193
|
-
test("toContain string", () => {
|
|
194
|
-
expect("hello world").toContain("world");
|
|
195
|
-
expect("abc").toContain("b");
|
|
196
|
-
});
|
|
197
|
-
`);
|
|
198
|
-
const results = await runTests(context);
|
|
199
|
-
assert.strictEqual(results.passed, 1);
|
|
200
|
-
assert.strictEqual(results.failed, 0);
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
describe("toThrow", () => {
|
|
205
|
-
test("passes when function throws", async () => {
|
|
206
|
-
context.evalSync(`
|
|
207
|
-
test("toThrow", () => {
|
|
208
|
-
expect(() => { throw new Error("boom"); }).toThrow();
|
|
209
|
-
});
|
|
210
|
-
`);
|
|
211
|
-
const results = await runTests(context);
|
|
212
|
-
assert.strictEqual(results.passed, 1);
|
|
213
|
-
assert.strictEqual(results.failed, 0);
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
test("can match error message", async () => {
|
|
217
|
-
context.evalSync(`
|
|
218
|
-
test("toThrow with message", () => {
|
|
219
|
-
expect(() => { throw new Error("something went wrong"); }).toThrow("went wrong");
|
|
220
|
-
});
|
|
221
|
-
`);
|
|
222
|
-
const results = await runTests(context);
|
|
223
|
-
assert.strictEqual(results.passed, 1);
|
|
224
|
-
assert.strictEqual(results.failed, 0);
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
describe("toBeInstanceOf", () => {
|
|
229
|
-
test("passes for correct instance", async () => {
|
|
230
|
-
context.evalSync(`
|
|
231
|
-
test("toBeInstanceOf", () => {
|
|
232
|
-
expect(new Error()).toBeInstanceOf(Error);
|
|
233
|
-
expect([]).toBeInstanceOf(Array);
|
|
234
|
-
expect({}).toBeInstanceOf(Object);
|
|
235
|
-
});
|
|
236
|
-
`);
|
|
237
|
-
const results = await runTests(context);
|
|
238
|
-
assert.strictEqual(results.passed, 1);
|
|
239
|
-
assert.strictEqual(results.failed, 0);
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
describe("toHaveLength", () => {
|
|
244
|
-
test("passes for correct array length", async () => {
|
|
245
|
-
context.evalSync(`
|
|
246
|
-
test("toHaveLength array", () => {
|
|
247
|
-
expect([1, 2, 3]).toHaveLength(3);
|
|
248
|
-
expect([]).toHaveLength(0);
|
|
249
|
-
});
|
|
250
|
-
`);
|
|
251
|
-
const results = await runTests(context);
|
|
252
|
-
assert.strictEqual(results.passed, 1);
|
|
253
|
-
assert.strictEqual(results.failed, 0);
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
test("passes for correct string length", async () => {
|
|
257
|
-
context.evalSync(`
|
|
258
|
-
test("toHaveLength string", () => {
|
|
259
|
-
expect("hello").toHaveLength(5);
|
|
260
|
-
expect("").toHaveLength(0);
|
|
261
|
-
});
|
|
262
|
-
`);
|
|
263
|
-
const results = await runTests(context);
|
|
264
|
-
assert.strictEqual(results.passed, 1);
|
|
265
|
-
assert.strictEqual(results.failed, 0);
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
describe("toMatch", () => {
|
|
270
|
-
test("passes for matching regexp", async () => {
|
|
271
|
-
context.evalSync(`
|
|
272
|
-
test("toMatch regexp", () => {
|
|
273
|
-
expect("hello world").toMatch(/world/);
|
|
274
|
-
expect("abc123").toMatch(/\\d+/);
|
|
275
|
-
});
|
|
276
|
-
`);
|
|
277
|
-
const results = await runTests(context);
|
|
278
|
-
assert.strictEqual(results.passed, 1);
|
|
279
|
-
assert.strictEqual(results.failed, 0);
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
test("passes for matching substring", async () => {
|
|
283
|
-
context.evalSync(`
|
|
284
|
-
test("toMatch substring", () => {
|
|
285
|
-
expect("hello world").toMatch("world");
|
|
286
|
-
});
|
|
287
|
-
`);
|
|
288
|
-
const results = await runTests(context);
|
|
289
|
-
assert.strictEqual(results.passed, 1);
|
|
290
|
-
assert.strictEqual(results.failed, 0);
|
|
291
|
-
});
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
describe("toHaveProperty", () => {
|
|
295
|
-
test("passes when property exists", async () => {
|
|
296
|
-
context.evalSync(`
|
|
297
|
-
test("toHaveProperty exists", () => {
|
|
298
|
-
expect({ a: 1 }).toHaveProperty("a");
|
|
299
|
-
expect({ nested: { value: 42 } }).toHaveProperty("nested.value");
|
|
300
|
-
});
|
|
301
|
-
`);
|
|
302
|
-
const results = await runTests(context);
|
|
303
|
-
assert.strictEqual(results.passed, 1);
|
|
304
|
-
assert.strictEqual(results.failed, 0);
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
test("passes when property has expected value", async () => {
|
|
308
|
-
context.evalSync(`
|
|
309
|
-
test("toHaveProperty with value", () => {
|
|
310
|
-
expect({ a: 1 }).toHaveProperty("a", 1);
|
|
311
|
-
expect({ nested: { value: 42 } }).toHaveProperty("nested.value", 42);
|
|
312
|
-
});
|
|
313
|
-
`);
|
|
314
|
-
const results = await runTests(context);
|
|
315
|
-
assert.strictEqual(results.passed, 1);
|
|
316
|
-
assert.strictEqual(results.failed, 0);
|
|
317
|
-
});
|
|
318
|
-
});
|
|
319
|
-
});
|
package/src/hooks.test.ts
DELETED
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
import { test, describe, beforeEach, afterEach } from "node:test";
|
|
2
|
-
import assert from "node:assert";
|
|
3
|
-
import ivm from "isolated-vm";
|
|
4
|
-
import { setupTestEnvironment, runTests } from "./index.ts";
|
|
5
|
-
|
|
6
|
-
describe("test hooks", () => {
|
|
7
|
-
let isolate: ivm.Isolate;
|
|
8
|
-
let context: ivm.Context;
|
|
9
|
-
|
|
10
|
-
beforeEach(async () => {
|
|
11
|
-
isolate = new ivm.Isolate();
|
|
12
|
-
context = await isolate.createContext();
|
|
13
|
-
await setupTestEnvironment(context);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
afterEach(() => {
|
|
17
|
-
context.release();
|
|
18
|
-
isolate.dispose();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe("beforeEach", () => {
|
|
22
|
-
test("runs before each test", async () => {
|
|
23
|
-
context.evalSync(`
|
|
24
|
-
let counter = 0;
|
|
25
|
-
|
|
26
|
-
describe("suite", () => {
|
|
27
|
-
beforeEach(() => {
|
|
28
|
-
counter++;
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test("first test", () => {
|
|
32
|
-
expect(counter).toBe(1);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test("second test", () => {
|
|
36
|
-
expect(counter).toBe(2);
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
`);
|
|
40
|
-
const results = await runTests(context);
|
|
41
|
-
assert.strictEqual(results.passed, 2);
|
|
42
|
-
assert.strictEqual(results.failed, 0);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
describe("afterEach", () => {
|
|
47
|
-
test("runs after each test", async () => {
|
|
48
|
-
context.evalSync(`
|
|
49
|
-
let log = [];
|
|
50
|
-
|
|
51
|
-
describe("suite", () => {
|
|
52
|
-
afterEach(() => {
|
|
53
|
-
log.push("afterEach");
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test("first test", () => {
|
|
57
|
-
log.push("test1");
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test("second test", () => {
|
|
61
|
-
log.push("test2");
|
|
62
|
-
expect(log).toEqual(["test1", "afterEach", "test2"]);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
`);
|
|
66
|
-
const results = await runTests(context);
|
|
67
|
-
assert.strictEqual(results.passed, 2);
|
|
68
|
-
assert.strictEqual(results.failed, 0);
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe("beforeAll", () => {
|
|
73
|
-
test("runs once before all tests", async () => {
|
|
74
|
-
context.evalSync(`
|
|
75
|
-
let setupCount = 0;
|
|
76
|
-
|
|
77
|
-
describe("suite", () => {
|
|
78
|
-
beforeAll(() => {
|
|
79
|
-
setupCount++;
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test("first test", () => {
|
|
83
|
-
expect(setupCount).toBe(1);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test("second test", () => {
|
|
87
|
-
expect(setupCount).toBe(1);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
test("third test", () => {
|
|
91
|
-
expect(setupCount).toBe(1);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
`);
|
|
95
|
-
const results = await runTests(context);
|
|
96
|
-
assert.strictEqual(results.passed, 3);
|
|
97
|
-
assert.strictEqual(results.failed, 0);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
describe("afterAll", () => {
|
|
102
|
-
test("runs once after all tests", async () => {
|
|
103
|
-
context.evalSync(`
|
|
104
|
-
let log = [];
|
|
105
|
-
|
|
106
|
-
describe("suite", () => {
|
|
107
|
-
afterAll(() => {
|
|
108
|
-
log.push("afterAll");
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
test("first test", () => {
|
|
112
|
-
log.push("test1");
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
test("second test", () => {
|
|
116
|
-
log.push("test2");
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
// We can check in a sibling suite that afterAll ran
|
|
121
|
-
describe("verification", () => {
|
|
122
|
-
test("afterAll was called", () => {
|
|
123
|
-
expect(log).toEqual(["test1", "test2", "afterAll"]);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
`);
|
|
127
|
-
const results = await runTests(context);
|
|
128
|
-
assert.strictEqual(results.passed, 3);
|
|
129
|
-
assert.strictEqual(results.failed, 0);
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
describe("nested describe", () => {
|
|
134
|
-
test("hooks run in correct order", async () => {
|
|
135
|
-
context.evalSync(`
|
|
136
|
-
let log = [];
|
|
137
|
-
|
|
138
|
-
describe("outer", () => {
|
|
139
|
-
beforeAll(() => log.push("outer beforeAll"));
|
|
140
|
-
afterAll(() => log.push("outer afterAll"));
|
|
141
|
-
beforeEach(() => log.push("outer beforeEach"));
|
|
142
|
-
afterEach(() => log.push("outer afterEach"));
|
|
143
|
-
|
|
144
|
-
describe("inner", () => {
|
|
145
|
-
beforeAll(() => log.push("inner beforeAll"));
|
|
146
|
-
afterAll(() => log.push("inner afterAll"));
|
|
147
|
-
beforeEach(() => log.push("inner beforeEach"));
|
|
148
|
-
afterEach(() => log.push("inner afterEach"));
|
|
149
|
-
|
|
150
|
-
test("nested test", () => {
|
|
151
|
-
log.push("test");
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
describe("check results", () => {
|
|
157
|
-
test("hooks ran in correct order", () => {
|
|
158
|
-
expect(log).toEqual([
|
|
159
|
-
"outer beforeAll",
|
|
160
|
-
"inner beforeAll",
|
|
161
|
-
"outer beforeEach",
|
|
162
|
-
"inner beforeEach",
|
|
163
|
-
"test",
|
|
164
|
-
"inner afterEach",
|
|
165
|
-
"outer afterEach",
|
|
166
|
-
"inner afterAll",
|
|
167
|
-
"outer afterAll"
|
|
168
|
-
]);
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
`);
|
|
172
|
-
const results = await runTests(context);
|
|
173
|
-
assert.strictEqual(results.passed, 2);
|
|
174
|
-
assert.strictEqual(results.failed, 0);
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
describe("test.skip", () => {
|
|
179
|
-
test("skips tests marked with skip", async () => {
|
|
180
|
-
context.evalSync(`
|
|
181
|
-
describe("suite", () => {
|
|
182
|
-
test("normal test", () => {
|
|
183
|
-
expect(true).toBe(true);
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
test.skip("skipped test", () => {
|
|
187
|
-
expect(true).toBe(false); // This would fail if run
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
`);
|
|
191
|
-
const results = await runTests(context);
|
|
192
|
-
assert.strictEqual(results.passed, 1);
|
|
193
|
-
assert.strictEqual(results.failed, 0);
|
|
194
|
-
assert.strictEqual(results.results.filter((r: any) => r.skipped).length, 1);
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
describe("test.only", () => {
|
|
199
|
-
test("runs only tests marked with only", async () => {
|
|
200
|
-
context.evalSync(`
|
|
201
|
-
describe("suite", () => {
|
|
202
|
-
test("should not run", () => {
|
|
203
|
-
expect(true).toBe(false); // Would fail if run
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
test.only("should run", () => {
|
|
207
|
-
expect(true).toBe(true);
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
test("also should not run", () => {
|
|
211
|
-
expect(true).toBe(false); // Would fail if run
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
`);
|
|
215
|
-
const results = await runTests(context);
|
|
216
|
-
assert.strictEqual(results.passed, 1);
|
|
217
|
-
assert.strictEqual(results.failed, 0);
|
|
218
|
-
assert.strictEqual(results.total, 1);
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
describe("describe.skip", () => {
|
|
223
|
-
test("skips all tests in skipped describe", async () => {
|
|
224
|
-
context.evalSync(`
|
|
225
|
-
describe.skip("skipped suite", () => {
|
|
226
|
-
test("test 1", () => {
|
|
227
|
-
expect(true).toBe(false);
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
test("test 2", () => {
|
|
231
|
-
expect(true).toBe(false);
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
describe("normal suite", () => {
|
|
236
|
-
test("normal test", () => {
|
|
237
|
-
expect(true).toBe(true);
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
`);
|
|
241
|
-
const results = await runTests(context);
|
|
242
|
-
assert.strictEqual(results.passed, 1);
|
|
243
|
-
assert.strictEqual(results.failed, 0);
|
|
244
|
-
assert.strictEqual(results.results.filter((r: any) => r.skipped).length, 2);
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
describe("async tests", () => {
|
|
249
|
-
test("supports async test functions", async () => {
|
|
250
|
-
context.evalSync(`
|
|
251
|
-
describe("async suite", () => {
|
|
252
|
-
test("async test", async () => {
|
|
253
|
-
await Promise.resolve();
|
|
254
|
-
expect(1 + 1).toBe(2);
|
|
255
|
-
});
|
|
256
|
-
});
|
|
257
|
-
`);
|
|
258
|
-
const results = await runTests(context);
|
|
259
|
-
assert.strictEqual(results.passed, 1);
|
|
260
|
-
assert.strictEqual(results.failed, 0);
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
test("supports async hooks", async () => {
|
|
264
|
-
context.evalSync(`
|
|
265
|
-
let value = 0;
|
|
266
|
-
|
|
267
|
-
describe("async hooks", () => {
|
|
268
|
-
beforeEach(async () => {
|
|
269
|
-
await Promise.resolve();
|
|
270
|
-
value = 42;
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
test("value is set", () => {
|
|
274
|
-
expect(value).toBe(42);
|
|
275
|
-
});
|
|
276
|
-
});
|
|
277
|
-
`);
|
|
278
|
-
const results = await runTests(context);
|
|
279
|
-
assert.strictEqual(results.passed, 1);
|
|
280
|
-
assert.strictEqual(results.failed, 0);
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
describe("it alias", () => {
|
|
285
|
-
test("it works as alias for test", async () => {
|
|
286
|
-
context.evalSync(`
|
|
287
|
-
describe("suite", () => {
|
|
288
|
-
it("uses it instead of test", () => {
|
|
289
|
-
expect(1).toBe(1);
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
it.skip("skipped with it", () => {
|
|
293
|
-
expect(true).toBe(false);
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
`);
|
|
297
|
-
const results = await runTests(context);
|
|
298
|
-
assert.strictEqual(results.passed, 1);
|
|
299
|
-
assert.strictEqual(results.failed, 0);
|
|
300
|
-
assert.strictEqual(results.results.filter((r: any) => r.skipped).length, 1);
|
|
301
|
-
});
|
|
302
|
-
});
|
|
303
|
-
});
|