-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Watch non-spec files for changes and reload specs #456
Comments
Allowing the user to configure using glob patterns would be awesome. |
Is this looking to be picked up anytime soon? Having a glob pattern specified for /src/ would be incredibly useful when doing TDD with e2e tests. |
@collinstevens for now you can use this plugin to watch arbitrary files and rerun the tests https://github.com/bahmutov/cypress-watch-and-reload |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I only need to re-run tests if Cypress's browser was reloaded by HMR. I do not want Cypress to watch for file changes because HMR already does that for me. HMR actually determines whether the preview window needs a reload since not every src file is a dependency of what is being previewed (such as in a monorepo). Basically, if the browser window reloaded on its own, re-run the tests. |
This comment has been minimized.
This comment has been minimized.
The method shared by @bkucera doesn't work for me, as there's no such message being printed in the console. Agreeing with @jsphstls, that HMR already keeps track of changes, I decided to try hook into that. Ended up putting the result of the experiment in a simple package, and it seems to work pretty well on my machine with It connects to the |
@Svish's package worked for me 👍 Thanks! |
@cypressTeam You should consider putting Svish's plugin (or an equivalent) forward. Maybe by making it an official plugin or referencing it somewhere ? It's simple yet effective and helps cypress achieve a true TDD experience:
|
I'm also really interested in this feature! For me the package from @Svish sadly didn't work. I'm using Storybook, maybe the hot reloading is setup differently there. However I got it working with this snippet: // Re-run tests when source files change.
// Workaround for https://github.com/cypress-io/cypress/issues/456
Cypress.on('window:before:load', window => {
const { XMLHttpRequest } = window;
const originalOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function open(...args) {
this.addEventListener('load', function load() {
if (this.url.endsWith('hot-update.json')) {
cy.$$('.stop', window.top.document).click();
cy.$$('.restart', window.top.document).click();
}
});
originalOpen.apply(this, args);
};
}); I noticed that pressing the stop button before restart can be helpful if there's currently a test running. EDIT: The same works for me with Next.js |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Anyone coming here for TDD on Angular @bkucera's answer works brilliantly. Adding the "stop" to it from @amannn's answer for this brilliant TDD solution! Cypress.on('window:before:load', (win)=>{
const _consoleInfo = win.console.info
win.console.info = function () {
if (arguments[0].includes('App updated.')) {
cy.$$('.stop', top.document).click()
cy.$$('.restart', top.document).click()
}
return _consoleInfo.apply(win.console, arguments)
}
}) |
For those here who tried out my cypress-hmr-restarter plugin, I finally got around to add the "pre restart stopping feature" (like @amannn also suggested). Tested it with our app here, and seems to work great. 🙂 👍 |
Whoever didnt had luck with @Svish awesome cypress-hmr-restarter plugin might wanna recheck it. It also works now with projects which use webpack-hot-middleware plugin (e.g. gatsby, nuxt?!? havent tested it) |
This comment has been minimized.
This comment has been minimized.
@strowk PR accepted, and also added an option to allow for overriding the URL completely. |
Many of our users express the need to want to watch files on their system other than the
*spec
files that we normally watch.Although we currently watch the
spec
file you're currently working in (and all of the subdependencies) many of our users express the need to watch other files (like their src files) for e2e/integration tests.We should do one or both options:
a) give you the ability to specific additional glob paths via
cypress.json
b) give you the ability to watch things yourself and signal to cypress when to reload
With our upcoming CLI refactor we could offer something like this...
The text was updated successfully, but these errors were encountered: