Skip to content

Commit

Permalink
fix(component-testing): vite server dependency refresh (#15366)
Browse files Browse the repository at this point in the history
* fix: monkey patch vite

* fix: make sure we on ly refresh once

* fix: update error display on compile error

* chore: add compatibility comment

* fix: add vite-dev-server to ci
  • Loading branch information
Barthélémy Ledoux authored Mar 9, 2021
1 parent 2fde9bb commit 59dbed9
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
13 changes: 13 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,16 @@ jobs:
name: Run tests
command: yarn workspace @cypress/webpack-dev-server test

npm-vite-dev-server:
<<: *defaults
steps:
- attach_workspace:
at: ~/
- check-conditional-ci
- run:
name: Run tests
command: yarn workspace @cypress/vite-dev-server test

npm-rollup-dev-server:
<<: *defaults
steps:
Expand Down Expand Up @@ -1751,6 +1761,9 @@ linux-workflow: &linux-workflow
- npm-webpack-dev-server:
requires:
- build
- npm-vite-dev-server:
requires:
- build
- npm-rollup-dev-server:
requires:
- build
Expand Down
19 changes: 18 additions & 1 deletion npm/vite-dev-server/index-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,24 @@
return node
}

let importsToLoad = [() => import("{{{specPath}}}")];
const specPath = "{{{specPath}}}"

let importsToLoad = [() => import(specPath).catch(e => {
// if the import failed, it might be because of dependencies
// so we try a quick refresh just in case it is
const expectedMessage = `Failed to fetch dynamically imported module: ${location.origin + specPath}`
// since vite does not work with IE we can use URLSearchParams without polyfill
var searchParams = new URLSearchParams(window.location.search);
if (e.message === expectedMessage && !searchParams.has("refresh")) {
searchParams.set('refresh', '1')
window.location.search = searchParams
} else {
throw new Error(`
**Error during compilation.**
Check the terminal log for more info
`, e)
}
})];
if ("{{{supportPath}}}") {
importsToLoad.push(() => import("{{{supportPath}}}"));
}
Expand Down
7 changes: 5 additions & 2 deletions npm/vite-dev-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"devDependencies": {
"@types/mustache": "4.1.1",
"vite": "2.0.1"
"vite": "2.0.5"
},
"peerDependencies": {
"vite": ">= 2"
Expand All @@ -34,5 +34,8 @@
"bugs": "https://github.com/cypress-io/cypress/issues/new?template=1-bug-report.md",
"publishConfig": {
"access": "public"
}
},
"ciJobs": [
"npm-vite-dev-server"
]
}
1 change: 0 additions & 1 deletion npm/vite-dev-server/src/makeCypressPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export const makeCypressPlugin = (
server.middlewares.use('/index.html', (req, res) => handleIndex(indexHtml, projectRoot, supportFilePath, req, res))
},
handleHotUpdate: () => {
console.log('HOT UPDATE')
devServerEvents.emit('dev-server:compile:success')

return []
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14858,10 +14858,10 @@ es6-weak-map@^2.0.1:
es6-iterator "^2.0.3"
es6-symbol "^3.1.1"

esbuild@^0.8.34:
version "0.8.38"
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.8.38.tgz#04dc395e15c77bbc9d6798e9b31275546bcf7b9a"
integrity sha512-wSunJl8ujgBs9eVGubc8Y6fn/DkDjNyfQBVOFTY1E7sRxr8KTjmqyLIiE0M3Z4CjMnCu/rttCugwnOzY+HiwIw==
esbuild@^0.8.52:
version "0.8.57"
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.8.57.tgz#a42d02bc2b57c70bcd0ef897fe244766bb6dd926"
integrity sha512-j02SFrUwFTRUqiY0Kjplwjm1psuzO1d6AjaXKuOR9hrY0HuPsT6sV42B6myW34h1q4CRy+Y3g4RU/cGJeI/nNA==

escalade@^3.0.1, escalade@^3.1.1:
version "3.1.1"
Expand Down Expand Up @@ -35006,12 +35006,12 @@ vinyl@^2.0.0, vinyl@^2.1.0, vinyl@^2.2.0:
remove-trailing-separator "^1.0.1"
replace-ext "^1.0.0"

[email protected].1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/vite/-/vite-2.0.1.tgz#348fc5c0de510aa90bd01ecf87df210ce741b38e"
integrity sha512-x7ZfikjNs+6n4cdvwb9L5r5xBCdjmtmHFHaI4JVR3nAkJbMCK/dynfDWky8/NseZ9Ncz1jVxTQ/Bcf+n1ps1Ww==
[email protected].5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/vite/-/vite-2.0.5.tgz#ac46857a3fa8686d077921e61bd48a986931df1d"
integrity sha512-QTgEDbq1WsTtr6j+++ewjhBFEk6c8v0xz4fb/OWJQKNYU8ZZtphOshwOqAlnarSstPBtWCBR0tsugXx6ajfoUg==
dependencies:
esbuild "^0.8.34"
esbuild "^0.8.52"
postcss "^8.2.1"
resolve "^1.19.0"
rollup "^2.38.5"
Expand Down

4 comments on commit 59dbed9

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 59dbed9 Mar 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/6.7.0/circle-develop-59dbed90dcfd6c71d3478cd61d0228cff702087f/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 59dbed9 Mar 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/6.7.0/appveyor-develop-59dbed90dcfd6c71d3478cd61d0228cff702087f/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 59dbed9 Mar 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/6.7.0/appveyor-develop-59dbed90dcfd6c71d3478cd61d0228cff702087f/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 59dbed9 Mar 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/6.7.0/circle-develop-59dbed90dcfd6c71d3478cd61d0228cff702087f/cypress.tgz

Please sign in to comment.