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

167
Visualizações
Jest read published directory as if it published - SyntaxError Unexpected token ','

I have a library that I build and maintain. I'm trying to build a particular unit test with it. When I build a class around ClassWeProvide in TypeScript, the Jest unit tests work just fine.

I am trying to test a JS version since some of my library's users may want to use raw JavaScript. My Jest is in TS, and MyJSClass is in JS, intended to be using a "published" version of my library (dist/bundle.js) which is pre-built as part of my pipeline. (I webpack the library into a bundle.)

The issue I'm seeing is that the Jest file, on require is failing to load the JS file do to the require statement below. I cannot figure if I need to configure Jest, or do something entirely different, or maybe this isn't possible.

The library and ClassWeProvide are intended to be run in NodeJS, not the Frontend.

In jest.config.js:

module.exports = {
  testEnvironment: 'node',
  collectCoverage: false,
  coveragePathIgnorePatterns: ['dist', 'other', 'directories'],
  roots: ['<rootDir>'],
  transform: { '^.+\\.(t|j)s$': 'ts-jest' },
  transformIgnorePatterns: ['/node_modules/'],
  moduleFileExtensions: ['ts', 'js'],
  watchPathIgnorePatterns: ['node_modules'],
  moduleNameMapper: {
    'my-library': '<rootDir>'
  }
};

In my-class.js:

const { ClassWeProvide } = require('my-library');

module.exports = class MyJSClass extends ClassWeProvide {
  ...
};

In my MyJSClass.test.ts:

/* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports */
const MyJSClass = require('../MyJSClass');

describe('My JS Class', () => {...});
SyntaxError: Unexpected token ','

> 1 | const { MyJSClass } = require('my-library');
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