如何在Visual Studio代码中运行茉莉花测试?

sun*_*pat 6 jasmine typescript visual-studio-code

我已经安装了茉莉花和打字稿的安装Visual Studio代码。

我有以下规格文件

测试规范

describe("Testing", () =>{
    it("should pass", () =>{
   let msg = "Welcome to TypeScript";
    //I want to print the msg first like a log
    expect(msg).toBe("Welcome to TypeScript")
    })
})
Run Code Online (Sandbox Code Playgroud)

请指导我如何将味精值打印为日志并在Visual Studio代码中运行茉莉花测试?

我尝试使用specrunner.html运行,但结果只是通过或失败,但无法在specrunner结果文件上打印任何日志。

Pac*_*ace 5

这是我最终做的。

  1. npm install --save-dev jasmine @types/jasmine
  2. 配置tsconfig.jsonjasmine全局包含类型并生成源映射并将所有输出发送到dist文件夹。
{
  "compilerOptions": {
    /* ... */
    "sourceMap": true,
    "outDir": "./dist",
    "types": [
      "node",
      "jasmine"
    ],
    /* ... */
  }
}
Run Code Online (Sandbox Code Playgroud)
  1. 创建了一个 npm 任务以使用节点检查器运行 jasmineinspect-brk需要节点版本 8 或更高版本。您可以使用inspect7 和 6 的某些版本,但我担心它可能无法及时捕获我的断点,并且没有对该选项进行过多调查。
{
  /* ... */
  "scripts": {
    "build": "tsc --project .",
    "test:debug": "npm run build && node --inspect-brk node_modules/jasmine/bin/jasmine.js JASMINE_CONFIG_PATH=jasmine.json"
  },
  /* ... */
}
Run Code Online (Sandbox Code Playgroud)
  1. 在 VS 代码 ( launch.json) 中创建了一个启动任务来启动 NPM 任务。
{
  /* ... */
  "configurations": [
    /* ... */
    {
      "type": "node",
      "request": "launch",
      "name": "Run Jasmine Tests",
      "runtimeExecutable": "npm",
      "runtimeArgs": [
        "run-script",
        "test:debug"
      ],
      "outFiles": [
        "${workspaceRoot}/dist/**.js"
      ],
      "protocol": "inspector",
      "port": 9229,
      "sourceMaps": true
    },
    /* ... */
  ]
  /* ... */
}
Run Code Online (Sandbox Code Playgroud)

完成所有这些后,您可以从 Visual Studio 运行启动任务。它将运行您的代码并在适用的断点处停止。