mirror of
https://github.com/cypress-io/cypress.git
synced 2026-01-23 23:49:05 -06:00
Co-authored-by: Lachlan Miller <lachlan.miller.1990@outlook.com> Co-authored-by: Zach Bloomquist <git@chary.us> Co-authored-by: Tyler Biethman <tbiethman@users.noreply.github.com> Co-authored-by: Matt Henkes <mjhenkes@gmail.com> Co-authored-by: Chris Breiding <chrisbreiding@users.noreply.github.com> Co-authored-by: Matt Schile <mschile@cypress.io> Co-authored-by: Mark Noonan <mark@cypress.io> Co-authored-by: Zachary Williams <ZachJW34@gmail.com> Co-authored-by: Ben M <benm@cypress.io> Co-authored-by: Zachary Williams <zachjw34@gmail.com> Co-authored-by: astone123 <adams@cypress.io> Co-authored-by: Bill Glesias <bglesias@gmail.com> Co-authored-by: Emily Rohrbough <emilyrohrbough@yahoo.com> Co-authored-by: Emily Rohrbough <emilyrohrbough@users.noreply.github.com> Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net> Co-authored-by: Adam Stone <adams@cypress.io> Co-authored-by: Blue F <blue@cypress.io> Co-authored-by: GitStart <1501599+gitstart@users.noreply.github.com> Co-authored-by: Mike Plummer <mike-plummer@users.noreply.github.com> Co-authored-by: Jordan <jordan@jpdesigning.com> Co-authored-by: Sam Goodger <turbo@tailz.dev> Co-authored-by: Colum Ferry <cferry09@gmail.com> Co-authored-by: Stokes Player <stokes@cypress.io> Co-authored-by: Vilhelm Melkstam <vilhelm.melkstam@gmail.com> Co-authored-by: amehta265 <65267668+amehta265@users.noreply.github.com>
89 lines
3.1 KiB
TypeScript
89 lines
3.1 KiB
TypeScript
import * as Fixtures from '@tooling/system-tests'
|
|
import * as FixturesScaffold from '@tooling/system-tests/lib/dep-installer'
|
|
import type { fixtureDirs } from '@tooling/system-tests'
|
|
import { expect } from 'chai'
|
|
import path from 'path'
|
|
import fs from 'fs'
|
|
|
|
import { sourceDefaultWebpackDependencies } from '../src/helpers/sourceRelativeWebpackModules'
|
|
import { WebpackDevServerConfig } from '../src/devServer'
|
|
import './support'
|
|
|
|
type ProjectDirs = typeof fixtureDirs
|
|
|
|
const CY_ROOT = path.join(__dirname, '..', '..', '..')
|
|
|
|
const WEBPACK_REACT: Partial<Record<ProjectDirs[number], {
|
|
webpack: number
|
|
webpackDevServer: number
|
|
htmlWebpackPlugin: number
|
|
}>> = {
|
|
'webpack4_wds3-react': {
|
|
webpack: 4,
|
|
webpackDevServer: 3,
|
|
htmlWebpackPlugin: 4,
|
|
},
|
|
'webpack4_wds4-react': {
|
|
webpack: 4,
|
|
webpackDevServer: 4,
|
|
htmlWebpackPlugin: 4,
|
|
},
|
|
'webpack5_wds3-react': {
|
|
webpack: 5,
|
|
webpackDevServer: 3,
|
|
htmlWebpackPlugin: 5,
|
|
},
|
|
'webpack5_wds4-react': {
|
|
webpack: 5,
|
|
webpackDevServer: 4,
|
|
htmlWebpackPlugin: 5,
|
|
},
|
|
}
|
|
|
|
async function sourceModulesForProject (fixture: ProjectDirs[number]) {
|
|
Fixtures.remove()
|
|
const projectRoot = await Fixtures.scaffoldProject(fixture)
|
|
|
|
await FixturesScaffold.scaffoldProjectNodeModules({ project: fixture })
|
|
|
|
const result = sourceDefaultWebpackDependencies({
|
|
cypressConfig: {
|
|
projectRoot,
|
|
},
|
|
} as WebpackDevServerConfig)
|
|
|
|
return { result, projectRoot }
|
|
}
|
|
|
|
// Ensures that we are properly sourcing the webpacks from the node_modules in the given project,
|
|
// rather than from the node_modules in the project root
|
|
describe('sourceDefaultWebpackDependencies', () => {
|
|
for (const [fixture, versionsToMatch] of Object.entries(WEBPACK_REACT)) {
|
|
describe(fixture, () => {
|
|
it(`sources the correct webpack versions for ${fixture}`, async () => {
|
|
const { result, projectRoot } = await sourceModulesForProject(fixture as ProjectDirs[number])
|
|
const projectNodeModules = fs.realpathSync(path.resolve(projectRoot, 'node_modules'))
|
|
|
|
expect(result.webpack.majorVersion).to.eq(versionsToMatch.webpack, 'match webpackVersion')
|
|
expect(result.webpackDevServer.majorVersion).to.eq(versionsToMatch.webpackDevServer, 'match webpackDevServerVersion')
|
|
expect(result.webpack.importPath).to.include(projectNodeModules)
|
|
expect(result.webpackDevServer.importPath).to.include(projectNodeModules)
|
|
})
|
|
})
|
|
}
|
|
|
|
it('sources the webpack path from the correct location once imported', async () => {
|
|
expect(require.resolve('webpack')).to.include(CY_ROOT)
|
|
const localWebpack = require('webpack')
|
|
|
|
const { result, projectRoot } = await sourceModulesForProject('webpack4_wds3-react')
|
|
const projectNodeModules = fs.realpathSync(path.resolve(projectRoot, 'node_modules'))
|
|
|
|
expect(localWebpack).not.to.eq(result.webpack.module)
|
|
expect(result.webpack.importPath).to.include(projectNodeModules)
|
|
expect(result.webpack.majorVersion).to.eq(4, 'match webpackVersion')
|
|
expect(require('webpack')).to.eq(result.webpack.module)
|
|
expect(require.resolve('webpack')).to.include(projectNodeModules)
|
|
})
|
|
})
|