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

Crash in type-coverage #47

Open
robin-anil opened this issue May 18, 2020 · 5 comments
Open

Crash in type-coverage #47

robin-anil opened this issue May 18, 2020 · 5 comments
Labels

Comments

@robin-anil
Copy link

robin-anil commented May 18, 2020

Version(if relevant): 2.6.1

tsc runs successfully from the same folder. by type-coverage or typescript-coverage-report both errors out with the same stacktrace

Environment(if relevant):

Mac OS

$ npx typescript-coverage-report
TypeError: Cannot read property 'lastIndexOf' of undefined
    at Object.startsWith (/Users/robinanil/work/admin/dashboard/node_modules/typescript-coverage-report/node_modules/typescript/lib/typescript.js:2044:20)
    at isPathRelativeToParent (/Users/robinanil/work/admin/dashboard/node_modules/typescript-coverage-report/node_modules/typescript/lib/typescript.js:102732:23)
    at /Users/robinanil/work/admin/dashboard/node_modules/typescript-coverage-report/node_modules/typescript/lib/typescript.js:102691:24
    at Object.firstDefined (/Users/robinanil/work/admin/dashboard/node_modules/typescript-coverage-report/node_modules/typescript/lib/typescript.js:347:26)
    at getPathRelativeToRootDirs (/Users/robinanil/work/admin/dashboard/node_modules/typescript-coverage-report/node_modules/typescript/lib/typescript.js:102689:23)
    at tryGetModuleNameFromRootDirs (/Users/robinanil/work/admin/dashboard/node_modules/typescript-coverage-report/node_modules/typescript/lib/typescript.js:102550:40)
    at getLocalModuleSpecifier (/Users/robinanil/work/admin/dashboard/node_modules/typescript-coverage-report/node_modules/typescript/lib/typescript.js:102408:44)
    at /Users/robinanil/work/admin/dashboard/node_modules/typescript-coverage-report/node_modules/typescript/lib/typescript.js:102395:96
    at Array.map (<anonymous>)
    at Object.getModuleSpecifiers (/Users/robinanil/work/admin/dashboard/node_modules/typescript-coverage-report/node_modules/typescript/lib/typescript.js:102395:57)
@plantain-00
Copy link
Owner

  1. The stacktrace shows no code about type-coverage
  2. type-coverage calls API provided by typescript, while tsc is not, it may be typescript's API's bug, eg: same error caused by getPathRelativeToRootDirs like Unhandled error when computing local module specifier microsoft/TypeScript#37731

@robin-anil
Copy link
Author

Is type-coverage correctly passing cwd as the base path? Reading that bug it sounds like it ought to do that to handle code bases like mine with relative paths

@plantain-00
Copy link
Owner

I don't know how to do something to fix this bug.
If there is a workaround, PR is welcome.

@robin-anil
Copy link
Author

I haven't dug into this code base, so it may take some time for me to issue a patch.
but I can show you that the following works. So if you can resolve to absolute path when you parse the tsconfig.json it may fix it.

npx type-coverage -p /Users/robinanil/work/admin/dashboard/tsconfig.json
363638 / 382102 95.16%
type-coverage success.

@robin-anil
Copy link
Author

I cannot figure out how to do this with typescript-coverage-report -- they don't seem to have a -p option. So the fix may need to go directly into code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants