Closed petevb closed 3 years ago
@petdun2519 Thanks for the submission, it looks like there are a few points in your issue.
First problem: this seems to be intended behavior, it looks like the jest config that's generated targets the __test__
folder. That said, it would be useful to have this called out in quick start example. We can get that added.
Second problem: This seems like it is likely a bug that I can reproduce. I am uncertain as to why this is not working. We'll take a look and see if there is a good fix!
@kenotron fyi
Thanks @joschect . As an example fix, if you modify the "minimal" App.test.tsx and import ignore-styles
import React from "react";
import register from 'ignore-styles'
register(['.sass', '.scss', '.css', '.png']);
import { App } from './App';
...
then the test will pass. I think it'd be useful for the generated app to include that npm package and a basic component test as it's a better user experience IMHO.
To the first point, it looks to me like that jest config is trying to run tests that are in __tests__
or src
but perhaps I'm misunderstanding. Thanks for the quick response!
@petevb You are correct! I missed the second string in the array. I have been able to run a test in the root folder without issue using both .spec and .test. I'm not sure why you're encountering a problem.
For the second point though, we are actively moving away from using npm init uifabric in favor of using react create app. This pr was one step in moving us away. I'll be changing the documentation on the "Quick Start" page to map to the language used in that pr. In the future we may look into making a RCA configuration to do something similar to what npm init does right now, but that is not currently in the works.
@joschect So does that mean we (uifabric consumers) should move away from the "npm init uifabric created" app and base off CRA instead? We haven't got far, so could start again at this stage. I'm a little nervous to take a "legacy" dependency on just-scripts if the public will be using react-scripts (or ejecting) going forward. Given what you've said, please feel free to close this too. Thanks for the feedback.
Also, please consider exporting this https://github.com/microsoft/fluentui/wiki/Testing#shallowuntiltarget-function as we'll have the same problem as you when trying to write tests for our apps. Let me know if you want a separate issue for that :)
@petevb Yes that's correct. It shouldn't be too much of a difference. and if you want to start with react-create-app is fairly minimal and it should provide a good start! That said I don't believe that just
is a legacy package. @kenotron should be able to comment on that.
ShallountilTarget looks like it is exported, but I don't see it as being easily accessible. I'll look into adding it to a better index. That being said, I don't see us actually using it anywhere so I'm going to have to see if it works as expected or if there is another option now.
Closing this since we've switched to recommending a different starter based on Create React App. See this page for details.
It seems like jest isn't configured correctly with the generated app:
src
folder (it looks like it's meant to); and;App.tsx
due to the import of a png.Environment Information
Repro
in a clean folder, create, build, & test a new app:
(
src\__tests__index.spec.ts
will pass)First problem: Tests in
src
seem to be ignored, i.e. create anApp.spec.tsx
test insrc
& it won't get run unless you tweak that glob/regex injest.config.js
. Change:'<rootDir>/src/**/?(*.)+(spec|test).[tj]s?(x)']
to'<rootDir>/src/**/*.(spec|test).[tj]s?(x)']
it'll then pick up tests insrc
, but they still won't pass...Second problem: Create a minimal
App.spec.tsx
test file insrc
:and re-run
npm run test
...Actual behavior:
Expected behavior:
I'd expect the generated app to be able to run the tests out of the box.
Priorities and help requested:
Are you willing to submit a PR to fix? No Requested priority: Normal Products/sites affected: (if applicable): Fluent UI React "Quick Start"
Issue looks similar to #9150 but that was resolved by moving to 7.0.0 so I don't think it's a dupe.
Perhaps the generated app needs
moduleNameMapper
so jest can handle the png? But I don't see where to do that with the out-of-boxjust
scripts.As a suggestion, it'd be great if the generated app could include a working component test rather than the simpler index please.
By comparison the Create React App sample at https://github.com/microsoft/create-react-app-uifabric does include an
App.test.tsx
but for a differentApp.tsx
that doesn't import an image.Thanks.