-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
getVersion is not defined #7704
Comments
I can't repro the error. Can you share what you executed when it crashed? |
Not sure what's happening, but one thing that's bitten me before is mismatching Make sure to not have both |
Our setup is somewhat complex, I basically ran But regardless of how I ran it and what my setup is, why should it work at all? What breaks the cyclic reference between |
|
I 100% agree it's not ideal, of course 🙂 |
@SimenB stepping through the transpiled code, it seems like nodejs is first executing 'use strict';
var _package = require('../package.json');
var _SearchSource = _interopRequireDefault(require('./SearchSource'));
var _TestScheduler = _interopRequireDefault(require('./TestScheduler'));
var _TestWatcher = _interopRequireDefault(require('./TestWatcher'));
var _cli = require('./cli'); // === here ===
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {default: obj};
}
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
// === this is not executed yet ===
module.exports = {
SearchSource: _SearchSource.default,
TestScheduler: _TestScheduler.default,
TestWatcher: _TestWatcher.default,
getVersion: () => _package.version,
run: _cli.run,
runCLI: _cli.runCLI
};
Where it then descends into function _asyncToGenerator(fn) {
return function() {
var self = this,
args = arguments;
return new Promise(function(resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, 'next', value);
}
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, 'throw', err);
}
_next(undefined);
});
};
}
const _require = require('../jest'),
getVersion = _require.getVersion;
// === at this point, `_require` equals `{}`, so getVersion is undefined. ===
function run(_x, _x2) {
return _run2.apply(this, arguments);
} Clearly, here, it then crashes: const buildArgv = (maybeArgv, project) => {
const version =
getVersion() + // === getVersion is still undefined ===
(__dirname.includes(`packages${_path().default.sep}jest-cli`)
? '-dev'
: '');
// [...] |
Not sure what's going on - I'm unable to reproduce. $ mkdir 24
$ cd 24
$ yarn init -y
# ...
$ yarn add jest
# ...
$ yarn jest --version
yarn run v1.13.0
$ /Users/simen/24/node_modules/.bin/jest --version
24.0.0 So a reproduction would be awesome! It might very well be that |
We need |
However, installing $ yarn add ts-node typescript
$ npx ts-node node_modules/.bin/jest --version
24.0.0 |
Further debugging showed that the issue is the order in which the modules are loaded. If jest/cli/index is loaded first, everything works. If jest/jest.js is loaded first, it crashes due to the described reasons. I am currently investigating why jest/jest.js is loaded before jest/cli/index in our setup. Anyways, code should not break if it is loaded in a different order than the default case, especially if the order is up to the caller of the API. |
For reference: Whatever the circumstances this appears under may be, reason why it started showing in v24 is this PR. |
I'm running into this same error but only when running jest programmatically ( |
Thank you, we also run it programmatically. That seems to be it. |
Ah, ok. We need #7696 😅 I'll put together a PR |
@SimenB thank you for your help :) |
@SimenB Is there a workaround for 24 or is this likely something we won't see until 25 or 24.1? |
Sounds good. Thanks! |
Does anyone know why it breaks when running it like that though? Don't think I've seen something like this happening because of cyclic dependencies before |
It breaks when |
@jeysal see my in-detail explanation above what happens and why it breaks. |
Oh I see now... |
@SimenB it doesn't even work with a workaround 😢 > node scripts/test.js
TypeError: getVersion is not a function
at buildArgv (~\node_modules\jest\node_modules\jest-cli\build\cli\index.js:399:5)
at Object.<anonymous> (~\node_modules\jest\node_modules\jest-cli\build\cli\index.js:243:20)
at Generator.next (<anonymous>)
at asyncGeneratorStep (~\node_modules\jest\node_modules\jest-cli\build\cli\index.js:202:24)
at _next (~\node_modules\jest\node_modules\jest-cli\build\cli\index.js:222:9)
at ~\node_modules\jest\node_modules\jest-cli\build\cli\index.js:227:7
at new Promise (<anonymous>)
at Object.<anonymous> (~\node_modules\jest\node_modules\jest-cli\build\cli\index.js:219:12)
at Object._run2 (~\node_modules\jest\node_modules\jest-cli\build\cli\index.js:265:16)
at Object.run (~\node_modules\jest\node_modules\jest-cli\build\cli\index.js:236:16) |
Weird. The workaround worked fine for me. |
@bricss what does |
@SimenB technically, as I know, it was created by create-react-app version P.S.: |
How are you applying the workaround then, if you haven't updated the file? |
@SimenB I meant it wasn't touched by anyone before me. I placed imports exact in same order as was suggested. |
Hey @SimenB, is this released as part of Also, I can confirm that #7704 (comment) worked for me |
The fix #7707 is not yet released. |
I kinda don't wanna rush anyone, but maybe it's time to let it go with version |
Battlefield news: 📰 I have managed to start Jest by adding those lines into the // jest v24.0 workaround
require('jest/node_modules/jest-cli/build/cli');
require('jest').run(argv); After, when I'm start Jest to run all over the tests, it shows this: No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In C:\<projectPath>
49 files checked.
testMatch: <projectPath>/src/**\?(*.)(spec|test).{js,jsx,ts,tsx} - 0 matches
testPathIgnorePatterns: \\node_modules\\ - 49 matches
testRegex: - 49 matches
Pattern: - 0 matches Unable to locate any of the test files. 🔍 |
I had the same experience as @bricss. |
To break the dependency cycle, we can delete the module cache and require it again in delete require.cache[require.resolve('jest-cli/build/cli/index.js')];
const cli = require('jest-cli/build/cli/index.js'); |
24.1.0 is released |
The workaround was needed because jest 24.0 had a dependency cycle and therefore was problematic to import and use programatically. See jestjs/jest#7704. This closes #25.
jestjs/jest#7704 was resolved in a new version of jest
…moved jestjs/jest#7704 was resolved in a new version of jest
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
🐛 Bug Report
Jest v24 crashes with "getVersion" is not defined.
To Reproduce
See source code.
Expected behavior
Jest does not crash.
Issue in source
This line requires
cli
.But
cli
itself requiresjest
here. Clearly,getVersion
is not exported at this point.Run
npx envinfo --preset jest
Paste the results here:
The text was updated successfully, but these errors were encountered: