Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!