Skip to content

Commit 4c834cd

Browse files
feat(qwik-nx): build executor migration and test coverage
1 parent 9166525 commit 4c834cd

File tree

14 files changed

+593
-18
lines changed

14 files changed

+593
-18
lines changed

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
runCommandUntil,
1010
promisifiedTreeKill,
1111
killPort,
12+
stripConsoleColors,
1213
} from '@qwikifiers/e2e/utils';
1314

1415
describe('appGenerator e2e', () => {
@@ -38,9 +39,18 @@ describe('appGenerator e2e', () => {
3839
}, 200000);
3940

4041
it('should create qwik-nx', async () => {
41-
const result = await runNxCommandAsync(`build-ssr ${project}`);
42+
const result = await runNxCommandAsync(`build ${project}`);
43+
expect(stripConsoleColors(result.stdout.replace(/\n|\s/g, ''))).toContain(
44+
[
45+
'Targets to be executed:',
46+
`${project}:build.client`,
47+
`${project}:build.ssr`,
48+
]
49+
.join('')
50+
.replace(/\n|\s/g, '')
51+
);
4252
expect(result.stdout).toContain(
43-
`Successfully ran target build-ssr for project ${project}`
53+
`Successfully ran target build for project ${project}`
4454
);
4555
expect(() =>
4656
checkFilesExist(`dist/apps/${project}/client/q-manifest.json`)
@@ -50,6 +60,25 @@ describe('appGenerator e2e', () => {
5060
).not.toThrow();
5161
}, 200000);
5262

63+
it('should run build with a specified configuration', async () => {
64+
// TODO: cloudflare pages or custom configurations should also be tested
65+
const result = await runNxCommandAsync(
66+
`build ${project} --configuration=preview`
67+
);
68+
expect(stripConsoleColors(result.stdout.replace(/\n|\s/g, ''))).toContain(
69+
[
70+
'Targets to be executed:',
71+
`${project}:build.client:preview`,
72+
`${project}:build.ssr:preview`,
73+
]
74+
.join('')
75+
.replace(/\n|\s/g, '')
76+
);
77+
expect(result.stdout).toContain(
78+
`Successfully ran target build for project ${project}`
79+
);
80+
}, 200000);
81+
5382
it('should serve application in dev mode with custom port', async () => {
5483
const port = 4212;
5584
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
@@ -182,7 +182,7 @@ export function getEnvironmentVariables() {
182182
* @param log
183183
* @returns
184184
*/
185-
function stripConsoleColors(log: string): string {
185+
export function stripConsoleColors(log: string): string {
186186
return log.replace(
187187
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
188188
''

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"eslint-config-prettier": "8.1.0",
4545
"fs-extra": "11.1.0",
4646
"husky": "^8.0.1",
47+
"is-windows": "1.0.2",
4748
"jest": "28.1.1",
4849
"jest-environment-jsdom": "28.1.1",
4950
"jsonc-eslint-parser": "^2.1.0",

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)