-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To keep up to date with dependencies, it's really hard to know we've done it correctly without some tests and samples to check against. This provides a sample (from guides), with which we can test against in both the positive and negative cases, we include a GitHub Actions configuration too, so tests are automated. https://github.com/thoughtbot/guides/tree/main/sass Co-authored-by: Luke Mitchell <LkeMitchll@users.noreply.github.com>
- Loading branch information
1 parent
e751c72
commit 365ae0e
Showing
7 changed files
with
292 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
name: Tests | ||
on: | ||
push: | ||
branches: | ||
- 'main' | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v4 | ||
- run: npm ci | ||
- run: npm test | ||
|
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,72 @@ | ||
import { beforeEach, describe, it } from 'node:test'; | ||
import assert from 'node:assert/strict'; | ||
import fs from 'node:fs'; | ||
|
||
import stylelint from 'stylelint'; | ||
|
||
import config from '../index.js'; | ||
|
||
describe('rules', () => { | ||
const ruleNames = Object.keys(config.rules); | ||
|
||
it('is not empty', () => { | ||
assert.ok(ruleNames.length > 0); | ||
}); | ||
|
||
for (const ruleName of ruleNames) { | ||
it(`${ruleName}`, async () => { | ||
const rule = await stylelint.rules[ruleName]; | ||
|
||
assert.ok(!rule.meta.deprecated, `the ${ruleName} rule is deprecated`); | ||
}); | ||
} | ||
}) | ||
|
||
describe('with the valid example', () => { | ||
const sampleScss = fs.readFileSync('./__tests__/valid.scss', 'utf-8'); | ||
let result; | ||
|
||
beforeEach(async () => { | ||
result = await stylelint.lint({ | ||
code: sampleScss, | ||
config, | ||
}); | ||
}); | ||
|
||
it('does not error', () => { | ||
assert.equal(result.errored, false); | ||
}); | ||
|
||
it('has no warnings', () => { | ||
assert.equal(result.results[0].warnings.length, 0); | ||
}); | ||
}); | ||
|
||
describe('with the invalid example', () => { | ||
const sampleScss = fs.readFileSync('./__tests__/invalid.scss', 'utf-8'); | ||
let result; | ||
|
||
beforeEach(async () => { | ||
result = await stylelint.lint({ | ||
code: sampleScss, | ||
config, | ||
}); | ||
}); | ||
|
||
it('do error', () => { | ||
assert.equal(result.errored, true); | ||
}); | ||
|
||
it('has the correct amount of warnings', () => { | ||
assert.equal(result.results[0].warnings.length, 1); | ||
}); | ||
|
||
it('flags the correct rules', () => { | ||
assert.deepEqual( | ||
result.results[0].warnings.map((w) => w.rule), | ||
[ | ||
'color-hex-length', | ||
], | ||
); | ||
}); | ||
}); |
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 @@ | ||
$color-variable: #fff; |
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,51 @@ | ||
@import "partial-name"; | ||
|
||
$color-variable: #ffffff; | ||
|
||
/* I'm here to explain what this class does */ | ||
.class-one { | ||
background-color: $color-variable; | ||
border: 0; | ||
line-height: 1.5; | ||
text-size: 0.5rem; | ||
transition: background-color 0.5s ease; | ||
|
||
@media (width >= 1px) { | ||
margin: ($spacing-variable * 2) 1rem; | ||
} | ||
|
||
&:hover { | ||
box-shadow: 0 0 2px 1px rgba($color-variable, 0.2); | ||
} | ||
|
||
&::before { | ||
content: "hello"; | ||
} | ||
} | ||
|
||
$map: ( | ||
"key-1": value-1, | ||
"key-2": value-2, | ||
); | ||
|
||
.class-two { | ||
@extend %placeholder; | ||
@include mixin; | ||
|
||
align-items: center; | ||
display: flex; | ||
flex: 1 1 auto; | ||
|
||
a { | ||
text-decoration: none; | ||
|
||
&:focus, | ||
&:hover { | ||
text-decoration: underline; | ||
} | ||
} | ||
|
||
&.child { | ||
color: $red; | ||
} | ||
} |
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
Oops, something went wrong.