Skip to content

Commit

Permalink
✨ more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
a-tokyo committed Jan 26, 2023
1 parent e07785a commit e2ca7c8
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
__tests__/**/*.css
__tests__/**/*.scss
.stylelintrc.js
72 changes: 72 additions & 0 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,75 @@ describe('flags warnings with invalid css', () => {
expect(result.results[0].warnings[0].column).toBe(15);
});
});

describe('flags no warnings with valid scss', () => {
const validScss = fs.readFileSync('./__tests__/valid.scss', 'utf-8');
let result;

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

it('did not error', () => {
expect(result.errored).toBe(false);
});

it('flags no warnings', () => {
expect(result.results[0].warnings).toHaveLength(0);
});
});

describe('flags warnings with invalid scss', () => {
const invalidScss = fs.readFileSync('./__tests__/invalid.scss', 'utf-8');
let result;

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

it('did error', () => {
expect(result.errored).toBe(true);
});

it('flags warnings', () => {
expect(result.results[0].warnings).toHaveLength(5);
});

it('correct warning text', () => {
expect(result.results[0].warnings.map((w) => w.text)).toEqual([
'Expected custom media query name "--FOO" to be kebab-case',
'Expected custom property name "--FOO" to be kebab-case',
'Expected keyframe name "FOO" to be kebab-case',
'Expected class selector ".FOO" to match BEM CSS pattern https://en.bem.info/methodology/css. Selector validation tool: https://regexr.com/3apms',
'Expected id selector "#FOO" to be kebab-case',
]);
});

it('correct rule flagged', () => {
expect(result.results[0].warnings.map((w) => w.rule)).toEqual([
'custom-media-pattern',
'custom-property-pattern',
'keyframes-name-pattern',
'selector-class-pattern',
'selector-id-pattern',
]);
});

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

it('correct line number', () => {
expect(result.results[0].warnings[0].line).toBe(5);
});

it('correct column number', () => {
expect(result.results[0].warnings[0].column).toBe(15);
});
});
13 changes: 13 additions & 0 deletions __tests__/invalid.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
a {
top: .2em;
}

@custom-media --FOO;

:root { --FOO: 1px; }

@keyframes FOO { /* ... */ }

.FOO { /* ... */ }

#FOO { /* ... */ }
8 changes: 8 additions & 0 deletions __tests__/valid.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@import 'x';
@import '_y';

$color-black: #000000;

.bem-css__classname {
display: none;
}

0 comments on commit e2ca7c8

Please sign in to comment.