Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit 40f69df

Browse files
committed
Asyncify the specs
Bring in `jasmine-fix` to allow the use of `async`/`await` in the specs, and refactor them to take advantage of this.
1 parent b8cba0d commit 40f69df

File tree

2 files changed

+46
-86
lines changed

2 files changed

+46
-86
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"devDependencies": {
3131
"eslint": "^4.3.0",
3232
"eslint-config-airbnb-base": "^11.3.1",
33-
"eslint-plugin-import": "^2.7.0"
33+
"eslint-plugin-import": "^2.7.0",
34+
"jasmine-fix": "^1.3.0"
3435
},
3536
"package-deps": [
3637
"linter"

spec/linter-csslint-spec.js

Lines changed: 44 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use babel';
22

33
import * as path from 'path';
4+
// eslint-disable-next-line no-unused-vars
5+
import { it, fit, wait, beforeEach, afterEach } from 'jasmine-fix';
46

57
const badPath = path.join(__dirname, 'fixtures', 'bad.css');
68
const goodPath = path.join(__dirname, 'fixtures', 'good.css');
@@ -12,105 +14,62 @@ const projectBadPath = path.join(projectPath, 'files', 'badWC.css');
1214
describe('The csslint provider for Linter', () => {
1315
const lint = require('../lib/main.js').provideLinter().lint;
1416

15-
beforeEach(() => {
17+
beforeEach(async () => {
1618
atom.workspace.destroyActivePaneItem();
17-
waitsForPromise(() =>
18-
Promise.all([
19-
atom.packages.activatePackage('linter-csslint'),
20-
atom.packages.activatePackage('language-css'),
21-
]).then(() =>
22-
atom.workspace.open(goodPath),
23-
),
24-
);
19+
20+
await atom.packages.activatePackage('linter-csslint');
21+
await atom.packages.activatePackage('language-css');
2522
});
2623

2724
describe('checks bad.css and', () => {
28-
let editor = null;
29-
beforeEach(() =>
30-
waitsForPromise(() =>
31-
atom.workspace.open(badPath).then((openEditor) => { editor = openEditor; }),
32-
),
33-
);
34-
35-
it('finds at least one message', () =>
36-
waitsForPromise(() =>
37-
lint(editor).then(messages =>
38-
expect(messages.length).toBeGreaterThan(0),
39-
),
40-
),
41-
);
25+
it('verifies the first message', async () => {
26+
const editor = await atom.workspace.open(badPath);
27+
const messages = await lint(editor);
4228

43-
it('verifies the first message', () =>
44-
waitsForPromise(() =>
45-
lint(editor).then((messages) => {
46-
expect(messages[0].type).toBe('Warning');
47-
expect(messages[0].text).toBe('Rule is empty.');
48-
expect(messages[0].filePath).toBe(badPath);
49-
expect(messages[0].range).toEqual([[0, 0], [0, 4]]);
50-
}),
51-
),
52-
);
29+
expect(messages.length).toBe(1);
30+
expect(messages[0].type).toBe('Warning');
31+
expect(messages[0].text).toBe('Rule is empty.');
32+
expect(messages[0].filePath).toBe(badPath);
33+
expect(messages[0].range).toEqual([[0, 0], [0, 4]]);
34+
});
5335
});
5436

5537
describe('warns on invalid CSS', () => {
56-
let editor = null;
57-
beforeEach(() =>
58-
waitsForPromise(() =>
59-
atom.workspace.open(invalidPath).then((openEditor) => { editor = openEditor; }),
60-
),
61-
);
38+
it('verifies the message', async () => {
39+
const editor = await atom.workspace.open(invalidPath);
40+
const messages = await lint(editor);
41+
42+
expect(messages.length).toBe(1);
43+
expect(messages[0].type).toBe('Error');
44+
expect(messages[0].text).toBe('Unexpected token \'}\' at line 1, col 1.');
45+
expect(messages[0].filePath).toBe(invalidPath);
46+
expect(messages[0].range).toEqual([[0, 0], [0, 1]]);
47+
});
48+
});
6249

63-
it('finds one message', () =>
64-
waitsForPromise(() =>
65-
lint(editor).then(messages =>
66-
expect(messages.length).toBe(1),
67-
),
68-
),
69-
);
50+
it('finds nothing wrong with a valid file', async () => {
51+
const editor = await atom.workspace.open(goodPath);
52+
const messages = await lint(editor);
7053

71-
it('verifies the message', () =>
72-
waitsForPromise(() =>
73-
lint(editor).then((messages) => {
74-
expect(messages[0].type).toBe('Error');
75-
expect(messages[0].text).toBe('Unexpected token \'}\' at line 1, col 1.');
76-
expect(messages[0].filePath).toBe(invalidPath);
77-
expect(messages[0].range).toEqual([[0, 0], [0, 1]]);
78-
}),
79-
),
80-
);
54+
expect(messages.length).toEqual(0);
8155
});
8256

83-
it('finds nothing wrong with a valid file', () =>
84-
waitsForPromise(() =>
85-
atom.workspace.open(goodPath).then(editor =>
86-
lint(editor).then(messages =>
87-
expect(messages.length).toEqual(0),
88-
),
89-
),
90-
),
91-
);
57+
it('handles an empty file', async () => {
58+
const editor = await atom.workspace.open(emptyPath);
59+
const messages = await lint(editor);
9260

93-
it('handles an empty file', () =>
94-
waitsForPromise(() =>
95-
atom.workspace.open(emptyPath).then(editor =>
96-
lint(editor).then(messages =>
97-
expect(messages.length).toEqual(0),
98-
),
99-
),
100-
),
101-
);
61+
expect(messages.length).toEqual(0);
62+
});
10263

103-
it('respects .csslintrc configurations at the project root', () => {
64+
it('respects .csslintrc configurations at the project root', async () => {
10465
atom.project.addPath(projectPath);
105-
waitsForPromise(() =>
106-
atom.workspace.open(projectBadPath).then(editor =>
107-
lint(editor).then((messages) => {
108-
expect(messages[0].type).toBeDefined();
109-
expect(messages[0].type).toEqual('Error');
110-
expect(messages[0].text).toBeDefined();
111-
expect(messages[0].text).toEqual('Rule is empty.');
112-
}),
113-
),
114-
);
66+
const editor = await atom.workspace.open(projectBadPath);
67+
const messages = await lint(editor);
68+
69+
expect(messages.length).toBe(1);
70+
expect(messages[0].type).toBeDefined();
71+
expect(messages[0].type).toEqual('Error');
72+
expect(messages[0].text).toBeDefined();
73+
expect(messages[0].text).toEqual('Rule is empty.');
11574
});
11675
});

0 commit comments

Comments
 (0)