Skip to content

Commit

Permalink
Revised gitignore to add test back
Browse files Browse the repository at this point in the history
  • Loading branch information
seankovacs committed Apr 29, 2021
1 parent abe0362 commit 46fb0b9
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
!index.js
node_modules/
.DS_Store
gatsby-node.js
internals.js
./gatsby-node.js
./internals.js
!src/*.js
103 changes: 103 additions & 0 deletions src/__tests__/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
jest.mock(`fs-extra`)
const fs = require(`fs-extra`)
const path = require(`path`)
const { onPostBuild } = require(`../gatsby-node`)

describe("gatsby-plugin-guru-export", () => {
describe(`onPostBuild`, () => {
beforeEach(() => {
fs.exists = jest.fn().mockResolvedValue(true);
fs.writeFile = jest.fn().mockResolvedValue();
fs.mkdirp = jest.fn().mockResolvedValue();
});

it(`exports`, async () => {
fs.writeFile = jest.fn();
fs.writeFile.mockResolvedValue(true);
const graphql = jest.fn();
graphql.mockResolvedValue({
data: {
site: {
siteMetadata: {
title: `a sample title`,
description: `a description`,
siteUrl: `http://dummy.url/`,
},
},
allMarkdownRemark: {
edges: [
{
node: {
frontmatter: {
id: 1,
title: "sample title",
description: "sample description",
slug: 'sample1'
},
},
},
{
node: {
frontmatter: {
id: 2,
title: "sample title 2",
description: "sample description 2",
slug: 'sample2'
},
},
},
],
},
},
});
const customQuery = `
{
allMarkdownRemark(
limit: 1000,
) {
edges {
node {
frontmatter {
id
title
description
slug
}
}
}
}
}
`;
const options = {
feeds: [
{
output: `/guru`,
serialize: ({ query: { site, allMarkdownRemark } }) =>
allMarkdownRemark.edges.map((edge) => {
return {site: site, ... edge.node.frontmatter};
}),
query: customQuery,
guruFieldMapping: {
Title: "title",
ExternalId: "id",
ExternalUrl: (serializedData) =>
`${serializedData.site.siteMetadata.siteUrl}${serializedData.slug}`,
},
},
],
};
await onPostBuild({ graphql }, options);

expect(fs.writeFile).toHaveBeenCalledTimes(2);

const call0 = fs.writeFile.mock.calls[0];
const call1 = fs.writeFile.mock.calls[1];

expect(call0[0]).toEqual(path.join(`public/guru`, `card0.yaml`));
expect(call0[1]).toMatchSnapshot();

expect(call1[0]).toEqual(path.join(`public/guru`, `card1.yaml`));
expect(call1[1]).toMatchSnapshot();
});
});
});

0 comments on commit 46fb0b9

Please sign in to comment.