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 Windows portability issues, move fakeJsdoc to jsdocStub #1

Merged
merged 3 commits into from
Dec 28, 2023

Conversation

mbland
Copy link
Owner

@mbland mbland commented Dec 28, 2023

There were a few problems here. It looks like a lot based on the description, but the actual overall change isn't very large.

First, I applied url.fileURLToPath to main.test.js, which should've been part of commit 3492207. This fixed the problem of not finding the jsdoc stub on Windows.

I then added an error handler to the process spawned within spawnMain() to make the tests fail faster instead of timing out after five seconds. This made iterating on the following problems much faster.

Today I learned that on Windows, we need to use process.env.Path, not process.env.PATH. So now the new PATH_KEY constant is used in place of raw env.PATH accesses and { PATH: "..." } object literals. This was the biggest of the problems.

Next, the jsdoc.CMD invocation kept echoing its commands to standard output, causing tests to fail. The solution was to add @echo off as the first line of the jsdoc.CMD script.

In runMainWithoutJsdoc from main.test.js, jsdocDir contained unescaped backslashes on Windows, so the regular expression created from it didn't match the jsdoc path. The fix was to replace all \ in jsdocDir with \\ first.

Finally, spawnMain() from main.test.js now runs the mainPath script by passing process.execPath (the path to the Node interpreter) as the first argument. This is because Windows can't interpret the shebang at the top of the mainPath script. This is also portable to macOS and Linux.

In the process (ha!), I also stopped manipulating process.env.PATH in spawnMain() after remembering I could just define a new env object. This also enabled returning the Promise directly from the function, rather than using await internally to reset process.env.PATH afterwards.


And one more housekeeping thing: I renamed the fakeJsdoc test fixture to jsdocStub. This didn't change any functionality, but better reflects the nature of the jsdoc test double scripts.

"Fake" would imply that the doubles are fully functional, but merely scaled down implementations. These are really more "stubs," incomplete implementations to simulate specific operations and responses.

Should've been part of commit 3492207.

This fixes the problem of not finding the `jsdoc` stub on Windows, but
now the tests in main.test.js are failing on Windows with:

  Serialized Error: { errno: -4094, code: 'UNKNOWN', syscall: 'spawn' }

Which is odd, because runJsdoc() calls spawn() and runJsdoc.test.js
passes just fine. Investigating...
There were a few problems here. First, I added an error handler to the
process spawned within spawnMain() to make the tests fail faster instead
of timing out after five seconds. This made iterating on the following
problems much faster.

Today I learned that on Windows, we need to use process.env.Path, not
process.env.PATH. So now the new PATH_KEY constant is used in place of
raw env.PATH accesses and `{ PATH: "..." }` object literals. This was
the biggest of the problems.

Next, the jsdoc.CMD invocation kept echoing its commands to standard
output, causing tests to fail. The solution was to add `@echo off` as
the first line of the jsdoc.CMD script.

In runMainWithoutJsdoc from main.test.js, `jsdocDir` contained unescaped
backslashes on Windows, so the regular expression created from it didn't
match the jsdoc path. The fix was to replace all `\` in `jsdocDir` with
`\\` first.

Finally, spawnMain() from main.test.js now runs the mainPath script by
passing process.execPath (the path to the Node interpreter) as the first
argument. This is because Windows can't interpret the shebang at the top
of the mainPath script. This is also portable to macOS and Linux.

In the process (ha!), I also stopped manipulating process.env.PATH in
spawnMain() after remembering I could just define a new env object. This
also enabled returning the Promise directly from the function, rather
than using await internally to reset process.env.PATH afterwards.
This doesn't change any functionality, but better reflects the nature of
the jsdoc test double scripts.

"Fake" would imply that the doubles are fully functional, but merely
scaled down implementations. These are really more "stubs," incomplete
implementations to simulate specific operations and responses.
@mbland mbland self-assigned this Dec 28, 2023
@mbland mbland merged commit d62f081 into main Dec 28, 2023
2 checks passed
@mbland mbland deleted the fix-windows-portability branch December 28, 2023 17:57
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.

1 participant