Skip to content

Commit 9eb5827

Browse files
committed
Use locally built serverless package instead of pulling from npm in e2e tests
1 parent 5baa31d commit 9eb5827

File tree

1 file changed

+32
-3
lines changed
  • dev-packages/e2e-tests/test-applications/aws-serverless/src

1 file changed

+32
-3
lines changed

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

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const LAMBDA_FUNCTIONS_WITH_LAYER_DIR = './src/lambda-functions-layer';
1212
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/';
15+
const WORKSPACE_AWS_SERVERLESS_DIR = path.resolve(__dirname, '../../../../packages/aws-serverless');
1516
const DEFAULT_NODE_VERSION = '22';
1617
export const SAM_PORT = 3001;
1718

@@ -67,10 +68,38 @@ export class LocalLambdaStack extends Stack {
6768
const functionName = `${addLayer ? 'Layer' : 'Npm'}${lambdaDir}`;
6869

6970
if (!addLayer) {
71+
const lambdaPath = path.resolve(functionsDir, lambdaDir);
72+
const packageLockPath = path.join(lambdaPath, 'package-lock.json');
73+
const nodeModulesPath = path.join(lambdaPath, 'node_modules');
74+
// Point the dependency at the locally built aws-serverless package so tests use the current workspace bits
75+
if (!fs.existsSync(WORKSPACE_AWS_SERVERLESS_DIR)) {
76+
throw new Error(
77+
`[LocalLambdaStack] Workspace aws-serverless package not found at ${WORKSPACE_AWS_SERVERLESS_DIR}. Did you run the build?`,
78+
);
79+
}
80+
const localAwsServerlessPath = path.relative(lambdaPath, WORKSPACE_AWS_SERVERLESS_DIR);
81+
const dependencyPath = localAwsServerlessPath.replace(/\\/g, '/');
82+
7083
console.log(`[LocalLambdaStack] Install dependencies for ${functionName}`);
71-
const packageJson = { dependencies: { '@sentry/aws-serverless': '* || latest' } };
72-
fs.writeFileSync(path.join(functionsDir, lambdaDir, 'package.json'), JSON.stringify(packageJson, null, 2));
73-
execFileSync('npm', ['install', '--prefix', path.join(functionsDir, lambdaDir)], { stdio: 'inherit' });
84+
85+
if (fs.existsSync(packageLockPath)) {
86+
// Prevent stale lock files from pinning the published package version
87+
fs.rmSync(packageLockPath);
88+
}
89+
90+
if (fs.existsSync(nodeModulesPath)) {
91+
// Ensure we reinstall from the workspace instead of reusing cached dependencies
92+
fs.rmSync(nodeModulesPath, { recursive: true, force: true });
93+
}
94+
95+
const packageJson = {
96+
dependencies: {
97+
'@sentry/aws-serverless': `file:${dependencyPath}`,
98+
},
99+
};
100+
101+
fs.writeFileSync(path.join(lambdaPath, 'package.json'), JSON.stringify(packageJson, null, 2));
102+
execFileSync('npm', ['install', '--prefix', lambdaPath], { stdio: 'inherit' });
74103
}
75104

76105
new CfnResource(this, functionName, {

0 commit comments

Comments
 (0)