mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
feat(core): setup jest
This commit is contained in:
parent
f1052e8f0f
commit
cd57fe8866
8 changed files with 919 additions and 21 deletions
4
.github/workflows/core-main.yml
vendored
4
.github/workflows/core-main.yml
vendored
|
@ -37,6 +37,10 @@ jobs:
|
|||
working-directory: packages/core
|
||||
run: pnpm lint
|
||||
|
||||
- name: Test
|
||||
working-directory: packages/core
|
||||
run: pnpm test
|
||||
|
||||
- name: Build
|
||||
working-directory: packages/core
|
||||
run: pnpm build
|
||||
|
|
10
packages/core/jest.config.js
Normal file
10
packages/core/jest.config.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
|
||||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
globals: {
|
||||
'ts-jest': {
|
||||
tsconfig: 'tsconfig.test.json',
|
||||
},
|
||||
},
|
||||
};
|
|
@ -12,7 +12,8 @@
|
|||
"build": "rm -rf build/ && tsc",
|
||||
"lint": "eslint --format pretty --ext .ts src",
|
||||
"dev": "rm -rf build/ && tsc-watch --preserveWatchOutput --onSuccess \"node ./build/index.js\"",
|
||||
"start": "NODE_ENV=production node build/index.js"
|
||||
"start": "NODE_ENV=production node build/index.js",
|
||||
"test": "jest"
|
||||
},
|
||||
"dependencies": {
|
||||
"@logto/essentials": "^1.1.0-rc.2",
|
||||
|
@ -41,8 +42,9 @@
|
|||
"zod": "^3.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@logto/eslint-config": "^0.1.0-rc.14",
|
||||
"@logto/ts-config": "^0.1.0-rc.14",
|
||||
"@logto/eslint-config": "^0.1.0-rc.17",
|
||||
"@logto/ts-config": "^0.1.0-rc.17",
|
||||
"@types/jest": "^27.0.1",
|
||||
"@types/koa": "^2.13.3",
|
||||
"@types/koa-logger": "^3.1.1",
|
||||
"@types/koa-mount": "^4.0.0",
|
||||
|
@ -53,9 +55,11 @@
|
|||
"@types/oidc-provider": "^7.4.1",
|
||||
"eslint": "^7.30.0",
|
||||
"eslint-formatter-pretty": "^4.1.0",
|
||||
"jest": "^27.0.6",
|
||||
"lint-staged": "^11.1.1",
|
||||
"openapi-types": "^9.1.0",
|
||||
"prettier": "^2.3.2",
|
||||
"ts-jest": "^27.0.5",
|
||||
"tsc-watch": "^4.4.0",
|
||||
"typescript": "^4.3.5"
|
||||
},
|
||||
|
|
32
packages/core/src/utils/env.test.ts
Normal file
32
packages/core/src/utils/env.test.ts
Normal file
|
@ -0,0 +1,32 @@
|
|||
import { AssertionError } from 'assert';
|
||||
import { assertEnv, getEnv } from './env';
|
||||
|
||||
describe('getEnv()', () => {
|
||||
beforeAll(() => {
|
||||
process.env = { FOO: 'bar' };
|
||||
});
|
||||
|
||||
it('returns correct env value', () => {
|
||||
expect(getEnv('FOO')).toEqual('bar');
|
||||
});
|
||||
|
||||
it("returns fallback if env doesn't exist", () => {
|
||||
expect(getEnv('BAR', '123')).toEqual('123');
|
||||
});
|
||||
});
|
||||
|
||||
describe('assertEnv()', () => {
|
||||
beforeAll(() => {
|
||||
process.env = { FOO: 'bar' };
|
||||
});
|
||||
|
||||
it('returns correct env value', () => {
|
||||
expect(assertEnv('FOO')).toEqual('bar');
|
||||
});
|
||||
|
||||
it("throws an error if env doesn't exist", () => {
|
||||
expect(() => assertEnv('BAR')).toThrow(
|
||||
new AssertionError({ message: 'env variable BAR not found' })
|
||||
);
|
||||
});
|
||||
});
|
12
packages/core/tsconfig.base.json
Normal file
12
packages/core/tsconfig.base.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"extends": "@logto/ts-config/tsconfig.base",
|
||||
"compilerOptions": {
|
||||
"outDir": "build",
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"src/*"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +1,9 @@
|
|||
{
|
||||
"extends": "@logto/ts-config/tsconfig.base",
|
||||
"compilerOptions": {
|
||||
"outDir": "build",
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"src/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"extends": "./tsconfig.base",
|
||||
"include": [
|
||||
"src"
|
||||
],
|
||||
"exclude": [
|
||||
"src/**/*.test.ts"
|
||||
]
|
||||
}
|
||||
|
|
9
packages/core/tsconfig.test.json
Normal file
9
packages/core/tsconfig.test.json
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"extends": "./tsconfig.base",
|
||||
"compilerOptions": {
|
||||
"isolatedModules": false
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.test.ts"
|
||||
]
|
||||
}
|
849
pnpm-lock.yaml
849
pnpm-lock.yaml
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue