Olszewskidev / lens-up

LensUp is a web application that serves as a virtual gallery, allowing party guests to upload their photos from the event and also write down their wishes.
54 stars 3 forks source link

Testing for ui #87

Open JanSafronov opened 4 months ago

JanSafronov commented 4 months ago

I am thinking about setting up testing for ui packages, will Jest framework be good enough for lens-up @Olszewskidev? It has a few limitations with Vite so if it's ok I will configure babel for the ui packages?

JanSafronov commented 4 months ago

90 has an issue regarding import.meta property.

The error during testing reads:

Test suite failed to run

    packages/gallery-ui/src/services/GalleryApi.ts:6:14 - error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 
'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

    6     baseUrl: import.meta.env.VITE_GALLERY_SERVICE_URL,
                   ~~~~~~~~~~~
    packages/gallery-ui/src/services/GalleryApi.ts:26:74 - error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

    26                     const socket = new HubConnectionBuilder().withUrl(`${import.meta.env.VITE_GALLERY_SERVICE_URL}/hubs/gallery?galleryId=${galleryId}`).build();
JanSafronov commented 4 months ago

I think adding the --experimental-vm-modules option to Jest testing command has partially resolved the issue but now there is a different error;

TypeError: Cannot read properties of undefined (reading 'VITE_GALLERY_SERVICE_URL')

      4 |
      5 | const baseQuery = fetchBaseQuery({
    > 6 |     baseUrl: import.meta.env.VITE_GALLERY_SERVICE_URL,
        |                              ^
      7 | });
      8 |
      9 | export const galleryApi = createApi({

      at packages/gallery-ui/src/services/GalleryApi.tsx:6:30
JanSafronov commented 4 months ago

I will just use Vitest, it seems like Jest isn't worth the setup since there are hurdles with Vite, ts and Jest..

JanSafronov commented 4 months ago

I also want to mock getGalleryPhotos in the galleryApi together with "Cypress" SignalR JS testing library if this is fine @Olszewskidev