From 796a8b0d3b7d4fec0b94a286a23693553e9311a9 Mon Sep 17 00:00:00 2001 From: Landon Abney Date: Thu, 21 Sep 2017 23:58:35 -0700 Subject: [PATCH] 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. --- package.json | 3 ++- spec/.eslintrc.js | 14 +++++++---- spec/linter-htmlhint-spec.js | 45 ++++++++++++++++-------------------- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index 143cbbc..7dae334 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,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": { "rules": { diff --git a/spec/.eslintrc.js b/spec/.eslintrc.js index ea5b10d..3dc3525 100644 --- a/spec/.eslintrc.js +++ b/spec/.eslintrc.js @@ -1,8 +1,14 @@ module.exports = { - globals: { - waitsForPromise: true - }, env: { - jasmine: true + atomtest: true, + jasmine: true, + }, + rules: { + "import/no-extraneous-dependencies": [ + "error", + { + "devDependencies": true + } + ] } }; diff --git a/spec/linter-htmlhint-spec.js b/spec/linter-htmlhint-spec.js index 2fe67ab..7a32e37 100644 --- a/spec/linter-htmlhint-spec.js +++ b/spec/linter-htmlhint-spec.js @@ -1,40 +1,35 @@ '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/index.js').provideLinter(); describe('The htmlhint provider for Linter', () => { - beforeEach(() => { + beforeEach(async () => { atom.workspace.destroyActivePaneItem(); - waitsForPromise(() => - Promise.all([ - atom.packages.activatePackage('linter-htmlhint'), - atom.packages.activatePackage('language-html') - ])); + await atom.packages.activatePackage('linter-htmlhint'); + await atom.packages.activatePackage('language-html'); }); - it('detects invalid coding style in bad.html and report as error', () => { - waitsForPromise(() => { - const bad = path.join(__dirname, 'fixtures', 'bad.html'); - return atom.workspace.open(bad).then(editor => lint(editor)).then((messages) => { - expect(messages.length).toEqual(1); + it('detects invalid coding style in bad.html and report as error', async () => { + const bad = path.join(__dirname, 'fixtures', 'bad.html'); + const editor = await atom.workspace.open(bad); + const messages = await lint(editor); - // test only the first error - expect(messages[0].type).toBe('error'); - expect(messages[0].text).toBe('Doctype must be declared first.'); - expect(messages[0].filePath).toBe(bad); - expect(messages[0].range).toEqual([[0, 0], [0, 5]]); - }); - }); + expect(messages.length).toEqual(1); + expect(messages[0].type).toBe('error'); + expect(messages[0].text).toBe('Doctype must be declared first.'); + expect(messages[0].filePath).toBe(bad); + expect(messages[0].range).toEqual([[0, 0], [0, 5]]); }); - it('finds nothing wrong with a valid file (good.html)', () => { - waitsForPromise(() => { - const good = path.join(__dirname, 'fixtures', 'good.html'); - return atom.workspace.open(good).then(editor => lint(editor)).then((messages) => { - expect(messages.length).toBe(0); - }); - }); + it('finds nothing wrong with a valid file (good.html)', async () => { + const good = path.join(__dirname, 'fixtures', 'good.html'); + const editor = await atom.workspace.open(good); + const messages = await lint(editor); + + expect(messages.length).toBe(0); }); });