我正在尝试为lance-gg中的Renderer子类编写单元测试
// test/client.js
const lance = require('lance-gg');
console.log(lance);{
GameEngine: [Function: GameEngine],
GameWorld: [Function: GameWorld],
P2PhysicsEngine: [Function: P2PhysicsEngine],
SimplePhysicsEngine: [Function: SimplePhysicsEngine],
BaseTypes: [Function: BaseTypes] {
TYPES: {
FLOAT32: 'FLOAT32',
INT32: 'INT32',
INT16: 'INT16',
INT8: 'INT8',
UINT8: 'UINT8',
STRING: 'STRING',
CLASSINSTANCE: 'CLASSINSTANCE',
LIST: 'LIST'
}
},
TwoVector: [Function: TwoVector],
DynamicObject: [Function: DynamicObject],
PhysicalObject2D: [Function: PhysicalObject2D],
PhysicalObject3D: [Function: PhysicalObject3D],
ServerEngine: [Function: ServerEngine],
Lib: { Trace: [Function: Trace] }
}./node_modules/.bin/mocha --require @babel/register ./test/client.js但是,lance.Renderer解析为undefined,这使我怀疑lance是从服务器导出而不是从这里定义的客户机导出构建的:https://github.com/lance-gg/lance/blob/911b60bdb5b887aa281e7c968506028797616132/rollup.config.js
下面是一个现有测试的示例,它似乎可以正确地将客户端代码编译成测试:https://github.com/lance-gg/lance/blob/master/test/EndToEnd/multiplayer.js
我的问题是,要求(‘lance-gg’)如何知道是导入客户端还是服务器端
如何从客户端导出中编译测试?
发布于 2021-01-24 17:50:39
lance库对于客户端和服务器都是通用的,即使它是一个单独的包。两种可能的导入之间的差异是通过lance的package.json文件的main和browser属性实现的。
看看https://github.com/lance-gg/lance/blob/master/package.json和这两个属性。
在您的示例中,mocha需要指明它正在加载针对浏览器的包。听起来像是mocha正在获取主要的入口点。
请参阅https://docs.npmjs.com/cli/v6/configuring-npm/package-json#browser
https://stackoverflow.com/questions/65755989
复制相似问题