forked from cypress-io/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-deps.js
79 lines (67 loc) · 2.12 KB
/
test-deps.js
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
const execa = require('execa')
const pkg = require('./package.json')
const fs = require('fs')
/**
* This file installs dependencies that we support but don't have coverage for.
* We read package.json, update the dependency, then re-run yarn install.
* After it finishes, pass or fail,
* we revert the package.json back to the original state.
*/
const main = async () => {
const depsToTest = [
[
{
name: 'webpack-dev-server',
version: '3.11.0',
type: 'devDependencies',
},
],
[
{ name: 'webpack', version: '5.53.0', type: 'devDependencies' },
{
name: 'html-webpack-plugin',
version: '5.3.2',
type: 'devDependencies',
},
],
]
const originalPkg = JSON.stringify(pkg, null, 2)
const install = () => execa('yarn', ['install', '--ignore-scripts'], { stdio: 'inherit' })
const exit = async (exitCode) => {
fs.writeFileSync('package.json', originalPkg, 'utf8')
await install()
process.exit(exitCode)
}
for (const deps of depsToTest) {
const pkg = JSON.parse(originalPkg)
const depsInfo = JSON.stringify(deps)
deps.forEach(({ type, name, version }) => (pkg[type][name] = version))
// eslint-disable-next-line no-console
console.log('[@cypress/webpack-dev-server]: updating package.json...')
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2), 'utf8')
// eslint-disable-next-line no-console
console.log('[@cypress/webpack-dev-server]: install dependencies...')
await install()
// eslint-disable-next-line no-console
console.log(
`[@cypress/webpack-dev-server]: Testing with deps: ${depsInfo}`,
)
const { exitCode } = await execa('yarn', ['test-all'], {
stdio: 'inherit',
})
if (typeof exitCode !== 'number') {
// eslint-disable-next-line no-console
console.error(
`Testing with deps: ${depsInfo} finished with missing exit code from execa (received ${exitCode})`,
)
}
if (exitCode !== 0) {
exit(exitCode)
}
}
exit(0)
}
// execute main function if called from command line
if (require.main === module) {
main()
}