Skip to content

Commit 0f32147

Browse files
committed
Rip out tsdx, configure jest etc manually
1 parent 81e5c80 commit 0f32147

8 files changed

+1264
-4606
lines changed

jest.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
};

package.json

+13-10
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@
1515
"src"
1616
],
1717
"scripts": {
18-
"build": "tsdx build",
19-
"coverage": "tsdx test --coverage",
20-
"lint": "tsdx lint src tests",
21-
"prepare": "tsdx build",
22-
"start": "tsdx watch",
23-
"test": "tsdx test"
18+
"build": "tsc",
19+
"coverage": "jest --coverage",
20+
"lint": "tsc && prettier -list-different --write src tests",
21+
"test": "jest"
2422
},
2523
"repository": {
2624
"type": "git",
@@ -35,14 +33,19 @@
3533
"environment variable",
3634
"validation"
3735
],
36+
"dependencies": {},
3837
"devDependencies": {
38+
"@types/jest": "26.0.24",
39+
"@types/node": "16.4.0",
3940
"husky": "4.3.6",
40-
"tsdx": "^0.14.1",
41-
"typescript": "^4.1.3"
41+
"jest": "27.0.6",
42+
"prettier": "2.3.2",
43+
"ts-jest": "27.0.4",
44+
"tslib": "2.3.0",
45+
"typescript": "4.3.5"
4246
},
4347
"author": "Aaron Franks",
4448
"license": "MIT",
45-
"dependencies": {},
4649
"prettier": {
4750
"printWidth": 100,
4851
"semi": false,
@@ -51,7 +54,7 @@
5154
},
5255
"husky": {
5356
"hooks": {
54-
"pre-commit": "yarn lint --fix",
57+
"pre-commit": "yarn lint",
5558
"pre-push": "yarn test"
5659
}
5760
}

src/envalid.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ export function customCleanEnv<T, MW>(
4545
* For more context, see https://github.com/af/envalid/issues/32
4646
*/
4747
export const testOnly = <T>(defaultValueForTests: T) => {
48-
return process.env.NODE_ENV === 'test' ? defaultValueForTests : ((testOnlySymbol as unknown) as T) // T is not strictly correct, but prevents type errors during usage
48+
return process.env.NODE_ENV === 'test' ? defaultValueForTests : (testOnlySymbol as unknown as T) // T is not strictly correct, but prevents type errors during usage
4949
}

src/reporter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const defaultReporter = <T = any>(
5656
colors.yellow('\n Exiting with error code 1'),
5757
RULE,
5858
]
59-
.filter(x => !!x)
59+
.filter((x) => !!x)
6060
.join('\n')
6161

6262
logger(output)

src/validators.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ const isFQDN = (input: string) => {
1717
// "best effort" regex-based IP address check
1818
// If you want a more exhaustive check, create your own custom validator, perhaps wrapping this
1919
// implementation (the source of the ipv4 regex below): https://github.com/validatorjs/validator.js/blob/master/src/lib/isIP.js
20-
const ipv4Regex = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/
20+
const ipv4Regex =
21+
/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/
2122
const ipv6Regex = /([a-f0-9]+:+)+[a-f0-9]+/
2223
const isIP = (input: string) => {
2324
if (!input.length) return false
@@ -27,7 +28,7 @@ const isIP = (input: string) => {
2728
const EMAIL_REGEX = /^[^@\s]+@[^@\s]+\.[^@\s]+$/ // intentionally non-exhaustive
2829

2930
export const makeValidator = <T>(parseFn: (input: string) => T) => {
30-
return function(spec?: Spec<T>): ValidatorSpec<T> {
31+
return function (spec?: Spec<T>): ValidatorSpec<T> {
3132
return { ...spec, _parse: parseFn }
3233
}
3334
}
@@ -104,6 +105,7 @@ export function port<T extends number = number>(spec?: Spec<T>) {
104105
export function url<T extends string = string>(spec?: Spec<T>) {
105106
return makeValidator((x: string) => {
106107
try {
108+
// @ts-expect-error TS doesn't acknowledge this API by default yet
107109
new URL(x)
108110
return x
109111
} catch (e) {

tests/validators.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ test('str()', () => {
114114
})
115115

116116
test('custom types', () => {
117-
const alwaysFoo = makeValidator(_x => 'foo')
117+
const alwaysFoo = makeValidator((_x) => 'foo')
118118

119119
const fooEnv = cleanEnv({ FOO: 'asdf' }, { FOO: alwaysFoo() })
120120
expect(fooEnv).toEqual({ FOO: 'foo' })
121121

122-
const hex10 = makeValidator(x => {
122+
const hex10 = makeValidator((x) => {
123123
if (/^[a-f0-9]{10}$/.test(x)) return x
124124
throw new Error('need 10 hex chars')
125125
})

tsconfig.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
{
22
"compilerOptions": {
3+
"outDir": "./dist",
34
"rootDir": "./src",
45
"strict": true,
5-
"module": "esnext",
6+
"module": "commonjs",
67
"moduleResolution": "node",
78
"esModuleInterop": true,
89
"importHelpers": true,
910
"declaration": true,
1011
"sourceMap": true,
1112
"noUnusedLocals": true,
1213
"noUnusedParameters": true,
13-
"noImplicitReturns": true
14+
"noImplicitReturns": true,
15+
"lib": ["es2019"]
1416
},
1517
"include": ["src"],
1618
"exclude": [

0 commit comments

Comments
 (0)