mirror of
https://github.com/logto-io/logto.git
synced 2025-02-17 22:04:19 -05:00
refactor: remove jest
This commit is contained in:
parent
412a3df1cf
commit
340d562f37
14 changed files with 46 additions and 127 deletions
|
@ -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)$': '<rootDir>/../shared/lib/esm/module-proxy.js',
|
||||
},
|
||||
};
|
||||
|
||||
export default config;
|
|
@ -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"
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { normalizeError } from './normalize-error.js';
|
||||
|
||||
describe('normalizeError()', () => {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"extends": "@silverhand/ts-config-react/tsconfig.base",
|
||||
"compilerOptions": {
|
||||
"outDir": "lib",
|
||||
"types": ["node", "jest"],
|
||||
"types": ["node"],
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
{
|
||||
"extends": "./tsconfig.build",
|
||||
"compilerOptions": {
|
||||
"isolatedModules": false,
|
||||
"allowJs": true,
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
|
@ -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)$': '<rootDir>/../shared/lib/esm/module-proxy.js',
|
||||
},
|
||||
};
|
||||
|
||||
export default config;
|
|
@ -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",
|
||||
|
|
|
@ -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<object>()),
|
||||
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<object>()),
|
||||
getCurrentDatabaseAlterationTimestamp,
|
||||
}));
|
||||
|
||||
const { getAvailableAlterations } = await import('./index.js');
|
||||
|
||||
|
|
5
packages/cli/src/include.d/import-meta.d.ts
vendored
5
packages/cli/src/include.d/import-meta.d.ts
vendored
|
@ -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;
|
||||
}
|
|
@ -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<QueryType> = jest.fn();
|
||||
const mockQuery: MockedFunction<QueryType> = 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 () => {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"extends": "@silverhand/ts-config/tsconfig.base",
|
||||
"compilerOptions": {
|
||||
"outDir": "lib",
|
||||
"types": ["node", "jest"]
|
||||
"types": ["node"]
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
{
|
||||
"extends": "./tsconfig",
|
||||
"compilerOptions": {
|
||||
"isolatedModules": false,
|
||||
"allowJs": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
58
pnpm-lock.yaml
generated
58
pnpm-lock.yaml
generated
|
@ -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'}
|
||||
|
|
Loading…
Add table
Reference in a new issue