我们正在尝试将 stacktrace-js 与很棒的 logary-js(我的项目)一起使用,但是在通过 webpack 之后,它似乎不再起作用了。
这是 webpack 的配置https://github.com/logary/logary-js/blob/c7fdec752e5ce33843d458e9e6c590657005c60a/webpack.config.js
这是让我担心的输出(npm run build
):
> logary@2.0.2 build /Users/h/dev/haf/logary-js
> NODE_ENV=production webpack --progress --color --display-error-details --display-reasons --optimize-minimize
Hash: d1c4b6913d586c4424ce
Version: webpack 1.13.0
Time: 2263ms
Asset Size Chunks Chunk Names
logary.js 55.2 kB 0 [emitted] logary
logary.js.map 407 kB 0 [emitted] logary
+ 19 hidden modules
WARNING in logary.js from UglifyJs
Side effects in initialization of unused variable promise [./src/index.js:357,8]
Side effects in initialization of unused variable Targets [./src/index.js:382,13]
Dropping side-effect-free statement [./~/jssha/src/sha.js:12,0]
Condition always true [./~/jssha/src/sha.js:37,116]
Condition always true [./~/stacktrace-js/stacktrace.js:6,0]
Dropping unreachable code [./~/stacktrace-js/stacktrace.js:8,5]
Condition always true [./~/error-stack-parser/error-stack-parser.js:6,0]
Dropping unreachable code [./~/error-stack-parser/error-stack-parser.js:8,5]
Condition always true [./~/stackframe/stackframe.js:6,0]
Dropping unreachable code [./~/stackframe/stackframe.js:8,5]
Condition always true [./~/stack-generator/stack-generator.js:6,0]
Dropping unreachable code [./~/stack-generator/stack-generator.js:8,5]
Condition always true [./~/stacktrace-gps/stacktrace-gps.js:6,0]
Dropping unreachable code [./~/stacktrace-gps/stacktrace-gps.js:8,5]
在这个分支上,我尝试禁用 UglifyJs 无济于事。
npm run test
给出这个输出(剪断):
stacktrace enricher
✓ should be a function
✓ should accept a message and return a function
✓ passes through messages without errors
✓ parses errors in generated errors (385ms)
✓ should parse errors into stack traces
所以看起来开发中的 webpack-mocha 集成工作得很好。但是,当我在发布后使用其他 JS 的 logary 时,我会从 stacktrace-js 获得以下输出:
当它应该完成这些单元测试时(当我运行 mocha 时会这样做,但在我在浏览器中运行时不会这样做):
const stacktrace = Middleware.stacktrace
// snip
it('passes through messages without errors', function() {
const msg = Message.event('Signup');
const res = stacktrace(logger)(msg);
expect(res.value.event).to.equal('Signup');
expect(res.level).to.equal('info');
expect(res.fields).to.deep.equal({});
expect(res.context).to.deep.equal({
logger: 'AreaX.ComponentA',
service: 'MyWebSite'
});
});
it('parses errors in generated errors', function(done) {
const msg = Message.eventError('Uncomfortable Error', error);
const subjectMsg = stacktrace(logger)(msg);
expect(expect(subjectMsg).to.eventually.be.fulfilled.then(msg => {
expect(msg.fields).to.be.an('object');
expect(msg.fields.errors).to.have.lengthOf(1);
expect(msg.fields.errors[0]).to.not.equal(error);
expect(msg.fields.errors[0]).to.be.an('Array');
})).to.notify(done);
});
it('should parse errors into stack traces', function(done) {
const msg = Message.eventError('Uncomfortable Error', error, {
myField: 'abc'
}),
actual = stacktrace(logger)(msg).then(x => x.fields);
expect(expect(Promise.all([
actual,
StackTrace.fromError(error)
])).to.eventually.be.fulfilled.then(([actualFields, expectedError]) => {
expect(actualFields.errors[0]).to.deep.equal(expectedError);
expect(actualFields.myField).to.equal('abc');
})).to.notify(done);