[英]Mocha not recognizing CoffeeScript/JS test when adding programatically
I am trying to add mocha to an existing project. 我正在尝试将摩卡咖啡添加到现有项目中。 I have the following test just for putting things together...
我进行以下测试只是为了将它们放在一起...
assert = require('assert');
describe 'Array', ->
describe '#indexOf()', ->
it 'should return -1 when the value is not present', ->
assert.equal(-1, [1,2,3].indexOf(4));
Options... 选项...
--compilers coffee:coffee-script/register
Then I run mocha --opts ./mocha.opts src/test/coffee/test/test.coffee
and I see 然后我运行
mocha --opts ./mocha.opts src/test/coffee/test/test.coffee
我看到
1 passing (6ms)
1次通过(6毫秒)
Now I try to create a runner file to handle 现在,我尝试创建一个运行程序文件来处理
globFlat = require('glob-flat');
Mocha = require('mocha');
mocha = new Mocha();
files = globFlat.sync([
'src/test/coffee/test/test.coffee'
]);
mocha.addFile file for file in files
mocha.run();
And run mocha --opts ./mocha.opts src/test/mocha/mocha-runner.coffee
I get 并运行
mocha --opts ./mocha.opts src/test/mocha/mocha-runner.coffee
我得到
0 passing (0ms)
0通过(0ms)
So why is it not finding the test? 那么为什么找不到测试呢?
Update 更新资料
I have also converted everything over to JS to ensure it wasn't an issue with CS and I am getting the same thing... 我也已经将所有内容都转换为JS以确保它不是CS的问题,而且我得到了同样的东西...
require('coffee-script');
var globFlat = require('glob-flat');
var Mocha = require('mocha');
var mocha = new Mocha();
mocha.addFile('src/test/coffee/test/test.js');
runner = mocha.run();
console.log("Done");
It runs like this... 它像这样运行
mocha src/test/mocha/mocha-runner.js
Done
0 passing (0ms)
Update 2 更新2
Ok so it appears I should be using node and not mocha for running it. 好的,所以看来我应该使用node而不是mocha来运行它。 This presents a problem as the .js version works but the .coffee version throws an error...
这是一个问题,因为.js版本可以使用,但是.coffee版本会引发错误...
(function (exports, require, module, __filename, __dirname) { require 'coffee-script';
^^^^^^^^^^^^^^^
SyntaxError: Unexpected string
Because node cannot recognize the coffeescript 因为节点无法识别咖啡脚本
I am going to post this up here as an answer, although I don't like it... 我将在此处将其发布为答案,尽管我不喜欢它...
mocha-wrapper.js mocha-wrapper.js
require('coffee-script/register');
require('./mocha-runner.coffee');
mocha-runner.coffee 摩卡咖啡
globFlat = require 'glob-flat';
Mocha = require 'mocha';
mocha = new Mocha();
files = globFlat.sync([
'src/test/coffee/test/test.coffee'
]);
mocha.addFile file for file in files
mocha.run();
I would like to avoid the multiple files but for now it looks like I am stuck :-/. 我想避免使用多个文件,但现在看来我被卡住了:-/。 That is why I am going to wait to accept my answer.
这就是为什么我要等待接受我的回答。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.