Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart Veneman committed Sep 12, 2023
1 parent 8af477f commit 089537a
Show file tree
Hide file tree
Showing 11 changed files with 269 additions and 264 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ jobs:
timeout-minutes: 3
strategy:
matrix:
nodejs: [12, 14, 16, 18]
nodejs: [18, 20]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.nodejs }}
- name: Install dependencies
run: npm ci
run: npm ci --ignore-scripts --no-audit
- name: Run tests
run: npm test
env:
Expand Down
398 changes: 199 additions & 199 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
"dist"
],
"dependencies": {
"@projectwallace/css-analyzer": "^5.7.1",
"@projectwallace/css-analyzer": "^5.12.0",
"picocolors": "^1.0.0"
},
"devDependencies": {
"esbuild": "^0.16.14",
"esbuild": "^0.16.17",
"uvu": "^0.5.6"
}
}
}
2 changes: 1 addition & 1 deletion src/__fixtures__/bol-dot-com.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ AtRules Total Unique Unique %
@container 0 0 0.0%

Declarations Total Unique Unique %
Declarations 10,083 1,798 17.8%
Declarations 10,083 1,797 17.8%
!important 1,589

Values Total Unique Unique %
Expand Down
4 changes: 2 additions & 2 deletions src/__fixtures__/cnn.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ AtRules Total Unique Unique %
@container 0 0 0.0%

Declarations Total Unique Unique %
Declarations 13,265 2,888 21.8%
Declarations 13,265 2,886 21.8%
!important 132

Values Total Unique Unique %
Expand All @@ -29,4 +29,4 @@ Font-sizes 1,293 319 24.7%
Font-families 398 19 4.8%
Text-shadows 9 6 66.7%
Box-shadows 15 9 60.0%
Z-indexes 173 20 11.6%
Z-indexes 173 19 11.0%
2 changes: 1 addition & 1 deletion src/__fixtures__/css-tricks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ AtRules Total Unique Unique %
@container 0 0 0.0%

Declarations Total Unique Unique %
Declarations 2,633 1,133 43.0%
Declarations 2,633 1,132 43.0%
!important 167

