Code Monkey home page Code Monkey logo

Comments (7)

cliren avatar cliren commented on June 3, 2024

Any update on this? Or has anyone been successful with any other plugin to print the correct stack trace?

from gulp-jsx-coverage.

zordius avatar zordius commented on June 3, 2024

Sorry for missing this issue, can you provide a sample stack trace? thanks.

from gulp-jsx-coverage.

cliren avatar cliren commented on June 3, 2024

Here is an example I have setup to demonstrate the issue. When a test fails unable to trace to the correct line number from the stack trace. All tests ending with .jsx seems to work fine but not any other extension. I tried including multiple extensions in the babel options but that didn't work. Please advise!

https://github.com/cliren/react-jsx-coverage-example

/usr/local/bin/node /Users/user1/project/react/react-jsx-coverage-example/node_modules/gulp/bin/gulp.js --color --gulpfile /Users/user1/project/react/react-jsx-coverage-example/gulpfile.js test
  [10:02:44] Using gulpfile ~/project/react/react-jsx-coverage-example/gulpfile.js
  [10:02:44] Starting 'test'...


Util
1) should add two numbers

UserProfileLink
2) should render link


0 passing (28ms)
2 failing

1) Util should add two numbers:

  AssertionError: expected 4 to equal 5
+ expected - actual

-4
+5

at Assertion.fail (/Users/user1/project/react/react-jsx-coverage-example/node_modules/should/lib/assertion.js:196:17)
at Assertion.prop.(anonymous function) [as eql] (/Users/user1/project/react/react-jsx-coverage-example/node_modules/should/lib/assertion.js:81:17)
at Context.<anonymous> (/Users/user1/project/react/react-jsx-coverage-example/src/__tests__/util_spec.js:9:833)
TRANSPILED: var _should2 = _interopRequireDefault(_should);
at callFn (/Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runnable.js:286:21)
at Test.Runnable.run (/Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runnable.js:279:7)
at Runner.runTest (/Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runner.js:421:10)
at /Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runner.js:528:12
at next (/Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runner.js:341:14)
at /Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runner.js:351:7
at next (/Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runner.js:283:14)

2) UserProfileLink should render link:

  AssertionError: expected 'My Profile' to equal 'My Profile2'
+ expected - actual

-My Profile
+My Profile2

at Assertion.fail (/Users/user1/project/react/react-jsx-coverage-example/node_modules/should/lib/assertion.js:196:17)
at Assertion.prop.(anonymous function) [as eql] (/Users/user1/project/react/react-jsx-coverage-example/node_modules/should/lib/assertion.js:81:17)
at Context.<anonymous> (/Users/user1/project/react/react-jsx-coverage-example/src/react-components/__tests__/UserProfileLink_spec.jsx:26:28)
at callFn (/Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runnable.js:286:21)
at Test.Runnable.run (/Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runnable.js:279:7)
at Runner.runTest (/Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runner.js:421:10)
at /Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runner.js:528:12
at next (/Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runner.js:341:14)
at /Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runner.js:351:7
at next (/Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runner.js:283:14)



[10:02:45] 'test' errored after 603 ms
  [10:02:45] Error in plugin 'gulp-mocha'
Message:
  2 tests failed.

=============================== Coverage summary ===============================
  Statements   : 100% ( 12/12 )
Branches     : 75% ( 3/4 )
Functions    : 100% ( 4/4 )
Lines        : 100% ( 11/11 )
================================================================================

Process finished with exit code 1

from gulp-jsx-coverage.

zordius avatar zordius commented on June 3, 2024

Thank you for your sample project! I just reviewed the project I found the behavior is as my expectation.

  1. for test case 1, gulp-jsx-coverage found the util_spec.js is in the transpiled mapping table and try to recover the original line by source-map. But, in the source-map we can not know the original line for line 9, so gulp-jsx-coverage just hint the transpiled code as TRANSPILED: var _should2 = _interopRequireDefault(_should); without ORIGINALSRC: ..... .
  2. for test case 2, gulp-jsx-coverage can not find the UserProfileLink_spec.jsx in the transpiled mapping table. There are 2 issues in this projects:
    1. https://github.com/cliren/react-jsx-coverage-example/blob/master/gulpfile.js#L12 You used a module loader hook, so some transpile works are done by the hook but not by gulp-jsx-coverage. Remove line 12 then all related files can be transpiled properly by gulp-jsx-coverage.
    2. https://github.com/cliren/react-jsx-coverage-example/blob/master/src/react-components/__tests__/UserProfileLink_spec.jsx#L3 You should require full name of the module when it is not .js file. Try to fix this line to:
import UserProfileLink from '../UserProfileLink.jsx';

