import { expect } from 'chai' ; import * as path from 'path' ; import { Hover , Position , MarkdownString , commands , window , workspace } from 'vscode' ; import { LanguageClient } from 'vscode-languageclient' ; import { createLanguageClient } from '../../src/languageClient' ; describe ( 'LWC Hovers' , ( ) => { let lwcDir = path . join ( workspace . workspaceFolders ! [ 0 ] . uri . fsPath , 'force-app' , 'main' , 'default' , 'lwc' ) ; let client ; before ( async function ( ) { this . timeout ( 10000 ) ; client = createLanguageClient ( path . join ( __dirname , '..' , '..' , '..' , 'node_modules' , '@salesforce' , 'lwc-language-server' , 'lib' , 'server.js' ) ) ; client . start ( ) ; await client . onReady ( ) ; } ) ; afterEach ( async ( ) => { await commands . executeCommand ( 'workbench.action.closeActiveEditor' ) ; } ) ; after ( ( ) => client . stop ( ) ) ; it ( 'Should provide additional details when hovering over a LWC tag' , async ( ) => { const doc = await workspace . openTextDocument ( path . join ( lwcDir , 'hello' , 'hello.html' ) ) ; const editor = await window . showTextDocument ( doc ) ; const position = new Position ( 1 , 14 ) ; const hoverInstances = ( await commands . executeCommand ( 'vscode.executeHoverProvider' , editor . document . uri , position ) ) as Hover [ ] ; expect ( hoverInstances ) . to . have . lengthOf . at . least ( 1 ) ; const content = findContentFromInstances ( hoverInstances , 'Cards apply a' ) ; expect ( content ) . not . to . be . undefined ; expect ( content ) . not . to . be . null ; expect ( content ! . value ) . to . include ( 'Attributes' ) ; expect ( content ! . value ) . to . include ( 'View in Component Library' ) ; } ) ; it ( 'Should provide additional details when hovering over a LWC attribute' , async ( ) => { const doc = await workspace . openTextDocument ( path . join ( lwcDir , 'hello' , 'hello.html' ) ) ; const editor = await window . showTextDocument ( doc ) ; const position = new Position ( 1 , 22 ) ; const hoverInstances = ( await commands . executeCommand ( 'vscode.executeHoverProvider' , editor . document . uri , position ) ) as Hover [ ] ; expect ( hoverInstances ) . to . have . lengthOf . at . least ( 1 ) ; const content = findContentFromInstances ( hoverInstances , 'The title can' ) ; expect ( content ) . not . to . be . undefined ; expect ( content ) . not . to . be . null ; expect ( content ! . value ) . to . include ( 'title' ) ; expect ( content ! . value ) . to . include ( 'The title can include text, and is displayed in the header.\nTo include additional markup or another component, use the title slot.' ) ; } ) ; } ) ; param instances param expectedContent returns function findContentFromInstances ( instances , expectedContent ) { for ( const instance of instances ) { const contents = instance ! . contents as MarkdownString [ ] ; const content = contents . find ( content => content . value . includes ( expectedContent ) ) ; if ( content ) { return content ; } } }