Skip to content

Commit

Permalink
Update tests and fix monorepo workspace issues
Browse files Browse the repository at this point in the history
  • Loading branch information
1aron committed May 21, 2024
1 parent 74c1683 commit d4241c9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/language-server/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export default class CSSLanguageServer {
}

private async initWorkspaceFolder(workspaceFolderURI: string) {
const workspaceFolderCWD = URI.parse(workspaceFolderURI).fsPath
const workspaceFolderCWD = path.resolve(URI.parse(workspaceFolderURI).fsPath)
let customWorkspaceFolderSettings: Settings | undefined
if (this.clientCapabilities.workspace?.configuration) {
customWorkspaceFolderSettings = await this.connection.workspace.getConfiguration({
Expand Down
7 changes: 4 additions & 3 deletions packages/language-server/tests/custom-workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { resolve } from 'path'
import { withFixture } from './setup'
import { test } from 'vitest'
import { Settings } from '../src'
import { URI } from 'vscode-uri'

const settings: Settings = {
workspaces: [
Expand All @@ -12,10 +13,10 @@ const settings: Settings = {
withFixture('monorepo', async (context) => {
test.concurrent('workspaces', async ({ expect }) => {
expect(context.server.workspaces.length).toBe(2)
expect(context.server.workspaces).toEqual(
expect(context.server.workspaces.map((x) => x.uri)).toEqual(
expect.arrayContaining([
expect.objectContaining({ path: resolve('tests/fixtures/monorepo') }),
expect.objectContaining({ path: resolve('tests/fixtures/monorepo/c') }),
URI.file(resolve('tests/fixtures/monorepo')).toString(),
URI.file(resolve('tests/fixtures/monorepo/c')).toString(),
])
)
})
Expand Down
11 changes: 6 additions & 5 deletions packages/language-server/tests/monorepo.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { resolve } from 'path'
import { withFixture } from './setup'
import { test } from 'vitest'
import { URI } from 'vscode-uri'

withFixture('monorepo', async (context) => {
test.concurrent('workspaces', async ({ expect }) => {
expect(context.server.workspaces.length).toBe(3)
expect(context.server.workspaces).toEqual(
expect(context.server.workspaces.map((x) => x.uri)).toEqual(
expect.arrayContaining([
expect.objectContaining({ path: resolve('tests/fixtures/monorepo') }),
expect.objectContaining({ path: resolve('tests/fixtures/monorepo/a') }),
expect.objectContaining({ path: resolve('tests/fixtures/monorepo/b') }),
URI.file(resolve('tests/fixtures/monorepo')).toString(),
URI.file(resolve('tests/fixtures/monorepo/a')).toString(),
URI.file(resolve('tests/fixtures/monorepo/b')).toString()
])
)
})
Expand All @@ -18,7 +19,7 @@ withFixture('monorepo', async (context) => {
const dir = resolve(__dirname, './fixtures/monorepo/a')
const textDocument = context.createDocument('', { dir })
await context.server.onDidOpen({ document: textDocument })
const targetWorkspace = context.server.workspaces.find((workspace) => workspace.path === resolve(dir))
const targetWorkspace = context.server.workspaces.find((workspace) => workspace.uri === URI.file(dir).toString())
expect(targetWorkspace?.openedTextDocuments.length).toBe(1)
await context.server.onDidClose({ document: textDocument })
expect(context.rootWorkspace?.openedTextDocuments?.length).toBe(0)
Expand Down

0 comments on commit d4241c9

Please sign in to comment.