0
正在努力让项目从Mocha过渡到Jest,以利用运行测试的速度以及Jest框架本身的速度,并且遇到问题。 Rewire在代码库中使用相当广泛,我在运行gulp-jest任务时遇到问题,对于那些使用rewire的文件,只有只有。我认为它与模块加载或不加载有关,但我很难过。这是真正的骨头吞咽任务,没有太多的东西。我已经在代码库上运行了一个广泛的代码模式,许多测试都通过了,而不是那些使用rewire的测试。集成Jest和Rewire
gulp.task('jest', function() {
process.env.NODE_ENV = 'test';
return gulp.src('name/path').pipe(
jest({
preprocessorIgnorePatterns: ['<rootDir>/node_modules/'],
automock: false,
resetModules: true,
setupFiles: ['./jestsetup.js']
})
);
});
gulp.task('newtest', function(callback) {
runSequence('env', 'jest', callback);
});
任何时候rewire相关的文件运行,他们抱怨文件没有被发现。我在这里错过了什么吗?我确定模块本身具有为require
设置的正确路径。
下面是开玩笑实际的错误/重新连接:
FAIL path/to/folder/file/app.test.js
● Test suite failed to run
Cannot find module '../../../../path/to/folder/file/app'
at Function.Module._resolveFilename (module.js:469:15)
at internalRewire (node_modules/rewire/lib/rewire.js:23:25)
at rewire (node_modules/rewire/lib/index.js:11:12)
at Object.<anonymous (path/to/folder/file/app.test.js:10:14)
at process._tickCallback (internal/process/next_tick.js:109:7)
使用节点6.X,开玩笑20.x
提前感谢!
权而采取的,我明白,但有周围没有任何办法吗?我们严重地使用重新连线,并且使用jest的嘲讽工具重新编写文件并不重要。想知道如果我可以动态dontMock的东西,绕过JEST? – markthethomas
*我相信现在是'unmock' – markthethomas
也许你可以使用'rewire'的猴子补丁,编写你自己的“rewire”函数,在内部它将使用jest.mock。 把它放在jest.setup文件https://jest-bot.github.io/jest/docs/configuration.html#setuptestframeworkscriptfilefile-string – felixmosh