|
| 1 | +/** |
| 2 | + * @fileoverview TypeScript completion tests for MDX files |
| 3 | + * |
| 4 | + * These tests verify that code completion works correctly |
| 5 | + * in MDX files through the TypeScript plugin. |
| 6 | + */ |
| 7 | +import assert from 'node:assert/strict' |
| 8 | +import {after, before, test} from 'node:test' |
| 9 | +import {fixturePath, getTsServer} from './server.js' |
| 10 | + |
| 11 | +/** @type {Awaited<ReturnType<typeof getTsServer>>} */ |
| 12 | +let server |
| 13 | + |
| 14 | +before(async () => { |
| 15 | + server = await getTsServer() |
| 16 | +}) |
| 17 | + |
| 18 | +after(() => { |
| 19 | + server.shutdown() |
| 20 | +}) |
| 21 | + |
| 22 | +test('support completion in ESM', async () => { |
| 23 | + const filePath = fixturePath('node16/completion.mdx') |
| 24 | + await server.openFile(filePath) |
| 25 | + |
| 26 | + try { |
| 27 | + const res = await server.tsserver.message({ |
| 28 | + seq: server.nextSeq(), |
| 29 | + type: 'request', |
| 30 | + command: 'completions', |
| 31 | + arguments: { |
| 32 | + file: filePath, |
| 33 | + line: 2, |
| 34 | + offset: 1, |
| 35 | + includeExternalModuleExports: true |
| 36 | + } |
| 37 | + }) |
| 38 | + |
| 39 | + assert.ok(res.success, 'Request should succeed') |
| 40 | + assert.ok(res.body, 'Response should have body') |
| 41 | + assert.ok(res.body.length > 0, 'Should have completions') |
| 42 | + |
| 43 | + const booleanCompletion = res.body.find( |
| 44 | + (/** @type {{name: string}} */ c) => c.name === 'Boolean' |
| 45 | + ) |
| 46 | + assert.ok(booleanCompletion, 'Should have Boolean completion') |
| 47 | + } finally { |
| 48 | + await server.closeFile(filePath) |
| 49 | + } |
| 50 | +}) |
| 51 | + |
| 52 | +test('support completion in JSX', async () => { |
| 53 | + const filePath = fixturePath('node16/completion.mdx') |
| 54 | + await server.openFile(filePath) |
| 55 | + |
| 56 | + try { |
| 57 | + const res = await server.tsserver.message({ |
| 58 | + seq: server.nextSeq(), |
| 59 | + type: 'request', |
| 60 | + command: 'completions', |
| 61 | + arguments: { |
| 62 | + file: filePath, |
| 63 | + line: 6, |
| 64 | + offset: 3, |
| 65 | + includeExternalModuleExports: true |
| 66 | + } |
| 67 | + }) |
| 68 | + |
| 69 | + assert.ok(res.success, 'Request should succeed') |
| 70 | + assert.ok(res.body, 'Response should have body') |
| 71 | + assert.ok(res.body.length > 0, 'Should have completions') |
| 72 | + |
| 73 | + const booleanCompletion = res.body.find( |
| 74 | + (/** @type {{name: string}} */ c) => c.name === 'Boolean' |
| 75 | + ) |
| 76 | + assert.ok(booleanCompletion, 'Should have Boolean completion') |
| 77 | + } finally { |
| 78 | + await server.closeFile(filePath) |
| 79 | + } |
| 80 | +}) |
0 commit comments