Skip to content

Commit 5901dba

Browse files
committed
add e2e test app
1 parent b5036f2 commit 5901dba

File tree

9 files changed

+187
-0
lines changed

9 files changed

+187
-0
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,7 @@ jobs:
993993
[
994994
'angular-17',
995995
'angular-18',
996+
'aws-lambda-layer',
996997
'cloudflare-astro',
997998
'node-express',
998999
'create-react-app',
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@sentry:registry=http://127.0.0.1:4873
2+
@sentry-internal:registry=http://127.0.0.1:4873
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "node-express-app",
3+
"version": "1.0.0",
4+
"private": true,
5+
"scripts": {
6+
"copy:layer": "cp -r ./../../../../packages/aws-serverless/build/aws/dist-serverless/nodejs/node_modules/ ./node_modules",
7+
"start": "node src/run.js",
8+
"test": "playwright test",
9+
"clean": "npx rimraf node_modules pnpm-lock.yaml",
10+
"test:build": "pnpm install && pnpm copy:layer",
11+
"test:assert": "pnpm test"
12+
},
13+
"dependencies": {
14+
},
15+
"devDependencies": {
16+
"@sentry-internal/event-proxy-server": "link:../../../event-proxy-server",
17+
"@playwright/test": "^1.41.1",
18+
"wait-port": "1.0.4"
19+
},
20+
"volta": {
21+
"extends": "../../package.json"
22+
}
23+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import type { PlaywrightTestConfig } from '@playwright/test';
2+
import { devices } from '@playwright/test';
3+
4+
// Fix urls not resolving to localhost on Node v17+
5+
// See: https://github.com/axios/axios/issues/3821#issuecomment-1413727575
6+
import { setDefaultResultOrder } from 'dns';
7+
setDefaultResultOrder('ipv4first');
8+
9+
const eventProxyPort = 3031;
10+
const lambdaPort = 3030;
11+
12+
/**
13+
* See https://playwright.dev/docs/test-configuration.
14+
*/
15+
const config: PlaywrightTestConfig = {
16+
testDir: './tests',
17+
/* Maximum time one test can run for. */
18+
timeout: 150_000,
19+
expect: {
20+
/**
21+
* Maximum time expect() should wait for the condition to be met.
22+
* For example in `await expect(locator).toHaveText();`
23+
*/
24+
timeout: 5000,
25+
},
26+
/* Run tests in files in parallel */
27+
fullyParallel: true,
28+
/* Fail the build on CI if you accidentally left test.only in the source code. */
29+
forbidOnly: !!process.env.CI,
30+
/* Retry on CI only */
31+
retries: 0,
32+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
33+
reporter: 'list',
34+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
35+
use: {
36+
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
37+
actionTimeout: 0,
38+
39+
/* Base URL to use in actions like `await page.goto('/')`. */
40+
baseURL: `http://localhost:${lambdaPort}`,
41+
42+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
43+
trace: 'on-first-retry',
44+
},
45+
46+
/* Configure projects for major browsers */
47+
projects: [
48+
{
49+
name: 'chromium',
50+
use: {
51+
...devices['Desktop Chrome'],
52+
},
53+
},
54+
// For now we only test Chrome!
55+
// {
56+
// name: 'firefox',
57+
// use: {
58+
// ...devices['Desktop Firefox'],
59+
// },
60+
// },
61+
// {
62+
// name: 'webkit',
63+
// use: {
64+
// ...devices['Desktop Safari'],
65+
// },
66+
// },
67+
],
68+
69+
/* Run your local dev server before starting the tests */
70+
webServer: [
71+
{
72+
command: `node start-event-proxy.mjs && pnpm wait-port ${eventProxyPort}`,
73+
port: eventProxyPort,
74+
stdout: 'pipe',
75+
},
76+
],
77+
};
78+
79+
export default config;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const Sentry = require('@sentry/aws-serverless');
2+
3+
const http = require('http');
4+
5+
function handle() {
6+
Sentry.startSpanManual({ name: 'aws-lambda-layer-test-txn', op: 'test' }, span => {
7+
http.get('http://example.com', res => {
8+
res.on('data', d => {
9+
process.stdout.write(d);
10+
});
11+
12+
res.on('end', () => {
13+
span.end();
14+
});
15+
});
16+
});
17+
}
18+
19+
module.exports = { handle };
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const { handle } = require('./lambda-function');
2+
handle();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const child_process = require('child_process');
2+
3+
child_process.execSync('node ./src/run-lambda.js', {
4+
stdio: 'inherit',
5+
env: {
6+
...process.env,
7+
LAMBDA_TASK_ROOT: '.',
8+
_HANDLER: 'handle',
9+
10+
NODE_OPTIONS: '--require @sentry/aws-serverless/dist/awslambda-auto',
11+
SENTRY_DSN: 'http://public@localhost:3031/1337',
12+
SENTRY_TRACES_SAMPLE_RATE: '1.0',
13+
SENTRY_DEBUG: 'true',
14+
},
15+
cwd: process.cwd(),
16+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { startEventProxyServer } from '@sentry-internal/event-proxy-server';
2+
3+
console.log('start proxy server');
4+
5+
startEventProxyServer({
6+
port: 3031,
7+
proxyServerName: 'aws-serverless-lambda-layer',
8+
forwardToSentry: false,
9+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import * as child_process from 'child_process';
2+
import { expect, test } from '@playwright/test';
3+
import { waitForTransaction } from '@sentry-internal/event-proxy-server';
4+
5+
test('Lambda layer SDK bundle sends events', async ({ request }) => {
6+
const transactionEventPromise = waitForTransaction('aws-serverless-lambda-layer', transactionEvent => {
7+
return transactionEvent?.transaction === 'aws-lambda-layer-test-txn';
8+
});
9+
10+
await new Promise<void>(resolve =>
11+
setTimeout(() => {
12+
resolve();
13+
}, 1000),
14+
);
15+
16+
child_process.execSync('pnpm start', {
17+
stdio: 'ignore',
18+
});
19+
20+
const transactionEvent = await transactionEventPromise;
21+
22+
// shows the SDK sent a transaction
23+
expect(transactionEvent.transaction).toEqual('aws-lambda-layer-test-txn');
24+
25+
// shows that the Otel Http instrumentation is working
26+
expect(transactionEvent.spans).toHaveLength(1);
27+
expect(transactionEvent.spans![0]).toMatchObject({
28+
data: expect.objectContaining({
29+
'sentry.op': 'http.client',
30+
'sentry.origin': 'auto.http.otel.http',
31+
url: 'http://example.com/',
32+
}),
33+
description: 'GET http://example.com/',
34+
op: 'http.client',
35+
});
36+
});

0 commit comments

Comments
 (0)