How to run mocha tests with webpack when you don't have a single entry point to tests?
我正在尝试将项目从
webpack文档演示了如何使用
所有现有测试在设计时都考虑了
下面的设置适合??我。它仍然使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | var path = require("path"); var child_process = require('child_process'); module.exports = { entry: { tests:"./tests.js" }, output: { filename:"tests.js", // Should be a unique name path:"/tmp" }, plugins: [ // Automatically run all tests when webpack is done function () { this.plugin("done", function (stats) { child_process.execSync('mochify /tmp/tests.js', { stdio: 'inherit'}); }); } ], }; |
1 2 3 4 5 6 7 8 | // List all test dirs here if you have multiple var contexts = [ require.context('./dir1/test', true, /\\.js$/), require.context('./dir2/test', true, /\\.js$/) ]; contexts.forEach(function (context) { context.keys().forEach(context); }); |
此处介绍了另一种方法:https://stackoverflow.com/a/32386750/675011
这不是一个确切的答案,但是它为我解决了这个问题。我想结合使用mochify和webpack的原因是我想使用浏览器控制台调试我的mocha测试。由于我的Mocha测试本身不依赖浏览器,因此我终于意识到我可以使用节点调试器,它可以启动Chrome控制台,(几乎)解决了我的问题。 node-inspector是节点调试器,但是我使用的是babel,所以我需要babel-node-debug,但是现在还不能与babel6一起使用,但是有一个未合并的pull请求可以修复它:https:// github。 com / CrabDude / babel-node-debug / pull / 12。