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

Unexpected token when running tests with nyc #3009

Open
rotu opened this issue May 22, 2024 · 3 comments
Open

Unexpected token when running tests with nyc #3009

rotu opened this issue May 22, 2024 · 3 comments

Comments

@rotu
Copy link

rotu commented May 22, 2024

Upon running tests, nyc is crashing out due to a syntax error.

I believe this is because it's mistakenly trying to parse the TypeScript file as Flow. The file declaredScope.d.ts contains the below code:

declare function declaredScope(
    context: Rule.RuleContext,
    name: string
): Scope.Scope['type'] | undefined;
> cross-env BABEL_ENV=test nyc mocha tests/src

D:/Source/eslint-plugin-import/utils/declaredScope.d.ts: Unexpected token, expected ] (6:15)
node:events:498
      throw er; // Unhandled 'error' event
      ^

Error: spawn nyc ENOENT
    at notFoundError (D:\Source\eslint-plugin-import\node_modules\cross-spawn\lib\enoent.js:11:11)       
    at verifyENOENT (D:\Source\eslint-plugin-import\node_modules\cross-spawn\lib\enoent.js:46:16)        
    at cp.emit (D:\Source\eslint-plugin-import\node_modules\cross-spawn\lib\enoent.js:33:19)
    at ChildProcess._handle.onexit (node:internal/child_process:294:12)
    at Process.callbackTrampoline (node:internal/async_hooks:130:17)
Emitted 'error' event on ChildProcess instance at:
    at cp.emit (D:\Source\eslint-plugin-import\node_modules\cross-spawn\lib\enoent.js:36:37)
    at ChildProcess._handle.onexit (node:internal/child_process:294:12)
    at Process.callbackTrampoline (node:internal/async_hooks:130:17) {
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn nyc'
}

debugger trace:

SyntaxError: Unexpected token, expected ] (6:15)
    at Parser.pp$5.raise (D:\Source\eslint-plugin-import\node_modules\babylon\lib\index.js:4454:13)
    at Parser.pp.unexpected (D:\Source\eslint-plugin-import\node_modules\babylon\lib\index.js:1761:8)
    at Parser.pp.expect (D:\Source\eslint-plugin-import\node_modules\babylon\lib\index.js:1749:33)
    at Parser.pp$8.flowParsePostfixType (D:\Source\eslint-plugin-import\node_modules\babylon\lib\index.js:5783:10)
    at Parser.pp$8.flowParsePrefixType (D:\Source\eslint-plugin-import\node_modules\babylon\lib\index.js:5795:17)
    at Parser.pp$8.flowParseAnonFunctionWithoutParens (D:\Source\eslint-plugin-import\node_modules\babylon\lib\index.js:5800:20)
    at Parser.pp$8.flowParseIntersectionType (D:\Source\eslint-plugin-import\node_modules\babylon\lib\index.js:5815:19)
    at Parser.pp$8.flowParseUnionType (D:\Source\eslint-plugin-import\node_modules\babylon\lib\index.js:5826:19)
    at Parser.pp$8.flowParseType (D:\Source\eslint-plugin-import\node_modules\babylon\lib\index.js:5837:19)
    at Parser.pp$8.flowParseTypeAndPredicateInitialiser (D:\Source\eslint-plugin-import\node_modules\babylon\lib\index.js:5023:17)
    at Parser.pp$8.flowParseDeclareFunction (D:\Source\eslint-plugin-import\node_modules\babylon\lib\index.js:5059:36)
    at Parser.pp$8.flowParseDeclare (D:\Source\eslint-plugin-import\node_modules\babylon\lib\index.js:5079:17)
    at Parser.parseExpressionStatement (D:\Source\eslint-plugin-import\node_modules\babylon\lib\index.js:5921:25)
    at Parser.pp$1.parseStatement (D:\Source\eslint-plugin-import\node_modules\babylon\lib\index.js:1911:17)
    at Parser.parseStatement (D:\Source\eslint-plugin-import\node_modules\babylon\lib\index.js:5910:22)
    at Parser.pp$1.parseBlockBody (D:\Source\eslint-plugin-import\node_modules\babylon\lib\index.js:2268:21)
    at Parser.pp$1.parseTopLevel (D:\Source\eslint-plugin-import\node_modules\babylon\lib\index.js:1778:8)
    at Parser.parse (D:\Source\eslint-plugin-import\node_modules\babylon\lib\index.js:1673:17)
    at parse (D:\Source\eslint-plugin-import\node_modules\babylon\lib\index.js:7305:37)
    at File.parse (D:\Source\eslint-plugin-import\node_modules\babel-core\lib\transformation\file\index.js:485:15)
    at File.parseCode (D:\Source\eslint-plugin-import\node_modules\babel-core\lib\transformation\file\index.js:570:20)
    at D:\Source\eslint-plugin-import\node_modules\babel-core\lib\transformation\pipeline.js:49:12
    at File.wrap (D:\Source\eslint-plugin-import\node_modules\babel-core\lib\transformation\file\index.js:532:16)
    at Pipeline.transform (D:\Source\eslint-plugin-import\node_modules\babel-core\lib\transformation\pipeline.js:47:17)
    at Object.transformFileSync (D:\Source\eslint-plugin-import\node_modules\babel-core\lib\api\node.js:152:10)
    at compile (D:\Source\eslint-plugin-import\node_modules\babel-register\lib\node.js:118:20)
    at loader (D:\Source\eslint-plugin-import\node_modules\babel-register\lib\node.js:144:14)
    at Object.require.extensions.<computed> [as .js] (D:\Source\eslint-plugin-import\node_modules\babel-register\lib\node.js:154:7)
    at NYC._readTranspiledSource (D:\Source\eslint-plugin-import\node_modules\nyc\index.js:166:28)
    at NYC.addFile (D:\Source\eslint-plugin-import\node_modules\nyc\index.js:156:25)
    at NYC.addAllFiles (D:\Source\eslint-plugin-import\node_modules\nyc\index.js:202:14)
    at main (D:\Source\eslint-plugin-import\node_modules\nyc\bin\nyc.js:72:5) {pos: 134, loc: Position, stack: 'SyntaxError: Unexpected token, expected ] (6:…-import\\node_modules\\nyc\\bin\\nyc.js:72:5)', message: 'Unexpected token, expected ] (6:15)'}
@ljharb
Copy link
Member

ljharb commented May 22, 2024

hm, that makes sense. is there a way to tell nyc to strip types, or strip them ourselves?

@rotu
Copy link
Author

rotu commented May 22, 2024

I am very unfamiliar with nyc but I think adding "**/*.d.ts" to the root .nycrc "exclude" list does the trick.

But I don't know why there are several .nycrc files scattered throughout the project. Can these be removed?

@ljharb
Copy link
Member

ljharb commented May 23, 2024

This is a monorepo and each subpackage has its own config.

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

No branches or pull requests

2 participants