Skip to content

Commit d2dd8e0

Browse files
authored
fix: vite.config for cloudflare adapter miss-configurations (#175)
* fix: vite.config for cloudflare adapter missconfigurations * chore: add e2e tests to the cloudflare generator * fix: specify a unique port for cloudflare preview * docs: adjust the comments to the describe group * chore: temporarily skip serve cloudflare application
1 parent 3def657 commit d2dd8e0

File tree

2 files changed

+93
-4
lines changed

2 files changed

+93
-4
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import {
2+
checkFilesExist,
3+
ensureNxProject,
4+
runNxCommandAsync,
5+
uniq,
6+
} from '@nx/plugin/testing';
7+
8+
import {
9+
runCommandUntil,
10+
promisifiedTreeKill,
11+
killPort,
12+
killPorts,
13+
DEFAULT_E2E_TIMEOUT,
14+
} from '@qwikifiers/e2e/utils';
15+
16+
const CLOUDFLARE_PREVIEW_PORT = 4300;
17+
18+
describe('qwik nx cloudflare generator', () => {
19+
// Setting up individual workspaces per
20+
// test can cause e2e runs to take a long time.
21+
// For this reason, we recommend each suite only
22+
// consumes 1 workspace. The tests should each operate
23+
// on a unique project in the workspace, such that they
24+
// are not dependant on one another.
25+
beforeAll(async () => {
26+
await killPorts(CLOUDFLARE_PREVIEW_PORT);
27+
ensureNxProject('qwik-nx', 'dist/packages/qwik-nx');
28+
}, 10000);
29+
30+
afterAll(async () => {
31+
// `nx reset` kills the daemon, and performs
32+
// some work which can help clean up e2e leftovers
33+
await runNxCommandAsync('reset');
34+
});
35+
36+
describe('should build and serve a project with the cloudflare adapter', () => {
37+
let project: string;
38+
beforeAll(async () => {
39+
project = uniq('qwik-nx');
40+
await runNxCommandAsync(
41+
`generate qwik-nx:app ${project} --no-interactive`
42+
);
43+
await runNxCommandAsync(
44+
`generate qwik-nx:cloudflare-pages-integration ${project} --no-interactive`
45+
);
46+
47+
// move header component into the library
48+
}, DEFAULT_E2E_TIMEOUT);
49+
50+
it(
51+
'should be able to successfully build the application',
52+
async () => {
53+
const result = await runNxCommandAsync(`build-cloudflare ${project}`);
54+
expect(result.stdout).toContain(
55+
`Successfully ran target build for project ${project}`
56+
);
57+
expect(() =>
58+
checkFilesExist(`dist/apps/${project}/client/q-manifest.json`)
59+
).not.toThrow();
60+
expect(() =>
61+
checkFilesExist(
62+
`dist/apps/${project}/server/entry.cloudflare-pages.js`
63+
)
64+
).not.toThrow();
65+
},
66+
DEFAULT_E2E_TIMEOUT
67+
);
68+
69+
xit(
70+
'should serve application in preview mode with custom port',
71+
async () => {
72+
const p = await runCommandUntil(
73+
`run ${project}:preview-cloudflare --port=${CLOUDFLARE_PREVIEW_PORT}`,
74+
(output) => {
75+
return (
76+
output.includes('Local:') &&
77+
output.includes(`:${CLOUDFLARE_PREVIEW_PORT}`)
78+
);
79+
}
80+
);
81+
try {
82+
await promisifiedTreeKill(p.pid!, 'SIGKILL');
83+
await killPort(CLOUDFLARE_PREVIEW_PORT);
84+
} catch {
85+
// ignore
86+
}
87+
},
88+
DEFAULT_E2E_TIMEOUT
89+
);
90+
});
91+
});

packages/qwik-nx/src/generators/integrations/cloudflare-pages-integration/files/adapters/cloudflare-pages/vite.config.ts.template

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { cloudflarePagesAdaptor } from '@builder.io/qwik-city/adapters/cloudflare-pages/vite';
1+
import { cloudflarePagesAdapter } from '@builder.io/qwik-city/adapters/cloudflare-pages/vite';
22
import { extendConfig } from '@builder.io/qwik-city/vite';
33
import baseConfig from '../../vite.config';
44

@@ -11,9 +11,7 @@ export default extendConfig(baseConfig, () => {
1111
},
1212
},
1313
plugins: [
14-
cloudflarePagesAdaptor({
15-
staticGenerate: true,
16-
}),
14+
cloudflarePagesAdapter(),
1715
],
1816
};
1917
});

0 commit comments

Comments
 (0)