@@ -13,7 +13,8 @@ import {
1313 Range ,
1414 TextDocument ,
1515} from '../jsonLanguageService' ;
16- import { resolve as resolvePath } from 'path' ;
16+ import * as path from 'path' ;
17+ import { URI } from 'vscode-uri' ;
1718
1819suite ( 'JSON Find Links' , ( ) => {
1920 const testFindLinksFor = function ( value : string , expected : { offset : number , length : number , target : number } | null ) : PromiseLike < void > {
@@ -72,9 +73,13 @@ suite('JSON Find Links', () => {
7273 } ) ;
7374
7475 test ( 'URI reference link' , async function ( ) {
75- const relativePath = './src/test/fixtures/uri-reference.txt' ;
76- const content = `{"stringProp": "string-value", "uriProp": "${ relativePath } ", "uriPropNotFound": "./does/not/exist.txt"}` ;
77- const document = TextDocument . create ( 'test://test.json' , 'json' , 0 , content ) ;
76+ // This test file runs in `./lib/umd/test`, but the fixtures are in `./src`.
77+ const refRelPath = '../../../src/test/fixtures/uri-reference.txt' ;
78+ const refAbsPath = path . join ( __dirname , refRelPath ) ;
79+ const docAbsPath = path . join ( __dirname , 'test.json' ) ;
80+
81+ const content = `{"stringProp": "string-value", "uriProp": "${ refRelPath } ", "uriPropNotFound": "./does/not/exist.txt"}` ;
82+ const document = TextDocument . create ( URI . file ( docAbsPath ) . toString ( ) , 'json' , 0 , content ) ;
7883 const schema : JSONSchema = {
7984 type : 'object' ,
8085 properties : {
@@ -94,11 +99,10 @@ suite('JSON Find Links', () => {
9499 await testFindLinksWithSchema ( document , schema ) . then ( ( links ) => {
95100 assert . notDeepEqual ( links , [ ] ) ;
96101
97- const absPath = resolvePath ( relativePath ) ;
98- assert . equal ( links [ 0 ] . target , `file://${ absPath } ` ) ;
102+ assert . equal ( links [ 0 ] . target , URI . file ( refAbsPath ) . toString ( ) ) ;
99103
100- const startOffset = content . indexOf ( relativePath ) ;
101- const endOffset = startOffset + relativePath . length ;
104+ const startOffset = content . indexOf ( refRelPath ) ;
105+ const endOffset = startOffset + refRelPath . length ;
102106 const range = Range . create ( document . positionAt ( startOffset ) , document . positionAt ( endOffset ) ) ;
103107 assert . deepEqual ( links [ 0 ] . range , range ) ;
104108 } ) ;
0 commit comments