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

Commit 895bab7

Browse files
Get some more tests passing.
1 parent 4373221 commit 895bab7

File tree

1 file changed

+57
-56
lines changed

1 file changed

+57
-56
lines changed

spec/linter-eslint-node-spec.js

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import * as path from 'path';
44
import * as fs from 'fs';
55
import { tmpdir } from 'os';
6-
// import rimraf from 'rimraf';
6+
import rimraf from 'rimraf';
77
import linterEslintNode from '../lib/main';
88

99
const fixturesDir = path.join(__dirname, 'fixtures');
@@ -146,23 +146,23 @@ describe('The eslint provider for Linter', () => {
146146
const messages = await lint(editor);
147147
expect(messages.length).toBe(2);
148148

149-
const expected0 = "[no-undef] 'foo' is not defined.";
150-
// TODO: const expected0Url = 'https://eslint.org/docs/rules/no-undef';
151-
const expected1 = '[semi] Extra semicolon.';
152-
// TODO: const expected1Url = 'https://eslint.org/docs/rules/semi';
149+
const expected0 = "'foo' is not defined. (no-undef)";
150+
const expected0Url = 'https://eslint.org/docs/rules/no-undef';
151+
const expected1 = 'Extra semicolon. (semi)';
152+
const expected1Url = 'https://eslint.org/docs/rules/semi';
153153

154154
console.log(messages);
155155

156156
expect(messages[0].severity).toBe('error');
157157
expect(messages[0].excerpt).toBe(expected0);
158-
// TODO: expect(messages[0].url).toBe(expected0Url);
158+
expect(messages[0].url).toBe(expected0Url);
159159
expect(messages[0].location.file).toBe(paths.bad);
160160
expect(messages[0].location.position).toEqual([[0, 0], [0, 3]]);
161161
expect(messages[0].solutions).not.toBeDefined();
162162

163163
expect(messages[1].severity).toBe('error');
164164
expect(messages[1].excerpt).toBe(expected1);
165-
// TODO: expect(messages[1].url).toBe(expected1Url);
165+
expect(messages[1].url).toBe(expected1Url);
166166
expect(messages[1].location.file).toBe(paths.bad);
167167
expect(messages[1].location.position).toEqual([[0, 8], [0, 9]]);
168168
expect(messages[1].solutions.length).toBe(1);
@@ -207,13 +207,13 @@ describe('The eslint provider for Linter', () => {
207207
it('shows a message for an invalid import', async () => {
208208
const editor = await atom.workspace.open(paths.badImport);
209209
const messages = await lint(editor);
210-
const expected = "[import/no-unresolved] Unable to resolve path to module '../nonexistent'.";
211-
// TODO: const expectedUrlRegEx = /https[\S]+eslint-plugin-import[\S]+no-unresolved.md/;
210+
const expected = "Unable to resolve path to module '../nonexistent'. (import/no-unresolved)";
211+
const expectedUrlRegEx = /https[\S]+eslint-plugin-import[\S]+no-unresolved.md/;
212212

213213
expect(messages.length).toBe(1);
214214
expect(messages[0].severity).toBe('error');
215215
expect(messages[0].excerpt).toBe(expected);
216-
// TODO: expect(messages[0].url).toMatch(expectedUrlRegEx);
216+
expect(messages[0].url).toMatch(expectedUrlRegEx);
217217
expect(messages[0].location.file).toBe(paths.badImport);
218218
expect(messages[0].location.position).toEqual([[0, 24], [0, 40]]);
219219
expect(messages[0].solutions).not.toBeDefined();
@@ -369,22 +369,22 @@ describe('The eslint provider for Linter', () => {
369369
let expectedPath;
370370

371371
const checkNoConsole = (message) => {
372-
const text = '[no-console] Unexpected console statement.';
373-
// TODO: const url = 'https://eslint.org/docs/rules/no-console';
372+
const text = 'Unexpected console statement. (no-console)';
373+
const url = 'https://eslint.org/docs/rules/no-console';
374374
expect(message.severity).toBe('error');
375375
expect(message.excerpt).toBe(text);
376-
// TODO: expect(message.url).toBe(url);
376+
expect(message.url).toBe(url);
377377
expect(message.location.file).toBe(expectedPath);
378378
expect(message.location.position).toEqual([[0, 0], [0, 11]]);
379379
};
380380

381381
const checkNoTrailingSpace = (message) => {
382-
const text = '[no-trailing-spaces] Trailing spaces not allowed.';
383-
// TODO: const url = 'https://eslint.org/docs/rules/no-trailing-spaces';
382+
const text = 'Trailing spaces not allowed. (no-trailing-spaces)';
383+
const url = 'https://eslint.org/docs/rules/no-trailing-spaces';
384384

385385
expect(message.severity).toBe('error');
386386
expect(message.excerpt).toBe(text);
387-
// TODO: expect(message.url).toBe(url);
387+
expect(message.url).toBe(url);
388388
expect(message.location.file).toBe(expectedPath);
389389
expect(message.location.position).toEqual([[1, 9], [1, 10]]);
390390
};
@@ -527,12 +527,12 @@ describe('The eslint provider for Linter', () => {
527527
it('handles ranges in messages', async () => {
528528
const editor = await atom.workspace.open(paths.endRange);
529529
const messages = await lint(editor);
530-
const expected = '[no-unreachable] Unreachable code.';
531-
// TODO: const expectedUrl = 'https://eslint.org/docs/rules/no-unreachable';
530+
const expected = 'Unreachable code. (no-unreachable)';
531+
const expectedUrl = 'https://eslint.org/docs/rules/no-unreachable';
532532

533533
expect(messages[0].severity).toBe('error');
534534
expect(messages[0].excerpt).toBe(expected);
535-
// TODO: expect(messages[0].url).toBe(expectedUrl);
535+
expect(messages[0].url).toBe(expectedUrl);
536536
expect(messages[0].location.file).toBe(paths.endRange);
537537
expect(messages[0].location.position).toEqual([[5, 2], [6, 15]]);
538538
});
@@ -573,28 +573,27 @@ describe('The eslint provider for Linter', () => {
573573
// });
574574

575575
// TODO:
576-
// describe('when `disableWhenNoEslintConfig` is true', () => {
577-
// let editor;
578-
// let tempFixtureDir;
579-
//
580-
// beforeEach(async () => {
581-
// atom.config.set('linter-eslint-node.disabling.disableWhenNoEslintConfig', true);
582-
//
583-
// const tempFilePath = await copyFileToTempDir(paths.badInline);
584-
// editor = await atom.workspace.open(tempFilePath);
585-
// tempFixtureDir = path.dirname(tempFilePath);
586-
// });
587-
//
588-
// afterEach(() => {
589-
// rimraf.sync(tempFixtureDir);
590-
// });
591-
//
592-
// it('does not report errors when no config file is found', async () => {
593-
// const messages = await lint(editor);
594-
//
595-
// expect(messages.length).toBe(0);
596-
// });
597-
// });
576+
describe('when `disableWhenNoEslintConfig` is true', () => {
577+
let editor;
578+
let tempFixtureDir;
579+
580+
beforeEach(async () => {
581+
atom.config.set('linter-eslint-node.disabling.disableWhenNoEslintConfig', true);
582+
583+
const tempFilePath = await copyFileToTempDir(paths.badInline);
584+
editor = await atom.workspace.open(tempFilePath);
585+
tempFixtureDir = path.dirname(tempFilePath);
586+
});
587+
588+
afterEach(() => {
589+
rimraf.sync(tempFixtureDir);
590+
});
591+
592+
it('does not report errors when no config file is found', async () => {
593+
const messages = await lint(editor);
594+
expect(messages.length).toBe(0);
595+
});
596+
});
598597

599598
// TODO:
600599
// describe('lets ESLint handle configuration', () => {
@@ -686,18 +685,18 @@ describe('The eslint provider for Linter', () => {
686685
// });
687686

688687
describe('handles the Show Rule ID in Messages option', () => {
689-
// TODO: const expectedUrlRegEx = /https[\S]+eslint-plugin-import[\S]+no-unresolved.md/;
688+
const expectedUrlRegEx = /https[\S]+eslint-plugin-import[\S]+no-unresolved.md/;
690689

691690
it('shows the rule ID when enabled', async () => {
692691
atom.config.set('linter-eslint-node.advanced.showRuleIdInMessage', true);
693692
const editor = await atom.workspace.open(paths.badImport);
694693
const messages = await lint(editor);
695-
const expected = "[import/no-unresolved] Unable to resolve path to module '../nonexistent'.";
694+
const expected = "Unable to resolve path to module '../nonexistent'. (import/no-unresolved)";
696695

697696
expect(messages.length).toBe(1);
698697
expect(messages[0].severity).toBe('error');
699698
expect(messages[0].excerpt).toBe(expected);
700-
// TODO: expect(messages[0].url).toMatch(expectedUrlRegEx);
699+
expect(messages[0].url).toMatch(expectedUrlRegEx);
701700
expect(messages[0].location.file).toBe(paths.badImport);
702701
expect(messages[0].location.position).toEqual([[0, 24], [0, 40]]);
703702
expect(messages[0].solutions).not.toBeDefined();
@@ -712,7 +711,7 @@ describe('The eslint provider for Linter', () => {
712711
expect(messages.length).toBe(1);
713712
expect(messages[0].severity).toBe('error');
714713
expect(messages[0].excerpt).toBe(expected);
715-
// TODO: expect(messages[0].url).toMatch(expectedUrlRegEx);
714+
expect(messages[0].url).toMatch(expectedUrlRegEx);
716715
expect(messages[0].location.file).toBe(paths.badImport);
717716
expect(messages[0].location.position).toEqual([[0, 24], [0, 40]]);
718717
expect(messages[0].solutions).not.toBeDefined();
@@ -722,17 +721,19 @@ describe('The eslint provider for Linter', () => {
722721
it("registers an 'ESLint Fix' right click menu command", () => {
723722
// NOTE: Reaches into the private data of the ContextMenuManager, there is
724723
// no public method to check this though so...
725-
expect(atom.contextMenu.itemSets.some((itemSet) => (
726-
// Matching selector...
727-
itemSet.selector === 'atom-text-editor:not(.mini), .overlayer'
728-
&& itemSet.items.some((item) => (
729-
// Matching command...
730-
item.command === 'linter-eslint:fix-file'
731-
// Matching label
732-
&& item.label === 'ESLint Fix'
733-
// And has a function controlling display
734-
&& typeof item.shouldDisplay === 'function'
724+
expect(
725+
atom.contextMenu.itemSets.some((itemSet) => (
726+
// Matching selector...
727+
itemSet.selector === 'atom-text-editor:not(.mini), .overlayer'
728+
&& itemSet.items.some((item) => (
729+
// Matching command...
730+
item.command === 'linter-eslint:fix-file'
731+
// Matching label
732+
&& item.label === 'ESLint Fix'
733+
// And has a function controlling display
734+
&& typeof item.shouldDisplay === 'function'
735+
))
735736
))
736-
)));
737+
).toBe(true);
737738
});
738739
});

0 commit comments

Comments
 (0)