@plugjs/plug 0.0.27 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{failure.cjs → asserts.cjs} +30 -10
- package/dist/asserts.cjs.map +6 -0
- package/dist/{failure.d.ts → asserts.d.ts} +4 -1
- package/dist/asserts.mjs +51 -0
- package/dist/asserts.mjs.map +6 -0
- package/dist/async.cjs +2 -2
- package/dist/async.cjs.map +1 -1
- package/dist/async.mjs +2 -2
- package/dist/async.mjs.map +1 -1
- package/dist/build.cjs +22 -33
- package/dist/build.cjs.map +1 -1
- package/dist/build.d.ts +2 -13
- package/dist/build.mjs +17 -27
- package/dist/build.mjs.map +1 -1
- package/dist/files.cjs +7 -11
- package/dist/files.cjs.map +1 -1
- package/dist/files.mjs +5 -9
- package/dist/files.mjs.map +1 -1
- package/dist/fork.cjs +35 -30
- package/dist/fork.cjs.map +1 -1
- package/dist/fork.d.ts +6 -3
- package/dist/fork.mjs +18 -13
- package/dist/fork.mjs.map +1 -1
- package/dist/{utils/asyncfs.cjs → fs.cjs} +6 -6
- package/dist/fs.cjs.map +6 -0
- package/dist/{utils/asyncfs.d.ts → fs.d.ts} +1 -1
- package/dist/{utils/asyncfs.mjs → fs.mjs} +3 -3
- package/dist/fs.mjs.map +6 -0
- package/dist/helpers.cjs +31 -14
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.ts +30 -1
- package/dist/helpers.mjs +22 -7
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.cjs +36 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +25 -8
- package/dist/index.mjs +20 -5
- package/dist/index.mjs.map +1 -1
- package/dist/{log → logging}/colors.cjs +1 -1
- package/dist/{log → logging}/colors.cjs.map +1 -1
- package/dist/{log → logging}/colors.d.ts +0 -0
- package/dist/{log → logging}/colors.mjs +1 -1
- package/dist/{log → logging}/colors.mjs.map +1 -1
- package/dist/{log → logging}/emit.cjs +1 -2
- package/dist/{log → logging}/emit.cjs.map +2 -2
- package/dist/{log → logging}/emit.d.ts +1 -1
- package/dist/{log → logging}/emit.mjs +1 -2
- package/dist/{log → logging}/emit.mjs.map +2 -2
- package/dist/{log → logging}/levels.cjs +1 -1
- package/dist/{log → logging}/levels.cjs.map +1 -1
- package/dist/{log → logging}/levels.d.ts +6 -6
- package/dist/{log → logging}/levels.mjs +1 -1
- package/dist/{log → logging}/levels.mjs.map +1 -1
- package/dist/{log → logging}/logger.cjs +13 -7
- package/dist/logging/logger.cjs.map +6 -0
- package/dist/{log → logging}/logger.d.ts +0 -0
- package/dist/{log → logging}/logger.mjs +11 -5
- package/dist/logging/logger.mjs.map +6 -0
- package/dist/{log → logging}/options.cjs +12 -6
- package/dist/logging/options.cjs.map +6 -0
- package/dist/{log → logging}/options.d.ts +1 -1
- package/dist/{log → logging}/options.mjs +12 -6
- package/dist/logging/options.mjs.map +6 -0
- package/dist/{log → logging}/report.cjs +11 -11
- package/dist/logging/report.cjs.map +6 -0
- package/dist/{log → logging}/report.d.ts +1 -1
- package/dist/{log → logging}/report.mjs +8 -8
- package/dist/logging/report.mjs.map +6 -0
- package/dist/{log → logging}/spinner.cjs +1 -1
- package/dist/{log → logging}/spinner.cjs.map +1 -1
- package/dist/{log → logging}/spinner.d.ts +0 -0
- package/dist/{log → logging}/spinner.mjs +1 -1
- package/dist/{log → logging}/spinner.mjs.map +1 -1
- package/dist/{log.cjs → logging.cjs} +13 -16
- package/dist/logging.cjs.map +6 -0
- package/dist/logging.d.ts +10 -0
- package/dist/{log.mjs → logging.mjs} +10 -13
- package/dist/logging.mjs.map +6 -0
- package/dist/paths.cjs +25 -27
- package/dist/paths.cjs.map +1 -1
- package/dist/paths.d.ts +8 -8
- package/dist/paths.mjs +23 -25
- package/dist/paths.mjs.map +1 -1
- package/dist/pipe.cjs +10 -13
- package/dist/pipe.cjs.map +1 -1
- package/dist/pipe.d.ts +13 -19
- package/dist/pipe.mjs +6 -9
- package/dist/pipe.mjs.map +1 -1
- package/dist/plugs/copy.cjs +14 -14
- package/dist/plugs/copy.cjs.map +1 -1
- package/dist/plugs/copy.d.ts +1 -1
- package/dist/plugs/copy.mjs +3 -3
- package/dist/plugs/copy.mjs.map +1 -1
- package/dist/plugs/debug.cjs +7 -7
- package/dist/plugs/debug.cjs.map +1 -1
- package/dist/plugs/debug.d.ts +1 -1
- package/dist/plugs/debug.mjs +1 -1
- package/dist/plugs/edit.cjs +21 -0
- package/dist/plugs/edit.cjs.map +6 -0
- package/dist/plugs/edit.d.ts +7 -0
- package/dist/plugs/edit.mjs +29 -0
- package/dist/plugs/edit.mjs.map +6 -0
- package/dist/plugs/esbuild/fix-extensions.cjs +7 -8
- package/dist/plugs/esbuild/fix-extensions.cjs.map +1 -1
- package/dist/plugs/esbuild/fix-extensions.mjs +4 -5
- package/dist/plugs/esbuild/fix-extensions.mjs.map +1 -1
- package/dist/plugs/esbuild.cjs +19 -14
- package/dist/plugs/esbuild.cjs.map +1 -1
- package/dist/plugs/esbuild.d.ts +2 -2
- package/dist/plugs/esbuild.mjs +8 -3
- package/dist/plugs/esbuild.mjs.map +1 -1
- package/dist/plugs/exec.cjs +2 -82
- package/dist/plugs/exec.cjs.map +2 -2
- package/dist/plugs/exec.d.ts +6 -32
- package/dist/plugs/exec.mjs +2 -68
- package/dist/plugs/exec.mjs.map +1 -1
- package/dist/plugs/filter.d.ts +1 -1
- package/dist/plugs/rmf.cjs +5 -5
- package/dist/plugs/rmf.cjs.map +1 -1
- package/dist/plugs/rmf.d.ts +1 -1
- package/dist/plugs/rmf.mjs +2 -2
- package/dist/plugs/rmf.mjs.map +1 -1
- package/dist/plugs.cjs +1 -4
- package/dist/plugs.cjs.map +1 -1
- package/dist/plugs.d.ts +1 -4
- package/dist/plugs.mjs +1 -4
- package/dist/plugs.mjs.map +1 -1
- package/dist/types.d.ts +8 -8
- package/dist/utils/caller.cjs +8 -5
- package/dist/utils/caller.cjs.map +1 -1
- package/dist/utils/caller.mjs +6 -3
- package/dist/utils/caller.mjs.map +1 -1
- package/dist/utils/exec.cjs +102 -0
- package/dist/utils/exec.cjs.map +6 -0
- package/dist/utils/exec.d.ts +15 -0
- package/dist/utils/exec.mjs +71 -0
- package/dist/utils/exec.mjs.map +6 -0
- package/dist/utils/match.d.ts +1 -1
- package/dist/utils/options.d.ts +3 -3
- package/dist/utils/walk.cjs +7 -7
- package/dist/utils/walk.cjs.map +1 -1
- package/dist/utils/walk.mjs +2 -2
- package/dist/utils/walk.mjs.map +1 -1
- package/dist/{plugs/tsc.cjs → utils.cjs} +9 -7
- package/dist/utils.cjs.map +6 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.mjs +6 -0
- package/dist/utils.mjs.map +6 -0
- package/extra/cli.mjs +26 -5
- package/extra/ts-loader.mjs +4 -4
- package/package.json +101 -20
- package/src/{assert.ts → asserts.ts} +36 -1
- package/src/async.ts +3 -1
- package/src/build.ts +179 -0
- package/src/files.ts +5 -5
- package/src/fork.ts +19 -11
- package/src/{utils/asyncfs.ts → fs.ts} +7 -6
- package/src/helpers.ts +56 -8
- package/src/index.ts +30 -8
- package/src/{log → logging}/colors.ts +0 -0
- package/src/{log → logging}/emit.ts +0 -1
- package/src/{log → logging}/levels.ts +0 -0
- package/src/{log → logging}/logger.ts +13 -4
- package/src/{log → logging}/options.ts +11 -7
- package/src/{log → logging}/report.ts +10 -9
- package/src/{log → logging}/spinner.ts +0 -0
- package/src/{log.ts → logging.ts} +7 -7
- package/src/paths.ts +36 -41
- package/src/pipe.ts +13 -20
- package/src/plugs/copy.ts +4 -4
- package/src/plugs/debug.ts +2 -2
- package/src/plugs/edit.ts +34 -0
- package/src/plugs/esbuild/fix-extensions.ts +2 -2
- package/src/plugs/esbuild.ts +13 -7
- package/src/plugs/exec.ts +8 -129
- package/src/plugs/filter.ts +1 -1
- package/src/plugs/rmf.ts +3 -3
- package/src/plugs.ts +1 -13
- package/src/types.ts +1 -1
- package/src/utils/caller.ts +6 -3
- package/src/utils/exec.ts +112 -0
- package/src/utils/walk.ts +3 -3
- package/src/utils.ts +4 -0
- package/types/{webassembly.d.ts → plugjs.d.ts} +7 -1
- package/dist/assert.cjs +0 -52
- package/dist/assert.cjs.map +0 -6
- package/dist/assert.d.ts +0 -4
- package/dist/assert.mjs +0 -26
- package/dist/assert.mjs.map +0 -6
- package/dist/failure.cjs.map +0 -6
- package/dist/failure.mjs +0 -33
- package/dist/failure.mjs.map +0 -6
- package/dist/log/logger.cjs.map +0 -6
- package/dist/log/logger.mjs.map +0 -6
- package/dist/log/options.cjs.map +0 -6
- package/dist/log/options.mjs.map +0 -6
- package/dist/log/report.cjs.map +0 -6
- package/dist/log/report.mjs.map +0 -6
- package/dist/log.cjs.map +0 -6
- package/dist/log.d.ts +0 -10
- package/dist/log.mjs.map +0 -6
- package/dist/plugs/coverage/analysis.cjs +0 -234
- package/dist/plugs/coverage/analysis.cjs.map +0 -6
- package/dist/plugs/coverage/analysis.d.ts +0 -104
- package/dist/plugs/coverage/analysis.mjs +0 -207
- package/dist/plugs/coverage/analysis.mjs.map +0 -6
- package/dist/plugs/coverage/report.cjs +0 -235
- package/dist/plugs/coverage/report.cjs.map +0 -6
- package/dist/plugs/coverage/report.d.ts +0 -59
- package/dist/plugs/coverage/report.mjs +0 -220
- package/dist/plugs/coverage/report.mjs.map +0 -6
- package/dist/plugs/coverage.cjs +0 -140
- package/dist/plugs/coverage.cjs.map +0 -6
- package/dist/plugs/coverage.d.ts +0 -49
- package/dist/plugs/coverage.mjs +0 -123
- package/dist/plugs/coverage.mjs.map +0 -6
- package/dist/plugs/eslint/runner.cjs +0 -91
- package/dist/plugs/eslint/runner.cjs.map +0 -6
- package/dist/plugs/eslint/runner.d.ts +0 -8
- package/dist/plugs/eslint/runner.mjs +0 -68
- package/dist/plugs/eslint/runner.mjs.map +0 -6
- package/dist/plugs/eslint.cjs +0 -22
- package/dist/plugs/eslint.cjs.map +0 -6
- package/dist/plugs/eslint.d.ts +0 -34
- package/dist/plugs/eslint.mjs +0 -5
- package/dist/plugs/eslint.mjs.map +0 -6
- package/dist/plugs/mocha/reporter.cjs +0 -159
- package/dist/plugs/mocha/reporter.cjs.map +0 -6
- package/dist/plugs/mocha/reporter.d.ts +0 -6
- package/dist/plugs/mocha/reporter.mjs +0 -127
- package/dist/plugs/mocha/reporter.mjs.map +0 -6
- package/dist/plugs/mocha/runner.cjs +0 -82
- package/dist/plugs/mocha/runner.cjs.map +0 -6
- package/dist/plugs/mocha/runner.d.ts +0 -8
- package/dist/plugs/mocha/runner.mjs +0 -53
- package/dist/plugs/mocha/runner.mjs.map +0 -6
- package/dist/plugs/mocha.cjs +0 -22
- package/dist/plugs/mocha.cjs.map +0 -6
- package/dist/plugs/mocha.d.ts +0 -37
- package/dist/plugs/mocha.mjs +0 -5
- package/dist/plugs/mocha.mjs.map +0 -6
- package/dist/plugs/tsc/compiler.cjs +0 -74
- package/dist/plugs/tsc/compiler.cjs.map +0 -6
- package/dist/plugs/tsc/compiler.d.ts +0 -24
- package/dist/plugs/tsc/compiler.mjs +0 -43
- package/dist/plugs/tsc/compiler.mjs.map +0 -6
- package/dist/plugs/tsc/options.cjs +0 -82
- package/dist/plugs/tsc/options.cjs.map +0 -6
- package/dist/plugs/tsc/options.d.ts +0 -8
- package/dist/plugs/tsc/options.mjs +0 -51
- package/dist/plugs/tsc/options.mjs.map +0 -6
- package/dist/plugs/tsc/report.cjs +0 -90
- package/dist/plugs/tsc/report.cjs.map +0 -6
- package/dist/plugs/tsc/report.d.ts +0 -5
- package/dist/plugs/tsc/report.mjs +0 -59
- package/dist/plugs/tsc/report.mjs.map +0 -6
- package/dist/plugs/tsc/runner.cjs +0 -124
- package/dist/plugs/tsc/runner.cjs.map +0 -6
- package/dist/plugs/tsc/runner.d.ts +0 -8
- package/dist/plugs/tsc/runner.mjs +0 -95
- package/dist/plugs/tsc/runner.mjs.map +0 -6
- package/dist/plugs/tsc.cjs.map +0 -6
- package/dist/plugs/tsc.d.ts +0 -48
- package/dist/plugs/tsc.mjs +0 -5
- package/dist/plugs/tsc.mjs.map +0 -6
- package/dist/utils/asyncfs.cjs.map +0 -6
- package/dist/utils/asyncfs.mjs.map +0 -6
- package/src/failure.ts +0 -43
- package/src/plugs/coverage/analysis.ts +0 -400
- package/src/plugs/coverage/report.ts +0 -368
- package/src/plugs/coverage.ts +0 -216
- package/src/plugs/eslint/runner.ts +0 -100
- package/src/plugs/eslint.ts +0 -42
- package/src/plugs/mocha/reporter.ts +0 -178
- package/src/plugs/mocha/runner.ts +0 -66
- package/src/plugs/mocha.ts +0 -43
- package/src/plugs/tsc/compiler.ts +0 -68
- package/src/plugs/tsc/options.ts +0 -100
- package/src/plugs/tsc/report.ts +0 -77
- package/src/plugs/tsc/runner.ts +0 -133
- package/src/plugs/tsc.ts +0 -58
- package/types/globals.d.ts +0 -15
package/src/plugs/eslint.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { installForking } from '../fork'
|
|
2
|
-
import { requireResolve } from '../paths'
|
|
3
|
-
|
|
4
|
-
export interface ESLintOptions {
|
|
5
|
-
/** ESLint's own _current working directory_, where config files are. */
|
|
6
|
-
directory?: string
|
|
7
|
-
/** Show sources in report? */
|
|
8
|
-
showSources?: boolean
|
|
9
|
-
/**
|
|
10
|
-
* ESLint's _override_ configuration file: configurations specified in this
|
|
11
|
-
* file will override any other configuration specified elsewhere.
|
|
12
|
-
*/
|
|
13
|
-
configFile?: string
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
declare module '../pipe' {
|
|
17
|
-
export interface Pipe {
|
|
18
|
-
/**
|
|
19
|
-
* Run {@link https://eslint.org/ _ESlint_} over the input source files,
|
|
20
|
-
* using the configuration from the local `.eslintrc.*` file.
|
|
21
|
-
*/
|
|
22
|
-
eslint(): Promise<undefined>
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Run {@link https://eslint.org/ _ESlint_} over the input source files,
|
|
26
|
-
* using the configuration from the specified `configFile` (this wil
|
|
27
|
-
* override any `.eslintrc.*` file).
|
|
28
|
-
*
|
|
29
|
-
* @param configFile The configuration file to use
|
|
30
|
-
*/
|
|
31
|
-
eslint(configFile: string): Promise<undefined>
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Run {@link https://eslint.org/ _ESlint_} over the input source files..
|
|
35
|
-
*
|
|
36
|
-
* @param options {@link ESLintOptions | Options} to pass to _ESLint_
|
|
37
|
-
*/
|
|
38
|
-
eslint(options: ESLintOptions): Promise<undefined>
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
installForking('eslint', requireResolve(__fileurl, './eslint/runner'))
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import { diffJson } from 'diff'
|
|
2
|
-
import RealMocha from 'mocha' // Mocha types pollute the global scope!
|
|
3
|
-
|
|
4
|
-
import { $blu, $grn, $gry, $ms, $red, $wht, $ylw, ERROR, NOTICE, WARN } from '../../log'
|
|
5
|
-
|
|
6
|
-
import type { Logger } from '../../log'
|
|
7
|
-
import type { AssertionError } from 'node:assert'
|
|
8
|
-
|
|
9
|
-
const _pending = '\u22EF' // middle ellipsis
|
|
10
|
-
const _success = '\u2714' // heavy check mark
|
|
11
|
-
const _failure = '\u2718' // heavy ballot x
|
|
12
|
-
const _details = '\u21B3' // downwards arrow with tip rightwards
|
|
13
|
-
|
|
14
|
-
/* ========================================================================== *
|
|
15
|
-
* LOGGER / REPORTER *
|
|
16
|
-
* ========================================================================== */
|
|
17
|
-
|
|
18
|
-
/** Symbol to inject `Logger` in reporter options */
|
|
19
|
-
export const logSymbol = Symbol()
|
|
20
|
-
|
|
21
|
-
export class PlugReporter extends RealMocha.reporters.Base {
|
|
22
|
-
constructor(runner: RealMocha.Runner, options: RealMocha.MochaOptions) {
|
|
23
|
-
super(runner, options)
|
|
24
|
-
|
|
25
|
-
const showDiff = !! options.diff
|
|
26
|
-
const log = options.reporterOptions[logSymbol] as Logger
|
|
27
|
-
const failures: RealMocha.Test[] = []
|
|
28
|
-
const rootSuite = runner.suite
|
|
29
|
-
let slow = 0
|
|
30
|
-
|
|
31
|
-
// Enter a suite (increase indent)
|
|
32
|
-
runner.on('suite', (suite) => {
|
|
33
|
-
if (suite === rootSuite) return
|
|
34
|
-
log.notice('')
|
|
35
|
-
log.enter(NOTICE, `${$wht(suite.title)}`)
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
// Leave a suite (decrease indent)
|
|
39
|
-
runner.on('suite end', () => {
|
|
40
|
-
log.leave()
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
runner.on('fail', (test) => {
|
|
44
|
-
// Hooks fail here (not on "hook end")
|
|
45
|
-
if (test.type as any === 'hook') {
|
|
46
|
-
const number = failures.push(test)
|
|
47
|
-
const tag = $gry('[') + $red('failed') + $gry('] [') + $red(number) + $gry(']')
|
|
48
|
-
log.error(`${$red(_failure)} ${test.title} ${tag}`)
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
// Enter a test (increase indent)
|
|
53
|
-
runner.on('test', (test) => {
|
|
54
|
-
// mark that we _entered_ the test ('pending' might be called)
|
|
55
|
-
(<any> test).__plugjs__entered = true
|
|
56
|
-
log.enter(NOTICE, `${$blu(_pending)} ${test.title}`)
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
// Enter a pending test (increase indent)
|
|
60
|
-
runner.on('pending', (test) => {
|
|
61
|
-
// pending is also called when "this.skip" gets called inside the test
|
|
62
|
-
if ((<any> test).__plugjs__entered === true) return
|
|
63
|
-
log.enter(NOTICE, `${$blu(_pending)} ${test.title}`)
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
// Leave a test (handle warning/failures and decrease indent)
|
|
67
|
-
runner.on('test end', (test) => {
|
|
68
|
-
if (test.isPassed()) {
|
|
69
|
-
const duration = test.duration || 0
|
|
70
|
-
if (duration < test.slow()) {
|
|
71
|
-
log.leave(NOTICE, `${$grn(_success)} ${test.title}`)
|
|
72
|
-
} else {
|
|
73
|
-
log.leave(WARN, `${$ylw(_success)} ${test.title} ${$ms(duration, 'slow')}`)
|
|
74
|
-
slow ++
|
|
75
|
-
}
|
|
76
|
-
} else if (test.isPending()) {
|
|
77
|
-
const tag = $gry('[') + $ylw('skipped') + $gry(']')
|
|
78
|
-
log.leave(WARN, `${$ylw(_pending)} ${test.title} ${tag}`)
|
|
79
|
-
} else if (test.isFailed()) {
|
|
80
|
-
const number = failures.push(test)
|
|
81
|
-
const tag = $gry('[') + $red('failed') + $gry('] [') + $red(number) + $gry(']')
|
|
82
|
-
log.leave(ERROR, `${$red(_failure)} ${test.title} ${tag}`)
|
|
83
|
-
}
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
// Mocha finished running, dump our report
|
|
87
|
-
runner.once('end', () => {
|
|
88
|
-
// console.log('[end]')
|
|
89
|
-
try {
|
|
90
|
-
// Each failure gets dumped individually
|
|
91
|
-
for (let i = 0; i < failures.length; i ++) {
|
|
92
|
-
log.notice('')
|
|
93
|
-
const failure = failures[i]
|
|
94
|
-
|
|
95
|
-
// The titles (from the suite, up to the test)
|
|
96
|
-
const titles = [ failure.title ]
|
|
97
|
-
for (let parent = failure.parent; parent; parent = parent?.parent) {
|
|
98
|
-
if (parent.parent) titles.unshift(parent.title)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Log out our titles (one per line, indented)
|
|
102
|
-
log.error(`${$gry('Failure [')}${$red(i + 1)}${$gry(']')}`)
|
|
103
|
-
titles.forEach((title, indent) => {
|
|
104
|
-
log.error(` ${''.padStart(indent * 4)}${$gry(_details)} ${$wht(title)}`)
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
// If we have an error, luckily this is an `Error` instance
|
|
108
|
-
if (failure.err) {
|
|
109
|
-
const message = `${failure.err}` // this is the message, can be multiple lines
|
|
110
|
-
const messageOrStack = failure.err.stack || `${failure.err}` // maybe a stack?
|
|
111
|
-
const messageIndex = messageOrStack.indexOf(message)
|
|
112
|
-
|
|
113
|
-
// Subtrack the message from the stack
|
|
114
|
-
const stack =
|
|
115
|
-
messageOrStack === message ? '' :
|
|
116
|
-
messageIndex < 0 ? messageOrStack :
|
|
117
|
-
messageOrStack.substring(messageIndex + message.length)
|
|
118
|
-
|
|
119
|
-
// Split and clean up stack lines
|
|
120
|
-
const stackLines = stack.split('\n')
|
|
121
|
-
.map((line) => line.trim())
|
|
122
|
-
.filter((line) => !! line)
|
|
123
|
-
|
|
124
|
-
// Output the message
|
|
125
|
-
log.enter(ERROR, '')
|
|
126
|
-
log.error($red(message))
|
|
127
|
-
|
|
128
|
-
// Should we diff?
|
|
129
|
-
if (showDiff && ('actual' in failure.err) && ('expected' in failure.err)) {
|
|
130
|
-
const err = failure.err as AssertionError
|
|
131
|
-
const actual =
|
|
132
|
-
err.actual === undefined ? '[undefined]' :
|
|
133
|
-
err.actual === null ? '[null]' :
|
|
134
|
-
err.actual
|
|
135
|
-
|
|
136
|
-
const expected =
|
|
137
|
-
err.expected === undefined ? '[undefined]' :
|
|
138
|
-
err.expected === null ? '[null]' :
|
|
139
|
-
err.expected
|
|
140
|
-
|
|
141
|
-
const changes = diffJson(actual as any, expected as any)
|
|
142
|
-
|
|
143
|
-
const diff = changes.map((change): string => {
|
|
144
|
-
if (change.removed) return $red(change.value)
|
|
145
|
-
if (change.added) return $grn(change.value)
|
|
146
|
-
return $gry(change.value)
|
|
147
|
-
}).join('')
|
|
148
|
-
|
|
149
|
-
log.enter(ERROR, `${$gry('diff')} ${$grn('expected')} ${$gry('/')} ${$red('actual')}`)
|
|
150
|
-
log.error(diff)
|
|
151
|
-
log.leave()
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// Dump our stack trace and leave
|
|
155
|
-
stackLines.forEach((line) => log.error(line))
|
|
156
|
-
log.leave()
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// If we have some statistics, then let's dump them out in pretty colors
|
|
161
|
-
if (runner.stats) {
|
|
162
|
-
log.notice('')
|
|
163
|
-
const { passes, pending, failures, duration = 0 } = runner.stats
|
|
164
|
-
const fmt = (n: number): string => n === 1 ? `${n} test` : `${n} tests`
|
|
165
|
-
if (passes) log.notice($grn(fmt(passes)), 'passing', $ms(duration))
|
|
166
|
-
if (slow) log.warn($ylw(fmt(slow)), 'slow')
|
|
167
|
-
if (pending) log.warn($ylw(fmt(pending)), 'pending')
|
|
168
|
-
if (failures) log.error($red(fmt(failures)), 'failed')
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// Done...
|
|
172
|
-
log.notice('')
|
|
173
|
-
} catch (error) {
|
|
174
|
-
log.error('Error rendering Mocha report', error)
|
|
175
|
-
}
|
|
176
|
-
})
|
|
177
|
-
}
|
|
178
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import RealMocha from 'mocha' // Mocha types pollute the global scope!
|
|
2
|
-
|
|
3
|
-
import { assert } from '../../assert'
|
|
4
|
-
import { BuildFailure } from '../../failure'
|
|
5
|
-
import { $p, $wht, NOTICE } from '../../log'
|
|
6
|
-
import { resolveFile } from '../../paths'
|
|
7
|
-
import { logSymbol, PlugReporter } from './reporter'
|
|
8
|
-
|
|
9
|
-
import type { Files } from '../../files'
|
|
10
|
-
import type { Context, PipeParameters, Plug } from '../../pipe'
|
|
11
|
-
import type { MochaOptions } from '../mocha'
|
|
12
|
-
|
|
13
|
-
/** Writes some info about the current {@link Files} being passed around. */
|
|
14
|
-
export default class Mocha implements Plug<void> {
|
|
15
|
-
constructor(...args: PipeParameters<'mocha'>)
|
|
16
|
-
constructor(private readonly _options: MochaOptions = {}) {}
|
|
17
|
-
|
|
18
|
-
async pipe(files: Files, context: Context): Promise<void> {
|
|
19
|
-
// Enter log here, so that log messages called when loading files get
|
|
20
|
-
// properly indented by our logger
|
|
21
|
-
context.log.notice('') // empty line
|
|
22
|
-
context.log.enter(NOTICE, $wht('Starting Mocha'))
|
|
23
|
-
|
|
24
|
-
// Expand our options
|
|
25
|
-
const { require, ...options } = this._options
|
|
26
|
-
|
|
27
|
-
// See if we require a setup script...
|
|
28
|
-
if (require) {
|
|
29
|
-
const requiredFile = context.resolve(require)
|
|
30
|
-
const scriptFile = resolveFile(requiredFile)
|
|
31
|
-
assert(scriptFile, `Mocha setup file ${$p(requiredFile)} not found`)
|
|
32
|
-
context.log.debug(`Importing setup script ${$p(requiredFile)}`)
|
|
33
|
-
await import(scriptFile)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Create the mocha runner
|
|
37
|
-
const mocha = new RealMocha({
|
|
38
|
-
diff: true, // by defaut enable diffs
|
|
39
|
-
reporter: PlugReporter, // default to our reporter
|
|
40
|
-
...options, // override defaults with all other options
|
|
41
|
-
reporterOptions: {
|
|
42
|
-
...options.reporterOptions,
|
|
43
|
-
[logSymbol]: context.log, // always force a log
|
|
44
|
-
},
|
|
45
|
-
allowUncaught: false, // never allow uncaught exceptions
|
|
46
|
-
delay: false, // never delay running
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
// Tell mocha about all our files
|
|
50
|
-
for (const file of files.absolutePaths()) mocha.addFile(file)
|
|
51
|
-
|
|
52
|
-
await mocha.loadFilesAsync()
|
|
53
|
-
|
|
54
|
-
// Run mocha!
|
|
55
|
-
return new Promise((resolve, reject) => {
|
|
56
|
-
try {
|
|
57
|
-
mocha.run((failures) => {
|
|
58
|
-
if (failures) reject(BuildFailure.fail())
|
|
59
|
-
resolve(undefined)
|
|
60
|
-
})
|
|
61
|
-
} catch (error) {
|
|
62
|
-
reject(error)
|
|
63
|
-
}
|
|
64
|
-
})
|
|
65
|
-
}
|
|
66
|
-
}
|
package/src/plugs/mocha.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { installForking } from '../fork'
|
|
2
|
-
import { requireResolve } from '../paths'
|
|
3
|
-
|
|
4
|
-
/** Options to construct our {@link Mocha} plug. */
|
|
5
|
-
export interface MochaOptions {
|
|
6
|
-
/** Specify the directory where coverage data will be saved */
|
|
7
|
-
coverageDir?: string,
|
|
8
|
-
/** Bail after first test failure? */
|
|
9
|
-
bail?: boolean,
|
|
10
|
-
/** Show diff on failure? */
|
|
11
|
-
diff?: boolean,
|
|
12
|
-
/** Report tests without running them? */
|
|
13
|
-
dryRun?: boolean,
|
|
14
|
-
/** Tests marked `only` fail the suite? */
|
|
15
|
-
forbidOnly?: boolean,
|
|
16
|
-
/** Pending tests fail the suite? */
|
|
17
|
-
forbidPending?: false,
|
|
18
|
-
/** Reporter name. */
|
|
19
|
-
reporter?: string
|
|
20
|
-
/** Options for the reporter */
|
|
21
|
-
reporterOptions?: Record<string, any>,
|
|
22
|
-
/** Number of times to retry failed tests. */
|
|
23
|
-
retries?: number,
|
|
24
|
-
/** Slow threshold value. */
|
|
25
|
-
slow?: number,
|
|
26
|
-
/** Setup file to import before running Mocha. */
|
|
27
|
-
require?: string,
|
|
28
|
-
/** Timeout threshold value. */
|
|
29
|
-
timeout?: number,
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
declare module '../pipe' {
|
|
33
|
-
export interface Pipe {
|
|
34
|
-
/**
|
|
35
|
-
* Run tests using {@link https://mochajs.org/ _Mocha_}.
|
|
36
|
-
*
|
|
37
|
-
* @param options Optional {@link MochaOptions | options} for _Mocha_.
|
|
38
|
-
*/
|
|
39
|
-
mocha(options?: MochaOptions): Promise<undefined>
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
installForking('mocha', requireResolve(__fileurl, './mocha/runner'))
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import ts from 'typescript' // TypeScript does NOT support ESM modules
|
|
2
|
-
|
|
3
|
-
import { resolveAbsolutePath } from '../../paths'
|
|
4
|
-
|
|
5
|
-
import type { AbsolutePath } from '../../paths'
|
|
6
|
-
|
|
7
|
-
export class TypeScriptHost
|
|
8
|
-
implements ts.CompilerHost {
|
|
9
|
-
constructor(directory: AbsolutePath)
|
|
10
|
-
constructor(private readonly _directory: AbsolutePath) {}
|
|
11
|
-
|
|
12
|
-
/* ======================================================================== */
|
|
13
|
-
|
|
14
|
-
/** Get a source file parsing one of our virtual files */
|
|
15
|
-
getSourceFile(
|
|
16
|
-
fileName: string,
|
|
17
|
-
languageVersion: ts.ScriptTarget,
|
|
18
|
-
): ts.SourceFile | undefined {
|
|
19
|
-
const code = this.readFile(fileName)
|
|
20
|
-
return code ? ts.createSourceFile(fileName, code, languageVersion) : void 0
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** Never write any files */
|
|
24
|
-
writeFile(fileName: string): void {
|
|
25
|
-
throw new Error(`Cowardly refusing to write "${fileName}"`)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** Get the default library associated with the given options */
|
|
29
|
-
getDefaultLibFileName(options: ts.CompilerOptions): string {
|
|
30
|
-
return ts.getDefaultLibFilePath(options)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** Check for filesystem case sensitivity */
|
|
34
|
-
useCaseSensitiveFileNames(): boolean {
|
|
35
|
-
return ts.sys.useCaseSensitiveFileNames
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** Check for the existence of a given file */
|
|
39
|
-
fileExists(fileName: string): boolean {
|
|
40
|
-
return ts.sys.fileExists(resolveAbsolutePath(this.getCurrentDirectory(), fileName))
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** Read the file if it exists, otherwise return undefined */
|
|
44
|
-
readFile(fileName: string): string | undefined {
|
|
45
|
-
return ts.sys.readFile(resolveAbsolutePath(this.getCurrentDirectory(), fileName))
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** Return the current working directory */
|
|
49
|
-
getCurrentDirectory(): AbsolutePath {
|
|
50
|
-
return this._directory
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** Return the canonical name for the specified file */
|
|
54
|
-
getCanonicalFileName(fileName: string): string {
|
|
55
|
-
if (ts.sys.useCaseSensitiveFileNames) return fileName
|
|
56
|
-
|
|
57
|
-
// Lifted from TypeScript sources
|
|
58
|
-
const fileNameLowerCaseRegExp = /[^\u0130\u0131\u00DFa-z0-9\\/:\-_. ]+/g
|
|
59
|
-
return fileNameLowerCaseRegExp.test(fileName) ?
|
|
60
|
-
fileName.replace(fileNameLowerCaseRegExp, (s) => s.toLowerCase()) :
|
|
61
|
-
fileName
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** Return the new line sequence used by this platform */
|
|
65
|
-
getNewLine(): string {
|
|
66
|
-
return ts.sys.newLine
|
|
67
|
-
}
|
|
68
|
-
}
|
package/src/plugs/tsc/options.ts
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import ts from 'typescript' // TypeScript does NOT support ESM modules
|
|
2
|
-
|
|
3
|
-
import { getAbsoluteParent, resolveAbsolutePath } from '../../paths'
|
|
4
|
-
import { readFile } from '../../utils/asyncfs'
|
|
5
|
-
|
|
6
|
-
import type { AbsolutePath } from '../../paths'
|
|
7
|
-
|
|
8
|
-
/* ========================================================================== */
|
|
9
|
-
|
|
10
|
-
export type CompilerOptionsAndDiagnostics = {
|
|
11
|
-
options: ts.CompilerOptions,
|
|
12
|
-
errors: readonly ts.Diagnostic[],
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/* ========================================================================== */
|
|
16
|
-
|
|
17
|
-
function mergeResults(
|
|
18
|
-
base: CompilerOptionsAndDiagnostics,
|
|
19
|
-
override: CompilerOptionsAndDiagnostics,
|
|
20
|
-
): CompilerOptionsAndDiagnostics {
|
|
21
|
-
return {
|
|
22
|
-
options: { ...base.options, ...override.options },
|
|
23
|
-
errors: [ ...base.errors, ...override.errors ],
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/* ========================================================================== */
|
|
28
|
-
|
|
29
|
-
async function loadOptions(
|
|
30
|
-
file: AbsolutePath,
|
|
31
|
-
stack: AbsolutePath[] = [ file ],
|
|
32
|
-
): Promise<CompilerOptionsAndDiagnostics> {
|
|
33
|
-
const dir = getAbsoluteParent(file)
|
|
34
|
-
|
|
35
|
-
// Load up our config file and convert is wicked JSON
|
|
36
|
-
const data = await readFile(file, 'utf-8')
|
|
37
|
-
const { config, error } = ts.parseConfigFileTextToJson(file, data)
|
|
38
|
-
if (error) return { options: {}, errors: [ error ] }
|
|
39
|
-
|
|
40
|
-
// Parse up the configuration file as options
|
|
41
|
-
const { compilerOptions = {}, extends: extendsPath } = config
|
|
42
|
-
const result = ts.convertCompilerOptionsFromJson(compilerOptions, dir, file)
|
|
43
|
-
if (result.errors.length) return result
|
|
44
|
-
|
|
45
|
-
// If we don't extend, we can return our result
|
|
46
|
-
if (!extendsPath) return result
|
|
47
|
-
|
|
48
|
-
// Resolve the name of the file this config extends
|
|
49
|
-
const ext = resolveAbsolutePath(dir, extendsPath)
|
|
50
|
-
|
|
51
|
-
// Triple check that we are not recursively importing this file
|
|
52
|
-
if (stack.includes(ext)) {
|
|
53
|
-
return { options: {}, errors: [ {
|
|
54
|
-
messageText: `Circularity detected extending from "${ext}"`,
|
|
55
|
-
category: ts.DiagnosticCategory.Error,
|
|
56
|
-
code: 18000, // copied from typescript internals...
|
|
57
|
-
file: ts.createSourceFile(file, data, ts.ScriptTarget.JSON, false, ts.ScriptKind.JSON),
|
|
58
|
-
start: undefined,
|
|
59
|
-
length: undefined,
|
|
60
|
-
} ] }
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Push our file in the stack and load recursively
|
|
64
|
-
return mergeResults(await loadOptions(ext, [ ...stack, ext ]), result)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/* ========================================================================== */
|
|
68
|
-
|
|
69
|
-
export async function getCompilerOptions(
|
|
70
|
-
file?: AbsolutePath,
|
|
71
|
-
): Promise<CompilerOptionsAndDiagnostics>
|
|
72
|
-
|
|
73
|
-
export async function getCompilerOptions(
|
|
74
|
-
file: AbsolutePath | undefined,
|
|
75
|
-
overrides: ts.CompilerOptions,
|
|
76
|
-
overridesFile: AbsolutePath,
|
|
77
|
-
overridesBasePath: AbsolutePath,
|
|
78
|
-
): Promise<CompilerOptionsAndDiagnostics>
|
|
79
|
-
|
|
80
|
-
/** Load compiler options from a JSON file, and merge in the overrides */
|
|
81
|
-
export async function getCompilerOptions(
|
|
82
|
-
file?: AbsolutePath,
|
|
83
|
-
...override: [ ts.CompilerOptions, AbsolutePath, AbsolutePath ] | []
|
|
84
|
-
): Promise<CompilerOptionsAndDiagnostics> {
|
|
85
|
-
let result: CompilerOptionsAndDiagnostics = { options: ts.getDefaultCompilerOptions(), errors: [] }
|
|
86
|
-
|
|
87
|
-
// If we have a file to parse, load it, otherwise try "tsconfig.json"
|
|
88
|
-
if (file) result = mergeResults(result, await loadOptions(file))
|
|
89
|
-
|
|
90
|
-
// If we have overrides, merge them
|
|
91
|
-
if (override.length) {
|
|
92
|
-
const [ overrides, overridesFile, overridesDir ] = override
|
|
93
|
-
const options = ts.convertCompilerOptionsFromJson(overrides, overridesDir, overridesFile)
|
|
94
|
-
delete options.options.configFilePath // remove build file name...
|
|
95
|
-
result = mergeResults(result, options)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Return all we have
|
|
99
|
-
return result
|
|
100
|
-
}
|
package/src/plugs/tsc/report.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import ts from 'typescript' // TypeScript does NOT support ESM modules
|
|
2
|
-
|
|
3
|
-
import { ERROR, NOTICE, WARN } from '../../log'
|
|
4
|
-
import { resolveAbsolutePath } from '../../paths'
|
|
5
|
-
|
|
6
|
-
import type { Report, ReportLevel, ReportRecord } from '../../log'
|
|
7
|
-
import type { AbsolutePath } from '../../paths'
|
|
8
|
-
|
|
9
|
-
function convertMessageChain(chain: ts.DiagnosticMessageChain, indent = 0): string[] {
|
|
10
|
-
const message = `${''.padStart(indent * 2)}${chain.messageText}`
|
|
11
|
-
|
|
12
|
-
if (chain.next) {
|
|
13
|
-
const next = chain.next.map((c) => convertMessageChain(c, indent + 1))
|
|
14
|
-
return [ message, ...next.flat(1) ]
|
|
15
|
-
} else {
|
|
16
|
-
return [ message ]
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function convertDiagnostics(
|
|
21
|
-
diagnostics: readonly ts.Diagnostic[],
|
|
22
|
-
directory: AbsolutePath,
|
|
23
|
-
): ReportRecord[] {
|
|
24
|
-
return diagnostics.map((diagnostic): ReportRecord => {
|
|
25
|
-
// console.log(diagnostic)
|
|
26
|
-
void directory
|
|
27
|
-
|
|
28
|
-
// Convert the `DiagnosticCategory` to our level
|
|
29
|
-
let level: ReportLevel
|
|
30
|
-
switch (diagnostic.category) {
|
|
31
|
-
case ts.DiagnosticCategory.Error: level = ERROR; break
|
|
32
|
-
case ts.DiagnosticCategory.Warning: level = WARN; break
|
|
33
|
-
default: level = NOTICE
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Convert the `messageText` to a string
|
|
37
|
-
let message: string | string[]
|
|
38
|
-
if (typeof diagnostic.messageText === 'string') {
|
|
39
|
-
message = diagnostic.messageText
|
|
40
|
-
} else {
|
|
41
|
-
message = convertMessageChain(diagnostic.messageText)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Simple variables
|
|
45
|
-
const tags = `TS${diagnostic.code}`
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (diagnostic.file) {
|
|
49
|
-
const { file: sourceFile, start, length } = diagnostic
|
|
50
|
-
const file = resolveAbsolutePath(directory, sourceFile.fileName)
|
|
51
|
-
const source = sourceFile.getFullText()
|
|
52
|
-
|
|
53
|
-
if (start !== undefined) {
|
|
54
|
-
const position = sourceFile.getLineAndCharacterOfPosition(start)
|
|
55
|
-
let { line, character: column } = position
|
|
56
|
-
column += 1
|
|
57
|
-
line += 1
|
|
58
|
-
|
|
59
|
-
return { level, message, tags, file, source, line, column, length }
|
|
60
|
-
} else {
|
|
61
|
-
return { level, message, tags, file, source }
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
return { level, message, tags }
|
|
65
|
-
}
|
|
66
|
-
})
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** Update a report, adding records from an array of {@link ts.Diagnostic} */
|
|
70
|
-
export function updateReport(
|
|
71
|
-
report: Report,
|
|
72
|
-
diagnostics: readonly ts.Diagnostic[],
|
|
73
|
-
directory: AbsolutePath,
|
|
74
|
-
): void {
|
|
75
|
-
const records = convertDiagnostics(diagnostics, directory)
|
|
76
|
-
report.add(...records)
|
|
77
|
-
}
|