freshollie / jest-dynalite

Jest preset to run Dynalite (DynamoDB local) per test runner
https://www.npmjs.com/package/jest-dynalite
MIT License
149 stars 16 forks source link

When using withDb at the top of a test file test.concurrent seem to execute before tables are available. #92

Open kitsunde opened 1 year ago

kitsunde commented 1 year ago

Hello,

I setup jest in each test file, but his an issue where in test.concurrent the table doesn't seem to exist:

require('jest-dynalite/withDb');

const { DynamoDB } = require('aws-sdk');

const client = new DynamoDB({
  ...(process.env.MOCK_DYNAMODB_ENDPOINT && {
    endpoint: process.env.MOCK_DYNAMODB_ENDPOINT,
    sslEnabled: false,
    region: 'local',
  }),
});

describe('dynalite', () => {
  test.concurrent('will contain tables concurrent', async () => {
    const tables = await client.listTables().promise();

    expect(tables.TableNames.length).toEqual(1);
  });

  test('will contain tables not concurrnet', async () => {
    const tables = await client.listTables().promise();

    expect(tables.TableNames.length).toEqual(1);
  });
});

This is when it's used with a setupBeforeEnv.js:

const { setup } = require('jest-dynalite');

setup(__dirname);

However if I switch to preset: 'jest-dynalite' both modes work.

freshollie commented 11 months ago

To use concurrent you are gonna need to manually start and stop the DB. The default behaviour removes the tables and recreates them between each test, which I imagine doesn't work with concurrency.