Skip to content

Commit

Permalink
fix(webpack-dev-server): remove output.publicPath from webpack-dev-se…
Browse files Browse the repository at this point in the history
…rver (#15839)

* fix: remove publicPath in react-scripts if it is present

* fix: remove publicPath in react-scripts if it is present

* fix: remove publicPath in webpack-dev-server regardless

* fix: add root path

* chore: revert

* fix: remove user base path

* remove unused function

* test: add unit test for make webpack config

* chore: make purpose for fake url more clear

* do not include local filesystem path in snapshot
  • Loading branch information
lmiller1990 committed Apr 9, 2021
1 parent 726120d commit 8e894a0
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
1 change: 1 addition & 0 deletions npm/react/examples/react-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"react-dom": "17.0.1",
"react-scripts": "4.0.2"
},
"homepage": "/fake-to-avoid-regression-https://github.com/cypress-io/cypress/issues/15811",
"browserslist": {
"production": [
">0.2%",
Expand Down
17 changes: 17 additions & 0 deletions npm/webpack-dev-server/__snapshots__/makeWebpackConfig.spec.ts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
exports['makeWebpackConfig ignores userland webpack `output.publicPath` 1'] = {
"output": {
"publicPath": "/test-public-path/",
"filename": "[name].js"
},
"mode": "development",
"optimization": {
"splitChunks": {
"chunks": "all"
}
},
"plugins": [
"HtmlWebpackPlugin",
"CypressCTOptionsPlugin",
"LazyCompilePlugin"
]
}
1 change: 1 addition & 0 deletions npm/webpack-dev-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@types/webpack-dev-server": "^3.11.1",
"chai": "^4.2.0",
"mocha": "^8.1.3",
"snap-shot-it": "7.9.3",
"speed-measure-webpack-plugin": "1.4.2",
"typescript": "^4.2.3",
"webpack": "^4.44.2",
Expand Down
6 changes: 1 addition & 5 deletions npm/webpack-dev-server/src/makeWebpackConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ interface MakeWebpackConfigOptions extends CypressCTOptionsPluginOptions, UserWe
isOpenMode: boolean
}

const mergePublicPath = (baseValue = '/', userValue = '/') => {
return path.join(baseValue, userValue, '/')
}

function getLazyCompilationWebpackConfig (options: MakeWebpackConfigOptions): webpack.Configuration {
if (options.disableLazyCompilation || !options.isOpenMode) {
return {}
Expand All @@ -53,7 +49,7 @@ export async function makeWebpackConfig (userWebpackConfig: webpack.Configuratio

const entry = path.resolve(__dirname, './browser.js')

const publicPath = mergePublicPath(devServerPublicPathRoute, userWebpackConfig?.output?.publicPath)
const publicPath = path.join(devServerPublicPathRoute, '/')

const dynamicWebpackConfig = {
output: {
Expand Down
31 changes: 31 additions & 0 deletions npm/webpack-dev-server/test/unit/makeWebpackConfig.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { expect } from 'chai'
import snapshot from 'snap-shot-it'
import { makeWebpackConfig } from '../../src/makeWebpackConfig'

describe('makeWebpackConfig', () => {
it('ignores userland webpack `output.publicPath`', async () => {
const actual = await makeWebpackConfig({
output: {
publicPath: '/this-will-be-ignored',
},
}, {
devServerPublicPathRoute: '/test-public-path',
isOpenMode: true,
supportFile: '/support.js',
projectRoot: '.',
files: [],
})

// plugins contain circular deps which cannot be serialized in a snapshot.
// instead just compare the name and order of the plugins.
// @ts-expect-error
actual.plugins = actual.plugins.map((p) => p.constructor.name)

// these will include paths from the user's local file system, so we should not include them the snapshot
delete actual.output.path
delete actual.entry

expect(actual.output.publicPath).to.eq('/test-public-path/')
snapshot(actual)
})
})

4 comments on commit 8e894a0

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 8e894a0 Apr 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/7.0.2/circle-develop-8e894a0fdb899be8dd8993319c9297ea73c10321/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 8e894a0 Apr 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/7.0.2/appveyor-develop-8e894a0fdb899be8dd8993319c9297ea73c10321/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 8e894a0 Apr 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/7.0.2/appveyor-develop-8e894a0fdb899be8dd8993319c9297ea73c10321/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 8e894a0 Apr 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/7.0.2/circle-develop-8e894a0fdb899be8dd8993319c9297ea73c10321/cypress.tgz

Please sign in to comment.