Webpack umd似乎打破了stacktrace-js的功能

时间:2016-05-20 15:29:41

标签: webpack uglifyjs2 umd stacktrace.js logary

我们正在尝试将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]

this branch上我尝试禁用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获取此输出:

stacktrace-js enricher for logary-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);

0 个答案:

没有答案