jest throws error that it fails to parse a file

27 views Asked by At

I am trying to use the keycloak admin client in my project. I import the package and adjust my code. Then, when I run my tests, jest tells me the following:

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Jest: Got error running globalSetup - <path>/test/setup.ts, 
reason: Unknown file extension ".ts" for <path>/test/setup.ts

This happened since the implementation of the library above. Upon removing relevant code from the setup and rerunning the tests, I get a couple of the following

● Test suite failed to run

    Jest encountered an unexpected token

    Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

    Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

    By default "node_modules" folder is ignored by transformers.

    Here's what you can do:
     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
     • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/configuration
    For information about custom transformations, see:
    https://jestjs.io/docs/code-transformation  

I am using typescript and tried to make that work with jest so I followed the second step which didn't have any impact on the result. I tried the code transformation but that "solution" will immediately throw errors when typescript is used in the tests. This is getting very frustrating. I don't understand why it is this library that is causing the error.

0

There are 0 answers