Skip to content

Commit

Permalink
Vitest-2 app package (#7757)
Browse files Browse the repository at this point in the history
* vitest insomnia-inso

* remove skipped logs

* vitest insomnia config

* remove jest

* mocks?

* remove globalBeforeEach smell

* 110 left

* 38 failing

* 34

* 30

* 26

* 3 to go

* fix tests

* fix type checks

* delete send-request

* fix lint

* test runner hack for now

* remove duplicate snapshots

---------

Co-authored-by: gatzjames <[email protected]>
  • Loading branch information
jackkav and gatzjames authored Jul 26, 2024
1 parent e3ad3c5 commit e2b466a
Show file tree
Hide file tree
Showing 117 changed files with 563 additions and 3,691 deletions.
2 changes: 0 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ module.exports = {
plugins: [
'@typescript-eslint',
'react',
'jest',
'html',
'json',
'filenames',
Expand All @@ -52,7 +51,6 @@ module.exports = {
browser: true,
commonjs: true,
es6: true,
'jest/globals': true,
node: true,
},
overrides: [
Expand Down
2 changes: 1 addition & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Insomnia stores data in a few places:
## Automated testing

We use [Jest](https://jestjs.io/) and [react-testing-library](https://testing-library.com/docs/react-testing-library) to write our unit tests, and [Playwright](https://github.com/microsoft/playwright) for integration tests.
We use [Vitest](https://vitest.dev/) and [Playwright](https://github.com/microsoft/playwright)

Unit tests exist alongside the file under test. For example:

Expand Down
2,685 changes: 191 additions & 2,494 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
"download-all-npm-plugins": "esr ./scripts/download-all-npm-plugins.ts"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@jest/types": "^29.6.3",
"@types/chai": "^4.3.14",
"@types/eslint": "^8.56.7",
"@types/har-format": "^1.2.15",
Expand All @@ -58,13 +56,10 @@
"eslint-plugin-filenames": "^1.3.2",
"eslint-plugin-html": "^8.0.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-json": "^3.1.0",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-simple-import-sort": "^12.0.0",
"jest": "^29.7.0",
"ts-jest": "^29.1.2",
"tslib": "2.0.1",
"type-fest": "^4.15.0",
"typescript": "^5.4.4",
Expand Down
3 changes: 1 addition & 2 deletions packages/insomnia-inso/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"scripts": {
"lint": "eslint . --ext .js,.ts,.tsx --cache",
"test": "esr esbuild.ts && vitest --exclude '**/cli.test.ts'",
"test": "esr esbuild.ts && vitest run --exclude '**/cli.test.ts'",
"test:watch": "npm run test -- --watch",
"test:bundle": "vitest cli.test.ts -t \"inso dev bundle\"",
"test:binary": "vitest cli.test.ts -t \"inso packaged binary\"",
Expand Down Expand Up @@ -53,7 +53,6 @@
"consola": "^2.15.0",
"cosmiconfig": "^9.0.0",
"enquirer": "^2.4.1",
"insomnia-send-request": "../insomnia-send-request",
"string-argv": "^0.3.2",
"yaml": "^1.6.0"
}
Expand Down
4 changes: 3 additions & 1 deletion packages/insomnia-inso/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"sourceMap": true,
/* Runs in the DOM NOTE: this is inconsistent with reality */
"lib": [
"ES2020"
"ES2020",
"DOM",
"DOM.Iterable"
],
/* Strictness */
"strict": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/insomnia-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"main": "src/objects/index.ts",
"types": "src/objects/index.ts",
"scripts": {
"test": "vitest"
"test": "vitest run"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/insomnia-testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"types": "src/index.ts",
"scripts": {
"lint": "eslint . --ext .js,.ts,.tsx --cache",
"test": "vitest",
"test": "vitest run",
"type-check": "tsc --noEmit --project tsconfig.json"
},
"homepage": "https://github.com/Kong/insomnia#readme",
Expand Down
38 changes: 0 additions & 38 deletions packages/insomnia/jest.config.js

This file was deleted.

8 changes: 1 addition & 7 deletions packages/insomnia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
"start": "concurrently -n browser,main --kill-others \"npm run start:dev-server\" \"npm run start:electron\"",
"start:dev-server": "vite dev",
"start:electron": "cross-env NODE_ENV=development esr esbuild.main.ts && electron --inspect=5858 .",
"test": "jest",
"test": "vitest run",
"electron:dev-build": "electron ./build/main.min.js",
"test:watch": "jest --watch",
"type-check": "tsc --noEmit --project tsconfig.json",
"type-check:watch": "npm run type-check -- --watch",
"convert-svg": "npm_config_yes=true npx @svgr/[email protected] --no-index --config-file svgr.config.js --out-dir src/ui/components/assets/svgr src/ui/components/assets/"
Expand All @@ -41,7 +40,6 @@
"@getinsomnia/node-libcurl": "^2.4.30",
"@grpc/grpc-js": "^1.10.10",
"@grpc/proto-loader": "^0.7.13",
"@jest/globals": "^29.7.0",
"@seald-io/nedb": "^4.0.4",
"@segment/analytics-node": "2.1.0",
"apiconnect-wsdl": "1.8.31",
Expand Down Expand Up @@ -96,7 +94,6 @@
"@tailwindcss/typography": "^0.5.12",
"@tanstack/react-virtual": "3.2.0",
"@testing-library/dom": "^9.3.4",
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^14.2.2",
"@testing-library/user-event": "^14.5.2",
"@types/aws4": "^1.11.6",
Expand Down Expand Up @@ -155,9 +152,6 @@
"highlight.js": "^11.9.0",
"httplease-asap": "^0.6.0",
"isomorphic-git": "1.25.7",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-mock": "^29.7.0",
"json-diff-kit": "^1.0.23",
"json-order": "^1.1.3",
"less": "^4.2.0",
Expand Down
23 changes: 23 additions & 0 deletions packages/insomnia/setup-vitest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { vi } from 'vitest';

import { nodeLibcurlMock } from './src/__mocks__/@getinsomnia/node-libcurl';
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 }));

vi.mock('uuid', () => ({
v4: () => v4Mock(),
}));
vi.mock('@getinsomnia/node-libcurl', () => nodeLibcurlMock);

vi.mock('isomorphic-git', async importOriginal => {
const actual = await importOriginal();
return {
...Object.assign({}, actual),
push: vi.fn(),
clone: vi.fn(),
};
});
14 changes: 0 additions & 14 deletions packages/insomnia/src/__jest__/before-each.ts

This file was deleted.

23 changes: 0 additions & 23 deletions packages/insomnia/src/__jest__/mock-code-editor.tsx

This file was deleted.

12 changes: 0 additions & 12 deletions packages/insomnia/src/__jest__/mock-component.tsx

This file was deleted.

1 change: 0 additions & 1 deletion packages/insomnia/src/__jest__/setup-after-env.ts

This file was deleted.

27 changes: 0 additions & 27 deletions packages/insomnia/src/__jest__/setup.ts

This file was deleted.

21 changes: 10 additions & 11 deletions packages/insomnia/src/__mocks__/@getinsomnia/node-libcurl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { EventEmitter } from 'events';
import fs from 'fs';

class Curl extends EventEmitter {
_options = {};
_meta = {};
_features = {};
_options: { [key: string]: any } = {};
_meta: { [key: string]: any } = {};
_features: { [key: string]: any } = {};

static info = {
COOKIELIST: 'COOKIELIST',
Expand Down Expand Up @@ -71,11 +71,11 @@ class Curl extends EventEmitter {
return 'libcurl/7.54.0 LibreSSL/2.0.20 zlib/1.2.11 nghttp2/1.24.0';
}

enable(name) {
enable(name: string | number) {
this._features[name] = true;
}

setOpt(name, value) {
setOpt(name: string, value: number | ((arg0: Buffer) => any)) {
if (!name) {
throw new Error(`Invalid option ${name} ${value}`);
}
Expand All @@ -85,7 +85,7 @@ class Curl extends EventEmitter {
return;
}

if (name === Curl.option.READFUNCTION) {
if (name === Curl.option.READFUNCTION && typeof value === 'function') {
let body = '';

// Only limiting this to prevent infinite loops
Expand All @@ -108,7 +108,7 @@ class Curl extends EventEmitter {
this._options[name] = this._options[name] || [];

this._options[name].push(value);
} else if (name === Curl.option.READDATA) {
} else if (name === Curl.option.READDATA && typeof value === 'number') {
const { size } = fs.fstatSync(value);
const buffer = Buffer.alloc(size);
fs.readSync(value, buffer, 0, size, 0);
Expand All @@ -118,7 +118,7 @@ class Curl extends EventEmitter {
}
}

getInfo(name) {
getInfo(name: string) {
switch (name) {
case Curl.info.COOKIELIST:
return [`#HttpOnly_.insomnia.rest\tTRUE\t/url/path\tTRUE\t${Date.now() / 1000}\tfoo\tbar`];
Expand Down Expand Up @@ -148,7 +148,6 @@ class Curl extends EventEmitter {
);
this.emit('data', data);

// @ts-expect-error -- TSCONVERSION
this._options.WRITEFUNCTION(data);

process.nextTick(() => {
Expand Down Expand Up @@ -181,7 +180,7 @@ class Curl extends EventEmitter {
* ```
* We only want the named members (non-number ones)
*/
const getTsEnumOnlyWithNamedMembers = enumObj => {
const getTsEnumOnlyWithNamedMembers = (enumObj: any) => {
let obj = {};

for (const member in enumObj) {
Expand All @@ -194,7 +193,7 @@ const getTsEnumOnlyWithNamedMembers = enumObj => {
};

// WARNING: changing this to `export default` will break the mock and be incredibly hard to debug. Ask me how I know.
module.exports = {
export const nodeLibcurlMock = {
Curl,
CurlAuth: getTsEnumOnlyWithNamedMembers(CurlAuth),
CurlCode: getTsEnumOnlyWithNamedMembers(CurlCode),
Expand Down
24 changes: 12 additions & 12 deletions packages/insomnia/src/__mocks__/@grpc/grpc-js.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import grpcJSOriginal from '@grpc/grpc-js';
import { jest } from '@jest/globals';
import { EventEmitter } from 'events';
import { vi } from 'vitest';

const grpcJs = jest.requireActual('@grpc/grpc-js') as typeof grpcJSOriginal;
const grpcJs = vi.requireActual('@grpc/grpc-js') as typeof grpcJSOriginal;

const mockCallWrite = jest.fn();
const mockCallEnd = jest.fn();
const mockCallCancel = jest.fn();
const mockCallWrite = vi.fn();
const mockCallEnd = vi.fn();
const mockCallCancel = vi.fn();

export const status = grpcJs.status;

Expand All @@ -32,13 +32,13 @@ const makeMockCall = () => {

const getMockCall = () => mockCall;

const mockConstructor = jest.fn();
const mockMakeUnaryRequest = jest.fn();
const mockMakeClientStreamRequest = jest.fn();
const mockMakeServerStreamRequest = jest.fn();
const mockMakeBidiStreamRequest = jest.fn();
const mockCreateInsecure = jest.fn();
const mockCreateSsl = jest.fn();
const mockConstructor = vi.fn();
const mockMakeUnaryRequest = vi.fn();
const mockMakeClientStreamRequest = vi.fn();
const mockMakeServerStreamRequest = vi.fn();
const mockMakeBidiStreamRequest = vi.fn();
const mockCreateInsecure = vi.fn();
const mockCreateSsl = vi.fn();

export const grpcMocks = {
getMockCall,
Expand Down
Loading

0 comments on commit e2b466a

Please sign in to comment.