Skip to content

Commit

Permalink
Remove path hacks from tests
Browse files Browse the repository at this point in the history
Folder URLs work fine if they use a trailing slash.
  • Loading branch information
remcohaszing committed Aug 21, 2023
1 parent b53f08a commit e762717
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import assert from 'node:assert/strict'
import {spawn} from 'node:child_process'
import fs from 'node:fs/promises'
import path from 'node:path'
import {afterEach, test} from 'node:test'
import {fileURLToPath} from 'node:url'
import {
Expand Down Expand Up @@ -560,8 +559,7 @@ test('`textDocument/codeAction` (and diagnostics)', async () => {
})

test('`initialize` w/ nothing (finds closest `package.json`)', async () => {
const cwd = new URL('..', import.meta.url)
startLanguageServer('remark-with-cwd.js', fileURLToPath(cwd))
startLanguageServer('remark-with-cwd.js', '../')

await connection.sendRequest(InitializeRequest.type, {
processId: null,
Expand Down Expand Up @@ -592,8 +590,7 @@ test('`initialize` w/ nothing (finds closest `package.json`)', async () => {
})

test('`initialize` w/ nothing (find closest `.git`)', async () => {
const cwd = new URL('..', import.meta.url)
startLanguageServer('remark-with-cwd.js', fileURLToPath(cwd))
startLanguageServer('remark-with-cwd.js', '../')
await fs.mkdir(new URL('folder-with-git/.git', import.meta.url), {
recursive: true
})
Expand Down Expand Up @@ -627,8 +624,7 @@ test('`initialize` w/ nothing (find closest `.git`)', async () => {

test('`initialize` w/ `rootUri`', async () => {
const cwd = new URL('folder/', import.meta.url)
const processCwd = new URL('..', cwd)
startLanguageServer('remark-with-cwd.js', fileURLToPath(processCwd))
startLanguageServer('remark-with-cwd.js')

await connection.sendRequest(InitializeRequest.type, {
processId: null,
Expand Down Expand Up @@ -658,8 +654,8 @@ test('`initialize` w/ `rootUri`', async () => {
})

test('`initialize` w/ `workspaceFolders`', async () => {
const processCwd = new URL('.', import.meta.url)
startLanguageServer('remark-with-cwd.js', fileURLToPath(processCwd))
const processCwd = new URL('./', import.meta.url)
startLanguageServer('remark-with-cwd.js')

const otherCwd = new URL('folder/', processCwd)

Expand Down Expand Up @@ -694,9 +690,9 @@ test('`initialize` w/ `workspaceFolders`', async () => {
})

test('`workspace/didChangeWorkspaceFolders`', async () => {
const processCwd = new URL('.', import.meta.url)
const processCwd = new URL('./', import.meta.url)

startLanguageServer('remark-with-cwd.js', fileURLToPath(processCwd))
startLanguageServer('remark-with-cwd.js')

await connection.sendRequest(InitializeRequest.type, {
processId: null,
Expand Down Expand Up @@ -777,18 +773,12 @@ function cleanStack(stack, max) {
* this test file.
* @param cwd The cwd to use for the process relative to this test file.
*/
function startLanguageServer(serverFilePath, cwd = '.') {
function startLanguageServer(serverFilePath, cwd = './') {
const proc = spawn(
'node',
[
path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
serverFilePath
),
'--node-ipc'
],
[fileURLToPath(new URL(serverFilePath, import.meta.url)), '--node-ipc'],
{
cwd: path.resolve(path.dirname(fileURLToPath(import.meta.url)), cwd),
cwd: new URL(cwd, import.meta.url),
stdio: [null, 'inherit', 'inherit', 'ipc']
}
)
Expand Down

0 comments on commit e762717

Please sign in to comment.