cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.66k stars 3.16k forks source link

Driver is not reloading when spec files are modified in Windows #712

Closed brian-mann closed 6 years ago

brian-mann commented 6 years ago

This is likely due to the different system paths and separators.

We should also take the opportunity to change the way the server process is notified of file watching.

Instead of letting the driver or desktop gui ask the server to watch a file - the server should instead automatically watch the file when it is being served when tests begin running.

That way state is kept in one place and likely this would just fix it.

egucciar commented 6 years ago

Is this going to get resolved ? Trying to be keyboard only with this new TDD approach :)

brian-mann commented 6 years ago

It will get resolved relatively soon. Our team is working on other things. PR's from the community are welcome ;-)

It's likely a pathing issue (since Windows is different) due to the way we watch files for changes.

Imlus commented 6 years ago

Is there a temporary workaround for this? As it gets annoying pretty fast :)

brian-mann commented 6 years ago

The good news is that we realized we actually fixed this issue without us knowing in 1.1.0.

We manually tested again with the latest fixes coming in 1.1.3 and verified it will continue to work.

brian-mann commented 6 years ago

Released in 1.1.0.

Zoe7 commented 6 years ago

Hi there,

I'm not sure if my issues are related to this at all, but I'm also experiencing problems with the reloading on Windows, using Cypress 1.1.2. When I makes changes to my spec file, the browser doesn't always reload the tests (I cannot seem to find a pattern to when it does and doesn't). If I re-run them manually, they run with the old version of the spec file, which makes it really hard to work.

ghost commented 6 years ago

Hi there, I confirm Zoe7's comment. I have the same issue with Cypress 1.1.2 (Windows 10).

Imlus commented 6 years ago

The issue exists after the 1.1.0 patch. Using Windows 10

brian-mann commented 6 years ago

Can @vincium and @Imlus and @Zoe7 check if this issue has been resolved in 1.1.3?

We manually tested it in Windows and it was working for us.

Zoe7 commented 6 years ago

I upgraded to 1.1.3 and it didn't seem to make any difference. Let me know if I can provide anything to help you debug this.

ghost commented 6 years ago

Hey, I confirm that upgrading to 1.1.3 does not make any difference.

leny commented 6 years ago

Any news here? Seems that keeping windows updated doesn't change anything, the issue still here.

escorponox commented 6 years ago

I'm suffering this. Windows 10 Cypress 1.4.0

brian-mann commented 6 years ago

Is everyone here on Windows 10? Is there another OS combination who are having trouble?

We're working on a fix going out in 1.4.1 that will expose more DEBUG logs. As it stands, we cannot reproduce this on our Windows machines. So the underlying issue is still unknown.

escorponox commented 6 years ago

I'm also using create-react-app. Maybe the CRA dev server file watcher conflicts with cypress file watcher? I'm just guessing. I will test it...

leny commented 6 years ago

Here we have the problem testing a React app on Windows 10 (the React app run inside a vagrant/virtualbox VM), with the same setup on Windows 7, we don't have the issue. We will try with the 1.4.1 to have more debug logs to help.

Thanks!

escorponox commented 6 years ago

I can confirm this is also happening on Linux Mint.

jblaketc commented 6 years ago

This is happening sometimes for me as well. Windows 10 Node 8.9.4 Cypress 1.4.1

I launch Cypress with 'npm run cypress' which in the package.json is set to 'cypress open'

I click on one of the tests and it runs. Sometimes I can make a change and save and it'll rerun the test with the change, but other times, I have to make a couple of changes and save a couple of times before it reloads the test that I opened.

abhilashshettigartrt commented 6 years ago

i am also getting same issue with one of my project ,it runs good with my old project i.e cypress:- 1.4.1 and 1.4.2 but not reloading spec file in my new project and i have also updated the cypress to 2.0.2 ,windows-10

stuartdotnet commented 6 years ago

