Skip to content

Commit b541663

Browse files
committed
Fix tests on Windows
1 parent 04041da commit b541663

File tree

3 files changed

+30
-38
lines changed

3 files changed

+30
-38
lines changed

packages/tailwindcss-language-server/src/project-locator.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { URL, fileURLToPath } from 'url'
55
import { Settings } from '@tailwindcss/language-service/src/util/state'
66
import { createResolver } from './resolver'
77
import { css, defineTest, js, json, scss, Storage, TestUtils } from './testing'
8+
import { normalizePath } from './utils'
89

910
let settings: Settings = {
1011
tailwindCSS: {
@@ -29,12 +30,14 @@ function testFixture(fixture: string, details: any[]) {
2930

3031
let detail = details[i]
3132

32-
let configPath = path.relative(fixturePath, project.config.path)
33+
let configPath = path.posix.relative(normalizePath(fixturePath), project.config.path)
3334

3435
expect(configPath).toEqual(detail?.config)
3536

3637
if (detail?.content) {
37-
let expected = detail?.content.map((path) => path.replace('{URL}', fixturePath)).sort()
38+
let expected = detail?.content
39+
.map((path) => path.replace('{URL}', normalizePath(fixturePath)))
40+
.sort()
3841

3942
let actual = project.documentSelector
4043
.filter((selector) => selector.priority === 1 /** content */)
@@ -45,7 +48,9 @@ function testFixture(fixture: string, details: any[]) {
4548
}
4649

4750
if (detail?.selectors) {
48-
let expected = detail?.selectors.map((path) => path.replace('{URL}', fixturePath)).sort()
51+
let expected = detail?.selectors
52+
.map((path) => path.replace('{URL}', normalizePath(fixturePath)))
53+
.sort()
4954

5055
let actual = project.documentSelector.map((selector) => selector.pattern).sort()
5156

@@ -364,7 +369,7 @@ async function prepare({ root }: TestUtils) {
364369
} as Settings
365370

366371
function adjustPath(filepath: string) {
367-
filepath = filepath.replace(root, '{URL}')
372+
filepath = filepath.replace(normalizePath(root), '{URL}')
368373

369374
if (filepath.startsWith('{URL}/')) {
370375
filepath = filepath.slice(5)

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,13 @@ async function setup<T>(config: TestConfig<T>): Promise<TestUtils> {
5858

5959
onTestFinished(async (result) => {
6060
// Once done, move all the files to a new location
61-
await fs.rename(baseDir, doneDir)
61+
try {
62+
await fs.rename(baseDir, doneDir)
63+
} catch {
64+
// If it fails it doesn't really matter. It only fails on Windows and then
65+
// only randomly so whatever
66+
console.error('Failed to move test files to done directory')
67+
}
6268

6369
if (result.state === 'fail') return
6470

packages/tailwindcss-language-server/tests/document-links/document-links.test.js

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { test } from 'vitest'
2-
import { withFixture } from '../common'
32
import * as path from 'path'
3+
import { URI } from 'vscode-uri'
4+
import { withFixture } from '../common'
45

56
withFixture('basic', (c) => {
67
async function testDocumentLinks(name, { text, lang, expected }) {
@@ -19,9 +20,7 @@ withFixture('basic', (c) => {
1920
lang: 'css',
2021
expected: [
2122
{
22-
target: `file://${path
23-
.resolve('./tests/fixtures/basic/tailwind.config.js')
24-
.replace(/@/g, '%40')}`,
23+
target: URI.file(path.resolve('./tests/fixtures/basic/tailwind.config.js')).toString(),
2524
range: { start: { line: 0, character: 8 }, end: { line: 0, character: 28 } },
2625
},
2726
],
@@ -32,9 +31,7 @@ withFixture('basic', (c) => {
3231
lang: 'css',
3332
expected: [
3433
{
35-
target: `file://${path
36-
.resolve('./tests/fixtures/basic/does-not-exist.js')
37-
.replace(/@/g, '%40')}`,
34+
target: URI.file(path.resolve('./tests/fixtures/basic/does-not-exist.js')).toString(),
3835
range: { start: { line: 0, character: 8 }, end: { line: 0, character: 27 } },
3936
},
4037
],
@@ -58,9 +55,7 @@ withFixture('v4/basic', (c) => {
5855
lang: 'css',
5956
expected: [
6057
{
61-
target: `file://${path
62-
.resolve('./tests/fixtures/v4/basic/tailwind.config.js')
63-
.replace(/@/g, '%40')}`,
58+
target: URI.file(path.resolve('./tests/fixtures/v4/basic/tailwind.config.js')).toString(),
6459
range: { start: { line: 0, character: 8 }, end: { line: 0, character: 28 } },
6560
},
6661
],
@@ -71,9 +66,7 @@ withFixture('v4/basic', (c) => {
7166
lang: 'css',
7267
expected: [
7368
{
74-
target: `file://${path
75-
.resolve('./tests/fixtures/v4/basic/does-not-exist.js')
76-
.replace(/@/g, '%40')}`,
69+
target: URI.file(path.resolve('./tests/fixtures/v4/basic/does-not-exist.js')).toString(),
7770
range: { start: { line: 0, character: 8 }, end: { line: 0, character: 27 } },
7871
},
7972
],
@@ -84,9 +77,7 @@ withFixture('v4/basic', (c) => {
8477
lang: 'css',
8578
expected: [
8679
{
87-
target: `file://${path
88-
.resolve('./tests/fixtures/v4/basic/plugin.js')
89-
.replace(/@/g, '%40')}`,
80+
target: URI.file(path.resolve('./tests/fixtures/v4/basic/plugin.js')).toString(),
9081
range: { start: { line: 0, character: 8 }, end: { line: 0, character: 19 } },
9182
},
9283
],
@@ -97,9 +88,7 @@ withFixture('v4/basic', (c) => {
9788
lang: 'css',
9889
expected: [
9990
{
100-
target: `file://${path
101-
.resolve('./tests/fixtures/v4/basic/does-not-exist.js')
102-
.replace(/@/g, '%40')}`,
91+
target: URI.file(path.resolve('./tests/fixtures/v4/basic/does-not-exist.js')).toString(),
10392
range: { start: { line: 0, character: 8 }, end: { line: 0, character: 27 } },
10493
},
10594
],
@@ -110,9 +99,7 @@ withFixture('v4/basic', (c) => {
11099
lang: 'css',
111100
expected: [
112101
{
113-
target: `file://${path
114-
.resolve('./tests/fixtures/v4/basic/index.html')
115-
.replace(/@/g, '%40')}`,
102+
target: URI.file(path.resolve('./tests/fixtures/v4/basic/index.html')).toString(),
116103
range: { start: { line: 0, character: 8 }, end: { line: 0, character: 20 } },
117104
},
118105
],
@@ -123,9 +110,7 @@ withFixture('v4/basic', (c) => {
123110
lang: 'css',
124111
expected: [
125112
{
126-
target: `file://${path
127-
.resolve('./tests/fixtures/v4/basic/does-not-exist.html')
128-
.replace(/@/g, '%40')}`,
113+
target: URI.file(path.resolve('./tests/fixtures/v4/basic/does-not-exist.html')).toString(),
129114
range: { start: { line: 0, character: 8 }, end: { line: 0, character: 29 } },
130115
},
131116
],
@@ -136,9 +121,7 @@ withFixture('v4/basic', (c) => {
136121
lang: 'css',
137122
expected: [
138123
{
139-
target: `file://${path
140-
.resolve('./tests/fixtures/v4/basic/index.html')
141-
.replace(/@/g, '%40')}`,
124+
target: URI.file(path.resolve('./tests/fixtures/v4/basic/index.html')).toString(),
142125
range: { start: { line: 0, character: 12 }, end: { line: 0, character: 24 } },
143126
},
144127
],
@@ -149,9 +132,7 @@ withFixture('v4/basic', (c) => {
149132
lang: 'css',
150133
expected: [
151134
{
152-
target: `file://${path
153-
.resolve('./tests/fixtures/v4/basic/does-not-exist.html')
154-
.replace(/@/g, '%40')}`,
135+
target: URI.file(path.resolve('./tests/fixtures/v4/basic/does-not-exist.html')).toString(),
155136
range: { start: { line: 0, character: 12 }, end: { line: 0, character: 33 } },
156137
},
157138
],
@@ -177,11 +158,11 @@ withFixture('v4/basic', (c) => {
177158
lang: 'css',
178159
expected: [
179160
{
180-
target: `file://${path.resolve('./tests/fixtures').replace(/@/g, '%40')}`,
161+
target: URI.file(path.resolve('./tests/fixtures')).toString(),
181162
range: { start: { line: 1, character: 35 }, end: { line: 1, character: 43 } },
182163
},
183164
{
184-
target: `file://${path.resolve('./tests/fixtures').replace(/@/g, '%40')}`,
165+
target: URI.file(path.resolve('./tests/fixtures')).toString(),
185166
range: { start: { line: 2, character: 33 }, end: { line: 2, character: 41 } },
186167
},
187168
],

0 commit comments

Comments
 (0)