Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: migrate to Vitest for Uppy core and Uppy plugins #4700

Merged
merged 5 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions .yarn/patches/jest-environment-jsdom-npm-29.5.0-fc600add1e.patch

This file was deleted.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@
"eslint-plugin-unicorn": "^46.0.0",
"github-contributors-list": "^1.2.4",
"glob": "^8.0.0",
"jest": "^29.0.0",
"jest-environment-jsdom": "^29.0.0",
"jsdom": "^22.1.0",
"lint-staged": "^13.0.0",
"mime-types": "^2.1.26",
"nodemon": "^2.0.8",
Expand All @@ -104,6 +103,7 @@
"tar": "^6.1.0",
"tsd": "^0.22.0",
"typescript": "~4.8",
"vitest": "^0.34.5",
"vue-template-compiler": "workspace:*"
},
"scripts": {
Expand Down Expand Up @@ -143,8 +143,8 @@
"test:locale-packs:unused": "yarn workspace @uppy-dev/locale-pack test unused",
"test:locale-packs:warnings": "yarn workspace @uppy-dev/locale-pack test warnings",
"test:type": "yarn workspaces foreach -piv --include '@uppy/*' --exclude '@uppy/{angular,react-native,locales,companion,provider-views,robodog,svelte}' exec tsd",
"test:unit": "yarn run build:lib && NODE_OPTIONS=--experimental-vm-modules jest --env jsdom",
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --env jsdom --watch --no-coverage",
"test:unit": "yarn run build:lib && yarn test:watch",
"test:watch": "vitest --environment jsdom --dir packages/@uppy",
"test": "npm-run-all lint test:locale-packs:unused test:unit test:type test:companion",
"uploadcdn": "yarn node ./bin/upload-to-cdn.js",
"version": "yarn node ./bin/after-version-bump.js",
Expand All @@ -171,7 +171,6 @@
"@types/eslint@^7.2.13": "^8.2.0",
"@types/react": "^17",
"@types/webpack-dev-server": "^4",
"jest-environment-jsdom": "patch:jest-environment-jsdom@npm:29.5.0#.yarn/patches/jest-environment-jsdom-npm-29.5.0-fc600add1e.patch",
"pre-commit": "patch:pre-commit@npm:1.2.2#.yarn/patches/pre-commit-npm-1.2.2-f30af83877.patch",
"preact": "patch:preact@npm:10.10.0#.yarn/patches/preact-npm-10.10.0-dd04de05e8.patch",
"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",
aduh95 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/audio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"preact": "^10.5.13"
},
"devDependencies": {
"@jest/globals": "^29.0.0"
"vitest": "^0.34.5"
},
"peerDependencies": {
"@uppy/core": "workspace:^"
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/audio/src/formatSeconds.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, it } from '@jest/globals'
import { describe, expect, it } from 'vitest'
import formatSeconds from './formatSeconds.js'

