-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Stylelint and Configs to Latest Versions
- 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
1 parent
88e9b6b
commit dd76f21
Showing
9 changed files
with
995 additions
and
985 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
// }); | ||
// }); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.