mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
chore(toolkit): add UTs for connector-kit (#3760)
This commit is contained in:
parent
db4bc9e3ba
commit
6a463f6a2a
6 changed files with 94 additions and 6 deletions
13
packages/toolkit/connector-kit/jest.config.js
Normal file
13
packages/toolkit/connector-kit/jest.config.js
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
/** @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;
|
|
@ -29,7 +29,11 @@
|
||||||
"build:test": "pnpm build",
|
"build:test": "pnpm build",
|
||||||
"lint": "eslint --ext .ts src",
|
"lint": "eslint --ext .ts src",
|
||||||
"lint:report": "pnpm lint --format json --output-file report.json",
|
"lint:report": "pnpm lint --format json --output-file report.json",
|
||||||
"prepack": "pnpm build"
|
"prepack": "pnpm build",
|
||||||
|
"test:only": "NODE_OPTIONS=--experimental-vm-modules jest",
|
||||||
|
"test": "pnpm build:test && pnpm test:only",
|
||||||
|
"test:ci": "pnpm test:only",
|
||||||
|
"test:coverage": "pnpm test:only --silent --coverage"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@logto/language-kit": "workspace:^1.0.0",
|
"@logto/language-kit": "workspace:^1.0.0",
|
||||||
|
@ -39,10 +43,13 @@
|
||||||
"zod": "^3.20.2"
|
"zod": "^3.20.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@jest/types": "^29.0.3",
|
||||||
"@silverhand/eslint-config": "3.0.1",
|
"@silverhand/eslint-config": "3.0.1",
|
||||||
"@silverhand/ts-config": "3.0.0",
|
"@silverhand/ts-config": "3.0.0",
|
||||||
|
"@types/jest": "^29.4.0",
|
||||||
"@types/node": "^18.11.18",
|
"@types/node": "^18.11.18",
|
||||||
"eslint": "^8.34.0",
|
"eslint": "^8.34.0",
|
||||||
|
"jest": "^29.5.0",
|
||||||
"lint-staged": "^13.0.0",
|
"lint-staged": "^13.0.0",
|
||||||
"prettier": "^2.8.2",
|
"prettier": "^2.8.2",
|
||||||
"tslib": "^2.4.1",
|
"tslib": "^2.4.1",
|
||||||
|
|
50
packages/toolkit/connector-kit/src/index.test.ts
Normal file
50
packages/toolkit/connector-kit/src/index.test.ts
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
import { parseJson, parseJsonObject, validateConfig } from './index.js';
|
||||||
|
|
||||||
|
describe('connector-kit', () => {
|
||||||
|
describe('validateConfig', () => {
|
||||||
|
it('valid config', () => {
|
||||||
|
const testingTypeGuard = z.unknown();
|
||||||
|
type TestingType = z.infer<typeof testingTypeGuard>;
|
||||||
|
const testingConfig = { foo: 'foo', bar: 1, baz: true };
|
||||||
|
expect(() => {
|
||||||
|
validateConfig<TestingType>(testingConfig, testingTypeGuard);
|
||||||
|
}).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('invalid config', () => {
|
||||||
|
const testingTypeGuard = z.record(z.string());
|
||||||
|
type TestingType = z.infer<typeof testingTypeGuard>;
|
||||||
|
const testingConfig = { foo: 'foo', bar: 1 };
|
||||||
|
expect(() => {
|
||||||
|
validateConfig<TestingType>(testingConfig, testingTypeGuard);
|
||||||
|
}).toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('parseJson', () => {
|
||||||
|
it('should return parsed result', () => {
|
||||||
|
const literalContent = 'foo';
|
||||||
|
expect(parseJson(JSON.stringify(literalContent))).toEqual(literalContent);
|
||||||
|
|
||||||
|
const objectContent = { foo: 'foo', bar: 1, baz: true, qux: [1, '2', null] };
|
||||||
|
expect(parseJson(JSON.stringify(objectContent))).toEqual(objectContent);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('throw error when parsing invalid Json string', () => {
|
||||||
|
expect(() => parseJson('[1,2,3,"4",]')).toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('parseJsonObject', () => {
|
||||||
|
it('should return parsed object', () => {
|
||||||
|
const objectContent = { foo: 'foo', bar: 1, baz: true, qux: [1, '2', null] };
|
||||||
|
expect(parseJsonObject(JSON.stringify(objectContent))).toEqual(objectContent);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('throw error when parsing non-object result', () => {
|
||||||
|
expect(() => parseJsonObject(JSON.stringify('foo'))).toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
5
packages/toolkit/connector-kit/tsconfig.build.json
Normal file
5
packages/toolkit/connector-kit/tsconfig.build.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"extends": "./tsconfig",
|
||||||
|
"include": ["src"],
|
||||||
|
"exclude": ["src/**/*.test.ts"]
|
||||||
|
}
|
8
packages/toolkit/connector-kit/tsconfig.test.json
Normal file
8
packages/toolkit/connector-kit/tsconfig.test.json
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"extends": "./tsconfig",
|
||||||
|
"compilerOptions": {
|
||||||
|
"isolatedModules": false,
|
||||||
|
"allowJs": true
|
||||||
|
},
|
||||||
|
"include": ["src"]
|
||||||
|
}
|
|
@ -3681,18 +3681,27 @@ importers:
|
||||||
specifier: ^3.20.2
|
specifier: ^3.20.2
|
||||||
version: 3.20.2
|
version: 3.20.2
|
||||||
devDependencies:
|
devDependencies:
|
||||||
|
'@jest/types':
|
||||||
|
specifier: ^29.0.3
|
||||||
|
version: 29.1.2
|
||||||
'@silverhand/eslint-config':
|
'@silverhand/eslint-config':
|
||||||
specifier: 3.0.1
|
specifier: 3.0.1
|
||||||
version: 3.0.1(eslint@8.34.0)(prettier@2.8.4)(typescript@5.0.2)
|
version: 3.0.1(eslint@8.34.0)(prettier@2.8.4)(typescript@5.0.2)
|
||||||
'@silverhand/ts-config':
|
'@silverhand/ts-config':
|
||||||
specifier: 3.0.0
|
specifier: 3.0.0
|
||||||
version: 3.0.0(typescript@5.0.2)
|
version: 3.0.0(typescript@5.0.2)
|
||||||
|
'@types/jest':
|
||||||
|
specifier: ^29.4.0
|
||||||
|
version: 29.4.0
|
||||||
'@types/node':
|
'@types/node':
|
||||||
specifier: ^18.11.18
|
specifier: ^18.11.18
|
||||||
version: 18.11.18
|
version: 18.11.18
|
||||||
eslint:
|
eslint:
|
||||||
specifier: ^8.34.0
|
specifier: ^8.34.0
|
||||||
version: 8.34.0
|
version: 8.34.0
|
||||||
|
jest:
|
||||||
|
specifier: ^29.5.0
|
||||||
|
version: 29.5.0(@types/node@18.11.18)
|
||||||
lint-staged:
|
lint-staged:
|
||||||
specifier: ^13.0.0
|
specifier: ^13.0.0
|
||||||
version: 13.0.0
|
version: 13.0.0
|
||||||
|
@ -12564,7 +12573,7 @@ packages:
|
||||||
resolution: {integrity: sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==}
|
resolution: {integrity: sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==}
|
||||||
engines: {node: '>=12'}
|
engines: {node: '>=12'}
|
||||||
dependencies:
|
dependencies:
|
||||||
graceful-fs: 4.2.9
|
graceful-fs: 4.2.10
|
||||||
jsonfile: 6.1.0
|
jsonfile: 6.1.0
|
||||||
universalify: 2.0.0
|
universalify: 2.0.0
|
||||||
dev: true
|
dev: true
|
||||||
|
@ -12876,10 +12885,6 @@ packages:
|
||||||
resolution: {integrity: sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==}
|
resolution: {integrity: sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/graceful-fs@4.2.9:
|
|
||||||
resolution: {integrity: sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==}
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/grapheme-splitter@1.0.4:
|
/grapheme-splitter@1.0.4:
|
||||||
resolution: {integrity: sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==}
|
resolution: {integrity: sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
Loading…
Reference in a new issue