skovhus / jest-codemods

Codemods for migrating to Jest https://github.com/facebook/jest 👾
MIT License
877 stars 81 forks source link

Sinon transformer doesn't support cjs #544

Closed marklai1998 closed 3 months ago

marklai1998 commented 1 year ago

Hello, I'm trying to use this tool to transform existing Sinon code to Jest But the transformer skips every file I throw at it.

I see the test case for Sinon transformer is using ESM while all other is Cjs Its nice to support ESM, but cjs should be the majority of the user here

skovhus commented 1 year ago

Can you add an example file here, it should work for both?

marklai1998 commented 1 year ago

test.spec.js

const { expect } = require("chai");
const sinon = require("sinon");

const featureFlagSdk = require("./file");

describe("test", () => {
  describe("createCustomIcon", () => {
    before(() => {
      sinon.stub(featureFlagSdk, "evaluate").resolves(true);
    });

    it("should get file url and create icon for zeus", async () => {
      expect(true).to.be.deep.equal(true);
    });
  });
});

My settings:

? Which parser do you want to use? Babel
? Which test library would you like to migrate from? Sinon
? Are you using the global object for assertions (i.e. without requiring them) Yes, and I'm not afraid of false positive transformations
? Will you be using Jest on Node.js as your test runner? Yes, use the globals provided by Jest (recommended)
skovhus commented 1 year ago

Thanks! Would you be up for fixing this? I hope it should be pretty straightforward as the other transformers handles this correctly (I believe).

I suggest adding a test case in https://github.com/skovhus/jest-codemods/blob/main/src/transformers/sinon.test.ts and take it from there.

marklai1998 commented 1 year ago

Thanks! Would you be up for fixing this? I hope it should be pretty straightforward as the other transformers handles this correctly (I believe).

I suggest adding a test case in https://github.com/skovhus/jest-codemods/blob/main/src/transformers/sinon.test.ts and take it from there.

just tried for a while, I don't think I'm able to do it, most of the type def is gone and I don't have the knowledge foundation jscodeshift