-
-
Notifications
You must be signed in to change notification settings - Fork 269
/
index.ts
147 lines (132 loc) · 4.64 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import { env, TapPlugin } from '@tapjs/core'
import { statSync } from 'node:fs'
import { resolve } from 'node:path'
// This just adds the ts-node/esm loader
// appease the import-deps test
// import('@isaacs/ts-node-temp-fork-for-pr-2009')
export const loader = '@isaacs/ts-node-temp-fork-for-pr-2009/esm'
export const importLoader =
'@isaacs/ts-node-temp-fork-for-pr-2009/import'
// ts-node/esm should come AHEAD of other loaders in the args list,
// otherwise any other resolve()'s won't be run
export const preload = true
const fileExists = (path: string) => {
try {
return statSync(path).isFile()
} catch {
return false
}
}
let didSet = false
export const plugin: TapPlugin<{}> = () => {
if (!didSet) {
if (env.TAP_TYPECHECK === '1') {
env.TS_NODE_TRANSPILE_ONLY = '0'
} else {
env.TS_NODE_TRANSPILE_ONLY = '1'
}
if (env.TAP_CWD && !env.TAP_TSCONFIG) {
for (const tsconfig of [
'tsconfig.tap.json',
'tsconfig.test.json',
'tsconfig.spec.json',
'tsconfig.json',
]) {
if (fileExists(resolve(env.TAP_CWD, tsconfig))) {
env.TAP_TSCONFIG = tsconfig
break
}
}
}
if (env.TAP_TSCONFIG && env.TAP_CWD) {
env.TS_NODE_PROJECT = resolve(env.TAP_CWD, env.TAP_TSCONFIG)
}
didSet = true
}
return {}
}
/**
* File types that this plugin adds support for
*/
export const testFileExtensions = ['ts', 'cts', 'mts', 'tsx', 'jsx']
/**
* Options added by this plugin
*
* @group Configuration
*/
export const config = {
/**
* flag
*
* Type-check test files, in addition to transpiling and running them.
*
* This defaults to false, even though type checking your tests is generally
* a good idea. Unfortunately, it is also often considerably slower, adding
* as much as 500-750ms to each test suite file, which can be painful if you
* have a lot of tests. In large project folders, the effect can be even more
* pronounced.
*
* It is a good idea to enable this in CI environments, where test speed is
* less of an ergonomic drawback.
*
* The `"skipLibCheck": true` option in tsconfig will also speed things up a
* bit, at the expense of some type safety.
*
* Note that even if you pre-compile your tests, they will still be subject
* to type checking if `"allowJs": true` is set in your tsconfig.
*
* @group Configuration
*/
typecheck: {
type: 'boolean',
description: `Type-check test files, in addition to transpiling and running
them.
This defaults to false, even though type checking your tests
is generally a good idea. Unfortunately, it is also often
considerably slower, adding as much as 500-750ms to each test
suite file, which can be painful if you have a lot of tests.
In large project folders, the effect can be even more
pronounced.
It is a good idea to enable this in CI environments, where
test speed is less of an ergonomic drawback.
The \`"skipLibCheck": true"\` option in tsconfig will also
speed things up a bit, at the expense of some type safety.
Note that even if you pre-compile your tests, they will still
be subject to type checking if \`"allowJs": true\` is set in
your tsconfig.
`,
},
/**
* Path to the `tsconfig.json` file containing project settings provided to
* ts-node when running tests.
*
* Similar to the `--project` option to ts-node. Sets the `TS_NODE_PROJECT`
* environment variable.
*
* If this is a relative directory, then it is resolved against the project
* root directory.
*
* Defaults to the first of these files that are found in the project root
* directory:
*
* - tsconfig.tap.json
* - tsconfig.test.json
* - tsconfig.spec.json
* - tsconfig.json
*/
tsconfig: {
type: 'string',
description: `Path to the \`tsconfig.json\` file containing project
settings provided to ts-node when running tests.
Similar to the \`--project\` option to ts-node. Sets the
\`TS_NODE_PROJECT\` environment variable.
If this is a relative directory, then it is resolved
against the project root directory.
Defaults to the first of these files that are found in
the project root directory:
- tsconfig.tap.json
- tsconfig.test.json
- tsconfig.spec.json
- tsconfig.json`,
},
}