Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 未找到磁带测试目录的节点js模块_Node.js_Testing_Npm_Tap - Fatal编程技术网

Node.js 未找到磁带测试目录的节点js模块

Node.js 未找到磁带测试目录的节点js模块,node.js,testing,npm,tap,Node.js,Testing,Npm,Tap,我的结构如下: src/examples/test_file.js src/test/example.test.js package.json: "scripts": { "test": "node ./test/*.test.js" }, 我已通过npm安装磁带-保存 我运行npm测试,得到: > node ./test/*.test.js module.js:328 throw err; ^ Error: Cannot find module '

我的结构如下:

src/examples/test_file.js
src/test/example.test.js
package.json:

  "scripts": {
    "test": "node ./test/*.test.js"
  },
我已通过
npm安装磁带-保存

我运行
npm测试
,得到:

> node ./test/*.test.js

module.js:328
    throw err;
    ^

Error: Cannot find module 'c:\src\test\*.test.js'
    at Function.Module._resolveFilename (module.js:326:15)
    at Function.Module._load (module.js:277:25)
    at Function.Module.runMain (module.js:430:10)
    at startup (node.js:141:18)
    at node.js:1003:3
npm ERR! Test failed.  See above for more details.
根据这一点:

对整个目录的测试应该只适用于节点包的全局安装。在不全局安装磁带的情况下,如何使上述功能正常工作

我正在使用node 5.4和windows 10

编辑:

这在Mac上很好,在linux构建服务器上也很好。我假设它与windows相关

如何设置其他文件以运行所有其他测试

一个选项是获取
test
目录中的文件列表,并对每个文件执行
节点
命令。假设下面是test.js,它将运行与指定模式匹配的每个文件

var fs = require('fs-extra')
  //child_process `exec` will let you normal bash-style executions
  //eg, exec('ls') is like programmatically entering the ls command
  //into a terminal window
  , exec = require("child_process").exec;

//callback for after our exec process finishes
function execCallback(error, stdout, stderr) { 
  console.log(stdout);
}
fs.readdir will give us a list of files in the current ('.') directory
var testFiles = fs.readdir('.', function(err, files){
  if (err){
    console.log('error reading files', err);
  }else{
    //use this regex to reduce the list of files to only those which
    //adhere to the pattern you specified using a wildcar "*.test.js"
    files.filter(function(file){
      return /^.*?\.test\.js/.test(file)
    })
    //filter returns the reduced array which is immediately passed to
    //this forEach loop which will use our `exec` command to execute
    //the shell command `node xxxxxx.test.js` for every file in the array we just created
    .forEach(function(testFile){
      exec('node ' + testFile, execCallback);
    });
  }
});
尝试使用对“磁带”而不是“节点”的调用更新脚本语句 npm将在本地安装的./node_moduels/.bin/tape中找到磁带
无需通过节点发送

您不必在单个文件中导入所有测试。您可以使用
tape
命令和shell的globbing(文件扩展):

tape test/**/*.test.js
或者使用磁带的内置globbing:

tape 'test/**/*.test.js'
这仅在磁带位于路径中时有效(package.json中的脚本会将node_modules/.bin添加到路径中)。否则,您必须提供磁带的路径:

node_modules/.bin/tape test/**/*.test.js

拥有一个主测试文件
main.test.js
,并使用
require
运行所有其他测试文件<代码>节点
不能运行多个文件。它正在寻找一个名为
*.test.js
@usandfriends的文件,我如何设置另一个文件来运行所有其他测试?我不明白。我主要是一个java/c的家伙,所以这个js有点超出了我的想象me@user3574076我在代码中添加了很多注释。这是否消除了混淆?确实如此,但fs extra和child_进程来自何方?您需要安装它们,可能是通过npm。它们将作为依赖项添加到您的项目中,您可以在任何其他节点文件中要求它们。@user3574076这对您有意义吗?
node_modules/.bin/tape test/**/*.test.js