Skip to content

Commit

Permalink
Merge 5081e03 into 4c9b003
Browse files Browse the repository at this point in the history
  • Loading branch information
bartveneman committed Mar 3, 2019
2 parents 4c9b003 + 5081e03 commit 16c8181
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 34 deletions.
12 changes: 0 additions & 12 deletions test/analyzer/values/input.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,6 @@
grid-column: 1/-1; /* Used to cause an Error */
}

.prefixes {
-webkit-border-radius: 0;
-moz-border-radius: 0;
-o-border-radius: 0;
border-radius: 0;
background: -webkit-gradient(transparent, transparent);
background: -moz-linear-gradient(transparent, transparent);
background: -ms-linear-gradient(transparent, transparent);
background: -o-linear-gradient(transparent, transparent);
background: linear-gradient(transparent, transparent);
}

/**
* Browser hacks
*/
Expand Down
27 changes: 5 additions & 22 deletions test/analyzer/values/output.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"total": 17,
"total": 8,
"fontfamilies": {
"total": 0,
"totalUnique": 0,
Expand All @@ -11,27 +11,10 @@
"unique": []
},
"prefixed": {
"total": 4,
"totalUnique": 4,
"unique": [
{
"value": "-moz-linear-gradient(transparent, transparent)",
"count": 1
},
{
"value": "-ms-linear-gradient(transparent, transparent)",
"count": 1
},
{
"value": "-o-linear-gradient(transparent, transparent)",
"count": 1
},
{
"value": "-webkit-gradient(transparent, transparent)",
"count": 1
}
],
"share": 0.23529411764705882
"total": 0,
"totalUnique": 0,
"unique": [],
"share": 0
},
"colors": {
"total": 0,
Expand Down
105 changes: 105 additions & 0 deletions test/analyzer/values/prefixed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
const test = require('ava')
const analyze = require('../../../src/analyzer/values/prefixed.js')

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

t.deepEqual(actual, expected)
})

test('It recognizes prefixed values correctly', t => {
const fixtures = [
'-webkit-gradient(transparent, transparent)',
'-moz-linear-gradient(transparent, transparent)',
'-ms-linear-gradient(transparent, transparent)',
'-o-linear-gradient(transparent, transparent)'
]

fixtures.forEach(value => {
t.deepEqual(analyze([value]), {
total: 1,
unique: [{count: 1, value}],
totalUnique: 1,
share: 1
})
})
})

test('It sorts multiple prefixed values correctly', t => {
const fixtures = [
'-webkit-gradient(transparent, transparent)',
'-moz-linear-gradient(transparent, transparent)',
'-ms-linear-gradient(transparent, transparent)',
'-o-linear-gradient(transparent, transparent)'
]
const expected = {
share: 1,
total: 4,
totalUnique: 4,
unique: [
{
count: 1,
value: '-moz-linear-gradient(transparent, transparent)'
},
{
count: 1,
value: '-ms-linear-gradient(transparent, transparent)'
},
{
count: 1,
value: '-o-linear-gradient(transparent, transparent)'
},
{
count: 1,
value: '-webkit-gradient(transparent, transparent)'
}
]
}

t.deepEqual(analyze(fixtures), expected)
})

test('It calculates the share correctly', t => {
const provider = [
[['-webkit-test', 'no-prefix'], 0.5],
[['-webkit-test', 'test1', 'test2', 'test3'], 0.25],
[['test1', 'test2'], 0],
[[], 0]
]

provider.forEach(([values, expected]) => {
t.is(analyze(values).share, expected)
})
})

test('It ignores values that are not prefixed', t => {
const expected = {
total: 0,
unique: [],
totalUnique: 0,
share: 0
}
const actual = analyze([
{
property: 'line-height',
value: '1'
},
{
property: 'margin',
value: '0'
},
{property: '-webkit-border-radius', value: '0'},
{property: '-moz-border-radius', value: '0'},
{property: '-o-border-radius', value: '0'},
{property: 'border-radius', value: '0'},
{property: 'background', value: 'linear-gradient(transparent, transparent)'}
])

t.deepEqual(actual, expected)
})

0 comments on commit 16c8181

Please sign in to comment.