Fix slow unit test (#17465)

This PR reworks a unit test that created a file in the project root and
then proceeded by scanning everything in the git root for candidates.
The issue specifically is that with the `.debug/` folder, our project
root can grow quite a bit which makes this test slower the more you work
on other tests...

To fix this we now simply create a tmp folder with only that one test
file. 🚀
This commit is contained in:
Philipp Spiess 2025-03-31 15:26:01 +02:00 committed by GitHub
parent eec1bf2b84
commit c7ba564f92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 7 deletions

2
.gitignore vendored
View File

@ -7,4 +7,4 @@ playwright-report/
blob-report/
playwright/.cache/
target/
.debug
.debug/

View File

@ -1,7 +1,9 @@
import dedent from 'dedent'
import { unlink, writeFile } from 'node:fs/promises'
import { mkdir, mkdtemp, unlink, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import path from 'path'
import postcss from 'postcss'
import { afterEach, beforeEach, describe, expect, test } from 'vitest'
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
import tailwindcss from './index'
// We give this file path to PostCSS for processing.
@ -106,14 +108,21 @@ test('@apply can be used without emitting the theme in the CSS file', async () =
})
describe('processing without specifying a base path', () => {
let filepath = `${process.cwd()}/my-test-file.html`
let filepath: string
let dir: string
beforeEach(() =>
writeFile(filepath, `<div class="md:[&:hover]:content-['testing_default_base_path']">`),
)
beforeEach(async () => {
dir = await mkdtemp(path.join(tmpdir(), 'tw-postcss'))
await mkdir(dir, { recursive: true })
filepath = path.join(dir, 'my-test-file.html')
await writeFile(filepath, `<div class="md:[&:hover]:content-['testing_default_base_path']">`)
})
afterEach(() => unlink(filepath))
test('the current working directory is used by default', async () => {
const spy = vi.spyOn(process, 'cwd')
spy.mockReturnValue(dir)
let processor = postcss([tailwindcss({ optimize: { minify: false } })])
let result = await processor.process(`@import "tailwindcss"`, { from: inputCssFilePath() })