-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add test converage report support (#458)
- Loading branch information
1 parent
675876c
commit 020f9ad
Showing
6 changed files
with
147 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ lib/ | |
*.log | ||
ks/test-results/* | ||
coverage/ | ||
jest_html_reporters.html | ||
jest_html_reporters.html | ||
html-report/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,7 @@ | |
"build": "tsc --project . --outDir lib", | ||
"build:watch": "tsc --watch --project . --outDir lib --watch", | ||
"type-docs": "typedoc", | ||
"openapispec:generate": "npx @hey-api/openapi-ts", | ||
"start-client": "ts-node src/sdk/baseClient.ts" | ||
"openapispec:generate": "npx @hey-api/openapi-ts" | ||
}, | ||
"keywords": [], | ||
"author": "Utkarsh Dixit <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { jsonSchemaToTsType, jsonSchemaToModel, getEnvVariable, nodeExternalRequire } from './shared'; | ||
import z from 'zod'; | ||
|
||
describe('shared utilities', () => { | ||
describe('jsonSchemaToTsType', () => { | ||
it('should convert json schema types to TypeScript types', () => { | ||
expect(jsonSchemaToTsType({ type: 'string' })).toBe(String); | ||
expect(jsonSchemaToTsType({ type: 'integer' })).toBe(Number); | ||
expect(jsonSchemaToTsType({ type: 'number' })).toBe(Number); | ||
expect(jsonSchemaToTsType({ type: 'boolean' })).toBe(Boolean); | ||
expect(jsonSchemaToTsType({ type: 'null' })).toBe(null); | ||
expect(() => jsonSchemaToTsType({ type: 'unknown' })).toThrow('Unsupported JSON schema type: unknown'); | ||
}); | ||
}); | ||
|
||
describe('jsonSchemaToModel', () => { | ||
it('should convert json schema to zod model', () => { | ||
const schema = { | ||
type: 'object', | ||
properties: { | ||
name: { type: 'string' }, | ||
age: { type: 'integer' }, | ||
}, | ||
required: ['name'] | ||
}; | ||
const model = jsonSchemaToModel(schema); | ||
expect(model).toBeInstanceOf(z.ZodObject); | ||
expect(() => model.parse({ name: 'John', age: 'not a number' })).toThrow(); | ||
expect(model.parse({ name: 'John', age: 30 })).toEqual({ name: 'John', age: 30 }); | ||
}); | ||
}); | ||
|
||
describe('getEnvVariable', () => { | ||
it('should return the environment variable if set', () => { | ||
process.env.TEST_VAR = 'test'; | ||
expect(getEnvVariable('TEST_VAR')).toBe('test'); | ||
}); | ||
|
||
it('should return undefined if the environment variable is not set', () => { | ||
delete process.env.TEST_VAR; | ||
expect(getEnvVariable('TEST_VAR')).toBeUndefined(); | ||
}); | ||
|
||
it('should return the default value if the environment variable is not set and default is provided', () => { | ||
expect(getEnvVariable('TEST_VAR', 'default')).toBe('default'); | ||
}); | ||
}); | ||
|
||
describe('nodeExternalRequire', () => { | ||
it('should require a module', () => { | ||
const module = nodeExternalRequire('path'); | ||
expect(module).toBeDefined(); | ||
}); | ||
|
||
it('should return null if the module cannot be required', () => { | ||
const module = nodeExternalRequire('nonexistent-module'); | ||
expect(module).toBeNull(); | ||
}); | ||
}); | ||
}); |