Skip to content

Commit

Permalink
Improve test speed: 1000ms -> 35ms (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartveneman authored Oct 15, 2023
1 parent beaeaf0 commit 88fd34f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ Api('handles empty input gracefully', () => {
})

Api('has metadata', () => {
const fixture = Array.from({ length: 10 }).map(_ => `
const fixture = Array.from({ length: 100 }).map(_ => `
html {
font: 1em/1 sans-serif;
color: rgb(0 0 0 / 0.5);
Expand Down
27 changes: 16 additions & 11 deletions src/smoke.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as fs from 'fs'
import { readFileSync, writeFileSync } from 'fs'
import { suite } from 'uvu';
import * as assert from 'uvu/assert';
import { analyze } from './index.js'
Expand All @@ -16,23 +16,28 @@ Object.entries({
'Smashing Magazine': 'smashing-magazine-20231008',
'Trello': 'trello-20231008',
}).map(([name, fileName]) => {
const css = fs.readFileSync(`./src/__fixtures__/${fileName}.css`, 'utf-8')
const json = fs.readFileSync(`./src/__fixtures__/${fileName}.json`, 'utf-8')
const css = readFileSync(`./src/__fixtures__/${fileName}.css`, 'utf-8')
const json = readFileSync(`./src/__fixtures__/${fileName}.json`, 'utf-8')
return {
name,
fileName,
json,
css,
}
}).forEach(({ name, fileName, css, json }) => {
// const result = analyze(css)
// delete result.__meta__
// fs.writeFileSync(`./src/__fixtures__/${fileName}.json`, JSON.stringify(result, null, 2))
Smoke(`${name} matches fixture`, () => {
const result = analyze(css)
delete result.__meta__
assert.fixture(JSON.stringify(result, null, 2), json)
})
const actual = analyze(css)
delete actual.__meta__
const expected = JSON.parse(json)

// writeFileSync(`./src/__fixtures__/${fileName}.json`, JSON.stringify(actual, null, 2))

Smoke(`${name} - Stylesheet`, () => assert.equal(actual.stylesheet, expected.stylesheet))
Smoke(`${name} - Atrules`, () => assert.equal(actual.atrules, expected.atrules))
Smoke(`${name} - Rules`, () => assert.equal(actual.rules, expected.rules))
Smoke(`${name} - Selectors`, () => assert.equal(actual.selectors, expected.selectors))
Smoke(`${name} - Declarations`, () => assert.equal(actual.declarations, expected.declarations))
Smoke(`${name} - Properties`, () => assert.equal(actual.properties, expected.properties))
Smoke(`${name} - Values`, () => assert.equal(actual.values, expected.values))
})

Smoke.run()

0 comments on commit 88fd34f

Please sign in to comment.