Skip to content

Commit

Permalink
Rebuild testing setup (#1226)
Browse files Browse the repository at this point in the history
This PR basically rebuilds the testing infra with code in place to keep
existing tests working.

This was done so we can add tests for the CSS language server in a
followup PR.
  • Loading branch information
thecrypticace authored Feb 21, 2025
1 parent 4d50880 commit 4bf0e13
Show file tree
Hide file tree
Showing 15 changed files with 1,206 additions and 510 deletions.
1 change: 1 addition & 0 deletions packages/tailwindcss-language-server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function getDefaultSettings(): Settings {
return {
editor: { tabSize: 2 },
tailwindCSS: {
inspectPort: null,
emmetCompletions: false,
classAttributes: ['class', 'className', 'ngClass', 'class:list'],
codeActions: true,
Expand Down
10 changes: 6 additions & 4 deletions packages/tailwindcss-language-server/src/testing/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterAll, onTestFinished, test, TestOptions } from 'vitest'
import { onTestFinished, test, TestOptions } from 'vitest'
import * as fs from 'node:fs/promises'
import * as path from 'node:path'
import * as proc from 'node:child_process'
Expand All @@ -16,7 +16,7 @@ export interface Storage {

export interface TestConfig<Extras extends {}> {
name: string
fs: Storage
fs?: Storage
prepare?(utils: TestUtils): Promise<Extras>
handle(utils: TestUtils & Extras): void | Promise<void>

Expand All @@ -43,8 +43,10 @@ async function setup<T>(config: TestConfig<T>): Promise<TestUtils> {

await fs.mkdir(baseDir, { recursive: true })

await prepareFileSystem(baseDir, config.fs)
await installDependencies(baseDir, config.fs)
if (config.fs) {
await prepareFileSystem(baseDir, config.fs)
await installDependencies(baseDir, config.fs)
}

onTestFinished(async (result) => {
// Once done, move all the files to a new location
Expand Down
8 changes: 8 additions & 0 deletions packages/tailwindcss-language-server/src/tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ export class TW {
configTailwindVersionMap.get(projectConfig.configPath),
userLanguages,
resolver,
baseUri,
),
),
)
Expand Down Expand Up @@ -663,6 +664,11 @@ export class TW {
}),
)
}

// TODO: This is a hack and shouldn't be necessary
if (isTestMode) {
await this.connection.sendNotification('@/tailwindCSS/serverReady')
}
}

private filterNewWatchPatterns(patterns: string[]) {
Expand All @@ -684,6 +690,7 @@ export class TW {
tailwindVersion: string,
userLanguages: Record<string, string>,
resolver: Resolver,
baseUri: URI,
): Promise<void> {
let key = String(this.projectCounter++)
const project = await createProjectService(
Expand Down Expand Up @@ -717,6 +724,7 @@ export class TW {
}

this.connection.sendNotification('@/tailwindCSS/projectDetails', {
uri: baseUri.toString(),
config: projectConfig.configPath,
tailwind: projectConfig.tailwind,
})
Expand Down
Loading

0 comments on commit 4bf0e13

Please sign in to comment.