Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
thecrypticace committed Aug 29, 2022
1 parent b0a5499 commit 40996f5
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/important-boolean.test.js
@@ -1,5 +1,6 @@
import fs from 'fs'
import path from 'path'
import * as sharedState from '../src/lib/sharedState'

import { run, css } from './util/run'

Expand Down Expand Up @@ -63,3 +64,56 @@ test('important boolean', () => {
expect(result.css).toMatchFormattedCss(expected)
})
})

test('important rules are not duplicated when rebuilding', async () => {
let config = {
important: true,
content: [path.resolve(__dirname, './important-boolean-duplicates.test.html')],
}

await fs.promises.writeFile(config.content[0], `<div class="mt-2 pt-4"></div>`)

let input = css`
@tailwind utilities;
`

let result = await run(input, config)
let allContexts = Array.from(sharedState.contextMap.values())

let context = allContexts[allContexts.length - 1]

let ruleCacheSize1 = context.ruleCache.size

expect(result.css).toMatchFormattedCss(css`
.mt-2 {
margin-top: 0.5rem !important;
}
.pt-4 {
padding-top: 1rem !important;
}
`)

await new Promise((resolve) => setTimeout(resolve, 1000))
await fs.promises.writeFile(config.content[0], `<div class="mt-2 pt-6"></div>`)

result = await run(input, config)

let ruleCacheSize2 = context.ruleCache.size

expect(result.css).toMatchFormattedCss(css`
.mt-2 {
margin-top: 0.5rem !important;
}
.pt-4 {
padding-top: 1rem !important;
}
.pt-6 {
padding-top: 1.5rem !important;
}
`)

// The rule cache was effectively doubling in size previously
// because the rule cache was never de-duped
// This ensures this behavior doesn't return
expect(ruleCacheSize2 - ruleCacheSize1).toBeLessThan(10)
})

0 comments on commit 40996f5

Please sign in to comment.