Values Total Unique Unique %
Expand Down
2 changes: 1 addition & 1 deletion src/__fixtures__/small.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"stylesheet":{"sourceLinesOfCode":7,"linesOfCode":13,"size":173,"comments":{"total":0,"size":0},"embeddedContent":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0,"size":{"total":0,"ratio":0}}},"atrules":{"fontface":{"total":0,"totalUnique":0,"unique":[],"uniquenessRatio":1},"import":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0},"media":{"total":1,"totalUnique":1,"unique":{"(min-width: 100px)":1},"uniquenessRatio":1},"charset":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0},"supports":{"total":1,"totalUnique":1,"unique":{"(display: grid)":1},"uniquenessRatio":1},"keyframes":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0,"prefixed":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0,"ratio":0}},"container":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0}},"rules":{"total":2,"empty":{"total":0,"ratio":0},"selectors":{"min":1,"max":1,"mean":1,"mode":1,"median":1,"range":0,"sum":2,"items":[1,1]},"declarations":{"min":1,"max":2,"mean":1.5,"mode":1.5,"median":1.5,"range":1,"sum":3,"items":[1,2]}},"selectors":{"total":2,"totalUnique":2,"uniquenessRatio":1,"specificity":{"min":[0,0,2],"max":[0,1,0],"sum":[0,1,2],"mean":[0,0.5,1],"mode":[0,0.5,1],"median":[0,0.5,1],"items":[[0,1,0],[0,0,2]]},"complexity":{"min":1,"max":2,"mean":1.5,"mode":1.5,"median":1.5,"range":1,"sum":3,"total":2,"totalUnique":2,"unique":{"1":1,"2":1},"uniquenessRatio":1,"items":[1,2]},"id":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0,"ratio":0},"accessibility":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0,"ratio":0},"keyframes":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0,"ratio":0}},"declarations":{"total":3,"unique":{"total":3,"ratio":1},"importants":{"total":1,"ratio":0.3333333333333333,"inKeyframes":{"total":0,"ratio":0}}},"properties":{"total":3,"totalUnique":3,"unique":{"color":1,"content":1,"*zoom":1},"uniquenessRatio":1,"prefixed":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0,"ratio":0},"custom":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0,"ratio":0},"browserhacks":{"total":1,"totalUnique":1,"unique":{"*zoom":1},"uniquenessRatio":1,"ratio":0.3333333333333333}},"values":{"colors":{"total":1,"totalUnique":1,"unique":{"green":1},"uniquenessRatio":1,"itemsPerContext":{"color":{"total":1,"totalUnique":1,"unique":{"green":1},"uniquenessRatio":1}}},"fontFamilies":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0},"fontSizes":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0},"zindexes":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0},"textShadows":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0},"boxShadows":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0},"animations":{"durations":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0},"timingFunctions":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0}},"prefixes":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0},"units":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0,"itemsPerContext":{}}}}
{"stylesheet":{"sourceLinesOfCode":7,"linesOfCode":13,"size":173,"comments":{"total":0,"size":0},"embeddedContent":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0,"size":{"total":0,"ratio":0},"types":{"total":0,"totalUnique":0,"uniquenessRatio":0,"unique":{}}}},"atrules":{"fontface":{"total":0,"totalUnique":0,"unique":[],"uniquenessRatio":0},"import":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0},"media":{"total":1,"totalUnique":1,"unique":{"(min-width: 100px)":1},"uniquenessRatio":1,"browserhacks":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0}},"charset":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0},"supports":{"total":1,"totalUnique":1,"unique":{"(display: grid)":1},"uniquenessRatio":1,"browserhacks":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0}},"keyframes":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0,"prefixed":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0,"ratio":0}},"container":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0},"layer":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0},"property":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0}},"rules":{"total":2,"empty":{"total":0,"ratio":0},"sizes":{"min":2,"max":3,"mean":2.5,"mode":2.5,"median":2.5,"range":1,"sum":5,"items":[2,3],"total":2,"totalUnique":2,"unique":{"2":1,"3":1},"uniquenessRatio":1},"selectors":{"min":1,"max":1,"mean":1,"mode":1,"median":1,"range":0,"sum":2,"items":[1,1],"total":2,"totalUnique":1,"unique":{"1":2},"uniquenessRatio":0.5},"declarations":{"min":1,"max":2,"mean":1.5,"mode":1.5,"median":1.5,"range":1,"sum":3,"items":[1,2],"total":2,"totalUnique":2,"unique":{"1":1,"2":1},"uniquenessRatio":1}},"selectors":{"total":2,"totalUnique":2,"uniquenessRatio":1,"specificity":{"min":[0,0,2],"max":[0,1,0],"sum":[0,1,2],"mean":[0,0.5,1],"mode":[0,0.5,1],"median":[0,0.5,1],"items":[[0,1,0],[0,0,2]],"total":2,"totalUnique":2,"unique":{"0,1,0":1,"0,0,2":1},"uniquenessRatio":1},"complexity":{"min":1,"max":2,"mean":1.5,"mode":1.5,"median":1.5,"range":1,"sum":3,"total":2,"totalUnique":2,"unique":{"1":1,"2":1},"uniquenessRatio":1,"items":[1,2]},"id":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0,"ratio":0},"accessibility":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0,"ratio":0},"keyframes":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0},"prefixed":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0,"ratio":0},"combinators":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0}},"declarations":{"total":3,"totalUnique":3,"uniquenessRatio":1,"unique":{"total":3,"ratio":1},"importants":{"total":1,"ratio":0.3333333333333333,"inKeyframes":{"total":0,"ratio":0}}},"properties":{"total":3,"totalUnique":3,"unique":{"color":1,"content":1,"*zoom":1},"uniquenessRatio":1,"prefixed":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0,"ratio":0},"custom":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0,"ratio":0,"importants":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0,"ratio":0}},"browserhacks":{"total":1,"totalUnique":1,"unique":{"*zoom":1},"uniquenessRatio":1,"ratio":0.3333333333333333},"complexity":{"min":1,"max":2,"mean":1.3333333333333333,"mode":1,"median":1,"range":1,"sum":4}},"values":{"colors":{"total":1,"totalUnique":1,"unique":{"green":1},"uniquenessRatio":1,"itemsPerContext":{"color":{"total":1,"totalUnique":1,"unique":{"green":1},"uniquenessRatio":1}},"formats":{"total":1,"totalUnique":1,"unique":{"named":1},"uniquenessRatio":1}},"gradients":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0},"fontFamilies":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0},"fontSizes":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0},"lineHeights":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0},"zindexes":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0},"textShadows":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0},"boxShadows":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0},"animations":{"durations":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0},"timingFunctions":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0}},"prefixes":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0},"browserhacks":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0},"units":{"total":0,"totalUnique":0,"unique":{},"uniquenessRatio":0,"itemsPerContext":{}}}}
4 changes: 2 additions & 2 deletions src/__fixtures__/small.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
───────────────────────────────────────────────────────────
Lines of Code │ Filesize │ Rules │ Selectors │ Declarations
7 │ 173B │ 2 │ 2 │ 3
7 │ 173B │ 2 │ 2 │ 3
───────────────────────────────────────────────────────────

Rulesets Most common Average Maximum
Expand All @@ -14,7 +14,7 @@ Specificity 0/0.5/1 0/0.5/1 0/1/0
AtRules Total Unique Unique %
@media 1 1 100.0%
@supports 1 1 100.0%
@font-face 0 0 100.0%
@font-face 0 0 0.0%
@import 0 0 0.0%
@keyframes 0 0 0.0%
@container 0 0 0.0%
Expand Down
6 changes: 3 additions & 3 deletions src/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ export function Analytics(stats, style) {
),
Row(
'Specificity',
selectors.specificity.mode.join(style.dim(',')),
selectors.specificity.mode.join(style.dim('/')),
selectors.specificity.mean
.map(n => toNumber(n, { decimals: 1 }))
.join(style.dim(',')),
selectors.specificity.max.join(style.dim(','))
.join(style.dim('/')),
selectors.specificity.max.join(style.dim('/'))
),
].join('\n')
}
Expand Down
5 changes: 5 additions & 0 deletions src/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export async function Program({ args, readFile, terminalColors, stdin }) {
return true
})
const css = pathParam ? await readFile(pathParam) : stdin

