Skip to content

Commit 42e9b23

Browse files
authored
test(e2e): Enable ESM loader test (#12020)
Supersedes #11912 I just cleaned up and renamed this to align with other things
1 parent 13b1897 commit 42e9b23

File tree

34 files changed

+162
-78
lines changed

34 files changed

+162
-78
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ jobs:
10031003
'create-remix-app-express',
10041004
'create-remix-app-express-vite-dev',
10051005
'debug-id-sourcemaps',
1006-
# 'esm-loader-node-express-app', # This is currently broken for upstream reasons. See https://github.com/getsentry/sentry-javascript/pull/11338#issuecomment-2025450675
1006+
'node-express-esm-loader',
10071007
'nextjs-app-dir',
10081008
'nextjs-14',
10091009
'react-create-hash-router',

dev-packages/e2e-tests/test-applications/angular-17/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"test": "playwright test",
1212
"test:build": "pnpm install && npx playwright install && pnpm build",
1313
"test:assert": "playwright test",
14-
"clean": "npx rimraf .angular,node_modules,pnpm-lock.yaml,dist"
14+
"clean": "npx rimraf .angular node_modules pnpm-lock.yaml dist"
1515
},
1616
"private": true,
1717
"dependencies": {

dev-packages/e2e-tests/test-applications/cloudflare-astro/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"astro": "astro",
88
"build": "astro build",
99
"build:bundle": "astro build",
10-
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
10+
"clean": "npx rimraf node_modules pnpm-lock.yaml",
1111
"dev": "astro dev",
1212
"preview": "astro preview",
1313
"start": "astro dev",

dev-packages/e2e-tests/test-applications/create-next-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"scripts": {
66
"build": "next build",
7-
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
7+
"clean": "npx rimraf node_modules pnpm-lock.yaml",
88
"test:prod": "TEST_ENV=prod playwright test",
99
"test:dev": "TEST_ENV=dev playwright test",
1010
"test:build": "pnpm install && npx playwright install && pnpm build",

dev-packages/e2e-tests/test-applications/create-react-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"build": "react-scripts build",
2323
"test": "react-scripts test",
2424
"eject": "react-scripts eject",
25-
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
25+
"clean": "npx rimraf node_modules pnpm-lock.yaml",
2626
"test:build": "pnpm install && pnpm build",
2727
"test:build-ts3.8": "pnpm install && pnpm add typescript@3.8 && pnpm build",
2828
"test:build-canary": "pnpm install && pnpm add react@canary react-dom@canary && pnpm build",

dev-packages/e2e-tests/test-applications/create-remix-app-express-vite-dev/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"lint": "eslint --ignore-path .gitignore --cache --cache-location ./node_modules/.cache/eslint .",
88
"start": "cross-env NODE_ENV=production node ./server.mjs",
99
"typecheck": "tsc",
10-
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
10+
"clean": "npx rimraf node_modules pnpm-lock.yaml",
1111
"test:build": "pnpm install && npx playwright install && pnpm build",
1212
"test:assert": "pnpm playwright test"
1313
},

dev-packages/e2e-tests/test-applications/create-remix-app-express/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"lint": "eslint --ignore-path .gitignore --cache --cache-location ./node_modules/.cache/eslint .",
99
"start": "cross-env NODE_ENV=production node ./server.mjs",
1010
"typecheck": "tsc",
11-
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
11+
"clean": "npx rimraf node_modules pnpm-lock.yaml",
1212
"test:build": "pnpm install && npx playwright install && pnpm build",
1313
"test:assert": "pnpm playwright test"
1414
},

dev-packages/e2e-tests/test-applications/create-remix-app-v2/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"dev": "remix dev",
77
"start": "remix-serve build/index.js",
88
"typecheck": "tsc",
9-
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
9+
"clean": "npx rimraf node_modules pnpm-lock.yaml",
1010
"test:build": "pnpm install && npx playwright install && pnpm build",
1111
"test:assert": "pnpm playwright test"
1212
},

dev-packages/e2e-tests/test-applications/create-remix-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"dev": "remix dev",
77
"start": "remix-serve build",
88
"typecheck": "tsc",
9-
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
9+
"clean": "npx rimraf node_modules pnpm-lock.yaml",
1010
"test:build": "pnpm install && npx playwright install && pnpm build",
1111
"test:assert": "pnpm playwright test"
1212
},

