-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
hooks.ts
96 lines (85 loc) · 2.52 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
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
import { After, Before, formatterHelpers } from '../../'
import fs from 'fs'
import fsExtra from 'fs-extra'
import path from 'path'
import tmp from 'tmp'
import { doesHaveValue } from '../../src/value_checker'
import { World } from './world'
import { ITestCaseHookParameter } from '../../src/support_code_library_builder/types'
const projectPath = path.join(__dirname, '..', '..')
const projectNodeModulesPath = path.join(projectPath, 'node_modules')
const moduleNames = fs.readdirSync(projectNodeModulesPath)
Before('@debug', function(this: World) {
this.debug = true
})
Before('@spawn', 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}`
)
fsExtra.removeSync(this.tmpDir)
const tmpDirNodeModulesPath = path.join(this.tmpDir, 'node_modules')
const tmpDirCucumberPath = path.join(tmpDirNodeModulesPath, 'cucumber')
// @ts-ignore
fsExtra.createSymlinkSync(projectPath, tmpDirCucumberPath)
this.localExecutablePath = path.join(projectPath, 'bin', 'cucumber-js')
})
Before('@global-install', function(this: World) {
const tmpObject = tmp.dirSync({ unsafeCleanup: true })
const globalInstallNodeModulesPath = path.join(tmpObject.name, 'node_modules')
moduleNames.forEach(moduleName => {
const globalInstallNodeModulePath = path.join(
globalInstallNodeModulesPath,
moduleName
)
const projectNodeModulePath = path.join(
projectPath,
'node_modules',
moduleName
)
// @ts-ignore
fsExtra.createSymlinkSync(
projectNodeModulePath,
globalInstallNodeModulePath
)
})
const globalInstallCucumberPath = path.join(
globalInstallNodeModulesPath,
'cucumber'
)
const itemsToCopy = ['bin', 'lib', 'package.json']
itemsToCopy.forEach(item => {
fsExtra.copySync(
path.join(projectPath, item),
path.join(globalInstallCucumberPath, item)
)
})
this.globalExecutablePath = path.join(
globalInstallCucumberPath,
'bin',
'cucumber-js'
)
})
After(function(this: World) {
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}`
)
}
})