Skip to content

🎥 Make videos programmatically with React

lambda vitest

Jonny Burger04fb97aa7c37
diff --git a/packages/lambda/package.json b/packages/lambda/package.json
index cd606e6309..9b4d969444 100644
--- a/packages/lambda/package.json
+++ b/packages/lambda/package.json
@@ -11,7 +11,7 @@
"scripts": {
"testintegration": "jest src/test/integration --runInBand --forceExit",
"lint": "eslint src --ext ts,tsx",
- "test": "jest src/test/unit",
+ "test": "vitest src/test/unit --run",
"watch": "tsc -w",
"build": "tsc -d && pnpm run buildlambda",
"buildlambda": "ts-node src/admin/bundle-lambda.ts",
@@ -57,7 +57,8 @@
"ts-jest": "^27.0.5",
"ts-node": "^10.8.0",
"typescript": "^4.7.0",
- "zip-lib": "^0.7.2"
+ "zip-lib": "^0.7.2",
+ "vitest": "^0.18.0"
},
"publishConfig": {
"access": "public"
diff --git a/packages/lambda/src/test/unit/best-frames-per-lambda-param.test.ts b/packages/lambda/src/test/unit/best-frames-per-lambda-param.test.ts
index 5f28759027..391e6f68b2 100644
--- a/packages/lambda/src/test/unit/best-frames-per-lambda-param.test.ts
+++ b/packages/lambda/src/test/unit/best-frames-per-lambda-param.test.ts
@@ -1,3 +1,4 @@
+import {expect, test} from 'vitest';
import {bestFramesPerLambdaParam} from '../../functions/helpers/best-frames-per-lambda-param';
test('Get reasonable framesPerLambda defaults', () => {
diff --git a/packages/lambda/src/test/unit/cloudwatch-validation.test.ts b/packages/lambda/src/test/unit/cloudwatch-validation.test.ts
index 58915e59b7..b10b8f5cb2 100644
--- a/packages/lambda/src/test/unit/cloudwatch-validation.test.ts
+++ b/packages/lambda/src/test/unit/cloudwatch-validation.test.ts
@@ -1,15 +1,13 @@
+import {expect, test} from 'vitest';
import {validateCloudWatchRetentionPeriod} from '../../shared/validate-retention-period';
-import {expectToThrow} from '../helpers/expect-to-throw';
test('Should be a valid cloudwatch retention period', () => {
expect(validateCloudWatchRetentionPeriod(1)).toBe(undefined);
expect(validateCloudWatchRetentionPeriod(undefined)).toBe(undefined);
- expectToThrow(
- () => validateCloudWatchRetentionPeriod(0),
+ expect(() => validateCloudWatchRetentionPeriod(0)).toThrow(
/CloudWatch retention period must be at least 1, but is 0/
);
- expectToThrow(
- () => validateCloudWatchRetentionPeriod(1000000),
+ expect(() => validateCloudWatchRetentionPeriod(1000000)).toThrow(
/CloudWatch retention period must be at most 3650, but is 1000000/
);
});
diff --git a/packages/lambda/src/test/unit/expected-out-name.test.ts b/packages/lambda/src/test/unit/expected-out-name.test.ts
index da47af3652..ff24e4b78e 100644
--- a/packages/lambda/src/test/unit/expected-out-name.test.ts
+++ b/packages/lambda/src/test/unit/expected-out-name.test.ts
@@ -1,6 +1,6 @@
+import {expect, test} from 'vitest';
import type {RenderMetadata} from '../../defaults';
import {getExpectedOutName} from '../../functions/helpers/expected-out-name';
-import {expectToThrow} from '../helpers/expect-to-throw';
const bucketName = 'remotionlambda-98fsduf';
@@ -85,13 +85,9 @@ test('Should throw on invalid names', () => {
...testRenderMetadata,
outName: '👺.jpeg',
};
- expectToThrow(() => {
- expect(getExpectedOutName(newRenderMetadata, bucketName, null)).toEqual({
- customCredentials: null,
- renderBucketName: 'remotionlambda-98fsduf',
- key: 'renders/9n8dsfafs/justaname.jpeg',
- });
- }, /The S3 Key must match the RegExp/);
+ expect(() => {
+ getExpectedOutName(newRenderMetadata, bucketName, null);
+ }).toThrow(/The S3 Key must match the RegExp/);
});
test('Should allow outName an outname with a slash', () => {
diff --git a/packages/lambda/src/test/unit/frame-bug.test.ts b/packages/lambda/src/test/unit/frame-bug.test.ts
index da0612508c..64c8a30ecf 100644
--- a/packages/lambda/src/test/unit/frame-bug.test.ts
+++ b/packages/lambda/src/test/unit/frame-bug.test.ts
@@ -1,3 +1,4 @@
+import {expect, test} from 'vitest';
import {isValidOptimizationProfile} from '../../functions/chunk-optimization/is-valid-profile';
import {optimizeProfile} from '../../functions/chunk-optimization/optimize-profile';
diff --git a/packages/lambda/src/test/unit/handlers.test.ts b/packages/lambda/src/test/unit/handlers.test.ts
index c50dd28356..ccf43730eb 100644
--- a/packages/lambda/src/test/unit/handlers.test.ts
+++ b/packages/lambda/src/test/unit/handlers.test.ts
@@ -1,3 +1,4 @@
+import {expect, test} from 'vitest';
import {handler} from '../../functions/index';
import type {Await} from '../../shared/await';
import {LambdaRoutines} from '../../shared/constants';
diff --git a/packages/lambda/src/test/unit/hosted-layers-match.test.ts b/packages/lambda/src/test/unit/hosted-layers-match.test.ts
index 9135daf82b..a8a4120d30 100644
--- a/packages/lambda/src/test/unit/hosted-layers-match.test.ts
+++ b/packages/lambda/src/test/unit/hosted-layers-match.test.ts
@@ -1,3 +1,4 @@
+import {expect, test} from 'vitest';
import type {LambdaArchitecture} from '../..';
import {
hostedLayers,
diff --git a/packages/lambda/src/test/unit/invoke-webhook.test.ts b/packages/lambda/src/test/unit/invoke-webhook.test.ts
index 71bfb1283d..632e69ae80 100644
--- a/packages/lambda/src/test/unit/invoke-webhook.test.ts
+++ b/packages/lambda/src/test/unit/invoke-webhook.test.ts
@@ -1,8 +1,12 @@
+import {expect, test} from 'vitest';
import {calculateSignature} from '../../shared/invoke-webhook';
test('calculateSignature should return correct sha512 signature', () => {
- const signature = calculateSignature(JSON.stringify({payload: 'test'}), 'INSECURE_DEFAULT_SECRET')
- console.error(signature)
- expect(signature).toEqual('sha512=faa8735b7bac44d521749b45aa2c95cb6204822f54eb18f85aeb30b9a29d309a138f6b7358653336c592a69e29eb696ccc4f2c6c20335d3deb76b09efd4b6a5d');
- }
-);
+ const signature = calculateSignature(
+ JSON.stringify({payload: 'test'}),
+ 'INSECURE_DEFAULT_SECRET'
+ );
+ expect(signature).toEqual(
+ 'sha512=faa8735b7bac44d521749b45aa2c95cb6204822f54eb18f85aeb30b9a29d309a138f6b7358653336c592a69e29eb696ccc4f2c6c20335d3deb76b09efd4b6a5d'
+ );
+});
diff --git a/packages/lambda/src/test/unit/lambda-timing-file-name.test.ts b/packages/lambda/src/test/unit/lambda-timing-file-name.test.ts
index 50f442d25a..93ad657807 100644
--- a/packages/lambda/src/test/unit/lambda-timing-file-name.test.ts
+++ b/packages/lambda/src/test/unit/lambda-timing-file-name.test.ts
@@ -1,3 +1,4 @@
+import {expect, test} from 'vitest';
import {lambdaTimingsKey} from '../../shared/constants';
import {parseLambdaTimingsKey} from '../../shared/parse-lambda-timings-key';
diff --git a/packages/lambda/src/test/unit/lambda-timings-key.test.ts b/packages/lambda/src/test/unit/lambda-timings-key.test.ts
index 3f33ec905f..1b1239cd0e 100644
--- a/packages/lambda/src/test/unit/lambda-timings-key.test.ts
+++ b/packages/lambda/src/test/unit/lambda-timings-key.test.ts
@@ -1,3 +1,4 @@
+import {expect, test} from 'vitest';
import {lambdaChunkInitializedKey} from '../../shared/constants';
import {parseLambdaInitializedKey} from '../../shared/parse-lambda-initialized-key';
diff --git a/packages/lambda/src/test/unit/make-s3-key.test.ts b/packages/lambda/src/test/unit/make-s3-key.test.ts
index f5b376a231..81204a9576 100644
--- a/packages/lambda/src/test/unit/make-s3-key.test.ts
+++ b/packages/lambda/src/test/unit/make-s3-key.test.ts
@@ -1,3 +1,4 @@
+import {expect, test} from 'vitest';
import {makeS3Key} from '../../shared/make-s3-key';
test('makeS3Key should return POSIX syntax cross-platform', () => {
diff --git a/packages/lambda/src/test/unit/min-max.test.ts b/packages/lambda/src/test/unit/min-max.test.ts
index 55f9fcae0d..3fbf53cbad 100644
--- a/packages/lambda/src/test/unit/min-max.test.ts
+++ b/packages/lambda/src/test/unit/min-max.test.ts
@@ -1,5 +1,5 @@
+import {describe, expect, test} from 'vitest';
import {max, min} from '../../functions/helpers/min-max';
-import {expectToThrow} from '../helpers/expect-to-throw';
describe('min() and max()', () => {
test('Implemented min() functions correctly', () => {
@@ -10,22 +10,16 @@ describe('min() and max()', () => {
});
test('min() should throw on empty arr', () => {
- expectToThrow(() => min([]), /Array of 0 length/);
+ expect(() => min([])).toThrow(/Array of 0 length/);
});
test('max() should throw on empty arr', () => {
- expectToThrow(() => min([]), /Array of 0 length/);
+ expect(() => min([])).toThrow(/Array of 0 length/);
});
const bigArray = new Array(300000).fill(true).map((_, i) => {
return i;
});
- test('Regular Math.max() should throw', () => {
- expectToThrow(
- () => Math.max(...bigArray),
- /Maximum call stack size exceeded/
- );
- });
test('Custom max() should not throw', () => {
expect(max(bigArray)).toBe(299999);
});
diff --git a/packages/lambda/src/test/unit/most-expensive-chunks.test.ts b/packages/lambda/src/test/unit/most-expensive-chunks.test.ts
index 1e0d3d8877..5745790fc5 100644
--- a/packages/lambda/src/test/unit/most-expensive-chunks.test.ts
+++ b/packages/lambda/src/test/unit/most-expensive-chunks.test.ts
@@ -1,3 +1,5 @@
+import {expect, test} from 'vitest';
+
import {getMostExpensiveChunks} from '../../shared/get-most-expensive-chunks';
test('Should calculate most expensive chunks', () => {
diff --git a/packages/lambda/src/test/unit/optimize-profile.test.ts b/packages/lambda/src/test/unit/optimize-profile.test.ts
index f2cc1b4c92..20a987a41c 100644
--- a/packages/lambda/src/test/unit/optimize-profile.test.ts
+++ b/packages/lambda/src/test/unit/optimize-profile.test.ts
@@ -1,3 +1,4 @@
+import {describe, expect, test} from 'vitest';
import {
getFrameRangesFromProfile,
sortProfileByFrameRanges,
diff --git a/packages/lambda/src/test/unit/plan-frame-ranges.test.ts b/packages/lambda/src/test/unit/plan-frame-ranges.test.ts
index d4102de3bc..c49813d453 100644
--- a/packages/lambda/src/test/unit/plan-frame-ranges.test.ts
+++ b/packages/lambda/src/test/unit/plan-frame-ranges.test.ts
@@ -1,3 +1,4 @@
+import {expect, test} from 'vitest';
import {planFrameRanges} from '../../functions/chunk-optimization/plan-frame-ranges';
test('Plan frame ranges should respect everyNthFrame', () => {
diff --git a/packages/lambda/src/test/unit/price-calculation.test.ts b/packages/lambda/src/test/unit/price-calculation.test.ts
index 92e407baf6..710e8215a6 100644
--- a/packages/lambda/src/test/unit/price-calculation.test.ts
+++ b/packages/lambda/src/test/unit/price-calculation.test.ts
@@ -1,9 +1,10 @@
+import {expect, test} from 'vitest';
import {estimatePriceFromBucket} from '../../functions/helpers/calculate-price-from-bucket';
test('Should not throw while calculating prices when time shifts occur', () => {
const aDate = Date.now();
process.env.__RESERVED_IS_INSIDE_REMOTION_LAMBDA = 'true';
- process.env.REMOTION_AWS_REGION = 'us-east-1';
+ process.env.AWS_REGION = 'us-east-1';
const price = estimatePriceFromBucket({
contents: [
diff --git a/packages/lambda/src/test/unit/pricing.test.ts b/packages/lambda/src/test/unit/pricing.test.ts
index c6054ff1cb..6c4371d330 100644
--- a/packages/lambda/src/test/unit/pricing.test.ts
+++ b/packages/lambda/src/test/unit/pricing.test.ts
@@ -1,3 +1,4 @@
+import {expect, test} from 'vitest';
import {estimatePrice} from '../../api/estimate-price';
test('Should calculate costs accurately', () => {
diff --git a/packages/lambda/src/test/unit/validate-disk-size-in-mb.test.ts b/packages/lambda/src/test/unit/validate-disk-size-in-mb.test.ts
index 81e57ab628..7ffa2f76f1 100644
--- a/packages/lambda/src/test/unit/validate-disk-size-in-mb.test.ts
+++ b/packages/lambda/src/test/unit/validate-disk-size-in-mb.test.ts
@@ -1,13 +1,15 @@
+import {expect, test} from 'vitest';
import {validateDiskSizeInMb} from '../../shared/validate-disk-size-in-mb';
-import {expectToThrow} from '../helpers/expect-to-throw';
test('Disk size tests', () => {
expect(() => validateDiskSizeInMb(512)).not.toThrow();
expect(() => validateDiskSizeInMb(10240)).not.toThrow();
- expectToThrow(() => {
+ expect(() => {
validateDiskSizeInMb(0);
- }, /parameter 'diskSizeInMb' must be between 512 and 10240, but got 0/);
- expectToThrow(() => {
+ }).toThrow(
+ /parameter 'diskSizeInMb' must be between 512 and 10240, but got 0/
+ );
+ expect(() => {
validateDiskSizeInMb({});
- }, /parameter 'diskSizeInMb' must be a number, got a object/);
+ }).toThrow(/parameter 'diskSizeInMb' must be a number, got a object/);
});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 4600dc9c6c..042965dcb6 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -556,6 +556,7 @@ importers:
ts-jest: ^27.0.5
ts-node: ^10.8.0
typescript: ^4.7.0
+ vitest: ^0.18.0
zip-lib: ^0.7.2
dependencies:
'@aws-sdk/abort-controller': 3.55.0
@@ -585,9 +586,10 @@ importers:
prettier: 2.4.1
prettier-plugin-organize-imports: 2.3.4_pxx7xhvr2bexxfjjff3nukai7m
- ts-jest: 27.0.5_h5rbqvnmqo6ezjz2gx5x5dlwkm
+ ts-jest: 27.0.5_g2mfyom6zaxqcgedxrl4lakegu
ts-node: 10.8.0_ysvagj6uoj2jcpx4fli7niyicq
typescript: 4.7.2
+ vitest: 0.18.0
zip-lib: 0.7.2
packages/lottie:
@@ -722,7 +724,7 @@ importers:
prettier-plugin-organize-imports: 2.3.4_pxx7xhvr2bexxfjjff3nukai7m
react: 18.0.0
react-dom: [email protected]
- ts-jest: 27.0.5_h5rbqvnmqo6ezjz2gx5x5dlwkm
+ ts-jest: 27.0.5_g2mfyom6zaxqcgedxrl4lakegu
typescript: 4.7.2
webpack: 5.74.0
@@ -20894,7 +20896,7 @@ packages:
resolution: {integrity: sha512-3IVX4nI6B5cc31/GFFE+i8ey/N2eA0CZDbo6n0yrz0zDX8ZJ8djmU1p+XRz7G3is0F3bB3pu2pAroFdAWQKU3w==}
dev: false
- /ts-jest/27.0.5_h5rbqvnmqo6ezjz2gx5x5dlwkm:
+ /ts-jest/27.0.5_g2mfyom6zaxqcgedxrl4lakegu:
resolution: {integrity: sha512-lIJApzfTaSSbtlksfFNHkWOzLJuuSm4faFAfo5kvzOiRAuoN4/eKxVJ2zEAho8aecE04qX6K1pAzfH5QHL1/8w==}
engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0}
hasBin: true
@@ -20912,6 +20914,7 @@ packages:
babel-jest:
optional: true
dependencies:
+ '@babel/core': 7.18.6
'@types/jest': 27.4.0
bs-logger: 0.2.6
fast-json-stable-stringify: 2.1.0