Jest integration with Adonis V5
Asked Answered
E

0

7

I'm developing an application with Adonis v5 but its test runner isn't finished. So, my workaround is to apply Jest in its place. I got this working but I'm having trouble importing types from Adonis.

In any model, I have the following import:

import { BaseModel, column } from '@ioc:Adonis/Lucid/Orm'

To solve the alias, I added this rule in jest.config.js:

moduleNameMapper: {
  '^App(.*)$': '<rootDir>/app$1',
  '^@ioc:Adonis/Lucid/Database$': '@adonisjs/lucid/build/src/Database/index.js',
  '^@ioc:Adonis/Lucid/Orm$': '@adonisjs/lucid/build/adonis-typings/orm.d.ts',
  //'^@ioc:Adonis/Core/Validator$': '',
},

The third rule points to the previous import. Inside of the pointed file, I found the declaration of a module which exports the desired types.

declare module '@ioc:Adonis/Lucid/Orm' {
    import { ScopeFn, LucidModel, HooksDecorator, ...
    ...

The complete file is this.

When I run Jest, I get this error. What am I missing? Before I forget, I'm using ts-jest to define the settings of Jest.

enter image description here

Enshrine answered 15/5, 2020 at 17:53 Comment(4)
managed to solve?Holdfast
Have you got esModuleInterop set to true in tsconfig?Coxalgia
I don't remember about esModuleInterop. My settings are the same of default. My unique solution is to use Cypress Test Framework disabling all resources to tests beyond the back-end.Enshrine
Despite the excessive resources, Cypress is extremely easy and usefullEnshrine

© 2022 - 2024 — McMap. All rights reserved.