|
| 1 | +import { ESLint } from "eslint"; |
| 2 | + |
| 3 | +Feature("linting js files (commonjs)", () => { |
| 4 | + Scenario("js file passing lint rules", () => { |
| 5 | + let eslint; |
| 6 | + Given("we have an eslint instance with the base config", () => { |
| 7 | + eslint = new ESLint({ |
| 8 | + overrideConfigFile: "../../js.js", |
| 9 | + ignore: false, |
| 10 | + }); |
| 11 | + }); |
| 12 | + |
| 13 | + let results; |
| 14 | + When("we lint a folder", async () => { |
| 15 | + results = await eslint.lintFiles([ "data/js/noerrors.js" ]); |
| 16 | + }); |
| 17 | + |
| 18 | + Then("we should have linted the correct number of files", () => { |
| 19 | + expect(results.length).to.eql(1); |
| 20 | + }); |
| 21 | + |
| 22 | + And("one file should have no messages", () => { |
| 23 | + expect(results[0].messages.length).to.eql(0, JSON.stringify(results[0].messages)); |
| 24 | + }); |
| 25 | + }); |
| 26 | + |
| 27 | + Scenario("js file does not pass, tries to extend class", () => { |
| 28 | + let eslint; |
| 29 | + Given("we have an eslint instance with the base config", () => { |
| 30 | + eslint = new ESLint({ |
| 31 | + overrideConfigFile: "../../js.js", |
| 32 | + ignore: false, |
| 33 | + }); |
| 34 | + }); |
| 35 | + |
| 36 | + let results; |
| 37 | + When("we lint a file which extends a class", async () => { |
| 38 | + results = await eslint.lintFiles([ "data/js/extends.js" ]); |
| 39 | + }); |
| 40 | + |
| 41 | + Then("we should have linted the correct number of files", () => { |
| 42 | + expect(results.length).to.eql(1); |
| 43 | + }); |
| 44 | + |
| 45 | + And("one file should have errors", () => { |
| 46 | + expect(results[0].messages.length).to.be.eql(1, JSON.stringify(results[0].messages)); |
| 47 | + }); |
| 48 | + |
| 49 | + And("one error should be because it extends a class", () => { |
| 50 | + const error = results[0].messages.find(({ ruleId }) => ruleId === "@bonniernews/typescript-rules/disallow-class-extends"); |
| 51 | + expect(error).to.not.be.undefined; |
| 52 | + expect(error.message).to.have.string("Extending"); |
| 53 | + }); |
| 54 | + }); |
| 55 | +}); |
0 commit comments