Skip to content

Commit 4064157

Browse files
committed
test(nuxt): Use sentry.server.config.ts in E2E tests
1 parent 8d5a084 commit 4064157

File tree

8 files changed

+114
-4
lines changed

8 files changed

+114
-4
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
4+
/* This script copies the `import-in-the-middle` content of the E2E test project root `node_modules` to the build output `node_modules`
5+
For some reason, some files are missing in the output (like `hook.mjs`) and this is not reproducible in external, standalone projects.
6+
7+
Things we tried (that did not fix the problem):
8+
- Adding a resolution for `@vercel/nft` v0.27.0 (this worked in the standalone project)
9+
- Also adding `@vercel/nft` v0.27.0 to pnpm `peerDependencyRules`
10+
*/
11+
function copyFolderSync(src, dest) {
12+
if (!fs.existsSync(dest)) {
13+
fs.mkdirSync(dest, { recursive: true });
14+
}
15+
16+
const entries = fs.readdirSync(src, { withFileTypes: true });
17+
18+
for (let entry of entries) {
19+
const srcPath = path.join(src, entry.name);
20+
const destPath = path.join(dest, entry.name);
21+
22+
if (entry.isDirectory()) {
23+
copyFolderSync(srcPath, destPath);
24+
} else {
25+
fs.copyFileSync(srcPath, destPath);
26+
}
27+
}
28+
}
29+
30+
function getSourceFolder() {
31+
const specificVersionFolder = `node_modules${path.sep}.pnpm${path.sep}[email protected]${path.sep}node_modules${path.sep}import-in-the-middle`;
32+
33+
if (fs.existsSync(specificVersionFolder)) {
34+
return specificVersionFolder;
35+
}
36+
37+
const parentFolder = `node_modules${path.sep}.pnpm`;
38+
const folders = fs.readdirSync(parentFolder, { withFileTypes: true });
39+
40+
for (let folder of folders) {
41+
if (folder.isDirectory() && folder.name.startsWith('import-in-the-middle@')) {
42+
return path.join(parentFolder, folder.name, 'node_modules', 'import-in-the-middle');
43+
}
44+
}
45+
46+
throw new Error('No suitable import-in-the-middle folder found');
47+
}
48+
49+
const sourceFolder = getSourceFolder();
50+
const destinationFolder = `.output${path.sep}server${path.sep}node_modules${path.sep}import-in-the-middle`;
51+
52+
copyFolderSync(sourceFolder, destinationFolder);

dev-packages/e2e-tests/test-applications/nuxt-3/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"private": true,
44
"type": "module",
55
"scripts": {
6-
"build": "nuxt build",
6+
"build": "nuxt build && node ./copyIITM.mjs",
77
"dev": "nuxt dev",
88
"generate": "nuxt generate",
99
"preview": "NODE_OPTIONS='--import ./public/instrument.server.mjs' nuxt preview",
@@ -20,5 +20,8 @@
2020
"@nuxt/test-utils": "^3.14.1",
2121
"@playwright/test": "^1.44.1",
2222
"@sentry-internal/test-utils": "link:../../../test-utils"
23+
},
24+
"overrides": {
25+
"@vercel/nft": "0.27.4"
2326
}
2427
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
4+
/* This script copies the `import-in-the-middle` content of the E2E test project root `node_modules` to the build output `node_modules`
5+
For some reason, some files are missing in the output (like `hook.mjs`) and this is not reproducible in external, standalone projects.
6+
7+
Things we tried (that did not fix the problem):
8+
- Adding a resolution for `@vercel/nft` v0.27.0 (this worked in the standalone project)
9+
- Also adding `@vercel/nft` v0.27.0 to pnpm `peerDependencyRules`
10+
*/
11+
function copyFolderSync(src, dest) {
12+
if (!fs.existsSync(dest)) {
13+
fs.mkdirSync(dest, { recursive: true });
14+
}
15+
16+
const entries = fs.readdirSync(src, { withFileTypes: true });
17+
18+
for (let entry of entries) {
19+
const srcPath = path.join(src, entry.name);
20+
const destPath = path.join(dest, entry.name);
21+
22+
if (entry.isDirectory()) {
23+
copyFolderSync(srcPath, destPath);
24+
} else {
25+
fs.copyFileSync(srcPath, destPath);
26+
}
27+
}
28+
}
29+
30+
function getSourceFolder() {
31+
const specificVersionFolder = `node_modules${path.sep}.pnpm${path.sep}[email protected]${path.sep}node_modules${path.sep}import-in-the-middle`;
32+
33+
if (fs.existsSync(specificVersionFolder)) {
34+
return specificVersionFolder;
35+
}
36+
37+
const parentFolder = `node_modules${path.sep}.pnpm`;
38+
const folders = fs.readdirSync(parentFolder, { withFileTypes: true });
39+
40+
for (let folder of folders) {
41+
if (folder.isDirectory() && folder.name.startsWith('import-in-the-middle@')) {
42+
return path.join(parentFolder, folder.name, 'node_modules', 'import-in-the-middle');
43+
}
44+
}
45+
46+
throw new Error('No suitable import-in-the-middle folder found');
47+
}
48+
49+
const sourceFolder = getSourceFolder();
50+
const destinationFolder = `.output${path.sep}server${path.sep}node_modules${path.sep}import-in-the-middle`;
51+
52+
copyFolderSync(sourceFolder, destinationFolder);

dev-packages/e2e-tests/test-applications/nuxt-4/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"private": true,
44
"type": "module",
55
"scripts": {
6-
"build": "nuxt build",
6+
"build": "nuxt build && node ./copyIITM.mjs",
77
"dev": "nuxt dev",
88
"generate": "nuxt generate",
99
"preview": "NODE_OPTIONS='--import ./public/instrument.server.mjs' nuxt preview",
@@ -20,5 +20,8 @@
2020
"@nuxt/test-utils": "^3.14.2",
2121
"@playwright/test": "^1.44.1",
2222
"@sentry-internal/test-utils": "link:../../../test-utils"
23+
},
24+
"overrides": {
25+
"@vercel/nft": "0.27.4"
2326
}
2427
}

dev-packages/e2e-tests/test-applications/nuxt-4/tests/errors.client.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect, test } from '@nuxt/test-utils/playwright';
1+
import { expect, test } from '@playwright/test';
22
import { waitForError } from '@sentry-internal/test-utils';
33

44
test.describe('client-side errors', async () => {

dev-packages/e2e-tests/test-applications/nuxt-4/tests/tracing.client.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect, test } from '@nuxt/test-utils/playwright';
1+
import { expect, test } from '@playwright/test';
22
import { waitForTransaction } from '@sentry-internal/test-utils';
33
import type { Span } from '@sentry/nuxt';
44

0 commit comments

Comments
 (0)