Skip to content

Commit

Permalink
fix(vite-dev-server): ensure assets are correctly reloaded (#24965)
Browse files Browse the repository at this point in the history
* do not use custom HMR

* remove old code
  • Loading branch information
lmiller1990 authored Dec 8, 2022
1 parent 78412e9 commit 89c013f
Show file tree
Hide file tree
Showing 12 changed files with 931 additions and 3 deletions.
39 changes: 39 additions & 0 deletions npm/vite-dev-server/cypress/e2e/vite-dev-server.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,45 @@
import dedent from 'dedent'

describe('Config options', () => {
it('works with tailwind', () => {
cy.scaffoldProject('tailwind-vite')
cy.openProject('tailwind-vite')
cy.startAppServer('component')

cy.visitApp()
cy.contains('App.cy.jsx').click()
cy.waitForSpecToFinish()
cy.get('.passed > .num').should('contain', 1)
cy.withCtx(async (ctx) => {
// Add a new spec with bg-blue-100 that asserts the style is correct
// If HMR + Tailwind is working properly, it'll pass.
await ctx.actions.file.writeFileInProject(
'src/App.cy.jsx', `
import React from 'react'
import { mount } from 'cypress/react18'
export const App = () => {
return (
<div className='bg-blue-100' id='hello'>
Hello
</div>
)
}
it('works', () => {
mount(<App />)
cy.get('#hello').should('have.css', 'background-color', 'rgb(219, 234, 254)')
})
it('dummy', () => {})
`,
)
})

cy.waitForSpecToFinish()
cy.get('.passed > .num').should('contain', 2)
})

it('supports supportFile = false', () => {
cy.scaffoldProject('vite2.9.1-react')
cy.openProject('vite2.9.1-react', ['--config-file', 'cypress-vite-no-support.config.ts'])
Expand Down
6 changes: 3 additions & 3 deletions npm/vite-dev-server/src/plugins/cypress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const Cypress = (
if (iterationNumber > HMR_DEPENDENCY_LOOKUP_MAX_ITERATION) {
debug(`max hmr iteration reached: ${HMR_DEPENDENCY_LOOKUP_MAX_ITERATION}; Rerun will not happen on this file change.`)

return []
return
}

// as soon as we find one of the specs, we trigger the re-run of tests
Expand All @@ -139,7 +139,7 @@ export const Cypress = (

// if we update support we know we have to re-run it all
// no need to check further
return []
return
}

if (mod.file && specsPathsSet.has(mod.file)) {
Expand All @@ -156,7 +156,7 @@ export const Cypress = (
iterationNumber += 1
}

return []
return
},
}
}
Expand Down
12 changes: 12 additions & 0 deletions system-tests/projects/tailwind-vite/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const path = require('path')

module.exports = {
component: {
devServer: {
framework: 'react',
bundler: 'vite',
},
indexHtmlFile: path.join(__dirname, 'index.html'),
supportFile: path.join(__dirname, 'support.js'),
},
}
3 changes: 3 additions & 0 deletions system-tests/projects/tailwind-vite/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
12 changes: 12 additions & 0 deletions system-tests/projects/tailwind-vite/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Components App</title>
</head>
<body>
<div data-cy-root></div>
</body>
</html>
11 changes: 11 additions & 0 deletions system-tests/projects/tailwind-vite/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"dependencies": {
"@cypress/vite-dev-server": "file:../../../npm/vite-dev-server",
"autoprefixer": "10.4.13",
"postcss": "8.4.19",
"react": "18.2.0",
"react-dom": "18.2.0",
"tailwindcss": "3.2.4",
"vite": "3.2.2"
}
}
6 changes: 6 additions & 0 deletions system-tests/projects/tailwind-vite/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
15 changes: 15 additions & 0 deletions system-tests/projects/tailwind-vite/src/App.cy.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'
import { mount } from 'cypress/react18'

export const App = () => {
return (
<div className='bg-red-100' id='hello'>
Hello
</div>
)
}

it('works', () => {
mount(<App />)
cy.get('#hello').should('have.css', 'background-color', 'rgb(254, 226, 226)')
})
1 change: 1 addition & 0 deletions system-tests/projects/tailwind-vite/support.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './index.css'
8 changes: 8 additions & 0 deletions system-tests/projects/tailwind-vite/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ['./src/**/*'],
theme: {
extend: {},
},
plugins: [],
}
10 changes: 10 additions & 0 deletions system-tests/projects/tailwind-vite/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
resolve: {
alias: {
'react': require.resolve('react'),
'react-dom/client': require.resolve('react-dom/client'),
'react-dom': require.resolve('react-dom'),
},
},
logLevel: 'silent',
}
Loading

5 comments on commit 89c013f

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 89c013f Dec 8, 2022

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 arm64 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/12.1.0/linux-arm64/develop-89c013fcedc2509850ec820f938d33f08f9cbb42/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 89c013f Dec 8, 2022

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/12.1.0/linux-x64/develop-89c013fcedc2509850ec820f938d33f08f9cbb42/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 89c013f Dec 9, 2022

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 arm64 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/12.1.0/darwin-arm64/develop-89c013fcedc2509850ec820f938d33f08f9cbb42/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 89c013f Dec 9, 2022

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/12.1.0/darwin-x64/develop-89c013fcedc2509850ec820f938d33f08f9cbb42/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 89c013f Dec 9, 2022

Choose a reason for hiding this comment

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

Circle 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/12.1.0/win32-x64/develop-89c013fcedc2509850ec820f938d33f08f9cbb42/cypress.tgz

Please sign in to comment.