Skip to content

fix(internal): clean up undefined File test #51

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

Merged
merged 1 commit into from
Mar 4, 2025
Merged
Changes from all 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
18 changes: 12 additions & 6 deletions tests/uploads.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ function mockResponse({ url, content }: { url: string; content?: Blob }): Respon
};
}

beforeEach(() => {
// The file shim captures the global File object when it's first imported.
// Reset modules before each test so we can test the error thrown when it's undefined.
jest.resetModules();
});

describe('toFile', () => {
it('throws a helpful error for mismatched types', async () => {
await expect(
Expand Down Expand Up @@ -80,11 +74,23 @@ describe('toFile', () => {
});

describe('missing File error message', () => {
let prevFile: unknown;
beforeEach(() => {
// The file shim captures the global File object when it's first imported.
// Reset modules before each test so we can test the error thrown when it's undefined.
jest.resetModules();
// @ts-ignore
prevFile = globalThis.File;
// @ts-ignore
globalThis.File = undefined;
require('node:buffer').File = undefined;
});
afterEach(() => {
// Clean up
// @ts-ignore
globalThis.File = prevFile;
jest.resetModules();
});

test('is thrown', async () => {
const uploads = await import('@gitpod/sdk/uploads');
Expand Down