Skip to content

Commit c092085

Browse files
authored
rewrite tests for properties (#113)
1 parent b3fc8b9 commit c092085

File tree

7 files changed

+122
-131
lines changed

7 files changed

+122
-131
lines changed

src/analyzer/properties/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const uniquer = require('../../utils/uniquer.js')
22

33
module.exports = declarations => {
4-
const all = declarations.map(declaration => declaration.property)
4+
const all = declarations.map(({property}) => property)
55

66
const prefixed = require('./prefixed.js')(all)
77
const browserhacks = require('./browserhacks.js')(all)

src/analyzer/properties/prefixed.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,7 @@ const uniquer = require('../../utils/uniquer')
33

44
module.exports = properties => {
55
const all = properties.filter(isVendorPrefixed)
6-
7-
const share = (() => {
8-
if (properties.length === 0) {
9-
return 0
10-
}
11-
12-
return all.length / properties.length
13-
})()
6+
const share = properties.length === 0 ? 0 : all.length / properties.length
147

158
return {
169
total: all.length,

test/analyzer/properties/browserhacks.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,33 @@ test('It responds with the correct structure', t => {
1313
})
1414

1515
test('It recognizes browser hacks correctly', t => {
16-
const actual = analyze(['_color'])
16+
const actual = analyze(['_color', '*zoom'])
1717
const expected = {
18-
total: 1,
18+
total: 2,
1919
unique: [
20+
{
21+
value: '*zoom',
22+
count: 1
23+
},
24+
2025
{
2126
value: '_color',
2227
count: 1
2328
}
2429
],
25-
totalUnique: 1
30+
totalUnique: 2
2631
}
2732

2833
t.deepEqual(actual, expected)
2934
})
3035

3136
test('It does not report values that are no browser hacks', t => {
37+
const actual = analyze(['color'])
3238
const expected = {
3339
total: 0,
3440
unique: [],
3541
totalUnique: 0
3642
}
3743

38-
const actual = analyze(['color'])
39-
4044
t.deepEqual(actual, expected)
4145
})

test/analyzer/properties/index.js

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,60 @@
11
const test = require('ava')
2-
const testScope = require('../../utils/scope-tester.js')
2+
const analyze = require('../../../src/analyzer/properties')
33

4-
const SCOPE = 'properties'
4+
test('it responds with the correct structure', t => {
5+
const actual = analyze([])
6+
const expected = {
7+
total: 0,
8+
totalUnique: 0,
9+
unique: [],
10+
browserhacks: {
11+
total: 0,
12+
totalUnique: 0,
13+
unique: []
14+
},
15+
prefixed: {
16+
total: 0,
17+
totalUnique: 0,
18+
unique: [],
19+
share: 0
20+
}
21+
}
522

6-
test(SCOPE, async t => {
7-
const {actual, expected} = await testScope(SCOPE)
8-
t.deepEqual(actual[SCOPE], expected)
23+
t.deepEqual(actual, expected)
24+
})
25+
26+
test('it counts all properties', t => {
27+
const fixture = [
28+
{property: 'color', value: 'unset'},
29+
{property: 'border', value: 'unset'},
30+
{property: 'font-size', value: 'unset'}
31+
]
32+
const {total: actual} = analyze(fixture)
33+
const expected = 3
34+
35+
t.is(actual, expected)
36+
})
37+
38+
test('it lists all unique properties with their count and sorted alphabeticlly', t => {
39+
const fixture = [
40+
{property: 'color', value: 'unset'},
41+
{property: 'color', value: 'unset'},
42+
{property: 'border', value: 'unset'}
43+
]
44+
const {unique: actual} = analyze(fixture)
45+
const expected = [{value: 'border', count: 1}, {value: 'color', count: 2}]
46+
47+
t.deepEqual(actual, expected)
48+
})
49+
50+
test('it counts all unique properties', t => {
51+
const fixture = [
52+
{property: 'color', value: 'unset'},
53+
{property: 'color', value: 'unset'},
54+
{property: 'border', value: 'unset'}
55+
]
56+
const {totalUnique: actual} = analyze(fixture)
57+
const expected = 2
58+
59+
t.is(actual, expected)
960
})

test/analyzer/properties/input.css

Lines changed: 0 additions & 33 deletions
This file was deleted.

test/analyzer/properties/output.json

Lines changed: 0 additions & 79 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const test = require('ava')
2+
const analyze = require('../../../src/analyzer/properties/prefixed')
3+
4+
test('it responds with the correct structure', t => {
5+
const actual = analyze([])
6+
const expected = {
7+
total: 0,
8+
share: 0,
9+
totalUnique: 0,
10+
unique: []
11+
}
12+
13+
t.deepEqual(actual, expected)
14+
})
15+
16+
const FIXTURE = [
17+
'color',
18+
'-webkit-animation',
19+
'-webkit-animation', // Duplicate
20+
'-moz-appearance'
21+
]
22+
23+
test('it counts prefixed properties', t => {
24+
const {total: actual} = analyze(FIXTURE)
25+
26+
t.is(actual, 3)
27+
})
28+
29+
test('it calculates the prefixed share', t => {
30+
const {share: actual} = analyze(FIXTURE)
31+
32+
t.is(actual, 0.75)
33+
})
34+
35+
test('it finds the unique prefixed properties and counts and sorts them', t => {
36+
const {unique: actual} = analyze(FIXTURE)
37+
const expected = [
38+
{
39+
value: '-moz-appearance',
40+
count: 1
41+
},
42+
{
43+
value: '-webkit-animation',
44+
count: 2
45+
}
46+
]
47+
48+
t.deepEqual(actual, expected)
49+
})
50+
51+
test('it counts the total unique prefixed properties', t => {
52+
const {totalUnique: actual} = analyze(FIXTURE)
53+
54+
t.is(actual, 2)
55+
})

0 commit comments

Comments
 (0)