Files
cypress/npm/webpack-preprocessor/scripts/test-webpack-5.js
Zach Bloomquist d01932bf75 fix: retry on EMFILE always, lint sync FS calls (#22175)
* fix: use graceful-fs always, warn in development on sync calls

* skip prop linting in some dirs

* eslint rules

* use AST-based lint rule instead

* comment

* ignore existsSync

* run without nextTick

* remove dev warning code

* fix order

* register TS first

* fix tests

* fix test

* cover new call site

* fix new test
2022-06-16 14:35:31 +10:00

63 lines
2.0 KiB
JavaScript

const execa = require('execa')
const path = require('path')
const pkg = require('../package.json')
const fs = require('fs')
const pkgJsonPath = path.join(__dirname, '..', 'package.json')
/**
* This file installs Webpack 5 and runs the unit and e2e tests for the preprocessor.
* We read package.json, update the webpack version, then re-run yarn install.
* After it finishes, pass or fail,
* we revert the package.json back to the original state.
*
* The tests for the example projects (inside of examples) run with Webpack 4.
* This ensures we have some coverage for both versions.
*/
const main = async () => {
const originalPkg = JSON.stringify(pkg, null, 2)
const install = () => execa('yarn', ['install', '--ignore-scripts'], { stdio: 'inherit' })
const resetPkg = async () => {
fs.writeFileSync(pkgJsonPath, originalPkg, 'utf8')
await install()
}
const checkExit = async ({ exitCode, step }) => {
if (typeof exitCode !== 'number') {
// eslint-disable-next-line no-console
console.error(`${step} finished with missing exit code from execa (received ${exitCode})`)
}
if (step === 'e2e' || (step === 'unit' && exitCode !== 0)) {
await resetPkg()
process.exit(exitCode)
}
}
pkg.dependencies['webpack'] = '^5.39.0'
delete pkg.devDependencies['@types/webpack']
delete pkg.devDependencies['webpack']
// eslint-disable-next-line no-console
console.log('[@cypress/webpack-preprocessor]: updating package.json...')
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkg, null, 2))
// eslint-disable-next-line no-console
console.log('[@cypress/webpack-preprocessor]: install dependencies...')
await install()
const unit = await execa('yarn', ['test-unit'], { stdio: 'inherit' })
await checkExit({ exitCode: unit.exitCode, step: 'unit' })
const e2e = await execa('yarn', ['test-e2e'], { stdio: 'inherit' })
await checkExit({ exitCode: e2e.exitCode, step: 'e2e' })
}
// execute main function if called from command line
if (require.main === module) {
main()
}