-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4aefaf1
commit 2e84f56
Showing
10 changed files
with
162 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"presets": [ | ||
"@babel/preset-env", | ||
"@babel/preset-typescript" | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { JestConfigWithTsJest } from 'ts-jest'; | ||
|
||
const config: JestConfigWithTsJest = { | ||
verbose: true, | ||
transform: { | ||
'^.+\\.ts?$': [ | ||
'ts-jest', | ||
{ | ||
useESM: true, | ||
}, | ||
], | ||
}, | ||
extensionsToTreatAsEsm: ['.ts'], | ||
moduleNameMapper: { | ||
'^(\\.{1,2}/.*)\\.js$': '$1', | ||
}, | ||
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'] | ||
}; | ||
|
||
export default config; |
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 @@ | ||
// TODO Env |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import {Schema, SchemaErrors} from 'vts'; | ||
|
||
interface CustomMatcherResult { | ||
pass: boolean; | ||
message: () => string; | ||
} | ||
|
||
export const SchemaMatchers = { | ||
toValidateSchema: (received: any, schema: Schema<any>): CustomMatcherResult | Promise<CustomMatcherResult> => { | ||
const errors: SchemaErrors = []; | ||
|
||
if (schema.validate(received, errors)) { | ||
return { | ||
message: () => 'expected object schema is not validate', | ||
pass: false, | ||
}; | ||
} | ||
|
||
return { | ||
message: () => 'expected object schema is validate', | ||
pass: true, | ||
}; | ||
} | ||
}; | ||
|
||
declare global { | ||
// eslint-disable-next-line @typescript-eslint/no-namespace | ||
namespace jest { | ||
|
||
interface Matchers<R> { | ||
toValidateSchema(schema: Schema<any>): R; | ||
} | ||
} | ||
} | ||
|
||
export {}; |
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,21 @@ | ||
import {IpLocateData, IpLocateIo, SchemaIpLocateData} from '../../../src/inc/Provider/IpLocate/IpLocateIo'; | ||
import {SchemaMatchers} from '../../../src/types/ExpectSchema'; | ||
|
||
expect.extend(SchemaMatchers); | ||
|
||
describe('testing ip locate IO by ip 8.8.8.8', () => { | ||
const ip = '8.8.8.8'; | ||
let result: IpLocateData|null = null; | ||
|
||
beforeAll(async() => { | ||
result = await IpLocateIo.location(ip); | ||
}); | ||
|
||
test('test result is not empty', async() => { | ||
expect(result).toBeTruthy(); | ||
}); | ||
|
||
test('test result type by schema: SchemaIpLocateData', async() => { | ||
expect(result).toValidateSchema(SchemaIpLocateData); | ||
}); | ||
}); |
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