-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(PPDSC-2611): fewer tests for baseline updates (#588)
* chore(PPDSC-2611): log which baselines require updating * chore(PPDSC-2611): only run tests required * chore(PPDSC-2611): set baselines updates as partial builds * chore(PPDSC-2611): revert log changes * chore(PPDSC-2611): simply script and add tests * chore(PPDSC-2611): simplify token setting
- Loading branch information
Showing
7 changed files
with
166 additions
and
37 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
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,11 +1,13 @@ | ||
const SKIP_GITHUB_CHECK = process.env.SKIP_PERCY_CHECK === 'true'; | ||
const storybookConfig = require('./percy-storybook.config.json'); | ||
|
||
module.exports = { | ||
version: 2, | ||
snapshot: { | ||
widths: [375, 1280], | ||
}, | ||
storybook: { | ||
...storybookConfig, | ||
...(SKIP_GITHUB_CHECK ? {include: 'skip-percy-tests'} : {}), | ||
}, | ||
}; |
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,99 @@ | ||
const https = require('https'); | ||
const fs = require('fs'); | ||
const Stream = require('stream'); | ||
|
||
const {run} = require('../check-baseline-updates'); | ||
|
||
const BUILDS = { | ||
data: [ | ||
{ | ||
attributes: { | ||
branch: 'branch/approved-with-diffs', | ||
'review-state': 'approved', | ||
'total-comparisons-diff': '3', | ||
}, | ||
relationships: { | ||
snapshots: { | ||
links: { | ||
related: 'branch/approved-with-diffs-related', | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
attributes: { | ||
branch: 'branch/approved-no-diffs', | ||
'review-state': 'approved', | ||
'total-comparisons-diff': 0, | ||
}, | ||
}, | ||
{ | ||
attributes: { | ||
branch: 'branch/diffs-not-approved', | ||
'review-state': 'pending', | ||
'total-comparisons-diff': 0, | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
const SNAPSHOTS = { | ||
data: [ | ||
{ | ||
attributes: { | ||
'review-state-reason': 'user_approved', | ||
name: 'snapshot1', | ||
}, | ||
}, | ||
{ | ||
attributes: { | ||
'review-state-reason': 'user_approved', | ||
name: 'snapshot2', | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
const mockHttp = (url, options, callback) => { | ||
const streamStream = new Stream(); | ||
callback(streamStream); | ||
const data = url.includes('/api/v1/builds') ? BUILDS : SNAPSHOTS; | ||
streamStream.emit('data', JSON.stringify(data)); | ||
streamStream.emit('end'); | ||
}; | ||
|
||
describe('check-baseline-updates', () => { | ||
beforeEach(() => { | ||
process.env.PERCY_TOKEN = '__PERCY_TOKEN__'; | ||
https.get = jest.fn().mockImplementation(mockHttp); | ||
}); | ||
|
||
it('should update config file and return true if updates required', async () => { | ||
fs.writeFileSync = jest.fn(); | ||
const result = await run('branch/approved-with-diffs'); | ||
expect(fs.writeFileSync).toHaveBeenCalledWith( | ||
'./percy-storybook.config.json', | ||
JSON.stringify({include: ['^snapshot1$', '^snapshot2$']}), | ||
); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should return false if no diffs require updates', async () => { | ||
const result = await run('branch/approved-no-diffs'); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('should return false if build not approved', async () => { | ||
const result = await run('branch/diffs-not-approved'); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('should raise an exception if no token found', async () => { | ||
delete process.env.PERCY_TOKEN; | ||
await expect(run('branch/approved-no-diffs')).rejects.toThrowError(); | ||
}); | ||
|
||
it('should raise an exception if build not found', async () => { | ||
await expect(run('invalid-branch')).rejects.toThrowError(); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
name: 'scripts', | ||
displayName: 'NewsKit Scripts', | ||
testRegex: '(.|-)test\\.js$', | ||
}; |