Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✅ Use Percy CLI testing mode for tests #425

Merged
merged 2 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@
},
"scripts": {
"lint": "eslint --ignore-path .gitignore .",
"test": "MOZ_HEADLESS=1 nightwatch",
"test": "MOZ_HEADLESS=1 percy exec --testing -- nightwatch",
"test:coverage": "nyc yarn test",
"test:types": "tsd"
},
"dependencies": {
"@percy/sdk-utils": "^1.0.0"
},
"peerDependencies": {
"nightwatch": ">=1"
"nightwatch": ">=1 || >=2"
},
"devDependencies": {
"@percy/core": "^1.1.3",
"@percy/cli": "^1.9.1",
"@types/nightwatch": "^2.0.0",
"eslint": "^7.11.0",
"eslint-config-standard": "^16.0.1",
Expand Down
76 changes: 30 additions & 46 deletions test/percySnapshot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,60 @@ const expect = require('expect');
const helpers = require('@percy/sdk-utils/test/helpers');

module.exports = {
async before() {
await helpers.mockSite();
},

async after() {
await helpers.closeSite();
},

async beforeEach(browser) {
await helpers.setup();
browser.url('http://localhost:8000');
await helpers.setupTest();
await browser.url(helpers.testSnapshotURL);
},

async afterEach(browser) {
await helpers.teardown();
after(browser) {
browser.end();
},

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

await browser.percySnapshot();
await browser.percySnapshot('Snapshot 2');

await expect(helpers.getRequests()).resolves.toEqual([
['/percy/healthcheck']
]);

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

browser.assert.ok(true);
},

'posts snapshots to the local percy server': async browser => {
'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);
},

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

await expect(helpers.getRequests()).resolves.toEqual([
['/percy/healthcheck'],
['/percy/dom.js'],
['/percy/snapshot', {
name: 'posts snapshots to the local percy server',
url: 'http://localhost:8000/',
domSnapshot: '<html><head></head><body>Snapshot Me</body></html>',
clientInfo: expect.stringMatching(/@percy\/nightwatch\/.+/),
environmentInfo: expect.stringMatching(/nightwatch\/.+/)
}],
['/percy/snapshot', expect.objectContaining({
name: 'Snapshot 2'
})]
]);
expect(await helpers.get('logs')).toEqual(expect.arrayContaining([
'Snapshot found: Snapshot 1',
'Snapshot found: Snapshot 2',
`- url: ${helpers.testSnapshotURL}`,
expect.stringMatching(/clientInfo: @percy\/nightwatch\/.+/),
expect.stringMatching(/environmentInfo: nightwatch\/.+/)
]));

expect(helpers.logger.stdout).toEqual([]);
expect(helpers.logger.stderr).toEqual([]);
browser.assert.ok(true);
},

'handles snapshot failures': async browser => {
await helpers.testFailure('/percy/snapshot', 'failure');

await browser.percySnapshot();
await helpers.test('error', '/percy/snapshot');
await browser.percySnapshot('Snapshot 1');

expect(helpers.logger.stdout).toEqual([]);
expect(helpers.logger.stderr).toEqual([
'[percy] Could not take DOM snapshot "handles snapshot failures"',
'[percy] Error: failure'
]);
expect(await helpers.get('logs')).toEqual(expect.arrayContaining([
'Could not take DOM snapshot "Snapshot 1"'
]));

browser.assert.ok(true);
}
Expand Down
147 changes: 112 additions & 35 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -292,33 +292,96 @@
"@nodelib/fs.scandir" "2.1.3"
fastq "^1.6.0"

"@percy/client@1.7.2":
version "1.7.2"
resolved "https://registry.yarnpkg.com/@percy/client/-/client-1.7.2.tgz#124604c40e3b16c79f0a243a62f1f27d1ab37ab3"
integrity sha512-GjEp3m+WXO2S0iLGwKZs+6zDFkP/V5XJICeou6Q1pOb8N1E3ZhyFfm3+gS2qMwVuf6xIWgxO+RXZxIs2JVJrJw==
"@percy/cli-build@1.9.1":
version "1.9.1"
resolved "https://registry.yarnpkg.com/@percy/cli-build/-/cli-build-1.9.1.tgz#aa2408929bf116a7742c62ebadb3b1e30844fa07"
integrity sha512-BeviHvXOnX74Cntw99hRe0HY2eiqFm9BASkfjSB5AoEdtxLKm0xfYM0WcOIec5XtlztRrQKHA49VVOh2pLWK1Q==
dependencies:
"@percy/env" "1.7.2"
"@percy/logger" "1.7.2"
"@percy/cli-command" "1.9.1"

"@percy/config@1.7.2":
version "1.7.2"
resolved "https://registry.yarnpkg.com/@percy/config/-/config-1.7.2.tgz#c087bd9dd35c81372b03b51360b91fd2cfd58428"
integrity sha512-omING0fj92NG6XVScclkg8l82QUdPw+4YKJjUOHQVqOqyq+7H9A45KtlOk9LVStbVenzRiqH7C+9NhYa+a+/Vg==
"@percy/cli-command@1.9.1":
version "1.9.1"
resolved "https://registry.yarnpkg.com/@percy/cli-command/-/cli-command-1.9.1.tgz#bf492875573fc4fc63a9ebf62b33749f298442e6"
integrity sha512-4vzOUyorU+0KbqpqXTlSfqRBi+XCPDuPRekNwd0HTsgIQB3KQ8Us5cEhk5x2q8/y0jPHqCb5BK/GJBpS8lwO3Q==
dependencies:
"@percy/logger" "1.7.2"
"@percy/config" "1.9.1"
"@percy/core" "1.9.1"
"@percy/logger" "1.9.1"

"@percy/[email protected]":
version "1.9.1"
resolved "https://registry.yarnpkg.com/@percy/cli-config/-/cli-config-1.9.1.tgz#e095bf66bec66db0bced9ee926c30a211936321a"
integrity sha512-R6bimILhdLswXWnIyU+1+X3h6N0xXuwOBcNT8X3GrcTrBFZJpDJ7CNCxj7f6B5Z5uuEFsvdJKN8rRYfVKLRpwg==
dependencies:
"@percy/cli-command" "1.9.1"

"@percy/[email protected]":
version "1.9.1"
resolved "https://registry.yarnpkg.com/@percy/cli-exec/-/cli-exec-1.9.1.tgz#31ff86b372dc44ce163c0f218c8758413c84d89e"
integrity sha512-upWZhJYBvIbQYPhkh0np+RfMYthnhph1FXwaa/Rj4N+RiU/Qb0rFwDf6fz1Je0m1XNPhXu1R/5FnC30W+SsgAg==
dependencies:
"@percy/cli-command" "1.9.1"
cross-spawn "^7.0.3"
which "^2.0.2"

"@percy/[email protected]":
version "1.9.1"
resolved "https://registry.yarnpkg.com/@percy/cli-snapshot/-/cli-snapshot-1.9.1.tgz#b494484b08bbc5927bc7b6a9353c4d59b076be0e"
integrity sha512-cI4oXI6vrDPEuQaU4xx6wmMozyzhUooNBRh+flu52CQcog6K9DuJnkUuu+Uf/guMX2tacp30UfAq/IMaH3AenA==
dependencies:
"@percy/cli-command" "1.9.1"
yaml "^2.0.0"

"@percy/[email protected]":
version "1.9.1"
resolved "https://registry.yarnpkg.com/@percy/cli-upload/-/cli-upload-1.9.1.tgz#f1d97be77cd36574b5a57129be1d3dc1c81bb374"
integrity sha512-g72PepLUU0XgZiYSGcSn8nUxTbEW7NYGgh+uo/J3rnIp5OyH5olpIz/+r3+OXezAAwgyLQTSv+/pYY4ClkvQaQ==
dependencies:
"@percy/cli-command" "1.9.1"
fast-glob "^3.2.11"
image-size "^1.0.0"

"@percy/cli@^1.9.1":
version "1.9.1"
resolved "https://registry.yarnpkg.com/@percy/cli/-/cli-1.9.1.tgz#0df5b6af5dd848ed1c2a57db4f6e2b547583fe3c"
integrity sha512-B62SYu2vHGcR1lkQzP2RHHJRjuEBoWwgeccwBf3mYSzwl4fEB6n1feBRKDx7UNCazRnAzXKrL+g4X7FIesHqnA==
dependencies:
"@percy/cli-build" "1.9.1"
"@percy/cli-command" "1.9.1"
"@percy/cli-config" "1.9.1"
"@percy/cli-exec" "1.9.1"
"@percy/cli-snapshot" "1.9.1"
"@percy/cli-upload" "1.9.1"
"@percy/client" "1.9.1"
"@percy/logger" "1.9.1"

"@percy/[email protected]":
version "1.9.1"
resolved "https://registry.yarnpkg.com/@percy/client/-/client-1.9.1.tgz#b6d7278436942bf241154cd79a123e23c4cdbcba"
integrity sha512-8A2WBoXV+zFT/+P2j8fflPOhv7dX0LNrk6bivgB6E1d6o9xcxEO94KNEIlU4hWkFC2vi+u5fpQXi+OWYQle2wQ==
dependencies:
"@percy/env" "1.9.1"
"@percy/logger" "1.9.1"

"@percy/[email protected]":
version "1.9.1"
resolved "https://registry.yarnpkg.com/@percy/config/-/config-1.9.1.tgz#382d0ff8d7b94da7cbe5ad823c5553b1c9af11a7"
integrity sha512-LY8SBM7ngoLOItr6HOqu0dludsw6G/8dk7U3aMivzUYMZuO05maD7XlTTqfYr8HKUvxG7F6ZXQrRSG0SvwOFVg==
dependencies:
"@percy/logger" "1.9.1"
ajv "^8.6.2"
cosmiconfig "^7.0.0"
yaml "^2.0.0"

"@percy/core@^1.1.3":
version "1.7.2"
resolved "https://registry.yarnpkg.com/@percy/core/-/core-1.7.2.tgz#95551573a623355e47b026645d1258f75cad8acf"
integrity sha512-TsHQbsGtpzEW6bo+BIRkNoIFZrjrWHb9B2pXoMRnG61m6F6KtoL1yOuHhorhrHkCtCtX3A7KXfJtcO9E1oN9RQ==
"@percy/core@1.9.1":
version "1.9.1"
resolved "https://registry.yarnpkg.com/@percy/core/-/core-1.9.1.tgz#ba5a22073cfbf15c20b1964986a8f50b5ee5d024"
integrity sha512-LLqRoqd2AmbcV4CXQBceeaoZlQGSUN5qyfsNRYQ/7c8AmgTbccy5C1N8bpqaeiyqTpJWduXFGg1TI9awgi1UWQ==
dependencies:
"@percy/client" "1.7.2"
"@percy/config" "1.7.2"
"@percy/dom" "1.7.2"
"@percy/logger" "1.7.2"
"@percy/client" "1.9.1"
"@percy/config" "1.9.1"
"@percy/dom" "1.9.1"
"@percy/logger" "1.9.1"
content-disposition "^0.5.4"
cross-spawn "^7.0.3"
extract-zip "^2.0.1"
Expand All @@ -329,25 +392,25 @@
rimraf "^3.0.2"
ws "^8.0.0"

"@percy/dom@1.7.2":
version "1.7.2"
resolved "https://registry.yarnpkg.com/@percy/dom/-/dom-1.7.2.tgz#df12f2d6cd2389a01acd8354fac8496dbbf1e50f"
integrity sha512-ipi7SF4nS+/UfHXYLeJTRp25rGvZhRwmGQv6WjAK1HGkl4OJaFJNPbWe0+SCG4zwSsCudeY4lxk5rk05Ev6b1A==
"@percy/dom@1.9.1":
version "1.9.1"
resolved "https://registry.yarnpkg.com/@percy/dom/-/dom-1.9.1.tgz#0a034be46260d440884e6a3c5d4bda04eeff49af"
integrity sha512-/3q0SkimuCHANbQlnT1pDPQNb01YHtEEYNvkLv4SHFGkbOyGkZb2QEXbPryjZ0ApgLi3nm7TkKR6kNXugprhXw==

"@percy/env@1.7.2":
version "1.7.2"
resolved "https://registry.yarnpkg.com/@percy/env/-/env-1.7.2.tgz#99fd35eeabedcf3762af2efbba177c7bbc57309a"
integrity sha512-exnZsBROCg17bNHqF7CEJVheGVnysZlChSiJHssLcdPGjg2+decefc26UZLA4PuEqgcmYWun5WyGLRPQo62oUQ==
"@percy/env@1.9.1":
version "1.9.1"
resolved "https://registry.yarnpkg.com/@percy/env/-/env-1.9.1.tgz#568bd6b7048fe1fd2cf00de24a423bd807d6fe23"
integrity sha512-8zkZrNDBuPFUA6gSi7rYeK+TMuXTgH6bQCQYPlQJuIrSXA4CbLWaL8S3qX69hk91F9DB4glhIgR9N4RWO+R5EQ==

"@percy/logger@1.7.2":
version "1.7.2"
resolved "https://registry.yarnpkg.com/@percy/logger/-/logger-1.7.2.tgz#38b008459f5598d3a8f8708dc68a246473aac8a8"
integrity sha512-GSbOqPpjM+UC/0pcm6oTi+KI4u/nbs8Awz0HtFcoxyaNRBptRFUh75zF7qI0zB/HRp8QlZ0z4DayCepfrqqO0A==
"@percy/logger@1.9.1":
version "1.9.1"
resolved "https://registry.yarnpkg.com/@percy/logger/-/logger-1.9.1.tgz#d5a4f30ca60d56eb2b1700fb56fd8e4e55dfbbfa"
integrity sha512-WOtU8eX/fsgz49Hh6N8hSpy95WJV209G9yGFVaZXWIbKJ90FWrONksX/Kz8FxQ0q/7oIW36zXy0ibr2qRy095g==

"@percy/sdk-utils@^1.0.0":
version "1.8.0"
resolved "https://registry.yarnpkg.com/@percy/sdk-utils/-/sdk-utils-1.8.0.tgz#8db2aefbb211747f8f622db6daf25b781464a308"
integrity sha512-ehyYs7L4MDmqjBAfTHA8wDGrsDHiPrJ5SwMA9g9tT06VUey1JJtjSK30VidoouZQm+Sus9r5lW/K73CQZc3lSg==
version "1.9.1"
resolved "https://registry.yarnpkg.com/@percy/sdk-utils/-/sdk-utils-1.9.1.tgz#daa5d2cb9a2dfb306c094c3b6e1ae3891846f5e4"
integrity sha512-/9k1XDYj3xl9xI/cQM1uItIcC8HWpm12sYVAZRMKdddCPc3SAQN93sgVZXF3L4uGgaNiTD1+AtkzuUVSccUpPQ==

"@sindresorhus/is@^4.0.0":
version "4.0.1"
Expand Down Expand Up @@ -1838,6 +1901,13 @@ ignore@^5.1.1, ignore@^5.1.4:
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.1.8.tgz#f150a8b50a34289b33e22f5889abd4d8016f0e57"
integrity sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw==

image-size@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/image-size/-/image-size-1.0.2.tgz#d778b6d0ab75b2737c1556dd631652eb963bc486"
integrity sha512-xfOoWjceHntRb3qFCrh5ZFORYH8XCdYpASltMhZ/Q0KZiOwjdE/Yl2QCiWdwD+lygV5bMCvauzgu5PxBX/Yerg==
dependencies:
queue "6.0.2"

immediate@~3.0.5:
version "3.0.6"
resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.0.6.tgz#9db1dbd0faf8de6fbe0f5dd5e56bb606280de69b"
Expand Down Expand Up @@ -3043,6 +3113,13 @@ punycode@^2.1.0:
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"
integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==

[email protected]:
version "6.0.2"
resolved "https://registry.yarnpkg.com/queue/-/queue-6.0.2.tgz#b91525283e2315c7553d2efa18d83e76432fed65"
integrity sha512-iHZWu+q3IdFZFX36ro/lKBkSvfkztY5Y7HMiPlOUjhupPcG2JMfst2KKEpu5XndviX/3UhFbRngUPNKtgvtZiA==
dependencies:
inherits "~2.0.3"

quick-lru@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-4.0.1.tgz#5b8878f113a58217848c6482026c73e1ba57727f"
Expand Down Expand Up @@ -3671,7 +3748,7 @@ which-module@^2.0.0:
resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a"
integrity sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=

[email protected], which@^2.0.1:
[email protected], which@^2.0.1, which@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1"
integrity sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==
Expand Down