-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexec.ts
63 lines (59 loc) · 1.53 KB
/
exec.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
import {
IConfiguration,
loadConfiguration,
runCucumber,
} from '@cucumber/cucumber/api'
import { glob } from 'glob'
import { join } from 'path'
import { PassThrough } from 'stream'
import * as streamToString from 'stream-to-string'
import { ThemeStyles } from '../src/theme'
type FormatOptions = {
colorsEnabled: boolean
theme: Partial<ThemeStyles>
}
export const run = async (
fileName: string,
cucumberOptions: Partial<IConfiguration> = {},
formatOptions: Partial<FormatOptions> = {},
throws = false
): Promise<string> => {
// clear require cache for support code
const matches = await glob('features/support/*', {
absolute: true,
cwd: __dirname,
})
matches.forEach((match) => delete require.cache[match])
const configuration: Partial<IConfiguration> = {
...cucumberOptions,
format: [join(__dirname, '..', 'src')],
formatOptions: {
colorsEnabled: false,
theme: {},
...formatOptions,
},
paths: [join('test', 'features', fileName)],
publishQuiet: true,
require: [join(__dirname, 'features')],
}
const { runConfiguration } = await loadConfiguration({
provided: configuration,
})
const stdout = new PassThrough()
const stderr = new PassThrough()
try {
await runCucumber(runConfiguration, {
cwd: join(__dirname, '..', '..'),
stdout,
stderr,
})
} catch (ex) {
if (throws) {
throw ex
}
}
stdout.end()
stderr.end()
const result = await streamToString(stdout)
return result.replace(/\d+m\d+\.\d+s/g, '0m00.000s')
}