-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
e2e.impl.ts
63 lines (54 loc) · 1.62 KB
/
e2e.impl.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
63
import 'dotenv/config';
import type { ExecutorContext } from '@nrwl/devkit';
import {
convertNxExecutor,
logger,
parseTargetString,
readTargetOptions,
runExecutor,
} from '@nrwl/devkit';
import { jestExecutor } from '@nrwl/jest/src/executors/jest/jest.impl';
import type { NxPluginE2EExecutorOptions } from './schema';
export async function* nxPluginE2EExecutor(
options: NxPluginE2EExecutorOptions,
context: ExecutorContext
): AsyncGenerator<{ success: boolean }> {
let success: boolean;
for await (const _ of runBuildTarget(options.target, context)) {
try {
success = await runTests(options.jestConfig, context);
} catch (e) {
logger.error(e.message);
success = false;
}
}
return { success };
}
async function* runBuildTarget(
buildTarget: string,
context: ExecutorContext
): AsyncGenerator<boolean> {
const { project, target, configuration } = parseTargetString(buildTarget);
const buildTargetOptions = readTargetOptions(
{ project, target, configuration },
context
);
const targetSupportsWatch = Object.keys(buildTargetOptions).includes('watch');
for await (const output of await runExecutor<{ success: boolean }>(
{ project, target, configuration },
targetSupportsWatch ? { watch: false } : {},
context
)) {
if (!output.success)
throw new Error('Could not compile application files.');
yield output.success;
}
}
async function runTests(
jestConfig: string,
context: ExecutorContext
): Promise<boolean> {
const { success } = await jestExecutor({ jestConfig, watch: false }, context);
return success;
}
export default nxPluginE2EExecutor;