|
| 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 | +}); |
0 commit comments