Happening in Windows 10. Need to close and re-run Cypress to pick up saved changes.

brian-mann commented 6 years ago

We need more information, because as it stands we cannot reproduce this issue in our Windows environments.

What prepreprocessor are you all using? The built in Cypress one? The webpack one? Are you changing any of the options?

Can one of you provide the minimum number of steps to reproduce. This may sound obvious but we need to start from scratch on this one.

What I'm looking for is this:

  1. create a blank project (literally nothing in it)
  2. npm init -y
  3. npm install --save-dev cypress
  4. cypress open
  5. run example_spec.js
  6. remove everything in example_spec.js and add a simple it(...) test
  7. save the file -> does the test run?
  8. If not, what is the text editor you are using?
  9. Try a different text editor.

When we do the above steps - it works.

Imlus commented 6 years ago

I believe it's a bit harder than this. As I've tried on two almost identical laptops, just one was of a newer series. And one is working as expected, but the other does not re-run any tests on save. So probably there's a deeper issue here which is not that trivial to find and understand.

ghost commented 6 years ago

Just a quick update, that it is now working with 2.0.4 (maybe earlier versions as well) and it's great! Thanks for your work!

rrrainbows commented 6 years ago

I'm facing same problem on Linux Ubuntu 16.04 on VW inside Windows 10 (Cypress 2.1.0). Project runs inside Docker container, Cypress added as a part of the project. But I haven't seen this before I moved from Sublime to PhpStorm. Now I have to run another file first and then re-run my file with changes to see these changes.

rrrainbows commented 6 years ago

I've just reproduced this with PhpStorm after 5 savings (it worked well before). Then I moved back to Sublime and after 13 savings it still worked good. Then I moved to PhpStorm again and now it doesn't re-run at all.

hannaofsweden commented 6 years ago

The issue seems to be that IntelliJ (and other JetBrains apps such as WebStorm) don't trigger the file system watcher when they're using the Safe Write feature when on Windows 10. This feature is enabled by default. The problem is inconsistent and sometimes everything seems to work fine, while at other times even restarting Cypress doesn't solve it.

If I'm correct it's a version of this: https://stackoverflow.com/questions/34213253/webpack-watch-not-working-on-webstorm-on-windows

I'm not why this problem should exist but I'm sure there's some way to work around it. There are multiple file watcher implementations in Node and maybe they don't all have this issue.

As a temporary workaround from the user side, try disabling Safe Write in the IntelliJ settings (File - Settings and search for it).

rrrainbows commented 6 years ago

@hannaofsweden thank you. This workaround works good.

jolanantonio commented 6 years ago

I'm having the same issue in the following environment:

The test runner doesn't automatically update after I save changes in my code. Reopening the browser also doesnt reflect the changes. It only updates if I close cypress, reopen it, and click.on the .js file.

ghost commented 6 years ago

Unfortunately I'm receiving the same results as @lambootz My Code editor is VSCode. The test runner only updates if I close cypress, reopen it, and click.on the .js file.

brian-mann commented 6 years ago

@lambootz and @blodgettza if you want us to look at the issue please follow my instructions here: https://github.com/cypress-io/cypress/issues/712#issuecomment-370642617

Until someone provides reproducible steps there's nothing we can do. Users have reported this, and users have reported that the text editor is causing this. We have yet to reproduce on our end.

jolanantonio commented 6 years ago

