Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Murderlon committed Dec 5, 2023
1 parent ab5d243 commit 78b581a
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/@uppy/core/src/Restricter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class RestrictionError<M extends Meta, B extends Body> extends Error {
opts?: { isUserFacing?: boolean; file?: UppyFile<M, B> },
) {
super(message)
this.isUserFacing = opts?.isUserFacing ?? false
this.isUserFacing = opts?.isUserFacing ?? true
if (opts?.file) {
this.file = opts.file // only some restriction errors are related to a particular file
}
Expand Down
3 changes: 2 additions & 1 deletion packages/@uppy/core/src/Uppy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -821,14 +821,15 @@ describe('src/Core', () => {
name: 'foo.jpg',
preview: undefined,
data: fileData,
isGhost: false,
progress: {
bytesTotal: 17175,
bytesUploaded: 0,
percentage: 0,
uploadComplete: false,
uploadStarted: null,
},
remote: '',
remote: undefined,
size: 17175,
source: 'vi',
type: 'image/jpeg',
Expand Down
8 changes: 4 additions & 4 deletions packages/@uppy/core/src/Uppy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ interface CurrentUpload<M extends Meta, B extends Body> {
result: UploadResult<M, B>
}

// TODO: can we use namespaces in other plugins to populate this?
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface Plugins extends Record<string, Record<string, unknown> | undefined> {}

Expand Down Expand Up @@ -459,7 +460,7 @@ export class Uppy<M extends Meta, B extends Body> {
percentage: 0,
bytesUploaded: 0,
uploadComplete: false,
uploadStarted: 0,
uploadStarted: null,
}
const files = { ...this.getState().files }
const updatedFiles: State<M, B>['files'] = {}
Expand Down Expand Up @@ -638,7 +639,7 @@ export class Uppy<M extends Meta, B extends Body> {
}[],
): void {
for (const error of errors) {
if (error instanceof RestrictionError) {
if (error.isRestriction) {
this.emit('restriction-failed', error.file, error)
} else {
this.emit('error', error)
Expand Down Expand Up @@ -760,7 +761,6 @@ export class Uppy<M extends Meta, B extends Body> {
type: fileType,
data: file.data,
progress: {
progress: 0,
percentage: 0,
bytesUploaded: 0,
bytesTotal: size,
Expand Down Expand Up @@ -812,7 +812,7 @@ export class Uppy<M extends Meta, B extends Body> {
const isGhost = existingFiles[newFile.id]?.isGhost
if (isGhost) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { isGhost: _, ...existingFileState } = existingFiles[newFile.id]
const existingFileState = existingFiles[newFile.id]
newFile = {
...existingFileState,
isGhost: false,
Expand Down
69 changes: 69 additions & 0 deletions packages/@uppy/core/src/__snapshots__/Uppy.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`src/Core > plugins > should not be able to add a plugin that has no id 1`] = `"Your plugin must have an id"`;

exports[`src/Core > plugins > should not be able to add a plugin that has no type 1`] = `"Your plugin must have a type"`;

exports[`src/Core > plugins > should not be able to add an invalid plugin 1`] = `"Expected a plugin class, but got object. Please verify that the plugin was imported and spelled correctly."`;

exports[`src/Core > plugins > should prevent the same plugin from being added more than once 1`] = `
"Already found a plugin named 'TestSelector1'. Tried to use: 'TestSelector1'.
Uppy plugins must have unique \`id\` options. See https://uppy.io/docs/plugins/#id."
`;

exports[`src/Core > uploading a file > should only upload files that are not already assigned to another upload id 1`] = `
{
"failed": [],
"successful": [
{
"data": Uint8Array [],
"extension": "jpg",
"id": "uppy-foo/jpg-1e-image/jpeg",
"isGhost": false,
"isRemote": false,
"meta": {
"name": "foo.jpg",
"type": "image/jpeg",
},
"name": "foo.jpg",
"preview": undefined,
"progress": {
"bytesTotal": null,
"bytesUploaded": 0,
"percentage": 0,
"uploadComplete": false,
"uploadStarted": null,
},
"remote": undefined,
"size": null,
"source": "vi",
"type": "image/jpeg",
},
{
"data": Uint8Array [],
"extension": "jpg",
"id": "uppy-bar/jpg-1e-image/jpeg",
"isGhost": false,
"isRemote": false,
"meta": {
"name": "bar.jpg",
"type": "image/jpeg",
},
"name": "bar.jpg",
"preview": undefined,
"progress": {
"bytesTotal": null,
"bytesUploaded": 0,
"percentage": 0,
"uploadComplete": false,
"uploadStarted": null,
},
"remote": undefined,
"size": null,
"source": "vi",
"type": "image/jpeg",
},
],
"uploadID": "cjd09qwxb000dlql4tp4doz8h",
}
`;
2 changes: 1 addition & 1 deletion packages/@uppy/utils/src/FileProgress.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type FileProgress = {
progress: number
progress?: number
uploadComplete: boolean
percentage: number
bytesTotal: number | null
Expand Down

0 comments on commit 78b581a

Please sign in to comment.