Project use typescript, try to add test for my code use three according to Testing-with-NPM Testing-with-NPM
Use mocha. it works great with following code
following is test.ts
import * as THREE from 'three';
// import { ConvexHull } from 'three/examples/jsm/math/ConvexHull.js';
const assert = require('assert');
describe('The THREE object', function() {
it('should have a defined BasicShadowMap constant', function() {
assert.notEqual('undefined', THREE.BasicShadowMap);
}),
it('should be able to construct a Vector3 with default of x=0', function() {
const vec3 = new THREE.Vector3();
assert.equal(0, vec3.x);
// let cc = new ConvexHull();
})
})
but when i uncomment following code and use ConvexHull
import * as THREE from 'three';
import { ConvexHull } from 'three/examples/jsm/math/ConvexHull';
I got a error
Error: Cannot find module ‘D:\xxx\node_modules\three\examples\jsm\math\ConvexHull’
I got a error Error: Cannot find module ‘D:\xxx\node_modules\three\examples\jsm\math\ConvexHull’
I also try to add extension of ConvexHull file
const ConvexHull = require('three/examples/jsm/math/ConvexHull.js');
then got a diffrent error:
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension “.ts” for D:\xxx_test_\test.ts
at new NodeError (node:internal/errors:387:5)
at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:75:11)
Use any class under node_modules\three\examples\jsm. Got the sameerror: Cannot find module error or ERR_UNKNOWN_FILE_EXTENSION.
Don’t know how to solve it. any ideas would be appreciated, thanks.