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 path parsing and tests on windows #602

Merged
4 commits merged into from
Jan 10, 2024

Conversation

Joris-van-der-Wel
Copy link
Contributor

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 of node 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 of nyc, and also because single quotes were used in the run script.

Before:

  303 passing (14s)
  8 pending
  64 failing

After:

  374 passing (31s)
  5 pending

The individual commits in this PR contain more details.

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.
Copy link
Collaborator

@ljharb ljharb left a 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!

package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
Copy link

socket-security bot commented Jan 9, 2024

New dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
nyc 10.3.2 eval, environment +1 23.6 MB bcoe

@Joris-van-der-Wel
Copy link
Contributor Author

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?

@ljharb
Copy link
Collaborator

ljharb commented Jan 9, 2024

Force push to this branch would be great :-) thanks!

Copy link
Collaborator

@ljharb ljharb left a 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.

Copy link

codecov bot commented Jan 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (4640a91) 96.76% compared to head (fc33439) 96.76%.

❗ Current head fc33439 differs from pull request most recent head bcf6ce7. Consider uploading reports for the commit bcf6ce7 to get more accurate results

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.
📢 Have feedback on the report? Share it here.

@ljharb ljharb closed this pull request by merging all changes into tape-testing:master in 201e650 Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants