Skip to content

Commit 96ef150

Browse files
authored
Ensure purge tests work even for version mismatches (#5316)
We applied the same treatment for the sanity tests, where we ignore the first line (the tailwind header). An odd issue I have found is that diffing of big css files is _very_ slow. When te tests pass, then the first test takes `3302 ms`, however, when it fails it takes `477482 ms` on my machine. That's almost 8 minutes.
1 parent 211f40b commit 96ef150

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

tests/purgeUnusedStyles.test.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ function suppressConsoleLogs(cb, type = 'warn') {
2020
}
2121
}
2222

23+
function dropTailwindHeader(css) {
24+
let [header, ...lines] = css.split('\n')
25+
26+
expect(
27+
/\/*! tailwindcss v\d*\.\d*\.\d* \| MIT License \| https:\/\/tailwindcss.com \*\//g.test(header)
28+
).toBe(true)
29+
30+
return lines.join('\n')
31+
}
32+
2333
function extractRules(root) {
2434
let rules = []
2535

@@ -450,7 +460,7 @@ test(
450460
'utf8'
451461
)
452462

453-
expect(result.css).toMatchCss(expected)
463+
expect(dropTailwindHeader(result.css)).toMatchCss(dropTailwindHeader(expected))
454464
})
455465
})
456466
)
@@ -477,7 +487,7 @@ test('does not purge if the array is empty', () => {
477487
'utf8'
478488
)
479489

480-
expect(result.css).toMatchCss(expected)
490+
expect(dropTailwindHeader(result.css)).toMatchCss(dropTailwindHeader(expected))
481491
})
482492
})
483493
)
@@ -502,7 +512,7 @@ test('does not purge if explicitly disabled', () => {
502512
'utf8'
503513
)
504514

505-
expect(result.css).toMatchCss(expected)
515+
expect(dropTailwindHeader(result.css)).toMatchCss(dropTailwindHeader(expected))
506516
})
507517
})
508518
)
@@ -527,7 +537,7 @@ test('does not purge if purge is simply false', () => {
527537
'utf8'
528538
)
529539

530-
expect(result.css).toMatchCss(expected)
540+
expect(dropTailwindHeader(result.css)).toMatchCss(dropTailwindHeader(expected))
531541
})
532542
})
533543
)

0 commit comments

Comments
 (0)