Skip to content
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: chain update all specs when changing child #17693

Merged
merged 3 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Hello from './Hello.vue'

describe('Hello', () => {
it('shows error for short text', () => {
cy.viewport(300, 200)
cy.viewport(500, 800)
mount(Hello)
// use the component like a real user
cy.findByRole('textbox').type('abc')
Expand Down
4 changes: 4 additions & 0 deletions npm/vite-dev-server/cypress/components/vue/Hello/Hello.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
<input v-model="username" />
<div v-if="error" class="error">{{ error }}</div>
<img src="./logo.png" />
<Card/>
</div>
</template>

<script>
import Card from "../Card/Card.vue"

export default {
name: "Hello",
components: { Card },
data() {
return {
username: "",
Expand Down
26 changes: 19 additions & 7 deletions npm/vite-dev-server/src/makeCypressPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ interface Spec{

export const makeCypressPlugin = (
projectRoot: string,
supportFilePath: string,
devServerEvents: EventEmitter,
supportFilePath: string | false,
devServerEvents: NodeJS.EventEmitter,
specs: Spec[],
): Plugin => {
let base = '/'
Expand Down Expand Up @@ -93,8 +93,10 @@ export const makeCypressPlugin = (
let moduleImporters = server.moduleGraph.fileToModulesMap.get(file)
let iterationNumber = 0

const exploredFiles = new Set<string>()

// until we reached a point where the current module is imported by no other
while (moduleImporters && moduleImporters.size) {
while (moduleImporters?.size) {
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.`)

Expand All @@ -108,19 +110,27 @@ export const makeCypressPlugin = (
debug('handleHotUpdate - support compile success')
devServerEvents.emit('dev-server:compile:success')

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

if (mod.file && specsPathsSet.has(mod.file)) {
debug('handleHotUpdate - spec compile success', mod.file)
devServerEvents.emit('dev-server:compile:success', { specFile: mod.file })
// if we find one spec, does not mean we are done yet,
// there could be other spec files to re-run
// see https://github.com/cypress-io/cypress/issues/17691
}

return []
// to avoid circular updates, keep track of what we updated
if (mod.file) {
exploredFiles.add(mod.file)
}
}

// get all the modules that import the current one
moduleImporters = getImporters(moduleImporters)
moduleImporters = getImporters(moduleImporters, exploredFiles)
iterationNumber += 1
}

Expand All @@ -129,11 +139,13 @@ export const makeCypressPlugin = (
}
}

function getImporters (modules: Set<ModuleNode>): Set<ModuleNode> {
function getImporters (modules: Set<ModuleNode>, alreadyExploredFiles: Set<string>): Set<ModuleNode> {
const allImporters = new Set<ModuleNode>()

modules.forEach((m) => {
m.importers.forEach((imp) => allImporters.add(imp))
if (m.file && !alreadyExploredFiles.has(m.file)) {
m.importers.forEach((imp) => allImporters.add(imp))
}
})

return allImporters
Expand Down
9 changes: 1 addition & 8 deletions npm/vite-dev-server/src/startServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,11 @@ import { makeCypressPlugin } from './makeCypressPlugin'

const debug = Debug('cypress:vite-dev-server:start')

interface Options {
specs: Cypress.Cypress['spec'][]
config: Record<string, string>
devServerEvents: EventEmitter
[key: string]: unknown
}

export interface StartDevServerOptions {
/**
* the Cypress options object
*/
options: Options
options: Cypress.DevServerOptions
/**
* By default, vite will use your vite.config file to
* Start the server. If you need additional plugins or
Expand Down