Skip to content

Commit 2c432b1

Browse files
authored
test: migrate to Vitest for Uppy core and Uppy plugins (#4700)
1 parent 4ab1299 commit 2c432b1

File tree

78 files changed

+1144
-657
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1144
-657
lines changed

Diff for: .yarn/patches/jest-environment-jsdom-npm-29.5.0-fc600add1e.patch

-25
This file was deleted.

Diff for: package.json

+4-19
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
"adm-zip": "^0.5.5",
5454
"autoprefixer": "^10.2.6",
5555
"aws-sdk": "^2.1038.0",
56-
"babel-jest": "^29.0.0",
5756
"babel-plugin-inline-package-json": "^2.0.0",
5857
"chalk": "^5.0.0",
5958
"concat-stream": "^2.0.0",
@@ -80,8 +79,7 @@
8079
"eslint-plugin-unicorn": "^46.0.0",
8180
"github-contributors-list": "^1.2.4",
8281
"glob": "^8.0.0",
83-
"jest": "^29.0.0",
84-
"jest-environment-jsdom": "^29.0.0",
82+
"jsdom": "^22.1.0",
8583
"lint-staged": "^13.0.0",
8684
"mime-types": "^2.1.26",
8785
"nodemon": "^2.0.8",
@@ -104,6 +102,7 @@
104102
"tar": "^6.1.0",
105103
"tsd": "^0.22.0",
106104
"typescript": "~4.8",
105+
"vitest": "^0.34.5",
107106
"vue-template-compiler": "workspace:*"
108107
},
109108
"scripts": {
@@ -143,8 +142,8 @@
143142
"test:locale-packs:unused": "yarn workspace @uppy-dev/locale-pack test unused",
144143
"test:locale-packs:warnings": "yarn workspace @uppy-dev/locale-pack test warnings",
145144
"test:type": "yarn workspaces foreach -piv --include '@uppy/*' --exclude '@uppy/{angular,react-native,locales,companion,provider-views,robodog,svelte}' exec tsd",
146-
"test:unit": "yarn run build:lib && NODE_OPTIONS=--experimental-vm-modules jest --env jsdom",
147-
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --env jsdom --watch --no-coverage",
145+
"test:unit": "yarn run build:lib && yarn test:watch",
146+
"test:watch": "vitest --environment jsdom --dir packages/@uppy",
148147
"test": "npm-run-all lint test:locale-packs:unused test:unit test:type test:companion",
149148
"uploadcdn": "yarn node ./bin/upload-to-cdn.js",
150149
"version": "yarn node ./bin/after-version-bump.js",
@@ -154,24 +153,10 @@
154153
"watch:js": "npm-run-all --parallel watch:js:bundle watch:js:lib",
155154
"watch": "npm-run-all --parallel watch:css watch:js"
156155
},
157-
"jest": {
158-
"automock": false,
159-
"collectCoverage": true,
160-
"collectCoverageFrom": [
161-
"packages/**/src/**/*.js"
162-
],
163-
"testMatch": [
164-
"**/packages/**/*.test.js"
165-
],
166-
"testPathIgnorePatterns": [
167-
"/packages/@uppy/companion/"
168-
]
169-
},
170156
"resolutions": {
171157
"@types/eslint@^7.2.13": "^8.2.0",
172158
"@types/react": "^17",
173159
"@types/webpack-dev-server": "^4",
174-
"jest-environment-jsdom": "patch:jest-environment-jsdom@npm:29.5.0#.yarn/patches/jest-environment-jsdom-npm-29.5.0-fc600add1e.patch",
175160
"pre-commit": "patch:pre-commit@npm:1.2.2#.yarn/patches/pre-commit-npm-1.2.2-f30af83877.patch",
176161
"preact": "patch:preact@npm:10.10.0#.yarn/patches/preact-npm-10.10.0-dd04de05e8.patch",
177162
"start-server-and-test": "patch:start-server-and-test@npm:1.14.0#.yarn/patches/start-server-and-test-npm-1.14.0-841aa34fdf.patch",

Diff for: packages/@uppy/audio/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"preact": "^10.5.13"
3131
},
3232
"devDependencies": {
33-
"@jest/globals": "^29.0.0"
33+
"vitest": "^0.34.5"
3434
},
3535
"peerDependencies": {
3636
"@uppy/core": "workspace:^"

Diff for: packages/@uppy/audio/src/formatSeconds.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, it } from '@jest/globals'
1+
import { describe, expect, it } from 'vitest'
22
import formatSeconds from './formatSeconds.js'
33

