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

Asyncify the specs #114

Merged
merged 1 commit into from
Sep 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,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.0"
},
"eslintConfig": {
"extends": "airbnb-base",
Expand Down
10 changes: 9 additions & 1 deletion spec/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
module.exports = {
env: {
atomtest: true,
jasmine: true
jasmine: true,
},
rules: {
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": true
}
]
}
};
110 changes: 46 additions & 64 deletions spec/linter-tidy-spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use babel';

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

const { lint } = require('../lib/main.js').provideLinter();
Expand All @@ -9,91 +11,71 @@ const badTabFile = path.join(__dirname, 'fixtures', 'bad_tab.html');
const goodFile = path.join(__dirname, 'fixtures', 'good.html');

describe('The Tidy provider for Linter', () => {
beforeEach(() => {
beforeEach(async () => {
atom.workspace.destroyActivePaneItem();
waitsForPromise(() =>
Promise.all([
atom.packages.activatePackage('linter-tidy'),
atom.packages.activatePackage('language-html'),
])
.then(() => atom.workspace.open(goodFile)));
await atom.packages.activatePackage('linter-tidy');
await atom.packages.activatePackage('language-html');
await atom.workspace.open(goodFile);
});

describe('checks a file with issues and', () => {
let editor = null;
beforeEach(() => {
waitsForPromise(() =>
atom.workspace.open(badFile).then((openEditor) => {
editor = openEditor;
}));
});

it('finds at least one message', () => {
waitsForPromise(() =>
lint(editor).then(messages => expect(messages.length).toBeGreaterThan(0)));
});
it('checks a file with issues', async () => {
const editor = await atom.workspace.open(badFile);
const messages = await lint(editor);
const messageText = '<img> lacks "alt" attribute';

it('verifies the first message', () => {
const messageText = '<img> lacks "alt" attribute';
waitsForPromise(() =>
lint(editor).then((messages) => {
expect(messages[0].type).toBe('Warning');
expect(messages[0].html).not.toBeDefined();
expect(messages[0].text).toBe(messageText);
expect(messages[0].filePath).toBe(badFile);
expect(messages[0].range).toEqual([[6, 0], [6, 4]]);
}));
});
expect(messages.length).toBe(1);
expect(messages[0].type).toBe('Warning');
expect(messages[0].html).not.toBeDefined();
expect(messages[0].text).toBe(messageText);
expect(messages[0].filePath).toBe(badFile);
expect(messages[0].range).toEqual([[6, 0], [6, 4]]);
});

it('finds nothing wrong with a valid file', () => {
waitsForPromise(() =>
atom.workspace.open(goodFile)
.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(goodFile);
const messages = await lint(editor);

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

it('handles files indented with tabs', () => {
waitsForPromise(() =>
atom.workspace.open(badTabFile)
.then(editor => lint(editor))
.then(messages => expect(messages.length).toBeGreaterThan(0)));
it('handles files indented with tabs', async () => {
const editor = await atom.workspace.open(badTabFile);
const messages = await lint(editor);

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

it('finds errors on the fly', () => {
waitsForPromise(() =>
atom.workspace.open(goodFile)
.then((editor) => {
editor.moveToBottom();
editor.insertText('\n<h2>This should not be outside the body!</h2>\n');
return lint(editor);
})
.then(messages => expect(messages.length).toBeGreaterThan(0)));
it('finds errors on the fly', async () => {
const editor = await atom.workspace.open(goodFile);
editor.moveToBottom();
editor.insertText('\n<h2>This should not be outside the body!</h2>\n');
const messages = await lint(editor);

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

describe('allows for custom executable arguments and', () => {
it('ignores errors that a user has chosen to ignore', () => {
it('ignores errors that a user has chosen to ignore', async () => {
expect(atom.config.set('linter-tidy.executableArguments', [
'-utf8',
'--show-warnings',
'false',
])).toBe(true);
waitsForPromise(() =>
atom.workspace.open(badFile)
.then(editor => lint(editor))
.then(messages => expect(messages.length).toBe(0)));
const editor = await atom.workspace.open(badFile);
const messages = await lint(editor);

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

it('works as expected with an empty array of custom arguments', () => {
it('works as expected with an empty array of custom arguments', async () => {
expect(atom.config.set('linter-tidy.executableArguments', [])).toBe(true);
waitsForPromise(() => Promise.all([
atom.workspace.open(goodFile)
.then(editor => lint(editor))
.then(messages => expect(messages.length).toBe(0)),
atom.workspace.open(badFile)
.then(editor => lint(editor))
.then(messages => expect(messages.length).toBeGreaterThan(0)),
]));
const goodEditor = await atom.workspace.open(goodFile);
const goodMessages = await lint(goodEditor);
expect(goodMessages.length).toBe(0);

const badEditor = await atom.workspace.open(badFile);
const badMessages = await lint(badEditor);
expect(badMessages.length).toBeGreaterThan(0);
});
});
});