From a48b6fa0905bc71a74951d7d09370f673565368d Mon Sep 17 00:00:00 2001 From: Mark Murray Date: Wed, 6 Mar 2019 18:04:07 +0000 Subject: [PATCH 1/7] README --- README.md | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ce9fc0a..5d9ade3 100644 --- a/README.md +++ b/README.md @@ -1 +1,90 @@ -# jest-component-snapshot \ No newline at end of file +# Jest Component Snapshot + +[![Travis](https://img.shields.io/travis/mmmurray/jest-component-snapshot.svg)](https://travis-ci.org/mmmurray/jest-component-snapshot) +[![npm](https://img.shields.io/npm/v/jest-component-snapshot.svg)](https://www.npmjs.com/package/jest-component-snapshot) +[![MIT License][license-badge]][license] + +Component snapshot testing made easy. + +## Install + +```bash +yarn add -D jest-component-snapshot puppeteer +``` + +## Usage + +Update your Jest config to automatically setup and teardown Puppeteer: + +```json +{ + "globalSetup": "jest-component-snapshot/setup", + "globalTeardown": "jest-component-snapshot/teardown", + "setupFilesAfterEnv": ["jest-component-snapshot/extend-expect"] +} +``` + +### Image snapshot tests + +Image snapshot tests use [jest-image-snapshot](https://www.npmjs.com/package/jest-image-snapshot) but you provide a component instead of an image. All of the same options should work here. + +```js +test('Image snapshot from HTML string', () => { + expect('

Hello world

').toMatchImageSnapshot() +}) + +test('Image snapshot from DOM element', () => { + const headingElement = document.createElement('h1') + headingElement.innerHtml = 'Hello world' + expect(headingElement).toMatchImageSnapshot() +}) + +test('Image snapshot from React element', () => { + expect(

