Skip to content

Commit dae553d

Browse files
committed
Allow tests to create symlinks
1 parent dc77b91 commit dae553d

File tree

1 file changed

+16
-1
lines changed
  • packages/tailwindcss-language-server/src/testing

1 file changed

+16
-1
lines changed

packages/tailwindcss-language-server/src/testing/index.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface TestUtils {
1111

1212
export interface Storage {
1313
/** A list of files and their content */
14-
[filePath: string]: string | Uint8Array
14+
[filePath: string]: string | Uint8Array | { [IS_A_SYMLINK]: true; filepath: string }
1515
}
1616

1717
export interface TestConfig<Extras extends {}> {
@@ -69,6 +69,14 @@ async function setup<T>(config: TestConfig<T>): Promise<TestUtils> {
6969
}
7070
}
7171

72+
const IS_A_SYMLINK = Symbol('is-a-symlink')
73+
export const symlinkTo = function (filepath: string) {
74+
return {
75+
[IS_A_SYMLINK]: true as const,
76+
filepath,
77+
}
78+
}
79+
7280
async function prepareFileSystem(base: string, storage: Storage) {
7381
// Create a temporary directory to store the test files
7482
await fs.mkdir(base, { recursive: true })
@@ -77,6 +85,13 @@ async function prepareFileSystem(base: string, storage: Storage) {
7785
for (let [filepath, content] of Object.entries(storage)) {
7886
let fullPath = path.resolve(base, filepath)
7987
await fs.mkdir(path.dirname(fullPath), { recursive: true })
88+
89+
if (typeof content === 'object' && IS_A_SYMLINK in content) {
90+
let target = path.resolve(base, content.filepath)
91+
await fs.symlink(target, fullPath)
92+
continue
93+
}
94+
8095
await fs.writeFile(fullPath, content, { encoding: 'utf-8' })
8196
}
8297
}

0 commit comments

Comments
 (0)