Karma run single test

后端 未结 9 1292
后悔当初
后悔当初 2020-11-28 11:33

I use karma for run tests. I have many tests and run all tests is very slow process. I want to run only single test in order to spend less time, because all test runs about

9条回答
  •  抹茶落季
    2020-11-28 12:03

    For Angular users!

    I know two ways:

    1. Visual Studio Code Extension:

    The easiest way is to use the vscode-test-explorer extension along with its child angular-karma-test-explorer and jasmine-test-adapter, you'll get a list of current test to run one by one if you want:

    1. Directly modify test.ts

    For me, i wasn't able to use the extension way because of this bug, and so i ended up modifying the test.ts file (as stated here by Shashi), just to consolidate that answer here, by default context looks like this:

    const context = require.context('./', true, /\.spec\.ts$/);
    

    You should modify it's RegExp to match the files that you'r willing to test, for example if you want to test a single file named "my.single.file.custom.name.spec.ts" it'll look this way:

    const context = require.context('./', true, /my\.single\.file\.custom\.name\.spec\.ts$/);
    

    For more details about require parameters you may find it here at their wiki.

    1. Karma runner improvement

    Currently there's an open issue to improve their current behaviour, you can follow their progress at their github page (https://github.com/karma-runner/karma/issues/1507).

提交回复
热议问题