Skip to content

feat(jest-to-node-test-runner): add initial implementation #70

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Ceres6
Copy link

@Ceres6 Ceres6 commented May 11, 2025

No description provided.

@Ceres6
Copy link
Author

Ceres6 commented May 11, 2025

I have just started working on this. Any feedback is appreciated.

const importStatement =
'import { describe, it } from "node:test";\nimport { expect } from "expect";\n';

t.assert.deepStrictEqual(result, `${importStatement}${source.split("\n").slice(1).join("\n")}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I will use that in the end, but since I'm changing this a lot I didn't want to have to update them all the time yet

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hint node --run test -- --test-update-snapshot 😁

@AugustinMauroy
Copy link
Member

AugustinMauroy commented May 12, 2025

You should add on your todo for this codemod:

  • way to remove jest dep, then verify if expect is downloaded
    that need to have something that check which package manager is used
  • check if un-imporded jest describe, it is supported by the codemod
  • found a way to modify scripts key in package.json to use node --test

@Ceres6
Copy link
Author

Ceres6 commented May 14, 2025

You should add on your todo for this codemod:

  • way to remove jest dep, then verify if expect is downloaded
    that need to have something that check which package manager is used
  • check if un-imporded jest describe, it is supported by the codemod
  • found a way to modify scripts key in package.json to use node --test

Agreed. the un-imported one already works, maybe I should add a different test for that

{
"$schema": "https://codemod-utils.s3.us-west-1.amazonaws.com/configuration_schema.json",
"name": "jest-to-node-test-runner",
"description": "Convert Jest tests to Node Test Runner tests",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call this "node:test" instead of "Node Test Runner"

And "jest-to-node-test", etc


This package transforms Jest test files into Node Test Runner test files.

This is a one-and-done process, and the updated source-code should be committed to your version control (eg git); thereafter, source-code import statements should be authored compliant with the ECMAScript (JavaScript) standard.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a guaranteed "one-and-done"? I don't think we should make any promises.

At least right now, this definitely is not a one and done scenario

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"One-and-done" refers to it being a discrete, one-off process (contrary to a loader that runs every time).

Comment on lines 8 to 14
"describe",
"it",
"test",
"beforeEach",
"afterEach",
"beforeAll",
"afterAll",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the user defined and/or imported these from elsewhere?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still WIP, I'm trying to cover low hanging fruits first so I can test it with simple projects and then I/we could support projects with less standard usage

@Ceres6 Ceres6 force-pushed the feat/jest-to-node-test-runner branch 4 times, most recently from b409260 to 6d32aed Compare May 28, 2025 16:10
@Ceres6
Copy link
Author

Ceres6 commented May 28, 2025

I added a bunch of features, started a TODO list and left some TODO/FIXME were I think things could be done better. As before any feedback is welcomed.

I know it needs to be split across functions/files but I was delaying that until some abstractions become obvious.

What I'm planning next is:

  • support timers config options
  • support .each, .concurrent and failing
  • support timeout arg in suites/tests
  • improve module mocking support

I want something like

jest.mock('../myModule', () => {
  // Require the original module to not be mocked...
  const originalModule = jest.requireActual('../myModule');

  return {
    __esModule: true, // Use it when dealing with esModules
    ...originalModule,
    getRandom: jest.fn(() => 10),
  };
});

to work and hopefully support most of the https://jestjs.io/docs/jest-object#mock-modules methods

@Ceres6 Ceres6 force-pushed the feat/jest-to-node-test-runner branch from 6d32aed to b7ad997 Compare May 28, 2025 16:22

t.assert.snapshot(result);
});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it("should be a runnable test", async () => {
/**
* 1. run the codemod
* 2. up a child process
* 3. assert output code + stdout & stderr
*/
});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in some case you use ts.assert.something
you have to import assert module to do some asserting and only if you need to do some snapshots use t.assert.snapshot

@AugustinMauroy
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🏗 In progress
Development

Successfully merging this pull request may close these issues.

4 participants