gpt4 book ai didi

testing - 如何测试服务器端 debugOnly 包

转载 作者:行者123 更新时间:2023-11-28 20:40:42 24 4
gpt4 key购买 nike

我不明白如何测试 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 也没有在项目中导出。

来自 https://github.com/meteor/meteor/blob/0f0c5d3bb3a5492254cd0843339a6716ef65fce1/tools/isobuild/compiler.js

// 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com