44
describe('formatSeconds', () => {

Diff for: packages/@uppy/audio/src/supportsMediaRecorder.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable max-classes-per-file */
2-
import { describe, expect, it } from '@jest/globals'
2+
import { describe, expect, it } from 'vitest'
33
import supportsMediaRecorder from './supportsMediaRecorder.js'
44

55
describe('supportsMediaRecorder', () => {

Diff for: packages/@uppy/aws-s3-multipart/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
"devDependencies": {
3131
"@aws-sdk/client-s3": "^3.362.0",
3232
"@aws-sdk/s3-request-presigner": "^3.362.0",
33-
"@jest/globals": "^29.0.0",
3433
"nock": "^13.1.0",
34+
"vitest": "^0.34.5",
3535
"whatwg-fetch": "3.6.2"
3636
},
3737
"peerDependencies": {

Diff for: packages/@uppy/aws-s3-multipart/src/createSignedURL.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, beforeEach, afterEach } from '@jest/globals'
1+
import { describe, it, beforeEach, afterEach } from 'vitest'
22
import assert from 'node:assert'
33
import { S3Client, UploadPartCommand, PutObjectCommand } from '@aws-sdk/client-s3'
44
import { getSignedUrl } from '@aws-sdk/s3-request-presigner'

Diff for: packages/@uppy/aws-s3-multipart/src/index.test.js

+35-35
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { afterEach, beforeEach, describe, expect, it, jest } from '@jest/globals'
1+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
22

33
import 'whatwg-fetch'
44
import nock from 'nock'
@@ -68,15 +68,15 @@ describe('AwsS3Multipart', () => {
6868
const fileSize = 1
6969

7070
core.addFile({
71-
source: 'jest',
71+
source: 'vi',
7272
name: 'multitest.dat',
7373
type: 'application/octet-stream',
7474
data: new File([new Uint8Array(fileSize)], {
7575
type: 'application/octet-stream',
7676
}),
7777
})
7878

79-
const uploadSuccessHandler = jest.fn()
79+
const uploadSuccessHandler = vi.fn()
8080
core.on('upload-success', uploadSuccessHandler)
8181

8282
await core.upload()
@@ -102,15 +102,15 @@ describe('AwsS3Multipart', () => {
102102
core = new Core()
103103
core.use(AwsS3Multipart, {
104104
limit: 0,
105-
createMultipartUpload: jest.fn(() => {
105+
createMultipartUpload: vi.fn(() => {
106106
return {
107107
uploadId: '6aeb1980f3fc7ce0b5454d25b71992',
108108
key: 'test/upload/multitest.dat',
109109
}
110110
}),
111-
completeMultipartUpload: jest.fn(async () => ({ location: 'test' })),
112-
abortMultipartUpload: jest.fn(),
113-
prepareUploadParts: jest.fn(async (file, { parts }) => {
111+
completeMultipartUpload: vi.fn(async () => ({ location: 'test' })),
112+
abortMultipartUpload: vi.fn(),
113+
prepareUploadParts: vi.fn(async (file, { parts }) => {
114114
const presignedUrls = {}
115115
parts.forEach(({ number }) => {
116116
presignedUrls[
@@ -156,7 +156,7 @@ describe('AwsS3Multipart', () => {
156156
.reply(200, '', { ETag: 'test2' })
157157

158158
core.addFile({
159-
source: 'jest',
159+
source: 'vi',
160160
name: 'multitest.dat',
161161
type: 'application/octet-stream',
162162
data: new File([new Uint8Array(fileSize)], {
@@ -198,7 +198,7 @@ describe('AwsS3Multipart', () => {
198198
scope.persist()
199199

200200
core.addFile({
201-
source: 'jest',
201+
source: 'vi',
202202
name: 'multitest.dat',
203203
type: 'application/octet-stream',
204204
data: new File([new Uint8Array(fileSize)], {
@@ -270,13 +270,13 @@ describe('AwsS3Multipart', () => {
270270
let doneSpy
271271
awsS3Multipart.setOptions({
272272
retryDelays: [10],
273-
createMultipartUpload: jest.fn((file) => {
273+
createMultipartUpload: vi.fn((file) => {
274274
const multipartUploader = awsS3Multipart.uploaders[file.id]
275275
const testChunkState = multipartUploader.chunkState[6]
276276
let busy = false
277277
let done = false
278-
busySpy = jest.fn((value) => { busy = value })
279-
doneSpy = jest.fn((value) => { done = value })
278+
busySpy = vi.fn((value) => { busy = value })
279+
doneSpy = vi.fn((value) => { done = value })
280280
Object.defineProperty(testChunkState, 'busy', { get: () => busy, set: busySpy })
281281
Object.defineProperty(testChunkState, 'done', { get: () => done, set: doneSpy })
282282

@@ -288,7 +288,7 @@ describe('AwsS3Multipart', () => {
288288
})
289289

290290
core.addFile({
291-
source: 'jest',
291+
source: 'vi',
292292
name: 'multitest.dat',
293293
type: 'application/octet-stream',
294294
data: new File([new Uint8Array(fileSize)], {
@@ -316,29 +316,29 @@ describe('AwsS3Multipart', () => {
316316
})
317317

318318
describe('MultipartUploader', () => {
319-
const createMultipartUpload = jest.fn(() => {
319+
const createMultipartUpload = vi.fn(() => {
320320
return {
321321
uploadId: '6aeb1980f3fc7ce0b5454d25b71992',
322322
key: 'test/upload/multitest.dat',
323323
}
324324
})
325325

326-
const signPart = jest
326+
const signPart = vi
327327
.fn(async (file, { partNumber }) => {
328328
return { url: `https://bucket.s3.us-east-2.amazonaws.com/test/upload/multitest.dat?partNumber=${partNumber}&uploadId=6aeb1980f3fc7ce0b5454d25b71992&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIATEST%2F20210729%2Fus-east-2%2Fs3%2Faws4_request&X-Amz-Date=20210729T014044Z&X-Amz-Expires=600&X-Amz-SignedHeaders=host&X-Amz-Signature=test` }
329329
})
330330

331-
const uploadPartBytes = jest.fn()
331+
const uploadPartBytes = vi.fn()
332332

333-
afterEach(() => jest.clearAllMocks())
333+
afterEach(() => vi.clearAllMocks())
334334

335335
it('retries uploadPartBytes when it fails once', async () => {
336336
const core = new Core()
337337
.use(AwsS3Multipart, {
338338
createMultipartUpload,
339-
completeMultipartUpload: jest.fn(async () => ({ location: 'test' })),
339+
completeMultipartUpload: vi.fn(async () => ({ location: 'test' })),
340340
// eslint-disable-next-line no-throw-literal
341-
abortMultipartUpload: jest.fn(() => { throw 'should ignore' }),
341+
abortMultipartUpload: vi.fn(() => { throw 'should ignore' }),
342342
signPart,
343343
uploadPartBytes:
344344
uploadPartBytes
@@ -349,7 +349,7 @@ describe('AwsS3Multipart', () => {
349349
const fileSize = 5 * MB + 1 * MB
350350

351351
core.addFile({
352-
source: 'jest',
352+
source: 'vi',
353353
name: 'multitest.dat',
354354
type: 'application/octet-stream',
355355
data: new File([new Uint8Array(fileSize)], {
@@ -367,20 +367,20 @@ describe('AwsS3Multipart', () => {
367367
.use(AwsS3Multipart, {
368368
retryDelays: [10],
369369
createMultipartUpload,
370-
completeMultipartUpload: jest.fn(async () => ({ location: 'test' })),
371-
abortMultipartUpload: jest.fn(),
370+
completeMultipartUpload: vi.fn(async () => ({ location: 'test' })),
371+
abortMultipartUpload: vi.fn(),
372372
signPart,
373373
uploadPartBytes: uploadPartBytes
374374
// eslint-disable-next-line prefer-promise-reject-errors
375375
.mockImplementation(() => Promise.reject({ source: { status: 500 } })),
376376
})
377377
const awsS3Multipart = core.getPlugin('AwsS3Multipart')
378378
const fileSize = 5 * MB + 1 * MB
379-
const mock = jest.fn()
379+
const mock = vi.fn()
380380
core.on('upload-error', mock)
381381

382382
core.addFile({
383-
source: 'jest',
383+
source: 'vi',
384384
name: 'multitest.dat',
385385
type: 'application/octet-stream',
386386
data: new File([new Uint8Array(fileSize)], {
@@ -454,7 +454,7 @@ describe('AwsS3Multipart', () => {
454454

455455
describe('file metadata across custom main functions', () => {
456456
let core
457-
const createMultipartUpload = jest.fn(file => {
457+
const createMultipartUpload = vi.fn(file => {
458458
core.setFileMeta(file.id, {
459459
...file.meta,
460460
createMultipartUpload: true,
@@ -466,7 +466,7 @@ describe('AwsS3Multipart', () => {
466466
}
467467
})
468468

469-
const signPart = jest.fn((file, partData) => {
469+
const signPart = vi.fn((file, partData) => {
470470
expect(file.meta.createMultipartUpload).toBe(true)
471471

472472
core.setFileMeta(file.id, {
@@ -480,7 +480,7 @@ describe('AwsS3Multipart', () => {
480480
}
481481
})
482482

483-
const listParts = jest.fn((file) => {
483+
const listParts = vi.fn((file) => {
484484
expect(file.meta.createMultipartUpload).toBe(true)
485485
core.setFileMeta(file.id, {
486486
...file.meta,
@@ -495,7 +495,7 @@ describe('AwsS3Multipart', () => {
495495
}))
496496
})
497497

498-
const completeMultipartUpload = jest.fn((file) => {
498+
const completeMultipartUpload = vi.fn((file) => {
499499
expect(file.meta.createMultipartUpload).toBe(true)
500500
expect(file.meta.signPart).toBe(true)
501501
for (let i = 1; i <= 10; i++) {
@@ -504,7 +504,7 @@ describe('AwsS3Multipart', () => {
504504
return {}
505505
})
506506

507-
const abortMultipartUpload = jest.fn((file) => {
507+
const abortMultipartUpload = vi.fn((file) => {
508508
expect(file.meta.createMultipartUpload).toBe(true)
509509
expect(file.meta.signPart).toBe(true)
510510
expect(file.meta.abortingPart).toBe(5)
@@ -542,7 +542,7 @@ describe('AwsS3Multipart', () => {
542542

543543
const fileSize = 50 * MB
544544
core.addFile({
545-
source: 'jest',
545+
source: 'vi',
546546
name: 'multitest.dat',
547547
type: 'application/octet-stream',
548548
data: new File([new Uint8Array(fileSize)], {
@@ -557,7 +557,7 @@ describe('AwsS3Multipart', () => {
557557
})
558558

559559
it('preserves file metadata if upload is aborted', async () => {
560-
const signPartWithAbort = jest.fn((file, partData) => {
560+
const signPartWithAbort = vi.fn((file, partData) => {
561561
expect(file.meta.createMultipartUpload).toBe(true)
562562
if (partData.partNumber === 5) {
563563
core.setFileMeta(file.id, {
@@ -601,7 +601,7 @@ describe('AwsS3Multipart', () => {
601601

602602
const fileSize = 50 * MB
603603
core.addFile({
604-
source: 'jest',
604+
source: 'vi',
605605
name: 'multitest.dat',
606606
type: 'application/octet-stream',
607607
data: new File([new Uint8Array(fileSize)], {
@@ -616,7 +616,7 @@ describe('AwsS3Multipart', () => {
616616
})
617617

618618
it('preserves file metadata if upload is paused and resumed', async () => {
619-
const completeMultipartUploadAfterPause = jest.fn((file) => {
619+
const completeMultipartUploadAfterPause = vi.fn((file) => {
620620
expect(file.meta.createMultipartUpload).toBe(true)
621621
expect(file.meta.signPart).toBe(true)
622622
for (let i = 1; i <= 10; i++) {
@@ -627,7 +627,7 @@ describe('AwsS3Multipart', () => {
627627
return {}
628628
})
629629

630-
const signPartWithPause = jest.fn((file, partData) => {
630+
const signPartWithPause = vi.fn((file, partData) => {
631631
expect(file.meta.createMultipartUpload).toBe(true)
632632
if (partData.partNumber === 3) {
633633
core.setFileMeta(file.id, {
@@ -671,7 +671,7 @@ describe('AwsS3Multipart', () => {
671671

672672
const fileSize = 50 * MB
673673
core.addFile({
674-
source: 'jest',
674+
source: 'vi',
675675
name: 'multitest.dat',
676676
type: 'application/octet-stream',
677677
data: new File([new Uint8Array(fileSize)], {

Diff for: packages/@uppy/aws-s3/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"nanoid": "^4.0.0"
3131
},
3232
"devDependencies": {
33-
"@jest/globals": "^29.0.0",
33+
"vitest": "^0.34.5",
3434
"whatwg-fetch": "3.6.2"
3535
},
3636
"peerDependencies": {

Diff for: packages/@uppy/aws-s3/src/index.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeEach, describe, expect, it } from '@jest/globals'
1+
import { beforeEach, describe, expect, it } from 'vitest'
22
import 'whatwg-fetch'
33
import Core from '@uppy/core'
44
import AwsS3 from './index.js'

0 commit comments

Comments
 (0)