代码之家  ›  专栏  ›  技术社区  ›  user3205479

调试vs代码中typescript节点中编写的jasmine测试

  •  5
  • user3205479  · 技术社区  · 6 年前

    我的单元测试是用jasmine编写的,那些是用typescript编写的

    // about.service.spec.ts
    // say 4 to 5 test cases
    
    // spec/support/jasmine.json
    {
      "spec_dir": "src/tests/",
      "spec_files": ["**/*.spec.ts"],
      "helpers": ["jasmine-helpers/**/*.ts"],
      ...
    }
    
    // launch.json - vscode file
    {
      "version": "0.2.0",
      "configurations": [{
          "type": "node",
          "request": "launch",
          "name": "Jasmine tests",
          "preLaunchTask": "debuggertests",
       }]
    }
    
    // tasks.json - vscode 
    {
     "version": "2.0.0",
     "tasks": [{
        "label": "debuggertests",
        "type": "npm",
        "script": "test:unit",
        "problemMatcher": []
      }]
    }
    
    // package.json
    // have to use jasmine-ts which is flavor over ts-node
    "test:unit": "jasmine-ts JASMINE_CONFIG_PATH=spec/support/jasmine.json"
    

    我已使用此配置进行调试。vscode中的spec.ts文件,但它没有启动调试器,而是运行所有测试并启动调试。

    我在大约的一个测试用例中放置了一个断点。服务规范ts,但未激发断点。有谁能帮助我为jasmine测试设置vscode调试?

    2 回复  |  直到 6 年前
        1
  •  9
  •   isaacfi    6 年前

    在新的茉莉花ts版本中,您必须包含茉莉花。json到args,如下所示:

    {
      "type": "node",
      "request": "launch",
      "name": "Jasmine Current File",
      "program": "${workspaceFolder}/node_modules/jasmine-ts/lib/index",
      "args": ["--config=jasmine.json", "${file}"],
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen"
    }
    

    要避免此问题,请执行以下操作:

    找不到规格 在0.003秒内完成 不完整:未找到规格 随机配种子60766(茉莉花--随机=真--种子=60766)

        2
  •  6
  •   Chirag Rupani    6 年前

    以下配置将调试当前测试文件-请在VS代码中打开所需的测试文件,然后使用此配置开始调试:

    {
          "type": "node",
          "request": "launch",
          "name": "Jasmine Current File",
          "program": "${workspaceFolder}/node_modules/jasmine-ts/lib/index",
          "args": ["${file}"],
          "console": "integratedTerminal",
          "internalConsoleOptions": "neverOpen"
     }