Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test speed: 1000ms -> 35ms #351

Merged
merged 2 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()