Skip to content

Commit

Permalink
♻️ Refactor to use chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
Robdel12 committed Aug 17, 2022
1 parent 397d42c commit 347dfae
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 63 deletions.
7 changes: 1 addition & 6 deletions nightwatch.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ module.exports = {
test_settings: {
default: {
desiredCapabilities: {
browserName: 'firefox',
alwaysMatch: {
'moz:firefoxOptions': {
args: ['-headless']
}
}
browserName: 'firefox'
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"expect": "^27.0.2",
"geckodriver": "^3.0.1",
"mocha": "^10.0.0",
"nightwatch": "^2.1.3",
"nightwatch": "^2.3.0",
"nyc": "^15.1.0",
"tsd": "^0.22.0"
}
Expand Down
47 changes: 22 additions & 25 deletions test/percySnapshot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,56 @@ const helpers = require('@percy/sdk-utils/test/helpers');
module.exports = {
async beforeEach(browser) {
await helpers.setupTest();
await browser.url(helpers.testSnapshotURL);
},

after(browser) {
browser.end();
},

'disables snapshots when the healthcheck fails': async browser => {
await helpers.test('error', '/percy/healthcheck');

await browser.percySnapshot();
await browser.percySnapshot('Snapshot 2');
await browser
.navigateTo(helpers.testSnapshotURL)
.percySnapshot()
.percySnapshot('Snapshot 2');

expect(await helpers.get('logs')).toEqual(expect.arrayContaining([
'Percy is not running, disabling snapshots'
]));

browser.assert.ok(true);
},

'uses test name for snapshot name when percySnapshot is blank': async browser => {
await browser.percySnapshot();

expect(await helpers.get('logs')).toEqual(expect.arrayContaining([
'Snapshot found: uses test name for snapshot name when percySnapshot is blank'
]));

browser.assert.ok(true);
await browser
.assert.ok(true)
.end();
},

'posts snapshots to the local percy server': async function(browser) {
await browser.percySnapshot('Snapshot 1');
await browser.percySnapshot('Snapshot 2');
'posts snapshots to the local percy server': async browser => {
await browser
.navigateTo(helpers.testSnapshotURL)
.percySnapshot()
.percySnapshot('Snapshot 2');

expect(await helpers.get('logs')).toEqual(expect.arrayContaining([
'Snapshot found: Snapshot 1',
'Snapshot found: posts snapshots to the local percy server',
'Snapshot found: Snapshot 2',
`- url: ${helpers.testSnapshotURL}`,
expect.stringMatching(/clientInfo: @percy\/nightwatch\/.+/),
expect.stringMatching(/environmentInfo: nightwatch\/.+/)
]));

browser.assert.ok(true);
await browser
.assert.ok(true)
.end();
},

'handles snapshot failures': async browser => {
await helpers.test('error', '/percy/snapshot');
await browser.percySnapshot('Snapshot 1');
await browser
.navigateTo(helpers.testSnapshotURL)
.percySnapshot('Snapshot 1');

expect(await helpers.get('logs')).toEqual(expect.arrayContaining([
'Could not take DOM snapshot "Snapshot 1"'
]));

browser.assert.ok(true);
await browser
.assert.ok(true)
.end();
}
};
Loading

0 comments on commit 347dfae

Please sign in to comment.