Skip to content

Commit

Permalink
test: add gatsby-node tests for plugin manifest (#8598)
Browse files Browse the repository at this point in the history
* Add gatsby-node tests for plugin manifest

* Fixes after review

* Better fix the jest mocks

* Fix test to not fail for windows
  • Loading branch information
oorestisime authored and pieh committed Oct 8, 2018
1 parent 196c594 commit 70839b2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Test plugin manifest options correctly works with default parameters 1`] = `"{\\"name\\":\\"GatsbyJS\\",\\"short_name\\":\\"GatsbyJS\\",\\"start_url\\":\\"/\\",\\"background_color\\":\\"#f7f0eb\\",\\"theme_color\\":\\"#a2466c\\",\\"display\\":\\"minimal-ui\\",\\"icons\\":[{\\"src\\":\\"icons/icon-48x48.png\\",\\"sizes\\":\\"48x48\\",\\"type\\":\\"image/png\\"},{\\"src\\":\\"icons/icon-72x72.png\\",\\"sizes\\":\\"72x72\\",\\"type\\":\\"image/png\\"},{\\"src\\":\\"icons/icon-96x96.png\\",\\"sizes\\":\\"96x96\\",\\"type\\":\\"image/png\\"},{\\"src\\":\\"icons/icon-144x144.png\\",\\"sizes\\":\\"144x144\\",\\"type\\":\\"image/png\\"},{\\"src\\":\\"icons/icon-192x192.png\\",\\"sizes\\":\\"192x192\\",\\"type\\":\\"image/png\\"},{\\"src\\":\\"icons/icon-256x256.png\\",\\"sizes\\":\\"256x256\\",\\"type\\":\\"image/png\\"},{\\"src\\":\\"icons/icon-384x384.png\\",\\"sizes\\":\\"384x384\\",\\"type\\":\\"image/png\\"},{\\"src\\":\\"icons/icon-512x512.png\\",\\"sizes\\":\\"512x512\\",\\"type\\":\\"image/png\\"}]}"`;

exports[`Test plugin manifest options fails on non existing icon 1`] = `"icon (non/existing/path) does not exist as defined in gatsby-config.js. Make sure the file exists relative to the root of the site."`;
47 changes: 47 additions & 0 deletions packages/gatsby-plugin-manifest/src/__tests__/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
jest.mock(`fs`, () => {
return {
existsSync: jest.fn().mockImplementation(() => true),
writeFileSync: jest.fn(),
statSync: jest.fn(),
}
})
const fs = require(`fs`)
const path = require(`path`)
const { onPostBootstrap } = require(`../gatsby-node`)

describe(`Test plugin manifest options`, () => {
it(`correctly works with default parameters`, async () => {
await onPostBootstrap([], {
name: `GatsbyJS`,
short_name: `GatsbyJS`,
start_url: `/`,
background_color: `#f7f0eb`,
theme_color: `#a2466c`,
display: `minimal-ui`,
})
const [filePath, contents] = fs.writeFileSync.mock.calls[0]
expect(filePath).toEqual(path.join(`public`, `manifest.webmanifest`))
expect(contents).toMatchSnapshot()
})
it(`fails on non existing icon`, (done) => {
fs.statSync.mockReturnValueOnce({ isFile: () => false })
onPostBootstrap([], {
name: `GatsbyJS`,
short_name: `GatsbyJS`,
start_url: `/`,
background_color: `#f7f0eb`,
theme_color: `#a2466c`,
display: `minimal-ui`,
icon: `non/existing/path`,
icons: [{
src: `icons/icon-48x48.png`,
sizes: `48x48`,
type: `image/png`,
}],
})
.catch((err) => {
expect(err).toMatchSnapshot()
done()
})
})
})

0 comments on commit 70839b2

Please sign in to comment.