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

Commit bd8a97d

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 987d21d commit bd8a97d

File tree

2 files changed

+88
-109
lines changed

2 files changed

+88
-109
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
"eslint": "^4.6.0",
5858
"eslint-config-airbnb-base": "^12.0.0",
5959
"eslint-plugin-import": "^2.7.0",
60-
"fs-extra": "^4.0.1"
60+
"fs-extra": "^4.0.1",
61+
"jasmine-fix": "^1.3.0"
6162
},
6263
"eslintConfig": {
6364
"extends": "airbnb-base",

spec/linter-elixirc-spec.js

Lines changed: 86 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
'use babel';
22

33
import { join } from 'path';
4-
// eslint-disable-next-line import/no-extraneous-dependencies, import/no-unresolved
54
import { remove } from 'fs-extra';
5+
// eslint-disable-next-line no-unused-vars
6+
import { it, fit, wait, beforeEach, afterEach } from 'jasmine-fix';
67

78
const { lint } = require('../lib/init.js').provideLinter();
89

@@ -19,138 +20,115 @@ const mixBuildDirectory = join(__dirname, 'fixtures', 'mix-proj', '_build');
1920
remove(mixBuildDirectory);
2021

2122
describe('The elixirc provider for Linter', () => {
23+
beforeEach(async () => {
24+
atom.workspace.destroyActivePaneItem();
25+
26+
await atom.packages.activatePackage('linter-elixirc');
27+
await atom.packages.activatePackage('language-elixir');
28+
});
29+
2230
describe('when not working inside a Mix project', () => {
2331
describe('and using the standard configuration', () => {
24-
beforeEach(() => {
25-
atom.workspace.destroyActivePaneItem();
26-
27-
waitsForPromise(() =>
28-
Promise.all([
29-
atom.packages.activatePackage('linter-elixirc'),
30-
atom.packages.activatePackage('language-elixir'),
31-
]));
32-
});
32+
it('works with mode 1 errors', async () => {
33+
const editor = await atom.workspace.open(errorMode1PathElixirc);
34+
const messages = await lint(editor);
3335

34-
it('works with mode 1 errors', () => {
35-
waitsForPromise(() =>
36-
atom.workspace.open(errorMode1PathElixirc).then(editor =>
37-
lint(editor)).then((messages) => {
38-
expect(messages.length).toBe(1);
39-
expect(messages[0].severity).toBe('error');
40-
expect(messages[0].html).not.toBeDefined();
41-
expect(messages[0].excerpt).toBe('(ArgumentError) Dangerous is not available');
42-
expect(messages[0].location.file).toBe(errorMode1PathElixirc);
43-
expect(messages[0].location.position).toEqual([[1, 0], [1, 32]]);
44-
}));
36+
expect(messages.length).toBe(1);
37+
expect(messages[0].severity).toBe('error');
38+
expect(messages[0].html).not.toBeDefined();
39+
expect(messages[0].excerpt).toBe('(ArgumentError) Dangerous is not available');
40+
expect(messages[0].location.file).toBe(errorMode1PathElixirc);
41+
expect(messages[0].location.position).toEqual([[1, 0], [1, 32]]);
4542
});
4643

47-
it('works with mode 2 errors', () => {
48-
waitsForPromise(() =>
49-
atom.workspace.open(errorMode2PathElixirc).then(editor =>
50-
lint(editor)).then((messages) => {
51-
expect(messages.length).toBe(1);
52-
expect(messages[0].severity).toBe('error');
53-
expect(messages[0].html).not.toBeDefined();
54-
expect(messages[0].excerpt).toBe('(CompileError) module Usefulness is not loaded and could not be found');
55-
expect(messages[0].location.file).toBe(errorMode2PathElixirc);
56-
expect(messages[0].location.position).toEqual([[3, 2], [3, 20]]);
57-
}));
44+
it('works with mode 2 errors', async () => {
45+
const editor = await atom.workspace.open(errorMode2PathElixirc);
46+
const messages = await lint(editor);
47+
48+
expect(messages.length).toBe(1);
49+
expect(messages[0].severity).toBe('error');
50+
expect(messages[0].html).not.toBeDefined();
51+
expect(messages[0].excerpt).toBe('(CompileError) module Usefulness is not loaded and could not be found');
52+
expect(messages[0].location.file).toBe(errorMode2PathElixirc);
53+
expect(messages[0].location.position).toEqual([[3, 2], [3, 20]]);
5854
});
5955

60-
it('works with warnings', () => {
61-
waitsForPromise(() =>
62-
atom.workspace.open(warningPathElixirc).then(editor => lint(editor)).then((messages) => {
63-
expect(messages.length).toBe(1);
64-
expect(messages[0].severity).toBe('warning');
65-
expect(messages[0].html).not.toBeDefined();
66-
expect(messages[0].excerpt).toBe('variable "prepare_for_call" does not exist and is being expanded to "prepare_for_call()", please use parentheses to remove the ambiguity or change the variable name');
67-
expect(messages[0].location.file).toBe(warningPathElixirc);
68-
expect(messages[0].location.position).toEqual([[20, 4], [20, 20]]);
69-
}));
56+
it('works with warnings', async () => {
57+
const editor = await atom.workspace.open(warningPathElixirc);
58+
const messages = await lint(editor);
59+
60+
expect(messages.length).toBe(1);
61+
expect(messages[0].severity).toBe('warning');
62+
expect(messages[0].html).not.toBeDefined();
63+
expect(messages[0].excerpt).toBe('variable "prepare_for_call" does not exist and is being expanded to "prepare_for_call()", please use parentheses to remove the ambiguity or change the variable name');
64+
expect(messages[0].location.file).toBe(warningPathElixirc);
65+
expect(messages[0].location.position).toEqual([[20, 4], [20, 20]]);
7066
});
7167

72-
it('works with .exs files', () => {
73-
waitsForPromise(() =>
74-
atom.workspace.open(exsFilePathElixirc).then(editor => lint(editor)).then((messages) => {
75-
expect(messages.length).toBe(1);
76-
expect(messages[0].severity).toBe('warning');
77-
expect(messages[0].html).not.toBeDefined();
78-
expect(messages[0].excerpt).toBe('function simple_function/0 is unused');
79-
expect(messages[0].location.file).toBe(exsFilePathElixirc);
80-
expect(messages[0].location.position).toEqual([[1, 2], [1, 25]]);
81-
}));
68+
it('works with .exs files', async () => {
69+
const editor = await atom.workspace.open(exsFilePathElixirc);
70+
const messages = await lint(editor);
71+
72+
expect(messages.length).toBe(1);
73+
expect(messages[0].severity).toBe('warning');
74+
expect(messages[0].html).not.toBeDefined();
75+
expect(messages[0].excerpt).toBe('function simple_function/0 is unused');
76+
expect(messages[0].location.file).toBe(exsFilePathElixirc);
77+
expect(messages[0].location.position).toEqual([[1, 2], [1, 25]]);
8278
});
8379

84-
it('finds nothing wrong with a valid file', () => {
85-
waitsForPromise(() =>
86-
atom.workspace.open(validPathElixirc).then(editor => lint(editor)).then((messages) => {
87-
expect(messages.length).toBe(0);
88-
}));
80+
it('finds nothing wrong with a valid file', async () => {
81+
const editor = await atom.workspace.open(validPathElixirc);
82+
const messages = await lint(editor);
83+
84+
expect(messages.length).toBe(0);
8985
});
9086
});
9187
});
9288

9389
describe('when working inside a Mix project', () => {
9490
describe('and using the standard configuration', () => {
95-
beforeEach(() => {
96-
atom.workspace.destroyActivePaneItem();
97-
98-
waitsForPromise(() =>
99-
Promise.all([
100-
atom.packages.activatePackage('linter-elixirc'),
101-
atom.packages.activatePackage('language-elixir'),
102-
]));
103-
});
91+
it('works with mode 2 errors', async () => {
92+
const editor = await atom.workspace.open(errorMode2PathMix);
93+
const messages = await lint(editor);
10494

105-
it('works with mode 2 errors', () => {
106-
waitsForPromise(() =>
107-
atom.workspace.open(errorMode2PathMix).then(editor =>
108-
lint(editor)).then((messages) => {
109-
expect(messages.length).toBe(1);
110-
expect(messages[0].severity).toBe('error');
111-
expect(messages[0].html).not.toBeDefined();
112-
expect(messages[0].excerpt).toBe('(CompileError) Identicon.Image.__struct__/1 is undefined, cannot expand struct Identicon.Image');
113-
expect(messages[0].location.file).toBe(errorMode2PathMix);
114-
expect(messages[0].location.position).toEqual([[11, 4], [11, 30]]);
115-
}));
95+
expect(messages.length).toBe(1);
96+
expect(messages[0].severity).toBe('error');
97+
expect(messages[0].html).not.toBeDefined();
98+
expect(messages[0].excerpt).toBe('(CompileError) Identicon.Image.__struct__/1 is undefined, cannot expand struct Identicon.Image');
99+
expect(messages[0].location.file).toBe(errorMode2PathMix);
100+
expect(messages[0].location.position).toEqual([[11, 4], [11, 30]]);
116101
});
117102

118-
it('works with .exs files', () => {
119-
waitsForPromise(() =>
120-
atom.workspace.open(exsFilePathMix).then(editor => lint(editor)).then((messages) => {
121-
expect(messages.length).toBe(1);
122-
expect(messages[0].severity).toBe('warning');
123-
expect(messages[0].html).not.toBeDefined();
124-
expect(messages[0].excerpt).toBe('function simple_function/0 is unused');
125-
expect(messages[0].location.file).toBe(exsFilePathMix);
126-
expect(messages[0].location.position).toEqual([[1, 2], [1, 25]]);
127-
}));
103+
it('works with .exs files', async () => {
104+
const editor = await atom.workspace.open(exsFilePathMix);
105+
const messages = await lint(editor);
106+
107+
expect(messages.length).toBe(1);
108+
expect(messages[0].severity).toBe('warning');
109+
expect(messages[0].html).not.toBeDefined();
110+
expect(messages[0].excerpt).toBe('function simple_function/0 is unused');
111+
expect(messages[0].location.file).toBe(exsFilePathMix);
112+
expect(messages[0].location.position).toEqual([[1, 2], [1, 25]]);
128113
});
129114
});
130115
});
131-
});
132116

133-
describe('when using the setting forceElixirc', () => {
134-
beforeEach(() => {
135-
atom.config.set('linter-elixirc.forceElixirc', true);
136-
atom.workspace.destroyActivePaneItem();
117+
describe('when using the setting forceElixirc', () => {
118+
beforeEach(async () => {
119+
atom.config.set('linter-elixirc.forceElixirc', true);
120+
});
137121

138-
waitsForPromise(() =>
139-
Promise.all([
140-
atom.packages.activatePackage('linter-elixirc'),
141-
atom.packages.activatePackage('language-elixir'),
142-
]));
143-
});
122+
it('works with warnings', async () => {
123+
const editor = await atom.workspace.open(errorMode2PathMix);
124+
const messages = await lint(editor);
144125

145-
it('works with warnings', () => {
146-
waitsForPromise(() =>
147-
atom.workspace.open(errorMode2PathMix).then(editor => lint(editor)).then((messages) => {
148-
expect(messages.length).toBe(1);
149-
expect(messages[0].severity).toBe('error');
150-
expect(messages[0].html).not.toBeDefined();
151-
expect(messages[0].excerpt).toBe('(CompileError) Identicon.Image.__struct__/1 is undefined, cannot expand struct Identicon.Image');
152-
expect(messages[0].location.file).toBe(errorMode2PathMix);
153-
expect(messages[0].location.position).toEqual([[11, 4], [11, 30]]);
154-
}));
126+
expect(messages.length).toBe(1);
127+
expect(messages[0].severity).toBe('error');
128+
expect(messages[0].html).not.toBeDefined();
129+
expect(messages[0].excerpt).toBe('(CompileError) Identicon.Image.__struct__/1 is undefined, cannot expand struct Identicon.Image');
130+
expect(messages[0].location.file).toBe(errorMode2PathMix);
131+
expect(messages[0].location.position).toEqual([[11, 4], [11, 30]]);
132+
});
155133
});
156134
});

0 commit comments

Comments
 (0)