import { expect } from 'chai' ; import * as path from 'path' ; import { Location , Position , commands , window , workspace } from 'vscode' ; import URI from 'vscode-uri' ; describe ( 'Aura Definition Linking' , function ( ) { let auraDir ; let lwcDir ; before ( async function ( ) { auraDir = path . join ( workspace . workspaceFolders ! [ 0 ] . uri . fsPath , 'force-app' , 'main' , 'default' , 'aura' ) ; lwcDir = path . join ( workspace . workspaceFolders ! [ 0 ] . uri . fsPath , 'force-app' , 'main' , 'default' , 'lwc' ) ; await new Promise ( r => setTimeout ( r , 1500 ) ) ; } ) ; afterEach ( async function ( ) { await commands . executeCommand ( 'workbench.action.closeActiveEditor' ) ; } ) ; it ( 'Should provide navigation to a selected Aura tag' , function ( ) { testDefinitionNavigation ( path . join ( auraDir , 'DemoApp' , 'DemoApp.app' ) , path . join ( auraDir , 'DemoComponent' , 'DemoComponent.cmp' ) , new Position ( 1 , 12 ) ) ; } ) ; it ( 'Should provide navigation to a selected LWC tag' , function ( ) { testDefinitionNavigation ( path . join ( auraDir , 'auraEmbeddedLWC' , 'auraEmbeddedLWC.cmp' ) , path . join ( lwcDir , 'contactList' , 'contactList.js' ) , new Position ( 20 , 28 ) ) ; } ) ; } ) ; param startLocation param endLocation param position async function testDefinitionNavigation ( startLocation , endLocation , position ) { const doc = await workspace . openTextDocument ( startLocation ) ; const editor = await window . showTextDocument ( doc ) ; const locations = ( await commands . executeCommand ( 'vscode.executeDefinitionProvider' , editor . document . uri , position ) ) as Location [ ] ; expect ( locations ) . to . have . lengthOf ( 1 ) ; const location = locations ! [ 0 ] ; expect ( location ) . to . have . property ( 'uri' ) ; const expectedURI = URI . file ( endLocation ) ; expect ( location . uri . toString ( ) ) . to . equal ( expectedURI . toString ( ) ) ; }