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

@uppy/xhr-upload: correctly type xhrUpload meta #5344

Merged
merged 4 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
11 changes: 9 additions & 2 deletions packages/@uppy/xhr-upload/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,22 @@
onBeforeRequest,
onAfterResponse,
})
core.addFile({
const id = core.addFile({
type: 'image/png',
source: 'test',
name: 'test.jpg',
data: new Blob([new Uint8Array(8192)]),
})

core.setFileState(id, {
xhrUpload: {
// Test that we don't have a TS error for setting endpoint
// on metadata
endpoint: 'http://localhost:3000',
},
})
return core.upload().then(() => {
expect(shouldRetry).toHaveBeenCalledTimes(1)

Check failure on line 49 in packages/@uppy/xhr-upload/src/index.test.ts

View workflow job for this annotation

GitHub Actions / Unit tests (18.x)

packages/@uppy/xhr-upload/src/index.test.ts > XHRUpload > should leverage hooks from fetcher

AssertionError: expected "spy" to be called 1 times, but got 4 times ❯ packages/@uppy/xhr-upload/src/index.test.ts:49:27

Check failure on line 49 in packages/@uppy/xhr-upload/src/index.test.ts

View workflow job for this annotation

GitHub Actions / Unit tests (20.x)

packages/@uppy/xhr-upload/src/index.test.ts > XHRUpload > should leverage hooks from fetcher

AssertionError: expected "spy" to be called 1 times, but got 4 times ❯ packages/@uppy/xhr-upload/src/index.test.ts:49:27
expect(onAfterResponse).toHaveBeenCalledTimes(2)
expect(onBeforeRequest).toHaveBeenCalledTimes(2)
})
Expand All @@ -60,7 +67,7 @@
id: 'XHRUpload',
endpoint: 'https://fake-endpoint.uppy.io',
headers: (file) => ({
'x-sample-header': file.name,
'x-sample-header': file.name!,
}),
})
core.addFile({
Expand All @@ -72,7 +79,7 @@

await core.upload()

expect(scope.isDone()).toBe(true)

Check failure on line 82 in packages/@uppy/xhr-upload/src/index.test.ts

View workflow job for this annotation

GitHub Actions / Unit tests (18.x)

packages/@uppy/xhr-upload/src/index.test.ts > XHRUpload > headers > can be a function

AssertionError: expected false to be true // Object.is equality - Expected + Received - true + false ❯ packages/@uppy/xhr-upload/src/index.test.ts:82:30

Check failure on line 82 in packages/@uppy/xhr-upload/src/index.test.ts

View workflow job for this annotation

GitHub Actions / Unit tests (20.x)

packages/@uppy/xhr-upload/src/index.test.ts > XHRUpload > headers > can be a function

AssertionError: expected false to be true // Object.is equality - Expected + Received - true + false ❯ packages/@uppy/xhr-upload/src/index.test.ts:82:30
})
})
})
30 changes: 14 additions & 16 deletions packages/@uppy/xhr-upload/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,6 @@ import getAllowedMetaFields from '@uppy/utils/lib/getAllowedMetaFields'
import packageJson from '../package.json'
import locale from './locale.ts'

declare module '@uppy/utils/lib/UppyFile' {
// eslint-disable-next-line no-shadow, @typescript-eslint/no-unused-vars
export interface UppyFile<M extends Meta, B extends Body> {
// TODO: figure out what else is in this type
xhrUpload?: { headers: Record<string, string> }
}
}

declare module '@uppy/core' {
// eslint-disable-next-line no-shadow, @typescript-eslint/no-unused-vars
export interface State<M extends Meta, B extends Body> {
// TODO: figure out what else is in this type
xhrUpload?: { headers: Record<string, string> }
}
}

export interface XhrUploadOpts<M extends Meta, B extends Body>
extends PluginOpts {
endpoint: string
Expand Down Expand Up @@ -75,6 +59,20 @@ export interface XhrUploadOpts<M extends Meta, B extends Body>
bundle?: boolean
}

declare module '@uppy/utils/lib/UppyFile' {
// eslint-disable-next-line no-shadow
export interface UppyFile<M extends Meta, B extends Body> {
xhrUpload?: XhrUploadOpts<M, B>
}
}

declare module '@uppy/core' {
// eslint-disable-next-line no-shadow
export interface State<M extends Meta, B extends Body> {
xhrUpload?: XhrUploadOpts<M, B>
}
}

function buildResponseError(
xhr: XMLHttpRequest,
err?: string | Error | NetworkError,
Expand Down
Loading