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: enable running on Windows #89

Merged
merged 1 commit into from
Feb 12, 2023
Merged

fix: enable running on Windows #89

merged 1 commit into from
Feb 12, 2023

Conversation

webstech
Copy link
Contributor

import on Windows requires using the file:// url. This can be used on all platforms for absolute paths.

hackErrorStackToGetCallerFile() returns a pathname which includes a leading '/'. This must be removed on Windows for path.resolve but added back along with converting '\' to '/' for the import path.

This is to support the CI run of semantic-release v20 which uses testdouble. There are a couple of PRs for that project for Windows support as well. The CI runs under Windows with these changes and the other changes.

The tests have been run under Windows wsl. The esm and no-loader-esm tests fail on native Windows due to teenytest issues with Windows. The remaining tests run on Windows.

@searls
Copy link
Member

searls commented Jan 21, 2023

Thank you for submitting this! @giltayar can you take a look?

@searls
Copy link
Member

searls commented Feb 1, 2023

Hi @webstech! TIL that GH Actions supports Windows. Could you rebase main and try to see if you can get this passing before merge?

I opened #90 just to verify if it would or wouldn't pass (it failed)

@searls
Copy link
Member

searls commented Feb 1, 2023

i apparently had the power to rebase it!

@webstech
Copy link
Contributor Author

webstech commented Feb 1, 2023

try to see if you can get this passing before merge?

If you are willing to make node v14 the minimum engine, then the non-windows compatible if node test/supports-esm.js can be removed from the scripts in package.json. Node v14 is the oldest LTS version and had some security fixes last year that should have got people moving on from node v12.

I ran with this in the package.json:

"test:esm": "node --loader=quibble ./node_modules/teenytest/bin/teenytest.js ./test/esm-lib/*.test.{mjs,js}"

However, as I said earlier, teenytest has Windows issues. I do remember the stopping point was in lib\prepare\modules\load.js where require is using a fully qualified name. This does not appear to work in node under Windows - the doc mentions using search rules. I did make it work using relative paths so there may be a node issue here.

@searls
Copy link
Member

searls commented Feb 1, 2023

If you are willing to make node v14 the minimum engine, then the non-windows compatible if node test/supports-esm.js can be removed from the scripts in package.json. Node v14 is the oldest LTS version and had some security fixes last year that should have got people moving on from node v12.

Yeah, totally ok with that. That's what the matrix already does

However, as I said #89 (comment), teenytest has Windows issues. I do remember the stopping point was in lib\prepare\modules\load.js where require is using a fully qualified name. This does not appear to work in node under Windows - the doc mentions using search rules. I did make it work using relative paths so there may be a node issue here.

Sorry, I totally missed that. Hmm

@webstech
Copy link
Contributor Author

webstech commented Feb 2, 2023

I went back to specifying relative paths in teenytest\lib\prepare\modules\load.js to verify windows was working and this appears to need more work. Setting to draft. Sorry about that.

Edit:
The original patch works with semantic-release on Windows. The CI test has exposed other issues. e.g. quibble.esmImportWithPath was not tested.

@webstech webstech marked this pull request as draft February 2, 2023 00:57
@webstech
Copy link
Contributor Author

webstech commented Feb 2, 2023

Sorry, I totally missed that. Hmm

Initial testing shows positive results changing this line to:

var testPath = path.relative(__dirname, file)

may resolve the teenytest issue by 'require'ing relative to the loading file.

`import` on Windows requires using the `file://` url.  This can be used
on all platforms for absolute paths.

`hackErrorStackToGetCallerFile()` returns a pathname which includes a
leading '/'.  This must be removed on Windows for `path.resolve` but
added back along with converting '\' to '/' for the import path.  In
other words, the code must handle multiple forms of paths.

Signed-off-by: Chris. Webster <chris@webstech.net>
@webstech
Copy link
Contributor Author

If you are willing to make node v14 the minimum engine, then the non-windows compatible if node test/supports-esm.js can be removed from the scripts in package.json. Node v14 is the oldest LTS version and had some security fixes last year that should have got people moving on from node v12.

Yeah, totally ok with that. That's what the matrix already does

PR #92 has been opened for this, It is competing with PR #91 but rebasing should not be an issue.

@webstech
Copy link
Contributor Author

This has been tested with PR #91. It is dependent on teenytest PR #75 for running on Windows.

Windows testing was done using wsl, bash and cmd.

Removing draft status.

@webstech webstech marked this pull request as ready for review February 10, 2023 07:21
@searls searls merged commit 443fcc1 into testdouble:main Feb 12, 2023
@searls
Copy link
Member

searls commented Feb 12, 2023

Look at that!
Screenshot 2023-02-12 at 9 34 33 AM

Everything merged and updated, and we're running on windows! Published as v0.6.16

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