vendredi 20 novembre 2020

nestjs jest times out after 10 minutes circleci

I have a nestjs application that has a jest e2e test suite. Running it locally takes roughly 13s~. However when trying to run them on circleci, the tests hangs and does not seem to exit successfully. They timeout at 10 minutes and fails. I am not sure what causes this behaviour.

enter image description here

/.circleci/config.yml

version: 2.1
jobs:
  run_tests:
    docker:
      - image: circleci/node:10
    steps:
      - checkout #cloning git repo
      - run:
          name: Install npm dependencies
          command: |
            npm install --save
      - run:
          name: Run unit tests
          command: |
            NODE_ENV=test && node node_modules/.bin/jest
          environment:
            DATABASE_URL: postgres://_:_:@localhost:5432/testdb
      - run:
          name: Run e2e tests
          command: |
            NODE_ENV=test && node --inspect-brk node_modules/.bin/jest --runInBand --config ./test/jest-e2e.json --watchAll=false
          environment:
            DATABASE_URL: postgres://_:_:@localhost:5432/testdb
      - store_test_results:
          path: test-results
workflows:
  build_test:
    jobs:
      - run_tests

test/jest-e2e.json

{
  "moduleFileExtensions": ["js", "json", "ts"],
  "rootDir": ".",
  "testEnvironment": "node",
  "testRegex": ".e2e-spec.ts$",
  "transform": {
    "^.+\\.(t|j)s$": "ts-jest"
  },
  "verbose": true
}

test setup

beforeAll(async () => {
    const rootModule: TestingModule = await Test.createTestingModule({
      imports: [RootModule]
    }).compile();

    app = rootModule.createNestApplication();
    await app.init();
    shopboxService = app.select(ShopboxModule).get(ShopboxService);
    clothesService = app.select(ClothesModule).get(ClothesService);
    await shopboxService.deleteTags();
  });

  it('authenticates a user and includes a jwt token in the response', async () => {
    const response = await request(app.getHttpServer())
      .post('/auth/login')
      .send({ email: 'myemail@example.com', password: '123456789' })
      .expect(201);

    adminAccessToken = response.body.token;

    expect(adminAccessToken).toMatch(
      /^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$/
    );
  });

test teardown

  afterAll(async () => {
    try {
      await shopboxService.deleteTags();
    } catch (e) {
      console.warn('error', e);
    } finally {
      await app.close();
    }
  });

Aucun commentaire:

Enregistrer un commentaire