Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add test for alias path definition
- Loading branch information
1 parent
74f3877
commit 6a2a2f7
Showing
6 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
packages/vue-language-service/tests/definitions/alias_path.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import * as path from 'upath'; | ||
import { Position } from 'vscode-languageserver-protocol'; | ||
import { defineDefinition } from '../utils/defineDefinition'; | ||
|
||
const file = path.resolve(__dirname, '../../../vue-test-workspace/definitions/alias_path/B.vue'); | ||
|
||
defineDefinition({ | ||
fileName: file, | ||
position: Position.create(1, 15), | ||
}, ['/definitions/alias_path/A.vue']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/vue-language-service/tests/utils/defineDefinition.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type * as vscode from 'vscode-languageserver-protocol'; | ||
import { describe, expect, it } from 'vitest'; | ||
import * as path from 'upath'; | ||
import { tester } from './createTester'; | ||
import * as shared from '@volar/shared'; | ||
|
||
const volarRoot = path.resolve(__dirname, '../../../..'); | ||
|
||
export function defineDefinition(action: { | ||
fileName: string, | ||
position: vscode.Position, | ||
}, expectedResults: string[]) { | ||
|
||
const fileName = action.fileName; | ||
const uri = shared.fsPathToUri(fileName); | ||
const location = `${path.relative(volarRoot, fileName)}:${action.position.line + 1}:${action.position.character + 1}`; | ||
|
||
describe(`find definition ${path.basename(fileName)} ${location}`, async () => { | ||
const result = await tester.languageService.findDefinition( | ||
uri, | ||
{ line: action.position.line, character: action.position.character }, | ||
); | ||
for (const expectedResult of expectedResults) { | ||
it(`has ${expectedResult}`, () => { | ||
expect(result?.some(item => item.targetUri.endsWith(expectedResult))).toEqual(true); | ||
}); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<script setup lang="ts"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<script setup lang="ts"> | ||
import A from '@/../definitions/alias_path/A.vue'; | ||
</script> | ||
|
||
<template> | ||
<A></A> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters