Skip to content

Commit 4e59c85

Browse files
test(qwik-nx): run the same basic tests for both "app" and "preset" generators (#86)
1 parent f0e4d5d commit 4e59c85

File tree

4 files changed

+96
-83
lines changed

4 files changed

+96
-83
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import {
2+
checkFilesExist,
3+
ensureNxProject,
4+
runNxCommandAsync,
5+
uniq,
6+
} from '@nrwl/nx-plugin/testing';
7+
8+
import {
9+
runCommandUntil,
10+
promisifiedTreeKill,
11+
killPort,
12+
} from '@qwikifiers/e2e/utils';
13+
14+
export function testApplicationBasicBehavior(generator: 'app' | 'preset') {
15+
describe(`Basic behavior with ${generator} generator`, () => {
16+
let project: string;
17+
18+
beforeAll(() => {
19+
ensureNxProject('qwik-nx', 'dist/packages/qwik-nx');
20+
});
21+
22+
beforeAll(async () => {
23+
project = uniq('qwik-nx');
24+
25+
const projectNameParam =
26+
generator === 'preset' ? `--qwikAppName=${project}` : project;
27+
28+
await runNxCommandAsync(
29+
`generate qwik-nx:${generator} ${projectNameParam} --no-interactive`
30+
);
31+
}, 200000);
32+
33+
afterAll(async () => {
34+
await runNxCommandAsync('reset');
35+
});
36+
37+
it('should create qwik-nx', async () => {
38+
const result = await runNxCommandAsync(`build-ssr ${project}`);
39+
expect(result.stdout).toContain(
40+
`Successfully ran target build-ssr for project ${project}`
41+
);
42+
expect(() =>
43+
checkFilesExist(`dist/apps/${project}/client/q-manifest.json`)
44+
).not.toThrow();
45+
expect(() =>
46+
checkFilesExist(`dist/apps/${project}/server/entry.preview.mjs`)
47+
).not.toThrow();
48+
}, 200000);
49+
50+
it('should serve application in dev mode with custom port', async () => {
51+
const port = 4212;
52+
const p = await runCommandUntil(
53+
`run ${project}:serve --port=${port}`,
54+
(output) => {
55+
return output.includes('Local:') && output.includes(`:${port}`);
56+
}
57+
);
58+
try {
59+
await promisifiedTreeKill(p.pid!, 'SIGKILL');
60+
await killPort(port);
61+
} catch {
62+
// ignore
63+
}
64+
}, 200000);
65+
66+
it('should serve application in preview mode with custom port', async () => {
67+
const port = 4232;
68+
const p = await runCommandUntil(
69+
`run ${project}:preview --port=${port}`,
70+
(output) => {
71+
return output.includes('Local:') && output.includes(`:${port}`);
72+
}
73+
);
74+
try {
75+
await promisifiedTreeKill(p.pid!, 'SIGKILL');
76+
await killPort(port);
77+
} catch {
78+
// ignore
79+
}
80+
}, 200000);
81+
});
82+
}
Lines changed: 2 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,5 @@
1-
import {
2-
checkFilesExist,
3-
ensureNxProject,
4-
runNxCommandAsync,
5-
uniq,
6-
} from '@nrwl/nx-plugin/testing';
7-
8-
import {
9-
runCommandUntil,
10-
promisifiedTreeKill,
11-
killPort,
12-
} from '@qwikifiers/e2e/utils';
1+
import { testApplicationBasicBehavior } from './application-basic-behavior.suite';
132

143
describe('appGenerator e2e', () => {
15-
// Setting up individual workspaces per
16-
// test can cause e2e runs to take a long time.
17-
// For this reason, we recommend each suite only
18-
// consumes 1 workspace. The tests should each operate
19-
// on a unique project in the workspace, such that they
20-
// are not dependant on one another.
21-
beforeAll(() => {
22-
ensureNxProject('qwik-nx', 'dist/packages/qwik-nx');
23-
});
24-
25-
afterAll(async () => {
26-
// `nx reset` kills the daemon, and performs
27-
// some work which can help clean up e2e leftovers
28-
await runNxCommandAsync('reset');
29-
});
30-
31-
describe('Basic behavior', () => {
32-
let project: string;
33-
beforeAll(async () => {
34-
project = uniq('qwik-nx');
35-
await runNxCommandAsync(
36-
`generate qwik-nx:app ${project} --no-interactive`
37-
);
38-
}, 200000);
39-
40-
it('should create qwik-nx', async () => {
41-
const result = await runNxCommandAsync(`build-ssr ${project}`);
42-
expect(result.stdout).toContain(
43-
`Successfully ran target build-ssr for project ${project}`
44-
);
45-
expect(() =>
46-
checkFilesExist(`dist/apps/${project}/client/q-manifest.json`)
47-
).not.toThrow();
48-
expect(() =>
49-
checkFilesExist(`dist/apps/${project}/server/entry.preview.mjs`)
50-
).not.toThrow();
51-
}, 200000);
52-
53-
it('should serve application in dev mode with custom port', async () => {
54-
const port = 4212;
55-
const p = await runCommandUntil(
56-
`run ${project}:serve --port=${port}`,
57-
(output) => {
58-
return output.includes('Local:') && output.includes(`:${port}`);
59-
}
60-
);
61-
try {
62-
await promisifiedTreeKill(p.pid!, 'SIGKILL');
63-
await killPort(port);
64-
} catch {
65-
// ignore
66-
}
67-
}, 200000);
68-
69-
it('should serve application in preview mode with custom port', async () => {
70-
const port = 4232;
71-
const p = await runCommandUntil(
72-
`run ${project}:preview --port=${port}`,
73-
(output) => {
74-
return output.includes('Local:') && output.includes(`:${port}`);
75-
}
76-
);
77-
try {
78-
await promisifiedTreeKill(p.pid!, 'SIGKILL');
79-
await killPort(port);
80-
} catch {
81-
// ignore
82-
}
83-
}, 200000);
84-
});
4+
testApplicationBasicBehavior('app');
855
});

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { testApplicationBasicBehavior } from './application-basic-behavior.suite';
2+
3+
describe('presetGenerator e2e', () => {
4+
testApplicationBasicBehavior('preset');
5+
});

e2e/qwik-nx-e2e/tsconfig.spec.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,11 @@
55
"module": "commonjs",
66
"types": ["jest", "node"]
77
},
8-
"include": ["jest.config.ts", "**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"]
8+
"include": [
9+
"jest.config.ts",
10+
"**/*.test.ts",
11+
"**/*.spec.ts",
12+
"**/*.d.ts",
13+
"**/*.suite.ts"
14+
]
915
}

0 commit comments

Comments
 (0)