Skip to content

Commit a8143a8

Browse files
author
Barthélémy Ledoux
committed
Merge branch 'master' into develop
2 parents f4fee90 + 8f5308f commit a8143a8

File tree

6 files changed

+84
-6
lines changed

6 files changed

+84
-6
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* This file is intended to test the new normalized signature
3+
* of devServers. To make the test shorter we only test
4+
* the smkoke test here
5+
*/
6+
7+
const path = require('path')
8+
const { devServer, defineDevServerConfig } = require('../../dist')
9+
10+
module.exports = (on, config) => {
11+
on('dev-server:start', async (options) => {
12+
return devServer(
13+
options,
14+
defineDevServerConfig({
15+
configFile: path.resolve(__dirname, '..', '..', 'vite.config.ts'),
16+
}),
17+
)
18+
})
19+
20+
config.testFiles = '**/smoke.spec.ts'
21+
22+
return config
23+
}

npm/vite-dev-server/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"build-prod": "tsc",
99
"cy:open": "node ../../scripts/cypress.js open-ct --project ${PWD}",
1010
"cy:run": "node ../../scripts/cypress.js run-ct --project ${PWD}",
11-
"test": "yarn cy:run",
11+
"cy:run-signature": "yarn cy:run --config=\"{\\\"pluginsFile\\\":\\\"cypress/new-signature/plugins.js\\\"}\"",
12+
"test": "yarn cy:run && yarn cy:run-signature",
1213
"watch": "tsc -w"
1314
},
1415
"dependencies": {

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { debug as debugFn } from 'debug'
2+
import { InlineConfig } from 'vite'
23
import { start as createDevServer, StartDevServerOptions } from './startServer'
34
const debug = debugFn('cypress:vite-dev-server:vite')
45

@@ -14,3 +15,13 @@ export async function startDevServer (startDevServerArgs: StartDevServerOptions)
1415

1516
return { port, close: app.httpServer!.close }
1617
}
18+
19+
export type CypressViteDevServerConfig = Omit<InlineConfig, 'base' | 'root'>
20+
21+
export function devServer (cypressDevServerConfig: Cypress.DevServerConfig, devServerConfig?: CypressViteDevServerConfig) {
22+
return startDevServer({ options: cypressDevServerConfig, viteConfig: devServerConfig })
23+
}
24+
25+
export function defineDevServerConfig (devServerConfig: CypressViteDevServerConfig) {
26+
return devServerConfig
27+
}

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { debug as debugFn } from 'debug'
22
import { AddressInfo } from 'net'
33
import { Server } from 'http'
4-
import { start as createDevServer, StartDevServer } from './startServer'
4+
import { start as createDevServer, StartDevServer, WebpackConfigurationWithDevServer } from './startServer'
55
import { webpackDevServerFacts } from './webpackDevServerFacts'
66

77
const debug = debugFn('cypress:webpack-dev-server:webpack')
@@ -56,3 +56,22 @@ export async function startDevServer (startDevServerArgs: StartDevServer, exitPr
5656
reject(webpackDevServerFacts.unsupported())
5757
})
5858
}
59+
60+
export interface CypressWebpackDevServerConfig{
61+
/* support passing a path to the user's webpack config */
62+
webpackConfig?: WebpackConfigurationWithDevServer
63+
/* base html template to render in AUT */
64+
template?: string
65+
}
66+
67+
export function devServer (cypressDevServerConfig: Cypress.DevServerConfig, devServerConfig?: CypressWebpackDevServerConfig) {
68+
return startDevServer({
69+
options: cypressDevServerConfig,
70+
webpackConfig: devServerConfig?.webpackConfig,
71+
template: devServerConfig?.template,
72+
})
73+
}
74+
75+
export function defineDevServerConfig (devServerConfig: CypressWebpackDevServerConfig) {
76+
return devServerConfig
77+
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ import { webpackDevServerFacts } from './webpackDevServerFacts'
77
export interface StartDevServer extends UserWebpackDevServerOptions {
88
/* this is the Cypress dev server configuration object */
99
options: Cypress.DevServerConfig
10-
/* support passing a path to the user's webpack config */
11-
webpackConfig?: Record<string, any>
10+
/* Base webpack config object used for loading component testing */
11+
webpackConfig?: WebpackConfigurationWithDevServer
1212
/* base html template to render in AUT */
1313
template?: string
1414
}
1515

16+
export interface WebpackConfigurationWithDevServer extends webpack.Configuration {
17+
devServer?: WebpackDevServer.Configuration
18+
}
19+
1620
const debug = Debug('cypress:webpack-dev-server:start')
1721

1822
export async function start ({ webpackConfig: userWebpackConfig, template, options, ...userOptions }: StartDevServer, exitProcess = process.exit): Promise<WebpackDevServer> {
@@ -49,7 +53,7 @@ export async function start ({ webpackConfig: userWebpackConfig, template, optio
4953

5054
debug('starting webpack dev server')
5155
let webpackDevServerConfig: WebpackDevServer.Configuration = {
52-
...userWebpackConfig?.devServer,
56+
...(userWebpackConfig?.devServer || {}),
5357
hot: false,
5458
}
5559

npm/webpack-dev-server/test/e2e.spec.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import http from 'http'
66
import fs from 'fs'
77
import { webpackDevServerFacts } from '../src/webpackDevServerFacts'
88

9-
import { startDevServer } from '../'
9+
import { defineDevServerConfig, devServer, startDevServer } from '../'
1010

1111
const requestSpecFile = (port: number) => {
1212
return new Promise((res) => {
@@ -155,4 +155,24 @@ describe('#startDevServer', () => {
155155
close(() => res())
156156
})
157157
})
158+
159+
it('accepts the devServer signature', async function () {
160+
const devServerEvents = new EventEmitter()
161+
const { port, close } = await devServer(
162+
{
163+
config,
164+
specs,
165+
devServerEvents,
166+
},
167+
defineDevServerConfig({ webpackConfig }),
168+
)
169+
170+
const response = await requestSpecFile(port as number)
171+
172+
expect(response).to.eq('const foo = () => {}\n')
173+
174+
return new Promise((res) => {
175+
close(() => res())
176+
})
177+
})
158178
})

0 commit comments

Comments
 (0)