Skip to content

Commit

Permalink
test(language-server): Use vitest intead of mocha
Browse files Browse the repository at this point in the history
Only language-server package for now
  • Loading branch information
SevInf committed May 15, 2024
1 parent f035544 commit 2bca766
Show file tree
Hide file tree
Showing 15 changed files with 2,889 additions and 1,629 deletions.
4,142 changes: 2,747 additions & 1,395 deletions packages/language-server/package-lock.json

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions packages/language-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"cliVersion": "5.14.0-dev.77"
},
"bin": {
"prisma-language-server": "dist/src/bin.js"
"prisma-language-server": "dist/bin.js"
},
"repository": {
"type": "git",
Expand All @@ -24,8 +24,7 @@
"scripts": {
"build": "tsc",
"watch": "npm run build -- -w",
"test": "nyc --reporter=clover --reporter=text-summary mocha --ui tdd --useColors true ./dist/src/__test__/**/*.test.js",
"pretest": "tsc"
"test": "vitest"
},
"main": "./dist/index.js",
"typings": "dist/src/index",
Expand All @@ -41,11 +40,11 @@
"vscode-uri": "^3.0.8"
},
"devDependencies": {
"@types/mocha": "10.0.6",
"@types/node": "14.18.63",
"mocha": "10.4.0",
"@types/node": "18.15.3",
"@vitest/coverage-v8": "1.6.0",
"ts-dedent": "2.2.0",
"typescript": "5.4.5"
"typescript": "5.4.5",
"vitest": "^1.6.0"
},
"keywords": [
"autocomplete",
Expand Down
154 changes: 36 additions & 118 deletions packages/language-server/src/__test__/artificial-panic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import {
handleDocumentFormatting,
} from '../lib/MessageHandler'
import { CURSOR_CHARACTER, findCursorPosition, getTextDocument } from './helper'
import { describe, test, expect, vi, afterEach } from 'vitest'
import '../lib/prisma-schema-wasm/error/wasm'

import * as assert from 'assert'
import { PrismaSchema } from '../lib/Schema'

suite('Artificial Panics', () => {
const OLD_ENV = { ...process.env }
describe('Artificial Panics', () => {
afterEach(() => {
vi.unstubAllEnvs()
})

test('code actions', () => {
const fixturePath = './artificial-panic/schema.prisma'
Expand All @@ -37,28 +40,12 @@ suite('Artificial Panics', () => {
},
}

process.env.FORCE_PANIC_PRISMA_SCHEMA = '1'

let calledCount = 0
let calledArg: undefined | unknown = undefined

// No official mock implementation in mocha
// -> DIY mock for onError
const onError = (arg: unknown) => {
calledCount += 1
calledArg = arg
}

try {
const _codeActions = handleCodeActions(PrismaSchema.singleFile(document), document, params, onError)
vi.stubEnv('FORCE_PANIC_PRISMA_SCHEMA', '1')
const onError = vi.fn()

assert.fail("This shouldn't happen!")
} catch (e) {
assert.ok(calledArg)
assert.strictEqual(calledCount, 1)
} finally {
process.env = { ...OLD_ENV }
}
handleCodeActions(PrismaSchema.singleFile(document), document, params, onError)
expect(onError).toBeCalledTimes(1)
expect(onError).toBeCalledWith(expect.any(String))
})

test('formatter', () => {
Expand All @@ -73,52 +60,25 @@ suite('Artificial Panics', () => {
},
}

process.env.FORCE_PANIC_PRISMA_SCHEMA = '1'
vi.stubEnv('FORCE_PANIC_PRISMA_SCHEMA', '1')
const onError = vi.fn()

let calledCount = 0
let calledArg: undefined | unknown = undefined

const onError = (arg: unknown) => {
calledCount += 1
calledArg = arg
}

try {
const _formatResult = handleDocumentFormatting(PrismaSchema.singleFile(document), document, params, onError)

assert.fail("This shouldn't happen!")
} catch (e) {
assert.ok(calledArg)
assert.strictEqual(calledCount, 1)
} finally {
process.env = { ...OLD_ENV }
}
handleDocumentFormatting(PrismaSchema.singleFile(document), document, params, onError)
expect(onError).toBeCalledTimes(1)
expect(onError).toBeCalledWith(expect.any(String))
})

test('linting', () => {
const fixturePath = './artificial-panic/schema.prisma'
const document = getTextDocument(fixturePath)

process.env.FORCE_PANIC_PRISMA_SCHEMA = '1'
vi.stubEnv('FORCE_PANIC_PRISMA_SCHEMA', '1')
const onError = vi.fn()

let calledCount = 0
let calledArg: undefined | unknown = undefined
handleDiagnosticsRequest(PrismaSchema.singleFile(document), onError)

const onError = (arg: unknown) => {
calledCount += 1
calledArg = arg
}

try {
const _diagnostics = handleDiagnosticsRequest(PrismaSchema.singleFile(document), onError)

assert.fail("This shouldn't happen!")
} catch (e) {
assert.ok(calledArg)
assert.strictEqual(calledCount, 1)
} finally {
process.env = { ...OLD_ENV }
}
expect(onError).toBeCalledTimes(1)
expect(onError).toBeCalledWith(expect.any(String))
})

test('preview features', () => {
Expand All @@ -141,26 +101,11 @@ suite('Artificial Panics', () => {
position,
}

process.env.FORCE_PANIC_PRISMA_SCHEMA_LOCAL = '1'

let calledCount = 0
let calledArg: undefined | unknown = undefined

const onError = (arg: unknown) => {
calledCount += 1
calledArg = arg
}

try {
const _completions = handleCompletionRequest(PrismaSchema.singleFile(document), document, params, onError)

assert.fail("This shouldn't happen!")
} catch (e) {
assert.ok(calledArg)
assert.strictEqual(calledCount, 1)
} finally {
process.env = { ...OLD_ENV }
}
vi.stubEnv('FORCE_PANIC_PRISMA_SCHEMA_LOCAL', '1')
const onError = vi.fn()
handleCompletionRequest(PrismaSchema.singleFile(document), document, params, onError)
expect(onError).toBeCalledTimes(1)
expect(onError).toBeCalledWith(expect.any(String))
})

test('native types', () => {
Expand All @@ -183,26 +128,12 @@ suite('Artificial Panics', () => {
position,
}

process.env.FORCE_PANIC_PRISMA_SCHEMA_LOCAL = '1'
vi.stubEnv('FORCE_PANIC_PRISMA_SCHEMA_LOCAL', '1')
const onError = vi.fn()

let calledCount = 0
let calledArg: undefined | unknown = undefined

const onError = (arg: unknown) => {
calledCount += 1
calledArg = arg
}

try {
const _completions = handleCompletionRequest(PrismaSchema.singleFile(document), document, params, onError)

assert.fail("This shouldn't happen!")
} catch (e) {
assert.ok(calledArg)
assert.strictEqual(calledCount, 1)
} finally {
process.env = { ...OLD_ENV }
}
handleCompletionRequest(PrismaSchema.singleFile(document), document, params, onError)
expect(onError).toBeCalledTimes(1)
expect(onError).toBeCalledWith(expect.any(String))
})

test('completions', () => {
Expand All @@ -214,25 +145,12 @@ suite('Artificial Panics', () => {
position: { character: 0, line: 0 },
}

process.env.FORCE_PANIC_PRISMA_SCHEMA = '1'
vi.stubEnv('FORCE_PANIC_PRISMA_SCHEMA', '1')
const onError = vi.fn()

let calledCount = 0
let calledArg: undefined | unknown = undefined
handleCompletionRequest(PrismaSchema.singleFile(document), document, params, onError)

const onError = (arg: unknown) => {
calledCount += 1
calledArg = arg
}

try {
const _completions = handleCompletionRequest(PrismaSchema.singleFile(document), document, params, onError)

assert.fail("This shouldn't happen!")
} catch (e) {
assert.ok(calledArg)
assert.strictEqual(calledCount, 1)
} finally {
process.env = { ...OLD_ENV }
}
expect(onError).toBeCalledTimes(1)
expect(onError).toBeCalledWith(expect.any(String))
})
})
Loading

0 comments on commit 2bca766

Please sign in to comment.