From da6f269008b38bd49a195069f1a0e93429e00b5d Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Wed, 14 Aug 2024 14:42:33 -0400 Subject: [PATCH] refactor: asset e2e performance (#11779) --- e2e/src/api/specs/asset.e2e-spec.ts | 35 +++++++++++++++++++---------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/e2e/src/api/specs/asset.e2e-spec.ts b/e2e/src/api/specs/asset.e2e-spec.ts index b9282ff811..4ee035ee95 100644 --- a/e2e/src/api/specs/asset.e2e-spec.ts +++ b/e2e/src/api/specs/asset.e2e-spec.ts @@ -993,7 +993,7 @@ describe('/asset', () => { expect(body).toEqual(errorDto.badRequest()); }); - it.each([ + const tests = [ { input: 'formats/avif/8bit-sRGB.avif', expected: { @@ -1209,21 +1209,32 @@ describe('/asset', () => { }, }, }, - ])(`should upload and generate a thumbnail for $input`, async ({ input, expected }) => { - const filepath = join(testAssetDir, input); - const { id, status } = await utils.createAsset(admin.accessToken, { - assetData: { bytes: await readFile(filepath), filename: basename(filepath) }, - }); + ]; - expect(status).toBe(AssetMediaStatus.Created); + it(`should upload and generate a thumbnail for different file types`, async () => { + // upload in parallel + const assets = await Promise.all( + tests.map(async ({ input }) => { + const filepath = join(testAssetDir, input); + return utils.createAsset(admin.accessToken, { + assetData: { bytes: await readFile(filepath), filename: basename(filepath) }, + }); + }), + ); - await utils.waitForWebsocketEvent({ event: 'assetUpload', id: id }); + for (const { id, status } of assets) { + expect(status).toBe(AssetMediaStatus.Created); + await utils.waitForWebsocketEvent({ event: 'assetUpload', id }); + } - const asset = await utils.getAssetInfo(admin.accessToken, id); + for (const [i, { id }] of assets.entries()) { + const { expected } = tests[i]; + const asset = await utils.getAssetInfo(admin.accessToken, id); - expect(asset.exifInfo).toBeDefined(); - expect(asset.exifInfo).toMatchObject(expected.exifInfo); - expect(asset).toMatchObject(expected); + expect(asset.exifInfo).toBeDefined(); + expect(asset.exifInfo).toMatchObject(expected.exifInfo); + expect(asset).toMatchObject(expected); + } }); it('should handle a duplicate', async () => {