Skip to content

Commit

Permalink
Asyncify the specs
Browse files Browse the repository at this point in the history
Bring in `jasmine-fix` to allow the use of `async`/`await` in the specs
and refactor them to take advantage of this.
  • Loading branch information
Arcanemagus committed Sep 22, 2017
1 parent d4d2b19 commit 851510f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"devDependencies": {
"eslint": "^4.6.0",
"eslint-config-airbnb-base": "^12.0.0",
"eslint-plugin-import": "^2.7.0"
"eslint-plugin-import": "^2.7.0",
"jasmine-fix": "^1.3.1"
},
"eslintConfig": {
"extends": "airbnb-base",
Expand Down
48 changes: 24 additions & 24 deletions spec/linter-shellcheck-spec.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
'use babel';

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

const { lint } = require('../lib/main.js').provideLinter();

const cleanPath = path.join(__dirname, 'fixtures', 'clean.sh');
const badPath = path.join(__dirname, 'fixtures', 'bad.sh');

describe('The ShellCheck provider for Linter', () => {
const { lint } = require('../lib/main.js').provideLinter();

beforeEach(() => {
beforeEach(async () => {
atom.workspace.destroyActivePaneItem();

// Info about this beforeEach() implementation:
// https://github.com/AtomLinter/Meta/issues/15
const activationPromise =
atom.packages.activatePackage('linter-shellcheck');
const activationPromise = atom.packages.activatePackage('linter-shellcheck');

waitsForPromise(() =>
atom.packages.activatePackage('language-shellscript').then(() =>
atom.workspace.open(cleanPath)));
await atom.packages.activatePackage('language-shellscript');
await atom.workspace.open(cleanPath);

atom.packages.triggerDeferredActivationHooks();
waitsForPromise(() => activationPromise);
await activationPromise;
});

it('finds nothing wrong with a valid file', () => {
waitsForPromise(() =>
atom.workspace.open(cleanPath).then(editor => lint(editor)).then((messages) => {
expect(messages.length).toBe(0);
}));
it('finds nothing wrong with a valid file', async () => {
const editor = await atom.workspace.open(cleanPath);
const messages = await lint(editor);

expect(messages.length).toBe(0);
});

it('handles messages from ShellCheck', () => {
it('handles messages from ShellCheck', async () => {
const expectedMsg = 'Tips depend on target shell and yours is unknown. Add a shebang. ' +
'[<a href="https://github.com/koalaman/shellcheck/wiki/SC2148">SC2148</a>]';
waitsForPromise(() =>
atom.workspace.open(badPath).then(editor => lint(editor)).then((messages) => {
expect(messages.length).toBe(1);
expect(messages[0].type).toBe('error');
expect(messages[0].text).not.toBeDefined();
expect(messages[0].html).toBe(expectedMsg);
expect(messages[0].filePath).toBe(badPath);
expect(messages[0].range).toEqual([[0, 0], [0, 4]]);
}));
const editor = await atom.workspace.open(badPath);
const messages = await lint(editor);

expect(messages.length).toBe(1);
expect(messages[0].type).toBe('error');
expect(messages[0].text).not.toBeDefined();
expect(messages[0].html).toBe(expectedMsg);
expect(messages[0].filePath).toBe(badPath);
expect(messages[0].range).toEqual([[0, 0], [0, 4]]);
});
});

0 comments on commit 851510f

Please sign in to comment.