-
-
Notifications
You must be signed in to change notification settings - Fork 305
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 path parsing and tests on windows #602
Conversation
Source files which are located in the current working directory, have a part of their path replaced by `path.sep + '$CWD'`. However, this causes the regular expression for stack trace lines to not match on windows. Example of a stack trace line, after replacement (`console.log(lineWithTokens)` in lib/test.js): ``` at Test.assert [as _assert] (\$CWD\example\my-test.js:483:11) ``` The part of the regexp that fails is `(?:\/|[a-zA-Z]:\\)`. I fixed this by allowing the path to start with a backslash. So instead of `\/`, the regexp uses `[/\\]`. This issue is already covered by existing test cases that are currently failing when they are ran on windows. For example: `.\node_modules\.bin\tap test/*.js`
The current version of `glob` returns paths always with forward slashes, even on windows. This causes the `dotignore` `Matcher` to never match the paths on windows, because it expects backslashes on windows. This means that the `--ignore` and `--ignore-pattern` options do not work properly on windows. This is fixed in a newer version of glob (not sure which specific version). However, we can not upgrade because it drops support for older node versions that we still want to support in tape. So instead, a workaround is to correct the slashes ourselves. This issue is already covered by existing test cases (test/ignore-pattern.js), that are currently failing when they are ran on windows. For example: `.\node_modules\.bin\tap test/*.js`. However, an additional fix is needed to make these tests pass (see next commit).
… pass on windows In some parts of the code the `bin/tape` script was executed directly. This does not always work on windows, causing those tests to fail. So instead `process.execPath` is executed (which is the path to the node binary), and the script is passed as an argument. In other parts of the code, argv[0] was used. This has been made consistent so that execPath is used everywhere.
The version of "nyc" (v9) that is being used does not support launching binaries from node_modules/.bin on windows. As a workaround the path to tap's run.js is specified. Newer version of nyc fix this issue, however those versions drop support for older node versions that we still want to support here. Also, the windows shell does not understand single quotes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is amazing!
New dependencies detected. Learn more about Socket for GitHub ↗︎
|
I have a new version of these commits without any dependency update. They are on a different branch. How would you prefer to receive these new changes? Force push? New PR? Extra commit? |
Force push to this branch would be great :-) thanks! |
6159a6a
to
fc33439
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it, thank you! I'll verify tests locally and in a windows VM before merging.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #602 +/- ##
=======================================
Coverage 96.76% 96.76%
=======================================
Files 4 4
Lines 742 742
Branches 182 182
=======================================
Hits 718 718
Misses 24 24 ☔ View full report in Codecov by Sentry. |
201e650
This is a follow up of #183 which involved a similar fix for a much older version (9 years ago) of this library. I noted 4 years ago that the stack trace parsing on windows had already been fixed by someone else.
However I just discovered that the issue has cropped up again, which this PR attempts to fix. Luckily this time the existing tests already check for this issue, however the tests must be ran on windows. This uncovered more issues because a lot of tests were broken on windows.
Some tests were attempting to spawn
bin/tape
, instead ofnode bin/tape
. This does not work on my windows machine.The failing tests uncovered that the
--ignore
and--ignore-pattern
options do not work properly on windows. This was because the old version of glob uses forward slashes on windows, while dotignore expects backslashes.It was not possible to run the tests using
npm test
. This was because of a bug in the old versions ofnyc
, and also because single quotes were used in the run script.Before:
After:
The individual commits in this PR contain more details.