-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
hooks.ts
70 lines (61 loc) · 1.78 KB
/
hooks.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
import { After, Before, formatterHelpers, ITestCaseHookParameter } from '../../'
import fsExtra from 'fs-extra'
import path from 'path'
import { doesHaveValue } from '../../src/value_checker'
import { World } from './world'
import { warnUserAboutEnablingDeveloperMode } from './warn_user_about_enabling_developer_mode'
const projectPath = path.join(__dirname, '..', '..')
Before('@debug', function (this: World) {
this.debug = true
})
Before('@spawn or @esm', function (this: World) {
this.spawn = true
})
Before(function (
this: World,
{ gherkinDocument, pickle }: ITestCaseHookParameter
) {
const { line } = formatterHelpers.PickleParser.getPickleLocation({
gherkinDocument,
pickle,
})
this.tmpDir = path.join(
projectPath,
'tmp',
`${path.basename(pickle.uri)}_${line.toString()}`
)
fsExtra.removeSync(this.tmpDir)
const tmpDirNodeModulesPath = path.join(this.tmpDir, 'node_modules')
const tmpDirCucumberPath = path.join(
tmpDirNodeModulesPath,
'@cucumber',
'cucumber'
)
try {
fsExtra.ensureSymlinkSync(projectPath, tmpDirCucumberPath)
} catch (error) {
warnUserAboutEnablingDeveloperMode(error)
}
this.localExecutablePath = path.join(projectPath, 'bin', 'cucumber.js')
})
Before('@esm', function (this: World) {
fsExtra.writeJSONSync(path.join(this.tmpDir, 'package.json'), {
name: 'feature-test-pickle',
type: 'module',
})
})
After(async function (this: World) {
if (this.reportServer?.started) {
await this.reportServer.stop()
}
if (
doesHaveValue(this.lastRun) &&
doesHaveValue(this.lastRun.error) &&
!this.verifiedLastRunError
) {
throw new Error(
`Last run errored unexpectedly. Output:\n\n${this.lastRun.output}\n\n` +
`Error Output:\n\n${this.lastRun.errorOutput}`
)
}
})