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

[ESM] Tests no longer work on windows or WSL #170

Closed
gadicc opened this issue May 9, 2021 · 8 comments
Closed

[ESM] Tests no longer work on windows or WSL #170

gadicc opened this issue May 9, 2021 · 8 comments

Comments

@gadicc
Copy link
Owner

gadicc commented May 9, 2021

@gadicc Tests no longer work on windows or WSL. I am trying some hacks and reverting some things to make it work. I think that some parts of this PR will have to be reverted, like the tests. After reverting the .js addition and the changes to the jest config, I still failed to get tests running. node_modules/.bin/jest doesn't work on windows, see jestjs/jest#3750. Next, after fixing that, the tests fail saying that "the test environment has already been torn down", pointing at await import('./lib/fetchDevel.js').

Jest ESM support is currently poor, I think that this PR should be held off until ESM support works properly in jest, or at least until tests work on all platforms.
Also see #167.

Originally posted by @PythonCreator27 in #144 (comment)

@gadicc
Copy link
Owner Author

gadicc commented May 9, 2021

Hey @PythonCreator27, let's address this issue (esm testing on windows) separately and see if we can solve it. We can do the same with any other issues that crop up and then make a call on whether to revert or not.

Tests are all passing on my system and on the CI, so I think Jest's ESM support is working ok, but obviously we want it to work on Windows too.

Two things that came to mind:

  • Can I just double check that you ran yarn install again after pulling in the latest devel changes, that would have downloaded the latest "next" releases for jest and ts-jest that we specify in package.json.

  • Can you try deleting dist, api, tests-modules (and tests/modules if it exists) directories and see if that makes any difference? I think I recall this error when getting everything set up on overlapping tests of differing types / modules. Maybe an ignore pattern using / when windows needs \. But first let's see if this helps.

And if still not, we'll see what we can figure out.

@gadicc
Copy link
Owner Author

gadicc commented May 9, 2021

Oh wait, I just re-read your message... you said you reverted your jest.config too... that will definitely fail. Let's see if any of the above helps on a clean devel clone (I fixed the .bin/jest issue you mentioned in devel too).

@advaiyalad
Copy link
Contributor

advaiyalad commented May 9, 2021

I did run yarn again, and deleting the dist, api, and tests-modules folders seems to have made little to no difference.
A lot of tests are failing since they check for a specific type of error, and the error that it is replaced with is the jest "env has been torn down" error. I think that the ignore paths do not work on windows, as adding "\\tests-modules\\" to the ignore pattern sends the failing test count down from 87 (number varies) to 56 (number varies, and has gone down to 33 and up to 97), at least usually. Deleting tests-modules does the same thing. I think that this is a very fluctuating thing, so I might be wrong.

@advaiyalad
Copy link
Contributor

advaiyalad commented May 9, 2021

@gadicc After a little bit more of trying things out, I tried to add jest.useFakeTimers() to setupTests.js as suggested somewhere. I also added jest.setTimeout(50000000), but it seems to make the tests hang on the concurrency or some other yahooFinanceFetch tests. Overall, no progress.

@gadicc
Copy link
Owner Author

gadicc commented May 10, 2021

Hey @PythonCreator27, thanks (as usual!) for all your efforts here.

The problem seems to be with the dynamic import, but only when running a lot of tests. As you point out, the number of failures vary with each run. I've been trying to simplify it down to a minimal reproduction to submit as an upstream issue, but no luck yet.

In any event, just FYI, you can get the tests running by replacing the existing fetchDevel() function in env-node.js with something like:

import fetchDevel_ from "./lib/fetchDevel.js";
function fetchDevel() {
  return fetchDevel_;
}

With that, everything passes except for just this 1 failure:

● yahooFinanceFetch › concurrency › waits if exceeding concurrency max

which we can look at separately.

I'd like to try figure this out and submit upstream, but if we're impatient, we could pick a different way to conditionally include fetchDevel (probably with an environment variable). Might not be a bad idea to go that route anyway.

Unfortunately I have an overseas trip coming up next week so my time is a bit limited, but let's see how we go.

@gadicc
Copy link
Owner Author

gadicc commented May 10, 2021

Related to Jest issue #10944 and probably caused by Node issue #36351. Easier temporary fix, set # of workers to >= # of test suits, e.g.

# node-yahoo-finance2 has 16 test suites
$ yarn test -w 16

@advaiyalad
Copy link
Contributor

@gadicc Tests running (after I add --experimental-json-modules to package.json)! I am not sure how CI runs, since the current test scripts do not use --experimental-json-modules. Any ideas?

@gadicc
Copy link
Owner Author

gadicc commented May 11, 2021

Ok great news!

The main test script is using ts-jest which is converting from the source typescript (not the dist output) to whatever they use internally, presumably "es modules implemented in commonjs" so it's probably still requiring'ing the json under the hood. I think! Haven't actually checked their code 😅

Even test:esm presumably goes through a similar process... without the typescript but processed through babel still. Presumably 😁

@gadicc gadicc closed this as completed May 26, 2021
gadicc pushed a commit that referenced this issue Jun 1, 2021
# [1.11.0](v1.10.4...v1.11.0) (2021-06-01)

### Bug Fixes

* **deps:** update dependency ajv to ^8.1.0 ([1769641](1769641))
* **quoteCombine:** resolve `undefined` for missing symbols ([#150](#150)) ([f8c25e3](f8c25e3))
* **testing:** specify jest.js path, not bin ([#170](#170)) ([6772c8e](6772c8e))

### Features

* **options:** accept `date` option ([#186](#186)) ([11b8a72](11b8a72))
* add (friendly) warning when used in the browser ([3c4c5a0](3c4c5a0)), closes [#153](#153)
* add insights module ([#169](#169)) ([4603232](4603232))
* **concurrency:** ability to limit max simultaneous requests ([#76](#76)) ([3424d44](3424d44))
* **modules:** build (true) esm, (interop) cjs modules; tests/readme ([#144](#144)) ([2182f6c](2182f6c))
* **setGlobalConfig:** add setGlobalConfig function ([#133](#133)) ([43ebaa4](43ebaa4))
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

No branches or pull requests

2 participants