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

Doesn't work with TypeScript #2

Open
aminya opened this issue May 13, 2021 · 5 comments · May be fixed by #3
Open

Doesn't work with TypeScript #2

aminya opened this issue May 13, 2021 · 5 comments · May be fixed by #3

Comments

@aminya
Copy link

aminya commented May 13, 2021

Unless I add @babel/preset-typescript myself, it doesn't work.

I am simplifying my babel.config.json because Parcel has switched to SWC, which handles everything in the build process. But that doesn't work for the jest tests.

@aminya
Copy link
Author

aminya commented May 13, 2021

I fixed the issue by using a custom babel.config.js:

// base config used in all situations
const config = {
  presets: ["babel-preset-solid"],
  plugins: []
}

module.exports = (api) => {
  if (api.env("test")) {
    // modify the config for Jest
    config.presets.push("@babel/preset-typescript")
    config.plugins.push("@babel/plugin-transform-modules-commonjs")
  }
  return config
}

@ryansolid
Copy link
Member

Hmm.. I wonder if it is as easy as adding it here: https://github.com/solidui/solid-jest/blob/main/preset/browser/transform.js#L4 and the equivalent on the server. I'm just thinking that the config only is setup to transform JSX files and whether adding that is sufficient. So far I have been just adding it for TypeScript projects as needed. Things like create-solid already are setup this way.

I can get around to testing this, but if you have a project handy and can confirm that is sufficient I can go and add that easily.

@aminya
Copy link
Author

aminya commented May 13, 2021

I made it working with babel.
https://github.com/aminya/solid-simple-table/actions/runs/838498775

Here is my config:

// base config used in all situations
const config = {
  presets: ["babel-preset-solid"],
  plugins: [],
}

module.exports = (api) => {
  if (api.env("test")) {
    // modify the config for Jest
    config.presets.push("@babel/preset-typescript", [
      "@babel/preset-env",
      {
        targets: {
          node: "current",
          esmodules: false,
        },
      },
    ])
  }
  return config
}

@aminya
Copy link
Author

aminya commented May 13, 2021

There is also an esbuild-jest package. If we can use that instead, that would be much faster! I couldn't configure esbuild-jest, but you may be able to do this with the help of esbuild-plugin-solid
https://www.npmjs.com/package/esbuild-jest

@aminya aminya linked a pull request May 14, 2021 that will close this issue
@maxmilton
Copy link

https://jestjs.io/docs/getting-started#using-typescript

The jest docs are already quite clear about how to add TypeScript support, shouldn't that be enough? Seems like a separate concern from transforming solid components.

Also, looks like esbuild-jest doesn't support the jsx=preserve option added in esbuild v0.12.1 which would be required to use it in a solid project.

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

Successfully merging a pull request may close this issue.

3 participants