Skip to content

Commit

Permalink
Merge b7d0539 into 3d44318
Browse files Browse the repository at this point in the history
  • Loading branch information
bartveneman committed Mar 14, 2019
2 parents 3d44318 + b7d0539 commit 2a5d5ea
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 45 deletions.
24 changes: 19 additions & 5 deletions test/analyzer/rules/index.js
@@ -1,9 +1,23 @@
const test = require('ava')
const testScope = require('../../utils/scope-tester.js')
const analyze = require('../../../src/analyzer/rules')

const SCOPE = 'rules'
test('it responds with the correct structure', t => {
const actual = analyze([])

test(SCOPE, async t => {
const {actual, expected} = await testScope(SCOPE)
t.deepEqual(actual[SCOPE], expected)
t.deepEqual(actual, {
total: 0,
empty: {
total: 0
}
})
})

test('it counts basic rules', t => {
const {total} = analyze([{declarationsCount: 1}, {declarationsCount: 8}])
t.is(total, 2)
})

test('it counts empty rules', t => {
const actual = analyze([{declarationsCount: 1}, {declarationsCount: 0}])
t.is(actual.empty.total, 1)
})
27 changes: 0 additions & 27 deletions test/analyzer/rules/input.css

This file was deleted.

6 changes: 0 additions & 6 deletions test/analyzer/rules/output.json

This file was deleted.

29 changes: 22 additions & 7 deletions test/parser/rules.js
Expand Up @@ -2,18 +2,33 @@ const test = require('ava')
const parser = require('../../src/parser')

test('basic rules are parsed', async t => {
const fixture = 'html {} @media screen { html {} }'
const fixture = 'html {color:red} @media screen { html {} }'
const actual = await parser(fixture)
const expected = 2
const expected = [{declarationsCount: 1}, {declarationsCount: 0}]

t.is(actual.rules.length, expected)
t.deepEqual(actual.rules, expected)
})

test('declarations per rule are counted', async t => {
const fixture = ('html, body {color:red; font-size : 12px} .foo {color: red;}')
const fixture = 'html, body {color:red; font-size : 12px} .foo {color: red;}'
const actual = await parser(fixture)
const expected = [2, 1].map(num => ({declarationsCount: num}))
t.deepEqual(actual.rules, expected)
})

test('heavily nested rules are parsed', async t => {
const fixture = `
@media screen {
@media print {
@media (min-width: 1px) {
.rule2 {
color: red;
}
}
}
}
`
const actual = await parser(fixture)
const expected = [2, 1].map(num => {
return {declarationsCount: num}
})
const expected = [{declarationsCount: 1}]
t.deepEqual(actual.rules, expected)
})

0 comments on commit 2a5d5ea

Please sign in to comment.