Skip to content
This repository has been archived by the owner on Mar 5, 2022. It is now read-only.

Fonts are not applying in tests #284

Closed
taninnazar opened this issue Jun 12, 2020 · 12 comments · Fixed by #298
Closed

Fonts are not applying in tests #284

taninnazar opened this issue Jun 12, 2020 · 12 comments · Fixed by #298
Labels

Comments

@taninnazar
Copy link

taninnazar commented Jun 12, 2020

While running tests I see warning messages in browser console and also font are not applying to texts in test. Any ways to avoid that ?
image
image

Desktop (please complete the following information):

OS: Windows
Cypress Version 4.8.0
cypress-react-unit-test 4.5.0

@bahmutov
Copy link
Contributor

Hmm, can you create an example to recreate this? It might be true, but I don't have enough information to help

@taninnazar
Copy link
Author

Will try to add some example later. But for now - can you confirm that url for font should be http://localhost:65137/__cypress/iframes/component/component-library/Feedback/AlertBox/static/media/Inter-Regular.1e081edc.woff2 but not http://localhost:65137/static/media/Inter-Regular.1e081edc.woff2 ?

@bahmutov
Copy link
Contributor

this looks close to #140 but without a reproduction, I cannot tell

@taninnazar
Copy link
Author

taninnazar commented Jun 15, 2020

@bahmutov ok, it looks similar to the issue #140. But I didn't get how to fix. I pushed example based on your repo (https://github.com/bahmutov/try-cra-app-typescript). Here is a branch with new font and there is same error while running test - https://github.com/taninnazar/cypress-cra-typescript/tree/error-on-loading-fonts

@taninnazar
Copy link
Author

@bahmutov finally, I got it working. But it looks not very nice. Can this be fixed on Cypress side ?
Anyway, thanks for useful redirect. FYI my solution (as we don't have any css in our project)-
add font to test

@bahmutov
Copy link
Contributor

I will take a look later if I find time

@taninnazar
Copy link
Author

ok, are there any ways for now to apply this options object to all components inside mount() but not to add this in each mount?

@bahmutov
Copy link
Contributor

bahmutov commented Jun 15, 2020 via email

@bahmutov
Copy link
Contributor

Screenshot of resources loading:

Screen Shot 2020-06-16 at 2 16 15 PM

Notice that SVG image is loading correctly, we can see the response

Screen Shot 2020-06-16 at 2 16 36 PM

But the font file is NOT loading correctly (it responds with the iframe itself as a fallthrough)

Screen Shot 2020-06-16 at 2 16 45 PM

The difference is in the URL: we insert a loader for images that redirects all images to load from /__root

Screen Shot 2020-06-16 at 2 18 30 PM

but the fonts are still being loaded from relative path to iframe

Screen Shot 2020-06-16 at 2 18 36 PM

Proposal

Insert a loader that directs all relative fonts to be loaded from the /__root just like the image loader does

@bahmutov
Copy link
Contributor

@bahmutov
Copy link
Contributor

More complicated than that, since we have to work with the existing style-loader and css-loader

const a = {
  test: /\.css$/,
  exclude: /\.module\.css$/,
  use: [
    "/Users/gleb/git/cypress-react-unit-test/node_modules/style-loader/index.js",
    {
      loader:
        "/Users/gleb/git/cypress-react-unit-test/node_modules/react-scripts/node_modules/css-loader/dist/cjs.js",
      options: { importLoaders: 1, sourceMap: false },
    },
    {
      loader:
        "/Users/gleb/git/cypress-react-unit-test/node_modules/postcss-loader/src/index.js",
      options: {
        ident: "postcss",
        plugins: [(Function: plugins)],
        sourceMap: false,
      },
    },
  ],
  sideEffects: true,
};

@bahmutov
Copy link
Contributor

🎉 This issue has been resolved in version 4.7.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

2 participants