|
1 |
| -import * as semver from 'semver'; |
2 |
| - |
3 | 1 | import TemplateLinter from '../src/template-linter';
|
4 |
| -import { type Server } from '../src'; |
5 |
| -import { TextDocument } from 'vscode-languageserver-textdocument'; |
| 2 | +import { type Project, type Server } from '../src'; |
| 3 | +import { type TextDocument } from 'vscode-languageserver-textdocument'; |
6 | 4 |
|
7 |
| -describe('template-linter', function () { |
8 |
| - describe('sourcesForDocument', function () { |
9 |
| - const linter = new TemplateLinter({ |
10 |
| - options: { |
11 |
| - type: 'node', |
| 5 | +function getLinterInstance(depName?: string, depVersion?: string): [TemplateLinter, Project] { |
| 6 | + const linter = new TemplateLinter({ |
| 7 | + projectRoots: { |
| 8 | + // eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 9 | + projectForUri(_url: string) { |
| 10 | + return { |
| 11 | + dependencyMap: new Map(depName ? [[depName, { package: { name: depName, version: depVersion } }]] : []), |
| 12 | + } as Project; |
12 | 13 | },
|
13 |
| - } as Server); |
| 14 | + }, |
| 15 | + options: { |
| 16 | + type: 'node', |
| 17 | + }, |
| 18 | + } as Server); |
14 | 19 |
|
| 20 | + return [linter, linter['server'].projectRoots.projectForUri('') as Project]; |
| 21 | +} |
| 22 | + |
| 23 | +describe('template-linter', function () { |
| 24 | + describe('sourcesForDocument', function () { |
15 | 25 | it('supports empty template-lint version', function () {
|
| 26 | + const [linter, project] = getLinterInstance(); |
| 27 | + |
| 28 | + const doc: TextDocument = { |
| 29 | + uri: 'test.gjs', |
| 30 | + getText() { |
| 31 | + return 'let a = 12;<template>1</template>'; |
| 32 | + }, |
| 33 | + } as TextDocument; |
| 34 | + |
| 35 | + expect(linter.getSourcesForDocument(doc, project)).toEqual([]); |
| 36 | + }); |
| 37 | + it('supports incorrect template-lint version [foo-bar]', function () { |
| 38 | + const [linter, project] = getLinterInstance('ember-template-lint', 'foo-bar'); |
| 39 | + |
| 40 | + const doc: TextDocument = { |
| 41 | + uri: 'test.gjs', |
| 42 | + getText() { |
| 43 | + return 'let a = 12;<template>1</template>'; |
| 44 | + }, |
| 45 | + } as TextDocument; |
| 46 | + |
| 47 | + expect(linter.getSourcesForDocument(doc, project)).toEqual([doc.getText()]); |
| 48 | + }); |
| 49 | + it('supports incorrect template-lint version [*]', function () { |
| 50 | + const [linter, project] = getLinterInstance('ember-template-lint', '*'); |
| 51 | + |
16 | 52 | const doc: TextDocument = {
|
17 | 53 | uri: 'test.gjs',
|
18 | 54 | getText() {
|
19 | 55 | return 'let a = 12;<template>1</template>';
|
20 | 56 | },
|
21 | 57 | } as TextDocument;
|
22 | 58 |
|
23 |
| - expect(linter['sourcesForDocument'](doc, null)).toEqual(['let a = 12;<template>1</template>']); |
| 59 | + expect(linter.getSourcesForDocument(doc, project)).toEqual([doc.getText()]); |
24 | 60 | });
|
25 |
| - it('process gjs for template-lint v4 with ~', function () { |
| 61 | + it('process gjs for template-lint v2 with', function () { |
| 62 | + const [linter, project] = getLinterInstance('ember-template-lint', '2.0.0'); |
| 63 | + |
26 | 64 | const doc: TextDocument = {
|
27 | 65 | uri: 'test.gjs',
|
28 | 66 | getText() {
|
29 | 67 | return 'let a = 12;<template>1</template>';
|
30 | 68 | },
|
31 | 69 | } as TextDocument;
|
32 | 70 |
|
33 |
| - console.log(semver.parse('~4.3.1')); // should be counted as 4.3.1 |
34 |
| - expect(linter['sourcesForDocument'](doc, semver.parse('~4.3.1'))).toEqual([' 1']); |
| 71 | + expect(linter.getSourcesForDocument(doc, project)).toEqual([' 1']); |
35 | 72 | });
|
36 |
| - it('process gjs for template-lint v4 with ^', function () { |
| 73 | + it('process gjs for template-lint v3 with', function () { |
| 74 | + const [linter, project] = getLinterInstance('ember-template-lint', '3.3.1'); |
| 75 | + |
37 | 76 | const doc: TextDocument = {
|
38 | 77 | uri: 'test.gjs',
|
39 | 78 | getText() {
|
40 | 79 | return 'let a = 12;<template>1</template>';
|
41 | 80 | },
|
42 | 81 | } as TextDocument;
|
43 | 82 |
|
44 |
| - console.log(semver.parse('^4.3.1')); // should be counted as 4.3.1 |
45 |
| - expect(linter['sourcesForDocument'](doc, semver.parse('^4.3.1'))).toEqual([' 1']); |
| 83 | + expect(linter.getSourcesForDocument(doc, project)).toEqual([' 1']); |
46 | 84 | });
|
47 |
| - it('process gjs for template-lint v4 with strict dependency', function () { |
| 85 | + it('process gjs for template-lint v4 with', function () { |
| 86 | + const [linter, project] = getLinterInstance('ember-template-lint', '4.3.1'); |
| 87 | + |
| 88 | + const doc: TextDocument = { |
| 89 | + uri: 'test.gjs', |
| 90 | + getText() { |
| 91 | + return 'let a = 12;<template>1</template>'; |
| 92 | + }, |
| 93 | + } as TextDocument; |
| 94 | + |
| 95 | + expect(linter.getSourcesForDocument(doc, project)).toEqual([' 1']); |
| 96 | + }); |
| 97 | + it('skip gjs processing for template-lint v5', function () { |
| 98 | + const [linter, project] = getLinterInstance('ember-template-lint', '5.0.0'); |
| 99 | + |
| 100 | + const doc: TextDocument = { |
| 101 | + uri: 'test.gjs', |
| 102 | + getText() { |
| 103 | + return 'let a = 12;<template>1</template>'; |
| 104 | + }, |
| 105 | + } as TextDocument; |
| 106 | + |
| 107 | + expect(linter.getSourcesForDocument(doc, project)).toEqual([doc.getText()]); |
| 108 | + }); |
| 109 | + it('skip gjs processing for template-lint v6', function () { |
| 110 | + const [linter, project] = getLinterInstance('ember-template-lint', '6.0.0'); |
| 111 | + |
48 | 112 | const doc: TextDocument = {
|
49 | 113 | uri: 'test.gjs',
|
50 | 114 | getText() {
|
51 | 115 | return 'let a = 12;<template>1</template>';
|
52 | 116 | },
|
53 | 117 | } as TextDocument;
|
54 | 118 |
|
55 |
| - console.log(semver.parse('4.3.1')); // should be counted as 4.3.1 |
56 |
| - expect(linter['sourcesForDocument'](doc, semver.parse('4.3.1'))).toEqual([' 1']); |
| 119 | + expect(linter.getSourcesForDocument(doc, project)).toEqual([doc.getText()]); |
57 | 120 | });
|
58 | 121 | });
|
59 | 122 | });
|
0 commit comments