Skip to content

Commit

Permalink
✅ Fix outdated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trickypr committed Jan 15, 2024
1 parent 776c939 commit 585101e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
27 changes: 26 additions & 1 deletion apps/content/src/tests/manager.ts
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -45,3 +51,22 @@ export async function manageTests(

return performTests
}

interface IAssertionResult<T> {
pass: boolean
actual: unknown
expected: T
description: string
operator: string
at?: string
}

export async function then<T>(
t: IAssert,
result: IAssertionResult<T>,
description: string,
fn: ISpecFunction,
) {
const restFn = result.pass ? t.test : t.skip
restFn(description, fn)
}
25 changes: 17 additions & 8 deletions apps/content/src/tests/shared/search/providers/EngineProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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) {
Expand Down

0 comments on commit 585101e

Please sign in to comment.