|
7 | 7 | name: "JSON formatter",
|
8 | 8 |
|
9 | 9 | "File with no problems should say so": function() {
|
10 |
| - var result = { messages: [], stats: [] }, |
11 |
| - actual = CSSLint.getFormatter("json").formatResults(result, "path/to/FILE", {fullPath: "/absolute/path/to/FILE"}); |
12 |
| - Assert.areEqual("{\"messages\":[],\"stats\":[]}", actual); |
| 10 | + var result = { messages: [], stats: [] }; |
| 11 | + var expected = "{\"filename\":\"path/to/FILE\",\"messages\":[],\"stats\":[]}"; |
| 12 | + var formatter = CSSLint.getFormatter("json"); |
| 13 | + var actual = formatter.startFormat() + |
| 14 | + formatter.formatResults(result, "path/to/FILE", |
| 15 | + {fullPath: "/absolute/path/to/FILE"}) + |
| 16 | + formatter.endFormat(); |
| 17 | + Assert.areEqual(expected, actual); |
13 | 18 | },
|
14 | 19 |
|
15 | 20 | "Should have no output when quiet option is specified and no errors": function() {
|
16 |
| - var result = { messages: [], stats: [] }, |
17 |
| - actual = CSSLint.getFormatter("json").formatResults(result, "path/to/FILE", {fullPath: "/absolute/path/to/FILE", quiet: "true"}); |
| 21 | + var result = { messages: [], stats: [] }; |
| 22 | + var formatter = CSSLint.getFormatter("json"); |
| 23 | + var actual = formatter.startFormat() + |
| 24 | + formatter.formatResults(result, "path/to/FILE", |
| 25 | + {fullPath: "/absolute/path/to/FILE", quiet: "true"}) + |
| 26 | + formatter.endFormat(); |
18 | 27 | Assert.areEqual("", actual);
|
19 | 28 | },
|
20 | 29 |
|
21 | 30 | "Should have output when quiet option is specified and there are errors": function() {
|
22 | 31 | var result = { messages: [
|
23 |
| - { type: "warning", line: 1, col: 1, message: "BOGUS", evidence: "ALSO BOGUS", rule: [] }, |
24 |
| - { type: "error", line: 2, col: 1, message: "BOGUS", evidence: "ALSO BOGUS", rule: [] } |
25 |
| - ], stats: [] }, |
26 |
| - expected = "{\"messages\":[{\"type\":\"warning\",\"line\":1,\"col\":1,\"message\":\"BOGUS\",\"evidence\":\"ALSO BOGUS\",\"rule\":[]},{\"type\":\"error\",\"line\":2,\"col\":1,\"message\":\"BOGUS\",\"evidence\":\"ALSO BOGUS\",\"rule\":[]}],\"stats\":[]}", |
27 |
| - actual = CSSLint.getFormatter("json").formatResults(result, "path/to/FILE", {fullPath: "/absolute/path/to/FILE", quiet: "true"}); |
| 32 | + { type: "warning", line: 1, col: 1, message: "BOGUS", evidence: "ALSO BOGUS", rule: [] }], stats: [] }; |
| 33 | + var expected = "{\"filename\":\"path/to/FILE\",\"messages\":[{\"type\":\"warning\",\"line\":1,\"col\":1,\"message\":\"BOGUS\",\"evidence\":\"ALSO BOGUS\",\"rule\":[]}],\"stats\":[]}"; |
| 34 | + var formatter = CSSLint.getFormatter("json"); |
| 35 | + var actual = formatter.startFormat() + |
| 36 | + formatter.formatResults(result, "path/to/FILE", |
| 37 | + {fullPath: "/absolute/path/to/FILE", quiet: "true"}) + |
| 38 | + formatter.endFormat(); |
28 | 39 | Assert.areEqual(expected, actual);
|
29 | 40 | },
|
30 | 41 |
|
31 | 42 | "File with problems should list them": function() {
|
32 | 43 | var result = { messages: [
|
33 | 44 | { type: "warning", line: 1, col: 1, message: "BOGUS", evidence: "ALSO BOGUS", rule: [] },
|
34 | 45 | { type: "error", line: 2, col: 1, message: "BOGUS", evidence: "ALSO BOGUS", rule: [] }
|
35 |
| - ], stats: [] }, |
36 |
| - expected = "{\"messages\":[{\"type\":\"warning\",\"line\":1,\"col\":1,\"message\":\"BOGUS\",\"evidence\":\"ALSO BOGUS\",\"rule\":[]},{\"type\":\"error\",\"line\":2,\"col\":1,\"message\":\"BOGUS\",\"evidence\":\"ALSO BOGUS\",\"rule\":[]}],\"stats\":[]}", |
37 |
| - actual = CSSLint.getFormatter("json").formatResults(result, "path/to/FILE", {fullPath: "/absolute/path/to/FILE"}); |
| 46 | + ], stats: [] }; |
| 47 | + var expected = "{\"filename\":\"path/to/FILE\",\"messages\":[{\"type\":\"warning\",\"line\":1,\"col\":1,\"message\":\"BOGUS\",\"evidence\":\"ALSO BOGUS\",\"rule\":[]},{\"type\":\"error\",\"line\":2,\"col\":1,\"message\":\"BOGUS\",\"evidence\":\"ALSO BOGUS\",\"rule\":[]}],\"stats\":[]}"; |
| 48 | + var formatter = CSSLint.getFormatter("json"); |
| 49 | + var actual = formatter.startFormat() + |
| 50 | + formatter.formatResults(result, "path/to/FILE", |
| 51 | + {fullPath: "/absolute/path/to/FILE"}) + |
| 52 | + formatter.endFormat(); |
| 53 | + Assert.areEqual(expected, actual); |
| 54 | + }, |
| 55 | + |
| 56 | + "Multiple files are handled properly": function () { |
| 57 | + var result = { messages: [ |
| 58 | + { type: "warning", line: 1, col: 1, message: "BOGUS", evidence: "ALSO BOGUS", rule: [] }], stats: [] }; |
| 59 | + var expected = "[{\"filename\":\"path/to/FILE\",\"messages\":[{\"type\":\"warning\",\"line\":1,\"col\":1,\"message\":\"BOGUS\",\"evidence\":\"ALSO BOGUS\",\"rule\":[]}],\"stats\":[]},{\"filename\":\"path/to/FILE\",\"messages\":[{\"type\":\"warning\",\"line\":1,\"col\":1,\"message\":\"BOGUS\",\"evidence\":\"ALSO BOGUS\",\"rule\":[]}],\"stats\":[]}]"; |
| 60 | + var formatter = CSSLint.getFormatter("json"); |
| 61 | + var actual = formatter.startFormat() + |
| 62 | + formatter.formatResults(result, "path/to/FILE", |
| 63 | + {fullPath: "/absolute/path/to/FILE"}) + |
| 64 | + formatter.formatResults(result, "path/to/FILE", |
| 65 | + {fullPath: "/absolute/path/to/FILE"}) + |
| 66 | + formatter.endFormat(); |
38 | 67 | Assert.areEqual(expected, actual);
|
39 | 68 | }
|
40 | 69 |
|
|
0 commit comments