-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a339b90
Showing
11 changed files
with
2,460 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: CI | ||
on: [push, pull_request] | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node: [10, 12] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: yarn | ||
- run: yarn test |
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,16 @@ | ||
name: Publish | ||
on: | ||
release: | ||
types: [created] | ||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: '12.x' | ||
registry-url: 'https://registry.npmjs.org' | ||
- run: npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
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 @@ | ||
node_modules |
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,21 @@ | ||
Copyright (c) Perceptual Inc. | ||
|
||
The MIT License (MIT) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,43 @@ | ||
# gatsby-plugin-percy | ||
|
||
A Gatsby plugin for automatically taking Percy snapshots after a build. | ||
|
||
### Dependencies | ||
|
||
- [@percy/agent](https://github.com/percy/percy-agent) | ||
|
||
## Install | ||
|
||
```shell | ||
$ npm install --save @percy/agent gatsby-plugin-percy | ||
``` | ||
|
||
## Usage | ||
|
||
```javascript | ||
// In your gatsby-config.js | ||
module.exports = { | ||
plugins: [ | ||
{ | ||
resolve: `gatsby-plugin-percy`, | ||
options: { | ||
files: [`dir/*.html`], | ||
ignore: [`ignore/*.html*`], | ||
config: `config/.percy.yaml`, | ||
}, | ||
}, | ||
], | ||
} | ||
``` | ||
|
||
## Options | ||
|
||
Options are not required. Percy searches the current working directory and up | ||
for a [matching config file](https://docs.percy.io/docs/sdk-configuration#section-configuration-files). | ||
The `files` and `ignore` options can be specified within a | ||
[`static-snapshots` section](https://docs.percy.io/docs/sdk-configuration#section-static-snapshots) | ||
of your Percy config file as `snapshot-files` and `ignore-files` respectively. | ||
|
||
- `files` - A single file glob or array of file globs to snapshot within the `public` directory | ||
- `ignore` - A single file glob or array of file globs to ignore within the `public` directory | ||
- `config` - Path to a [Percy config file](https://docs.percy.io/docs/sdk-configuration) |
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,10 @@ | ||
# Releasing | ||
|
||
1. Create a new tag for the version `git tag vX.X.X` | ||
2. Push the tag to GitHub `git push --tags` | ||
3. Ensure tests have passed on that tag | ||
4. [Create a new release](https://github.com/percy/gatsby-plugin-percy/releases) on GitHub | ||
5. Wait for the publish workflow to complete (triggered via a new release) | ||
6. [Visit npm](https://www.npmjs.com/package/gatsby-plugin-percy) and see the new version is live | ||
|
||
* Announce the new release, making sure to say "thank you" to the contributors who helped shape this version! |
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,22 @@ | ||
const path = require('path') | ||
const { execSync } = require('child_process') | ||
const { isArray } = Array | ||
|
||
exports.onPostBuild = ({ store }, { files, ignore, config }) => { | ||
let { program: { useYarn, directory } } = store.getState() | ||
let cmd = [useYarn ? 'yarn' : 'npm', 'percy', 'snapshot', path.resolve(directory, 'public')] | ||
|
||
if (files) { | ||
cmd = cmd.concat('--snapshot-files', [].concat(files).join(',')) | ||
} | ||
|
||
if (ignore) { | ||
cmd = cmd.concat('--ignore-files', [].concat(ignore).join(',')) | ||
} | ||
|
||
if (config) { | ||
cmd = cmd.concat('--config', config) | ||
} | ||
|
||
execSync(cmd.join(' '), { stdio: 'inherit' }) | ||
} |
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 @@ | ||
// no-op |
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,29 @@ | ||
{ | ||
"name": "gatsby-plugin-percy", | ||
"version": "0.1.0", | ||
"description": "A Gatsby plugin for automatically taking Percy snapshots after a build.", | ||
"repository": "github:percy/gatsby-plugin-percy", | ||
"author": "Perceptual Inc.", | ||
"license": "MIT", | ||
"keywords": [ | ||
"gatsby", | ||
"gatsby-plugin", | ||
"percy", | ||
"visual", | ||
"screenshot" | ||
], | ||
"scripts": { | ||
"test": "mocha test.js" | ||
}, | ||
"dependencies": { | ||
"unist-util-visit": "^1.4.0" | ||
}, | ||
"peerDependencies": { | ||
"@percy/agent": "^0.20.0" | ||
}, | ||
"devDependencies": { | ||
"expect": "^25.1.0", | ||
"mocha": "^7.0.0", | ||
"mock-require": "^3.0.0" | ||
} | ||
} |
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,86 @@ | ||
const expect = require('expect') | ||
const mock = require('mock-require') | ||
|
||
function execSyncMock(...args) { | ||
(execSyncMock.calls = execSyncMock.calls || []).push(args) | ||
} | ||
|
||
mock('child_process', { execSync: execSyncMock }) | ||
// we don't need to actually resolve paths for tests | ||
mock('path', { resolve: (...p) => p.filter(Boolean).join('/') }) | ||
// required after mocking so we don't have to re-require | ||
const { onPostBuild } = require('./gatsby-node') | ||
|
||
describe('onPostBuild', () => { | ||
let program, store = { getState: () => ({ program }) } | ||
|
||
beforeEach(() => { | ||
delete execSyncMock.calls | ||
program = {} | ||
}) | ||
|
||
it('calls `percy snapshot` with npm using the public path', () => { | ||
onPostBuild({ store }, {}) | ||
expect(execSyncMock.calls).toHaveLength(1) | ||
expect(execSyncMock.calls[0][0]).toBe('npm percy snapshot public') | ||
}) | ||
|
||
it('calls `percy snapshot` with yarn using the public path', () => { | ||
program.useYarn = true | ||
onPostBuild({ store }, {}) | ||
expect(execSyncMock.calls).toHaveLength(1) | ||
expect(execSyncMock.calls[0][0]).toBe('yarn percy snapshot public') | ||
}) | ||
|
||
it('calls `percy snapshot` with the resolved public path', () => { | ||
program.directory = 'some/project/path' | ||
onPostBuild({ store }, {}) | ||
expect(execSyncMock.calls).toHaveLength(1) | ||
expect(execSyncMock.calls[0][0]).toBe('npm percy snapshot some/project/path/public') | ||
}) | ||
|
||
it('calls `percy snapshot` with the `snapshot-files` option', () => { | ||
onPostBuild({ store }, { files: '*.html' }) | ||
expect(execSyncMock.calls).toHaveLength(1) | ||
expect(execSyncMock.calls[0][0]).toBe('npm percy snapshot public --snapshot-files *.html') | ||
|
||
onPostBuild({ store }, { files: ['*.html', '*.htm'] }) | ||
expect(execSyncMock.calls).toHaveLength(2) | ||
expect(execSyncMock.calls[1][0]).toBe('npm percy snapshot public --snapshot-files *.html,*.htm') | ||
}) | ||
|
||
it('calls `percy snapshot` with the `ignore-files` option', () => { | ||
onPostBuild({ store }, { ignore: '*.html' }) | ||
expect(execSyncMock.calls).toHaveLength(1) | ||
expect(execSyncMock.calls[0][0]).toBe('npm percy snapshot public --ignore-files *.html') | ||
|
||
onPostBuild({ store }, { ignore: ['*.html', '*.htm'] }) | ||
expect(execSyncMock.calls).toHaveLength(2) | ||
expect(execSyncMock.calls[1][0]).toBe('npm percy snapshot public --ignore-files *.html,*.htm') | ||
}) | ||
|
||
it('calls `percy snapshot` with the `config` option', () => { | ||
onPostBuild({ store }, { config: 'path/to/.percy.yml' }) | ||
expect(execSyncMock.calls).toHaveLength(1) | ||
expect(execSyncMock.calls[0][0]).toBe('npm percy snapshot public --config path/to/.percy.yml') | ||
}) | ||
|
||
it('calls `percy snapshot` with multiple options', () => { | ||
program.directory = 'some/project/path' | ||
program.useYarn = true | ||
|
||
onPostBuild({ store }, { | ||
files: ['*.html'], | ||
ignore: ['*.htm'], | ||
config: 'path/to/.percy.yml' | ||
}) | ||
|
||
expect(execSyncMock.calls).toHaveLength(1) | ||
expect(execSyncMock.calls[0][0]).toBe([ | ||
'yarn percy snapshot some/project/path/public', | ||
'--snapshot-files *.html', | ||
'--ignore-files *.htm', | ||
'--config path/to/.percy.yml' | ||
].join(' ')) | ||
}) | ||
}) |
Oops, something went wrong.