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

205 to 206 update breaks jest tests with star imports #5204

Closed
Smrtnyk opened this issue Jul 14, 2022 · 4 comments
Closed

205 to 206 update breaks jest tests with star imports #5204

Smrtnyk opened this issue Jul 14, 2022 · 4 comments
Labels

Comments

@Smrtnyk
Copy link

Smrtnyk commented Jul 14, 2022

Describe the bug

Ever since I updated swc core from 205 to 206 my jest tests break with message:

Cannot redefine property: getCookie
TypeError: Cannot redefine property: getCookie
    at Function.defineProperty (<anonymous>)
    at ModuleMocker.spyOn (C:\workspaces\repositories\cdf\abc\node_modules\jest-mock\build\index.js:820:16)

I assume it is because of this commit
fa68cbd

I provided a screenshot with a diff of transformed output code
swc-repro
between 205 and 206

Seems like 206 now adds the extra

Object.defineProperty(exports, "__esModule", {
   value: true
});

I have a hunch that it could be related to the failure.
I have tried setting the module to commonjs in swc config but still didn't work

Input code

import type { JSAgent } from "../../types/dt-types";
import * as Cookies from "../jstf-utils/cookies";
import { CoreApiProp } from "../../types/dt-types";
import { getCurrentSessionId } from "./agent-utils";

jest.mock("../jstf-logger");

describe("testframework/api/dtutils/agent-utils.ts", () => {
    describe("getCurrentSessionId()", () => {
        it("detects current session id when v3 cookie format", () => {
            const v3CookieParserSpy = jest.fn().mockReturnValue({ serverId: "35", sessionId: "sessionID" });
            const agentMock = {
                [CoreApiProp.PARSE_V3_SESSION_COOKIE]: v3CookieParserSpy
            } as unknown as JSAgent;
            jest.spyOn(Cookies, "getCookie").mockReturnValue("=3=sn=sessionID");
            expect(getCurrentSessionId(agentMock)).toBe("sessionID");
            expect(v3CookieParserSpy).toHaveBeenCalledWith("=3=sn=sessionID");
        });
        it("returns empty string if no agent is available", () => {
            expect(getCurrentSessionId(null)).toBe("");
        });
    });
});

Config

transform: {
        "^.+\\.(t|j)sx?$": ["@swc/jest", {
            "sourceMaps": "inline",

            "module": {
                "strictMode": false
            },

            "jsc": {
                "target": "es2021",
                "parser": {
                    "syntax": "typescript"
                }
            }
        }]
    },

Playground link

No response

Expected behavior

I would expect since I changed nothing in swc config that tests still work.
Or was there some change that requires config update?

Actual behavior

Tests fail.

Version

1.2.206

Additional context

No response

@Smrtnyk Smrtnyk added the C-bug label Jul 14, 2022
@kdy1
Copy link
Member

kdy1 commented Jul 14, 2022

Closing as duplicate of lots of issues.

@kdy1 kdy1 closed this as not planned Won't fix, can't repro, duplicate, stale Jul 14, 2022
@Smrtnyk
Copy link
Author

Smrtnyk commented Jul 14, 2022

I think you should elaborate a bit why you closed this and which issues this duplicates.
You published a patch version 206 which had a breaking change, and you closed this issue as not planned.
I would at least like to know the reason why this happens and if it will be ever fixed, or if I need to adjust the config?
Otherwise I will need to stay on swc 205 not being able to upgrade.

@kdy1
Copy link
Member

kdy1 commented Jul 14, 2022

See #5205

@swc-bot
Copy link
Collaborator

swc-bot commented Oct 16, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants