-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: allow cypress config.port to override devServer.port for proxying assets #27677
Changes from 1 commit
f82fdf0
4c54f20
e90de0e
f842e3f
8e03114
c30ce10
ee912fa
ed303ba
fbd86e1
0bda09b
837a19c
078319e
37dd857
b6f8794
c697b80
b141c20
da36aa5
5b621de
8322f14
35523a2
3bacf34
8a60770
3a441c5
9a0481f
ca7bad2
0a0eebd
568e2a1
ee0fbd9
181b27c
e684546
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ export function makeCypressWebpackConfig ( | |
const { | ||
devServerConfig: { | ||
cypressConfig: { | ||
port, | ||
projectRoot, | ||
devServerPublicPathRoute, | ||
supportFile, | ||
|
@@ -43,6 +44,8 @@ export function makeCypressWebpackConfig ( | |
}, | ||
} = config | ||
|
||
const webpackDevServerPort = port ?? undefined | ||
|
||
debug(`Using HtmlWebpackPlugin version ${htmlWebpackPluginVersion} from ${htmlWebpackPluginImportPath}`) | ||
|
||
const optimization: Record<string, any> = { | ||
|
@@ -106,6 +109,7 @@ export function makeCypressWebpackConfig ( | |
return { | ||
...finalConfig, | ||
devServer: { | ||
port: webpackDevServerPort, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Types problem without coercing to undefined |
||
client: { | ||
overlay: false, | ||
}, | ||
|
@@ -117,6 +121,7 @@ export function makeCypressWebpackConfig ( | |
return { | ||
...finalConfig, | ||
devServer: { | ||
port: webpackDevServerPort, | ||
overlay: false, | ||
}, | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,6 +240,11 @@ export class ProjectLifecycleManager { | |
|
||
const devServerOptions = await this.ctx._apis.projectApi.getDevServer().start({ specs: this.ctx.project.specs, config: finalConfig }) | ||
|
||
// if we received a cypressConfig.port we want to null it out | ||
// because we propagated it into the devServer.port and it is | ||
// later set as baseUrl which cypress is launched into | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May be worth adding a link to the issue that explain this |
||
finalConfig.port = null | ||
|
||
span?.end() | ||
|
||
if (!devServerOptions?.port) { | ||
|
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import Fixtures from './fixtures' | ||
import _ from 'lodash' | ||
import stripAnsi from 'strip-ansi' | ||
|
||
export const e2ePath = Fixtures.projectPath('e2e') | ||
|
||
|
@@ -114,7 +115,7 @@ export const normalizeStdout = function (str: string, options: any = {}) { | |
|
||
// remove all of the dynamic parts of stdout | ||
// to normalize against what we expected | ||
str = str | ||
str = stripAnsi(str) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How come we need to change this to stripAnsi here |
||
// /Users/jane/........../ -> //foo/bar/.projects/ | ||
// (Required when paths are printed outside of our own formatting) | ||
.split(pathUpToProjectName).join('/foo/bar/.projects') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import viteConfig from './cypress-vite.config' | ||
|
||
const port = 9999 | ||
|
||
viteConfig.port = port | ||
viteConfig.env = { | ||
PORT_CHECK: port, | ||
} | ||
|
||
export default viteConfig |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import cypressWebpackConfig from './cypress-webpack.config' | ||
|
||
const port = 9999 | ||
|
||
cypressWebpackConfig.port = port | ||
cypressWebpackConfig.env = { | ||
PORT_CHECK: port, | ||
} | ||
|
||
export default cypressWebpackConfig |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const portCheck = Cypress.env('PORT_CHECK') | ||
|
||
it('ensures we have launched at the overriden port', () => { | ||
expect(portCheck).to.be.a('number') | ||
expect(portCheck).to.be.oneOf([8888, 9999]) | ||
|
||
expect(window.location.host).to.eq(`localhost:${portCheck}`) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could just be
port
- ifport
is provided, it's a number, otherwise it'll be undefined. No need for thevitePort
variableThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it’s needed because of types. Cypress provided types are number or null. Vite is number or undefined. Switch it and it’ll yell at you.