-
-
Notifications
You must be signed in to change notification settings - Fork 332
Expand file tree
/
Copy pathrunBasicTest.ts
More file actions
94 lines (87 loc) · 3.44 KB
/
runBasicTest.ts
File metadata and controls
94 lines (87 loc) · 3.44 KB
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
import { describe, it, before } from 'node:test';
const __dirname = import.meta.dirname;
import type { BrowserLauncher, TestRunnerCoreConfig, TestSession } from '@web/test-runner-core';
import { runTests } from '@web/test-runner-core/test-helpers';
import { legacyPlugin } from '@web/dev-server-legacy';
import { resolve } from 'path';
import { expect } from 'chai';
export function runBasicTest(
config: Partial<TestRunnerCoreConfig> & { browsers: BrowserLauncher[] },
) {
describe('basic', async function () {
const browserCount = config.browsers.length;
let allSessions: TestSession[];
before(async () => {
const result = await runTests({
...config,
files: [...(config.files ?? []), resolve(__dirname, 'browser-tests', '*.test.js')],
plugins: [...(config.plugins ?? []), legacyPlugin()],
});
allSessions = result.sessions;
expect(allSessions.every(s => s.passed)).to.equal(true, 'All sessions should have passed');
});
it('passes basic test', () => {
const sessions = allSessions.filter(s => s.testFile.endsWith('basic.test.js'));
expect(sessions.length === browserCount).to.equal(
true,
'Each browser should run basic.test.js',
);
for (const session of sessions) {
expect(session.testResults!.tests.length).to.equal(0);
expect(session.testResults!.suites.length).to.equal(1);
expect(session.testResults!.suites[0].tests.length).to.equal(1);
expect(session.testResults!.suites[0].tests.map(t => t.name)).to.eql(['works']);
}
});
it('passes js-syntax test', () => {
const sessions = allSessions.filter(s => s.testFile.endsWith('js-syntax.test.js'));
expect(sessions.length === browserCount).to.equal(
true,
'Each browser should run js-syntax.test.js',
);
for (const session of sessions) {
expect(session.testResults!.tests.map(t => t.name)).to.eql([
'supports object spread',
'supports async functions',
'supports exponentiation',
'supports classes',
'supports template literals',
'supports optional chaining',
'supports nullish coalescing',
]);
}
});
it('passes module-features test', () => {
const sessions = allSessions.filter(s => s.testFile.endsWith('module-features.test.js'));
expect(sessions.length === browserCount).to.equal(
true,
'Each browser should run module-features.test.js',
);
for (const session of sessions) {
expect(session.testResults!.tests.map(t => t.name)).to.eql([
'supports static imports',
'supports dynamic imports',
'supports import meta',
]);
}
});
it('passes timers test', () => {
const sessions = allSessions.filter(s => s.testFile.endsWith('timers.test.js'));
expect(sessions.length === browserCount).to.equal(
true,
'Each browser should run timers.test.js',
);
for (const session of sessions) {
expect(session.testResults!.tests.length).to.equal(0);
expect(session.testResults!.suites.length).to.equal(1);
expect(session.testResults!.suites[0].tests.map(t => t.name)).to.eql([
'can call setTimeout',
'can cancel setTimeout',
'can call and cancel setInterval',
'can call requestAnimationFrame',
'can cancel requestAnimationFrame',
]);
}
});
});
}