Skip to content

Commit

Permalink
devdocs: return results for empty query (#156)
Browse files Browse the repository at this point in the history
I noticed the other providers have this behaviour and it feels nice.
  • Loading branch information
keegancsmith authored Jun 18, 2024
1 parent 895aa83 commit 36e269c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
31 changes: 16 additions & 15 deletions provider/devdocs/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import devdocs, { type Settings } from './index.js'
const INTEGRATION = !!process.env.INTEGRATION

describe('devdocs', () => {
const fixturesDir = path.join(__dirname, '__fixtures__')
const fixturesSettings = {
urls: [url.pathToFileURL(fixturesDir).toString()],
}

test('meta', () => {
expect(devdocs.meta({}, {})).toEqual({
name: 'DevDocs',
Expand Down Expand Up @@ -55,12 +60,16 @@ describe('devdocs', () => {
})
})

test('test page type', async () => {
const fixturesDir = path.join(__dirname, '__fixtures__')
const settings = {
urls: [url.pathToFileURL(fixturesDir).toString()],
}
test('empty query returns results', async () => {
const settings = fixturesSettings

const mentions = await devdocs.mentions!({ query: '' }, settings)
expect(mentions).toBeInstanceOf(Array)
expect(mentions).toBeTruthy()
})

test('test page type', async () => {
const settings = fixturesSettings
const mentionPath = path.join(fixturesDir, 'strconv', 'index')
const item = await expectMentionItem({ query: 'strconv' }, settings, {
title: 'strconv',
Expand All @@ -85,11 +94,7 @@ describe('devdocs', () => {
})

test('test hash type', async () => {
const fixturesDir = path.join(__dirname, '__fixtures__')
const settings = {
urls: [url.pathToFileURL(fixturesDir).toString()],
}

const settings = fixturesSettings
const mentionURL = url.pathToFileURL(path.join(fixturesDir, 'io', 'index'))
mentionURL.hash = '#TeeReader'

Expand Down Expand Up @@ -138,11 +143,7 @@ describe('devdocs', () => {
})

test('missing documentation has no results', async () => {
const fixturesDir = path.join(__dirname, '__fixtures__')
const settings = {
urls: [url.pathToFileURL(fixturesDir).toString()],
}

const settings = fixturesSettings
const mentions = await devdocs.mentions!({ query: 'abortcontroller' }, settings)
expect(mentions).toHaveLength(0)
})
Expand Down
4 changes: 2 additions & 2 deletions provider/devdocs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ const devdocs: Provider<Settings> = {
},

async mentions(params: MentionsParams, settings: Settings): Promise<MentionsResult> {
const query = params.query?.toLowerCase()
if (!query) {
if (params.query === undefined) {
return []
}

const query = params.query.toLowerCase()
const urls = settings.urls ?? DEFAULT_URLS

const indexes = await Promise.all(urls.map(url => getMentionIndex(url)))
Expand Down

0 comments on commit 36e269c

Please sign in to comment.