describe('formatSeconds', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/audio/src/supportsMediaRecorder.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable max-classes-per-file */
import { describe, expect, it } from '@jest/globals'
import { describe, expect, it } from 'vitest'
import supportsMediaRecorder from './supportsMediaRecorder.js'

describe('supportsMediaRecorder', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/aws-s3-multipart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"devDependencies": {
"@aws-sdk/client-s3": "^3.362.0",
"@aws-sdk/s3-request-presigner": "^3.362.0",
"@jest/globals": "^29.0.0",
"nock": "^13.1.0",
"vitest": "^0.34.5",
"whatwg-fetch": "3.6.2"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, beforeEach, afterEach } from '@jest/globals'
import { describe, it, beforeEach, afterEach } from 'vitest'
import assert from 'node:assert'
import { S3Client, UploadPartCommand, PutObjectCommand } from '@aws-sdk/client-s3'
import { getSignedUrl } from '@aws-sdk/s3-request-presigner'
Expand Down
70 changes: 35 additions & 35 deletions packages/@uppy/aws-s3-multipart/src/index.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterEach, beforeEach, describe, expect, it, jest } from '@jest/globals'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'

import 'whatwg-fetch'
import nock from 'nock'
Expand Down Expand Up @@ -68,15 +68,15 @@ describe('AwsS3Multipart', () => {
const fileSize = 1

core.addFile({
source: 'jest',
source: 'vi',
name: 'multitest.dat',
type: 'application/octet-stream',
data: new File([new Uint8Array(fileSize)], {
type: 'application/octet-stream',
}),
})

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

await core.upload()
Expand All @@ -102,15 +102,15 @@ describe('AwsS3Multipart', () => {
core = new Core()
core.use(AwsS3Multipart, {
limit: 0,
createMultipartUpload: jest.fn(() => {
createMultipartUpload: vi.fn(() => {
return {
uploadId: '6aeb1980f3fc7ce0b5454d25b71992',
key: 'test/upload/multitest.dat',
}
}),
completeMultipartUpload: jest.fn(async () => ({ location: 'test' })),
abortMultipartUpload: jest.fn(),
prepareUploadParts: jest.fn(async (file, { parts }) => {
completeMultipartUpload: vi.fn(async () => ({ location: 'test' })),
abortMultipartUpload: vi.fn(),
prepareUploadParts: vi.fn(async (file, { parts }) => {
const presignedUrls = {}
parts.forEach(({ number }) => {
presignedUrls[
Expand Down Expand Up @@ -156,7 +156,7 @@ describe('AwsS3Multipart', () => {
.reply(200, '', { ETag: 'test2' })

core.addFile({
source: 'jest',
source: 'vi',
name: 'multitest.dat',
type: 'application/octet-stream',
data: new File([new Uint8Array(fileSize)], {
Expand Down Expand Up @@ -198,7 +198,7 @@ describe('AwsS3Multipart', () => {
scope.persist()

core.addFile({
source: 'jest',
source: 'vi',
name: 'multitest.dat',
type: 'application/octet-stream',
data: new File([new Uint8Array(fileSize)], {
Expand Down Expand Up @@ -270,13 +270,13 @@ describe('AwsS3Multipart', () => {
let doneSpy
awsS3Multipart.setOptions({
retryDelays: [10],
createMultipartUpload: jest.fn((file) => {
createMultipartUpload: vi.fn((file) => {
const multipartUploader = awsS3Multipart.uploaders[file.id]
const testChunkState = multipartUploader.chunkState[6]
let busy = false
let done = false
busySpy = jest.fn((value) => { busy = value })
doneSpy = jest.fn((value) => { done = value })
busySpy = vi.fn((value) => { busy = value })
doneSpy = vi.fn((value) => { done = value })
Object.defineProperty(testChunkState, 'busy', { get: () => busy, set: busySpy })
Object.defineProperty(testChunkState, 'done', { get: () => done, set: doneSpy })

Expand All @@ -288,7 +288,7 @@ describe('AwsS3Multipart', () => {
})

core.addFile({
source: 'jest',
source: 'vi',
name: 'multitest.dat',
type: 'application/octet-stream',
data: new File([new Uint8Array(fileSize)], {
Expand Down Expand Up @@ -316,29 +316,29 @@ describe('AwsS3Multipart', () => {
})

describe('MultipartUploader', () => {
const createMultipartUpload = jest.fn(() => {
const createMultipartUpload = vi.fn(() => {
return {
uploadId: '6aeb1980f3fc7ce0b5454d25b71992',
key: 'test/upload/multitest.dat',
}
})

const signPart = jest
const signPart = vi
.fn(async (file, { partNumber }) => {
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` }
})

const uploadPartBytes = jest.fn()
const uploadPartBytes = vi.fn()

afterEach(() => jest.clearAllMocks())
afterEach(() => vi.clearAllMocks())

it('retries uploadPartBytes when it fails once', async () => {
const core = new Core()
.use(AwsS3Multipart, {
createMultipartUpload,
completeMultipartUpload: jest.fn(async () => ({ location: 'test' })),
completeMultipartUpload: vi.fn(async () => ({ location: 'test' })),
// eslint-disable-next-line no-throw-literal
abortMultipartUpload: jest.fn(() => { throw 'should ignore' }),
abortMultipartUpload: vi.fn(() => { throw 'should ignore' }),
signPart,
uploadPartBytes:
uploadPartBytes
Expand All @@ -349,7 +349,7 @@ describe('AwsS3Multipart', () => {
const fileSize = 5 * MB + 1 * MB

core.addFile({
source: 'jest',
source: 'vi',
name: 'multitest.dat',
type: 'application/octet-stream',
data: new File([new Uint8Array(fileSize)], {
Expand All @@ -367,20 +367,20 @@ describe('AwsS3Multipart', () => {
.use(AwsS3Multipart, {
retryDelays: [10],
createMultipartUpload,
completeMultipartUpload: jest.fn(async () => ({ location: 'test' })),
abortMultipartUpload: jest.fn(),
completeMultipartUpload: vi.fn(async () => ({ location: 'test' })),
abortMultipartUpload: vi.fn(),
signPart,
uploadPartBytes: uploadPartBytes
// eslint-disable-next-line prefer-promise-reject-errors
.mockImplementation(() => Promise.reject({ source: { status: 500 } })),
})
const awsS3Multipart = core.getPlugin('AwsS3Multipart')
const fileSize = 5 * MB + 1 * MB
const mock = jest.fn()
const mock = vi.fn()
core.on('upload-error', mock)

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

describe('file metadata across custom main functions', () => {
let core
const createMultipartUpload = jest.fn(file => {
const createMultipartUpload = vi.fn(file => {
core.setFileMeta(file.id, {
...file.meta,
createMultipartUpload: true,
Expand All @@ -466,7 +466,7 @@ describe('AwsS3Multipart', () => {
}
})

const signPart = jest.fn((file, partData) => {
const signPart = vi.fn((file, partData) => {
expect(file.meta.createMultipartUpload).toBe(true)

core.setFileMeta(file.id, {
Expand All @@ -480,7 +480,7 @@ describe('AwsS3Multipart', () => {
}
})

const listParts = jest.fn((file) => {
const listParts = vi.fn((file) => {
expect(file.meta.createMultipartUpload).toBe(true)
core.setFileMeta(file.id, {
...file.meta,
Expand All @@ -495,7 +495,7 @@ describe('AwsS3Multipart', () => {
}))
})

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

const abortMultipartUpload = jest.fn((file) => {
const abortMultipartUpload = vi.fn((file) => {
expect(file.meta.createMultipartUpload).toBe(true)
expect(file.meta.signPart).toBe(true)
expect(file.meta.abortingPart).toBe(5)
Expand Down Expand Up @@ -542,7 +542,7 @@ describe('AwsS3Multipart', () => {

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

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

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

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

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

const fileSize = 50 * MB
core.addFile({
source: 'jest',
source: 'vi',
name: 'multitest.dat',
type: 'application/octet-stream',
data: new File([new Uint8Array(fileSize)], {
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/aws-s3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"nanoid": "^4.0.0"
},
"devDependencies": {
"@jest/globals": "^29.0.0",
"vitest": "^0.34.5",
"whatwg-fetch": "3.6.2"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/aws-s3/src/index.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, it } from '@jest/globals'
import { beforeEach, describe, expect, it } from 'vitest'
import 'whatwg-fetch'
import Core from '@uppy/core'
import AwsS3 from './index.js'
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/aws-s3/src/isXml.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, it } from '@jest/globals'
import { describe, expect, it } from 'vitest'
import isXml from './isXml.js'

describe('AwsS3', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/companion-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
"namespace-emitter": "^2.0.1"
},
"devDependencies": {
"@jest/globals": "^29.0.0"
"vitest": "^0.34.5"
}
}
2 changes: 1 addition & 1 deletion packages/@uppy/companion-client/src/RequestClient.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect } from '@jest/globals'
import { describe, it, expect } from 'vitest'
import RequestClient from './RequestClient.js'

describe('RequestClient', () => {
Expand Down
Loading