|
| 1 | +import { mergeLintConfigurations } from "./mergeLintConfigurations"; |
| 2 | +import { ESLintConfiguration } from "./findESLintConfiguration"; |
| 3 | + |
| 4 | +const stubTSLintConfiguration = { |
| 5 | + rulesDirectory: [], |
| 6 | + rules: { |
| 7 | + disabled: true, |
| 8 | + enabled: true, |
| 9 | + }, |
| 10 | +}; |
| 11 | + |
| 12 | +describe("mergeLintConfigurations", () => { |
| 13 | + it("returns the tslint configuration when the eslint configuration is an error", () => { |
| 14 | + // Arrange |
| 15 | + const eslint = new Error(); |
| 16 | + |
| 17 | + // Act |
| 18 | + const result = mergeLintConfigurations(eslint, stubTSLintConfiguration); |
| 19 | + |
| 20 | + // Assert |
| 21 | + expect(result).toBe(stubTSLintConfiguration); |
| 22 | + }); |
| 23 | + |
| 24 | + it("returns the tslint configuration when the eslint configuration doesn't have tslint rules", () => { |
| 25 | + // Arrange |
| 26 | + const eslint: ESLintConfiguration = { |
| 27 | + env: {}, |
| 28 | + extends: [], |
| 29 | + rules: {}, |
| 30 | + }; |
| 31 | + |
| 32 | + // Act |
| 33 | + const result = mergeLintConfigurations(eslint, stubTSLintConfiguration); |
| 34 | + |
| 35 | + // Assert |
| 36 | + expect(result).toBe(stubTSLintConfiguration); |
| 37 | + }); |
| 38 | + |
| 39 | + it("returns the tslint configuration when the eslint configuration's tslint rules are disabled", () => { |
| 40 | + // Arrange |
| 41 | + const eslint: ESLintConfiguration = { |
| 42 | + env: {}, |
| 43 | + extends: [], |
| 44 | + rules: { |
| 45 | + "@typescript-eslint/tslint/config": [ |
| 46 | + "off", |
| 47 | + { |
| 48 | + extra: true, |
| 49 | + }, |
| 50 | + ], |
| 51 | + }, |
| 52 | + }; |
| 53 | + |
| 54 | + // Act |
| 55 | + const result = mergeLintConfigurations(eslint, stubTSLintConfiguration); |
| 56 | + |
| 57 | + // Assert |
| 58 | + expect(result).toBe(stubTSLintConfiguration); |
| 59 | + }); |
| 60 | + |
| 61 | + it("returns the merged configurations when the eslint configuration has tslint rules", () => { |
| 62 | + // Arrange |
| 63 | + const extraRules = { |
| 64 | + extra: true, |
| 65 | + }; |
| 66 | + const eslint: ESLintConfiguration = { |
| 67 | + env: {}, |
| 68 | + extends: [], |
| 69 | + rules: { |
| 70 | + "@typescript-eslint/tslint/config": [ |
| 71 | + "error", |
| 72 | + { |
| 73 | + rules: extraRules, |
| 74 | + }, |
| 75 | + ], |
| 76 | + }, |
| 77 | + }; |
| 78 | + |
| 79 | + // Act |
| 80 | + const result = mergeLintConfigurations(eslint, stubTSLintConfiguration); |
| 81 | + |
| 82 | + // Assert |
| 83 | + expect(result).toEqual({ |
| 84 | + ...stubTSLintConfiguration, |
| 85 | + rules: { |
| 86 | + ...stubTSLintConfiguration.rules, |
| 87 | + ...extraRules, |
| 88 | + }, |
| 89 | + }); |
| 90 | + }); |
| 91 | +}); |
0 commit comments