Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow transparent loading of TypeScript custom reporters (by implementing requireAndTranspileModule in TestScheduler.ts loading custom reporters?) #10105

Closed
nelsonjchen opened this issue May 29, 2020 · 4 comments

Comments

@nelsonjchen
Copy link

I couldn't find an existing issue talking about this.

🚀 Feature Proposal

It would be great to be able to load TypeScript custom reporters directly.

I don't know if implementing this TODO allows for this:
https://github.com/facebook/jest/blob/3f107a33775cdff94cab6993741e3a1a22e00aa0/packages/jest-core/src/TestScheduler.ts#L329-L330

Jest 26 has already come, but this TODO wasn't fulfilled before 26.

Motivation

Implementing this into Jest would keep the overall project build config cleaner.

The alternative is to transpile the custom reporter manually from TS to JS or have to write the custom reporter in JS. These necessitate more build and IDE configuration. It's a similar motivation for plain TS files underneath __tests__ currently "just working".

Example

User writes a TypeScript custom reporter. And without compiling the TS, they can specify the TS script directly as a custom reporter.

It would look something like this in the config.

{
  "reporters": ["default", "<rootDir>/my-custom-reporter.ts"]
}

Pitch

There may be a chicken and egg problem with a Typescript config, but there shouldn't be one for reporters. We can currently load Typescript tests without compiling so why not TS reporters?

@jeysal
Copy link
Contributor

jeysal commented May 30, 2020

Thanks. I've amended the umbrella issue for transforming things from the config to also include this - cleaner to have it all there :)

@jeysal jeysal closed this as completed May 30, 2020
@aslettemark
Copy link

Is there a known "best way" to work around this for the time being?

@Bnaya
Copy link

Bnaya commented Aug 22, 2020

@aslettemark what i did:
You create intermediate js file that uses ts-node/babel-node register and requiring the actual file

// reporter.js

// jest can't transpile transformers on the fly so we help him
// https://github.com/facebook/jest/issues/10105

/* eslint-disable import/no-extraneous-dependencies */
const tsNode = require('ts-node');

tsNode.register({
    transpileOnly: true,
    compilerOptions: require('@testim/root-cause-jest/tsconfig').compilerOptions,
});

const Reporter = require('@testim/root-cause-jest/lib/reporter/default');

module.exports = Reporter;

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants