Skip to content

Commit

Permalink
Merge b4046d8 into f0e0688
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcgrtz committed Mar 1, 2024
2 parents f0e0688 + b4046d8 commit 2e6b0f4
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 7,351 deletions.
7,314 changes: 40 additions & 7,274 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -27,7 +27,7 @@
"scripts": {
"coverage": "c8 report --reporter=lcov",
"prepare": "husky",
"test": "xo && c8 ava"
"test": "xo && c8 node --test"
},
"files": [
"index.js"
Expand All @@ -49,7 +49,6 @@
"supports-hyperlinks": "^3.0.0"
},
"devDependencies": {
"ava": "^6.0.1",
"c8": "^9.1.0",
"husky": "^9.0.10",
"lint-staged": "^15.2.0",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
76 changes: 76 additions & 0 deletions test/index.test.js
@@ -0,0 +1,76 @@
import process from 'node:process';
import test from 'node:test';
import assert from 'node:assert';
import stripAnsi from 'strip-ansi';
import ansiEscapes from 'ansi-escapes';
import m from '../index.js';
import defaultFixture from './fixtures/default.js';
import deprecationsFixture from './fixtures/deprecations.js';
import invalidOptionsFixture from './fixtures/invalid-options.js';
import parseErrorFixture from './fixtures/parse-error.js';
import linterResultFixture from './fixtures/linter-result.js';

const enableHyperlinks = () => {
process.env.FORCE_HYPERLINK = '1';
};

const disableHyperlinks = () => {
process.env.FORCE_HYPERLINK = '0';
};

test('output', () => {
disableHyperlinks();
const output = m(defaultFixture);
assert.match(stripAnsi(output), /first\.css:3:12\n/);
assert.match(stripAnsi(output), /✖ {3}3:12 {2}Unexpected leading zero {26}number-leading-zero/);
});

test('deprecations', () => {
disableHyperlinks();
const output = m(deprecationsFixture);
assert.match(stripAnsi(output), /Stylelint Configuration\n/);
assert.match(stripAnsi(output), /ℹ time-no-imperceptible has been deprecated and in 8.0 will be removed. Instead use time-min-milliseconds with 100 as its primary option./);
assert.match(stripAnsi(output), /ℹ block-no-single-line has been deprecated and in 8.0 will be removed. Instead use block-opening-brace-newline-after and block-closing-brace-newline-before with the always option./);
assert.match(stripAnsi(output), /2 deprecations/);
});

test('invalid options', () => {
disableHyperlinks();
const output = m(invalidOptionsFixture);
assert.match(stripAnsi(output), /Stylelint Configuration\n/);
assert.match(stripAnsi(output), /✖ Invalid option value snakeCase for rule value-keyword-case/);
assert.match(stripAnsi(output), /✖ Unexpected option value always for rule no-unknown-animations/);
assert.match(stripAnsi(output), /2 invalid options/);
});

test('parse errors', () => {
disableHyperlinks();
const output = m(parseErrorFixture);
assert.match(stripAnsi(output), /first\.css:7:12\n/);
assert.match(stripAnsi(output), /✖ {2}7:12 {2}Unexpected token {2}parseError/);
assert.match(stripAnsi(output), /1 error/);
});

test('empty results', () => {
disableHyperlinks();
const output = m([]);
assert.equal(stripAnsi(output), '');
});

test('invalid Stylelint output', () => {
disableHyperlinks();
const output = m('foobar');
assert.equal(stripAnsi(output), '');
});

test('linked rules', () => {
enableHyperlinks();
const output = m(defaultFixture, linterResultFixture);
assert.ok(output.includes(ansiEscapes.link('number-leading-zero', 'https://stylelint.io/user-guide/rules/number-leading-zero')));
});

test('no errors when no URL is found to link a rule', () => {
enableHyperlinks();
const output = m(defaultFixture, linterResultFixture);
assert.ok(output.includes('number-no-trailing-zeros'));
});
75 changes: 0 additions & 75 deletions tests/index.test.js

This file was deleted.

0 comments on commit 2e6b0f4

Please sign in to comment.