Skip to content

test(e2e): Enable ESM loader test #12020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ jobs:
'create-remix-app-express',
'create-remix-app-express-vite-dev',
'debug-id-sourcemaps',
# 'esm-loader-node-express-app', # This is currently broken for upstream reasons. See https://github.com/getsentry/sentry-javascript/pull/11338#issuecomment-2025450675
'node-express-esm-loader',
'nextjs-app-dir',
'nextjs-14',
'react-create-hash-router',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"test": "playwright test",
"test:build": "pnpm install && npx playwright install && pnpm build",
"test:assert": "playwright test",
"clean": "npx rimraf .angular,node_modules,pnpm-lock.yaml,dist"
"clean": "npx rimraf .angular node_modules pnpm-lock.yaml dist"
},
"private": true,
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"astro": "astro",
"build": "astro build",
"build:bundle": "astro build",
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
"clean": "npx rimraf node_modules pnpm-lock.yaml",
"dev": "astro dev",
"preview": "astro preview",
"start": "astro dev",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"build": "next build",
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
"clean": "npx rimraf node_modules pnpm-lock.yaml",
"test:prod": "TEST_ENV=prod playwright test",
"test:dev": "TEST_ENV=dev playwright test",
"test:build": "pnpm install && npx playwright install && pnpm build",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
"clean": "npx rimraf node_modules pnpm-lock.yaml",
"test:build": "pnpm install && pnpm build",
"test:build-ts3.8": "pnpm install && pnpm add [email protected] && pnpm build",
"test:build-canary": "pnpm install && pnpm add react@canary react-dom@canary && pnpm build",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"lint": "eslint --ignore-path .gitignore --cache --cache-location ./node_modules/.cache/eslint .",
"start": "cross-env NODE_ENV=production node ./server.mjs",
"typecheck": "tsc",
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
"clean": "npx rimraf node_modules pnpm-lock.yaml",
"test:build": "pnpm install && npx playwright install && pnpm build",
"test:assert": "pnpm playwright test"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"lint": "eslint --ignore-path .gitignore --cache --cache-location ./node_modules/.cache/eslint .",
"start": "cross-env NODE_ENV=production node ./server.mjs",
"typecheck": "tsc",
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
"clean": "npx rimraf node_modules pnpm-lock.yaml",
"test:build": "pnpm install && npx playwright install && pnpm build",
"test:assert": "pnpm playwright test"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dev": "remix dev",
"start": "remix-serve build/index.js",
"typecheck": "tsc",
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
"clean": "npx rimraf node_modules pnpm-lock.yaml",
"test:build": "pnpm install && npx playwright install && pnpm build",
"test:assert": "pnpm playwright test"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dev": "remix dev",
"start": "remix-serve build",
"typecheck": "tsc",
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
"clean": "npx rimraf node_modules pnpm-lock.yaml",
"test:build": "pnpm install && npx playwright install && pnpm build",
"test:assert": "pnpm playwright test"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"build": "rollup --config rollup.config.mjs",
"test": "vitest run",
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
"clean": "npx rimraf node_modules pnpm-lock.yaml",
"test:build": "pnpm install && pnpm build",
"test:assert": "pnpm test"
},
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"build": "next build > .tmp_build_stdout 2> .tmp_build_stderr || (cat .tmp_build_stdout && cat .tmp_build_stderr && exit 1)",
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
"clean": "npx rimraf node_modules pnpm-lock.yaml",
"test:prod": "TEST_ENV=production playwright test",
"test:dev": "TEST_ENV=development playwright test",
"test:build": "pnpm install && npx playwright install && pnpm build",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"build": "next build > .tmp_build_stdout 2> .tmp_build_stderr || (cat .tmp_build_stdout && cat .tmp_build_stderr && exit 1)",
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
"clean": "npx rimraf node_modules pnpm-lock.yaml",
"test:prod": "TEST_ENV=production playwright test",
"test:dev": "TEST_ENV=development playwright test",
"test:build": "pnpm install && npx playwright install && pnpm build",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"build": "tsc",
"start": "pnpm build && bun run ./dist/consistentExports.js",
"test": " bun run ./dist/consistentExports.js",
"clean": "npx rimraf node_modules,pnpm-lock.yaml,dist",
"clean": "npx rimraf node_modules pnpm-lock.yaml dist",
"test:build": "pnpm install && pnpm build",
"test:assert": "pnpm test"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
{
"name": "node-express-app",
"name": "node-express-esm-loader",
"version": "1.0.0",
"private": true,
"scripts": {
"start": "node --import=@sentry/node/import-hook src/app.mjs",
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
"start": "node --import ./src/instrument.mjs src/app.mjs",
"clean": "npx rimraf node_modules pnpm-lock.yaml",
"test:build": "pnpm install",
"test:assert": "playwright test"
},
"dependencies": {
"@sentry/node": "latest || *",
"@sentry/types": "latest || *",
"express": "4.19.2",
"@types/express": "4.17.17",
"@types/node": "18.15.1",
"typescript": "4.9.5"
"@sentry/opentelemetry": "latest || *",
"express": "4.19.2"
},
"devDependencies": {
"@sentry-internal/event-proxy-server": "link:../../../event-proxy-server",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ const config: PlaywrightTestConfig = {
{
command: 'node start-event-proxy.mjs',
port: eventProxyPort,
stdout: 'pipe',
stderr: 'pipe',
},
{
command: 'pnpm start',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import * as Sentry from '@sentry/node';

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: process.env.E2E_TEST_DSN,
debug: true,
tunnel: `http://localhost:3031/`, // proxy server
tracesSampleRate: 1,
});
// @ts-check

import * as Sentry from '@sentry/node';
import express from 'express';

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

Sentry.setupExpressErrorHandler(app);

// @ts-ignore
app.use(function onError(err, req, res, next) {
// The error id is attached to `res.sentry` to be returned
// and optionally displayed to the user for support.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as Sentry from '@sentry/node';

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: process.env.E2E_TEST_DSN,
tunnel: `http://localhost:3031/`, // proxy server
tracesSampleRate: 1,
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { startEventProxyServer } from '@sentry-internal/event-proxy-server';

startEventProxyServer({
port: 3031,
proxyServerName: 'esm-loader-node-express-app',
proxyServerName: 'node-express-esm-loader',
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { expect, test } from '@playwright/test';
import { waitForError, waitForTransaction } from '@sentry-internal/event-proxy-server';

test('Should record exceptions captured inside handlers', async ({ request }) => {
const errorEventPromise = waitForError('node-express-esm-loader', errorEvent => {
return !!errorEvent?.exception?.values?.[0]?.value?.includes('This is an error');
});

await request.get('/test-error');

await expect(errorEventPromise).resolves.toBeDefined();
});

test('Should record a transaction for a parameterless route', async ({ request }) => {
const transactionEventPromise = waitForTransaction('node-express-esm-loader', transactionEvent => {
return transactionEvent?.transaction === 'GET /test-success';
});

await request.get('/test-success');

await expect(transactionEventPromise).resolves.toBeDefined();
});

test('Should record a transaction for route with parameters', async ({ request }) => {
const transactionEventPromise = waitForTransaction('node-express-esm-loader', transactionEvent => {
return transactionEvent.contexts?.trace?.data?.['http.target'] === '/test-transaction/1';
});

await request.get('/test-transaction/1');

const transactionEvent = await transactionEventPromise;

expect(transactionEvent).toBeDefined();
expect(transactionEvent.transaction).toEqual('GET /test-transaction/:param');
expect(transactionEvent.contexts?.trace?.data).toEqual(
expect.objectContaining({
'http.flavor': '1.1',
'http.host': 'localhost:3030',
'http.method': 'GET',
'http.response.status_code': 200,
'http.route': '/test-transaction/:param',
'http.scheme': 'http',
'http.status_code': 200,
'http.status_text': 'OK',
'http.target': '/test-transaction/1',
'http.url': 'http://localhost:3030/test-transaction/1',
'http.user_agent': expect.any(String),
'net.host.ip': expect.any(String),
'net.host.name': 'localhost',
'net.host.port': 3030,
'net.peer.ip': expect.any(String),
'net.peer.port': expect.any(Number),
'net.transport': 'ip_tcp',
'otel.kind': 'SERVER',
'sentry.op': 'http.server',
'sentry.origin': 'auto.http.otel.http',
'sentry.sample_rate': 1,
'sentry.source': 'route',
url: 'http://localhost:3030/test-transaction/1',
}),
);

const spans = transactionEvent.spans || [];
expect(spans).toContainEqual({
data: {
'express.name': 'query',
'express.type': 'middleware',
'http.route': '/',
'otel.kind': 'INTERNAL',
'sentry.origin': 'auto.http.otel.express',
},
description: 'middleware - query',
origin: 'auto.http.otel.express',
parent_span_id: expect.any(String),
span_id: expect.any(String),
start_timestamp: expect.any(Number),
status: 'ok',
timestamp: expect.any(Number),
trace_id: expect.any(String),
});

expect(spans).toContainEqual({
data: {
'express.name': 'expressInit',
'express.type': 'middleware',
'http.route': '/',
'otel.kind': 'INTERNAL',
'sentry.origin': 'auto.http.otel.express',
},
description: 'middleware - expressInit',
origin: 'auto.http.otel.express',
parent_span_id: expect.any(String),
span_id: expect.any(String),
start_timestamp: expect.any(Number),
status: 'ok',
timestamp: expect.any(Number),
trace_id: expect.any(String),
});

expect(spans).toContainEqual({
data: {
'express.name': '/test-transaction/:param',
'express.type': 'request_handler',
'http.route': '/test-transaction/:param',
'otel.kind': 'INTERNAL',
'sentry.origin': 'auto.http.otel.express',
},
description: 'request handler - /test-transaction/:param',
origin: 'auto.http.otel.express',
parent_span_id: expect.any(String),
span_id: expect.any(String),
start_timestamp: expect.any(Number),
status: 'ok',
timestamp: expect.any(Number),
trace_id: expect.any(String),
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"build": "tsc",
"start": "node dist/app.js",
"test": "playwright test",
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
"clean": "npx rimraf node_modules pnpm-lock.yaml",
"test:build": "pnpm install && pnpm build",
"test:assert": "pnpm test"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"build": "tsc",
"start": "node src/app.js",
"test": "playwright test",
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
"clean": "npx rimraf node_modules pnpm-lock.yaml",
"test:build": "pnpm install",
"test:assert": "pnpm test"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"start": "node index.js",
"test": "playwright test",
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
"clean": "npx rimraf node_modules pnpm-lock.yaml",
"test:build": "pnpm install",
"test:assert": "pnpm test"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
"clean": "npx rimraf node_modules pnpm-lock.yaml",
"test": "playwright test",
"test:build": "pnpm install",
"test:assert": "pnpm test"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"build": "react-scripts build",
"start": "serve -s build",
"test": "playwright test",
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
"clean": "npx rimraf node_modules pnpm-lock.yaml",
"test:build": "pnpm install && npx playwright install && pnpm build",
"test:build-canary": "pnpm install && pnpm add react@canary react-dom@canary && npx playwright install && pnpm build",
"test:assert": "pnpm test"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"build": "react-scripts build",
"start": "serve -s build",
"test": "playwright test",
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
"clean": "npx rimraf node_modules pnpm-lock.yaml",
"test:build": "pnpm install && npx playwright install && pnpm build",
"test:assert": "pnpm test"
},
Expand Down
Loading
Loading