From 7bf7ff74f158ce13ec42fa9730bac4d5a8081dff Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Tue, 25 Jun 2024 12:29:24 -0400 Subject: [PATCH 1/3] Add CI testing matrix --- .github/workflows/ci.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..409ce403 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,32 @@ +name: Run Tests +on: + pull_request: + branches: + - main + +jobs: + tests: + strategy: + matrix: + node: [22] + os: [ubuntu-latest, macos-latest, windows-latest] + + runs-on: ${{ matrix.os }} + name: Run Tests - Node v${{ matrix.node }} / ${{ matrix.os }} + + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v4 + with: + cache: 'pnpm' + node-version: ${{ matrix.node-version }} + + - name: Install dependencies + run: pnpm install + + - name: Run tests + run: | + cd packages/tailwindcss-language-server && + pnpm run build && + pnpm run test From 7975fc7461c21a3bf4b3a3b18466ca05b6ac8337 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Sat, 22 Mar 2025 13:29:03 -0400 Subject: [PATCH 2/3] Fix tests on Windows --- .../src/project-locator.test.ts | 13 +++-- .../src/testing/index.ts | 22 +++++++-- .../document-links/document-links.test.js | 47 ++++++------------- .../tests/env/v4.test.js | 2 +- 4 files changed, 43 insertions(+), 41 deletions(-) diff --git a/packages/tailwindcss-language-server/src/project-locator.test.ts b/packages/tailwindcss-language-server/src/project-locator.test.ts index f350dba1..52af6446 100644 --- a/packages/tailwindcss-language-server/src/project-locator.test.ts +++ b/packages/tailwindcss-language-server/src/project-locator.test.ts @@ -5,6 +5,7 @@ import { URL, fileURLToPath } from 'url' import { Settings } from '@tailwindcss/language-service/src/util/state' import { createResolver } from './resolver' import { css, defineTest, js, json, scss, Storage, TestUtils } from './testing' +import { normalizePath } from './utils' let settings: Settings = { tailwindCSS: { @@ -29,12 +30,14 @@ function testFixture(fixture: string, details: any[]) { let detail = details[i] - let configPath = path.relative(fixturePath, project.config.path) + let configPath = path.posix.relative(normalizePath(fixturePath), project.config.path) expect(configPath).toEqual(detail?.config) if (detail?.content) { - let expected = detail?.content.map((path) => path.replace('{URL}', fixturePath)).sort() + let expected = detail?.content + .map((path) => path.replace('{URL}', normalizePath(fixturePath))) + .sort() let actual = project.documentSelector .filter((selector) => selector.priority === 1 /** content */) @@ -45,7 +48,9 @@ function testFixture(fixture: string, details: any[]) { } if (detail?.selectors) { - let expected = detail?.selectors.map((path) => path.replace('{URL}', fixturePath)).sort() + let expected = detail?.selectors + .map((path) => path.replace('{URL}', normalizePath(fixturePath))) + .sort() let actual = project.documentSelector.map((selector) => selector.pattern).sort() @@ -364,7 +369,7 @@ async function prepare({ root }: TestUtils) { } as Settings function adjustPath(filepath: string) { - filepath = filepath.replace(root, '{URL}') + filepath = filepath.replace(normalizePath(root), '{URL}') if (filepath.startsWith('{URL}/')) { filepath = filepath.slice(5) diff --git a/packages/tailwindcss-language-server/src/testing/index.ts b/packages/tailwindcss-language-server/src/testing/index.ts index a0516d9a..91a07b81 100644 --- a/packages/tailwindcss-language-server/src/testing/index.ts +++ b/packages/tailwindcss-language-server/src/testing/index.ts @@ -1,4 +1,5 @@ import { onTestFinished, test, TestOptions } from 'vitest' +import * as os from 'node:os' import * as fs from 'node:fs/promises' import * as path from 'node:path' import * as proc from 'node:child_process' @@ -12,6 +13,7 @@ export interface TestUtils { export interface StorageSymlink { [IS_A_SYMLINK]: true filepath: string + type: 'file' | 'dir' | undefined } export interface Storage { @@ -56,7 +58,13 @@ async function setup(config: TestConfig): Promise { onTestFinished(async (result) => { // Once done, move all the files to a new location - await fs.rename(baseDir, doneDir) + try { + await fs.rename(baseDir, doneDir) + } catch { + // If it fails it doesn't really matter. It only fails on Windows and then + // only randomly so whatever + console.error('Failed to move test files to done directory') + } if (result.state === 'fail') return @@ -75,10 +83,11 @@ async function setup(config: TestConfig): Promise { } const IS_A_SYMLINK = Symbol('is-a-symlink') -export function symlinkTo(filepath: string): StorageSymlink { +export function symlinkTo(filepath: string, type?: 'file' | 'dir'): StorageSymlink { return { [IS_A_SYMLINK]: true as const, filepath, + type, } } @@ -93,7 +102,14 @@ async function prepareFileSystem(base: string, storage: Storage) { if (typeof content === 'object' && IS_A_SYMLINK in content) { let target = path.resolve(base, content.filepath) - await fs.symlink(target, fullPath) + + let type: string = content.type + + if (os.platform() === 'win32' && content.type === 'dir') { + type = 'junction' + } + + await fs.symlink(target, fullPath, type) continue } diff --git a/packages/tailwindcss-language-server/tests/document-links/document-links.test.js b/packages/tailwindcss-language-server/tests/document-links/document-links.test.js index 0fc76cb6..f187cc46 100644 --- a/packages/tailwindcss-language-server/tests/document-links/document-links.test.js +++ b/packages/tailwindcss-language-server/tests/document-links/document-links.test.js @@ -1,6 +1,7 @@ import { test } from 'vitest' -import { withFixture } from '../common' import * as path from 'path' +import { URI } from 'vscode-uri' +import { withFixture } from '../common' withFixture('basic', (c) => { async function testDocumentLinks(name, { text, lang, expected }) { @@ -19,9 +20,7 @@ withFixture('basic', (c) => { lang: 'css', expected: [ { - target: `file://${path - .resolve('./tests/fixtures/basic/tailwind.config.js') - .replace(/@/g, '%40')}`, + target: URI.file(path.resolve('./tests/fixtures/basic/tailwind.config.js')).toString(), range: { start: { line: 0, character: 8 }, end: { line: 0, character: 28 } }, }, ], @@ -32,9 +31,7 @@ withFixture('basic', (c) => { lang: 'css', expected: [ { - target: `file://${path - .resolve('./tests/fixtures/basic/does-not-exist.js') - .replace(/@/g, '%40')}`, + target: URI.file(path.resolve('./tests/fixtures/basic/does-not-exist.js')).toString(), range: { start: { line: 0, character: 8 }, end: { line: 0, character: 27 } }, }, ], @@ -58,9 +55,7 @@ withFixture('v4/basic', (c) => { lang: 'css', expected: [ { - target: `file://${path - .resolve('./tests/fixtures/v4/basic/tailwind.config.js') - .replace(/@/g, '%40')}`, + target: URI.file(path.resolve('./tests/fixtures/v4/basic/tailwind.config.js')).toString(), range: { start: { line: 0, character: 8 }, end: { line: 0, character: 28 } }, }, ], @@ -71,9 +66,7 @@ withFixture('v4/basic', (c) => { lang: 'css', expected: [ { - target: `file://${path - .resolve('./tests/fixtures/v4/basic/does-not-exist.js') - .replace(/@/g, '%40')}`, + target: URI.file(path.resolve('./tests/fixtures/v4/basic/does-not-exist.js')).toString(), range: { start: { line: 0, character: 8 }, end: { line: 0, character: 27 } }, }, ], @@ -84,9 +77,7 @@ withFixture('v4/basic', (c) => { lang: 'css', expected: [ { - target: `file://${path - .resolve('./tests/fixtures/v4/basic/plugin.js') - .replace(/@/g, '%40')}`, + target: URI.file(path.resolve('./tests/fixtures/v4/basic/plugin.js')).toString(), range: { start: { line: 0, character: 8 }, end: { line: 0, character: 19 } }, }, ], @@ -97,9 +88,7 @@ withFixture('v4/basic', (c) => { lang: 'css', expected: [ { - target: `file://${path - .resolve('./tests/fixtures/v4/basic/does-not-exist.js') - .replace(/@/g, '%40')}`, + target: URI.file(path.resolve('./tests/fixtures/v4/basic/does-not-exist.js')).toString(), range: { start: { line: 0, character: 8 }, end: { line: 0, character: 27 } }, }, ], @@ -110,9 +99,7 @@ withFixture('v4/basic', (c) => { lang: 'css', expected: [ { - target: `file://${path - .resolve('./tests/fixtures/v4/basic/index.html') - .replace(/@/g, '%40')}`, + target: URI.file(path.resolve('./tests/fixtures/v4/basic/index.html')).toString(), range: { start: { line: 0, character: 8 }, end: { line: 0, character: 20 } }, }, ], @@ -123,9 +110,7 @@ withFixture('v4/basic', (c) => { lang: 'css', expected: [ { - target: `file://${path - .resolve('./tests/fixtures/v4/basic/does-not-exist.html') - .replace(/@/g, '%40')}`, + target: URI.file(path.resolve('./tests/fixtures/v4/basic/does-not-exist.html')).toString(), range: { start: { line: 0, character: 8 }, end: { line: 0, character: 29 } }, }, ], @@ -136,9 +121,7 @@ withFixture('v4/basic', (c) => { lang: 'css', expected: [ { - target: `file://${path - .resolve('./tests/fixtures/v4/basic/index.html') - .replace(/@/g, '%40')}`, + target: URI.file(path.resolve('./tests/fixtures/v4/basic/index.html')).toString(), range: { start: { line: 0, character: 12 }, end: { line: 0, character: 24 } }, }, ], @@ -149,9 +132,7 @@ withFixture('v4/basic', (c) => { lang: 'css', expected: [ { - target: `file://${path - .resolve('./tests/fixtures/v4/basic/does-not-exist.html') - .replace(/@/g, '%40')}`, + target: URI.file(path.resolve('./tests/fixtures/v4/basic/does-not-exist.html')).toString(), range: { start: { line: 0, character: 12 }, end: { line: 0, character: 33 } }, }, ], @@ -177,11 +158,11 @@ withFixture('v4/basic', (c) => { lang: 'css', expected: [ { - target: `file://${path.resolve('./tests/fixtures').replace(/@/g, '%40')}`, + target: URI.file(path.resolve('./tests/fixtures')).toString(), range: { start: { line: 1, character: 35 }, end: { line: 1, character: 43 } }, }, { - target: `file://${path.resolve('./tests/fixtures').replace(/@/g, '%40')}`, + target: URI.file(path.resolve('./tests/fixtures')).toString(), range: { start: { line: 2, character: 33 }, end: { line: 2, character: 41 } }, }, ], diff --git a/packages/tailwindcss-language-server/tests/env/v4.test.js b/packages/tailwindcss-language-server/tests/env/v4.test.js index 36639f55..f57a45dc 100644 --- a/packages/tailwindcss-language-server/tests/env/v4.test.js +++ b/packages/tailwindcss-language-server/tests/env/v4.test.js @@ -737,7 +737,7 @@ defineTest({ presets: [require('some-pkg/config/tailwind.config.js').default] } `, - 'packages/some-pkg': symlinkTo('packages/some-pkg#c3f1e'), + 'packages/some-pkg': symlinkTo('packages/some-pkg#c3f1e', 'dir'), 'packages/some-pkg#c3f1e/package.json': json` { "name": "some-pkg", From f41e93d7f419c4668dc09338cdda993954b65768 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Sat, 22 Mar 2025 14:22:02 -0400 Subject: [PATCH 3/3] Test more Node versions --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 409ce403..f64cfa03 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ jobs: tests: strategy: matrix: - node: [22] + node: [18, 20, 22, 23] os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }}