Skip to content

🎥 Make videos programmatically with React

lambda test suite separate

Jonny Burger4efac22ba2b4
diff --git a/jest.config.js b/jest.config.js
index 590b5c9601..c564d9415c 100644
--- a/jest.config.js
+++ b/jest.config.js
@@ -3,4 +3,5 @@ module.exports = {
testEnvironment: "node",
rootDir: "tests",
testTimeout: 240000,
+ setupFiles: ["../../packages/lambda/src/test/setup.ts"],
};
diff --git a/packages/lambda/jest.config.js b/packages/lambda/jest.config.js
index d27d0b3495..b73c5ac074 100644
--- a/packages/lambda/jest.config.js
+++ b/packages/lambda/jest.config.js
@@ -2,5 +2,6 @@ module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testPathIgnorePatterns: ['dist'],
+ setupFiles: ['./src/test/setup.ts'],
resetMocks: true,
};
diff --git a/packages/lambda/src/cli/index.ts b/packages/lambda/src/cli/index.ts
index 00bcb1346b..bf367383c8 100644
--- a/packages/lambda/src/cli/index.ts
+++ b/packages/lambda/src/cli/index.ts
@@ -94,10 +94,7 @@ export const executeCommand = async (args: string[]) => {
await matchCommand(args);
} catch (err) {
const error = err as Error;
- if (
- error.stack?.includes('AccessDenied') ||
- error.stack?.includes('AccessDeniedException')
- ) {
+ if (error.stack?.includes('AccessDenied')) {
// TODO: Explain permission problem
Log.error('PERMISSION PROBLEM PUT HELPFUL MESSAGE HERE');
}
diff --git a/packages/lambda/src/functions/helpers/__mocks__/print-cloudwatch-helper.ts b/packages/lambda/src/functions/helpers/__mocks__/print-cloudwatch-helper.ts
new file mode 100644
index 0000000000..aec176b503
--- /dev/null
+++ b/packages/lambda/src/functions/helpers/__mocks__/print-cloudwatch-helper.ts
@@ -0,0 +1 @@
+export const printCloudwatchHelper = () => undefined;
diff --git a/packages/lambda/src/shared/__mocks__/check-credentials.ts b/packages/lambda/src/shared/__mocks__/check-credentials.ts
new file mode 100644
index 0000000000..0e630ef0e3
--- /dev/null
+++ b/packages/lambda/src/shared/__mocks__/check-credentials.ts
@@ -0,0 +1 @@
+export const checkCredentials = () => undefined;
diff --git a/packages/lambda/src/test/integration/delete-site.test.ts b/packages/lambda/src/test/integration/delete-site.test.ts
index 60c2e46c82..fa5ef2f90a 100644
--- a/packages/lambda/src/test/integration/delete-site.test.ts
+++ b/packages/lambda/src/test/integration/delete-site.test.ts
@@ -1,15 +1,5 @@
import {deleteSite, deploySite, getOrCreateBucket} from '../..';
-jest.mock('../../api/get-buckets');
-jest.mock('../../functions/helpers/io');
-jest.mock('../../shared/bundle-site');
-jest.mock('../../shared/get-account-id');
-jest.mock('../../api/enable-s3-website');
-jest.mock('../../api/create-bucket');
-jest.mock('../../api/upload-dir');
-jest.mock('../../api/bucket-exists');
-jest.mock('../../api/clean-items');
-
test('Return 0 total size if site did not exist', async () => {
const {bucketName} = await getOrCreateBucket({
region: 'ap-east-1',
diff --git a/packages/lambda/src/test/integration/deploy-function.test.ts b/packages/lambda/src/test/integration/deploy-function.test.ts
index 357c0fa14c..cc8eca7955 100644
--- a/packages/lambda/src/test/integration/deploy-function.test.ts
+++ b/packages/lambda/src/test/integration/deploy-function.test.ts
@@ -7,20 +7,6 @@ import {
} from '../../api/mock-functions';
import {CURRENT_VERSION} from '../../shared/constants';
-jest.mock('../../api/get-buckets');
-jest.mock('../../functions/helpers/io');
-jest.mock('../../shared/bundle-site');
-jest.mock('../../shared/random-hash');
-jest.mock('../../api/enable-s3-website');
-jest.mock('../../api/create-bucket');
-jest.mock('../../api/upload-dir');
-jest.mock('../../api/bucket-exists');
-jest.mock('../../api/clean-items');
-jest.mock('../../api/create-function');
-jest.mock('../../api/delete-function');
-jest.mock('../../api/get-functions');
-jest.mock('../../shared/get-account-id');
-
test('Should be able to deploy function', async () => {
const {functionName} = await deployFunction({
memorySizeInMb: 2048,
diff --git a/packages/lambda/src/test/integration/deploy-site.test.ts b/packages/lambda/src/test/integration/deploy-site.test.ts
index a2dac1b1ff..9c3536298b 100644
--- a/packages/lambda/src/test/integration/deploy-site.test.ts
+++ b/packages/lambda/src/test/integration/deploy-site.test.ts
@@ -3,17 +3,6 @@ import {deploySite} from '../../api/deploy-site';
import {getDirFiles} from '../../api/upload-dir';
import {lambdaLs} from '../../functions/helpers/io';
-jest.mock('../../api/get-buckets');
-jest.mock('../../functions/helpers/io');
-jest.mock('../../shared/bundle-site');
-jest.mock('../../shared/random-hash');
-jest.mock('../../shared/get-account-id');
-jest.mock('../../api/enable-s3-website');
-jest.mock('../../api/create-bucket');
-jest.mock('../../api/upload-dir');
-jest.mock('../../api/bucket-exists');
-jest.mock('../../api/clean-items');
-
test('Should throw on wrong prefix', async () => {
await expect(() =>
deploySite({
diff --git a/packages/lambda/src/test/integration/get-sites.test.ts b/packages/lambda/src/test/integration/get-sites.test.ts
index e3d4afd31e..fb7169d3b6 100644
--- a/packages/lambda/src/test/integration/get-sites.test.ts
+++ b/packages/lambda/src/test/integration/get-sites.test.ts
@@ -1,17 +1,6 @@
import {deploySite, getOrCreateBucket} from '../..';
import {getSites} from '../../api/get-sites';
-jest.mock('../../api/get-buckets');
-jest.mock('../../functions/helpers/io');
-jest.mock('../../shared/bundle-site');
-jest.mock('../../shared/get-account-id');
-jest.mock('../../api/enable-s3-website');
-jest.mock('../../api/upload-dir');
-jest.mock('../../api/clean-items');
-jest.mock('../../api/create-bucket');
-jest.mock('../../api/bucket-exists');
-jest.mock('../../shared/random-hash');
-
test('Should have no buckets at first', async () => {
expect(
await getSites({
diff --git a/packages/lambda/src/test/setup.ts b/packages/lambda/src/test/setup.ts
new file mode 100644
index 0000000000..d9f0f10907
--- /dev/null
+++ b/packages/lambda/src/test/setup.ts
@@ -0,0 +1,45 @@
+jest.mock('../api/get-buckets', () =>
+ jest.requireActual('../api/__mocks__/get-buckets')
+);
+jest.mock('../functions/helpers/io', () =>
+ jest.requireActual('../functions/helpers/__mocks__/io')
+);
+jest.mock('../functions/helpers/print-cloudwatch-helper', () =>
+ jest.requireActual('../functions/helpers/__mocks__/print-cloudwatch-helper')
+);
+jest.mock('../shared/bundle-site', () =>
+ jest.requireActual('../shared/__mocks__/bundle-site')
+);
+jest.mock('../shared/get-account-id', () =>
+ jest.requireActual('../shared/__mocks__/get-account-id')
+);
+jest.mock('../api/enable-s3-website', () =>
+ jest.requireActual('../api/__mocks__/enable-s3-website')
+);
+jest.mock('../api/create-bucket', () =>
+ jest.requireActual('../api/__mocks__/create-bucket')
+);
+jest.mock('../api/upload-dir', () =>
+ jest.requireActual('../api/__mocks__/upload-dir')
+);
+jest.mock('../api/bucket-exists', () =>
+ jest.requireActual('../api/__mocks__/bucket-exists')
+);
+jest.mock('../api/clean-items', () =>
+ jest.requireActual('../api/__mocks__/clean-items')
+);
+jest.mock('../api/create-function', () =>
+ jest.requireActual('../api/__mocks__/create-function')
+);
+jest.mock('../api/get-functions', () =>
+ jest.requireActual('../api/__mocks__/get-functions')
+);
+jest.mock('../api/delete-function', () =>
+ jest.requireActual('../api/__mocks__/delete-function')
+);
+jest.mock('../shared/random-hash', () =>
+ jest.requireActual('../shared/__mocks__/random-hash')
+);
+jest.mock('../shared/check-credentials', () =>
+ jest.requireActual('../shared/__mocks__/check-credentials')
+);
diff --git a/tests/lambda/cli.test.ts b/tests/lambda/cli.test.ts
new file mode 100644
index 0000000000..57213c01f0
--- /dev/null
+++ b/tests/lambda/cli.test.ts
@@ -0,0 +1,23 @@
+import { LambdaInternals, getFunctions } from "../../packages/lambda/src/index";
+
+const getConsoleOutput = () => {
+ // @ts-expect-error
+ return process.stdout.write.mock.calls.map((c) => c[0].toString()).join("\n");
+};
+
+test("Deploy function", async () => {
+ process.stdout.write = jest.fn();
+ await LambdaInternals.executeCommand(["functions", "deploy"]);
+ expect(getConsoleOutput()).toContain("Deployed as remotion-render-abcdef\n");
+});
+
+test("Deploy function and list it", async () => {
+ await LambdaInternals.executeCommand(["functions", "deploy"]);
+ process.stdout.write = jest.fn();
+ await LambdaInternals.executeCommand(["functions", "ls"]);
+ expect(getConsoleOutput()).toContain("Getting functions...");
+ expect(getConsoleOutput()).toContain("Memory (MB)");
+ expect(getConsoleOutput()).toMatch(
+ /remotion-render-abcdef\s+(.*)\s+1024\s+120/g
+ );
+});