Skip to content

Commit

Permalink
Merge pull request #200 from AElfProject/chore/switch-packages-to-use…
Browse files Browse the repository at this point in the history
…-vitest

Chore/switch packages to use vitest
  • Loading branch information
aelf-lxy authored Nov 27, 2024
2 parents 4756be0 + 50635cb commit 4c621c1
Show file tree
Hide file tree
Showing 50 changed files with 850 additions and 2,347 deletions.
11 changes: 1 addition & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,17 @@
"@biomejs/biome": "^1.9.2",
"@changesets/changelog-git": "^0.2.0",
"@changesets/cli": "^2.27.1",
"@happy-dom/jest-environment": "^15.11.6",
"@ianvs/prettier-plugin-sort-imports": "^4.1.1",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.0.1",
"@testing-library/react-hooks": "^8.0.1",
"@types/jest": "^29.5.12",
"@types/node": "^22.9.3",
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.0",
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
"@vitest/coverage-v8": "^2.1.5",
"babel-jest": "^29.7.0",
"@vitest/ui": "^2.1.5",
"babel-plugin-transform-remove-console": "^6.9.4",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
Expand All @@ -82,17 +80,10 @@
"father": "^4.3.8",
"happy-dom": "^15.11.6",
"husky": "^8.0.3",
"jest": "^29.7.0",
"jest-canvas-mock": "^2.5.2",
"jest-environment-jsdom": "^29.7.0",
"jest-junit": "^16.0.0",
"jest-transform-stub": "^2.0.0",
"jsdom": "^23.0.1",
"lint-staged": "^15.2.0",
"node-fetch": "^3.3.2",
"prettier": "^3.1.1",
"rimraf": "^5.0.5",
"ts-jest": "^29.2.5",
"typescript": "^5.3.3",
"vite-tsconfig-paths": "^5.1.3",
"vitest": "^2.1.5"
Expand Down
187 changes: 0 additions & 187 deletions packages/base/jest.config.ts

This file was deleted.

6 changes: 4 additions & 2 deletions packages/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
"scripts": {
"dev": "father dev",
"build": "father build",
"test": "jest --config=jest.config.ts --detectOpenHandles",
"test:coverage": "jest --config=jest.config.ts --coverage --detectOpenHandles"
"test": "vitest",
"test:dev": "pnpm test -- --watch",
"test:coverage": "pnpm test -- --coverage",
"test:ui": "pnpm test:dev --ui"
},
"dependencies": {
"eventemitter3": "^5.0.1"
Expand Down
18 changes: 8 additions & 10 deletions packages/base/src/__tests__/enhancedLocalStorageInWindow.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
const originalConsoleLog = console.log;
beforeEach(() => {
vi.spyOn(console, 'log');
(global as any).window = {};
});
afterEach(() => {
vi.unmock('console.log');
delete (global as any).window;
});

describe('localStorageMock in window', () => {
beforeEach(() => {
console.log = jest.fn();
(global as any).window = {};
});
afterEach(() => {
console.log = originalConsoleLog;
delete (global as any).window;
});

it('enhancedLocalStorage should be set to localStorage in browser environment', async () => {
await import('../enhancedLocalStorage');
expect(console.log).toHaveBeenCalledWith('enhancedLocalStorage in window');
Expand Down
4 changes: 4 additions & 0 deletions packages/base/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import baseViteConfig from '../tools/vite.config';
import { mergeConfig } from 'vitest/config';

export default mergeConfig(baseViteConfig, {});
2 changes: 2 additions & 0 deletions packages/base/vitest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import '../tools/__mocks__/setupGlobal';
import '../tools/__mocks__/setupLocal';
4 changes: 2 additions & 2 deletions packages/bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@
"test": "vitest",
"test:dev": "pnpm test -- --watch",
"test:coverage": "pnpm test -- --coverage",
"test:debug": "pnpm test -- --detectOpenHandles"
"test:ui": "pnpm test:dev --ui"
},
"dependencies": {
"@aelf-web-login/wallet-adapter-base": "workspace:*",
"@aelf-web-login/tools": "workspace:*",
"@portkey/contracts": "^2.15.9",
"@portkey/services": "^2.15.9",
"@reduxjs/toolkit": "^2.2.3",
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"devDependencies": {
"babel-jest": "^29.7.0",
"@portkey/did-ui-react": "^2.15.9",
"@portkey/types": "^2.15.9",
"@portkey/utils": "^2.15.9",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,29 @@ import { type Mock } from 'vitest';
afterEach(() => {
vi.unmock('@portkey/contracts');
});

vi.mock('@portkey/contracts', () => ({
getContractBasic: vi.fn(),
}));

vi.mock('@portkey/did-ui-react', () => ({
getChainInfo: (c: TChainId) => (!c ? null : {}),
did: {
didWallet: {
managementAccount: {
privateKey: '',
},
},
},
PortkeyProvider: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}));

vi.mock('@portkey/utils', () => ({
aelf: {
getWallet: vi.fn(),
},
}));

describe('getCaContractBase()', () => {
it('should throw error about chain is not running', async () => {
const chainId = null;
Expand Down
47 changes: 3 additions & 44 deletions packages/bridge/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,4 @@
import { defineConfig, configDefaults } from 'vitest/config';
import tsconfigPaths from 'vite-tsconfig-paths';
import baseViteConfig from '../tools/vite.config';
import { mergeConfig } from 'vitest/config';

const exclude = [...configDefaults.exclude, '**/dist/*.*', '**/.*', '**/*.setup.*'];

export default defineConfig({
plugins: [tsconfigPaths()],
test: {
maxConcurrency: 20,
pool: 'vmThreads',
poolOptions: {
threads: {
singleThread: true,
},
},
isolate: false, // only safe with the poolOptions above
css: false,
deps: {
optimizer: {
web: {
enabled: true,
},
},
},
globals: true,
watch: false,
environment: 'happy-dom',
setupFiles: ['./vitest.setup'],
include: ['./src/**/*(*.)?{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
name: 'bridge',
exclude,
reporters: ['junit', 'default'],
outputFile: {
junit: './jest-report.xml',
},
coverage: {
all: false,
enabled: true,
provider: 'v8',
exclude: [...exclude, '**/__tests__/*.*'],
reportsDirectory: './coverage',
reporter: [['json', { file: 'coverage-summary.json' }], ['text']],
},
},
});
export default mergeConfig(baseViteConfig, {});
Loading

0 comments on commit 4c621c1

Please sign in to comment.