-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathplaywright.ts
62 lines (49 loc) · 1.28 KB
/
playwright.ts
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
import type * as P from '@playwright/test/reporter';
import { options } from './adapter-options';
import { buildCommand } from './build-command';
import { emitError } from './helpers';
import { logger } from './logging';
export const get_config = () => {
const cmd = buildCommand(
{
bin: options.get_playwright_binary(),
config: options.get_playwright_config(),
reporters: ['json'],
},
['--list'],
);
// apply any custom environment variables when resolving the config
cmd.unshift(
Object.entries(options.env)
.map(([key, value]) => `${key}=${value}`)
.join(' '),
);
const output = run(cmd.join(' '));
if (!output) {
throw new Error('Failed to get Playwright config');
}
return output;
};
/** Returns the playwright config */
const run = (cmd: string) => {
const [handle, errmsg] = io.popen(cmd);
if (typeof errmsg === 'string') {
logger('error', errmsg);
}
if (!handle) {
emitError(`Failed to execute command: ${cmd}`);
return;
}
const output = handle.read('*a');
handle.close();
if (typeof output !== 'string') {
emitError(`Failed to read output from command: ${cmd}`);
return;
}
if (output === '') {
emitError(`No output from command: ${cmd}`);
return;
}
const decoded = vim.fn.json_decode(output) as P.JSONReport;
return decoded;
};