[英]How does lance-gg know whether to load the client
I am trying to write a unit test for a Renderer subclass from lance-gg我正在尝试为 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
However, lance.Renderer
resolves to undefined, which leads me to suspect that somehow lance is building from the server exports rather than the client exports defined here: https://github.com/lance-gg/lance/blob/911b60bdb5b887aa281e7c968506028797616132/rollup.config.js但是, lance.Renderer
解析为未定义,这使我怀疑 lance 是从服务器导出而不是此处定义的客户端导出构建的: https://github.com/lance-gg/lance/blob/911b60bdb5b887aa281e7c968506028797616132/rollup .config.js
Here is an example of an existing test that seems to compile the client-side code into the test properly: https://github.com/lance-gg/lance/blob/master/test/EndToEnd/multiplayer.js这是一个现有测试的示例,它似乎可以将客户端代码正确地编译到测试中: https://github.com/lance-gg/lance/blob/master/test/EndToEnd/multiplayer.js
My question is, how does require('lance-gg') know whether to import the client-side or server-side我的问题是, require('lance-gg') 如何知道是导入客户端还是服务器端
How do I get the test to compile from the client-side exports instead?如何从客户端导出中编译测试?
The lance library is common to both client and server, even though it is a single package. lance 库对客户端和服务器都是通用的,即使它是单个 package。 The way the differentiation happens between the two possible imports is through the main
and browser
attributes of lance's package.json file.两种可能的导入之间发生差异的方式是通过 lance 的 package.json 文件的main
属性和browser
属性。
Take a look at https://github.com/lance-gg/lance/blob/master/package.json and at those two attributes.看看https://github.com/lance-gg/lance/blob/master/package.json和这两个属性。
In your case, mocha needs to indicate that it is loading the browser-intended package.在您的情况下,mocha 需要表明它正在加载浏览器预期的 package。 It sounds like mocha is fetching the main entry point.听起来 mocha 正在获取主要入口点。
See https://docs.npmjs.com/cli/v6/configuring-npm/package-json#browser请参阅https://docs.npmjs.com/cli/v6/configuring-npm/package-json#browser
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.