nextapps-de / flexsearch

Next-Generation full text search library for Browser and Node.js
Apache License 2.0
12.54k stars 492 forks source link

Undefined is not Iterable #259

Closed samuelnunoo closed 3 years ago

samuelnunoo commented 3 years ago

Issue

When running index.export(handler) I get undefined is not iterable error.

Relevant Code


   //IndexLoader.spec.ts 

      const config = {
        tokenize:"reverse",
        document:{
          id:"_id",
          index:["content:text"],
          store:["content:text","parent"]
        }
      } as IIndexConfig

      const index = new Document(config)
      const data:Record<string,any> = await mockIndexData(config, [{
        _id:"123",
        content: { text:"Hello World"},
        parent:"parent"
      }])
//mockIndex.ts
//@ts-ignore
import {Document} from "flexsearch"

export const mockIndexData = async (config:IIndexConfig,documents:any[]) => {

  const index = new Document(config)

  for (const doc of documents) {
   index.add(doc)
  }

  const data:Record<string,any> = {}

 await Promise.all(index.export(function(key:string,value:any) {
   data[key] = value
  }))

  return data

}

Logs

undefined is not iterable (cannot read property Symbol(Symbol.iterator))
TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
    at Function.all (<anonymous>)
    at Object.mockIndexData (C:\Users\Samuel\Documents\GitHub\Type.io---Next\nuxt\src\Mocks\IndexMock\mockIndex.ts:54:16)
    at C:\Users\Samuel\Documents\GitHub\Type.io---Next\nuxt\test\backend\Index\IndexLoader.spec.ts:64:45
    at Promise.then.completed (C:\Users\Samuel\Documents\GitHub\Type.io---Next\nuxt\node_modules\jest-circus\build\utils.js:390:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (C:\Users\Samuel\Documents\GitHub\Type.io---Next\nuxt\node_modules\jest-circus\build\utils.js:315:10)
    at _callCircusHook (C:\Users\Samuel\Documents\GitHub\Type.io---Next\nuxt\node_modules\jest-circus\build\run.js:181:40)
    at _runTestsForDescribeBlock (C:\Users\Samuel\Documents\GitHub\Type.io---Next\nuxt\node_modules\jest-circus\build\run.js:47:7)
    at _runTestsForDescribeBlock (C:\Users\Samuel\Documents\GitHub\Type.io---Next\nuxt\node_modules\jest-circus\build\run.js:60:9)
    at _runTestsForDescribeBlock (C:\Users\Samuel\Documents\GitHub\Type.io---Next\nuxt\node_modules\jest-circus\build\run.js:60:9)