Skip to content

Commit 9e07d7e

Browse files
committed
test(aws): Run E2E tests in all supported Node versions
1 parent 444bd82 commit 9e07d7e

File tree

5 files changed

+58
-28
lines changed

5 files changed

+58
-28
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ jobs:
965965
- name: Run E2E test
966966
working-directory: ${{ runner.temp }}/test-application
967967
timeout-minutes: 10
968-
run: pnpm test:assert
968+
run: ${{ matrix.assert-command || 'pnpm test:assert' }}
969969

970970
- name: Upload Playwright Traces
971971
uses: actions/upload-artifact@v4
@@ -1086,7 +1086,7 @@ jobs:
10861086
- name: Run E2E test
10871087
working-directory: ${{ runner.temp }}/test-application
10881088
timeout-minutes: 10
1089-
run: pnpm ${{ matrix.assert-command || 'test:assert' }}
1089+
run: ${{ matrix.assert-command || 'pnpm test:assert' }}
10901090

10911091
- name: Pre-process E2E Test Dumps
10921092
if: failure()

dev-packages/e2e-tests/test-applications/aws-serverless/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,19 @@
2323
},
2424
"volta": {
2525
"extends": "../../package.json"
26+
},
27+
"sentryTest": {
28+
"variants": [
29+
{
30+
"build-command": "NODE_VERSION=20 ./pull-sam-image.sh && pnpm test:build",
31+
"assert-command": "NODE_VERSION=20 pnpm test:assert",
32+
"label": "aws-serverless (Node 20)"
33+
},
34+
{
35+
"build-command": "NODE_VERSION=18 ./pull-sam-image.sh && pnpm test:build",
36+
"assert-command": "NODE_VERSION=18 pnpm test:assert",
37+
"label": "aws-serverless (Node 18)"
38+
}
39+
]
2640
}
2741
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
# Script to pull the correct SAM docker image based on the NODE_VERSION environment variable.
4+
5+
set -e
6+
7+
if [[ -z "$NODE_VERSION" ]]; then
8+
echo "Error: NODE_VERSION not set"
9+
exit 1
10+
fi
11+
12+
echo "Pulling SAM Node $NODE_VERSION docker image..."
13+
docker pull --platform linux/amd64 "public.ecr.aws/sam/build-nodejs${NODE_VERSION}.x:latest"
14+
15+
echo "Successfully pulled SAM Node $NODE_VERSION docker image"

dev-packages/e2e-tests/test-applications/aws-serverless/src/stack.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const LAMBDA_FUNCTIONS_WITH_NPM_DIR = './src/lambda-functions-npm';
1313
const LAMBDA_FUNCTION_TIMEOUT = 10;
1414
const LAYER_DIR = './node_modules/@sentry/aws-serverless/';
1515
export const SAM_PORT = 3001;
16-
const NODE_RUNTIME = `nodejs${process.version.split('.').at(0)?.replace('v', '')}.x`;
1716

1817
export class LocalLambdaStack extends Stack {
1918
sentryLayer: CfnResource;
@@ -73,22 +72,20 @@ export class LocalLambdaStack extends Stack {
7372
execFileSync('npm', ['install', '--prefix', path.join(functionsDir, lambdaDir)], { stdio: 'inherit' });
7473
}
7574

76-
const isEsm = fs.existsSync(path.join(functionsDir, lambdaDir, 'index.mjs'));
77-
7875
new CfnResource(this, functionName, {
7976
type: 'AWS::Serverless::Function',
8077
properties: {
8178
CodeUri: path.join(functionsDir, lambdaDir),
8279
Handler: 'index.handler',
83-
Runtime: NODE_RUNTIME,
80+
Runtime: `nodejs${process.env.NODE_VERSION ?? '22'}.x`,
8481
Timeout: LAMBDA_FUNCTION_TIMEOUT,
8582
Layers: addLayer ? [{ Ref: this.sentryLayer.logicalId }] : undefined,
8683
Environment: {
8784
Variables: {
8885
SENTRY_DSN: dsn,
8986
SENTRY_TRACES_SAMPLE_RATE: 1.0,
9087
SENTRY_DEBUG: true,
91-
NODE_OPTIONS: `--${isEsm ? 'import' : 'require'}=@sentry/aws-serverless/awslambda-auto`,
88+
NODE_OPTIONS: `--import=@sentry/aws-serverless/awslambda-auto`,
9289
},
9390
},
9491
},

dev-packages/e2e-tests/test-applications/aws-serverless/tests/lambda-fixtures.ts

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,27 @@ export const test = base.extend<{ testEnvironment: LocalLambdaStack; lambdaClien
2929
const debugLog = tmp.fileSync({ prefix: 'sentry_aws_lambda_tests_sam_debug', postfix: '.log' });
3030
console.log(`[test_environment fixture] Writing SAM debug log to: ${debugLog.name}`);
3131

32-
const process = spawn(
33-
'sam',
34-
[
35-
'local',
36-
'start-lambda',
37-
'--debug',
38-
'--template',
39-
SAM_TEMPLATE_FILE,
40-
'--warm-containers',
41-
'EAGER',
42-
'--docker-network',
43-
DOCKER_NETWORK_NAME,
44-
],
45-
{
46-
stdio: ['ignore', debugLog.fd, debugLog.fd],
47-
},
48-
);
32+
const args = [
33+
'local',
34+
'start-lambda',
35+
'--debug',
36+
'--template',
37+
SAM_TEMPLATE_FILE,
38+
'--warm-containers',
39+
'EAGER',
40+
'--docker-network',
41+
DOCKER_NETWORK_NAME,
42+
];
43+
44+
if (process.env.NODE_VERSION) {
45+
args.push('--invoke-image', `public.ecr.aws/sam/build-nodejs${process.env.NODE_VERSION}.x:latest`);
46+
}
47+
48+
console.log(`[testEnvironment fixture] Running SAM with args: ${args.join(' ')}`);
49+
50+
const samProcess = spawn('sam', args, {
51+
stdio: ['ignore', debugLog.fd, debugLog.fd],
52+
});
4953

5054
try {
5155
await LocalLambdaStack.waitForStack();
@@ -54,12 +58,12 @@ export const test = base.extend<{ testEnvironment: LocalLambdaStack; lambdaClien
5458
} finally {
5559
console.log('[testEnvironment fixture] Tearing down AWS Lambda test infrastructure');
5660

57-
process.kill('SIGTERM');
61+
samProcess.kill('SIGTERM');
5862
await new Promise(resolve => {
59-
process.once('exit', resolve);
63+
samProcess.once('exit', resolve);
6064
setTimeout(() => {
61-
if (!process.killed) {
62-
process.kill('SIGKILL');
65+
if (!samProcess.killed) {
66+
samProcess.kill('SIGKILL');
6367
}
6468
resolve(void 0);
6569
}, 5000);

0 commit comments

Comments
 (0)