6

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

4
  • 1
    managed to solve?
    – Yung Silva
    Jun 27, 2020 at 18:12
  • 1
    Have you got esModuleInterop set to true in tsconfig? Jun 28, 2020 at 11:20
  • 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. Jun 28, 2020 at 23:34
  • Despite the excessive resources, Cypress is extremely easy and usefull Jun 28, 2020 at 23:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy