Skip to content

Commit 8782af8

Browse files
authored
test(nuxt): Use sentry.server.config.ts in E2E tests (#13999)
The E2E tests still used an `instrument` file in the `public` folder (which is not the way to setup the SDK anymore) because `import-in-the-middle/hook.mjs` was not available and threw an error. To be able to properly test the setup with `sentry.server.config.ts`, a function was added that copies the `import-in-the-middle` folder to the build output to include all files.
1 parent 471cf9a commit 8782af8

12 files changed

+42
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This script copies the `import-in-the-middle` content of the E2E test project root `node_modules` to the build output `node_modules`
2+
# For some reason, some files are missing in the output (like `hook.mjs`) and this is not reproducible in external, standalone projects.
3+
#
4+
# Things we tried (that did not fix the problem):
5+
# - Adding a resolution for `@vercel/nft` v0.27.0 (this worked in the standalone project)
6+
# - Also adding `@vercel/nft` v0.27.0 to pnpm `peerDependencyRules`
7+
cp -r node_modules/.pnpm/import-in-the-middle@1.*/node_modules/import-in-the-middle .output/server/node_modules/import-in-the-middle

dev-packages/e2e-tests/test-applications/nuxt-3/nuxt.config.ts

+6
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ export default defineNuxtConfig({
1111
},
1212
},
1313
},
14+
nitro: {
15+
rollupConfig: {
16+
// @sentry/... is set external to prevent bundling all of Sentry into the `runtime.mjs` file in the build output
17+
external: [/@sentry\/.*/],
18+
},
19+
},
1420
});

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
"private": true,
44
"type": "module",
55
"scripts": {
6-
"build": "nuxt build",
6+
"build": "nuxt build && bash ./copyIITM.bash",
77
"dev": "nuxt dev",
88
"generate": "nuxt generate",
9-
"preview": "NODE_OPTIONS='--import ./public/instrument.server.mjs' nuxt preview",
9+
"preview": "nuxt preview",
10+
"start": "node --import ./.output/server/sentry.server.config.mjs .output/server/index.mjs",
1011
"clean": "npx nuxi cleanup",
1112
"test": "playwright test",
1213
"test:build": "pnpm install && npx playwright install && pnpm build",
@@ -20,5 +21,8 @@
2021
"@nuxt/test-utils": "^3.14.1",
2122
"@playwright/test": "^1.44.1",
2223
"@sentry-internal/test-utils": "link:../../../test-utils"
24+
},
25+
"overrides": {
26+
"@vercel/nft": "0.27.4"
2327
}
2428
}

dev-packages/e2e-tests/test-applications/nuxt-3/playwright.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const nuxtConfigOptions: ConfigOptions = {
1212
* Like this: import { expect, test } from '@nuxt/test-utils/playwright' */
1313

1414
const config = getPlaywrightConfig({
15-
startCommand: `pnpm preview`,
15+
startCommand: `pnpm start`,
1616
use: { ...nuxtConfigOptions },
1717
});
1818

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This script copies the `import-in-the-middle` content of the E2E test project root `node_modules` to the build output `node_modules`
2+
# For some reason, some files are missing in the output (like `hook.mjs`) and this is not reproducible in external, standalone projects.
3+
#
4+
# Things we tried (that did not fix the problem):
5+
# - Adding a resolution for `@vercel/nft` v0.27.0 (this worked in the standalone project)
6+
# - Also adding `@vercel/nft` v0.27.0 to pnpm `peerDependencyRules`
7+
cp -r node_modules/.pnpm/import-in-the-middle@1.*/node_modules/import-in-the-middle .output/server/node_modules/import-in-the-middle

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

+6
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,10 @@ export default defineNuxtConfig({
1313
},
1414
},
1515
},
16+
nitro: {
17+
rollupConfig: {
18+
// @sentry/... is set external to prevent bundling all of Sentry into the `runtime.mjs` file in the build output
19+
external: [/@sentry\/.*/],
20+
},
21+
},
1622
});

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
"private": true,
44
"type": "module",
55
"scripts": {
6-
"build": "nuxt build",
6+
"build": "nuxt build && bash ./copyIITM.bash",
77
"dev": "nuxt dev",
88
"generate": "nuxt generate",
9-
"preview": "NODE_OPTIONS='--import ./public/instrument.server.mjs' nuxt preview",
9+
"preview": "nuxt preview",
10+
"start": "node --import ./.output/server/sentry.server.config.mjs .output/server/index.mjs",
1011
"clean": "npx nuxi cleanup",
1112
"test": "playwright test",
1213
"test:build": "pnpm install && npx playwright install && pnpm build",
@@ -20,5 +21,8 @@
2021
"@nuxt/test-utils": "^3.14.2",
2122
"@playwright/test": "^1.44.1",
2223
"@sentry-internal/test-utils": "link:../../../test-utils"
24+
},
25+
"overrides": {
26+
"@vercel/nft": "0.27.4"
2327
}
2428
}

dev-packages/e2e-tests/test-applications/nuxt-4/playwright.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const nuxtConfigOptions: ConfigOptions = {
1212
* Like this: import { expect, test } from '@nuxt/test-utils/playwright' */
1313

1414
const config = getPlaywrightConfig({
15-
startCommand: `pnpm preview`,
15+
startCommand: `pnpm start`,
1616
use: { ...nuxtConfigOptions },
1717
});
1818

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

+1-1
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

+1-1
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)