Hello world

).toMatchImageSnapshot() +}) +``` + +### A11y snapshot tests + +Uses Puppeteer to create an [accessibility tree snapshot](https://pptr.dev/#?product=Puppeteer&show=api-class-accessibility). The snapshot is converted to YAML for readability and empty properties and generic containers are removed. + +```js +test('A11y snapshot from HTML string', () => { + expect('

Hello world

').toMatchA11ySnapshot() +}) + +test('A11y snapshot from DOM element', () => { + const headingElement = document.createElement('h1') + headingElement.innerHtml = 'Hello world' + expect(headingElement).toMatchA11ySnapshot() +}) + +test('A11y snapshot from React element', () => { + expect(

Hello world

).toMatchA11ySnapshot() +}) +``` + +### DOM snapshot tests + +Snapshots formatted HTML for the given component. + +```js +test('DOM snapshot from HTML string', () => { + expect('

Hello world

').toMatchDomSnapshot() +}) + +test('DOM snapshot from DOM element', () => { + const headingElement = document.createElement('h1') + headingElement.innerHtml = 'Hello world' + expect(headingElement).toMatchDomSnapshot() +}) + +test('DOM snapshot from React element', () => { + expect(

Hello world

).toMatchDomSnapshot() +}) +``` + +## Alternatives + +- [jest-puppeteer](https://github.com/smooth-code/jest-puppeteer) +- [jest-image-snapshot](https://www.npmjs.com/package/jest-image-snapshot) From 24620a06059fbfb31b6d8f3fb5eff1adf407f0e4 Mon Sep 17 00:00:00 2001 From: Mark Murray Date: Wed, 6 Mar 2019 18:05:26 +0000 Subject: [PATCH 2/7] fix license badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5d9ade3..65f5f9e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Travis](https://img.shields.io/travis/mmmurray/jest-component-snapshot.svg)](https://travis-ci.org/mmmurray/jest-component-snapshot) [![npm](https://img.shields.io/npm/v/jest-component-snapshot.svg)](https://www.npmjs.com/package/jest-component-snapshot) -[![MIT License][license-badge]][license] +[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) Component snapshot testing made easy. From de7165626c0ad70ef07171e46cfd647395a32ec1 Mon Sep 17 00:00:00 2001 From: Mark Murray Date: Wed, 6 Mar 2019 18:06:41 +0000 Subject: [PATCH 3/7] update README --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 65f5f9e..38fdc29 100644 --- a/README.md +++ b/README.md @@ -29,17 +29,17 @@ Update your Jest config to automatically setup and teardown Puppeteer: Image snapshot tests use [jest-image-snapshot](https://www.npmjs.com/package/jest-image-snapshot) but you provide a component instead of an image. All of the same options should work here. ```js -test('Image snapshot from HTML string', () => { +test('image snapshot from HTML string', () => { expect('

Hello world

').toMatchImageSnapshot() }) -test('Image snapshot from DOM element', () => { +test('image snapshot from DOM element', () => { const headingElement = document.createElement('h1') headingElement.innerHtml = 'Hello world' expect(headingElement).toMatchImageSnapshot() }) -test('Image snapshot from React element', () => { +test('image snapshot from React element', () => { expect(

Hello world

).toMatchImageSnapshot() }) ``` @@ -49,17 +49,17 @@ test('Image snapshot from React element', () => { Uses Puppeteer to create an [accessibility tree snapshot](https://pptr.dev/#?product=Puppeteer&show=api-class-accessibility). The snapshot is converted to YAML for readability and empty properties and generic containers are removed. ```js -test('A11y snapshot from HTML string', () => { +test('a11y snapshot from HTML string', () => { expect('

Hello world

').toMatchA11ySnapshot() }) -test('A11y snapshot from DOM element', () => { +test('a11y snapshot from DOM element', () => { const headingElement = document.createElement('h1') headingElement.innerHtml = 'Hello world' expect(headingElement).toMatchA11ySnapshot() }) -test('A11y snapshot from React element', () => { +test('a11y snapshot from React element', () => { expect(

Hello world

).toMatchA11ySnapshot() }) ``` From 87d778511642240afd84751d3e0b24316a4a456b Mon Sep 17 00:00:00 2001 From: Mark Murray Date: Wed, 6 Mar 2019 18:09:32 +0000 Subject: [PATCH 4/7] update keywords --- package.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package.json b/package.json index 0cdaf77..036e1c8 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,8 @@ "jest", "component", "snapshot", + "snapshot-testing", + "jest-snapshots", "react", "dom", "a11y", From 26c4cc029d3ca15014c99c1b16a6b895505caa55 Mon Sep 17 00:00:00 2001 From: Mark Murray Date: Wed, 6 Mar 2019 18:09:38 +0000 Subject: [PATCH 5/7] update README --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 38fdc29..6f4f1e8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Jest Component Snapshot +# jest-component-snapshot [![Travis](https://img.shields.io/travis/mmmurray/jest-component-snapshot.svg)](https://travis-ci.org/mmmurray/jest-component-snapshot) [![npm](https://img.shields.io/npm/v/jest-component-snapshot.svg)](https://www.npmjs.com/package/jest-component-snapshot) @@ -26,7 +26,7 @@ Update your Jest config to automatically setup and teardown Puppeteer: ### Image snapshot tests -Image snapshot tests use [jest-image-snapshot](https://www.npmjs.com/package/jest-image-snapshot) but you provide a component instead of an image. All of the same options should work here. +Creates an image snapshot from a component using [jest-image-snapshot](https://www.npmjs.com/package/jest-image-snapshot). All of the same options are supported. ```js test('image snapshot from HTML string', () => { @@ -36,6 +36,7 @@ test('image snapshot from HTML string', () => { test('image snapshot from DOM element', () => { const headingElement = document.createElement('h1') headingElement.innerHtml = 'Hello world' + expect(headingElement).toMatchImageSnapshot() }) @@ -56,6 +57,7 @@ test('a11y snapshot from HTML string', () => { test('a11y snapshot from DOM element', () => { const headingElement = document.createElement('h1') headingElement.innerHtml = 'Hello world' + expect(headingElement).toMatchA11ySnapshot() }) @@ -76,6 +78,7 @@ test('DOM snapshot from HTML string', () => { test('DOM snapshot from DOM element', () => { const headingElement = document.createElement('h1') headingElement.innerHtml = 'Hello world' + expect(headingElement).toMatchDomSnapshot() }) From f4f5bd31d1faa185316cb98d06e21400b48028c6 Mon Sep 17 00:00:00 2001 From: Mark Murray Date: Wed, 6 Mar 2019 18:11:27 +0000 Subject: [PATCH 6/7] update README --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6f4f1e8..7543b00 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# jest-component-snapshot +# jest-component-snapshot 📸 [![Travis](https://img.shields.io/travis/mmmurray/jest-component-snapshot.svg)](https://travis-ci.org/mmmurray/jest-component-snapshot) [![npm](https://img.shields.io/npm/v/jest-component-snapshot.svg)](https://www.npmjs.com/package/jest-component-snapshot) @@ -6,13 +6,13 @@ Component snapshot testing made easy. -## Install +## Install ⚙️ ```bash yarn add -D jest-component-snapshot puppeteer ``` -## Usage +## Usage 🤖 Update your Jest config to automatically setup and teardown Puppeteer: @@ -87,7 +87,7 @@ test('DOM snapshot from React element', () => { }) ``` -## Alternatives +## Alternatives 🙌 - [jest-puppeteer](https://github.com/smooth-code/jest-puppeteer) - [jest-image-snapshot](https://www.npmjs.com/package/jest-image-snapshot) From 4555c7dc08a4fe549c38192166e1eb653b80192a Mon Sep 17 00:00:00 2001 From: Mark Murray Date: Wed, 6 Mar 2019 18:16:45 +0000 Subject: [PATCH 7/7] update description --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 036e1c8..5c341b1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "jest-component-snapshot", "version": "0.1.0", - "description": "Component snapshot matchers", + "description": "Component snapshot testing made easy.", "author": "Mark Murray", "license": "MIT", "repository": "git@github.com:mmmurray/jest-component-snapshot.git",