Mocha breakpoints using Visual Studio Code

后端 未结 20 1343
星月不相逢
星月不相逢 2020-12-12 11:52

Is it possible to add breakpoints to ones Mocha tests using Visual Studio Code?

Normally when debugging code one need to configure the launch.json, setting the prog

20条回答
  •  我在风中等你
    2020-12-12 12:09

    For those that are using grunt or gulp, the configuration is pretty simple.

    Launch.json

    {
    "version": "0.2.0",
    "configurations": [
    
        {
            "name": "Run mocha by grunt",
            "type": "node",
            "program": "${workspaceRoot}/node_modules/grunt/bin/grunt",
            "stopOnEntry": false,
            "args": ["mochaTest"],
            "cwd": "${workspaceRoot}",
            "runtimeExecutable": null
        }
    ]}
    

    Gruntfile.js

    module.exports = function (grunt) {
    
    grunt.initConfig({
        mochaTest: {
            test: {
                options: {
                    reporter: 'spec'
                },
                src: ['test/**/*test.js']
            }
        }
    });
    
    grunt.loadNpmTasks('grunt-mocha-test');
    
    grunt.registerTask('default', 'mochaTest');};
    

提交回复
热议问题