Then gulp-jsx-coverage can work better with the test file. A better hint will appears in the stack trace:

  TRANSPILED: var _reactLibReactTestUtils = require('react/lib/ReactTestUtils');

But, again, the original line number is not defined in the sourceMap, so you can not see ORIGINALSRC: .....

Please also refer to https://github.com/zordius/gulp-jsx-coverage#best-practices

And, both test case throws by the assert or should , in most case the stack trace will not related with test target. If there is some wrong in test target and throws there, you will see a better stack trace and gulp-jsx-coverage works better.

from gulp-jsx-coverage.

cliren avatar cliren commented on June 3, 2024

I removed module loader hook and referencing full file name for .jsx files and using just gulp-jsx-coverage as documented. Now every failure points to line#9 instead of the actual line. If I use plain gulp-mocha with module loader hook, I get the actual line numbers. I do like the simplicity of gulp-jsx-coverage but without the correct stack trace its hard to use it. Please let me know what I am missing or is that the expected behavior of this plugin?

/Users/user1/.nvm/versions/node/v5.1.0/bin/node /Users/user1/project/react/react-jsx-coverage-example/node_modules/gulp/bin/gulp.js --color --gulpfile /Users/user1/project/react/react-jsx-coverage-example/gulpfile.js test
  [10:01:45] Using gulpfile ~/project/react/react-jsx-coverage-example/gulpfile.js
  [10:01:45] Starting 'test'...


Util
1) should add two numbers

UserProfileLink
2) should render link


0 passing (24ms)
2 failing

1) Util should add two numbers:

  AssertionError: expected 4 to equal 5
+ expected - actual

-4
+5

at Assertion.fail (/Users/user1/project/react/react-jsx-coverage-example/node_modules/should/lib/assertion.js:196:17)
at Assertion.prop.(anonymous function) [as eql] (/Users/user1/project/react/react-jsx-coverage-example/node_modules/should/lib/assertion.js:81:17)
at Context.<anonymous> (/Users/user1/project/react/react-jsx-coverage-example/src/__tests__/util_spec.js:9:833)
TRANSPILED: var _should2 = _interopRequireDefault(_should);
at callFn (/Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runnable.js:286:21)
at Test.Runnable.run (/Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runnable.js:279:7)
at Runner.runTest (/Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runner.js:421:10)
at /Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runner.js:528:12
at next (/Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runner.js:341:14)
at /Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runner.js:351:7
at next (/Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runner.js:283:14)

2) UserProfileLink should render link:

  AssertionError: expected 'My Profile' to equal 'My Profile2'
+ expected - actual

-My Profile
+My Profile2

at Assertion.fail (/Users/user1/project/react/react-jsx-coverage-example/node_modules/should/lib/assertion.js:196:17)
at Assertion.prop.(anonymous function) [as eql] (/Users/user1/project/react/react-jsx-coverage-example/node_modules/should/lib/assertion.js:81:17)
at Context.<anonymous> (/Users/user1/project/react/react-jsx-coverage-example/src/react-components/__tests__/UserProfileLink_spec.jsx:9:2731)
TRANSPILED: var _reactLibReactTestUtils = require('react/lib/ReactTestUtils');
at callFn (/Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runnable.js:286:21)
at Test.Runnable.run (/Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runnable.js:279:7)
at Runner.runTest (/Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runner.js:421:10)
at /Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runner.js:528:12
at next (/Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runner.js:341:14)
at /Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runner.js:351:7
at next (/Users/user1/project/react/react-jsx-coverage-example/node_modules/mocha/lib/runner.js:283:14)



[10:01:46] 'test' errored after 534 ms
  [10:01:46] Error in plugin 'gulp-mocha'
Message:
  2 tests failed.

=============================== Coverage summary ===============================
  Statements   : 83% ( 83/100 )
Branches     : 58% ( 29/50 )
Functions    : 100% ( 19/19 )
Lines        : 100% ( 52/52 )
================================================================================

Process finished with exit code 1

from gulp-jsx-coverage.

zordius avatar zordius commented on June 3, 2024

The line number goes wrong after istanbul instrument the code, so we can prevent this issue by updating istanbul config https://github.com/cliren/react-jsx-coverage-example/pull/1/files#diff-b9e12334e9eafd8341a6107dd98510c9R26 (line 26). And, I also found an old bug about source map line number, I already fixed it and released a new version of gulp-jsx-coverage. (v0.3.3) Please try it, thanks.

from gulp-jsx-coverage.

zordius avatar zordius commented on June 3, 2024

The line 9 issue is caused by istanbul, any instrumented code will error at line 9, please refer to gotwarlost/istanbul#274 . This should be fixed in future istanbul version.

from gulp-jsx-coverage.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.