diff --git a/spec/fixtures/good/.stylelintrc b/spec/fixtures/good/.stylelintrc new file mode 100644 index 00000000..0eb6e7c4 --- /dev/null +++ b/spec/fixtures/good/.stylelintrc @@ -0,0 +1,5 @@ +{ + "rules": { + "block-no-empty": true + } +} diff --git a/spec/fixtures/ignore-files/.stylelintrc b/spec/fixtures/ignore-files/.stylelintrc index 22058bad..96d18db3 100644 --- a/spec/fixtures/ignore-files/.stylelintrc +++ b/spec/fixtures/ignore-files/.stylelintrc @@ -1,4 +1,8 @@ { - "ignoreFiles": ["styles.css"], - "rules": { "block-no-empty": true } + "ignoreFiles": [ + "styles.css" + ], + "rules": { + "block-no-empty": true + } } diff --git a/spec/fixtures/invalid/.stylelintrc b/spec/fixtures/invalid/.stylelintrc new file mode 100644 index 00000000..0eb6e7c4 --- /dev/null +++ b/spec/fixtures/invalid/.stylelintrc @@ -0,0 +1,5 @@ +{ + "rules": { + "block-no-empty": true + } +} diff --git a/spec/fixtures/less/.stylelintrc b/spec/fixtures/less/.stylelintrc new file mode 100644 index 00000000..0eb6e7c4 --- /dev/null +++ b/spec/fixtures/less/.stylelintrc @@ -0,0 +1,5 @@ +{ + "rules": { + "block-no-empty": true + } +} diff --git a/spec/fixtures/less/stylelint-config-standard.less b/spec/fixtures/less/bad.less similarity index 100% rename from spec/fixtures/less/stylelint-config-standard.less rename to spec/fixtures/less/bad.less diff --git a/spec/fixtures/postcss/.stylelintrc b/spec/fixtures/postcss/.stylelintrc new file mode 100644 index 00000000..0eb6e7c4 --- /dev/null +++ b/spec/fixtures/postcss/.stylelintrc @@ -0,0 +1,5 @@ +{ + "rules": { + "block-no-empty": true + } +} diff --git a/spec/fixtures/sugarss/.stylelintrc b/spec/fixtures/sugarss/.stylelintrc new file mode 100644 index 00000000..ae0266d1 --- /dev/null +++ b/spec/fixtures/sugarss/.stylelintrc @@ -0,0 +1,5 @@ +{ + "rules": { + "number-leading-zero": "always" + } +} diff --git a/spec/linter-stylelint-spec.js b/spec/linter-stylelint-spec.js index b9cfde9a..66b30c6c 100644 --- a/spec/linter-stylelint-spec.js +++ b/spec/linter-stylelint-spec.js @@ -4,22 +4,10 @@ import * as path from 'path'; // eslint-disable-next-line no-unused-vars, import/no-extraneous-dependencies import { it, fit, wait, beforeEach, afterEach } from 'jasmine-fix'; -const badDir = path.join(__dirname, 'fixtures', 'bad'); -const configStandardPath = path.join(badDir, 'stylelint-config-standard.css'); -const warn = path.join(__dirname, 'fixtures', 'warn', 'warn.css'); -const good = path.join(__dirname, 'fixtures', 'good', 'good.css'); -const ignorePath = path.join(__dirname, 'fixtures', 'ignore-files', 'styles.css'); -const invalidPath = path.join(__dirname, 'fixtures', 'invalid', 'invalid.css'); -const invalidRulePath = path.join(__dirname, 'fixtures', 'invalid-rule', 'styles.css'); -const invalidExtendsPath = path.join(__dirname, 'fixtures', 'invalid-extends', 'styles.css'); -const invalidConfigPath = path.join(__dirname, 'fixtures', 'invalid-config', 'styles.css'); -const lessDir = path.join(__dirname, 'fixtures', 'less'); -const goodLess = path.join(lessDir, 'good.less'); -const configStandardLessPath = path.join(lessDir, 'stylelint-config-standard.less'); -const goodPostCSS = path.join(__dirname, 'fixtures', 'postcss', 'styles.pcss'); -const issuesPostCSS = path.join(__dirname, 'fixtures', 'postcss', 'issues.pcss'); -const goodSugarSS = path.join(__dirname, 'fixtures', 'sugarss', 'good.sss'); -const badSugarSS = path.join(__dirname, 'fixtures', 'sugarss', 'bad.sss'); +const fixtures = path.join(__dirname, 'fixtures'); +const configStandardPath = path.join(fixtures, 'bad', 'stylelint-config-standard.css'); +const warningPath = path.join(fixtures, 'warn', 'warn.css'); +const invalidRulePath = path.join(fixtures, 'invalid-rule', 'styles.css'); const blockNoEmpty = 'Unexpected empty block (block-no-empty)'; @@ -28,14 +16,13 @@ describe('The stylelint provider for Linter', () => { beforeEach(async () => { atom.workspace.destroyActivePaneItem(); - atom.config.set('linter-stylelint.useStandard', true); await atom.packages.activatePackage('language-css'); await atom.packages.activatePackage('linter-stylelint'); }); it('bundles and works with stylelint-config-standard', async () => { - atom.config.set('linter-stylelint.disableWhenNoConfig', false); + atom.config.set('linter-stylelint.useStandard', true); const editor = await atom.workspace.open(configStandardPath); const messages = await lint(editor); expect(messages.length).toBeGreaterThan(0); @@ -50,8 +37,7 @@ describe('The stylelint provider for Linter', () => { }); it('reports rules set as warnings as a Warning', async () => { - atom.config.set('linter-stylelint.useStandard', false); - const editor = await atom.workspace.open(warn); + const editor = await atom.workspace.open(warningPath); const messages = await lint(editor); expect(messages.length).toBeGreaterThan(0); @@ -66,13 +52,14 @@ describe('The stylelint provider for Linter', () => { }); it('finds nothing wrong with a valid file', async () => { - const editor = await atom.workspace.open(good); + const goodPath = path.join(fixtures, 'good', 'good.css'); + const editor = await atom.workspace.open(goodPath); const messages = await lint(editor); expect(messages.length).toBe(0); }); it('shows CSS syntax errors with an invalid file', async () => { - atom.config.set('linter-stylelint.disableWhenNoConfig', false); + const invalidPath = path.join(fixtures, 'invalid', 'invalid.css'); const editor = await atom.workspace.open(invalidPath); const messages = await lint(editor); expect(messages.length).toBe(1); @@ -87,7 +74,6 @@ describe('The stylelint provider for Linter', () => { it('shows an error on non-fatal stylelint runtime error', async () => { const text = 'Unexpected option value "foo" for rule "block-no-empty"'; - atom.config.set('linter-stylelint.useStandard', false); const editor = await atom.workspace.open(invalidRulePath); const messages = await lint(editor); expect(messages.length).toBe(1); @@ -101,7 +87,8 @@ describe('The stylelint provider for Linter', () => { }); it('shows an error notification for a fatal stylelint runtime error', async () => { - atom.config.set('linter-stylelint.useStandard', false); + const invalidExtendsPath = path.join(fixtures, 'invalid-extends', 'styles.css'); + spyOn(atom.notifications, 'addError').andCallFake(() => ({})); const addError = atom.notifications.addError; @@ -117,7 +104,8 @@ describe('The stylelint provider for Linter', () => { }); it('shows an error notification with a broken syntax configuration', async () => { - atom.config.set('linter-stylelint.useStandard', false); + const invalidConfigPath = path.join(fixtures, 'invalid-config', 'styles.css'); + spyOn(atom.notifications, 'addError').andCallFake(() => ({})); const addError = atom.notifications.addError; @@ -133,7 +121,6 @@ describe('The stylelint provider for Linter', () => { }); it('disables when no configuration file is found', async () => { - atom.config.set('linter-stylelint.disableWhenNoConfig', true); spyOn(atom.notifications, 'addError').andCallFake(() => ({})); const editor = await atom.workspace.open(configStandardPath); @@ -143,9 +130,7 @@ describe('The stylelint provider for Linter', () => { }); describe('ignores files when files are specified in ignoreFiles and', () => { - beforeEach(() => { - atom.config.set('linter-stylelint.useStandard', true); - }); + const ignorePath = path.join(fixtures, 'ignore-files', 'styles.css'); it('shows a message when asked to', async () => { atom.config.set('linter-stylelint.showIgnored', true); @@ -170,35 +155,35 @@ describe('The stylelint provider for Linter', () => { }); it("doesn't persist settings across runs", async () => { - atom.config.set('linter-stylelint.useStandard', true); - atom.config.set('linter-stylelint.disableWhenNoConfig', false); // The config for this folder breaks the block-no-empty rule const invalidEditor = await atom.workspace.open(invalidRulePath); await lint(invalidEditor); // While this file uses that rule - const editor = await atom.workspace.open(configStandardPath); + const editor = await atom.workspace.open(warningPath); const messages = await lint(editor); expect(messages.length).toBeGreaterThan(0); // test only the first error - expect(messages[0].type).toBe('Error'); - expect(messages[0].severity).toBe('error'); + expect(messages[0].type).toBe('Warning'); + expect(messages[0].severity).toBe('warning'); expect(messages[0].text).not.toBeDefined(); expect(messages[0].html).toBe(blockNoEmpty); - expect(messages[0].filePath).toBe(configStandardPath); + expect(messages[0].filePath).toBe(warningPath); expect(messages[0].range).toEqual([[0, 5], [0, 7]]); }); describe('works with Less files and', () => { + const lessDir = path.join(fixtures, 'less'); + const goodLess = path.join(lessDir, 'good.less'); + const badLess = path.join(lessDir, 'bad.less'); + beforeEach(async () => { - atom.config.set('linter-stylelint.useStandard', true); - atom.config.set('linter-stylelint.disableWhenNoConfig', false); await atom.packages.activatePackage('language-less'); }); - it('works with stylelint-config-standard', async () => { - const editor = await atom.workspace.open(configStandardLessPath); + it('shows lint messages when found', async () => { + const editor = await atom.workspace.open(badLess); const messages = await lint(editor); expect(messages.length).toBeGreaterThan(0); @@ -207,7 +192,7 @@ describe('The stylelint provider for Linter', () => { expect(messages[0].severity).toBe('error'); expect(messages[0].text).not.toBeDefined(); expect(messages[0].html).toBe(blockNoEmpty); - expect(messages[0].filePath).toBe(configStandardLessPath); + expect(messages[0].filePath).toBe(badLess); expect(messages[0].range).toEqual([[0, 5], [0, 7]]); }); @@ -219,13 +204,14 @@ describe('The stylelint provider for Linter', () => { }); describe('works with PostCSS files and', () => { + const goodPostCSS = path.join(fixtures, 'postcss', 'styles.pcss'); + const issuesPostCSS = path.join(fixtures, 'postcss', 'issues.pcss'); + beforeEach(async () => { - atom.config.set('linter-stylelint.useStandard', true); - atom.config.set('linter-stylelint.disableWhenNoConfig', false); await atom.packages.activatePackage('language-postcss'); }); - it('works with stylelint-config-standard', async () => { + it('shows lint messages when found', async () => { const editor = await atom.workspace.open(issuesPostCSS); const messages = await lint(editor); expect(messages.length).toBeGreaterThan(0); @@ -247,13 +233,14 @@ describe('The stylelint provider for Linter', () => { }); describe('works with SugarSS files and', () => { + const goodSugarSS = path.join(fixtures, 'sugarss', 'good.sss'); + const badSugarSS = path.join(fixtures, 'sugarss', 'bad.sss'); + beforeEach(async () => { - atom.config.set('linter-stylelint.useStandard', true); - atom.config.set('linter-stylelint.disableWhenNoConfig', false); await atom.packages.activatePackage('language-postcss'); }); - it('works with stylelint-config-standard', async () => { + it('shows lint messages when found', async () => { const nlzMessage = 'Expected a leading zero (number-leading-zero)'; const editor = await atom.workspace.open(badSugarSS); const messages = await lint(editor);