Skip to content

Commit e353d5e

Browse files
committed
Convert some tests to async
1 parent b17aa81 commit e353d5e

File tree

1 file changed

+64
-94
lines changed

1 file changed

+64
-94
lines changed

e2e/tests/errors.js

+64-94
Original file line numberDiff line numberDiff line change
@@ -2,147 +2,120 @@
22
const assert = require('chai').assert;
33
const path = require('path');
44
const createServer = require('../server-fixture');
5-
const {openMockFile, getFirstResponseOfType} = require('./_helpers');
5+
const { openMockFile, getFirstResponseOfType } = require('./_helpers');
66

77
const mockFileName = path.join(__dirname, '..', 'project-fixture', 'main.ts');
88

99
const getSemanticDiagnosticsForFile = (fileContents) => {
1010
const server = createServer();
1111
openMockFile(server, mockFileName, fileContents);
12-
server.sendCommand('semanticDiagnosticsSync', {file: mockFileName});
12+
server.sendCommand('semanticDiagnosticsSync', { file: mockFileName });
1313

1414
return server.close().then(_ => {
1515
return getFirstResponseOfType('semanticDiagnosticsSync', server);
1616
});
1717
}
1818

1919
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);
3330
});
3431

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);
4236
});
4337

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);
5142
});
5243

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);
6048
});
6149

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([
6452
'function css(strings, ...) { return ""; }; const q = css`',
6553
' 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);
7158
});
7259

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);
8670
});
8771

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([
9074
'function css(x) { return x; };',
9175
'const q = css`',
9276
'boarder: 1px solid black;',
9377
'`'
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);
10587
});
10688

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([
10991
"function css(...args){}",
11092
"const mixin = ''",
111-
11293
// test single-line
11394
"css`${mixin}; color: blue;`",
114-
11595
// test multi-line (normal case)
11696
"css`",
11797
" ${mixin};",
11898
" color: blue;",
11999
"`",
120-
121100
// test multiple spaces after semi
122101
"css`",
123102
" ${mixin} ;",
124103
" color: blue;",
125104
"`",
126-
127105
// test hella semis - will this ever pop up? probably not, but screw it
128106
"css`",
129107
" ${mixin};;; ;; ;",
130108
" color: blue;",
131109
"`",
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);
137113
});
138114

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);
146119
});
147120

148121
it('should not return an error for a placeholder used as a complex selector (#30)', () => {
@@ -170,13 +143,10 @@ describe('Errors', () => {
170143
});
171144
});
172145

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);
180150
});
181151

182152
it('should not return an error for a placeholder in multiple properties (#39)', () => {

0 commit comments

Comments
 (0)