-
Notifications
You must be signed in to change notification settings - Fork 1
/
run-wdio.ts
60 lines (53 loc) · 1.49 KB
/
run-wdio.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
import {
formatFiles,
generateFiles,
getPackageManagerCommand,
joinPathFragments,
Tree,
workspaceRoot,
} from '@nx/devkit';
import { flushChanges } from 'nx/src/generators/tree';
import { exec } from 'node:child_process';
import { unlink } from 'node:fs/promises';
import type { NormalizedSchema } from '../schema';
export async function runWdio(options: NormalizedSchema) {
const { configPath, spec, suite, watch } = options;
let command = `${getPackageManagerCommand().exec} wdio ${configPath}`;
if (spec) command += ` --spec=${spec}`;
if (suite) command += ` --suite=${suite}`;
if (watch) command += ` --watch`;
await new Promise((resolve, reject) => {
exec(command, {}, (error, stdout, stderr) => {
error ? reject(error) : resolve({ stdout, stderr });
}).stdout.pipe(process.stdout);
if (watch) {
process.on('SIGINT', () => resolve({}));
process.on('SIGTERM', () => resolve({}));
}
});
}
export async function generateWdioConfig(
tree: Tree,
options: NormalizedSchema,
) {
const { projectRoot } = options;
generateFiles(
tree,
joinPathFragments(__dirname, '..', 'files'),
projectRoot,
{
tmpl: '',
options,
},
);
await formatFiles(tree);
flushChanges(workspaceRoot, tree.listChanges());
}
export async function unlinkWdioConfig(options: NormalizedSchema) {
const { configPath, isVerbose } = options;
try {
await unlink(configPath);
} catch (error) {
if (isVerbose) console.error(error);
}
}