Skip to content

Commit 3b88796

Browse files
feat(qwik-nx): use @nrwl/vite:preview-server executor (#87)
* feat: use [email protected] * fix(qwik-nx): do not yield intermediate build results * feat(qwik-nx): use @nrwl/vite:preview-server executor * test: add snapshot for app generator unit test
1 parent f35f973 commit 3b88796

File tree

12 files changed

+676
-216
lines changed

12 files changed

+676
-216
lines changed

e2e/qwik-nx-e2e/tests/chore.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,18 @@ describe('appGenerator e2e', () => {
3030
});
3131

3232
describe("qwik-nx's compiled package.json", () => {
33-
let project: string;
34-
3533
it("qwik-nx's package.json should contain only expected dependencies", async () => {
3634
const packageJson = readJson('node_modules/qwik-nx/package.json');
3735

3836
expect(packageJson.dependencies).toBeUndefined();
3937
expect(packageJson.peerDependencies).toEqual({
40-
'@nrwl/vite': '~15.6.0',
38+
'@nrwl/vite': '~15.7.2',
4139
'@builder.io/qwik': '^0.17.0',
4240
'@playwright/test': '^1.30.0',
4341
undici: '^5.18.0',
4442
vite: '^4.0.0',
4543
vitest: '^0.25.0',
46-
tslib: '2.4.1',
44+
tslib: '^2.3.0',
4745
});
4846
}, 200000);
4947
});

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818
"@commitlint/config-angular": "^17.3.0",
1919
"@commitlint/config-conventional": "^17.3.0",
2020
"@jscutlery/semver": "^2.29.0",
21-
"@nrwl/cli": "15.6.1",
22-
"@nrwl/cypress": "15.6.1",
23-
"@nrwl/devkit": "15.6.1",
24-
"@nrwl/eslint-plugin-nx": "15.6.1",
25-
"@nrwl/jest": "15.6.1",
26-
"@nrwl/js": "15.6.1",
27-
"@nrwl/linter": "15.6.1",
28-
"@nrwl/nx-plugin": "15.6.1",
29-
"@nrwl/vite": "15.6.1",
30-
"@nrwl/workspace": "15.6.1",
21+
"@nrwl/cli": "15.7.2",
22+
"@nrwl/cypress": "15.7.2",
23+
"@nrwl/devkit": "15.7.2",
24+
"@nrwl/eslint-plugin-nx": "15.7.2",
25+
"@nrwl/jest": "15.7.2",
26+
"@nrwl/js": "15.7.2",
27+
"@nrwl/linter": "15.7.2",
28+
"@nrwl/nx-plugin": "15.7.2",
29+
"@nrwl/vite": "15.7.2",
30+
"@nrwl/workspace": "15.7.2",
3131
"@nxkit/playwright": "^2.1.1",
3232
"@swc-node/register": "^1.4.2",
3333
"@swc/cli": "~0.1.55",
@@ -54,7 +54,7 @@
5454
"jsonc-eslint-parser": "^2.1.0",
5555
"kill-port": "2.0.1",
5656
"ngx-deploy-npm": "^5.2.0",
57-
"nx": "15.6.1",
57+
"nx": "15.7.2",
5858
"prettier": "^2.8.0",
5959
"pretty-quick": "^3.1.3",
6060
"tcp-port-used": "1.0.2",

packages/qwik-nx/executors.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"build": {
55
"implementation": "./src/executors/build/executor",
66
"schema": "./src/executors/build/schema.json",
7-
"description": "build executor"
7+
"description": "Build a Qwik application."
88
}
99
}
1010
}

packages/qwik-nx/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"generators": "./generators.json",
2323
"executors": "./executors.json",
2424
"peerDependencies": {
25-
"@nrwl/vite": "~15.6.0",
25+
"@nrwl/vite": "~15.7.2",
2626
"@builder.io/qwik": "^0.17.0",
2727
"vite": "^4.0.0",
2828
"vitest": "^0.25.0",

packages/qwik-nx/src/executors/build/executor.spec.ts

Lines changed: 89 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,39 @@ import { ExecutorContext, runExecutor, Target } from '@nrwl/devkit';
55
// eslint-disable-next-line @typescript-eslint/no-var-requires
66
const devkit: { runExecutor: typeof runExecutor } = require('@nrwl/devkit');
77

8+
enum MockFailTargets {
9+
NoSuccess = 'mock-no-success',
10+
Error = 'mock-error',
11+
}
12+
813
describe('Build Executor', () => {
914
let runExecutorPayloads: Target[] = [];
1015

11-
jest.spyOn(devkit, 'runExecutor').mockImplementation((target: Target) =>
12-
Promise.resolve(
13-
(async function* () {
14-
runExecutorPayloads.push(target);
15-
yield { success: true, target }; // yielding target for debugging purposes
16-
})()
17-
)
18-
);
16+
jest.spyOn(devkit, 'runExecutor').mockImplementation((target: Target) => {
17+
if (target.target === MockFailTargets.NoSuccess) {
18+
return Promise.resolve(
19+
(async function* () {
20+
runExecutorPayloads.push(target);
21+
yield { success: false, target }; // yielding target for debugging purposes
22+
})()
23+
);
24+
} else if (target.target === MockFailTargets.Error) {
25+
return Promise.resolve(
26+
// eslint-disable-next-line require-yield
27+
(async function* () {
28+
runExecutorPayloads.push(target);
29+
throw new Error('Something went wrong');
30+
})()
31+
);
32+
} else {
33+
return Promise.resolve(
34+
(async function* () {
35+
runExecutorPayloads.push(target);
36+
yield { success: true, target }; // yielding target for debugging purposes
37+
})()
38+
);
39+
}
40+
});
1941

2042
afterEach(() => {
2143
runExecutorPayloads = [];
@@ -33,18 +55,69 @@ describe('Build Executor', () => {
3355
runSequence: ['my-app:target1:development', 'my-app:target2'],
3456
};
3557
const iterable = executor(options, context);
36-
await iterable.next();
37-
expect(runExecutorPayloads.map((p) => p.target)).toEqual(['target1']);
38-
await iterable.next();
39-
expect(runExecutorPayloads.map((p) => p.target)).toEqual([
40-
'target1',
41-
'target2',
42-
]);
43-
const result = await iterable.next();
58+
let result = await iterable.next();
59+
expect(result.value?.success).toEqual(true);
4460
expect(runExecutorPayloads).toEqual([
4561
{ project: 'my-app', target: 'target1', configuration: 'development' },
4662
{ project: 'my-app', target: 'target2', configuration: 'production' },
4763
]);
64+
result = await iterable.next();
65+
expect(result.done).toEqual(true);
66+
});
67+
68+
it('should stop execution if executor returned "success: false"', async () => {
69+
const context = {
70+
root: '/root',
71+
projectName: 'my-app',
72+
targetName: 'build',
73+
configurationName: 'production',
74+
} as ExecutorContext;
75+
76+
const target = MockFailTargets.NoSuccess;
77+
78+
const options: BuildExecutorSchema = {
79+
runSequence: [
80+
'my-app:target1:development',
81+
`my-app:${target}`,
82+
'my-app:target2',
83+
],
84+
};
85+
const iterable = executor(options, context);
86+
let result = await iterable.next();
87+
expect(result.value?.success).toEqual(false);
88+
expect(runExecutorPayloads).toEqual([
89+
{ project: 'my-app', target: 'target1', configuration: 'development' },
90+
{ project: 'my-app', target: target, configuration: 'production' },
91+
]);
92+
result = await iterable.next();
93+
expect(result.done).toEqual(true);
94+
});
95+
96+
it('should stop execution if unhandled error occurs', async () => {
97+
const context = {
98+
root: '/root',
99+
projectName: 'my-app',
100+
targetName: 'build',
101+
configurationName: 'production',
102+
} as ExecutorContext;
103+
104+
const target = MockFailTargets.Error;
105+
106+
const options: BuildExecutorSchema = {
107+
runSequence: [
108+
'my-app:target1:development',
109+
`my-app:${target}`,
110+
'my-app:target2',
111+
],
112+
};
113+
const iterable = executor(options, context);
114+
let result = await iterable.next();
115+
expect(result.value?.success).toEqual(false);
116+
expect(runExecutorPayloads).toEqual([
117+
{ project: 'my-app', target: 'target1', configuration: 'development' },
118+
{ project: 'my-app', target: target, configuration: 'production' },
119+
]);
120+
result = await iterable.next();
48121
expect(result.done).toEqual(true);
49122
});
50123
});

packages/qwik-nx/src/executors/build/executor.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,21 @@ export default async function* runBuildExecutor(
2727
});
2828

2929
for (const target of configs) {
30-
const step = await runExecutor(target, {}, context);
30+
try {
31+
const step = await runExecutor(target, {}, context);
3132

32-
for await (const result of step) {
33-
if (!result.success) {
34-
return result;
33+
for await (const result of step) {
34+
if (!result.success) {
35+
yield { success: false };
36+
return;
37+
}
3538
}
36-
yield {
37-
success: true,
38-
};
39+
} catch (error) {
40+
console.error(error);
41+
yield { success: false };
42+
return;
3943
}
4044
}
45+
46+
yield { success: true };
4147
}

packages/qwik-nx/src/executors/build/schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"$schema": "http://json-schema.org/schema",
33
"version": 2,
44
"cli": "nx",
5-
"title": "Build executor",
6-
"description": "",
5+
"title": "Qwik Build",
6+
"description": "Builds a Qwik application for production.",
77
"type": "object",
88
"properties": {
99
"runSequence": {

0 commit comments

Comments
 (0)