ehrencrona / gatsby-plugin-testing Goto Github PK
View Code? Open in Web Editor NEWGatsby plugin enabling unit testing of Graph QL components
License: MIT License
Gatsby plugin enabling unit testing of Graph QL components
License: MIT License
Plugin is installed, Jasmine2 is installed, and I've added this to jest.config.js:
testRunner: "jest-jasmine2"
But when I run gatsby develop, it gives this:
If you need withQuerySnapshots, Jasmine needs to be the current test runner.
Install it using e.g. "npm i jest-jasmine2", then add "testRunner": "jest-jasmine2" to your Jest configuration.
Your Jest configuration is typically in jest.config.js in the root of your project.
Read more at https://jestjs.io/docs/configuration#testrunner-string
I am using Jest 28. I saw this comment on SO which suggest a compatibility issue?
versions of things:
"dependencies": {
"@contentful/rich-text-plain-text-renderer": "^15.12.1",
"@gatsby-cloud-pkg/gatsby-plugin-preview": "^1.0.13",
"@mdx-js/mdx": "^1.6.22",
"@mdx-js/react": "^1.6.22",
"gatsby": "^4.15.0",
"gatsby-plugin-advanced-sitemap": "^2.1.0",
"gatsby-plugin-image": "^2.15.0",
"gatsby-plugin-manifest": "^4.15.0",
"gatsby-plugin-mdx": "^3.15.0",
"gatsby-plugin-react-helmet": "^5.15.0",
"gatsby-plugin-robots-txt": "^1.7.1",
"gatsby-plugin-s3": "^0.3.8",
"gatsby-plugin-sharp": "^4.15.0",
"gatsby-plugin-testing": "^0.3.5",
"gatsby-source-contentful": "^7.13.1",
"gatsby-source-filesystem": "^4.15.0",
"gatsby-transformer-sharp": "^4.15.0",
"jest-jasmine2": "^28.1.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-helmet": "^6.1.0"
},
"devDependencies": {
"@types/jest": "^28.1.2",
"@types/node": "^17.0.35",
"@types/react": "^17.0.45",
"@types/react-dom": "^17.0.17",
"@types/react-test-renderer": "^17.0.2",
"identity-obj-proxy": "^3.0.0",
"react-test-renderer": "^17.0.2",
"ts-jest": "^28.0.5",
"typescript": "^4.6.4"
}
I want to write a test that checks frontmatter data in all my pages.
The best I think of now is loop through pages by page name and get the page data for each one like your getPageQueryData
function does.
But since the graphql data is populated somewhere can I just grab it directly?
I have set up testing for a project, and I work on it both on Linux and Windows,
all the tests that have static-query pass without problem on Linux,
however on Windows static queries are not loaded and it throws.
● Index › renders with fixtures
While getting static query data: Did not find component C:\Users\xx\xx\project\src\components\Sections\Index\IELTS\Courses.tsx, only:
C:/Users/xx/xx/project/src/components/Sections/Index/IELTS/Courses.tsx
C:/Users/xx/xx/project/src/components/Sections/Index/Speaking/Courses.tsx
Do you need to re-run gatsby build?
at getQueryHashForComponentPath (C:\Users\xx\xx\project\node_modules\gatsby-plugin-testing\src\static-query.js:75:11)
I have run gatsby build
, the page queries have no problem, the same test runs flawlessly on Linux.
It seems like it finds the component, but there's a problem with handling of slashes/backslashes.
Currently a path separator is missing in the const queryDataFileNameLegacy
definition. As a result, GraphQL result cannot be found. Fixed in #7.
Hey thanks for the great plugin, it really saves us a lot of time configuring testing.
After updating Gatsby to latest version, when I start dev server and compilation finishes, gatsby-plugin-testing indefinitely shows a spinner as if it is doing something, although development bundle has finished being created.
success write out requires - 0.001s
success Re-building development bundle - 2.169s
⠄ [gatsby-plugin-testing] stored static queries
Getting TypeError: Cannot set property 'isWithSnapshot' of undefined
when running a test like
describe('BGImageContainer', () => {
it(
'matches snapshot',
withQuerySnapshot(() => {
const tree = create(<BgImageContainer />);
expect(tree).toMatchSnapshot();
}),
);
});
Gatsby v3.6.2
gatsby-plugin-testing v0.3.4
Hello! Thank you for this plugin, it helped me a lot!
I've started to use it a few months ago and yesterday I needed to update the project and... It crashed...
I searched for the reason and found that in the new versions of Gatsby, the StaticQueries directory has changed. So I tried to fix it and I've founded a solution that works for the old versions and the new ones. Would be great to have your opinion about this and, if you allow me, I would like to merge my PR (after code review).
Sorry if I wrote a wrong sentence, I'm still learning English. I'm from Brazil. ;)
Thanks in advance.
I'm getting an error whenever I request for a specific URL in my tests:
The page path "languages" page query data was requested for is unknown. Known paths: dev-404-page, index, languages, sq
As you can see, "languages" is listed in the known paths. This is my simple test:
describe("Language page", () => {
it("renders correctly", async () => {
const tree = renderer
.create(<LanguagePage data={await getPageQueryData("languages")} />)
.toJSON()
expect(tree).toMatchSnapshot()
})
})
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.