-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
base: main
Are you sure you want to change the base?
Conversation
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")}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can use snapshot https://nodejs.org/docs/v22.15.0/api/test.html#snapshot-testing
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
😁
You should add on your todo for this codemod:
|
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", |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
"describe", | ||
"it", | ||
"test", | ||
"beforeEach", | ||
"afterEach", | ||
"beforeAll", | ||
"afterAll", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
b409260
to
6d32aed
Compare
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:
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 |
6d32aed
to
b7ad997
Compare
|
||
t.assert.snapshot(result); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it("should be a runnable test", async () => { | |
/** | |
* 1. run the codemod | |
* 2. up a child process | |
* 3. assert output code + stdout & stderr | |
*/ | |
}); |
There was a problem hiding this comment.
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
to modify dep read that https://docs.codemod.com/building-codemods/package-requirements#param-deps |
No description provided.