feat(jest-to-node-test-runner): add initial implementation#70
feat(jest-to-node-test-runner): add initial implementation#70Ceres6 wants to merge 6 commits intonodejs:mainfrom
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.
we can use snapshot https://nodejs.org/docs/v22.15.0/api/test.html#snapshot-testing
There was a problem hiding this comment.
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.
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.
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.
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.
"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.
What if the user defined and/or imported these from elsewhere?
There was a problem hiding this comment.
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.
| 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.
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 |
|
Hey on we are going to use new codemod CLI/approach https://codemod.com/blog/new-codemod-cli |
|
Bump @Ceres6 👋 |
| "type": "module", | ||
| "main": "./src/workflow.ts", | ||
| "scripts": { | ||
| "test": "npx codemod@next jssg test -l typescript ./src/workflow.ts ./" |
There was a problem hiding this comment.
| "test": "npx codemod@next jssg test -l typescript ./src/workflow.ts ./" | |
| "test": "npx codemod jssg test -l typescript ./src/workflow.ts ./" |
BTW no nedeed anymore
No description provided.