@brian-mann I just followed the specific instructions (started fresh #712 ). I am still having the same issue. example_spec.js ran perfectly and then I erased the contents and replaced with a simple code (same that is in tutorial).

I already tried the following browsers: sublime ver 3.0 build 3143 ultraedit notepad++ ver 7.5.1 notepad

Operating System: Windows 10 Home Single Language 64-bit version 1709

and I did these all twice just to be sure... let me know if there's anything else I can do on my side.

jolanantonio commented 6 years ago

Here's something new... I installed an older version ver 1.0.3

It still doesn't update and doesn't automatically rerun the code. But now I just need to close the browser and click on the example_spec.js file and I would see the changes (no need to close cypress and open again)

Imlus commented 6 years ago

Turning off the safe write solved the problem for me as well (Webstorm)

bcholewinski commented 6 years ago

Windows 10 Cypress 3.0.1 I had similar issue because I gave the prefix [wip] in my test file name. After I removed the prefix from the file name everything returned to normal.

agentHoover commented 6 years ago

I believe my issue is related to this thread. If not then I will happily create a new one but it seems to be related.

I'm on windows 10, Cypress 3.0.2.

Using VS Code and the cypress-cucumber-plugin I noticed that when I changed my feature file tests would rerun but if I changed my step_definition files they would not. I spent some time debugging and found path related issues (platform specific -- windows vs POSIX path seperators) in both the plugin (I will file a separate bug for that in that project) and in the Cypress/packages/server/lib/socket library. Line 77 of the socket.coffee file is this:

filePath = path.join(config.integrationFolder, originalFilePath.replace("integration/", ""))

I believe the replace is failing on windows because of the trailing slash. So the watched path ends up being .../integration/integration... Using the JavaScript path.sep property instead of a hardcoded slash should make this work cross-platform. Unfortunately I don't have the time to setup up everything and test this and create a pull request. If I get free before someone else can prove this out I will try to put one together.

I noticed this originally when trying to setup webpack to use with our angular project so I think it could be pretty significant for the windows world.

brian-mann commented 6 years ago

While you're correct about this - I don't believe this line of code affects file watching - it's purely for presentation in the Desktop GUI. We actually do have some cleanup / fixes that are in a PR related to this (but not quite this) that are going out in the next patch release.

Regardless though, it could be related to the cucumber plugin. We have a great many users of Windows and there hasn't been any recent reports of file watching problems. There were back in the day, but those have been long fixed. Perhaps try pulling that out temporarily to see if you can recreate the problem?

BTW in order to "test" this, you could edit the files directly in the production binary that you're using. If you tunnel into where Cypress is installed you'll eventually reach the source code. That way you can make any change you want in the final compiled product and those changes will take effect when you run Cypress. No fussing with the development versions.

agentHoover commented 6 years ago

I did test this as you suggested and it fixed the problem for me. This is the line of code with my modifications. Here is the path to the file I modified on my machine: %userprofile%\AppData\Local\Cypress\Cache\3.0.2\Cypress\resources\app\packages\server\lib\socket.js

the function I changed was Socket.prototype.watchTestFileByPath

//filePath = path.join(config.integrationFolder, originalFilePath.replace("integration/", ""));
filePath = path.join(config.integrationFolder, originalFilePath.replace(\`integration${path.sep}\`, ""));

Making this change allowed edits to the step_definition files to be picked up by Cypress and rerun.

brian-mann commented 6 years ago

Great, that makes it super easy for us. We'll write a test and get this in the next patch release. Thank you.

agentHoover commented 6 years ago

As a note, I just noticed the code markdown tag in my previous comment wacked the template literals I used around my string (`integration${path.sep}, "") ` . I'm sure you would have figured that out but wanted to note it just so there is not any confusion. I edited it to correct it.

Also, thanks for a great product. I'm have quickly become a great fan!

mhodgson commented 6 years ago

Hello, the path.sep fix was required by two of our windows developers in order to get Cypress to run at all (run or open). I'm not sure why this works for some people and not for others, but it seems that using path.sep works for everyone, so hopefully this can be fixed quickly.

agentHoover commented 6 years ago

@mhodgson I'm working on a PR for this today. As a side note for anyone else having this problem while using the cypress-cucumber-plugin, I submitted a PR to them today to fix a related issue in the plugin itself. You need both fixes for that plugin to work on windows correctly.

jennifer-shehane commented 5 years ago

This was released in 3.1.1