-
-
Notifications
You must be signed in to change notification settings - Fork 334
Expand file tree
/
Copy pathexecuteServerCommand.test.ts
More file actions
64 lines (58 loc) · 1.66 KB
/
Copy pathexecuteServerCommand.test.ts
File metadata and controls
64 lines (58 loc) · 1.66 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
import { describe, it } from 'node:test';
import path from 'path';
import { runTests } from '@web/test-runner-core/test-helpers';
import { chromeLauncher } from '@web/test-runner-chrome';
import type { Logger } from '@web/dev-server-core';
describe('executeServerCommand', { timeout: 20000 }, () => {
it('can execute commands', async () => {
const logger: Logger = {
...console,
debug() {
//
},
error(...args) {
if (
typeof args[0] === 'object' &&
typeof (args[0] as any).message === 'string' &&
(args[0] as any).message.includes('error expected to be thrown from command')
) {
return;
}
console.error(...args);
},
logSyntaxError: console.error,
};
await runTests({
files: [path.join(import.meta.dirname, 'browser-test.js')],
logger,
browsers: [chromeLauncher()],
plugins: [
{
name: 'test-a',
async executeCommand({ command, payload }) {
if (command === 'command-a') {
return { foo: 'bar' };
}
if (command === 'command-b') {
return (payload as any).message === 'hello world';
}
if (command === 'command-c') {
return null;
}
if (command === 'command-d') {
throw new Error('error expected to be thrown from command');
}
},
},
{
name: 'test-b',
async executeCommand({ command }) {
if (command === 'command-c') {
return true;
}
},
},
],
});
});
});