Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI testing matrix #989

Merged
merged 3 commits into from
Mar 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Run Tests
on:
pull_request:
branches:
- main

jobs:
tests:
strategy:
matrix:
node: [18, 20, 22, 23]
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
13 changes: 9 additions & 4 deletions packages/tailwindcss-language-server/src/project-locator.test.ts
Original file line number Diff line number Diff line change
@@ -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)
22 changes: 19 additions & 3 deletions packages/tailwindcss-language-server/src/testing/index.ts
Original file line number Diff line number Diff line change
@@ -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<T>(config: TestConfig<T>): Promise<TestUtils> {

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<T>(config: TestConfig<T>): Promise<TestUtils> {
}

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
}

Original file line number Diff line number Diff line change
@@ -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 } },
},
],
2 changes: 1 addition & 1 deletion packages/tailwindcss-language-server/tests/env/v4.test.js
Original file line number Diff line number Diff line change
@@ -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",