Skip to content

Commit 517cdd3

Browse files
committed
feat: add e2e tests for Next.js and Vite
1 parent f1beea5 commit 517cdd3

File tree

7 files changed

+34
-55
lines changed

7 files changed

+34
-55
lines changed

packages/core/__tests__/config/playwright.next.config.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,33 @@ const BASE_URL = `http://localhost:${PORT}`;
1111
export default defineConfig({
1212
testDir: "../e2e", // all E2E specs live here
1313
snapshotDir: "../snapshots",
14-
workers: 1,
15-
timeout: 300_000,
14+
workers: 2,
15+
timeout: 30_000,
1616
expect: {
17-
timeout: 150_000,
17+
timeout: 15_000,
1818
},
1919
reporter: "html",
20-
globalSetup: path.resolve(__dirname, "../helpers/globalSetup.next.js"),
2120

2221
use: {
2322
headless: true,
2423
baseURL: BASE_URL,
2524

2625
},
2726

28-
// One project = one fixture app (Next, Vite, etc.)
2927
projects: [
28+
{
29+
name: "setup",
30+
testMatch: /nextSetup\.js/,
31+
},
32+
{
33+
name: "next-cli-e2e",
34+
dependencies: ["setup"],
35+
testMatch: /cli-next\.spec\.js/,
36+
},
3037
{
3138
name: "next-e2e",
32-
testMatch: /.*next.*\.spec\.js/, // Matches both cli-next.spec.js and next.spec.js
33-
use: {
34-
baseURL: BASE_URL,
35-
},
39+
dependencies: ["next-cli-e2e"],
40+
testMatch: /next\.spec\.js/,
3641
},
3742
],
3843
webServer: {

packages/core/__tests__/config/playwright.vite.config.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ const BASE_URL = `http://localhost:${PORT}`;
1111
export default defineConfig({
1212
testDir: "../e2e", // all E2E specs live here
1313
snapshotDir: "../snapshots",
14-
workers: 1,
15-
timeout: 300_000,
14+
workers: 2,
15+
timeout: 30_000,
1616
expect: {
17-
timeout: 150_000,
17+
timeout: 15_000,
1818
},
1919
reporter: "html",
20-
globalSetup: path.resolve(__dirname, "../helpers/globalSetup.vite.js"),
2120

2221
use: {
2322
headless: true,
@@ -26,19 +25,19 @@ export default defineConfig({
2625

2726
// One project = one fixture app (Next, Vite, etc.)
2827
projects: [
28+
{
29+
name: "setup",
30+
testMatch: /viteSetup\.js/,
31+
},
2932
{
3033
name: "vite-cli-e2e",
34+
dependencies: ["setup"],
3135
testMatch: /cli-vite\.spec\.js/, // Matches both cli-vite.spec.js and vite.spec.js
32-
use: {
33-
baseURL: BASE_URL,
34-
},
3536
},
3637
{
3738
name: "vite-e2e",
39+
dependencies: ["vite-cli-e2e"],
3840
testMatch: /vite\.spec\.js/, // Matches both cli-vite.spec.js and vite.spec.js
39-
use: {
40-
baseURL: BASE_URL,
41-
},
4241
},
4342
],
4443
webServer: {
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
// packages/core/__tests__/helpers/globalSetup.next.js
21
import { resetZeroUiState } from '../helpers/resetProjectState.js';
32
import { loadCliFromFixture } from '../helpers/loadCli.js';
43
import path from 'node:path';
54
import { fileURLToPath } from 'node:url';
65

76
const __dirname = path.dirname(fileURLToPath(import.meta.url));
8-
console.log('__dirname: ', __dirname);
97

108
export default async function globalSetup() {
119
const projectDir = path.resolve(__dirname, '../fixtures/next');
12-
console.log('projectDir: ', projectDir);
1310

1411
// Reset and setup the Next.js fixture
1512
console.log('[Global Setup] Setting up Next.js fixture...');
@@ -18,5 +15,5 @@ export default async function globalSetup() {
1815
const zeroUiCli = await loadCliFromFixture(projectDir);
1916
await zeroUiCli([]);
2017

21-
console.log('[Global Setup] Next.js fixture setup complete!');
18+
console.log('[Global Setup] Next.js fixture setup complete!');
2219
}

packages/core/__tests__/helpers/globalSetup.vite.js renamed to packages/core/__tests__/e2e/viteSetup.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// packages/core/__tests__/helpers/globalSetup.vite.js
2-
import { resetZeroUiState } from './resetProjectState.js';
3-
import { loadCliFromFixture } from './loadCli.js';
1+
import { resetZeroUiState } from '../helpers/resetProjectState.js';
2+
import { loadCliFromFixture } from '../helpers/loadCli.js';
43
import path from 'node:path';
54
import { fileURLToPath } from 'node:url';
65

@@ -16,5 +15,5 @@ export default async function globalSetup() {
1615
const zeroUiCli = await loadCliFromFixture(projectDir);
1716
await zeroUiCli([]);
1817

19-
console.log('[Global Setup] Vite fixture setup complete!');
18+
console.log('[Global Setup] Vite fixture setup complete!');
2019
}

packages/core/__tests__/helpers/globalSetup.next.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

packages/core/__tests__/helpers/loadCli.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ export async function loadCliFromFixture(fixtureDir) {
66
const r = createRequire(path.join(fixtureDir, 'package.json'));
77
const modulePath = r.resolve('../../../src/cli/init.cjs'); // get the path
88
const mod = r(modulePath); // actually require the module
9-
9+
console.log('[Global Setup] Loaded CLI from fixture:', modulePath);
1010
// Return a wrapper function that changes directory before running CLI
1111
const wrappedCli = async (args = []) => {
1212
const originalCwd = process.cwd();
1313
try {
1414
process.chdir(fixtureDir); // Change to fixture directory
1515

1616
// The init.cjs exports a cli function, so call it
17+
1718
if (typeof mod === 'function') {
1819
return await Promise.resolve(mod(args)); // run the CLI
1920
} else if (typeof mod.default === 'function') {
@@ -23,6 +24,7 @@ export async function loadCliFromFixture(fixtureDir) {
2324
}
2425
} finally {
2526
process.chdir(originalCwd); // Always restore original directory
27+
console.log('[Global Setup] Restored original directory:', originalCwd);
2628
}
2729
};
2830

scripts/install-local-tarball.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@ const fixtures = [
1515
for (const dir of fixtures) {
1616
const pkgJson = join(dir, "package.json");
1717

18-
// 1: Install base deps
19-
execSync(`pnpm --dir ${dir} install --silent`, { stdio: "inherit" });
20-
21-
// 2: Inject the packed tarball
18+
// 1: Inject the packed tarball
2219
execSync(`pnpm --dir ${dir} add ${join(dist, pkg)}`, { stdio: "inherit" });
2320

24-
// 3: Re-install to resolve tree
25-
execSync(`pnpm --dir ${dir} install --silent`, { stdio: "inherit" });
21+
// 2: Install to resolve tree
22+
execSync(`pnpm --dir ${dir} install`, { stdio: "inherit" });
2623

27-
// ✅ 4: Undo changes to package.json
24+
// 3: Undo changes to package.json
2825
execSync(`git restore ${pkgJson}`, { stdio: "inherit" });
2926
}

0 commit comments

Comments
 (0)