import { assert , expect } from 'chai' ; import * as path from 'path' ; import * as vscode from 'vscode' ; describe ( 'LWC Intellisense Test Suite' , function ( ) { let lwcDir ; let lwcExtension ; before ( async ( ) => { lwcDir = path . join ( vscode . workspace . workspaceFolders ! [ 0 ] . uri . fsPath , 'force-app' , 'main' , 'default' , 'lwc' ) ; lwcExtension = vscode . extensions . getExtension ( 'salesforce.salesforcedx-vscode-lwc' ) as vscode . Extension < any > ; await lwcExtension . activate ( ) ; } ) ; afterEach ( async ( ) => { try { await vscode . commands . executeCommand ( 'workbench.action.closeActiveEditor' ) ; } catch ( e ) { throw e ; } } ) ; it ( 'lwc extension activation' , async function ( ) { expect ( lwcExtension . isActive ) ; } ) . timeout ( 10000 ) ; /**
     * Test that lwc markup intellisense includes standard lwc tags and custom lwc tags
     */ it ( 'LWC Markup Intellisense' , async ( ) => { const docUri = vscode . Uri . file ( path . join ( lwcDir , 'hello' , 'hello.html' ) ) ; const doc = await vscode . workspace . openTextDocument ( docUri ) ; const editor = await vscode . window . showTextDocument ( doc ) ; const text = '<c-' ; const startPosition = new vscode . Position ( 5 , 0 ) ; const endPosition = new vscode . Position ( startPosition . line , startPosition . character + text . length ) ; const rangeReplace = new vscode . Range ( startPosition , endPosition ) ; await editor . edit ( editBuilder => { editBuilder . replace ( rangeReplace , text ) ; } ) ; try { await testCompletion ( docUri , endPosition , { items : [ { label : 'lightning-accordion' , kind : vscode . CompletionItemKind . Property } , { label : 'c-hello-binding' , kind : vscode . CompletionItemKind . Property } ] } ) ; } catch ( error ) { throw error ; } } ) ; it ( 'LWC JS Module Import Intellisense' , async ( ) => { const docUri = vscode . Uri . file ( path . join ( lwcDir , 'hello' , 'hello.js' ) ) ; const doc = await vscode . workspace . openTextDocument ( docUri ) ; const editor = await vscode . window . showTextDocument ( doc ) ; const text = "import {} from 'c" ; const startPosition = new vscode . Position ( 1 , 0 ) ; const endPosition = new vscode . Position ( startPosition . line , startPosition . character + text . length ) ; const rangeReplace = new vscode . Range ( startPosition , endPosition ) ; await editor . edit ( editBuilder => { editBuilder . replace ( rangeReplace , text ) ; } ) ; try { await testCompletion ( docUri , endPosition , { items : [ { label : 'c/helloBinding' , kind : vscode . CompletionItemKind . Folder } ] } ) ; } catch ( error ) { throw error ; } } ) . timeout ( 5000 ) ; xit ( 'LWC JS @Salesforce Import Intellisense' , async ( ) => { const docUri = vscode . Uri . file ( path . join ( lwcDir , 'hello' , 'hello.js' ) ) ; const doc = await vscode . workspace . openTextDocument ( docUri ) ; const editor = await vscode . window . showTextDocument ( doc ) ; const text = "import {} from '@sales" ; const startPosition = new vscode . Position ( 1 , 0 ) ; const endPosition = new vscode . Position ( startPosition . line , startPosition . character + text . length ) ; const rangeReplace = new vscode . Range ( startPosition , endPosition ) ; await editor . edit ( editBuilder => { editBuilder . replace ( rangeReplace , text ) ; } ) ; try { await testCompletion ( docUri , endPosition , { items : [ { label : '@salesforce/apex' , kind : vscode . CompletionItemKind . Module } , { label : '@salesforce/apex/AccountController.getAccountList' , kind : vscode . CompletionItemKind . Module } , { label : '@salesforce/apex/ContactController.findContacts' , kind : vscode . CompletionItemKind . Module } , { label : '@salesforce/contentAssetUrl/Cookpatternv1' , kind : vscode . CompletionItemKind . Module } , { label : '@salesforce/resourceUrl/d3' , kind : vscode . CompletionItemKind . Module } , { label : '@salesforce/resourceUrl/trailhead_logo' , kind : vscode . CompletionItemKind . Module } , { label : '@salesforce/schema' , kind : vscode . CompletionItemKind . Module } , { label : '@salesforce/user/Id' , kind : vscode . CompletionItemKind . Module } ] } ) ; } catch ( error ) { throw error ; } } ) . timeout ( 10000 ) ; xit ( 'LWC JS Lightning Import Intellisense' , async ( ) => { const docUri = vscode . Uri . file ( path . join ( lwcDir , 'hello' , 'hello.js' ) ) ; const doc = await vscode . workspace . openTextDocument ( docUri ) ; const editor = await vscode . window . showTextDocument ( doc ) ; const text = "import {} from 'lightn" ; const startPosition = new vscode . Position ( 1 , 0 ) ; const endPosition = new vscode . Position ( startPosition . line , startPosition . character + text . length ) ; const rangeReplace = new vscode . Range ( startPosition , endPosition ) ; await editor . edit ( editBuilder => { editBuilder . replace ( rangeReplace , text ) ; } ) ; try { await testCompletion ( docUri , endPosition , { items : [ { label : 'lightning/uiListApi' , kind : vscode . CompletionItemKind . Module } , { label : 'lightning/uiRecordApi' , kind : vscode . CompletionItemKind . Module } ] } ) ; } catch ( error ) { throw error ; } } ) ; } ) ; async function testCompletion ( docUri , position , expectedCompletionList ) { const actualCompletionList = ( await vscode . commands . executeCommand ( 'vscode.executeCompletionItemProvider' , docUri , position ) ) as vscode . CompletionList ; expectedCompletionList . items . forEach ( expectedItem => { const actualItem = actualCompletionList . items . find ( obj => { if ( obj . label ) { return obj . label === expectedItem . label ; } return false ; } ) ; assert . isDefined ( actualItem , "Couldn't find expected completion item '" + expectedItem . label + "'" ) ; assert . equal ( actualItem ! . label , expectedItem . label , 'Expected completion item to have label: ' + expectedItem . label ) ; assert . equal ( actualItem ! . kind , expectedItem . kind , "Expected completion item'" + expectedItem . label + "' to have type: " + expectedItem . kind ) ; } ) ; }