-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add gatsby-node tests for plugin manifest (#8598)
* 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
1 parent
196c594
commit 70839b2
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
packages/gatsby-plugin-manifest/src/__tests__/__snapshots__/gatsby-node.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
47
packages/gatsby-plugin-manifest/src/__tests__/gatsby-node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) | ||
}) |