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

Error when running unit tests #83

Closed
GuillermoDylan opened this issue Apr 8, 2023 · 7 comments
Closed

Error when running unit tests #83

GuillermoDylan opened this issue Apr 8, 2023 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@GuillermoDylan
Copy link
Contributor

An error when trying to run the unit tests has been found, this error is not allowing the exeuction of the tests because of an issue with one of the Leaflet modules and how Jest is processing it, or at least that is how I have understanded the following trace:

First part of the trace
Second part of the trace
After a quick search on StackOverflow, I was able to find someone with this exact same problem: Link
Unfortunately, I have already tried changing the configuration of our jest.config.ts to what he proposes on the forum, right now it is like this:

const esModules = ['@react-leaflet', 'react-leaflet'].join('|');
export default {
    transformIgnorePatterns: [`/node_modules/(?!${esModules})`],
    transform: {
        "^.+\\.tsx?$": "ts-jest"
    },
}

I think this is a very important matter and should be taken care as soon as possible, since this prevents us from testing any test that imports any of the Leaflet modules.

Just in case, this is how the test is defined, I do not think this problem is related to the code, but to the configuration, but just to make sure this is how it is coded:

Test code

@GuillermoDylan
Copy link
Contributor Author

As a small note, I would like to add that this error could possibly be caused by the following (found on StackOverflow), the index.js file of the Leaflet module is compiled into th ESM syntax instead of the CommonJS syntax, which seems to be causing all of the trouble, since Jest is not able to process it. This page offers a way to activate support for ESM on the tests, but I have not been able to try it yet and don't know if it would be recommendable or not: jestjs.io/docs/ecmascript-modules.

@uo282892
Copy link
Contributor

In webapp/package.json, put the following line:

"test": "react-scripts test --transformIgnorePatterns \"node_modules/(?!ol)/\" --coverage",

@GuillermoDylan
Copy link
Contributor Author

Thanks! This seems ti solve the problem for the Leaflet module.

Unfortunatley there seems to be another problem, as another error arises leaving the following trace:

Error trace

I will be looking forward for soultions and keep this thread upadted.

@UO283428
Copy link
Contributor

UO283428 commented Apr 10, 2023

I have seen the error in a repository
inrupt/solid-client-authn-js#1676

Use "import { TextEncoder, TextDecoder } from 'util';
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;"

@uo282892
Copy link
Contributor

Try to append the following in the webapp/src/setUpTests.ts, after the last line:

import { TextEncoder, TextDecoder } from 'util';

global.TextEncoder = TextEncoder;
(global as any).textDecoder = TextDecoder;

@GuillermoDylan
Copy link
Contributor Author

Fantastic, this does finally solve the problems with Jest, it has all been fixed and updated in develop (commit 8378946)

@FdezAriasSara
Copy link

I got the same exact error using Maps api, so I think is rather a solid library -related issue as you mentioned before (I actually accessed this issue from there )

I used the solution mentioned here:

I have seen the error in a repository inrupt/solid-client-authn-js#1676

Use "import { TextEncoder, TextDecoder } from 'util'; global.TextEncoder = TextEncoder; global.TextDecoder = TextDecoder;"

since

Try to append the following in the webapp/src/setUpTests.ts, after the last line:

import { TextEncoder, TextDecoder } from 'util';

global.TextEncoder = TextEncoder;
(global as any).textDecoder = TextDecoder;

is not working for some reason ( maybe because i use javascript not ts)

thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants