diff --git a/packages/app-insights/jest.config.js b/packages/app-insights/jest.config.js deleted file mode 100644 index 5656d3347..000000000 --- a/packages/app-insights/jest.config.js +++ /dev/null @@ -1,13 +0,0 @@ -/** @type {import('jest').Config} */ -const config = { - transform: {}, - coveragePathIgnorePatterns: ['/node_modules/', '/src/__mocks__/'], - coverageReporters: ['text-summary', 'lcov'], - coverageProvider: 'v8', - roots: ['./lib'], - moduleNameMapper: { - '^(chalk|inquirer)$': '/../shared/lib/esm/module-proxy.js', - }, -}; - -export default config; diff --git a/packages/app-insights/package.json b/packages/app-insights/package.json index 948f80f26..4dedd4ea6 100644 --- a/packages/app-insights/package.json +++ b/packages/app-insights/package.json @@ -24,12 +24,11 @@ "scripts": { "precommit": "lint-staged", "build": "rm -rf lib/ && tsc -p tsconfig.build.json", - "build:test": "rm -rf lib/ && tsc -p tsconfig.test.json --sourcemap", "dev": "tsc -p tsconfig.build.json --watch --preserveWatchOutput --incremental", "lint": "eslint --ext .ts src", "lint:report": "pnpm lint --format json --output-file report.json", - "test:only": "NODE_OPTIONS=--experimental-vm-modules jest", - "test": "pnpm build:test && pnpm test:only", + "test": "vitest src", + "test:ci": "pnpm run test --silent --coverage", "prepack": "pnpm build" }, "devDependencies": { @@ -37,17 +36,15 @@ "@silverhand/eslint-config-react": "5.0.0", "@silverhand/ts-config": "5.0.0", "@silverhand/ts-config-react": "5.0.0", - "@types/jest": "^29.4.0", "@types/node": "^20.9.5", "@types/react": "^18.0.31", "eslint": "^8.44.0", "history": "^5.3.0", - "jest": "^29.7.0", "lint-staged": "^15.0.0", "prettier": "^3.0.0", "react": "^18.0.0", - "tslib": "^2.4.1", - "typescript": "^5.3.3" + "typescript": "^5.3.3", + "vitest": "^1.4.0" }, "engines": { "node": "^20.9.0" diff --git a/packages/app-insights/src/normalize-error.test.ts b/packages/app-insights/src/normalize-error.test.ts index 798d7cac6..ab60124a0 100644 --- a/packages/app-insights/src/normalize-error.test.ts +++ b/packages/app-insights/src/normalize-error.test.ts @@ -1,3 +1,5 @@ +import { describe, expect, it } from 'vitest'; + import { normalizeError } from './normalize-error.js'; describe('normalizeError()', () => { diff --git a/packages/app-insights/tsconfig.json b/packages/app-insights/tsconfig.json index 83eac9c0a..2e988e53b 100644 --- a/packages/app-insights/tsconfig.json +++ b/packages/app-insights/tsconfig.json @@ -2,7 +2,7 @@ "extends": "@silverhand/ts-config-react/tsconfig.base", "compilerOptions": { "outDir": "lib", - "types": ["node", "jest"], + "types": ["node"], }, "include": [ "src" diff --git a/packages/app-insights/tsconfig.test.json b/packages/app-insights/tsconfig.test.json deleted file mode 100644 index f30817b04..000000000 --- a/packages/app-insights/tsconfig.test.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "./tsconfig.build", - "compilerOptions": { - "isolatedModules": false, - "allowJs": true, - }, - "include": ["src"] -} diff --git a/packages/cli/jest.config.js b/packages/cli/jest.config.js deleted file mode 100644 index 5656d3347..000000000 --- a/packages/cli/jest.config.js +++ /dev/null @@ -1,13 +0,0 @@ -/** @type {import('jest').Config} */ -const config = { - transform: {}, - coveragePathIgnorePatterns: ['/node_modules/', '/src/__mocks__/'], - coverageReporters: ['text-summary', 'lcov'], - coverageProvider: 'v8', - roots: ['./lib'], - moduleNameMapper: { - '^(chalk|inquirer)$': '/../shared/lib/esm/module-proxy.js', - }, -}; - -export default config; diff --git a/packages/cli/package.json b/packages/cli/package.json index d8824de61..75b1cd649 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -25,15 +25,13 @@ "precommit": "lint-staged", "prepare:package-json": "node -p \"'export const packageJson = ' + JSON.stringify(require('./package.json'), undefined, 2) + ';'\" > src/package-json.ts", "build": "rm -rf lib && pnpm prepare:package-json && tsc -p tsconfig.build.json", - "build:test": "rm -rf lib/ && pnpm prepare:package-json && tsc -p tsconfig.test.json --sourcemap", "dev": "tsc -p tsconfig.build.json --watch --preserveWatchOutput --incremental", "start": "node .", "start:dev": "pnpm build && node .", "lint": "eslint --ext .ts src", "lint:report": "pnpm lint --format json --output-file report.json", - "test:only": "NODE_OPTIONS=--experimental-vm-modules jest", - "test": "pnpm build:test && pnpm test:only", - "test:ci": "pnpm test:only", + "test": "vitest src", + "test:ci": "pnpm run test --silent --coverage", "prepack": "pnpm build" }, "engines": { @@ -51,6 +49,7 @@ "@logto/schemas": "workspace:1.14.0", "@logto/shared": "workspace:^3.1.0", "@silverhand/essentials": "^2.9.0", + "@silverhand/slonik": "31.0.0-beta.2", "chalk": "^5.0.0", "decamelize": "^6.0.0", "dotenv": "^16.0.0", @@ -65,7 +64,6 @@ "pg-protocol": "^1.6.0", "roarr": "^7.11.0", "semver": "^7.3.8", - "@silverhand/slonik": "31.0.0-beta.2", "tar": "^6.1.11", "typescript": "^5.3.3", "yargs": "^17.6.0", @@ -74,19 +72,18 @@ "devDependencies": { "@silverhand/eslint-config": "5.0.0", "@silverhand/ts-config": "5.0.0", - "@withtyped/server": "^0.13.3", "@types/inquirer": "^9.0.0", - "@types/jest": "^29.4.0", "@types/node": "^20.9.5", "@types/semver": "^7.3.12", "@types/sinon": "^17.0.0", "@types/tar": "^6.1.2", "@types/yargs": "^17.0.13", + "@withtyped/server": "^0.13.3", "eslint": "^8.44.0", - "jest": "^29.7.0", "lint-staged": "^15.0.0", "prettier": "^3.0.0", - "sinon": "^17.0.0" + "sinon": "^17.0.0", + "vitest": "^1.4.0" }, "eslintConfig": { "extends": "@silverhand", diff --git a/packages/cli/src/commands/database/alteration/index.test.ts b/packages/cli/src/commands/database/alteration/index.test.ts index b05f21732..47dbcf02a 100644 --- a/packages/cli/src/commands/database/alteration/index.test.ts +++ b/packages/cli/src/commands/database/alteration/index.test.ts @@ -1,14 +1,11 @@ -import { createMockUtils } from '@logto/shared/esm'; import { createMockPool } from '@silverhand/slonik'; import Sinon from 'sinon'; +import { vi, expect, afterAll, describe, it } from 'vitest'; import { chooseAlterationsByVersion } from './version.js'; -const { jest } = import.meta; -const { mockEsmWithActual } = createMockUtils(jest); - const pool = createMockPool({ - query: jest.fn(), + query: vi.fn(), }); const files = Object.freeze([ @@ -17,16 +14,19 @@ const files = Object.freeze([ { filename: '1.0.0-1663923772-c.js', path: '/alterations-js/1.0.0-1663923772-c.js' }, ]); -await mockEsmWithActual('./utils.js', () => ({ +vi.mock('./utils.js', async (importOriginal) => ({ + // eslint-disable-next-line @typescript-eslint/ban-types + ...(await importOriginal()), getAlterationFiles: async () => files, })); -const { getCurrentDatabaseAlterationTimestamp } = await mockEsmWithActual( - '../../../queries/system.js', - () => ({ - getCurrentDatabaseAlterationTimestamp: jest.fn(), - }) -); +const getCurrentDatabaseAlterationTimestamp = vi.fn(); + +vi.doMock('../../../queries/system.js', async (importOriginal) => ({ + // eslint-disable-next-line @typescript-eslint/ban-types + ...(await importOriginal()), + getCurrentDatabaseAlterationTimestamp, +})); const { getAvailableAlterations } = await import('./index.js'); diff --git a/packages/cli/src/include.d/import-meta.d.ts b/packages/cli/src/include.d/import-meta.d.ts deleted file mode 100644 index 7a1591f98..000000000 --- a/packages/cli/src/include.d/import-meta.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -interface ImportMeta { - // By TypeScript design we must use `import()` - // eslint-disable-next-line @typescript-eslint/consistent-type-imports - jest: typeof jest & import('@logto/shared/esm').WithEsmMock; -} diff --git a/packages/cli/src/queries/system.test.ts b/packages/cli/src/queries/system.test.ts index 26d68a488..15058d322 100644 --- a/packages/cli/src/queries/system.test.ts +++ b/packages/cli/src/queries/system.test.ts @@ -1,6 +1,7 @@ import { AlterationStateKey, Systems } from '@logto/schemas'; import { createMockPool, createMockQueryResult, sql } from '@silverhand/slonik'; import { DatabaseError } from 'pg-protocol'; +import { describe, it, expect, vi, type MockedFunction, afterAll, beforeAll } from 'vitest'; import { convertToIdentifiers } from '../sql.js'; import type { QueryType } from '../test-utils.js'; @@ -8,9 +9,7 @@ import { expectSqlAssert } from '../test-utils.js'; import { updateDatabaseTimestamp, getCurrentDatabaseAlterationTimestamp } from './system.js'; -const { jest } = import.meta; - -const mockQuery: jest.MockedFunction = jest.fn(); +const mockQuery: MockedFunction = vi.fn(); const pool = createMockPool({ query: async (sql, values) => { @@ -94,12 +93,12 @@ describe('updateDatabaseTimestamp()', () => { const updatedAt = '2022-09-21T06:32:46.583Z'; beforeAll(() => { - jest.useFakeTimers(); - jest.setSystemTime(new Date(updatedAt)); + vi.useFakeTimers(); + vi.setSystemTime(new Date(updatedAt)); }); afterAll(() => { - jest.useRealTimers(); + vi.useRealTimers(); }); it('sends upsert sql with timestamp and updatedAt', async () => { diff --git a/packages/cli/src/test-utils.ts b/packages/cli/src/test-utils.ts index 574a0c597..67dfee35f 100644 --- a/packages/cli/src/test-utils.ts +++ b/packages/cli/src/test-utils.ts @@ -2,6 +2,7 @@ import type { QueryResult, QueryResultRow } from '@silverhand/slonik'; import type { PrimitiveValueExpression } from '@silverhand/slonik/dist/src/types.js'; +import { expect } from 'vitest'; export type QueryType = ( sql: string, diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json index 561ecb995..c4b6045bf 100644 --- a/packages/cli/tsconfig.json +++ b/packages/cli/tsconfig.json @@ -2,7 +2,7 @@ "extends": "@silverhand/ts-config/tsconfig.base", "compilerOptions": { "outDir": "lib", - "types": ["node", "jest"] + "types": ["node"] }, "include": [ "src" diff --git a/packages/cli/tsconfig.test.json b/packages/cli/tsconfig.test.json deleted file mode 100644 index 55de18c33..000000000 --- a/packages/cli/tsconfig.test.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "./tsconfig", - "compilerOptions": { - "isolatedModules": false, - "allowJs": true - }, - "include": ["src"] -} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3a499d24a..d1ec8d143 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -54,6 +54,9 @@ importers: applicationinsights: specifier: ^2.7.0 version: 2.7.0 + tslib: + specifier: ^2.4.1 + version: 2.4.1 devDependencies: '@silverhand/eslint-config': specifier: 5.0.0 @@ -67,9 +70,6 @@ importers: '@silverhand/ts-config-react': specifier: 5.0.0 version: 5.0.0(typescript@5.3.3) - '@types/jest': - specifier: ^29.4.0 - version: 29.4.0 '@types/node': specifier: ^20.9.5 version: 20.10.4 @@ -82,9 +82,6 @@ importers: history: specifier: ^5.3.0 version: 5.3.0 - jest: - specifier: ^29.7.0 - version: 29.7.0(@types/node@20.10.4) lint-staged: specifier: ^15.0.0 version: 15.0.2 @@ -94,12 +91,12 @@ importers: react: specifier: ^18.0.0 version: 18.2.0 - tslib: - specifier: ^2.4.1 - version: 2.4.1 typescript: specifier: ^5.3.3 version: 5.3.3 + vitest: + specifier: ^1.4.0 + version: 1.4.0(@types/node@20.10.4) packages/cli: dependencies: @@ -194,9 +191,6 @@ importers: '@types/inquirer': specifier: ^9.0.0 version: 9.0.3 - '@types/jest': - specifier: ^29.4.0 - version: 29.4.0 '@types/node': specifier: ^20.9.5 version: 20.10.4 @@ -218,9 +212,6 @@ importers: eslint: specifier: ^8.44.0 version: 8.44.0 - jest: - specifier: ^29.7.0 - version: 29.7.0(@types/node@20.10.4) lint-staged: specifier: ^15.0.0 version: 15.0.2 @@ -230,6 +221,9 @@ importers: sinon: specifier: ^17.0.0 version: 17.0.0 + vitest: + specifier: ^1.4.0 + version: 1.4.0(@types/node@20.10.4) packages/connectors/connector-alipay-native: dependencies: @@ -3395,7 +3389,7 @@ importers: devDependencies: '@jest/types': specifier: ^29.5.0 - version: 29.5.0 + version: 29.6.3 '@logto/app-insights': specifier: workspace:^1.4.0 version: link:../app-insights @@ -7427,7 +7421,7 @@ packages: dependencies: '@babel/core': 7.20.2 '@jest/types': 29.6.3 - '@jridgewell/trace-mapping': 0.3.18 + '@jridgewell/trace-mapping': 0.3.25 babel-plugin-istanbul: 6.1.1 chalk: 4.1.2 convert-source-map: 2.0.0 @@ -13811,7 +13805,7 @@ packages: engines: {node: '>=14'} dependencies: extend: 3.0.2 - https-proxy-agent: 7.0.1 + https-proxy-agent: 7.0.4 is-stream: 2.0.1 node-fetch: 2.7.0 transitivePeerDependencies: @@ -14510,16 +14504,6 @@ packages: transitivePeerDependencies: - supports-color - /https-proxy-agent@7.0.1: - resolution: {integrity: sha512-Eun8zV0kcYS1g19r78osiQLEFIRspRUDd9tIfBCTBPBeMieF/EsJNL8VI3xOIdYRDEkjQnqOYPsZ2DsWsVsFwQ==} - engines: {node: '>= 14'} - dependencies: - agent-base: 7.1.0 - debug: 4.3.4 - transitivePeerDependencies: - - supports-color - dev: false - /https-proxy-agent@7.0.4: resolution: {integrity: sha512-wlwpilI7YdjSkWaQ/7omYBMTliDcmCN8OLihO6I9B86g06lMyAoqgoDpV0XqoaPOKj+0DIdAvnsWfyAAhmimcg==} engines: {node: '>= 14'} @@ -14528,7 +14512,6 @@ packages: debug: 4.3.4 transitivePeerDependencies: - supports-color - dev: true /human-id@1.0.2: resolution: {integrity: sha512-UNopramDEhHJD+VR+ehk8rOslwSfByxPIZyJRfV739NDhN5LF1fa1MqnzKm2lGTQRjNrjK19Q5fhkgIfjlVUKw==} @@ -15734,7 +15717,7 @@ packages: '@babel/generator': 7.20.4 '@babel/plugin-syntax-jsx': 7.18.6(@babel/core@7.20.2) '@babel/plugin-syntax-typescript': 7.18.6(@babel/core@7.20.2) - '@babel/types': 7.20.2 + '@babel/types': 7.24.0 '@jest/expect-utils': 29.7.0 '@jest/transform': 29.7.0 '@jest/types': 29.6.3 @@ -15991,7 +15974,7 @@ packages: whatwg-encoding: 2.0.0 whatwg-mimetype: 3.0.0 whatwg-url: 11.0.0 - ws: 8.13.0 + ws: 8.16.0 xml-name-validator: 4.0.0 transitivePeerDependencies: - bufferutil @@ -21862,19 +21845,6 @@ packages: signal-exit: 4.1.0 dev: true - /ws@8.13.0: - resolution: {integrity: sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==} - engines: {node: '>=10.0.0'} - peerDependencies: - bufferutil: ^4.0.1 - utf-8-validate: '>=5.0.2' - peerDependenciesMeta: - bufferutil: - optional: true - utf-8-validate: - optional: true - dev: true - /ws@8.16.0: resolution: {integrity: sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ==} engines: {node: '>=10.0.0'}