0
Fork 0
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:
Gao Sun 2021-08-20 14:53:23 +08:00
parent f1052e8f0f
commit cd57fe8866
No known key found for this signature in database
GPG key ID: 0F0EFA2E36639F31
8 changed files with 919 additions and 21 deletions

View file

@ -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

View 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',
},
},
};

View file

@ -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"
},

View 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' })
);
});
});

View file

@ -0,0 +1,12 @@
{
"extends": "@logto/ts-config/tsconfig.base",
"compilerOptions": {
"outDir": "build",
"baseUrl": ".",
"paths": {
"@/*": [
"src/*"
]
}
}
}

View file

@ -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"
]
}

View file

@ -0,0 +1,9 @@
{
"extends": "./tsconfig.base",
"compilerOptions": {
"isolatedModules": false
},
"include": [
"src/**/*.test.ts"
]
}

File diff suppressed because it is too large Load diff