Skip to content

Commit

Permalink
Update Stylelint and Configs to Latest Versions
Browse files Browse the repository at this point in the history
- Updated `stylelint-config-cloudfour` to v10
- Updated `stylelint` peer dependency to v16
- Refactored tests to use node:test, to match the core configs
  • Loading branch information
spaceninja committed Feb 8, 2024
1 parent 88e9b6b commit dd76f21
Show file tree
Hide file tree
Showing 9 changed files with 995 additions and 985 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 10.0.0 - 2024-02-08

- Updated `stylelint-config-cloudfour` to v10
- Updated `stylelint` peer dependency to v16

# 9.0.0 - 2023-09-19

- Updated `stylelint-config-cloudfour` to v9
Expand Down
26 changes: 26 additions & 0 deletions __tests__/engines.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { execFileSync } from 'node:child_process';
import { readFileSync } from 'node:fs';

const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));

describe('engines.node', () => {
it("is the same as stylelint's one", () => {
const stylelintVersion = pkg.peerDependencies.stylelint;
const nodeVersion = JSON.parse(
execFileSync('npm', [
'view',
'--json',
`stylelint@${stylelintVersion}`,
'engines.node',
]).toString(),
);

// `^x.y.z` range can return multiple versions.
const nodeVersions = Array.isArray(nodeVersion) ? [...new Set(nodeVersion)] : [nodeVersion];

assert.equal(nodeVersions.length, 1);
assert.ok(nodeVersions.includes(pkg.engines.node));
});
});
72 changes: 0 additions & 72 deletions __tests__/selector-bem-pattern/index.test.js

This file was deleted.

138 changes: 138 additions & 0 deletions __tests__/selector-bem-pattern/index.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import { beforeEach, describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';

import stylelint from 'stylelint';

import config from '../../index.js';

const validCss = readFileSync('./__tests__/selector-bem-pattern/valid.css', 'utf-8');
const invalidCss = readFileSync('./__tests__/selector-bem-pattern/invalid.css', 'utf-8');

describe('stylelint-selector-bem-pattern', () => {
describe('flags no warnings with valid css', () => {
let result;

beforeEach(async () => {
result = await stylelint.lint({
code: validCss,
config,
});
});

it('has no errors', () => {
assert.equal(result.errored, false);
});

it('flags no warnings', () => {
assert.equal(result.results[0].warnings.length, 0);
});

// Useful for logging when unexpected warning text is flagged.
it('no warning text', () => {
assert.deepEqual(
result.results[0].warnings.map((w) => w.text),
[],
);
});

// Useful for logging when unexpected rules are flagged.
it('no rules flagged', () => {
assert.deepEqual(
result.results[0].warnings.map((w) => w.rule),
[],
);
});
});

describe('flags warnings with invalid css', () => {
let result;

beforeEach(async () => {
result = await stylelint.lint({
code: invalidCss,
config,
});
});

it('includes an error', () => {
assert.equal(result.errored, true);
});

it('flags warnings', () => {
assert.equal(result.results[0].warnings.length, 6);
});

it('correct warning text', () => {
assert.deepEqual(
result.results[0].warnings.map((w) => w.text),
[
'Invalid utility selector ".utilityName" (plugin/selector-bem-pattern)',
`Invalid custom property name "--whatever": a component's custom properties must start with the component name (plugin/selector-bem-pattern)`,
'Invalid component selector ".component-name" (plugin/selector-bem-pattern)',
'Invalid component selector ".component-name--modifier-name" (plugin/selector-bem-pattern)',
'Invalid component selector ".component-name__descendent-name" (plugin/selector-bem-pattern)',
'Invalid component selector ".component-name.is-state-of-component" (plugin/selector-bem-pattern)',
],
);
});

it('correct rule flagged', () => {
assert.deepEqual(
result.results[0].warnings.map((w) => w.rule),
[
'plugin/selector-bem-pattern',
'plugin/selector-bem-pattern',
'plugin/selector-bem-pattern',
'plugin/selector-bem-pattern',
'plugin/selector-bem-pattern',
'plugin/selector-bem-pattern',
],
);
});

it('corrects severity flagged', () => {
assert.equal(result.results[0].warnings[0].severity, 'error');
});

it('corrects line number', () => {
assert.equal(result.results[0].warnings[0].line, 7);
});

it('corrects column number', () => {
assert.equal(result.results[0].warnings[0].column, 1);
});
});
});

// describe('flags warnings with invalid css', () => {
// it('flags six warnings', () => {
// return result.then((data) => expect(data.results[0].warnings).toHaveLength(6));
// });

// it('correct warning text', () => {
// return result.then((data) =>
// expect(data.results[0].warnings[0].text).toBe(
// 'Invalid utility selector ".utilityName" (plugin/selector-bem-pattern)',
// ),
// );
// });

// it('correct rule flagged', () => {
// return result.then((data) =>
// expect(data.results[0].warnings[0].rule).toBe('plugin/selector-bem-pattern'),
// );
// });

// it('correct severity flagged', () => {
// return result.then((data) => expect(data.results[0].warnings[0].severity).toBe('error'));
// });

// it('correct line number', () => {
// return result.then((data) => expect(data.results[0].warnings[0].line).toBe(7));
// });

// it('correct column number', () => {
// return result.then((data) => expect(data.results[0].warnings[0].column).toBe(1));
// });
// });
3 changes: 0 additions & 3 deletions __tests__/suitcss/invalid.css

This file was deleted.

70 changes: 0 additions & 70 deletions __tests__/suitcss/suitcss.test.js

This file was deleted.

59 changes: 0 additions & 59 deletions __tests__/suitcss/valid.css

This file was deleted.

Loading

0 comments on commit dd76f21

Please sign in to comment.