如何在visual studio代码中运行jasmine测试?

时间:2017-07-11 13:43:50

标签: typescript jasmine visual-studio-code

我已经设置了安装了jasmine和typescript的visual studio代码。

我有以下规格文件

TestSpec.ts

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")
    })
})

请指导我如何将msg值打印为日志并在visual studio代码中运行jasmine测试?

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

1 个答案:

答案 0 :(得分:4)

这是我最终做的事情。

  1. npm install --save-dev jasmine @types/jasmine
  2. 配置tsconfig.json以全局包含jasmine类型并生成源地图并将所有输出发送到dist文件夹。
  3. { "compilerOptions": { /* ... */ "sourceMap": true, "outDir": "./dist", "types": [ "node", "jasmine" ], /* ... */ } }

    1. 创建了一个npm任务来运行jasmine,节点检查器 inspect-brk需要节点版本8或更高版本。您可以将inspect与7和6的某些版本一起使用,但我担心它可能无法及时捕获我的断点并且没有对该选项进行太多调查。
    2. { /* ... */ "scripts": { "build": "tsc --project .", "test:debug": "npm run build && node --inspect-brk node_modules/jasmine/bin/jasmine.js JASMINE_CONFIG_PATH=jasmine.json" }, /* ... */ }

      1. 在VS代码(launch.json)中创建启动任务以启动NPM任务。
      2. { /* ... */ "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 }, /* ... */ ] /* ... */ }

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

相关问题