From ca36c18936022c9c98277dd704e9060d1d37d103 Mon Sep 17 00:00:00 2001 From: Enguerrand de Ribaucourt Date: Thu, 14 Dec 2023 14:38:43 +0100 Subject: [PATCH] Fix: Update tests for BitbakeTerminal Commands are not executed through tasks anymore. Instead, a terminal is created. --- __mocks__/vscode.ts | 1 + .../src/tests/bitbake-commands.test.ts | 51 ++++--------------- 2 files changed, 12 insertions(+), 40 deletions(-) diff --git a/__mocks__/vscode.ts b/__mocks__/vscode.ts index b39207c4..1123f988 100644 --- a/__mocks__/vscode.ts +++ b/__mocks__/vscode.ts @@ -25,6 +25,7 @@ const languages = { createWebviewPanel: jest.fn(), registerTreeDataProvider: jest.fn(), createTreeView: jest.fn(), + createTerminal: jest.fn(), }; const workspace = { diff --git a/integration-tests/src/tests/bitbake-commands.test.ts b/integration-tests/src/tests/bitbake-commands.test.ts index e6139d5b..f4a95af0 100644 --- a/integration-tests/src/tests/bitbake-commands.test.ts +++ b/integration-tests/src/tests/bitbake-commands.test.ts @@ -6,16 +6,14 @@ import * as assert from 'assert' import * as vscode from 'vscode' import { afterEach } from 'mocha' -import { delay } from '../utils/async' +import { assertWillComeTrue, assertWorkspaceWillBeOpen } from '../utils/async' suite('Bitbake Commands Test Suite', () => { let disposables: vscode.Disposable[] = [] suiteSetup(async function (this: Mocha.Context) { this.timeout(10000) - while (vscode.workspace.workspaceFolders === undefined || vscode.workspace.workspaceFolders?.length === 0) { - await delay(100) - } + await assertWorkspaceWillBeOpen() }) afterEach(function () { @@ -35,43 +33,19 @@ suite('Bitbake Commands Test Suite', () => { }) test('Bitbake can run a task', async () => { - let taskExecuted = false - - disposables.push(vscode.tasks.onDidEndTask(async (e) => { - if (e.execution.task.definition.recipes !== undefined && e.execution.task.definition.recipes[0] === 'base-files') { - assert.strictEqual(e.execution.task.definition.task, 'unpack') - taskExecuted = true - } - })) - await vscode.commands.executeCommand('bitbake.run-task', 'base-files', 'unpack') - // eslint-disable-next-line no-unmodified-loop-condition - while (!taskExecuted) { - await delay(100) - } - - const files = await vscode.workspace.findFiles('build/tmp/work/*/base-files/*/issue') - assert.strictEqual(files.length, 1) + await assertWillComeTrue(async () => { + const files = await vscode.workspace.findFiles('build/tmp/work/*/base-files/*/issue') + return files.length === 1 + }) }).timeout(300000) test('Bitbake can clean a recipe', async () => { - let taskExecuted = false - - disposables.push(vscode.tasks.onDidEndTask(async (e) => { - if (e.execution.task.definition.recipes !== undefined && e.execution.task.definition.recipes[0] === 'base-files') { - assert.strictEqual(e.execution.task.definition.task, 'clean') - taskExecuted = true - } - })) - await vscode.commands.executeCommand('bitbake.clean-recipe', 'base-files') - // eslint-disable-next-line no-unmodified-loop-condition - while (!taskExecuted) { - await delay(100) - } - - const files = await vscode.workspace.findFiles('build/tmp/work/*/base-files') - assert.strictEqual(files.length, 0) + await assertWillComeTrue(async () => { + const files = await vscode.workspace.findFiles('build/tmp/work/*/base-files') + return files.length === 0 + }) }).timeout(300000) test('Bitbake can run from task.json', async () => { @@ -90,10 +64,7 @@ suite('Bitbake Commands Test Suite', () => { await vscode.tasks.executeTask(task) } } - // eslint-disable-next-line no-unmodified-loop-condition - while (!taskExecuted) { - await delay(100) - } + await assertWillComeTrue(async () => taskExecuted) const files = await vscode.workspace.findFiles('build/tmp/work/*/base-files/*/temp/log.do_fetch') assert.strictEqual(files.length, 1)