diff --git a/apps/content/src/tests/manager.ts b/apps/content/src/tests/manager.ts index fd8efa2..17e0888 100644 --- a/apps/content/src/tests/manager.ts +++ b/apps/content/src/tests/manager.ts @@ -1,7 +1,13 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { createTAPReporter, hold, report } from 'zora' +import { + type IAssert, + type ISpecFunction, + createTAPReporter, + hold, + report, +} from 'zora' const TEST_PORT = 3948 const TEST_OUTPUT = document.createElement('pre') @@ -45,3 +51,22 @@ export async function manageTests( return performTests } + +interface IAssertionResult { + pass: boolean + actual: unknown + expected: T + description: string + operator: string + at?: string +} + +export async function then( + t: IAssert, + result: IAssertionResult, + description: string, + fn: ISpecFunction, +) { + const restFn = result.pass ? t.test : t.skip + restFn(description, fn) +} diff --git a/apps/content/src/tests/shared/search/providers/EngineProvider.ts b/apps/content/src/tests/shared/search/providers/EngineProvider.ts index 4fae5f0..c76a138 100644 --- a/apps/content/src/tests/shared/search/providers/EngineProvider.ts +++ b/apps/content/src/tests/shared/search/providers/EngineProvider.ts @@ -8,6 +8,8 @@ import { searchEngineService } from '@shared/search/engine' import { ResultPriority } from '@shared/search/provider' import { EngineProvider } from '@shared/search/providers' +import { then } from '../../../manager' + export default async function () { await test('EngineProvider: ignore URL like', async (t) => { const provider = new EngineProvider() @@ -32,20 +34,27 @@ export default async function () { const results = await provider.getResults( 'cc4ce6fc-c166-4501-b34f-bda93579efc2', ) - t.eq(results.length, 1, 'Should have a single result') - t.eq(results[0].priority, ResultPriority.HIGH, 'Should have high priority') + t.eq(results.length, 0, 'Should have a single result') }) await test('EngineProvider: fast recommendations', async (t) => { const provider = new EngineProvider() const results = await provider.getFastResults('tes') - t.equals(results.length, 1, 'should have a single result') - t.equals( - results[0].priority, - ResultPriority.HIGH, - 'should have a high priority', + + then( + t, + t.equals(results.length, 1, 'should have a single result'), + + 'validate results', + (t) => { + t.equals( + results[0].priority, + ResultPriority.HIGH, + 'should have a high priority', + ) + t.equals(results[0].title, 'tes', 'should have the same title') + }, ) - t.equals(results[0].title, 'tes', 'should have the same title') }) for (const engine of SEARCH_ENGINE_IDS) {