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

Lit + Jest + Typescript + SWC Jest #4580

Open
gethari opened this issue Mar 12, 2024 · 6 comments
Open

Lit + Jest + Typescript + SWC Jest #4580

gethari opened this issue Mar 12, 2024 · 6 comments

Comments

@gethari
Copy link

gethari commented Mar 12, 2024

Which package(s) are affected?

Lit Core (lit / lit-html / lit-element / reactive-element)

Description

I am trying to use @swc/jest to speed up my tests on my lit+typescript+jest setup. When using the swc/jest as the test runner the willUpdate method is not getting executed. From what I see/find the call stack is different when using ts-jest & it works fine, but on using swc/jest the callstack is missing the _callSuper().

I am attaching a simple repository that can reproduce the issue. Additionally, I've included screenshots comparing the behavior with swc and ts-jest for your reference.

swc

image

ts-jest

image

Reproduction

Please check the readme in this repository for detailed repro steps.
https://github.com/gethari/typescript-webpack-lit-html-jest-swc

Workaround

I have not found a workaround

Is this a regression?

No or unsure. This never worked, or I haven't tried before.

Affected versions

3.1.2

Browser/OS/Node environment

Browser: Chrome 103.0.5060.53
OS: Windows 11
Node version: 20.11.1
npm version: 10.2.4

@augustjk
Copy link
Member

Are you using @property decorators? It might be that SWC isn't compiling them right. I don't know if SWC supports reading project tsconfigs but you should make sure SWC configs match those of tsconfig listed here https://lit.dev/docs/components/decorators/#decorators-typescript

@gethari
Copy link
Author

gethari commented Mar 13, 2024

@augustjk thanks for responding,

Are you using @property decorators?

Yes

This is my tsconfig.json , it has both the properties mentioned in the lit docs, as well my .swcrc config has decorators enabled.

I am not sure about the actual cause of the issue as I'm trying to use 3 different things together, that nobody before have seem to done ( so far from my search). Hence why raised issue for help across all 3 repo.

@augustjk
Copy link
Member

My suspicion is that swc's decorator config is the standard decorator proposal implementation, not TypeScript's experimental decorator, which might be this https://swc.rs/docs/configuration/compilation#jsctransformlegacydecorator

@gethari
Copy link
Author

gethari commented Mar 14, 2024

@augustjk you are right, by making the below config changes to swcrc I was able to bypass the error & got the tests up, but it results in a new error on a test, that is testing a component that is built on Stencil

Cannot find module 'web-date-picker/dist/types/components/duet-date-picker/duet-date-picker' from 'src/components/date-picker/date-picker.component.ts

image

image

But when I make the below props to false, the date-picker tests are working

"legacyDecorator": true,
"decoratorMetadata": true,

@gethari
Copy link
Author

gethari commented Mar 14, 2024

I also found these, I think might be related

my swcrc config for ref

{
    "$schema": "https://json.schemastore.org/swcrc",
    "jsc": {
        "parser": {
            "syntax": "typescript",
            "dynamicImport": true,
            "decorators": true
        },
        "baseUrl": ".",
        "paths": {
            "*": ["src/*"]
        },
        "keepClassNames": true,
        "transform": {
            "legacyDecorator": true,
            "decoratorMetadata": true,
            "useDefineForClassFields": false
        },
        "target": "esnext"
    }
}

@augustjk
Copy link
Member

I don't know about Stencil but we don't require decoratorMetadata to be true.

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

No branches or pull requests

2 participants