Skip to content

Commit

Permalink
Merge 60ad5d2 into b3fc8b9
Browse files Browse the repository at this point in the history
  • Loading branch information
bartveneman committed Mar 16, 2019
2 parents b3fc8b9 + 60ad5d2 commit 08c15fe
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 131 deletions.
2 changes: 1 addition & 1 deletion src/analyzer/properties/index.js
@@ -1,7 +1,7 @@
const uniquer = require('../../utils/uniquer.js')

module.exports = declarations => {
const all = declarations.map(declaration => declaration.property)
const all = declarations.map(({property}) => property)

const prefixed = require('./prefixed.js')(all)
const browserhacks = require('./browserhacks.js')(all)
Expand Down
9 changes: 1 addition & 8 deletions src/analyzer/properties/prefixed.js
Expand Up @@ -3,14 +3,7 @@ const uniquer = require('../../utils/uniquer')

module.exports = properties => {
const all = properties.filter(isVendorPrefixed)

const share = (() => {
if (properties.length === 0) {
return 0
}

return all.length / properties.length
})()
const share = properties.length === 0 ? 0 : all.length / properties.length

return {
total: all.length,
Expand Down
14 changes: 9 additions & 5 deletions test/analyzer/properties/browserhacks.js
Expand Up @@ -13,29 +13,33 @@ test('It responds with the correct structure', t => {
})

test('It recognizes browser hacks correctly', t => {
const actual = analyze(['_color'])
const actual = analyze(['_color', '*zoom'])
const expected = {
total: 1,
total: 2,
unique: [
{
value: '*zoom',
count: 1
},

{
value: '_color',
count: 1
}
],
totalUnique: 1
totalUnique: 2
}

t.deepEqual(actual, expected)
})

test('It does not report values that are no browser hacks', t => {
const actual = analyze(['color'])
const expected = {
total: 0,
unique: [],
totalUnique: 0
}

const actual = analyze(['color'])

t.deepEqual(actual, expected)
})
61 changes: 56 additions & 5 deletions test/analyzer/properties/index.js
@@ -1,9 +1,60 @@
const test = require('ava')
const testScope = require('../../utils/scope-tester.js')
const analyze = require('../../../src/analyzer/properties')

const SCOPE = 'properties'
test('it responds with the correct structure', t => {
const actual = analyze([])
const expected = {
total: 0,
totalUnique: 0,
unique: [],
browserhacks: {
total: 0,
totalUnique: 0,
unique: []
},
prefixed: {
total: 0,
totalUnique: 0,
unique: [],
share: 0
}
}

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

test('it counts all properties', t => {
const fixture = [
{property: 'color', value: 'unset'},
{property: 'border', value: 'unset'},
{property: 'font-size', value: 'unset'}
]
const {total: actual} = analyze(fixture)
const expected = 3

t.is(actual, expected)
})

test('it lists all unique properties with their count and sorted alphabeticlly', t => {
const fixture = [
{property: 'color', value: 'unset'},
{property: 'color', value: 'unset'},
{property: 'border', value: 'unset'}
]
const {unique: actual} = analyze(fixture)
const expected = [{value: 'border', count: 1}, {value: 'color', count: 2}]

t.deepEqual(actual, expected)
})

test('it counts all unique properties', t => {
const fixture = [
{property: 'color', value: 'unset'},
{property: 'color', value: 'unset'},
{property: 'border', value: 'unset'}
]
const {totalUnique: actual} = analyze(fixture)
const expected = 2

t.is(actual, expected)
})
33 changes: 0 additions & 33 deletions test/analyzer/properties/input.css

This file was deleted.

79 changes: 0 additions & 79 deletions test/analyzer/properties/output.json

This file was deleted.

55 changes: 55 additions & 0 deletions test/analyzer/properties/prefixed.js
@@ -0,0 +1,55 @@
const test = require('ava')
const analyze = require('../../../src/analyzer/properties/prefixed')

test('it responds with the correct structure', t => {
const actual = analyze([])
const expected = {
total: 0,
share: 0,
totalUnique: 0,
unique: []
}

t.deepEqual(actual, expected)
})

const FIXTURE = [
'color',
'-webkit-animation',
'-webkit-animation', // Duplicate
'-moz-appearance'
]

test('it counts prefixed properties', t => {
const {total: actual} = analyze(FIXTURE)

t.is(actual, 3)
})

test('it calculates the prefixed share', t => {
const {share: actual} = analyze(FIXTURE)

t.is(actual, 0.75)
})

test('it finds the unique prefixed properties and counts and sorts them', t => {
const {unique: actual} = analyze(FIXTURE)
const expected = [
{
value: '-moz-appearance',
count: 1
},
{
value: '-webkit-animation',
count: 2
}
]

t.deepEqual(actual, expected)
})

test('it counts the total unique prefixed properties', t => {
const {totalUnique: actual} = analyze(FIXTURE)

t.is(actual, 2)
})

0 comments on commit 08c15fe

Please sign in to comment.