-
-
Notifications
You must be signed in to change notification settings - Fork 269
/
index.ts
76 lines (71 loc) · 2.02 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
// Exports a loader, which does all the work.
// import('@esbuild-kit/esm-loader')
// import('@esbuild-kit/cjs-loader')
// import('@tapjs/core')
export const loader = '@tapjs/esbuild-kit/loader'
export const preload = true
import type { TapPlugin } from '@tapjs/core'
// the plugin just sets the configs for esbk, doesn't
// add any functionality to the Test class.
const env = (...keys: string[]) => {
for (const key of keys) {
if (process.env[`TAP_${key}`]) {
process.env[key] = process.env[`TAP_${key}`]
}
}
}
let didWarning = false
let didEnv = false
/**
* File types that this plugin adds support for
*/
export const testFileExtensions = ['ts', 'cts', 'mts', 'tsx', 'jsx']
/**
* Plugin function enabling esbuild-kit for running typescript tests
*
* The plugin function sets the esbuild-kit environment variables
* based on the tap configs, and prints a warning when used along with
* the `@tapjs/typescript` plugin, as this can cause strange conflicts,
* or at the very least, unnecessarily slow down tests by compiling the
* typescript twice.
*/
export const plugin: TapPlugin<{}> = () => {
if (!didEnv) {
env('ESBK_TSCONFIG_PATH', 'ESBK_DISABLE_CACHE')
}
const tp = process.env.TAP_PLUGIN || ''
if (!/^!@tapjs\/typescript$/m.test(tp) && !didWarning) {
didWarning = true
console.error(`
@tapjs/esbuild-kit may behave strangely when used along with
the @tapjs/typescript default plugin.
Please run: tap plugin rm @tapjs/typescript
`)
}
return {}
}
/**
* Configuration fields added by this plugin.
*
* @group Configuration
*/
export const config = {
/**
* String option. Tell `@esbuild-kit` where to find your tsconfig.json file.
*
* @group Configuration
*/
'esbk-tsconfig-path': {
type: 'string',
description: `Tell @esbuild-kit where to find your tsconfig.json file.`,
},
/**
* Flag. Tell `@esbuild-kit` not to use a cache
*
* @group Configuration
*/
'esbk-disable-cache': {
type: 'boolean',
description: `Tell @esbuild-kit not to use a cache`,
},
}