Skip to content

Commit

Permalink
Chore: Add integration tests for completion
Browse files Browse the repository at this point in the history
  • Loading branch information
idillon-sfl committed Nov 29, 2023
1 parent c6903bf commit 936b777
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
DESCRIPTION = 'FOO'

python do_foo(){
print('123')
}

do_bar(){
echo '123'
}
71 changes: 71 additions & 0 deletions integration-tests/src/tests/completion.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) 2023 Savoir-faire Linux. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */

import * as assert from 'assert'
import * as vscode from 'vscode'
import path from 'path'

async function delay (ms: number): Promise<void> {
await new Promise(resolve => setTimeout(resolve, ms))
}

suite('Bitbake Completion Test Suite', () => {
const filePath = path.resolve(__dirname, '../../project-folder/sources/meta-fixtures/completion.bb')
const docUri = vscode.Uri.parse(`file://${filePath}`)

suiteSetup(async function (this: Mocha.Context) {
this.timeout(100000)
const vscodeBitbake = vscode.extensions.getExtension('yocto-project.yocto-bitbake')
if (vscodeBitbake === undefined) {
assert.fail('Bitbake extension is not available')
}
await vscodeBitbake.activate()
await vscode.workspace.openTextDocument(docUri)
})

const checkHasItemWithLabel = (completionList: vscode.CompletionList, label: string): boolean => {
return completionList.items.some(item => {
if (typeof item.label === 'string') {
return item.label === label
}
return item.label.label === label
})
}

const testCompletion = async (position: vscode.Position, expected: string): Promise<void> => {
let completionList: vscode.CompletionList = { items: [] }
while (!checkHasItemWithLabel(completionList, expected)) {
completionList = await vscode.commands.executeCommand<vscode.CompletionList>(
'vscode.executeCompletionItemProvider',
docUri,
position
)
// For completion to work, an "embedded language document" needs to be generated.
// We have no practical way to know when it will be done.
// Attempts to wait for the "embedded language document" to be created in its folder still produced incorrect results.
// So here we are, just hoping everything is fine so our test won't take forever to fail.
await delay(100)
}
assert.strictEqual(checkHasItemWithLabel(completionList, expected), true)
}

test('Completion appears properly on bitbake variable', async () => {
const position = new vscode.Position(0, 2)
const expected = 'DESCRIPTION'
await testCompletion(position, expected)
}).timeout(300000)

test('Completion appears properly on embedded python', async () => {
const position = new vscode.Position(3, 6)
const expected = 'print'
await testCompletion(position, expected)
}).timeout(300000)

test('Completion appears properly on embedded bash', async () => {
const position = new vscode.Position(7, 6)
const expected = 'echo'
await testCompletion(position, expected)
}).timeout(300000)
})

0 comments on commit 936b777

Please sign in to comment.