mirror of
https://github.com/Kong/insomnia.git
synced 2026-04-20 22:27:24 -04:00
Mock browser environment in vitest
This commit is contained in:
13
package-lock.json
generated
13
package-lock.json
generated
@@ -24,6 +24,7 @@
|
||||
"@types/chai": "^4.3.14",
|
||||
"@types/eslint": "^8.56.7",
|
||||
"@types/har-format": "^1.2.15",
|
||||
"@types/jsdom": "^21.1.7",
|
||||
"@types/mocha": "^10.0.6",
|
||||
"@types/node": "^20.12.4",
|
||||
"@typescript-eslint/eslint-plugin": "^7.5.0",
|
||||
@@ -6353,6 +6354,18 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/jsdom": {
|
||||
"version": "21.1.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/jsdom/-/jsdom-21.1.7.tgz",
|
||||
"integrity": "sha512-yOriVnggzrnQ3a9OKOCxaVuSug3w3/SbOj5i7VwXWZEyUNl3bLF9V3MfxGbZKuwqJOQyRfqXyROBB1CoZLFWzA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/node": "*",
|
||||
"@types/tough-cookie": "*",
|
||||
"parse5": "^7.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/jshint": {
|
||||
"version": "2.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/jshint/-/jshint-2.12.4.tgz",
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
"@types/chai": "^4.3.14",
|
||||
"@types/eslint": "^8.56.7",
|
||||
"@types/har-format": "^1.2.15",
|
||||
"@types/jsdom": "^21.1.7",
|
||||
"@types/mocha": "^10.0.6",
|
||||
"@types/node": "^20.12.4",
|
||||
"@typescript-eslint/eslint-plugin": "^7.5.0",
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { JSDOM } from 'jsdom';
|
||||
import { vi } from 'vitest';
|
||||
|
||||
import { nodeLibcurlMock } from './src/__mocks__/@getinsomnia/node-libcurl';
|
||||
@@ -5,6 +6,7 @@ import { electronMock } from './src/__mocks__/electron';
|
||||
import { database as db } from './src/common/database';
|
||||
import * as models from './src/models';
|
||||
import { v4Mock } from './src/models/__mocks__/uuid';
|
||||
|
||||
await db.init(models.types(), { inMemoryOnly: true }, true, () => { },);
|
||||
vi.mock('electron', () => ({ default: electronMock }));
|
||||
|
||||
@@ -21,3 +23,23 @@ vi.mock('isomorphic-git', async importOriginal => {
|
||||
clone: vi.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
const {
|
||||
window,
|
||||
} = new JSDOM('<!DOCTYPE html><p>Hello world</p>', {
|
||||
url: 'https://example.org/',
|
||||
referrer: 'https://example.com/',
|
||||
contentType: 'text/html',
|
||||
includeNodeLocations: true,
|
||||
storageQuota: 10000000,
|
||||
});
|
||||
|
||||
vi.stubGlobal('window', window);
|
||||
[
|
||||
'document',
|
||||
'navigator',
|
||||
'FileReader',
|
||||
'Blob',
|
||||
].forEach((propName: string) => {
|
||||
vi.stubGlobal(propName, window[propName]);
|
||||
});
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
type WebSocketRequest,
|
||||
} from '../models/websocket-request';
|
||||
import { isWorkspace, type Workspace } from '../models/workspace';
|
||||
import type { CurrentPlan } from '../ui/routes/organization';
|
||||
import { type CurrentPlan } from '../ui/routes/organization';
|
||||
import { convert, type InsomniaImporter } from '../utils/importers/convert';
|
||||
import { id as postmanEnvImporterId } from '../utils/importers/importers/postman-env';
|
||||
import { invariant } from '../utils/invariant';
|
||||
|
||||
Reference in New Issue
Block a user