如何测试服务器端 debugOnly 包
How to test a server side debugOnly package
我不明白如何测试 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 未定义。 如果我删除 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");
}
我不明白如何测试 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 未定义。 如果我删除 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");
}