1.问题
当我试图在vscode中使用mocha-debug进行调试的时候,就会发现一段时间在命令行中就会报错,报错信息如下
Assertion failed: (object->InternalFieldCount() > 0), function Unwrap, file ../node_modules/nan/nan_object_wrap.h, line 33.
2.相关代码
测试文件
'use strict';
const { rootPath, testConfig, testLogger, wait } = _testHelper;
const Canvas = require('canvas');
const co = require('co');
const should = require('should');
const picFunc = require(`${rootPath}/utils/text2pic`);
const Image = Canvas.Image;
describe('小黄图生成图片测试', () => {
it('测试生成图片方法', () => {
return co(function*(){
let testLogger = {
info: console.log.bind(null)
};
let mPic = picFunc(testLogger, testConfig);
let novelList = require('./data.json').novels;
let novel = novelList[1];
novel.qrcodeUrl = `${rootPath}/img-dirs/yellow-pic/qrcodes/1.png`;
// let qrcodeImg = new Image(`${rootPath}/img-dirs/img-tpls/common/0 二胎政策创始人.jpg`);
let qrcodeImg = new Image(novel.qrcodeUrl);
novel.username = '谷阿莫';
let path = yield mPic.toPic(novel);
console.log(path);
});
});
mocha命令
"mocha-debug": "NODE_ENV=test mocha tests/utils/text2pic/test.js -r ./tests/helper.js -R spec --debug-brk",
3.重现过程:
随意打若干断点
使用
npm run mocha-debug
命令后,在vscode中启动单元测试执行报错信息出现,查了一下核心模块
nan_object_wrap.h
代码如下:
template <class T>
static inline T* Unwrap(v8::Local<v8::Object> object) {
assert(!object.IsEmpty());
assert(object->InternalFieldCount() > 0);
// Cast to ObjectWrap before casting to T. A direct cast from void
// to T won't work right when T has more than one base class.
void* ptr = GetInternalFieldPointer(object, 0);
ObjectWrap* wrap = static_cast<ObjectWrap*>(ptr);
return static_cast<T*>(wrap);
}
4.已经尝试的解决方案
更换图片地址
将有关picFunc图片处理函数的代码段全部注释掉
Google查询
应该是给native code或者原本应该是类的东西赋值成别的了。
也有可能是某些参数需要的接口是对象,但是没正确的传递