Skip to content

Commit 3a8797e

Browse files
authored
fix: wire up scaffolded indexHtml to dev servers (#20453)
* fix: wire up scaffolded indexHtml to dev servers * fix vite tests * update vuecli-5, fix system tests * fix vite build error and launchpad test * remove only * address comments, remove gitignores * remove only
1 parent 801603d commit 3a8797e

File tree

111 files changed

+20985
-687
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+20985
-687
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,21 @@ packages/data-context/test/unit/codegen/files
6868
# community templates we test against, no need to lint
6969
system-tests/projects/create-react-app-configured/**/*
7070
system-tests/projects/create-react-app-unconfigured/**/*
71+
system-tests/projects/create-react-app-custom-index-html
7172

7273
system-tests/projects/vueclivue2-unconfigured/**/*
7374
system-tests/projects/vueclivue2-configured/**/*
7475

7576
system-tests/projects/vueclivue3-unconfigured/**/*
7677
system-tests/projects/vueclivue3-configured/**/*
78+
system-tests/projects/vueclivue3-custom-index-html
7779

7880
system-tests/projects/vuecli5vue3-unconfigured/**/*
7981
system-tests/projects/vuecli5vue3-configured/**/*
8082

8183
system-tests/projects/vue3-vite-ts-unconfigured/**/*
8284
system-tests/projects/vue3-vite-ts-configured/**/*
85+
system-tests/projects/vue3-vite-ts-custom-index-html
8386

8487
system-tests/projects/nextjs-unconfigured/**/*
8588
system-tests/projects/nextjs-configured/**/*

npm/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"watch": "yarn build --watch --watch.exclude ./dist/**/*"
2121
},
2222
"dependencies": {
23-
"@cypress/mount-utils": "0.0.0-development",
23+
"@cypress/mount-utils": "*",
2424
"debug": "^4.3.2",
2525
"find-webpack": "2.2.1",
2626
"find-yarn-workspace-root": "2.0.0"

npm/react/plugins/babel/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ declare namespace CypressBabelDevServer {
1313
* Path to an index.html file that will serve as the template in
1414
* which your components will be rendered.
1515
*/
16-
indexHtml?: string
16+
indexHtmlFile?: string
1717
}
1818

1919
/**

npm/react/plugins/babel/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function devServer (cypressDevServerConfig, devServerConfig = {}) {
66
return startDevServer({
77
options: cypressDevServerConfig,
88
webpackConfig: getBabelWebpackConfig(cypressDevServerConfig.config, devServerConfig),
9-
indexHtml: devServerConfig.indexHtml,
9+
indexHtmlFile: devServerConfig.indexHtmlFile,
1010
})
1111
}
1212

npm/react/plugins/craco/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ declare namespace CypressCracoDevServer {
99
* Path to an index.html file that will serve as the template in
1010
* which your components will be rendered.
1111
*/
12-
indexHtml?: string
12+
indexHtmlFile?: string
1313
}
1414

1515
/**

npm/react/plugins/craco/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ const { startDevServer } = require('@cypress/webpack-dev-server')
22
const { createWebpackDevConfig } = require('@craco/craco')
33
const { getLegacyDevServer } = require('../utils/legacy-setup-dev-server')
44

5-
function devServer (cypressDevServerConfig, cracoConfig, indexHtml) {
5+
function devServer (cypressDevServerConfig, cracoConfig, indexHtmlFile) {
66
process.env.FAST_REFRESH = 'false'
77

88
return startDevServer({
99
options: cypressDevServerConfig,
1010
webpackConfig: createWebpackDevConfig(cracoConfig),
11-
indexHtml,
11+
indexHtmlFile,
1212
})
1313
}
1414

@@ -21,6 +21,6 @@ module.exports = getLegacyDevServer(devServer, (config) => {
2121

2222
// New signature
2323
// - Note that this also includes a change to the second argument!
24-
module.exports.devServer = (cypressDevServerConfig, { cracoConfig, indexHtml }) => {
25-
return devServer(cypressDevServerConfig, cracoConfig, indexHtml)
24+
module.exports.devServer = (cypressDevServerConfig, { cracoConfig, indexHtmlFile }) => {
25+
return devServer(cypressDevServerConfig, cracoConfig, indexHtmlFile)
2626
}

npm/react/plugins/load-webpack/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ declare namespace CypressWebpackDevServer {
99
* Path to an index.html file that will serve as the template in
1010
* which your components will be rendered.
1111
*/
12-
indexHtml?: string
12+
indexHtmlFile?: string
1313
}
1414

1515
/**

npm/react/plugins/load-webpack/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function normalizeWebpackPath (config, webpackConfigPath) {
1515
* **Important:** `webpackFilename` path is relative to the project root (cypress.config.{ts|js} location)
1616
* @type {(on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions, options: { webpackFilename: string }) => Cypress.PluginConfigOptions}
1717
*/
18-
function devServer (cypressDevServerConfig, { webpackFilename, indexHtml }) {
18+
function devServer (cypressDevServerConfig, { webpackFilename, indexHtmlFile }) {
1919
const webpackConfig = tryLoadWebpackConfig(normalizeWebpackPath(cypressDevServerConfig.config, webpackFilename))
2020

2121
if (!webpackConfig) {
@@ -25,7 +25,7 @@ function devServer (cypressDevServerConfig, { webpackFilename, indexHtml }) {
2525
return startDevServer({
2626
options: cypressDevServerConfig,
2727
webpackConfig,
28-
indexHtml,
28+
indexHtmlFile,
2929
})
3030
}
3131

npm/react/plugins/next/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ declare namespace CypressNextDevServer {
44
* Path to an index.html file that will serve as the template in
55
* which your components will be rendered.
66
*/
7-
indexHtml?: string
7+
indexHtmlFile?: string
88
}
99

1010
/**

npm/react/plugins/next/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const path = require('path')
22
const findNextWebpackConfig = require('./findNextWebpackConfig')
33
const { getLegacyDevServer } = require('../utils/legacy-setup-dev-server')
44

5-
async function devServer (cypressDevServerConfig, { indexHtml } = {}) {
5+
async function devServer (cypressDevServerConfig, { indexHtmlFile } = {}) {
66
const webpackConfig = await findNextWebpackConfig(cypressDevServerConfig.config)
77

88
// require('webpack') now points to nextjs bundled version
@@ -11,7 +11,7 @@ async function devServer (cypressDevServerConfig, { indexHtml } = {}) {
1111
return startDevServer({
1212
options: cypressDevServerConfig,
1313
webpackConfig,
14-
indexHtml: indexHtml || path.resolve(__dirname, 'index-template.html'),
14+
indexHtmlFile: indexHtmlFile || path.resolve(__dirname, 'index-template.html'),
1515
})
1616
}
1717

npm/react/plugins/react-scripts/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ declare namespace CypressCRADevServer {
99
* Path to an index.html file that will serve as the template in
1010
* which your components will be rendered.
1111
*/
12-
indexHtml?: string
12+
indexHtmlFile?: string
1313
}
1414

1515
/**

npm/react/plugins/react-scripts/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ const { getLegacyDevServer } = require('../utils/legacy-setup-dev-server')
44

55
function devServer (cypressDevServerConfig, {
66
webpackConfigPath,
7-
indexHtml,
7+
indexHtmlFile,
88
} = {}) {
99
return startDevServer({
1010
options: cypressDevServerConfig,
1111
webpackConfig: findReactScriptsWebpackConfig(cypressDevServerConfig.config, {
1212
webpackConfigPath: webpackConfigPath || 'react-scripts/config/webpack.config',
1313
}),
14-
indexHtml,
14+
indexHtmlFile,
1515
})
1616
}
1717

npm/vite-dev-server/src/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,16 @@ export async function startDevServer (startDevServerArgs: StartDevServerOptions)
2424
return { port, close: viteDevServer.close }
2525
}
2626

27-
export type CypressViteDevServerConfig = Omit<InlineConfig, 'base' | 'root'>
27+
export type CypressViteDevServerConfig = Omit<InlineConfig, 'base' | 'root'> & {
28+
/**
29+
* Path to an index.html file that will serve as the template in
30+
* which your components will be rendered.
31+
*/
32+
indexHtmlFile?: string
33+
}
2834

2935
export function devServer (cypressDevServerConfig: Cypress.DevServerConfig, devServerConfig?: CypressViteDevServerConfig) {
30-
return startDevServer({ options: cypressDevServerConfig, viteConfig: devServerConfig })
36+
const { indexHtmlFile, ...viteConfig } = devServerConfig ?? {}
37+
38+
return startDevServer({ options: cypressDevServerConfig, viteConfig, indexHtmlFile })
3139
}

npm/vite-dev-server/src/makeCypressPlugin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const makeCypressPlugin = (
3535
devServerEvents: NodeJS.EventEmitter,
3636
specs: Spec[],
3737
namespace: string,
38-
indexHtml?: string,
38+
indexHtmlFile?: string,
3939
): Plugin => {
4040
let base = '/'
4141

@@ -46,7 +46,7 @@ export const makeCypressPlugin = (
4646
})
4747

4848
const posixSupportFilePath = supportFilePath ? convertPathToPosix(resolve(projectRoot, supportFilePath)) : undefined
49-
const posixIndexHtml = indexHtml ? convertPathToPosix(resolve(projectRoot, indexHtml)) : undefined
49+
const posixIndexHtml = indexHtmlFile ? convertPathToPosix(resolve(projectRoot, indexHtmlFile)) : undefined
5050

5151
return {
5252
name: pluginName,
@@ -55,7 +55,7 @@ export const makeCypressPlugin = (
5555
base = config.base
5656
},
5757
async transformIndexHtml () {
58-
const indexHtmlPath = indexHtml ? resolve(projectRoot, indexHtml) : resolve(__dirname, '..', 'index.html')
58+
const indexHtmlPath = indexHtmlFile ? resolve(projectRoot, indexHtmlFile) : resolve(__dirname, '..', 'index.html')
5959
const indexHtmlContent = await readFile(indexHtmlPath, { encoding: 'utf8' })
6060
// find </body> last index
6161
const endOfBody = indexHtmlContent.lastIndexOf('</body>')

npm/vite-dev-server/src/resolveServerConfig.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ export interface StartDevServerOptions {
2222
* Path to an index.html file that will serve as the template in
2323
* which your components will be rendered.
2424
*/
25-
indexHtml?: string
25+
indexHtmlFile?: string
2626
}
2727

28-
export const resolveServerConfig = async ({ viteConfig, options, indexHtml }: StartDevServerOptions): Promise<InlineConfig> => {
28+
export const resolveServerConfig = async ({ viteConfig, options, indexHtmlFile }: StartDevServerOptions): Promise<InlineConfig> => {
2929
const { projectRoot, supportFile, namespace } = options.config
3030

3131
const requiredOptions: InlineConfig = {
@@ -35,7 +35,7 @@ export const resolveServerConfig = async ({ viteConfig, options, indexHtml }: St
3535

3636
const finalConfig: InlineConfig = { ...viteConfig, ...requiredOptions }
3737

38-
finalConfig.plugins = [...(finalConfig.plugins || []), makeCypressPlugin(projectRoot, supportFile, options.devServerEvents, options.specs, options.config.namespace, indexHtml)]
38+
finalConfig.plugins = [...(finalConfig.plugins || []), makeCypressPlugin(projectRoot, supportFile, options.devServerEvents, options.specs, options.config.namespace, indexHtmlFile)]
3939

4040
// This alias is necessary to avoid a "prefixIdentifiers" issue from slots mounting
4141
// only cjs compiler-core accepts using prefixIdentifiers in slots which vue test utils use.

npm/vue/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"test:ci:ct": "node ../../scripts/run-ct-examples.js --examplesList=./examples.env"
1616
},
1717
"dependencies": {
18-
"@cypress/mount-utils": "0.0.0-development",
18+
"@cypress/mount-utils": "*",
1919
"@vue/test-utils": "^2.0.0-rc.10"
2020
},
2121
"devDependencies": {

npm/webpack-dev-server/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,15 @@ export interface CypressWebpackDevServerConfig{
6262
/* support passing a path to the user's webpack config */
6363
webpackConfig?: WebpackConfigurationWithDevServer
6464
/* base html template to render in AUT */
65+
indexHtmlFile?: string
66+
/** @deprecated base html template to render in AUT */
6567
template?: string
6668
}
6769

6870
export function devServer (cypressDevServerConfig: Cypress.DevServerConfig, devServerConfig?: CypressWebpackDevServerConfig) {
6971
return startDevServer({
7072
options: cypressDevServerConfig,
7173
webpackConfig: devServerConfig?.webpackConfig,
72-
template: devServerConfig?.template,
74+
indexHtmlFile: devServerConfig?.indexHtmlFile || devServerConfig?.template,
7375
})
7476
}

npm/webpack-dev-server/src/loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const makeImport = (file: Cypress.Cypress['spec'], filename: string, chunkName:
2525
}
2626

2727
/**
28-
* Creates a object maping a spec file to an object mapping
28+
* Creates a object mapping a spec file to an object mapping
2929
* the spec name to the result of `makeImport`.
3030
*
3131
* @returns {Record<string, ReturnType<makeImport>}

npm/webpack-dev-server/src/makeWebpackConfig.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ export interface UserWebpackDevServerOptions {
2020
interface MakeWebpackConfigOptions extends CypressCTOptionsPluginOptionsWithEmitter, UserWebpackDevServerOptions {
2121
devServerPublicPathRoute: string
2222
isOpenMode: boolean
23-
indexHtml?: string
23+
indexHtmlFile?: string
2424
}
2525

2626
const OsSeparatorRE = RegExp(`\\${path.sep}`, 'g')
2727
const posixSeparator = '/'
2828

2929
export async function makeWebpackConfig (userWebpackConfig: webpack.Configuration, options: MakeWebpackConfigOptions): Promise<webpack.Configuration> {
30-
const { projectRoot, devServerPublicPathRoute, files, supportFile, devServerEvents, indexHtml } = options
30+
const { projectRoot, devServerPublicPathRoute, files, supportFile, devServerEvents, indexHtmlFile } = options
3131

3232
debug(`User passed in webpack config with values %o`, userWebpackConfig)
3333

@@ -80,7 +80,7 @@ export async function makeWebpackConfig (userWebpackConfig: webpack.Configuratio
8080

8181
const mergedConfig = merge<webpack.Configuration>(
8282
userWebpackConfig,
83-
makeDefaultWebpackConfig(indexHtml),
83+
makeDefaultWebpackConfig(indexHtmlFile),
8484
dynamicWebpackConfig,
8585
)
8686

npm/webpack-dev-server/src/startServer.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,11 @@ import webpack from 'webpack'
33
import WebpackDevServer from 'webpack-dev-server'
44
import { makeWebpackConfig, UserWebpackDevServerOptions } from './makeWebpackConfig'
55
import { webpackDevServerFacts } from './webpackDevServerFacts'
6+
import type { CypressWebpackDevServerConfig } from '.'
67

7-
export interface StartDevServer extends UserWebpackDevServerOptions {
8+
export interface StartDevServer extends UserWebpackDevServerOptions, CypressWebpackDevServerConfig {
89
/* this is the Cypress dev server configuration object */
910
options: Cypress.DevServerConfig
10-
/* Base webpack config object used for loading component testing */
11-
webpackConfig?: WebpackConfigurationWithDevServer
12-
/* base html template to render in AUT */
13-
template?: string
14-
/* base html template to render in AUT */
15-
indexHtml?: string
16-
1711
}
1812

1913
export interface WebpackConfigurationWithDevServer extends webpack.Configuration {
@@ -22,7 +16,7 @@ export interface WebpackConfigurationWithDevServer extends webpack.Configuration
2216

2317
const debug = Debug('cypress:webpack-dev-server:start')
2418

25-
export async function start ({ webpackConfig: userWebpackConfig, indexHtml, options, ...userOptions }: StartDevServer, exitProcess = process.exit): Promise<WebpackDevServer> {
19+
export async function start ({ webpackConfig: userWebpackConfig, indexHtmlFile, options, ...userOptions }: StartDevServer, exitProcess = process.exit): Promise<WebpackDevServer> {
2620
if (!userWebpackConfig) {
2721
debug('User did not pass in any webpack configuration')
2822
}
@@ -31,7 +25,7 @@ export async function start ({ webpackConfig: userWebpackConfig, indexHtml, opti
3125

3226
const webpackConfig = await makeWebpackConfig(userWebpackConfig || {}, {
3327
files: options.specs,
34-
indexHtml,
28+
indexHtmlFile,
3529
projectRoot,
3630
devServerPublicPathRoute,
3731
devServerEvents: options.devServerEvents,

npm/webpack-dev-server/src/webpack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin')
55
* @param {string} [template] - base template to use
66
* @returns {import('webpack').Configuration}
77
*/
8-
module.exports = function makeDefaultConfig (indexHtml) {
8+
module.exports = function makeDefaultConfig (indexHtmlFile) {
99
return {
1010
mode: 'development',
1111
optimization: {
@@ -18,7 +18,7 @@ module.exports = function makeDefaultConfig (indexHtml) {
1818
path: path.resolve(__dirname, 'dist'),
1919
},
2020
plugins: [new HtmlWebpackPlugin({
21-
template: indexHtml || path.resolve(__dirname, '..', 'index-template.html'),
21+
template: indexHtmlFile || path.resolve(__dirname, '..', 'index-template.html'),
2222
})],
2323
}
2424
}

packages/data-context/src/actions/ProjectActions.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -302,20 +302,6 @@ export class ProjectActions {
302302
this.api.setPromptShown(slug)
303303
}
304304

305-
async createComponentIndexHtml (template: string) {
306-
const project = this.ctx.currentProject
307-
308-
if (!project) {
309-
throw Error(`Cannot create index.html without currentProject.`)
310-
}
311-
312-
if (this.ctx.lifecycleManager.isTestingTypeConfigured('component')) {
313-
const indexHtmlPath = path.resolve(project, 'cypress/component/support/index.html')
314-
315-
await this.ctx.fs.outputFile(indexHtmlPath, template)
316-
}
317-
}
318-
319305
setSpecs (specs: FoundSpec[]) {
320306
this.ctx.project.setSpecs(specs)
321307
}

packages/data-context/src/actions/WizardActions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,10 @@ export class WizardActions {
313313
bodyModifier,
314314
})
315315

316+
const componentIndexHtmlPath = path.join(this.projectRoot, 'cypress', 'support', 'component-index.html')
317+
316318
return this.scaffoldFile(
317-
path.join(this.projectRoot, 'cypress', 'component', 'index.html'),
319+
componentIndexHtmlPath,
318320
template,
319321
'The HTML used as the wrapper for all component tests',
320322
)

0 commit comments

Comments
 (0)