dev-packages/e2e-tests/test-applications/debug-id-sourcemaps/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"build": "rollup --config rollup.config.mjs",
77
"test": "vitest run",
8-
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
8+
"clean": "npx rimraf node_modules pnpm-lock.yaml",
99
"test:build": "pnpm install && pnpm build",
1010
"test:assert": "pnpm test"
1111
},

dev-packages/e2e-tests/test-applications/esm-loader-node-express-app/tests/server.test.ts

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

dev-packages/e2e-tests/test-applications/nextjs-14/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"scripts": {
66
"build": "next build > .tmp_build_stdout 2> .tmp_build_stderr || (cat .tmp_build_stdout && cat .tmp_build_stderr && exit 1)",
7-
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
7+
"clean": "npx rimraf node_modules pnpm-lock.yaml",
88
"test:prod": "TEST_ENV=production playwright test",
99
"test:dev": "TEST_ENV=development playwright test",
1010
"test:build": "pnpm install && npx playwright install && pnpm build",

dev-packages/e2e-tests/test-applications/nextjs-app-dir/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"scripts": {
66
"build": "next build > .tmp_build_stdout 2> .tmp_build_stderr || (cat .tmp_build_stdout && cat .tmp_build_stderr && exit 1)",
7-
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
7+
"clean": "npx rimraf node_modules pnpm-lock.yaml",
88
"test:prod": "TEST_ENV=production playwright test",
99
"test:dev": "TEST_ENV=development playwright test",
1010
"test:build": "pnpm install && npx playwright install && pnpm build",

dev-packages/e2e-tests/test-applications/node-exports-test-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"build": "tsc",
88
"start": "pnpm build && bun run ./dist/consistentExports.js",
99
"test": " bun run ./dist/consistentExports.js",
10-
"clean": "npx rimraf node_modules,pnpm-lock.yaml,dist",
10+
"clean": "npx rimraf node_modules pnpm-lock.yaml dist",
1111
"test:build": "pnpm install && pnpm build",
1212
"test:assert": "pnpm test"
1313
},

dev-packages/e2e-tests/test-applications/esm-loader-node-express-app/package.json renamed to dev-packages/e2e-tests/test-applications/node-express-esm-loader/package.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
{
2-
"name": "node-express-app",
2+
"name": "node-express-esm-loader",
33
"version": "1.0.0",
44
"private": true,
55
"scripts": {
6-
"start": "node --import=@sentry/node/import-hook src/app.mjs",
7-
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
6+
"start": "node --import ./src/instrument.mjs src/app.mjs",
7+
"clean": "npx rimraf node_modules pnpm-lock.yaml",
88
"test:build": "pnpm install",
99
"test:assert": "playwright test"
1010
},
1111
"dependencies": {
1212
"@sentry/node": "latest || *",
13-
"@sentry/types": "latest || *",
14-
"express": "4.19.2",
15-
"@types/express": "4.17.17",
16-
"@types/node": "18.15.1",
17-
"typescript": "4.9.5"
13+
"@sentry/opentelemetry": "latest || *",
14+
"express": "4.19.2"
1815
},
1916
"devDependencies": {
2017
"@sentry-internal/event-proxy-server": "link:../../../event-proxy-server",

dev-packages/e2e-tests/test-applications/esm-loader-node-express-app/playwright.config.ts renamed to dev-packages/e2e-tests/test-applications/node-express-esm-loader/playwright.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ const config: PlaywrightTestConfig = {
5555
{
5656
command: 'node start-event-proxy.mjs',
5757
port: eventProxyPort,
58+
stdout: 'pipe',
59+
stderr: 'pipe',
5860
},
5961
{
6062
command: 'pnpm start',

dev-packages/e2e-tests/test-applications/esm-loader-node-express-app/src/app.mjs renamed to dev-packages/e2e-tests/test-applications/node-express-esm-loader/src/app.mjs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
import * as Sentry from '@sentry/node';
2-
3-
Sentry.init({
4-
environment: 'qa', // dynamic sampling bias to keep transactions
5-
dsn: process.env.E2E_TEST_DSN,
6-
debug: true,
7-
tunnel: `http://localhost:3031/`, // proxy server
8-
tracesSampleRate: 1,
9-
});
1+
// @ts-check
102

3+
import * as Sentry from '@sentry/node';
114
import express from 'express';
125

136
const app = express();
@@ -36,7 +29,6 @@ app.get('/test-error', function (req, res) {
3629

3730
Sentry.setupExpressErrorHandler(app);
3831

39-
// @ts-ignore
4032
app.use(function onError(err, req, res, next) {
4133
// The error id is attached to `res.sentry` to be returned
4234
// and optionally displayed to the user for support.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as Sentry from '@sentry/node';
2+
3+
Sentry.init({
4+
environment: 'qa', // dynamic sampling bias to keep transactions
5+
dsn: process.env.E2E_TEST_DSN,
6+
tunnel: `http://localhost:3031/`, // proxy server
7+
tracesSampleRate: 1,
8+
});

dev-packages/e2e-tests/test-applications/esm-loader-node-express-app/start-event-proxy.mjs renamed to dev-packages/e2e-tests/test-applications/node-express-esm-loader/start-event-proxy.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import { startEventProxyServer } from '@sentry-internal/event-proxy-server';
22

33
startEventProxyServer({
44
port: 3031,
5-
proxyServerName: 'esm-loader-node-express-app',
5+
proxyServerName: 'node-express-esm-loader',
66
});
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import { expect, test } from '@playwright/test';
2+
import { waitForError, waitForTransaction } from '@sentry-internal/event-proxy-server';
3+
4+
test('Should record exceptions captured inside handlers', async ({ request }) => {
5+
const errorEventPromise = waitForError('node-express-esm-loader', errorEvent => {
6+
return !!errorEvent?.exception?.values?.[0]?.value?.includes('This is an error');
7+
});
8+
9+
await request.get('/test-error');
10+
11+
await expect(errorEventPromise).resolves.toBeDefined();
12+
});
13+
14+
test('Should record a transaction for a parameterless route', async ({ request }) => {
15+
const transactionEventPromise = waitForTransaction('node-express-esm-loader', transactionEvent => {
16+
return transactionEvent?.transaction === 'GET /test-success';
17+
});
18+
19+
await request.get('/test-success');
20+
21+
await expect(transactionEventPromise).resolves.toBeDefined();
22+
});
23+
24+
test('Should record a transaction for route with parameters', async ({ request }) => {
25+
const transactionEventPromise = waitForTransaction('node-express-esm-loader', transactionEvent => {
26+
return transactionEvent.contexts?.trace?.data?.['http.target'] === '/test-transaction/1';
27+
});
28+
29+
await request.get('/test-transaction/1');
30+
31+
const transactionEvent = await transactionEventPromise;
32+
33+
expect(transactionEvent).toBeDefined();
34+
expect(transactionEvent.transaction).toEqual('GET /test-transaction/:param');
35+
expect(transactionEvent.contexts?.trace?.data).toEqual(
36+
expect.objectContaining({
37+
'http.flavor': '1.1',
38+
'http.host': 'localhost:3030',
39+
'http.method': 'GET',
40+
'http.response.status_code': 200,
41+
'http.route': '/test-transaction/:param',
42+
'http.scheme': 'http',
43+
'http.status_code': 200,
44+
'http.status_text': 'OK',
45+
'http.target': '/test-transaction/1',
46+
'http.url': 'http://localhost:3030/test-transaction/1',
47+
'http.user_agent': expect.any(String),
48+
'net.host.ip': expect.any(String),
49+
'net.host.name': 'localhost',
50+
'net.host.port': 3030,
51+
'net.peer.ip': expect.any(String),
52+
'net.peer.port': expect.any(Number),
53+
'net.transport': 'ip_tcp',
54+
'otel.kind': 'SERVER',
55+
'sentry.op': 'http.server',
56+
'sentry.origin': 'auto.http.otel.http',
57+
'sentry.sample_rate': 1,
58+
'sentry.source': 'route',
59+
url: 'http://localhost:3030/test-transaction/1',
60+
}),
61+
);
62+
63+
const spans = transactionEvent.spans || [];
64+
expect(spans).toContainEqual({
65+
data: {
66+
'express.name': 'query',
67+
'express.type': 'middleware',
68+
'http.route': '/',
69+
'otel.kind': 'INTERNAL',
70+
'sentry.origin': 'auto.http.otel.express',
71+
},
72+
description: 'middleware - query',
73+
origin: 'auto.http.otel.express',
74+
parent_span_id: expect.any(String),
75+
span_id: expect.any(String),
76+
start_timestamp: expect.any(Number),
77+
status: 'ok',
78+
timestamp: expect.any(Number),
79+
trace_id: expect.any(String),
80+
});
81+
82+
expect(spans).toContainEqual({
83+
data: {
84+
'express.name': 'expressInit',
85+
'express.type': 'middleware',
86+
'http.route': '/',
87+
'otel.kind': 'INTERNAL',
88+
'sentry.origin': 'auto.http.otel.express',
89+
},
90+
description: 'middleware - expressInit',
91+
origin: 'auto.http.otel.express',
92+
parent_span_id: expect.any(String),
93+
span_id: expect.any(String),
94+
start_timestamp: expect.any(Number),
95+
status: 'ok',
96+
timestamp: expect.any(Number),
97+
trace_id: expect.any(String),
98+
});
99+
100+
expect(spans).toContainEqual({
101+
data: {
102+
'express.name': '/test-transaction/:param',
103+
'express.type': 'request_handler',
104+
'http.route': '/test-transaction/:param',
105+
'otel.kind': 'INTERNAL',
106+
'sentry.origin': 'auto.http.otel.express',
107+
},
108+
description: 'request handler - /test-transaction/:param',
109+
origin: 'auto.http.otel.express',
110+
parent_span_id: expect.any(String),
111+
span_id: expect.any(String),
112+
start_timestamp: expect.any(Number),
113+
status: 'ok',
114+
timestamp: expect.any(Number),
115+
trace_id: expect.any(String),
116+
});
117+
});

dev-packages/e2e-tests/test-applications/node-express/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"build": "tsc",
77
"start": "node dist/app.js",
88
"test": "playwright test",
9-
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
9+
"clean": "npx rimraf node_modules pnpm-lock.yaml",
1010
"test:build": "pnpm install && pnpm build",
1111
"test:assert": "pnpm test"
1212
},

dev-packages/e2e-tests/test-applications/node-hapi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"build": "tsc",
77
"start": "node src/app.js",
88
"test": "playwright test",
9-
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
9+
"clean": "npx rimraf node_modules pnpm-lock.yaml",
1010
"test:build": "pnpm install",
1111
"test:assert": "pnpm test"
1212
},

dev-packages/e2e-tests/test-applications/node-koa/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"start": "node index.js",
77
"test": "playwright test",
8-
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
8+
"clean": "npx rimraf node_modules pnpm-lock.yaml",
99
"test:build": "pnpm install",
1010
"test:assert": "pnpm test"
1111
},

dev-packages/e2e-tests/test-applications/node-nestjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"start:dev": "nest start --watch",
1010
"start:debug": "nest start --debug --watch",
1111
"start:prod": "node dist/main",
12-
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
12+
"clean": "npx rimraf node_modules pnpm-lock.yaml",
1313
"test": "playwright test",
1414
"test:build": "pnpm install",
1515
"test:assert": "pnpm test"

dev-packages/e2e-tests/test-applications/react-create-hash-router/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"build": "react-scripts build",
2323
"start": "serve -s build",
2424
"test": "playwright test",
25-
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
25+
"clean": "npx rimraf node_modules pnpm-lock.yaml",
2626
"test:build": "pnpm install && npx playwright install && pnpm build",
2727
"test:build-canary": "pnpm install && pnpm add react@canary react-dom@canary && npx playwright install && pnpm build",
2828
"test:assert": "pnpm test"

dev-packages/e2e-tests/test-applications/react-router-5/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"build": "react-scripts build",
2727
"start": "serve -s build",
2828
"test": "playwright test",
29-
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
29+
"clean": "npx rimraf node_modules pnpm-lock.yaml",
3030
"test:build": "pnpm install && npx playwright install && pnpm build",
3131
"test:assert": "pnpm test"
3232
},

0 commit comments

Comments
 (0)