【发布时间】:2016-01-23 21:37:17
【问题描述】:
我正在尝试使用适当的测试和工具启动一个新项目 node.js。 我选择框架sails.js,我使用travis作为我的CI工具https://travis-ci.org/lomithrani/InteractiveResume。
我使用 npm 在我的 package.json 中使用这一行启动我的测试
"test": "mocha test/bootstrap.test.js test/unit/**/*.test.js"
bootstrap.test.js:
var Sails = require('sails'),
sails;
before(function (done) {
// Increase the Mocha timeout so that Sails has enough time to lift.
this.timeout(5000);
Sails.lift({
// configuration for testing purposes
}, function (err, server) {
sails = server;
if (err) return done(err);
// here you can load fixtures, etc.
done(err, sails);
});
});
after(function (done) {
// here you can clear fixtures, etc.
Sails.lower(done);
});
我用作样本的测试:
var request = require('supertest');
describe('ResumeController', function () {
console.log('test');
describe('#hi()', function () {
it('should say hi', function (done) {
request(sails.hooks.http.app)
.get('/resume/hi')
.expect(200, done);
});
});
});
所以如果我运行 npm test 或 travis 一切正常。但是在 Visual Studio 中运行它是行不通的。至于,据我了解,它只运行 *.test.js 而不是 bootstrap.test.js。我在sails.hooks.http.app 上遇到了一个未定义的错误,official doc from github.com/Microsoft 提供的配置方式非常少,只是我可以创建一个 mocha.json,比如这个:
{
"ui": "tdd",
"timeout": 300000,
"reporter": "xunit"
}
但我看不到可以使用https://mochajs.org/#usage 的哪个元素 为了首先执行引导程序。 如果您有任何解决方法建议或任何想法,我们非常欢迎。
这是我在视觉中得到的完整堆栈跟踪
Test Name: ResumeController #hi() should say hi
Test Outcome: Failed
Result StandardOutput:
1..1
not ok 1 ResumeController hi() should say hi
ReferenceError: sails is not defined
at Context.<anonymous> (C:\interactiveResume\test\unit\controllers\ResumeController.test.js:8:21)
at callFnAsync (C:\interactiveResume\node_modules\mocha\lib\runnable.js:306:8)
at Test.Runnable.run (C:\interactiveResume\node_modules\mocha\lib\runnable.js:261:7)
at Runner.runTest (C:\interactiveResume\node_modules\mocha\lib\runner.js:421:10)
at C:\interactiveResume\node_modules\mocha\lib\runner.js:528:12
at next (C:\interactiveResume\node_modules\mocha\lib\runner.js:341:14)
at C:\interactiveResume\node_modules\mocha\lib\runner.js:351:7
at next (C:\interactiveResume\node_modules\mocha\lib\runner.js:283:14)
at Immediate._onImmediate (C:\interactiveResume\node_modules\mocha\lib\runner.js:319:5)
# tests 1
# pass 0
# fail 1
【问题讨论】:
标签: node.js visual-studio sails.js mocha.js