摩卡:如何添加代码块(testing为函数/string),而不是mocha.addFile

我以编程方式使用Mocha,并在有关如何添加testing文件的链接中详细介绍了这些内容,但是我已经将以db为单位的testing保存为string。 有没有一种方法,我可以直接将它们添加为string/函数,而不是创build临时缓冲区,并将它们添加为文件?

//write my tests stored as strings into filesystem fs.writeFile("tempdir", myTest, function(err) { if(err) { return; } }); var mocha = new Mocha; // Then, you need to use the method "addFile" on the mocha // object for each file. // Here is an example: fs.readdirSync('tempdir').filter(function(file){ // Only keep the .js files return file.substr(-3) === '.js'; }).forEach(function(file){ // Use the method "addFile" to add the file to mocha mocha.addFile( path.join('some/dir', file) ); //remove the test created in tempdir