Skip to content

🎥 Make videos programmatically with React

fix tests

Jonny Burger7c5aef75395b
diff --git a/packages/lambda/src/api/__mocks__/mock-s3.ts b/packages/lambda/src/api/__mocks__/mock-s3.ts
index 9968f1e244..f8cceccc99 100644
--- a/packages/lambda/src/api/__mocks__/mock-s3.ts
+++ b/packages/lambda/src/api/__mocks__/mock-s3.ts
@@ -12,10 +12,6 @@ type S3MockFile = {
let mockS3Store: S3MockFile[] = [];
-export const mockS3Upload = (file: S3MockFile) => {
- mockS3Store.push(file);
-};
-
export const writeMockS3File = ({
body,
privacy,
@@ -29,6 +25,13 @@ export const writeMockS3File = ({
key: string;
region: AwsRegion;
}) => {
+ mockS3Store = mockS3Store.filter((m) => {
+ return !(
+ m.region === region &&
+ m.bucketName === bucketName &&
+ m.key === key
+ );
+ });
mockS3Store.push({
content: body,
acl:
diff --git a/packages/lambda/src/api/__mocks__/upload-dir.ts b/packages/lambda/src/api/__mocks__/upload-dir.ts
index 67f9ea85ba..f165314e48 100644
--- a/packages/lambda/src/api/__mocks__/upload-dir.ts
+++ b/packages/lambda/src/api/__mocks__/upload-dir.ts
@@ -1,5 +1,5 @@
import type {MockFile, uploadDir as original} from '../upload-dir';
-import {mockS3Upload} from './mock-s3';
+import {writeMockS3File} from './mock-s3';
export const getDirFiles = (dir: string): MockFile[] => {
if (dir === '/path/to/bundle-1') {
@@ -31,20 +31,15 @@ export const getDirFiles = (dir: string): MockFile[] => {
throw new Error('could not get dir for ' + dir);
};
-export const uploadDir: typeof original = async (input) => {
- const files = getDirFiles(input.dir);
+export const uploadDir: typeof original = (input) => {
+ const files = getDirFiles(input.localDir);
for (const file of files) {
- mockS3Upload({
- acl:
- input.privacy === 'no-acl'
- ? 'none'
- : input.privacy === 'private'
- ? 'private'
- : 'public-read',
+ writeMockS3File({
+ privacy: input.privacy,
bucketName: input.bucket,
- content: file.content,
+ body: file.content,
// Should not use path.join here because on Windows it's not / separator
- key: [input.folder, file.name].join('/'),
+ key: [input.keyPrefix, file.name].join('/'),
region: input.region,
});
}
diff --git a/packages/lambda/src/api/upload-dir.ts b/packages/lambda/src/api/upload-dir.ts
index 41277dcbba..be0c40bb25 100644
--- a/packages/lambda/src/api/upload-dir.ts
+++ b/packages/lambda/src/api/upload-dir.ts
@@ -74,9 +74,9 @@ async function getFiles(
export const uploadDir = async ({
bucket,
region,
- localDir: dir,
+ localDir,
onProgress,
- keyPrefix: folder,
+ keyPrefix,
privacy,
toUpload,
}: {
@@ -88,7 +88,7 @@ export const uploadDir = async ({
privacy: Privacy;
toUpload: string[];
}) => {
- const files = await getFiles(dir, dir, toUpload);
+ const files = await getFiles(localDir, localDir, toUpload);
const progresses: {[key: string]: number} = {};
for (const file of files) {
progresses[file.name] = 0;
@@ -97,7 +97,7 @@ export const uploadDir = async ({
const client = getS3Client(region, null);
const uploads = files.map(async (filePath) => {
- const Key = makeS3Key(folder, dir, filePath.name);
+ const Key = makeS3Key(keyPrefix, localDir, filePath.name);
const Body = createReadStream(filePath.name);
const ContentType = mimeTypes.lookup(Key) || 'application/octet-stream';
const ACL =
diff --git a/packages/lambda/src/functions/helpers/__mocks__/io.ts b/packages/lambda/src/functions/helpers/__mocks__/io.ts
index e27c318707..2af8e07ad3 100644
--- a/packages/lambda/src/functions/helpers/__mocks__/io.ts
+++ b/packages/lambda/src/functions/helpers/__mocks__/io.ts
@@ -103,7 +103,7 @@ export const lambdaLs: typeof lsOriginal = (
const size = typeof file.content === 'string' ? file.content.length : 0;
return {
Key: file.key,
- ETag: undefined,
+ ETag: 'etag',
LastModified: new Date(0),
Owner: undefined,
Size: size,
diff --git a/packages/lambda/src/shared/__mocks__/read-dir.ts b/packages/lambda/src/shared/__mocks__/read-dir.ts
new file mode 100644
index 0000000000..5202e72a31
--- /dev/null
+++ b/packages/lambda/src/shared/__mocks__/read-dir.ts
@@ -0,0 +1,13 @@
+import {getDirFiles} from '../../api/__mocks__/upload-dir';
+import type {readDirectory as original} from '../../shared/read-dir';
+
+export const readDirectory: typeof original = ({dir}) => {
+ const files = getDirFiles(dir);
+
+ const obj = {};
+ for (const file of files) {
+ obj[file.name] = 'etag';
+ }
+
+ return Promise.resolve(obj);
+};
diff --git a/packages/lambda/src/test/integration/deploy-site.test.ts b/packages/lambda/src/test/integration/deploy-site.test.ts
index 3844374881..3edb960d2b 100644
--- a/packages/lambda/src/test/integration/deploy-site.test.ts
+++ b/packages/lambda/src/test/integration/deploy-site.test.ts
@@ -54,6 +54,11 @@ test('Should apply name if given', async () => {
siteName: 'testing',
serveUrl:
'https://remotionlambda-abcdef.s3.ap-northeast-1.amazonaws.com/sites/testing/index.html',
+ stats: {
+ deletedFiles: 0,
+ untouchedFiles: 0,
+ uploadedFiles: 2,
+ },
});
});
@@ -72,6 +77,11 @@ test('Should use a random hash if no siteName is given', async () => {
siteName: 'testing',
serveUrl:
'https://remotionlambda-abcdef.s3.ap-northeast-1.amazonaws.com/sites/testing/index.html',
+ stats: {
+ deletedFiles: 0,
+ untouchedFiles: 2,
+ uploadedFiles: 0,
+ },
});
});
diff --git a/packages/lambda/src/test/setup.ts b/packages/lambda/src/test/setup.ts
index 874fe0f8f2..99f9068c3f 100644
--- a/packages/lambda/src/test/setup.ts
+++ b/packages/lambda/src/test/setup.ts
@@ -48,6 +48,9 @@ vi.mock('../api/enable-s3-website', () =>
vi.mock('../api/create-bucket', () =>
vi.importActual('../api/__mocks__/create-bucket')
);
+vi.mock('../shared/read-dir', () =>
+ vi.importActual('../shared/__mocks__/read-dir')
+);
vi.mock('../api/upload-dir', () =>
vi.importActual('../api/__mocks__/upload-dir')
);