|
1 | | -const execa = require("execa"); |
2 | | -const stripAnsi = require("strip-ansi"); |
3 | | -const Project = require("./__utils__/fake-project"); |
4 | | -const SonarQubeFormatter = require("../index"); |
| 1 | +const execa = require('execa'); |
| 2 | +const Project = require('./__utils__/fake-project'); |
5 | 3 |
|
6 | | -class MockConsole { |
7 | | - buffer = []; |
8 | | - |
9 | | - get lines() { |
10 | | - return this.buffer.map((message) => { |
11 | | - return stripAnsi(message).trim(); |
12 | | - }); |
13 | | - } |
14 | | - |
15 | | - log(message) { |
16 | | - this.buffer.push(message); |
17 | | - } |
18 | | - |
19 | | - toString() { |
20 | | - return stripAnsi(this.buffer.join("\n")); |
21 | | - } |
22 | | -} |
23 | | - |
24 | | -describe("SonarQube Formatter", () => { |
| 4 | +describe('SonarQube Formatter', () => { |
25 | 5 | let project; |
26 | 6 |
|
27 | 7 | beforeEach(() => { |
28 | | - project = new Project("fake-project"); |
| 8 | + project = new Project('fake-project'); |
29 | 9 | }); |
30 | 10 |
|
31 | 11 | afterEach(() => { |
32 | 12 | // project.dispose(); |
33 | 13 | }); |
34 | 14 |
|
35 | | - it("can format output from no results", () => { |
36 | | - let mockConsole = new MockConsole(); |
37 | | - let formatter = new SonarQubeFormatter({ |
38 | | - console: mockConsole, |
| 15 | + it('can format output from no results', async () => { |
| 16 | + project.setConfig({ |
| 17 | + rules: { |
| 18 | + 'no-bare-strings': 'warn', |
| 19 | + }, |
| 20 | + }); |
| 21 | + project.write({ |
| 22 | + app: { |
| 23 | + templates: { |
| 24 | + 'application.hbs': '<div></div>', |
| 25 | + }, |
| 26 | + }, |
39 | 27 | }); |
40 | 28 |
|
41 | | - formatter.print({}); |
| 29 | + let result = await emberTemplateLint(); |
42 | 30 |
|
43 | | - expect(mockConsole.toString()).toMatchInlineSnapshot(` |
| 31 | + expect(result.stdout).toMatchInlineSnapshot(` |
44 | 32 | "{ |
45 | 33 | \\"issues\\": [] |
46 | 34 | }" |
47 | 35 | `); |
48 | 36 | }); |
49 | 37 |
|
50 | | - it("can format output when there are warnings", async () => { |
| 38 | + it('can format output when there are warnings', async () => { |
51 | 39 | project.setConfig({ |
52 | 40 | rules: { |
53 | | - "no-bare-strings": "warn", |
| 41 | + 'no-bare-strings': 'warn', |
54 | 42 | }, |
55 | 43 | }); |
56 | 44 | project.write({ |
57 | 45 | app: { |
58 | 46 | templates: { |
59 | | - "application.hbs": |
60 | | - "<h2>Here too!!</h2> <div>Bare strings are bad...</div>", |
| 47 | + 'application.hbs': |
| 48 | + '<h2>Here too!!</h2> <div>Bare strings are bad...</div>', |
61 | 49 | components: { |
62 | | - "foo.hbs": "{{fooData}}", |
| 50 | + 'foo.hbs': '{{fooData}}', |
63 | 51 | }, |
64 | 52 | }, |
65 | 53 | }, |
@@ -107,19 +95,19 @@ describe("SonarQube Formatter", () => { |
107 | 95 | `); |
108 | 96 | }); |
109 | 97 |
|
110 | | - it("can format output when there are errors", async () => { |
| 98 | + it('can format output when there are errors', async () => { |
111 | 99 | project.setConfig({ |
112 | 100 | rules: { |
113 | | - "no-bare-strings": "error", |
| 101 | + 'no-bare-strings': 'error', |
114 | 102 | }, |
115 | 103 | }); |
116 | 104 | project.write({ |
117 | 105 | app: { |
118 | 106 | templates: { |
119 | | - "application.hbs": |
120 | | - "<h2>Here too!!</h2> <div>Bare strings are bad...</div>", |
| 107 | + 'application.hbs': |
| 108 | + '<h2>Here too!!</h2> <div>Bare strings are bad...</div>', |
121 | 109 | components: { |
122 | | - "foo.hbs": "{{fooData}}", |
| 110 | + 'foo.hbs': '{{fooData}}', |
123 | 111 | }, |
124 | 112 | }, |
125 | 113 | }, |
@@ -189,11 +177,11 @@ describe("SonarQube Formatter", () => { |
189 | 177 | process.execPath, |
190 | 178 | [ |
191 | 179 | require.resolve( |
192 | | - "../node_modules/ember-template-lint/bin/ember-template-lint.js" |
| 180 | + '../node_modules/ember-template-lint/bin/ember-template-lint.js' |
193 | 181 | ), |
194 | | - ".", |
195 | | - "--format", |
196 | | - require.resolve(".."), |
| 182 | + '.', |
| 183 | + '--format', |
| 184 | + require.resolve('..'), |
197 | 185 | ...argumentsOrOptions, |
198 | 186 | ], |
199 | 187 | mergedOptions |
|
0 commit comments