Skip to content

Commit 3754e08

Browse files
committed
test(create-cli): add test for preview
1 parent 40f098f commit 3754e08

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

e2e/qwik-cli-e2e/tests/serve.spec.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { existsSync, readFileSync, writeFileSync } from 'fs';
1212
import { join } from 'path';
1313

14-
const SERVE_PORT = 3535;
14+
let SERVE_PORT = 3535;
1515
beforeAll(() => {
1616
const config = scaffoldQwikProject();
1717
global.tmpDir = config.tmpDir;
@@ -43,6 +43,25 @@ test(
4343
}
4444
);
4545

46+
test('Should preview the app', { timeout: DEFAULT_TIMEOUT }, async () => {
47+
// the port doesn't clear immediately after the previous test
48+
SERVE_PORT++;
49+
const host = `http://localhost:${SERVE_PORT}/`;
50+
await assertHostUnused(host);
51+
const p = await runCommandUntil(
52+
`npm run preview -- --port ${SERVE_PORT}`,
53+
global.tmpDir,
54+
(output) => {
55+
return output.includes(host);
56+
}
57+
);
58+
assert.equal(existsSync(global.tmpDir), true);
59+
60+
await expectHtmlOnARootPage(host);
61+
62+
await promisifiedTreeKill(p.pid!, 'SIGKILL');
63+
});
64+
4665
async function expectHtmlOnARootPage(host: string) {
4766
expect((await getPageHtml(host)).querySelector('.container h1')?.textContent).toBe(
4867
`So fantasticto have you here`

0 commit comments

Comments
 (0)