-
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.
feat(gatsby-plugin-offline): Allow precaching custom pages (#16877)
* Allow precaching custom pages rather than just the offline shell * Document this and add tests
- Loading branch information
Showing
24 changed files
with
373 additions
and
66 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/*.js | ||
!index.js | ||
!src/__tests__/fixtures/public | ||
yarn.lock |
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
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
18 changes: 18 additions & 0 deletions
18
packages/gatsby-plugin-offline/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,18 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`getPrecachePages correctly matches pages 1`] = ` | ||
Array [ | ||
"<PROJECT_ROOT>/packages/gatsby-plugin-offline/src/__tests__/fixtures/public/dir1/index.html", | ||
"<PROJECT_ROOT>/packages/gatsby-plugin-offline/src/__tests__/fixtures/public/dir2/index.html", | ||
"<PROJECT_ROOT>/packages/gatsby-plugin-offline/src/__tests__/fixtures/public/index.html", | ||
"<PROJECT_ROOT>/packages/gatsby-plugin-offline/src/__tests__/fixtures/public/test.html", | ||
] | ||
`; | ||
exports[`getPrecachePages correctly matches pages 2`] = ` | ||
Array [ | ||
"<PROJECT_ROOT>/packages/gatsby-plugin-offline/src/__tests__/fixtures/public/dir1/index.html", | ||
"<PROJECT_ROOT>/packages/gatsby-plugin-offline/src/__tests__/fixtures/public/dir1/page1.html", | ||
"<PROJECT_ROOT>/packages/gatsby-plugin-offline/src/__tests__/fixtures/public/dir1/page2.html", | ||
] | ||
`; |
2 changes: 2 additions & 0 deletions
2
packages/gatsby-plugin-offline/src/__tests__/fixtures/public/dir1/index.html
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,2 @@ | ||
<!-- This is an HTML file. How exciting! | ||
Content of this file is irrelevant; it is used for testing `getPrecachePages` --> |
2 changes: 2 additions & 0 deletions
2
packages/gatsby-plugin-offline/src/__tests__/fixtures/public/dir1/page1.html
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,2 @@ | ||
<!-- This is an HTML file. How exciting! | ||
Content of this file is irrelevant; it is used for testing `getPrecachePages` --> |
2 changes: 2 additions & 0 deletions
2
packages/gatsby-plugin-offline/src/__tests__/fixtures/public/dir1/page2.html
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,2 @@ | ||
<!-- This is an HTML file. How exciting! | ||
Content of this file is irrelevant; it is used for testing `getPrecachePages` --> |
2 changes: 2 additions & 0 deletions
2
packages/gatsby-plugin-offline/src/__tests__/fixtures/public/dir1/script.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,2 @@ | ||
// This is a script. How exciting! | ||
// Content of this file is irrelevant; it is used for testing `getPrecachePages` |
2 changes: 2 additions & 0 deletions
2
packages/gatsby-plugin-offline/src/__tests__/fixtures/public/dir1/style.css
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,2 @@ | ||
/* This is a stylesheet. How exciting! | ||
Content of this file is irrelevant; it is used for testing `getPrecachePages` */ |
2 changes: 2 additions & 0 deletions
2
packages/gatsby-plugin-offline/src/__tests__/fixtures/public/dir2/index.html
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,2 @@ | ||
<!-- This is an HTML file. How exciting! | ||
Content of this file is irrelevant; it is used for testing `getPrecachePages` --> |
2 changes: 2 additions & 0 deletions
2
packages/gatsby-plugin-offline/src/__tests__/fixtures/public/dir2/page1.html
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,2 @@ | ||
<!-- This is an HTML file. How exciting! | ||
Content of this file is irrelevant; it is used for testing `getPrecachePages` --> |
2 changes: 2 additions & 0 deletions
2
packages/gatsby-plugin-offline/src/__tests__/fixtures/public/dir2/page2.html
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,2 @@ | ||
<!-- This is an HTML file. How exciting! | ||
Content of this file is irrelevant; it is used for testing `getPrecachePages` --> |
2 changes: 2 additions & 0 deletions
2
packages/gatsby-plugin-offline/src/__tests__/fixtures/public/dir2/script.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,2 @@ | ||
// This is a script. How exciting! | ||
// Content of this file is irrelevant; it is used for testing `getPrecachePages` |
2 changes: 2 additions & 0 deletions
2
packages/gatsby-plugin-offline/src/__tests__/fixtures/public/dir2/style.css
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,2 @@ | ||
/* This is a stylesheet. How exciting! | ||
Content of this file is irrelevant; it is used for testing `getPrecachePages` */ |
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
packages/gatsby-plugin-offline/src/__tests__/fixtures/public/no-index-html/style.css
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,2 @@ | ||
/* This is a stylesheet. How exciting! | ||
Content of this file is irrelevant; it is used for testing `getPrecachePages` */ |
2 changes: 2 additions & 0 deletions
2
packages/gatsby-plugin-offline/src/__tests__/fixtures/public/script.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,2 @@ | ||
// This is a script. How exciting! | ||
// Content of this file is irrelevant; it is used for testing `getPrecachePages` |
2 changes: 2 additions & 0 deletions
2
packages/gatsby-plugin-offline/src/__tests__/fixtures/public/style.css
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,2 @@ | ||
/* This is a stylesheet. How exciting! | ||
Content of this file is irrelevant; it is used for testing `getPrecachePages` */ |
2 changes: 2 additions & 0 deletions
2
packages/gatsby-plugin-offline/src/__tests__/fixtures/public/test.html
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,2 @@ | ||
<!-- This is an HTML file. How exciting! | ||
Content of this file is irrelevant; it is used for testing `getPrecachePages` --> |
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
4 changes: 2 additions & 2 deletions
4
packages/gatsby-plugin-offline/src/__tests__/get-resources-from-html.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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
const path = require(`path`) | ||
const getResourcesFromHTML = require(`../get-resources-from-html`) | ||
|
||
const htmlPath = path.resolve(`${__dirname}/index.html`) | ||
const htmlPath = path.resolve(`${__dirname}/fixtures/public/index.html`) | ||
|
||
it(`it extracts resources correctly`, () => { | ||
const resources = getResourcesFromHTML(htmlPath) | ||
const resources = getResourcesFromHTML(htmlPath, ``) | ||
expect(resources).toMatchSnapshot() | ||
}) |
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
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
Oops, something went wrong.