Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Jul 20, 2023
2 parents d4ceaab + 64e4f41 commit 4a113fd
Show file tree
Hide file tree
Showing 29 changed files with 123 additions and 265 deletions.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`esbuild bundling with esbuild options 1`] = `
""use strict";
(() => {
// aws-lambda-nodejs/test/integ-handlers/define.ts
// aws-lambda-nodejs/test/handlers/define.ts
function handler() {
return [
"VALUE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ test('esbuild bundling with esbuild options', () => {
});

// Make sure that the define instructions are working as expected with the esbuild CLI
const bundleProcess = util.exec('bash', ['-c', `npx esbuild --bundle ${`${__dirname}/integ-handlers/define.ts`} ${defineInstructions}`]);
const bundleProcess = util.exec('bash', ['-c', `npx esbuild --bundle ${`${__dirname}/handlers/define.ts`} ${defineInstructions}`]);
expect(bundleProcess.stdout.toString()).toMatchSnapshot();
});

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

46 changes: 37 additions & 9 deletions packages/aws-cdk-lib/aws-lambda-nodejs/test/function.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as fs from 'fs';
import * as path from 'path';
import { bockfs } from '@aws-cdk/cdk-build-tools';
import { Template, Match } from '../../assertions';
import { Vpc } from '../../aws-ec2';
import { CodeConfig, Runtime } from '../../aws-lambda';
Expand All @@ -25,12 +24,45 @@ jest.mock('../lib/bundling', () => {
};
});

const mockCallsites = jest.fn();
jest.mock('../lib/util', () => ({
...jest.requireActual('../lib/util'),
callsites: () => mockCallsites(),
}));

let stack: Stack;
beforeEach(() => {
stack = new Stack();
jest.clearAllMocks();
});

// We MUST use a fake file system here.
// Using the real filesystem causes the tests to be flaky and fail at random.
// This way we are guaranteed to have the fake files setup on each test run.
bockfs({
'/home/project/package.json': '{}',
'/home/project/package-lock.json': '{}',
'/home/project/handler.tsx': '// nothing',
'/home/project/function.test.handler1.ts': '// nothing',
'/home/project/function.test.handler2.js': '// nothing',
'/home/project/function.test.handler3.mjs': '// nothing',
'/home/project/function.test.handler4.mts': '// nothing',
'/home/project/function.test.handler5.cts': '// nothing',
'/home/project/function.test.handler6.cjs': '// nothing',
'/home/project/aws-lambda-nodejs/lib/index.ts': '// nothing',
});
const bockPath = bockfs.workingDirectory('/home/project');

// pretend the calling file is in a fake file path
mockCallsites.mockImplementation(() => [
{ getFunctionName: () => 'NodejsFunction' },
{ getFileName: () => bockPath`function.test.ts` },
]);

afterAll(() => {
bockfs.restore();
});

test('NodejsFunction with .ts handler', () => {
// WHEN
new NodejsFunction(stack, 'handler1');
Expand Down Expand Up @@ -151,15 +183,11 @@ test('throws when entry is not js/ts', () => {
});

test('accepts tsx', () => {
const entry = path.join(__dirname, 'handler.tsx');

fs.symlinkSync(path.join(__dirname, 'function.test.handler1.ts'), entry);
const entry = bockPath`handler.tsx`;

expect(() => new NodejsFunction(stack, 'Fn', {
entry,
})).not.toThrow();

fs.unlinkSync(entry);
});

test('throws when entry does not exist', () => {
Expand Down Expand Up @@ -196,7 +224,7 @@ test('resolves depsLockFilePath to an absolute path', () => {
});

expect(Bundling.bundle).toHaveBeenCalledWith(expect.objectContaining({
depsLockFilePath: expect.stringMatching(/aws-cdk-lib\/package.json$/),
depsLockFilePath: bockPath`/home/project/package.json`,
}));
});

Expand All @@ -207,7 +235,7 @@ test('resolves entry to an absolute path', () => {
});

expect(Bundling.bundle).toHaveBeenCalledWith(expect.objectContaining({
entry: expect.stringMatching(/aws-cdk-lib\/aws-lambda-nodejs\/lib\/index.ts$/),
entry: bockPath`/home/project/aws-lambda-nodejs/lib/index.ts`,
}));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ export function handler() {
process.env.NUMBER,
process.env.STRING,
];
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 4a113fd

Please sign in to comment.