Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
How to import types in a jestEnvironment?

I'm setting a jest-environment for my tests, and apparently, these environments are not considered as module by Jest. Therefore, I cannot use the ES6 syntax to import and export.

That is why I am trying to find a way to import interfaces or types using require. Is it possible?

This is my jestEnvironment.ts:

import Config = require('@jest/types');
const NodeEnvironment = require('jest-environment-node').default;

class CustomEnvironment extends NodeEnvironment {
  constructor(config: Config.ProjectConfig) {
    super(config);
    console.log(config);
  }

  async setup() {
    await super.setup();
    this.global.someGlobalVar = 'lala';
  }

  async teardown() {
    await super.teardown();
  }

  getVmContext() {
    return super.getVmContext();
  }
}

module.exports = CustomEnvironment;

And when running Jest, I get the following error:

● Test suite failed to run

    /path/to/project/src/jestEnvironment.ts:1
    import { Config } from '@jest/types';
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module

(Just for information: I'm using ts-jest 26.5.6... And I just saw that the version 28 introduced a support to ESM. However, there are too many breaking changes for me to switch to that version for now.)

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda