🎥 Make videos programmatically with React
compatible only
Jonny Burger34b6ba04345c
diff --git a/packages/lambda/src/api/__mocks__/get-functions.ts b/packages/lambda/src/api/__mocks__/get-functions.tsindex 4266c03a6b..e149d2d583 100644--- a/packages/lambda/src/api/__mocks__/get-functions.ts+++ b/packages/lambda/src/api/__mocks__/get-functions.ts@@ -1,6 +1,10 @@+import {CURRENT_VERSION} from '../../defaults';import {getFunctions as original} from '../get-functions';import {getAllMockFunctions} from '../mock-functions';-export const getFunctions: typeof original = async ({region}) => {- return getAllMockFunctions(region);+export const getFunctions: typeof original = async ({+ region,+ compatibleOnly,+}) => {+ return getAllMockFunctions(region, compatibleOnly ? CURRENT_VERSION : null);};diff --git a/packages/lambda/src/api/mock-functions.ts b/packages/lambda/src/api/mock-functions.tsindex b111fc5bee..044e24aa56 100644--- a/packages/lambda/src/api/mock-functions.ts+++ b/packages/lambda/src/api/mock-functions.ts@@ -1,10 +1,14 @@import {AwsRegion} from '..';+import {LambdaVersions} from '../shared/constants';import {FunctionInfo} from './get-function-info';-export let mockFunctionsStore: (FunctionInfo & {region: AwsRegion})[] = [];+export let mockFunctionsStore: (FunctionInfo & {+ region: AwsRegion;+ version: LambdaVersions;+})[] = [];export const addFunction = (fn: FunctionInfo, region: AwsRegion) => {- mockFunctionsStore.push({...fn, region});+ mockFunctionsStore.push({...fn, region, version: fn.version});};export const deleteMockFunction = (name: string, region: string) => {@@ -19,10 +23,23 @@ export const findFunction = (name: string, region: string) => {);};-export const getAllMockFunctions = (region: string) => {- return mockFunctionsStore.filter((f) => f.region === region);+export const getAllMockFunctions = (+ region: string,+ version: LambdaVersions | null+) => {+ return mockFunctionsStore.filter(+ (f) => f.region === region && (version ? f.version === version : true)+ );};export const cleanFnStore = () => {mockFunctionsStore = [];};++export const markFunctionAsIncompatible = (functionName: string) => {+ for (const fn of mockFunctionsStore) {+ if (fn.functionName === functionName) {+ fn.version = '2021-06-23';+ }+ }+};diff --git a/packages/lambda/src/test/integration/deploy-function.test.ts b/packages/lambda/src/test/integration/deploy-function.test.tsindex a8b84f5b9c..b0f15ec97c 100644--- a/packages/lambda/src/test/integration/deploy-function.test.ts+++ b/packages/lambda/src/test/integration/deploy-function.test.ts@@ -2,7 +2,11 @@ import {deleteFunction} from '../../api/delete-function';import {deployFunction} from '../../api/deploy-function';import {ensureLambdaBinaries} from '../../api/ensure-lambda-binaries';import {getFunctions} from '../../api/get-functions';-import {cleanFnStore} from '../../api/mock-functions';+import {+ cleanFnStore,+ markFunctionAsIncompatible,+} from '../../api/mock-functions';+import {CURRENT_VERSION} from '../../shared/constants';jest.mock('../../api/get-buckets');jest.mock('../../functions/helpers/io');@@ -63,10 +67,15 @@ test('Should be able to get the function afterwards', async () => {functionName: 'remotion-render-abcdef',memorySizeInMb: 1024,timeoutInSeconds: 120,- version: '2021-09-15',+ version: CURRENT_VERSION,region: 'us-east-1',},]);+ const foreignFunctions = await getFunctions({+ region: 'us-east-2',+ compatibleOnly: true,+ });+ expect(foreignFunctions).toEqual([]);});test('Should be able to delete the function', async () => {@@ -90,3 +99,48 @@ test('Should be able to delete the function', async () => {});expect(fns).toEqual([]);});++test('Should be able to get the function afterwards', async () => {+ cleanFnStore();+ const {layerArn} = await ensureLambdaBinaries('us-east-1');++ const {functionName} = await deployFunction({+ layerArn,+ memorySizeInMb: 2048,+ region: 'us-east-1',+ timeoutInSeconds: 120,+ });+ expect(functionName).toBe('remotion-render-abcdef');+ const fns = await getFunctions({+ region: 'us-east-1',+ compatibleOnly: true,+ });+ expect(fns).toEqual([+ {+ functionName: 'remotion-render-abcdef',+ memorySizeInMb: 1024,+ timeoutInSeconds: 120,+ version: CURRENT_VERSION,+ region: 'us-east-1',+ },+ ]);+ markFunctionAsIncompatible('remotion-render-abcdef');+ const compatibleFns = await getFunctions({+ region: 'us-east-1',+ compatibleOnly: true,+ });+ const incompatibleFns = await getFunctions({+ region: 'us-east-1',+ compatibleOnly: false,+ });+ expect(compatibleFns).toEqual([]);+ expect(incompatibleFns).toEqual([+ {+ functionName: 'remotion-render-abcdef',+ memorySizeInMb: 1024,+ timeoutInSeconds: 120,+ version: '2021-06-23',+ region: 'us-east-1',+ },+ ]);+});