🎥 Make videos programmatically with React
more tests
Jonny Burger50db363a701a
diff --git a/packages/lambda/src/api/__mocks__/upload-dir.ts b/packages/lambda/src/api/__mocks__/upload-dir.tsindex dd5bb874c8..32a646ccdd 100644--- a/packages/lambda/src/api/__mocks__/upload-dir.ts+++ b/packages/lambda/src/api/__mocks__/upload-dir.ts@@ -1,13 +1,8 @@import path from 'path';-import {uploadDir as original} from '../upload-dir';+import {MockFile, uploadDir as original} from '../upload-dir';import {mockS3Upload} from './mock-s3';-type MockFile = {- name: string;- content: string;-};--const getDirFiles = (dir: string): MockFile[] => {+export const getDirFiles = (dir: string): MockFile[] => {if (dir === '/path/to/bundle-1') {return [{@@ -21,7 +16,20 @@ const getDirFiles = (dir: string): MockFile[] => {];}- return [];+ if (dir === '/path/to/bundle-2') {+ return [+ {+ name: 'bundle.js',+ content: 'console.log("Hello World")',+ },+ {+ name: 'styles2.css',+ content: 'body {background: red}',+ },+ ];+ }++ throw new Error('could not get dir for ' + dir);};export const uploadDir: typeof original = async (input) => {diff --git a/packages/lambda/src/api/upload-dir.ts b/packages/lambda/src/api/upload-dir.tsindex 0e0a1ed68f..233d6e5a02 100644--- a/packages/lambda/src/api/upload-dir.ts+++ b/packages/lambda/src/api/upload-dir.ts@@ -17,6 +17,17 @@ export type UploadDirProgress = {sizeUploaded: number;};+export type MockFile = {+ name: string;+ content: string;+};++export const getDirFiles = (entry: string): MockFile[] => {+ throw new TypeError(+ 'should only be executed in test ' + JSON.stringify(entry)+ );+};+export const uploadDir = async ({bucket,region,diff --git a/packages/lambda/src/shared/__mocks__/bundle-site.ts b/packages/lambda/src/shared/__mocks__/bundle-site.tsindex c7a8bc5944..e4cb1f289a 100644--- a/packages/lambda/src/shared/__mocks__/bundle-site.ts+++ b/packages/lambda/src/shared/__mocks__/bundle-site.ts@@ -1,5 +1,13 @@import {bundle} from '@remotion/bundler';-export const bundleSite: typeof bundle = () => {- return Promise.resolve('/path/to/bundle-1');+export const bundleSite: typeof bundle = (entry: string) => {+ if (entry === 'first') {+ return Promise.resolve('/path/to/bundle-1');+ }++ if (entry === 'second') {+ return Promise.resolve('/path/to/bundle-2');+ }++ throw new Error('unknown entry');};diff --git a/packages/lambda/src/test/integration/delete-site.test.ts b/packages/lambda/src/test/integration/delete-site.test.tsindex fb08bd3809..b1ba57f618 100644--- a/packages/lambda/src/test/integration/delete-site.test.ts+++ b/packages/lambda/src/test/integration/delete-site.test.ts@@ -27,7 +27,7 @@ test('Return more than 0 total size if site did not exist', async () => {});const {siteName} = await deploySite({bucketName,- entryPoint: 'hi.tsx',+ entryPoint: 'first',region: 'ap-east-1',});expect(diff --git a/packages/lambda/src/test/integration/deploy-site.test.ts b/packages/lambda/src/test/integration/deploy-site.test.tsindex 985c1dca09..8371a02eb2 100644--- a/packages/lambda/src/test/integration/deploy-site.test.ts+++ b/packages/lambda/src/test/integration/deploy-site.test.ts@@ -1,5 +1,7 @@import {getOrCreateBucket} from '../..';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');@@ -15,7 +17,7 @@ test('Should throw on wrong prefix', async () => {await expect(() =>deploySite({bucketName: 'wrongprefix',- entryPoint: 'hi',+ entryPoint: 'first',region: 'us-east-1',})).rejects.toThrow(/The bucketName parameter must start /);@@ -25,7 +27,7 @@ test('Should throw if invalid region was passed', async () => {expect(() =>deploySite({bucketName: 'remotionlambda-testing',- entryPoint: 'hi',+ entryPoint: 'first',// @ts-expect-errorregion: 'ap-northeast-9',siteName: 'testing',@@ -37,7 +39,7 @@ test("Should throw if bucket doesn't exist", async () => {expect(() =>deploySite({bucketName: 'remotionlambda-non-existed',- entryPoint: 'hi',+ entryPoint: 'first',region: 'ap-northeast-1',siteName: 'testing',})@@ -51,7 +53,7 @@ test('Should apply name if given', async () => {expect(await deploySite({bucketName,- entryPoint: 'hi',+ entryPoint: 'first',region: 'ap-northeast-1',siteName: 'testing',})@@ -68,7 +70,7 @@ test('Should use random hash if no siteName is given', async () => {expect(await deploySite({bucketName,- entryPoint: 'hi',+ entryPoint: 'first',region: 'ap-northeast-1',siteName: 'testing',})@@ -77,3 +79,91 @@ test('Should use random hash if no siteName is given', async () => {url: 'https://remotionlambda-abcdef.s3.ap-northeast-1.amazonaws.com/sites/testing',});});++test('Should delete the previous site if deploying the new one', async () => {+ const {bucketName} = await getOrCreateBucket({+ region: 'ap-northeast-1',+ });++ await deploySite({+ bucketName,+ entryPoint: 'first',+ region: 'ap-northeast-1',+ siteName: 'testing',+ });+ await deploySite({+ bucketName,+ entryPoint: 'second',+ region: 'ap-northeast-1',+ siteName: 'testing',+ });++ const files = await lambdaLs({+ bucketName,+ expectedBucketOwner: null,+ prefix: 'sites/testing',+ region: 'ap-northeast-1',+ continuationToken: undefined,+ });+ expect(+ files.map((f) => {+ return f.Key;+ })+ ).toEqual(+ getDirFiles('/path/to/bundle-2').map((f) => {+ return 'sites/testing/' + f.name;+ })+ );+});++test('Should keep the previous site if deploying the new one with different ID', async () => {+ const {bucketName} = await getOrCreateBucket({+ region: 'ap-northeast-1',+ });++ await deploySite({+ bucketName,+ entryPoint: 'first',+ region: 'ap-northeast-1',+ siteName: 'testing',+ });+ await deploySite({+ bucketName,+ entryPoint: 'second',+ region: 'ap-northeast-1',+ siteName: 'testing-2',+ });++ const files = await lambdaLs({+ bucketName,+ expectedBucketOwner: null,+ prefix: 'sites/testing/',+ region: 'ap-northeast-1',+ continuationToken: undefined,+ });+ expect(+ files.map((f) => {+ return f.Key;+ })+ ).toEqual(+ getDirFiles('/path/to/bundle-1').map((f) => {+ return 'sites/testing/' + f.name;+ })+ );+ const files2 = await lambdaLs({+ bucketName,+ expectedBucketOwner: null,+ prefix: 'sites/testing-2/',+ region: 'ap-northeast-1',+ continuationToken: undefined,+ });+ expect(+ files2.map((f) => {+ return f.Key;+ })+ ).toEqual(+ getDirFiles('/path/to/bundle-2').map((f) => {+ return 'sites/testing-2/' + f.name;+ })+ );+});diff --git a/packages/lambda/src/test/integration/get-sites.test.ts b/packages/lambda/src/test/integration/get-sites.test.tsindex e6f8f47c61..990dd3aa72 100644--- a/packages/lambda/src/test/integration/get-sites.test.ts+++ b/packages/lambda/src/test/integration/get-sites.test.ts@@ -26,7 +26,7 @@ test('Should have a site after deploying', async () => {expect(await deploySite({bucketName: 'remotionlambda-abcdef',- entryPoint: './src/index.tsx',+ entryPoint: 'first',region: 'eu-central-1',siteName: 'testing',})