作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我不明白如何测试 debugOnly 包。我的 package.js
非常简单:
Package.describe({
name: 'lambda',
version: '0.0.1',
debugOnly: true // Will not be packaged into the production build
});
Package.onUse(function(api) {
api.versionsFrom('1.2.1');
api.addFiles('lambda.js');
api.export("Lambda", 'server');
});
Package.onTest(function(api) {
api.use('tinytest');
api.use('lambda');
api.addFiles('lambda-tests.js', 'server');
});
我的 lambda-test.js
:
Tinytest.add('example', function (test) {
test.equal(Lambda.func(), true);
});
我的 lambda.js
:
Lambda = {
func: function() {
return "Christmas";
}
}
当我运行 meteor test-packages
时,它只是失败了:Lambda is not defined. 如果我删除 debugOnly: true
测试经过。那么如何使用 tinytest 测试我的包呢?或者这是一个错误!
最佳答案
我遇到了同样的问题!事实证明测试工作正常。 Lambda 也没有在项目中导出。
// don't import symbols from debugOnly and prodOnly packages, because
// if the package is not linked it will cause a runtime error.
// the code must access them with `Package["my-package"].MySymbol`.
尝试:
Tinytest.add('example', function (test) {
//also changed expected value from true to Christmas to make test pass
test.equal(Package['lambda']['Lambda'].func(), "Christmas");
//you can use Package['lambda'].Lambda as well, but my IDE complains
});
现在你可以这样做:
if (Package['lambda']) {
console.log("we are in debug mode and we have lamda");
console.log("does this say Christmas? " + Package['lambda']["Lambda"]['func']());
} else {
console.log("we are in production mode, or we have not installed lambda");
}
关于testing - 如何测试服务器端 debugOnly 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34157639/
我不明白如何测试 debugOnly 包。我的 package.js 非常简单: Package.describe({ name: 'lambda', version: '0.0.1',
我是一名优秀的程序员,十分优秀!