-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
install_steps.ts
56 lines (52 loc) · 1.86 KB
/
install_steps.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
import { Given } from '../../'
import tmp from 'tmp'
import path from 'path'
import fs from 'fs'
import fsExtra from 'fs-extra'
import { World } from '../support/world'
/*
Simulates something like a global install, where the Cucumber being executed
is not the one being imported by support code
*/
Given('an invalid installation', async function (this: World) {
const projectPath = path.join(__dirname, '..', '..')
const tmpObject = tmp.dirSync({ unsafeCleanup: true })
// Symlink everything in node_modules so the fake installation has all the dependencies it needs
const projectNodeModulesPath = path.join(projectPath, 'node_modules')
const projectNodeModulesDirs = fs.readdirSync(projectNodeModulesPath)
const installationNodeModulesPath = path.join(tmpObject.name, 'node_modules')
projectNodeModulesDirs.forEach((nodeModuleDir) => {
let pathsToLink = [nodeModuleDir]
if (nodeModuleDir[0] === '@') {
const scopeNodeModuleDirs = fs.readdirSync(
path.join(projectNodeModulesPath, nodeModuleDir)
)
pathsToLink = scopeNodeModuleDirs.map((x) => path.join(nodeModuleDir, x))
}
pathsToLink.forEach((pathToLink) => {
const installationPackagePath = path.join(
installationNodeModulesPath,
pathToLink
)
const projectPackagePath = path.join(projectNodeModulesPath, pathToLink)
fsExtra.ensureSymlinkSync(projectPackagePath, installationPackagePath)
})
})
const invalidInstallationCucumberPath = path.join(
installationNodeModulesPath,
'@cucumber',
'cucumber'
)
const itemsToCopy = ['bin', 'lib', 'package.json']
itemsToCopy.forEach((item) => {
fsExtra.copySync(
path.join(projectPath, item),
path.join(invalidInstallationCucumberPath, item)
)
})
this.localExecutablePath = path.join(
invalidInstallationCucumberPath,
'bin',
'cucumber.js'
)
})