|
@@ -1,8 +1,9 @@
|
|
|
/* eslint no-console: "off", no-restricted-syntax: "off" */
|
|
|
-import { afterEach, beforeEach, describe, expect, it, jest, xit } from '@jest/globals'
|
|
|
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
|
|
import assert from 'node:assert'
|
|
|
import fs from 'node:fs'
|
|
|
+import path from 'node:path'
|
|
|
import prettierBytes from '@transloadit/prettier-bytes'
|
|
|
import Core from '../lib/index.js'
|
|
|
import UIPlugin from '../lib/UIPlugin.js'
|
|
@@ -14,12 +15,13 @@ import InvalidPluginWithoutId from './mocks/invalidPluginWithoutId.js'
|
|
|
import InvalidPluginWithoutType from './mocks/invalidPluginWithoutType.js'
|
|
|
import DeepFrozenStore from '../../../../e2e/cypress/fixtures/DeepFrozenStore.mjs'
|
|
|
|
|
|
-const sampleImage = fs.readFileSync(new URL('../../../../e2e/cypress/fixtures/images/image.jpg', import.meta.url))
|
|
|
+// eslint-disable-next-line no-restricted-globals
|
|
|
+const sampleImage = fs.readFileSync(path.join(__dirname, '../../../../e2e/cypress/fixtures/images/image.jpg'))
|
|
|
|
|
|
describe('src/Core', () => {
|
|
|
const RealCreateObjectUrl = globalThis.URL.createObjectURL
|
|
|
beforeEach(() => {
|
|
|
- globalThis.URL.createObjectURL = jest.fn().mockReturnValue('newUrl')
|
|
|
+ globalThis.URL.createObjectURL = vi.fn().mockReturnValue('newUrl')
|
|
|
})
|
|
|
|
|
|
afterEach(() => {
|
|
@@ -134,7 +136,7 @@ describe('src/Core', () => {
|
|
|
|
|
|
it('should update the state', () => {
|
|
|
const core = new Core()
|
|
|
- const stateUpdateEventMock = jest.fn()
|
|
|
+ const stateUpdateEventMock = vi.fn()
|
|
|
core.on('state-update', stateUpdateEventMock)
|
|
|
core.use(AcquirerPlugin1)
|
|
|
core.use(AcquirerPlugin2)
|
|
@@ -210,9 +212,9 @@ describe('src/Core', () => {
|
|
|
const core = new Core({
|
|
|
store: DeepFrozenStore(),
|
|
|
})
|
|
|
- // const corePauseEventMock = jest.fn()
|
|
|
- const coreCancelEventMock = jest.fn()
|
|
|
- const coreStateUpdateEventMock = jest.fn()
|
|
|
+ // const corePauseEventMock = vi.fn()
|
|
|
+ const coreCancelEventMock = vi.fn()
|
|
|
+ const coreStateUpdateEventMock = vi.fn()
|
|
|
core.on('cancel-all', coreCancelEventMock)
|
|
|
core.on('state-update', coreStateUpdateEventMock)
|
|
|
core.setState({ foo: 'bar', totalProgress: 30 })
|
|
@@ -240,14 +242,14 @@ describe('src/Core', () => {
|
|
|
const core = new Core()
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo1.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
|
})
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo2.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -277,14 +279,14 @@ describe('src/Core', () => {
|
|
|
})
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo1.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
|
})
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo2.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -314,14 +316,14 @@ describe('src/Core', () => {
|
|
|
})
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo1.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
|
})
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo2.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -351,14 +353,14 @@ describe('src/Core', () => {
|
|
|
})
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo1.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
|
})
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo2.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -383,8 +385,8 @@ describe('src/Core', () => {
|
|
|
})
|
|
|
core.use(AcquirerPlugin1)
|
|
|
|
|
|
- const coreCancelEventMock = jest.fn()
|
|
|
- const coreStateUpdateEventMock = jest.fn()
|
|
|
+ const coreCancelEventMock = vi.fn()
|
|
|
+ const coreStateUpdateEventMock = vi.fn()
|
|
|
const plugin = core[Symbol.for('uppy test: getPlugins')]('acquirer')[0]
|
|
|
|
|
|
core.on('cancel-all', coreCancelEventMock)
|
|
@@ -408,7 +410,7 @@ describe('src/Core', () => {
|
|
|
})
|
|
|
expect(plugin.mocks.uninstall.mock.calls.length).toEqual(1)
|
|
|
|
|
|
- const pluginIteration = jest.fn()
|
|
|
+ const pluginIteration = vi.fn()
|
|
|
core.iteratePlugins(pluginIteration)
|
|
|
expect(pluginIteration.mock.calls.length).toEqual(0)
|
|
|
})
|
|
@@ -445,13 +447,13 @@ describe('src/Core', () => {
|
|
|
|
|
|
it('should execute all the preprocessors when uploading a file', () => {
|
|
|
const core = new Core()
|
|
|
- const preprocessor1 = jest.fn()
|
|
|
- const preprocessor2 = jest.fn()
|
|
|
+ const preprocessor1 = vi.fn()
|
|
|
+ const preprocessor2 = vi.fn()
|
|
|
core.addPreProcessor(preprocessor1)
|
|
|
core.addPreProcessor(preprocessor2)
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -472,20 +474,20 @@ describe('src/Core', () => {
|
|
|
|
|
|
it('should not pass removed file IDs to next step', async () => {
|
|
|
const core = new Core()
|
|
|
- const uploader = jest.fn()
|
|
|
+ const uploader = vi.fn()
|
|
|
core.addPreProcessor((fileIDs) => {
|
|
|
core.removeFile(fileIDs[0])
|
|
|
})
|
|
|
core.addUploader(uploader)
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'rmd.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
|
})
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'kept.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -501,7 +503,7 @@ describe('src/Core', () => {
|
|
|
it('should update the file progress state when preprocess-progress event is fired', () => {
|
|
|
const core = new Core()
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -528,7 +530,7 @@ describe('src/Core', () => {
|
|
|
const core = new Core()
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -563,13 +565,13 @@ describe('src/Core', () => {
|
|
|
|
|
|
it('should execute all the postprocessors when uploading a file', () => {
|
|
|
const core = new Core()
|
|
|
- const postprocessor1 = jest.fn()
|
|
|
- const postprocessor2 = jest.fn()
|
|
|
+ const postprocessor1 = vi.fn()
|
|
|
+ const postprocessor2 = vi.fn()
|
|
|
core.addPostProcessor(postprocessor1)
|
|
|
core.addPostProcessor(postprocessor2)
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -597,7 +599,7 @@ describe('src/Core', () => {
|
|
|
const core = new Core()
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -624,7 +626,7 @@ describe('src/Core', () => {
|
|
|
const core = new Core()
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -650,7 +652,7 @@ describe('src/Core', () => {
|
|
|
const core = new Core()
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -683,7 +685,7 @@ describe('src/Core', () => {
|
|
|
|
|
|
describe('adding a file', () => {
|
|
|
it('should call onBeforeFileAdded if it was specified in the options when initialising the class', () => {
|
|
|
- const onBeforeFileAdded = jest.fn()
|
|
|
+ const onBeforeFileAdded = vi.fn()
|
|
|
|
|
|
const core = new Core({
|
|
|
// need to capture a snapshot of files, because files will change in the next tick, thus failing the expect below
|
|
@@ -691,7 +693,7 @@ describe('src/Core', () => {
|
|
|
})
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -707,14 +709,14 @@ describe('src/Core', () => {
|
|
|
const sameFileBlob = new File([sampleImage], { type: 'image/jpeg' })
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: sameFileBlob,
|
|
|
})
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: sameFileBlob,
|
|
@@ -723,12 +725,12 @@ describe('src/Core', () => {
|
|
|
|
|
|
it('should add a file', () => {
|
|
|
const fileData = new File([sampleImage], { type: 'image/jpeg' })
|
|
|
- const fileAddedEventMock = jest.fn()
|
|
|
+ const fileAddedEventMock = vi.fn()
|
|
|
const core = new Core()
|
|
|
core.on('file-added', fileAddedEventMock)
|
|
|
|
|
|
const fileId = core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: fileData,
|
|
@@ -750,7 +752,7 @@ describe('src/Core', () => {
|
|
|
},
|
|
|
remote: '',
|
|
|
size: 17175,
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
type: 'image/jpeg',
|
|
|
}
|
|
|
expect(core.getFile(fileId)).toEqual(newFile)
|
|
@@ -774,7 +776,7 @@ describe('src/Core', () => {
|
|
|
|
|
|
expect(() => {
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -783,7 +785,7 @@ describe('src/Core', () => {
|
|
|
|
|
|
expect(() => {
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.webm',
|
|
|
type: 'video/webm; codecs="vp8, opus"',
|
|
|
data: new File([sampleImage], { type: 'video/webm; codecs="vp8, opus"' }),
|
|
@@ -795,14 +797,14 @@ describe('src/Core', () => {
|
|
|
const core = new Core()
|
|
|
const sameFileBlob = new File([sampleImage], { type: 'image/jpeg' })
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: sameFileBlob,
|
|
|
})
|
|
|
expect(() => {
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: sameFileBlob,
|
|
@@ -819,13 +821,13 @@ describe('src/Core', () => {
|
|
|
it('should allow a duplicate file if its relativePath is different, thus the id is different', () => {
|
|
|
const core = new Core()
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
|
})
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -839,7 +841,7 @@ describe('src/Core', () => {
|
|
|
it('should not allow a file if onBeforeFileAdded returned false', () => {
|
|
|
const core = new Core({
|
|
|
onBeforeFileAdded: (file) => {
|
|
|
- if (file.source === 'jest') {
|
|
|
+ if (file.source === 'vi') {
|
|
|
return false
|
|
|
}
|
|
|
return undefined
|
|
@@ -847,7 +849,7 @@ describe('src/Core', () => {
|
|
|
})
|
|
|
expect(() => {
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -862,7 +864,7 @@ describe('src/Core', () => {
|
|
|
it('allows no new files after upload', async () => {
|
|
|
const core = new Core({ allowMultipleUploadBatches: false })
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -872,7 +874,7 @@ describe('src/Core', () => {
|
|
|
|
|
|
expect(() => {
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: '123.foo',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -885,7 +887,7 @@ describe('src/Core', () => {
|
|
|
it('allows no new files after upload with legacy allowMultipleUploads option', async () => {
|
|
|
const core = new Core({ allowMultipleUploads: false })
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -895,7 +897,7 @@ describe('src/Core', () => {
|
|
|
|
|
|
expect(() => {
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: '123.foo',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -910,13 +912,13 @@ describe('src/Core', () => {
|
|
|
|
|
|
// adding 2 files
|
|
|
const fileId1 = core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: '1.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
|
})
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: '2.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -933,13 +935,13 @@ describe('src/Core', () => {
|
|
|
|
|
|
// adding 2 files
|
|
|
const fileId1 = core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: '1.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
|
})
|
|
|
const fileId2 = core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: '2.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -959,13 +961,13 @@ describe('src/Core', () => {
|
|
|
data.lastModified = 1562770350937
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data,
|
|
|
})
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo푸.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data,
|
|
@@ -982,8 +984,8 @@ describe('src/Core', () => {
|
|
|
const core = new Core()
|
|
|
core.addUploader(() => Promise.resolve())
|
|
|
|
|
|
- core.addFile({ source: 'jest', name: 'foo.jpg', type: 'image/jpeg', data: new Uint8Array() })
|
|
|
- core.addFile({ source: 'jest', name: 'bar.jpg', type: 'image/jpeg', data: new Uint8Array() })
|
|
|
+ core.addFile({ source: 'vi', name: 'foo.jpg', type: 'image/jpeg', data: new Uint8Array() })
|
|
|
+ core.addFile({ source: 'vi', name: 'bar.jpg', type: 'image/jpeg', data: new Uint8Array() })
|
|
|
|
|
|
return expect(core.upload()).resolves.toMatchObject({
|
|
|
successful: [
|
|
@@ -1009,8 +1011,8 @@ describe('src/Core', () => {
|
|
|
return Promise.resolve()
|
|
|
})
|
|
|
|
|
|
- core.addFile({ source: 'jest', name: 'foo.jpg', type: 'image/jpeg', data: new Uint8Array() })
|
|
|
- core.addFile({ source: 'jest', name: 'bar.jpg', type: 'image/jpeg', data: new Uint8Array() })
|
|
|
+ core.addFile({ source: 'vi', name: 'foo.jpg', type: 'image/jpeg', data: new Uint8Array() })
|
|
|
+ core.addFile({ source: 'vi', name: 'bar.jpg', type: 'image/jpeg', data: new Uint8Array() })
|
|
|
|
|
|
return expect(core.upload()).resolves.toMatchObject({
|
|
|
successful: [
|
|
@@ -1034,8 +1036,8 @@ describe('src/Core', () => {
|
|
|
}
|
|
|
core.addUploader(() => Promise.resolve())
|
|
|
|
|
|
- core.addFile({ source: 'jest', name: 'foo.jpg', type: 'image/jpeg', data: new Uint8Array() })
|
|
|
- core.addFile({ source: 'jest', name: 'bar.jpg', type: 'image/jpeg', data: new Uint8Array() })
|
|
|
+ core.addFile({ source: 'vi', name: 'foo.jpg', type: 'image/jpeg', data: new Uint8Array() })
|
|
|
+ core.addFile({ source: 'vi', name: 'bar.jpg', type: 'image/jpeg', data: new Uint8Array() })
|
|
|
core.addFile({ source: 'file3', name: 'file3.jpg', type: 'image/jpeg', data: new Uint8Array() })
|
|
|
|
|
|
// uploadID is random, we don't want randomness in the snapshot
|
|
@@ -1058,19 +1060,19 @@ describe('src/Core', () => {
|
|
|
},
|
|
|
})
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
|
})
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'bar.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
|
})
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: '123.foo',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -1083,13 +1085,13 @@ describe('src/Core', () => {
|
|
|
it('only allows a single upload() batch when allowMultipleUploadBatches: false', async () => {
|
|
|
const core = new Core({ allowMultipleUploadBatches: false })
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
|
})
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'bar.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -1105,7 +1107,7 @@ describe('src/Core', () => {
|
|
|
const core = new Core({ allowMultipleUploadBatches: false })
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'bar.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -1115,7 +1117,7 @@ describe('src/Core', () => {
|
|
|
core.cancelAll()
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: '123.foo',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -1126,13 +1128,13 @@ describe('src/Core', () => {
|
|
|
|
|
|
describe('removing a file', () => {
|
|
|
it('should remove the file', () => {
|
|
|
- const fileRemovedEventMock = jest.fn()
|
|
|
+ const fileRemovedEventMock = vi.fn()
|
|
|
|
|
|
const core = new Core()
|
|
|
core.on('file-removed', fileRemovedEventMock)
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -1155,15 +1157,15 @@ describe('src/Core', () => {
|
|
|
|
|
|
describe('retries', () => {
|
|
|
it('should start a new upload with failed files', async () => {
|
|
|
- const onUpload = jest.fn()
|
|
|
- const onRetryAll = jest.fn()
|
|
|
+ const onUpload = vi.fn()
|
|
|
+ const onRetryAll = vi.fn()
|
|
|
|
|
|
const core = new Core()
|
|
|
core.on('upload', onUpload)
|
|
|
core.on('retry-all', onRetryAll)
|
|
|
|
|
|
const id = core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -1178,13 +1180,13 @@ describe('src/Core', () => {
|
|
|
})
|
|
|
|
|
|
it('should not start a new upload if there are no failed files', async () => {
|
|
|
- const onUpload = jest.fn()
|
|
|
+ const onUpload = vi.fn()
|
|
|
|
|
|
const core = new Core()
|
|
|
core.on('upload', onUpload)
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -1196,9 +1198,9 @@ describe('src/Core', () => {
|
|
|
})
|
|
|
|
|
|
describe('restoring a file', () => {
|
|
|
- xit('should restore a file', () => { })
|
|
|
+ it.skip('should restore a file', () => { })
|
|
|
|
|
|
- xit("should fail to restore a file if it doesn't exist", () => { })
|
|
|
+ it.skip("should fail to restore a file if it doesn't exist", () => { })
|
|
|
})
|
|
|
|
|
|
describe('get a file', () => {
|
|
@@ -1206,7 +1208,7 @@ describe('src/Core', () => {
|
|
|
const core = new Core()
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -1230,13 +1232,13 @@ describe('src/Core', () => {
|
|
|
const core = new Core()
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
|
})
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'empty.dat',
|
|
|
type: 'application/octet-stream',
|
|
|
data: new File([new Uint8Array(1000)], { type: 'application/octet-stream' }),
|
|
@@ -1309,7 +1311,7 @@ describe('src/Core', () => {
|
|
|
|
|
|
try {
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo1.png',
|
|
|
type: 'image/png',
|
|
|
data: new File([sampleImage], { type: 'image/png' }),
|
|
@@ -1328,7 +1330,7 @@ describe('src/Core', () => {
|
|
|
|
|
|
expect(() => {
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo1.png',
|
|
|
type: 'image/png',
|
|
|
data: new File([sampleImage], { type: 'image/png' }),
|
|
@@ -1360,7 +1362,7 @@ describe('src/Core', () => {
|
|
|
const core = new Core()
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -1383,7 +1385,7 @@ describe('src/Core', () => {
|
|
|
meta: { foo2: 'bar2' },
|
|
|
})
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
meta: {
|
|
@@ -1406,7 +1408,7 @@ describe('src/Core', () => {
|
|
|
const core = new Core()
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -1558,13 +1560,13 @@ describe('src/Core', () => {
|
|
|
})
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
|
})
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo2.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -1591,18 +1593,18 @@ describe('src/Core', () => {
|
|
|
})
|
|
|
|
|
|
it('should reset the progress', () => {
|
|
|
- const resetProgressEvent = jest.fn()
|
|
|
+ const resetProgressEvent = vi.fn()
|
|
|
const core = new Core()
|
|
|
core.on('reset-progress', resetProgressEvent)
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
|
})
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo2.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -1662,14 +1664,14 @@ describe('src/Core', () => {
|
|
|
|
|
|
// add 2 files
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo1.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
|
})
|
|
|
try {
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo2.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -1691,7 +1693,7 @@ describe('src/Core', () => {
|
|
|
expect(() => {
|
|
|
// add 1 ghost file
|
|
|
const fileId1 = core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo1.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -1700,7 +1702,7 @@ describe('src/Core', () => {
|
|
|
|
|
|
// add another file
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo2.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -1708,7 +1710,7 @@ describe('src/Core', () => {
|
|
|
}).not.toThrowError()
|
|
|
})
|
|
|
|
|
|
- xit('should enforce the minNumberOfFiles rule', () => { })
|
|
|
+ it.skip('should enforce the minNumberOfFiles rule', () => { })
|
|
|
|
|
|
it('should enforce the allowedFileTypes rule', () => {
|
|
|
const core = new Core({
|
|
@@ -1719,7 +1721,7 @@ describe('src/Core', () => {
|
|
|
|
|
|
try {
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo2.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -1753,7 +1755,7 @@ describe('src/Core', () => {
|
|
|
|
|
|
try {
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo2.png',
|
|
|
type: '',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -1765,7 +1767,7 @@ describe('src/Core', () => {
|
|
|
}
|
|
|
|
|
|
expect(() => core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo2.JPG',
|
|
|
type: '',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -1781,7 +1783,7 @@ describe('src/Core', () => {
|
|
|
|
|
|
try {
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -1802,7 +1804,7 @@ describe('src/Core', () => {
|
|
|
|
|
|
try {
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -1822,7 +1824,7 @@ describe('src/Core', () => {
|
|
|
})
|
|
|
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -1830,7 +1832,7 @@ describe('src/Core', () => {
|
|
|
|
|
|
expect(() => {
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo1.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -1854,7 +1856,7 @@ describe('src/Core', () => {
|
|
|
})
|
|
|
|
|
|
const newFile = {
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo1.jpg',
|
|
|
extension: 'jpg',
|
|
|
type: 'image/jpeg',
|
|
@@ -1879,7 +1881,7 @@ describe('src/Core', () => {
|
|
|
maxFileSize,
|
|
|
},
|
|
|
})
|
|
|
- const restrictionsViolatedEventMock = jest.fn()
|
|
|
+ const restrictionsViolatedEventMock = vi.fn()
|
|
|
const file = {
|
|
|
name: 'test.jpg',
|
|
|
data: new Blob([new Uint8Array(2 * maxFileSize)]),
|
|
@@ -1950,9 +1952,9 @@ describe('src/Core', () => {
|
|
|
})
|
|
|
|
|
|
it('should emit the correct event based on whether there is a network connection', () => {
|
|
|
- const onlineEventMock = jest.fn()
|
|
|
- const offlineEventMock = jest.fn()
|
|
|
- const backOnlineEventMock = jest.fn()
|
|
|
+ const onlineEventMock = vi.fn()
|
|
|
+ const offlineEventMock = vi.fn()
|
|
|
+ const backOnlineEventMock = vi.fn()
|
|
|
const core = new Core()
|
|
|
core.on('is-offline', offlineEventMock)
|
|
|
core.on('is-online', onlineEventMock)
|
|
@@ -1980,7 +1982,7 @@ describe('src/Core', () => {
|
|
|
|
|
|
describe('info', () => {
|
|
|
it('should set a string based message to be displayed infinitely', () => {
|
|
|
- const infoVisibleEvent = jest.fn()
|
|
|
+ const infoVisibleEvent = vi.fn()
|
|
|
const core = new Core()
|
|
|
core.on('info-visible', infoVisibleEvent)
|
|
|
|
|
@@ -1994,7 +1996,7 @@ describe('src/Core', () => {
|
|
|
})
|
|
|
|
|
|
it('should set a object based message to be displayed infinitely', () => {
|
|
|
- const infoVisibleEvent = jest.fn()
|
|
|
+ const infoVisibleEvent = vi.fn()
|
|
|
const core = new Core()
|
|
|
core.on('info-visible', infoVisibleEvent)
|
|
|
|
|
@@ -2015,8 +2017,8 @@ describe('src/Core', () => {
|
|
|
})
|
|
|
|
|
|
it('should set an info message to be displayed for a period of time before hiding', (done) => {
|
|
|
- const infoVisibleEvent = jest.fn()
|
|
|
- const infoHiddenEvent = jest.fn()
|
|
|
+ const infoVisibleEvent = vi.fn()
|
|
|
+ const infoHiddenEvent = vi.fn()
|
|
|
const core = new Core()
|
|
|
core.on('info-visible', infoVisibleEvent)
|
|
|
core.on('info-hidden', infoHiddenEvent)
|
|
@@ -2031,8 +2033,8 @@ describe('src/Core', () => {
|
|
|
})
|
|
|
|
|
|
it('should hide an info message', () => {
|
|
|
- const infoVisibleEvent = jest.fn()
|
|
|
- const infoHiddenEvent = jest.fn()
|
|
|
+ const infoVisibleEvent = vi.fn()
|
|
|
+ const infoHiddenEvent = vi.fn()
|
|
|
const core = new Core()
|
|
|
core.on('info-visible', infoVisibleEvent)
|
|
|
core.on('info-hidden', infoHiddenEvent)
|
|
@@ -2045,8 +2047,8 @@ describe('src/Core', () => {
|
|
|
})
|
|
|
|
|
|
it('should support multiple messages', () => {
|
|
|
- const infoVisibleEvent = jest.fn()
|
|
|
- const infoHiddenEvent = jest.fn()
|
|
|
+ const infoVisibleEvent = vi.fn()
|
|
|
+ const infoHiddenEvent = vi.fn()
|
|
|
const core = new Core()
|
|
|
|
|
|
core.on('info-visible', infoVisibleEvent)
|
|
@@ -2089,7 +2091,7 @@ describe('src/Core', () => {
|
|
|
it('should assign the specified files to a new upload', () => {
|
|
|
const core = new Core()
|
|
|
core.addFile({
|
|
|
- source: 'jest',
|
|
|
+ source: 'vi',
|
|
|
name: 'foo.jpg',
|
|
|
type: 'image/jpeg',
|
|
|
data: new File([sampleImage], { type: 'image/jpeg' }),
|
|
@@ -2138,9 +2140,9 @@ describe('src/Core', () => {
|
|
|
describe('log', () => {
|
|
|
it('should log via provided logger function', () => {
|
|
|
const myTestLogger = {
|
|
|
- debug: jest.fn(),
|
|
|
- warn: jest.fn(),
|
|
|
- error: jest.fn(),
|
|
|
+ debug: vi.fn(),
|
|
|
+ warn: vi.fn(),
|
|
|
+ error: vi.fn(),
|
|
|
}
|
|
|
|
|
|
const core = new Core({
|
|
@@ -2161,9 +2163,9 @@ describe('src/Core', () => {
|
|
|
|
|
|
it('should log via provided logger function, even if debug: true', () => {
|
|
|
const myTestLogger = {
|
|
|
- debug: jest.fn(),
|
|
|
- warn: jest.fn(),
|
|
|
- error: jest.fn(),
|
|
|
+ debug: vi.fn(),
|
|
|
+ warn: vi.fn(),
|
|
|
+ error: vi.fn(),
|
|
|
}
|
|
|
|
|
|
const core = new Core({
|
|
@@ -2186,8 +2188,8 @@ describe('src/Core', () => {
|
|
|
})
|
|
|
|
|
|
it('should log to console when logger: Uppy.debugLogger or debug: true is set', () => {
|
|
|
- console.debug = jest.fn()
|
|
|
- console.error = jest.fn()
|
|
|
+ console.debug = vi.fn()
|
|
|
+ console.error = vi.fn()
|
|
|
|
|
|
const core = new Core({
|
|
|
logger: debugLogger,
|
|
@@ -2220,8 +2222,8 @@ describe('src/Core', () => {
|
|
|
})
|
|
|
|
|
|
it('should only log errors to console when logger is not set', () => {
|
|
|
- console.debug = jest.fn()
|
|
|
- console.error = jest.fn()
|
|
|
+ console.debug = vi.fn()
|
|
|
+ console.error = vi.fn()
|
|
|
|
|
|
const core = new Core()
|
|
|
|