|
1 | 1 | import dedent from 'dedent' |
2 | | -import { unlink, writeFile } from 'node:fs/promises' |
| 2 | +import { mkdir, mkdtemp, unlink, writeFile } from 'node:fs/promises' |
| 3 | +import { tmpdir } from 'node:os' |
| 4 | +import path from 'path' |
3 | 5 | import postcss from 'postcss' |
4 | | -import { afterEach, beforeEach, describe, expect, test } from 'vitest' |
| 6 | +import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest' |
5 | 7 | import tailwindcss from './index' |
6 | 8 |
|
7 | 9 | // 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 () = |
106 | 108 | }) |
107 | 109 |
|
108 | 110 | describe('processing without specifying a base path', () => { |
109 | | - let filepath = `${process.cwd()}/my-test-file.html` |
110 | | - |
111 | | - beforeEach(() => |
112 | | - writeFile(filepath, `<div class="md:[&:hover]:content-['testing_default_base_path']">`), |
113 | | - ) |
| 111 | + let filepath: string |
| 112 | + let dir: string |
| 113 | + |
| 114 | + beforeEach(async () => { |
| 115 | + dir = await mkdtemp(path.join(tmpdir(), 'tw-postcss')) |
| 116 | + await mkdir(dir, { recursive: true }) |
| 117 | + filepath = path.join(dir, 'my-test-file.html') |
| 118 | + await writeFile(filepath, `<div class="md:[&:hover]:content-['testing_default_base_path']">`) |
| 119 | + }) |
114 | 120 | afterEach(() => unlink(filepath)) |
115 | 121 |
|
116 | 122 | test('the current working directory is used by default', async () => { |
| 123 | + const spy = vi.spyOn(process, 'cwd') |
| 124 | + spy.mockReturnValue(dir) |
| 125 | + |
117 | 126 | let processor = postcss([tailwindcss({ optimize: { minify: false } })]) |
118 | 127 |
|
119 | 128 | let result = await processor.process(`@import "tailwindcss"`, { from: inputCssFilePath() }) |
|
0 commit comments