我正在编写一个ESLint插件,并且一直在使用ESLint进行测试。RuleTester。这没关系,我知道如何配置他们的测试选项参数,但我总是要运行整个测试文件。
这是一个示例测试文件:
const {RuleTester} = require('eslint');
const rulester = new RuleTester({setup});
const rule = require ('myrule');
//this works also but i have to run the entire file (and thus all the tests)
ruleTester.run('myruletest',rule,{invalid,valid});
通常,当我安装测试运行程序时,我会得到它的运行/配置和方便的play
⏯和debug
🐞按钮与每次测试一致。当我编写更多的测试(尤其是在同一个文件中(时,快速单击测试旁边的=>
并只运行单个测试会很方便。
如果我尝试从mocha.it
回调调用ruletester.run
,它将无法正确报告测试(并且肯定无法调试/介入测试(。例如,不能很好地工作
const mocha = require('mocha');
const {RuleTester} = require('eslint');
const rulester = new RuleTester({setup});
const rule = require ('myrule');
// nice play button and custom run configruation but not honest test feeback
it('mytest', ()=>{
// it'll run this but will not report correctly -- `it` says it always passes
ruleTester.run('myruletest, rule, {invalid,valid});
});
it('mytest', async ()=>{
// async is of no help
await ruleTester.run('myruletest, rule, {invalid,valid});
});
//this still works also but then i have to run the entire file (and thus all the tests)
ruleTester.run('myruletest',rule,{invalid,valid});
那么我该如何告诉WebStorm或
- 将
eslint.RuleTester
视为测试运行程序 - 从我自己的testrunner中正确地调用和实例RuleTester
将eslint.RuleTester
识别为测试运行程序需要开发一个特殊的插件。看见http://www.jetbrains.org/intellij/sdk/docs/有关插件开发的基本文档。你可以使用现有的插件作为例子:Mocha runner不是完全开源的,但它的JavaScript部分是开源的(https://github.com/JetBrains/mocha-intellij);此外,还有一个Karma的开源插件https://github.com/JetBrains/intellij-plugins/tree/master/js-karma