Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadError: Database is not open / existing setup after env #67

Open
mattensor opened this issue Sep 21, 2021 · 5 comments
Open

ReadError: Database is not open / existing setup after env #67

mattensor opened this issue Sep 21, 2021 · 5 comments

Comments

@mattensor
Copy link

Hey there

I get the following error when running dynalite.

ReadError: Database is not open
    at /api/node_modules/levelup/lib/levelup.js:190:15
    at /api/node_modules/encoding-down/index.js:75:21
    at processTicksAndRejections (internal/process/task_queues.js:81:21)

I have an existing setupFilesAfterEnv file in which there are conflicts.
When I remove it, my tests work - but I have no dynalite goodness :(

afterEnvSetup

import { server } from '~mocks/server'

beforeAll(() => {
  server.listen({
    onUnhandledRequest: 'warn'
  })
})

afterAll(() => {
  server.close()
})

afterEach(() => {
  server.resetHandlers()
})

I've tried the granular approach importing the start / stop fns individually. The out of the box solution and on an individual file. Still no luck

Would be great to get some help

@jonoirwinrsa
Copy link

jonoirwinrsa commented Sep 21, 2021

I had this issue too. For me it was because I was returning undefined as a TableName in my jest-dynalite-config.js file.
Perhaps it's the same for you?

@freshollie
Copy link
Owner

@jonoirwinrsa might be right here. If you remove your other afterEnvSetup file, does this work? Can I see your dynalite config?

@mattensor
Copy link
Author

mattensor commented Sep 21, 2021

It works if I remove my other afterEnvSetup setup file, but I need that to mock external api calls.

Here's my jest-dynalite-config.ts file

const tables = [
  {
    TableName: 'conversations',
    AttributeDefinitions: [
      { AttributeName: 'id', AttributeType: 'S' },
      { AttributeName: 'userId', AttributeType: 'S' }
    ],
    KeySchema: [{ AttributeName: 'id', KeyType: 'HASH' }],
    BillingMode: 'PAY_PER_REQUEST',
    GlobalSecondaryIndexes: [
      {
        IndexName: 'userConversationsIndex',
        KeySchema: [{ AttributeName: 'userId', KeyType: 'HASH' }],
        Projection: { ProjectionType: 'ALL' }
      }
    ]
  }
]

module.exports = {
  tables,
  basePort: 8000
}

jest.config.ts

import { pathsToModuleNameMapper } from 'ts-jest/utils'
import { compilerOptions } from './tsconfig.json'

export default {
  moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
    prefix: '<rootDir>/'
  }),
  preset: 'jest-dynalite',
  setupFiles: ['<rootDir>/jestEnvironmentSetup.ts'],
  setupFilesAfterEnv: ['<rootDir>/jestServiceWorkerSetup.ts']
}

@freshollie
Copy link
Owner

freshollie commented Sep 27, 2021

Ok. Can you narrow down which test is causing this error and maybe post details about this test? It's likely you get an error like this if a DB call happens outside a test (as this library tears down the server after each test).

This could be due to a forgotten await keyword, or a side effect which is kicked off by another function and not being awaited.

@yamatatsu
Copy link

yamatatsu commented Mar 4, 2023

I've created a minimal representation code.

https://github.com/yamatatsu/represent-jest-dynalite-database-is-not-open

I guess the condition of this error is below:

  • many commands to db are queued to node event-loop
  • timeout the test case

In my case, the work arround I found is to extend the timeout period.

test('test case' async () => {...}, 60_000 /* long enough */)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants