Skip to content

Commit 887ca75

Browse files
feat(qwik-nx): use nx e2e generators directly (#210)
BREAKING CHANGE: `qwik-nx/e2e-project` has been removed in favour of direct usage of nx generators
1 parent e67c7bb commit 887ca75

File tree

19 files changed

+293
-3181
lines changed

19 files changed

+293
-3181
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030
"@nx/jest": "16.10.0",
3131
"@nx/js": "16.10.0",
3232
"@nx/linter": "16.10.0",
33+
"@nx/playwright": "16.10.0",
3334
"@nx/plugin": "16.10.0",
3435
"@nx/storybook": "16.10.0",
3536
"@nx/vite": "16.10.0",
3637
"@nx/workspace": "16.10.0",
37-
"@nxkit/playwright": "^3.0.2",
3838
"@swc-node/register": "1.6.8",
3939
"@swc/cli": "0.1.62",
40-
"@swc/core": "^1.2.173",
40+
"@swc/core": "^1.3.95",
4141
"@types/fs-extra": "11.0.1",
4242
"@types/jest": "29.4.0",
4343
"@types/node": "16.11.7",

packages/qwik-nx/generators.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@
4545
"description": "Set up Tailwind configuration for a project.",
4646
"aliases": ["tailwind", "tw", "t"]
4747
},
48-
"e2e-project": {
49-
"factory": "./src/generators/e2e-project/generator",
50-
"schema": "./src/generators/e2e-project/schema.json",
51-
"description": "Create an E2E app for a Qwik app"
52-
},
5348
"cloudflare-pages-integration": {
5449
"factory": "./src/generators/integrations/cloudflare-pages-integration/generator",
5550
"schema": "./src/generators/integrations/cloudflare-pages-integration/schema.json",

packages/qwik-nx/src/generators/application/generator.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('qwik-nx generator', () => {
6060
});
6161
const config = readProjectConfiguration(appTree, 'myapp-e2e');
6262
expect(config).toBeDefined();
63-
expect(config.targets?.e2e.executor).toEqual('@nxkit/playwright:test');
63+
expect(config.targets?.e2e.executor).toEqual('@nx/playwright:playwright');
6464
expect(
6565
appTree.exists('apps/myapp-e2e/playwright.config.ts')
6666
).toBeTruthy();

packages/qwik-nx/src/generators/application/generator.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { SetupTailwindOptions } from './../setup-tailwind/schema.d';
2020
import { NormalizedSchema, QwikAppGeneratorSchema } from './schema';
2121
import { getQwikApplicationProjectTargets } from './utils/get-qwik-application-project-params';
2222
import { normalizeOptions } from './utils/normalize-options';
23-
import { addE2eProject } from '../e2e-project/generator';
23+
import { addE2eProject } from './utils/add-e2e';
2424

2525
function addFiles(tree: Tree, options: NormalizedSchema) {
2626
const templateOptions = {
@@ -89,12 +89,7 @@ export async function appGenerator(
8989
normalizedOptions.e2eTestRunner &&
9090
normalizedOptions.e2eTestRunner !== 'none'
9191
) {
92-
const e2eProjectTask = await addE2eProject(tree, {
93-
project: normalizedOptions.projectName,
94-
directory: normalizedOptions.directory,
95-
e2eTestRunner: normalizedOptions.e2eTestRunner,
96-
skipFormat: true,
97-
});
92+
const e2eProjectTask = await addE2eProject(tree, normalizedOptions);
9893
tasks.push(e2eProjectTask);
9994
}
10095

packages/qwik-nx/src/generators/application/schema.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ export interface NormalizedSchema extends QwikAppGeneratorSchema {
2828
parsedTags: string[];
2929
styleExtension: Exclude<QwikAppGeneratorSchema['style'], 'none'> | null;
3030
projectNameAndRootFormat: ProjectNameAndRootFormat;
31+
e2eProjectName: string;
32+
e2eProjectRoot: string;
3133
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import {
2+
addProjectConfiguration,
3+
ensurePackage,
4+
GeneratorCallback,
5+
getPackageManagerCommand,
6+
joinPathFragments,
7+
Tree,
8+
} from '@nx/devkit';
9+
import { getInstalledNxVersion } from '../../../utils/get-installed-nx-version';
10+
import { NormalizedSchema } from '../schema';
11+
import { Linter } from '@nx/linter';
12+
13+
export async function addE2eProject(
14+
tree: Tree,
15+
options: NormalizedSchema
16+
): Promise<GeneratorCallback> {
17+
if (options.e2eTestRunner === 'cypress') {
18+
return addCypress(tree, options);
19+
}
20+
21+
if (options.e2eTestRunner === 'playwright') {
22+
return addPlaywright(tree, options);
23+
}
24+
25+
return () => void 0;
26+
}
27+
28+
async function addCypress(tree: Tree, options: NormalizedSchema) {
29+
ensurePackage('@nx/cypress', getInstalledNxVersion(tree));
30+
const { configurationGenerator } = await import('@nx/cypress');
31+
32+
addProjectConfiguration(tree, options.e2eProjectName, {
33+
projectType: 'application',
34+
root: options.e2eProjectRoot,
35+
sourceRoot: joinPathFragments(options.e2eProjectRoot, 'src'),
36+
targets: {},
37+
tags: [],
38+
implicitDependencies: [options.projectName],
39+
});
40+
return await configurationGenerator(tree, {
41+
project: options.e2eProjectName,
42+
directory: 'src',
43+
linter: options.linter,
44+
skipFormat: true,
45+
devServerTarget: `${options.projectName}:serve:development`,
46+
});
47+
}
48+
49+
async function addPlaywright(tree: Tree, options: NormalizedSchema) {
50+
ensurePackage('@nx/playwright', getInstalledNxVersion(tree));
51+
const { configurationGenerator: playwrightConfigurationGenerator } =
52+
await import('@nx/playwright');
53+
54+
addProjectConfiguration(tree, options.e2eProjectName, {
55+
projectType: 'application',
56+
root: options.e2eProjectRoot,
57+
sourceRoot: joinPathFragments(options.e2eProjectRoot, 'src'),
58+
targets: {},
59+
implicitDependencies: [options.projectName],
60+
});
61+
return await playwrightConfigurationGenerator(tree, {
62+
project: options.e2eProjectName,
63+
skipFormat: true,
64+
directory: 'src',
65+
js: false,
66+
linter: options.linter ?? Linter.EsLint,
67+
webServerCommand: `${getPackageManagerCommand().exec} nx serve ${
68+
options.projectName
69+
}`,
70+
webServerAddress: `http://localhost:${options.devServerPort ?? 4200}`,
71+
setParserOptionsProject: true,
72+
skipPackageJson: false,
73+
});
74+
}

packages/qwik-nx/src/generators/application/utils/normalize-options.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export async function normalizeOptions(
2626
options.strict = options.strict ?? true;
2727
options.unitTestRunner = options.unitTestRunner ?? 'vitest';
2828

29+
const rootProject = appProjectRoot === '.';
30+
const e2eProjectName = rootProject ? 'e2e' : `${appProjectName}-e2e`;
31+
const e2eProjectRoot = rootProject ? 'e2e' : `${appProjectRoot}-e2e`;
32+
2933
const styleExtension = options.style !== 'none' ? options.style : null;
3034

3135
return {
@@ -40,5 +44,7 @@ export async function normalizeOptions(
4044
devServerPort: options.devServerPort ?? 5173,
4145
previewServerPort: options.previewServerPort ?? 4173,
4246
projectNameAndRootFormat,
47+
e2eProjectName,
48+
e2eProjectRoot,
4349
};
4450
}

0 commit comments

Comments
 (0)