|
2 | 2 | const assert = require('chai').assert;
|
3 | 3 | const path = require('path');
|
4 | 4 | const createServer = require('../server-fixture');
|
5 |
| -const {openMockFile, getFirstResponseOfType} = require('./_helpers'); |
| 5 | +const { openMockFile, getFirstResponseOfType } = require('./_helpers'); |
6 | 6 |
|
7 | 7 | const mockFileName = path.join(__dirname, '..', 'project-fixture', 'main.ts');
|
8 | 8 |
|
9 | 9 | const getSemanticDiagnosticsForFile = (fileContents) => {
|
10 | 10 | const server = createServer();
|
11 | 11 | openMockFile(server, mockFileName, fileContents);
|
12 |
| - server.sendCommand('semanticDiagnosticsSync', {file: mockFileName}); |
| 12 | + server.sendCommand('semanticDiagnosticsSync', { file: mockFileName }); |
13 | 13 |
|
14 | 14 | return server.close().then(_ => {
|
15 | 15 | return getFirstResponseOfType('semanticDiagnosticsSync', server);
|
16 | 16 | });
|
17 | 17 | }
|
18 | 18 |
|
19 | 19 | describe('Errors', () => {
|
20 |
| - it('should return error for unknown property', () => { |
21 |
| - return getSemanticDiagnosticsForFile( |
22 |
| - 'function css(x) { return x; }; const q = css`boarder: 1px solid black;`' |
23 |
| - ).then(errorResponse => { |
24 |
| - assert.isTrue(errorResponse.success); |
25 |
| - assert.strictEqual(errorResponse.body.length, 1); |
26 |
| - const error = errorResponse.body[0]; |
27 |
| - assert.strictEqual(error.text, "Unknown property: 'boarder'"); |
28 |
| - assert.strictEqual(error.start.line, 1); |
29 |
| - assert.strictEqual(error.start.offset, 46); |
30 |
| - assert.strictEqual(error.end.line, 1); |
31 |
| - assert.strictEqual(error.end.offset, 53); |
32 |
| - }); |
| 20 | + it('should return error for unknown property', async () => { |
| 21 | + const errorResponse = await getSemanticDiagnosticsForFile('function css(x) { return x; }; const q = css`boarder: 1px solid black;`'); |
| 22 | + assert.isTrue(errorResponse.success); |
| 23 | + assert.strictEqual(errorResponse.body.length, 1); |
| 24 | + const error = errorResponse.body[0]; |
| 25 | + assert.strictEqual(error.text, "Unknown property: 'boarder'"); |
| 26 | + assert.strictEqual(error.start.line, 1); |
| 27 | + assert.strictEqual(error.start.offset, 46); |
| 28 | + assert.strictEqual(error.end.line, 1); |
| 29 | + assert.strictEqual(error.end.offset, 53); |
33 | 30 | });
|
34 | 31 |
|
35 |
| - it('should not return errors for empty rulesets', () => { |
36 |
| - return getSemanticDiagnosticsForFile( |
37 |
| - 'function css(x) { return x; }; const q = css``' |
38 |
| - ).then(errorResponse => { |
39 |
| - assert.isTrue(errorResponse.success); |
40 |
| - assert.strictEqual(errorResponse.body.length, 0); |
41 |
| - }); |
| 32 | + it('should not return errors for empty rulesets', async () => { |
| 33 | + const errorResponse = await getSemanticDiagnosticsForFile('function css(x) { return x; }; const q = css``'); |
| 34 | + assert.isTrue(errorResponse.success); |
| 35 | + assert.strictEqual(errorResponse.body.length, 0); |
42 | 36 | });
|
43 | 37 |
|
44 |
| - it('should not return errors for nested rulesets', () => { |
45 |
| - return getSemanticDiagnosticsForFile( |
46 |
| - 'function css(x) { return x; }; const q = css`&:hover { border: 1px solid black; }`' |
47 |
| - ).then(errorResponse => { |
48 |
| - assert.isTrue(errorResponse.success); |
49 |
| - assert.strictEqual(errorResponse.body.length, 0); |
50 |
| - }); |
| 38 | + it('should not return errors for nested rulesets', async () => { |
| 39 | + const errorResponse = await getSemanticDiagnosticsForFile('function css(x) { return x; }; const q = css`&:hover { border: 1px solid black; }`'); |
| 40 | + assert.isTrue(errorResponse.success); |
| 41 | + assert.strictEqual(errorResponse.body.length, 0); |
51 | 42 | });
|
52 | 43 |
|
53 |
| - it('should not return an error for a placeholder in a property', () => { |
54 |
| - return getSemanticDiagnosticsForFile( |
55 |
| - 'function css(strings, ...) { return ""; }; const q = css`color: ${"red"};`' |
56 |
| - ).then(errorResponse => { |
57 |
| - assert.isTrue(errorResponse.success); |
58 |
| - assert.strictEqual(errorResponse.body.length, 0); |
59 |
| - }); |
| 44 | + it('should not return an error for a placeholder in a property', async () => { |
| 45 | + const errorResponse = await getSemanticDiagnosticsForFile('function css(strings, ...) { return ""; }; const q = css`color: ${"red"};`'); |
| 46 | + assert.isTrue(errorResponse.success); |
| 47 | + assert.strictEqual(errorResponse.body.length, 0); |
60 | 48 | });
|
61 | 49 |
|
62 |
| - it('should not return an error for a placeholder in a property with a multiline string', () => { |
63 |
| - return getSemanticDiagnosticsForFile([ |
| 50 | + it('should not return an error for a placeholder in a property with a multiline string', async () => { |
| 51 | + const errorResponse = await getSemanticDiagnosticsForFile([ |
64 | 52 | 'function css(strings, ...) { return ""; }; const q = css`',
|
65 | 53 | ' color: ${"red"};',
|
66 |
| - '`'].join('\n') |
67 |
| - ).then(errorResponse => { |
68 |
| - assert.isTrue(errorResponse.success); |
69 |
| - assert.strictEqual(errorResponse.body.length, 0); |
70 |
| - }); |
| 54 | + '`' |
| 55 | + ].join('\n')); |
| 56 | + assert.isTrue(errorResponse.success); |
| 57 | + assert.strictEqual(errorResponse.body.length, 0); |
71 | 58 | });
|
72 | 59 |
|
73 |
| - it('should return errors when error occurs in last position', () => { |
74 |
| - return getSemanticDiagnosticsForFile( |
75 |
| - 'function css(strings, ...) { return ""; }; const q = css`;`' |
76 |
| - ).then(errorResponse => { |
77 |
| - assert.isTrue(errorResponse.success); |
78 |
| - assert.strictEqual(errorResponse.body.length, 1); |
79 |
| - const error = errorResponse.body[0]; |
80 |
| - assert.strictEqual(error.text, '} expected'); |
81 |
| - assert.strictEqual(error.start.line, 1); |
82 |
| - assert.strictEqual(error.start.offset, 58); |
83 |
| - assert.strictEqual(error.end.line, 1); |
84 |
| - assert.strictEqual(error.end.offset, 59); |
85 |
| - }); |
| 60 | + it('should return errors when error occurs in last position', async () => { |
| 61 | + const errorResponse = await getSemanticDiagnosticsForFile('function css(strings, ...) { return ""; }; const q = css`;`'); |
| 62 | + assert.isTrue(errorResponse.success); |
| 63 | + assert.strictEqual(errorResponse.body.length, 1); |
| 64 | + const error = errorResponse.body[0]; |
| 65 | + assert.strictEqual(error.text, '} expected'); |
| 66 | + assert.strictEqual(error.start.line, 1); |
| 67 | + assert.strictEqual(error.start.offset, 58); |
| 68 | + assert.strictEqual(error.end.line, 1); |
| 69 | + assert.strictEqual(error.end.offset, 59); |
86 | 70 | });
|
87 | 71 |
|
88 |
| - it('should return error for multiline unknown property #20', () => { |
89 |
| - return getSemanticDiagnosticsForFile([ |
| 72 | + it('should return error for multiline unknown property #20', async () => { |
| 73 | + const errorResponse = await getSemanticDiagnosticsForFile([ |
90 | 74 | 'function css(x) { return x; };',
|
91 | 75 | 'const q = css`',
|
92 | 76 | 'boarder: 1px solid black;',
|
93 | 77 | '`'
|
94 |
| - ].join('\n') |
95 |
| - ).then(errorResponse => { |
96 |
| - assert.isTrue(errorResponse.success); |
97 |
| - assert.strictEqual(errorResponse.body.length, 1); |
98 |
| - const error = errorResponse.body[0]; |
99 |
| - assert.strictEqual(error.text, "Unknown property: 'boarder'"); |
100 |
| - assert.strictEqual(error.start.line, 3); |
101 |
| - assert.strictEqual(error.start.offset, 1); |
102 |
| - assert.strictEqual(error.end.line, 3); |
103 |
| - assert.strictEqual(error.end.offset, 8); |
104 |
| - }); |
| 78 | + ].join('\n')); |
| 79 | + assert.isTrue(errorResponse.success); |
| 80 | + assert.strictEqual(errorResponse.body.length, 1); |
| 81 | + const error = errorResponse.body[0]; |
| 82 | + assert.strictEqual(error.text, "Unknown property: 'boarder'"); |
| 83 | + assert.strictEqual(error.start.line, 3); |
| 84 | + assert.strictEqual(error.start.offset, 1); |
| 85 | + assert.strictEqual(error.end.line, 3); |
| 86 | + assert.strictEqual(error.end.offset, 8); |
105 | 87 | });
|
106 | 88 |
|
107 |
| - it('should not error with interpolation at start, followed by semicolon #22', () => { |
108 |
| - return getSemanticDiagnosticsForFile([ |
| 89 | + it('should not error with interpolation at start, followed by semicolon #22', async () => { |
| 90 | + const errorResponse = await getSemanticDiagnosticsForFile([ |
109 | 91 | "function css(...args){}",
|
110 | 92 | "const mixin = ''",
|
111 |
| - |
112 | 93 | // test single-line
|
113 | 94 | "css`${mixin}; color: blue;`",
|
114 |
| - |
115 | 95 | // test multi-line (normal case)
|
116 | 96 | "css`",
|
117 | 97 | " ${mixin};",
|
118 | 98 | " color: blue;",
|
119 | 99 | "`",
|
120 |
| - |
121 | 100 | // test multiple spaces after semi
|
122 | 101 | "css`",
|
123 | 102 | " ${mixin} ;",
|
124 | 103 | " color: blue;",
|
125 | 104 | "`",
|
126 |
| - |
127 | 105 | // test hella semis - will this ever pop up? probably not, but screw it
|
128 | 106 | "css`",
|
129 | 107 | " ${mixin};;; ;; ;",
|
130 | 108 | " color: blue;",
|
131 | 109 | "`",
|
132 |
| - ].join('\n') |
133 |
| - ).then(errorResponse => { |
134 |
| - assert.isTrue(errorResponse.success); |
135 |
| - assert.strictEqual(errorResponse.body.length, 0); |
136 |
| - }); |
| 110 | + ].join('\n')); |
| 111 | + assert.isTrue(errorResponse.success); |
| 112 | + assert.strictEqual(errorResponse.body.length, 0); |
137 | 113 | });
|
138 | 114 |
|
139 |
| - it('should not return an error for a placeholder used as a selector (#30)', () => { |
140 |
| - return getSemanticDiagnosticsForFile( |
141 |
| - 'function css(strings, ...) { return ""; }; const q = css`${"button"} { color: red; }`' |
142 |
| - ).then(errorResponse => { |
143 |
| - assert.isTrue(errorResponse.success); |
144 |
| - assert.strictEqual(errorResponse.body.length, 0); |
145 |
| - }); |
| 115 | + it('should not return an error for a placeholder used as a selector (#30)', async () => { |
| 116 | + const errorResponse = await getSemanticDiagnosticsForFile('function css(strings, ...) { return ""; }; const q = css`${"button"} { color: red; }`'); |
| 117 | + assert.isTrue(errorResponse.success); |
| 118 | + assert.strictEqual(errorResponse.body.length, 0); |
146 | 119 | });
|
147 | 120 |
|
148 | 121 | it('should not return an error for a placeholder used as a complex selector (#30)', () => {
|
@@ -170,13 +143,10 @@ describe('Errors', () => {
|
170 | 143 | });
|
171 | 144 | });
|
172 | 145 |
|
173 |
| - it('should not return an error for a placeholder used as selector part (#39)', () => { |
174 |
| - return getSemanticDiagnosticsForFile( |
175 |
| - 'function css(strings, ...) { return ""; }; const Content = "button"; const q = css`& > ${Content} { margin-left: 1px; }`' |
176 |
| - ).then(errorResponse => { |
177 |
| - assert.isTrue(errorResponse.success); |
178 |
| - assert.strictEqual(errorResponse.body.length, 0); |
179 |
| - }); |
| 146 | + it('should not return an error for a placeholder used as selector part (#39)', async () => { |
| 147 | + const errorResponse = await getSemanticDiagnosticsForFile('function css(strings, ...) { return ""; }; const Content = "button"; const q = css`& > ${Content} { margin-left: 1px; }`'); |
| 148 | + assert.isTrue(errorResponse.success); |
| 149 | + assert.strictEqual(errorResponse.body.length, 0); |
180 | 150 | });
|
181 | 151 |
|
182 | 152 | it('should not return an error for a placeholder in multiple properties (#39)', () => {
|
|
0 commit comments