Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: invalid error callstacks and coverage reports in tests for components. #3147

Closed
3 tasks done
paladin80 opened this issue Nov 19, 2021 · 12 comments
Closed
3 tasks done
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil

Comments

@paladin80
Copy link

paladin80 commented Nov 19, 2021

Prerequisites

Stencil Version

2.10.0 - 2.11.0

Current Behavior

When running tests in stencil, any error callstacks and coverage report don't match the source code.

Expected Behavior

Error callstacks should point exactly to the line of TS code, where the error happened. Jest coverage report files should properly highlight source files.

Expected behavior was fullfilled in older stencil versions.

Steps to Reproduce

For call stacks:

  1. npm init stencil, choose component. Or just download the stencil-component-starter.
  2. npm install
  3. Open utils.ts and add a throwing code to line 2. Example: '1'.d();
  4. npm test
  5. Note the error output of tests: TypeError: "1".d is not a function
    at Object.format (src/utils/utils.ts:308:7)
    at Object. (src/utils/utils.spec.ts:15:20)
  6. The callstack points to line 308 of the utils.ts, but this file has less than 10 lines of code.
  7. The callstack points to line 15 of utils.spec.ts, which is an empty line.

For coverage:

  1. As in previous steps, install stencil-component-starter.
  2. Open utils.ts and add a false if statement with some code:
    if (1 == 2) {
    first = middle;
    }
  3. Run stencil test --spec --coverage
  4. Note that created coverage report has invalid highlighting for the utils.ts
    tests

Code Reproduction URL

https://github.com/paladin80/stencil-component-starter

Additional Information

I think that generated source maps don't work in tests.

@ionitron-bot ionitron-bot bot added the triage label Nov 19, 2021
@smndhm
Copy link

smndhm commented Nov 29, 2021

I'm having the same issue.
When downgrading to @stencil/core@2.9 and removing Jest cache jest --clearCache I'm not having it anymore.

@paladin80
Copy link
Author

The issue appeared in the version 2.10.0. And is still present in 2.11.0

Jest cache is preventing to clearly discover the problem. So please remove the "jest" folder from your %tmp% directory when testing the versions.

@paladin80
Copy link
Author

OS used: Windows 10 x64
Node used: 14.18.1 and 17.1.0 (same result)

@johnjenkins
Copy link
Contributor

johnjenkins commented Dec 1, 2021

just discussed this in stencil slack (here) - turns out the issue was unknowingly introduced within here as it effects this line < the new encoding should not run on an inlined sourcemap .. data:application/json;charset=utf-8 will become data%3Aapplication%2Fjson%3Bcharset%3Dutf-8%2C for example.
To test, within the stencil repo, jest --clearCache and run npm run test - take note of the coverage report - the file line numbers don't seem to relate to much.
Change the offending line to results.code = results.code.slice(0, sourceMapComment) + '//# sourceMappingURL=' + sourceMapInlined;, recompile, jest --clearCache and run npm run test. Coverage report looks very different. Line numbers relate to obvious blocks of code.

@paladin80
Copy link
Author

Thank you @johnjenkins. In the slack I just said my hypothesis that I got from comparing the code in branches. I had no time to properly test and verify it.

Can you create a pull request for this issue?

@rwaskiewicz
Copy link
Member

👀

@rwaskiewicz rwaskiewicz added Bug: Validated This PR or Issue is verified to be a bug within Stencil and removed Bug: Needs Validation labels Dec 1, 2021
@rwaskiewicz
Copy link
Member

Thanks @paladin80 for the super detailed reproduction case and @johnjenkins for debugging this! Both were super helpful and used directly in #3163, which should fix this issue.

@paladin80
Copy link
Author

Hi @rwaskiewicz. Thank you for the quick response.
The fix works, but now the code doesn't call the encodeFilenameToRfc3986() function. It looks like a rollback to an older status quo. Maybe there's another solution to keep both the URL RFC-compliant and don't lose the compatibility with the Node.

@rwaskiewicz
Copy link
Member

@paladin80 Hmm it looks like '+', '/', and '=' are all reserved characters in RFC-3986 that can also be part of a valid Base 64 encoding. Let me rework this real quick...

@paladin80
Copy link
Author

paladin80 commented Dec 1, 2021

I didn't dig into it yet, but I think that we shouldn't encode the part data:application/json;charset=utf-8;base64, since it is a protocol definition, and encode everything else. Testing is needed.

EDIT: On the other side, the current url is RFC-2397 compliant, so maybe there's no need to do additional encoding.

@rwaskiewicz
Copy link
Member

I spent some additional time on my PR, added tests, then tested everything manually and think everything is working in the PR as expected. #3163 has been merged, and will be in the next Stencil release (v2.12.0)

@rwaskiewicz
Copy link
Member

This fix has been included in the v2.12.0 release. I'm going to close this issue, however if the problem reappears, please feel free to open a new issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil
Projects
None yet
Development

No branches or pull requests

5 participants