【问题标题】:VSCode jest runner fails to debug Typescript codeVSCode jest runner 无法调试 Typescript 代码
【发布时间】:2021-05-15 19:49:02
【问题描述】:

我正在使用 VSCode 笑话运行器。 https://github.com/firsttris/vscode-jest-runner/ 。这是我在测试用例上进行调试时的输出:

失败的服务/servicenameA/handler.test.js ● 测试套件无法运行

SyntaxError: C:\Users\SIKAU\FILEPATH\filename.ts: Unexpected token, expected "," (9:58)

   7 |
   8 | //const dynamoDb = new AWS.DynamoDB.DocumentClient();
>  9 | export async function getAccountIdImplementation(accountId: string) {
     |                                                                                                       ^


  at Parser._raise (node_modules/@babel/parser/src/parser/error.js:97:45)
  at Parser.raiseWithData (node_modules/@babel/parser/src/parser/error.js:92:17)
  at Parser.raise (node_modules/@babel/parser/src/parser/error.js:41:17)
  at Parser.unexpected (node_modules/@babel/parser/src/parser/util.js:140:16)
  at Parser.expect (node_modules/@babel/parser/src/parser/util.js:117:28)
  at Parser.parseBindingList (node_modules/@babel/parser/src/parser/lval.js:315:14)
  at Parser.parseFunctionParams (node_modules/@babel/parser/src/parser/statement.js:1121:24)
  at Parser.parseFunction (node_modules/@babel/parser/src/parser/statement.js:1087:10)
  at Parser.parseFunctionStatement (node_modules/@babel/parser/src/parser/statement.js:553:17)
  at Parser.parseStatementContent (node_modules/@babel/parser/src/parser/statement.js:283:23)

测试套件:1 个失败,总共 1 个 测试:共 0 快照:共 0 个 时间:7.788 秒

我的 jest.config.js 如下所示:

// jest.config.js

module.exports = {
    collectCoverageFrom: ['./services/**/*.{js, ts,tsx}'],
    coverageThreshold: {
      './services/**/*.js': {
        branches: 100,
        functions: 100,
        lines: 100,
        statements: 100,
      },
      './services/**/*.ts': {
        branches: 100,
        functions: 100,
        lines: 100,
        statements: 100,
      },
    },
    moduleDirectories: [
        'node_modules',
    ],

  }

tsconfig.json 看起来像:

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "baseUrl": ".",
    "moduleResolution": "node",
    "sourceMap": true,
    "target": "ES6"
  },
  "exclude": ["node_modules", "**/*.spec.ts"],
  "composite": true,
  "declarationMap": true,
  "strict": true,
  "noUnusedLocals": true,
  "noImplicitThis": true,
  "strictNullChecks": true,
  "noImplicitReturns": true,
  "preserveConstEnums": true,
  "suppressImplicitAnyIndexErrors": true,
  "forceConsistentCasingInFileNames": true,
  "resolveJsonModule": true,
  "esModuleInterop": true
}

babel.config.js

module.exports = {presets: ['@babel/preset-env']}

调试器在测试 Typescript 代码时失败。

我该如何进行?尝试过谷歌搜索等等。没有解决问题,调试器无法运行。

【问题讨论】:

    标签: node.js typescript visual-studio-code vscode-debugger


    【解决方案1】:

    您收到的错误看起来像是编译问题。

    您有语法问题,可能在您共享的代码段上方的行中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-16
      • 1970-01-01
      • 2019-08-20
      • 1970-01-01
      • 2019-09-15
      • 2016-02-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多