Skip to content

Commit d632c7c

Browse files
feat(qwik-nx): build executor migration and test coverage
1 parent 5784053 commit d632c7c

File tree

11 files changed

+583
-17
lines changed

11 files changed

+583
-17
lines changed

e2e/qwik-nx-e2e/tests/application-basic-behavior.suite.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,18 @@ export function testApplicationBasicBehavior(generator: 'app' | 'preset') {
3535
});
3636

3737
it('should create qwik-nx', async () => {
38-
const result = await runNxCommandAsync(`build-ssr ${project}`);
38+
const result = await runNxCommandAsync(`build ${project}`);
39+
expect(stripConsoleColors(result.stdout.replace(/\n|\s/g, ''))).toContain(
40+
[
41+
'Targets to be executed:',
42+
`${project}:build.client`,
43+
`${project}:build.ssr`,
44+
]
45+
.join('')
46+
.replace(/\n|\s/g, '')
47+
);
3948
expect(result.stdout).toContain(
40-
`Successfully ran target build-ssr for project ${project}`
49+
`Successfully ran target build for project ${project}`
4150
);
4251
expect(() =>
4352
checkFilesExist(`dist/apps/${project}/client/q-manifest.json`)
@@ -47,6 +56,25 @@ export function testApplicationBasicBehavior(generator: 'app' | 'preset') {
4756
).not.toThrow();
4857
}, 200000);
4958

59+
it('should run build with a specified configuration', async () => {
60+
// TODO: cloudflare pages or custom configurations should also be tested
61+
const result = await runNxCommandAsync(
62+
`build ${project} --configuration=preview`
63+
);
64+
expect(stripConsoleColors(result.stdout.replace(/\n|\s/g, ''))).toContain(
65+
[
66+
'Targets to be executed:',
67+
`${project}:build.client:preview`,
68+
`${project}:build.ssr:preview`,
69+
]
70+
.join('')
71+
.replace(/\n|\s/g, '')
72+
);
73+
expect(result.stdout).toContain(
74+
`Successfully ran target build for project ${project}`
75+
);
76+
}, 200000);
77+
5078
it('should serve application in dev mode with custom port', async () => {
5179
const port = 4212;
5280
const p = await runCommandUntil(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ describe('qwikNxVite plugin e2e', () => {
106106
}, 200000);
107107

108108
it('should be able to successfully build the application', async () => {
109-
const result = await runNxCommandAsync(`build-ssr ${project}`);
109+
const result = await runNxCommandAsync(`build ${project}`);
110110
expect(result.stdout).toContain(
111-
`Successfully ran target build-ssr for project ${project}`
111+
`Successfully ran target build for project ${project}`
112112
);
113113
expect(() =>
114114
checkFilesExist(`dist/apps/${project}/client/q-manifest.json`)

e2e/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export function getEnvironmentVariables() {
186186
* @param log
187187
* @returns
188188
*/
189-
function stripConsoleColors(log: string): string {
189+
export function stripConsoleColors(log: string): string {
190190
return log.replace(
191191
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
192192
''

packages/qwik-nx/.eslintrc.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515
"rules": {}
1616
},
1717
{
18-
"files": ["./package.json", "./generators.json", "./executors.json"],
18+
"files": [
19+
"./package.json",
20+
"./generators.json",
21+
"./executors.json",
22+
"./migrations.json"
23+
],
1924
"parser": "jsonc-eslint-parser",
2025
"rules": {
2126
"@nrwl/nx/nx-plugin-checks": "error"

packages/qwik-nx/migrations.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"generators": {
3+
"switch-to-qwik-nx:build-executor": {
4+
"version": "0.11.0",
5+
"description": "switch-to-qwik-nx:build-executor",
6+
"cli": "nx",
7+
"implementation": "./src/migrations/switch-to-qwik-nx:build-executor/switch-to-qwik-nx:build-executor"
8+
}
9+
}
10+
}

packages/qwik-nx/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,8 @@
2828
"vitest": "^0.25.0",
2929
"@playwright/test": "^1.30.0",
3030
"undici": "^5.18.0"
31+
},
32+
"nx-migrations": {
33+
"migrations": "./migrations.json"
3134
}
3235
}

packages/qwik-nx/project.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
"input": "./packages/qwik-nx",
3838
"glob": "executors.json",
3939
"output": "."
40+
},
41+
{
42+
"input": "./packages/qwik-nx",
43+
"glob": "migrations.json",
44+
"output": "."
4045
}
4146
]
4247
}
@@ -49,7 +54,8 @@
4954
"packages/qwik-nx/**/*.ts",
5055
"packages/qwik-nx/generators.json",
5156
"packages/qwik-nx/executors.json",
52-
"packages/qwik-nx/package.json"
57+
"packages/qwik-nx/package.json",
58+
"packages/qwik-nx/migrations.json"
5359
]
5460
}
5561
},

packages/qwik-nx/src/generators/integrations/cloudflare-pages-integration/generator.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('cloudflare-pages-integration generator', () => {
3636
await cloudflarePagesIntegrationGenerator(appTree, options);
3737
const config = readProjectConfiguration(appTree, projectName);
3838
expect(
39-
config.targets!['build-ssr'].configurations!['cloudflare-pages']
39+
config.targets!['build.ssr'].configurations!['cloudflare-pages']
4040
).toEqual({
4141
configFile: `apps/${projectName}/adaptors/cloudflare-pages/vite.config.ts`,
4242
});
@@ -45,19 +45,19 @@ describe('cloudflare-pages-integration generator', () => {
4545
options: {
4646
dist: `dist/apps/${projectName}/client`,
4747
},
48-
dependsOn: ['build-ssr-cloudflare-pages'],
48+
dependsOn: ['build-cloudflare-pages'],
4949
});
5050
expect(config.targets!['preview-cloudflare-pages']).toEqual({
5151
executor: '@k11r/nx-cloudflare-wrangler:serve-page',
5252
options: {
5353
dist: `dist/apps/${projectName}/client`,
5454
},
55-
dependsOn: ['build-ssr-cloudflare-pages'],
55+
dependsOn: ['build-cloudflare-pages'],
5656
});
57-
expect(config.targets!['build-ssr-cloudflare-pages']).toEqual({
57+
expect(config.targets!['build-cloudflare-pages']).toEqual({
5858
executor: 'nx:run-commands',
5959
options: {
60-
command: `npx nx run ${projectName}:build-ssr:cloudflare-pages`,
60+
command: `npx nx run ${projectName}:build:cloudflare-pages`,
6161
},
6262
});
6363
});
@@ -95,10 +95,10 @@ describe('cloudflare-pages-integration generator', () => {
9595

9696
it('project does not have Qwik\'s "build-ssr" target', async () => {
9797
const config = readProjectConfiguration(appTree, projectName);
98-
delete config.targets!['build-ssr'];
98+
config.targets!.build.executor = 'changed';
9999
updateProjectConfiguration(appTree, projectName, config);
100100

101-
expect(
101+
await expect(
102102
cloudflarePagesIntegrationGenerator(appTree, options)
103103
).rejects.toThrow(
104104
'Cannot setup cloudflare integration for the given project.'

packages/qwik-nx/src/generators/integrations/cloudflare-pages-integration/generator.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
joinPathFragments,
77
names,
88
offsetFromRoot,
9+
output,
910
ProjectConfiguration,
1011
readProjectConfiguration,
1112
TargetConfiguration,
@@ -29,6 +30,10 @@ export async function cloudflarePagesIntegrationGenerator(
2930
config.projectType !== 'application' ||
3031
config.targets?.['build']?.executor !== 'qwik-nx:build'
3132
) {
33+
console.error(
34+
'Project contains invalid configuration. ' +
35+
'If you encounter this error within a Qwik project, make sure you have run necessary Nx migrations for qwik-nx plugin.'
36+
);
3237
throw new Error(
3338
'Cannot setup cloudflare integration for the given project.'
3439
);
@@ -46,7 +51,7 @@ export async function cloudflarePagesIntegrationGenerator(
4651
config.targets['deploy'] = getDeployTarget(normalizedOptions);
4752
config.targets['preview-cloudflare-pages'] =
4853
getCloudflarePreviewTarget(normalizedOptions);
49-
config.targets['build-ssr-cloudflare-pages'] =
54+
config.targets['build-cloudflare-pages'] =
5055
getIntermediateDependsOnTarget(normalizedOptions);
5156

5257
updateProjectConfiguration(tree, options.project, config);
@@ -72,7 +77,7 @@ function getDeployTarget(options: NormalizedOptions): TargetConfiguration {
7277
options: {
7378
dist: `dist/${options.projectConfig.root}/client`,
7479
},
75-
dependsOn: ['build-ssr-cloudflare-pages'],
80+
dependsOn: ['build-cloudflare-pages'],
7681
};
7782
}
7883

@@ -84,7 +89,7 @@ function getCloudflarePreviewTarget(
8489
options: {
8590
dist: `dist/${options.projectConfig.root}/client`,
8691
},
87-
dependsOn: ['build-ssr-cloudflare-pages'],
92+
dependsOn: ['build-cloudflare-pages'],
8893
};
8994
}
9095

0 commit comments

Comments
 (0)