Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

NONE) migration: migration jest to vitest #16

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ module.exports = {
browser: true,
node: true,
jasmine: true,
jest: true,
es6: true,
},
ignorePatterns: [".eslintrc.js", "dist", "webpack.config.js"],
ignorePatterns: [
".eslintrc.js",
"dist",
"webpack.config.js",
"vitest.config.ts",
],
rules: {
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/explicit-function-return-type": "off",
Expand Down
44 changes: 6 additions & 38 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,26 @@
"@babel/core": "^7.23.3",
"@babel/preset-env": "^7.23.3",
"@babel/preset-typescript": "^7.23.3",
"@types/jest": "^29.5.7",
"@types/node": "^20.8.10",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
"babel-jest": "^29.7.0",
"babel-loader": "^9.1.3",
"eslint": "^8.52.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-prettier": "^5.0.1",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jsdom": "^23.0.1",
"node-polyfill-webpack-plugin": "^2.0.1",
"prettier": "^3.0.3",
"terser-webpack-plugin": "^5.3.9",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"tsc-watch": "^6.0.4",
"tsconfig-paths": "^4.2.0",
"tsconfig-paths-webpack-plugin": "^4.1.0",
"tscpaths": "^0.0.9",
"typescript": "^5.2.2",
"vite-tsconfig-paths": "^4.2.1",
"vitest": "^0.33.0",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4"
},
Expand All @@ -47,44 +45,14 @@
"format": "prettier --write \"src/**/*.ts\"",
"lint": "eslint \"{src,test,__tests__}/**/*.ts\" --fix",
"lint:ci": "eslint \"{src,test,__tests__}/**/*.ts\"",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage"
"test": "vitest run",
"test:watch": "vitest watch",
"test:cov": "vitest run --coverage"
},
"keywords": [],
"publishConfig": {
"access": "public"
},
"jest": {
"moduleDirectories": [
"node_modules",
"src"
],
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"roots": [
"src"
],
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "jsdom",
"setupFiles": [
"./src/__tests__/setup.ts"
],
"moduleNameMapper": {
"gaxios": "gaxios",
"src/(.*)": "<rootDir>/src/$1"
}
},
"dependencies": {
"axios": "^1.6.1"
}
Expand Down
17 changes: 9 additions & 8 deletions src/__tests__/adcio.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { AdcioCore } from "lib/core";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { Adcio } from "../adcio";

beforeEach(() => {
jest.useFakeTimers();
vi.useFakeTimers();
});

afterEach(() => {
jest.restoreAllMocks();
jest.resetModules();
vi.restoreAllMocks();
vi.resetModules();
});

describe("test Adcio module", () => {
Expand All @@ -34,7 +35,7 @@ describe("test AdcioCore module", () => {

const initialSessionId = adcioCore.getSessionId();

jest.advanceTimersByTime(10000);
vi.advanceTimersByTime(10000);

// Verify that the session ID remains the same after 10s
expect(adcioCore.getSessionId()).toBe(initialSessionId);
Expand All @@ -47,17 +48,17 @@ describe("test AdcioCore module", () => {

const initialSessionId = adcioCore.getSessionId();

jest.advanceTimersByTime(30 * 60 * 1000);
vi.advanceTimersByTime(30 * 60 * 1000);

// AdcioCore should reset the session ID after 30m
// Verify that the session ID has changed after 30m
expect(adcioCore.getSessionId()).not.toBe(initialSessionId);
});

it("should call AdcioCore constructor once when Adcio is created", async () => {
jest.doMock("../lib/core", () => {
vi.doMock("../lib/core", () => {
return {
AdcioCore: jest.fn().mockImplementation(),
AdcioCore: vi.fn().mockImplementation((adcioCore) => adcioCore),
};
});

Expand All @@ -71,6 +72,6 @@ describe("test AdcioCore module", () => {

expect(AdcioCore).toHaveBeenCalledTimes(1);

jest.dontMock("../lib/core");
vi.doUnmock("../lib/core");
});
});
10 changes: 10 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from "vitest/config";
import tsconfigPaths from "vite-tsconfig-paths";

export default defineConfig({
test: {
globals: true,
environment: "jsdom",
},
plugins: [tsconfigPaths()],
});
Loading