Describe the issue/error/question
run a unit test under packages/nodes-base got failed.
But I can fix it by remove node_models and reinstall again with npm install
Steps to reproduce?
clone n8n repo
lerna bootstrap --hoist
npm run build
add the code below under packages/nodes-base/test/nodes/Stripe/helpers.test.js
beforeAll(() => {
jest
.useFakeTimers('modern')
.setSystemTime(new Date('2021-02-18 12:24:00'));
});
What is the error message (if any)?
TypeError: Cannot read property ‘useFakeTimers’ of undefined
Share the output returned by the test
PASS test/nodes/Postgres/Postgres.node.functions.test.js
FAIL test/nodes/Stripe/helpers.test.js
● adjustMetadata › it should adjust multiple metadata values
TypeError: Cannot read property 'useFakeTimers' of undefined
3 | beforeAll(() => {
4 | jest
> 5 | .useFakeTimers('modern')
| ^
6 | .setSystemTime(new Date('2021-02-18 12:24:00'));
7 |
8 | });
at Object.useFakeTimers (../../node_modules/jest/node_modules/jest-runtime/build/index.js:1751:38)
at Object.<anonymous> (test/nodes/Stripe/helpers.test.js:5:4)
PASS test/placeholder.test.ts
Information on your n8n setup
Running n8n via [Docker, npm, n8n.cloud, desktop app]: npm
ivov
December 28, 2021, 5:09pm
2
Thanks for your report.
For reference, the issue seems to be mismatched versions of @jest/fake-timers
.
opened 09:59PM - 28 Jan 21 UTC
### Version
4.5.11
### Reproduction link
[https://github.com/Robin-Hoodie/t… est-jest-modern-faketimers](https://github.com/Robin-Hoodie/test-jest-modern-faketimers)
### Environment info
```
System:
OS: macOS 11.1
CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Binaries:
Node: 15.0.1 - ~/.nvm/versions/node/v15.0.1/bin/node
Yarn: 1.22.5 - ~/.yarn/bin/yarn
npm: 7.0.3 - ~/.nvm/versions/node/v15.0.1/bin/npm
Browsers:
Chrome: 88.0.4324.96
Edge: 88.0.705.53
Firefox: 84.0.2
Safari: 14.0.2
npmPackages:
@vue/cli-plugin-unit-jest: ^4.5.11 => 4.5.11
@vue/cli-shared-utils: 4.5.11
jest-serializer-vue: 2.0.2
vue-jest: 3.0.7
vue-template-es2015-compiler: 1.9.1
npmGlobalPackages:
@vue/cli: Not Found
```
### Steps to reproduce
- Clone repo
- Run command "yarn jest"
### What is expected?
Using Jest's `fakeTimers` in modern mode should work (https://jestjs.io/blog/2020/05/05/jest-26#new-fake-timers)
### What is actually happening?
An error is thrown: "TypeError: setSystemTime is not available when not using modern timers"
---
I'm honestly not sure whether this is a Jest issue, a Vue CLI issue or a Yarn issue.
This can be fixed by removing the dependency on `@vue/cli-plugin-unit-jest` entirely, though that's obviously not ideal.
It seems that somehow, running `jest` while having a dependency on `@vue/cli-plugin-unit-jest` will still use `jest@24`
Even overwriting the `jest@24` dependency to `jest@26` using [Yarn resolutions](https://classic.yarnpkg.com/en/docs/selective-version-resolutions/) does not fix the issue.
I bumped into this while working on a monorepo where I have have 2 sub packages in my workspace:
- A server package in which tests are run with `jest`
- A client (Vue) package in which tests are run with `vue-cli-service test:unit`
(The error message is slightly different there, logging "TypeError: Cannot read property 'useFakeTimers' of undefined", though the root cause is likely the same)
EDIT: Just found out that installing dependencies with `npm i` (first removing `yarn.lock` and `node_modules`) will actually also fix this (though that doesn't convince me yet that this is a yarn issue)
EDIT#2: Using yarn 2 to install dependencies also removes this problem
opened 06:44AM - 14 Jul 21 UTC
closed 10:02AM - 15 Oct 21 UTC
Needs Triage
Bug Report
## 🐛 Bug Report
Jest relies on yarn/npm to deduplicate `@jest/fake-timers`. I… f it is not deduplicated, the following functions always throw the error `setSystemTime is not available when not using modern/legacy timers`.
* setSystemTime
* getRealSystemTime
* runAllImmediates
It's caused by the instanceof checks in this file: https://github.com/facebook/jest/blob/master/packages/jest-runtime/src/index.ts.
I've attached my real yarn lock file to prove that deduplication can fail in the wild, and not just in the contrived example below. [yarn.lock.zip](https://github.com/facebook/jest/files/6814044/yarn.lock.zip)
## To Reproduce
Run the following
```
yarn add [email protected] @jest/[email protected]
echo "jest.useFakeTimers('modern').setSystemTime(new Date());" > test.js
yarn jest
```
It will output this:
```
FAIL ./test.js
● Test suite failed to run
TypeError: setSystemTime is not available when not using modern timers
> 1 | jest.useFakeTimers('modern').setSystemTime(new Date());
| ^
2 |
at Object.setSystemTime (node_modules/jest-runtime/build/index.js:1989:17)
at Object.<anonymous> (test.js:1:1)
```
## Expected behavior
Jest should not rely on yarn/npm deduplication behavior.
## Link to repl or repo (highly encouraged)
Just run the script above in an empty folder.
## envinfo
<!--
Run npx envinfo --preset jest
Paste the results here:
-->
```
System:
OS: macOS 10.15.7
CPU: (8) x64 Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
Binaries:
Node: 14.17.3 - /usr/local/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 6.14.13 - /usr/local/bin/npm
npmPackages:
jest: 27.0.3 => 27.0.3
```
Cannot look more deeply into this at the moment. Could you install try installing @jest/fake-timers
in packages/nodes-base
and switch back to the legacy
implementation in the meantime?
1 Like