if (!css) {
return help(terminalColors)
}

const stats = analyze(css)
delete stats.__meta__

Expand Down
100 changes: 50 additions & 50 deletions src/program.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { help } from './help.js'

const cssFixture = fs.readFileSync('./src/__fixtures__/small.css', 'utf-8')
const resultFixture = fs.readFileSync('./src/__fixtures__/small.txt', 'utf-8')
const resultJson = fs.readFileSync('./src/__fixtures__/small.json', 'utf-8')
const resultJson = JSON.parse(fs.readFileSync('./src/__fixtures__/small.json', 'utf-8'))

const terminalColors = {
bold: str => str,
Expand All @@ -22,66 +22,90 @@ ProgramSuite('wallace (no stdIn + no args)', async () => {
args: [],
readFile: () => Promise.resolve(),
terminalColors,
stdIn: '',
stdin: '',
})
const expected = help(terminalColors)

assert.equal(actual, expected)
})

ProgramSuite('cat style.css | wallace', async () => {
ProgramSuite('cat style.css | wallace --help', async () => {
const actual = await Program({
args: [],
readFile: undefined,
terminalColors,
stdIn: cssFixture,
args: ['--help'],
readFile: Promise.resolve,
terminalColors: terminalColors,
stdin: cssFixture,
})
const expected = help(terminalColors)

assert.equal(actual, resultFixture.trim())
assert.equal(actual, expected)
})

ProgramSuite('cat style.css | wallace --json', async () => {
ProgramSuite('wallace style.css --help', async () => {
const actual = await Program({
args: ['--json'],
readFile: undefined,
terminalColors,
stdIn: cssFixture,
args: ['style.css', '--help'],
readFile: () => Promise.resolve(cssFixture),
terminalColors: terminalColors,
stdin: '',
})
const expected = help(terminalColors)

assert.equal(actual, resultJson.trim())
assert.equal(actual, expected)
})

ProgramSuite('cat style.css | wallace --help', async () => {
ProgramSuite('cat style.css | wallace -h', async () => {
const actual = await Program({
args: ['--help'],
args: ['-h'],
readFile: Promise.resolve,
terminalColors: terminalColors,
stdIn: cssFixture,
stdin: cssFixture,
})
const expected = help(terminalColors)

assert.equal(actual, expected)
})

ProgramSuite('cat style.css | wallace -h', async () => {
ProgramSuite('wallace style.css -h', async () => {
const actual = await Program({
args: ['-h'],
readFile: Promise.resolve,
args: ['style.css', '-h'],
readFile: () => Promise.resolve(cssFixture),
terminalColors: terminalColors,
stdIn: cssFixture,
stdin: '',
})
const expected = help(terminalColors)

assert.equal(actual, expected)
})

ProgramSuite('cat style.css | wallace', async () => {
const actual = await Program({
args: [],
readFile: Promise.resolve,
terminalColors,
stdin: cssFixture,
})

assert.is(actual, resultFixture.trim())
})

ProgramSuite('cat style.css | wallace --json', async () => {
const actual = await Program({
args: ['--json'],
readFile: Promise.resolve,
terminalColors,
stdin: cssFixture,
})

assert.equal(JSON.parse(actual), resultJson)
})

ProgramSuite('wallace non-existing.css', async () => {
try {
await Program({
args: ['non-existing.css'],
readFile: () => Promise.reject(new Error()),
terminalColors,
stdIn: '',
stdin: '',
})
assert.unreachable()
} catch (error) {
Expand All @@ -94,45 +118,21 @@ ProgramSuite('wallace style.css', async () => {
args: ['style.css'],
readFile: () => Promise.resolve(cssFixture),
terminalColors,
stdIn: '',
stdin: '',
})

assert.equal(actual, resultFixture.trim())
assert.is(actual, resultFixture.trim())
})

ProgramSuite('wallace style.css --json', async () => {
const actual = await Program({
args: ['style.css', '--json'],
readFile: () => Promise.resolve(cssFixture),
terminalColors,
stdIn: '',
})

assert.equal(actual, resultJson.trim())
})

ProgramSuite('wallace style.css --help', async () => {
const actual = await Program({
args: ['style.css', '--help'],
readFile: () => Promise.resolve(cssFixture),
terminalColors: terminalColors,
stdIn: '',
stdin: '',
})
const expected = help(terminalColors)

assert.equal(actual, expected)
})

ProgramSuite('wallace style.css -h', async () => {
const actual = await Program({
args: ['style.css', '-h'],
readFile: () => Promise.resolve(cssFixture),
terminalColors: terminalColors,
stdIn: '',
})
const expected = help(terminalColors)

assert.equal(actual, expected)
assert.equal(JSON.parse(actual), resultJson)
})

ProgramSuite.run()

0 comments on commit 089537a

Please sign in to comment.