|
1 | 1 | import path from 'path' |
2 | | -import {expect, test} from '@jest/globals' |
| 2 | +import url from 'url' |
| 3 | +import {expect} from '@jest/globals' |
3 | 4 | import {Annotation} from '../src/annotation.js' |
4 | 5 | import {parseXmls, parseXml} from '../src/parser.js' |
5 | 6 |
|
6 | | -test('test parseXmls', () => { |
7 | | - const file1 = path.join(__dirname, 'resource', 'lint-results.xml') |
8 | | - const file2 = path.join(__dirname, 'resource', 'empty-results.xml') |
| 7 | +describe('parser.ts', () => { |
| 8 | + const __dirname = path.dirname(url.fileURLToPath(import.meta.url)) |
9 | 9 |
|
10 | | - const annotation1 = new Annotation( |
11 | | - 'Warning', |
12 | | - 'Useless parent layout: This `RelativeLayout` layout or its `FrameLayout` parent is useless; transfer the `background` attribute to the other view', |
13 | | - 'layout.xml', |
14 | | - 11, |
15 | | - 22 |
16 | | - ) |
17 | | - const annotation2 = new Annotation( |
18 | | - 'Error', |
19 | | - 'Ignoring results: The result of `subscribe` is not used', |
20 | | - 'Foo.kt', |
21 | | - 33, |
22 | | - 44 |
23 | | - ) |
| 10 | + it('test parseXmls', () => { |
| 11 | + const file1 = path.join(__dirname, 'resource', 'lint-results.xml') |
| 12 | + const file2 = path.join(__dirname, 'resource', 'empty-results.xml') |
24 | 13 |
|
25 | | - expect(parseXmls([file1, file2], false)).resolves.toEqual([ |
26 | | - annotation1, |
27 | | - annotation2 |
28 | | - ]) |
29 | | -}) |
| 14 | + const annotation1 = new Annotation( |
| 15 | + 'Warning', |
| 16 | + 'Useless parent layout: This `RelativeLayout` layout or its `FrameLayout` parent is useless; transfer the `background` attribute to the other view', |
| 17 | + 'layout.xml', |
| 18 | + 11, |
| 19 | + 22 |
| 20 | + ) |
| 21 | + const annotation2 = new Annotation( |
| 22 | + 'Error', |
| 23 | + 'Ignoring results: The result of `subscribe` is not used', |
| 24 | + 'Foo.kt', |
| 25 | + 33, |
| 26 | + 44 |
| 27 | + ) |
30 | 28 |
|
31 | | -test('test parseXmls and ignore warnings', () => { |
32 | | - const file1 = path.join(__dirname, 'resource', 'lint-results.xml') |
33 | | - const file2 = path.join(__dirname, 'resource', 'empty-results.xml') |
| 29 | + expect(parseXmls([file1, file2], false)).resolves.toEqual([ |
| 30 | + annotation1, |
| 31 | + annotation2 |
| 32 | + ]) |
| 33 | + }) |
34 | 34 |
|
35 | | - const annotation2 = new Annotation( |
36 | | - 'Error', |
37 | | - 'Ignoring results: The result of `subscribe` is not used', |
38 | | - 'Foo.kt', |
39 | | - 33, |
40 | | - 44 |
41 | | - ) |
| 35 | + it('test parseXmls and ignore warnings', () => { |
| 36 | + const file1 = path.join(__dirname, 'resource', 'lint-results.xml') |
| 37 | + const file2 = path.join(__dirname, 'resource', 'empty-results.xml') |
42 | 38 |
|
43 | | - expect(parseXmls([file1, file2], true)).resolves.toEqual([annotation2]) |
44 | | -}) |
| 39 | + const annotation2 = new Annotation( |
| 40 | + 'Error', |
| 41 | + 'Ignoring results: The result of `subscribe` is not used', |
| 42 | + 'Foo.kt', |
| 43 | + 33, |
| 44 | + 44 |
| 45 | + ) |
45 | 46 |
|
46 | | -test('test parseXml with issues', () => { |
47 | | - const xml = `<?xml version="1.0" encoding="UTF-8"?> |
48 | | - <issues format="6" by="lint 7.2.1"> |
49 | | - <issue |
50 | | - id="CheckResult" |
51 | | - severity="Error" |
52 | | - message="The result of \`subscribe\` is not used" |
53 | | - category="Correctness" |
54 | | - priority="6" |
55 | | - summary="Ignoring results" |
56 | | - explanation="Some methods have no side effects, and calling them without doing something without the result is suspicious." |
57 | | - errorLine1=" lifecycle.subscribe { event ->" |
58 | | - errorLine2=" ^"> |
59 | | - <location |
60 | | - file="Foo.kt" |
61 | | - line="33" |
62 | | - column="44"/> |
63 | | - </issue> |
64 | | - </issues>` |
65 | | - const annotation = new Annotation( |
66 | | - 'Error', |
67 | | - 'Ignoring results: The result of `subscribe` is not used', |
68 | | - 'Foo.kt', |
69 | | - 33, |
70 | | - 44 |
71 | | - ) |
| 47 | + expect(parseXmls([file1, file2], true)).resolves.toEqual([annotation2]) |
| 48 | + }) |
72 | 49 |
|
73 | | - expect(parseXml(xml, false)).resolves.toEqual([annotation]) |
74 | | -}) |
| 50 | + it('test parseXml with issues', () => { |
| 51 | + const xml = `<?xml version="1.0" encoding="UTF-8"?> |
| 52 | + <issues format="6" by="lint 7.2.1"> |
| 53 | + <issue |
| 54 | + id="CheckResult" |
| 55 | + severity="Error" |
| 56 | + message="The result of \`subscribe\` is not used" |
| 57 | + category="Correctness" |
| 58 | + priority="6" |
| 59 | + summary="Ignoring results" |
| 60 | + explanation="Some methods have no side effects, and calling them without doing something without the result is suspicious." |
| 61 | + errorLine1=" lifecycle.subscribe { event ->" |
| 62 | + errorLine2=" ^"> |
| 63 | + <location |
| 64 | + file="Foo.kt" |
| 65 | + line="33" |
| 66 | + column="44"/> |
| 67 | + </issue> |
| 68 | + </issues>` |
| 69 | + const annotation = new Annotation( |
| 70 | + 'Error', |
| 71 | + 'Ignoring results: The result of `subscribe` is not used', |
| 72 | + 'Foo.kt', |
| 73 | + 33, |
| 74 | + 44 |
| 75 | + ) |
| 76 | + |
| 77 | + expect(parseXml(xml, false)).resolves.toEqual([annotation]) |
| 78 | + }) |
75 | 79 |
|
76 | | -test('test parseXml without issue', () => { |
77 | | - const xml = `<?xml version="1.0" encoding="UTF-8"?> |
78 | | - <issues format="6" by="lint 7.2.1"> |
79 | | - </issues>` |
| 80 | + it('test parseXml without issue', () => { |
| 81 | + const xml = `<?xml version="1.0" encoding="UTF-8"?> |
| 82 | + <issues format="6" by="lint 7.2.1"> |
| 83 | + </issues>` |
80 | 84 |
|
81 | | - expect(parseXml(xml, false)).resolves.toEqual([]) |
| 85 | + expect(parseXml(xml, false)).resolves.toEqual([]) |
| 86 | + }) |
82 | 87 | }) |
0 commit comments