From fe030420877d905162e235440c85dd75722dcbb8 Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Wed, 13 Dec 2017 16:00:57 -0500 Subject: [PATCH] major: call .register() on the module, close #7 --- README.md | 2 +- cypress/support/commands.js | 2 +- src/index.js | 12 +++++++----- src/snapshot-spec.js | 10 +++++++--- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 953ccce..007b7fb 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ npm install --save-dev @cypress/snapshot After installing, add the following to your `cypress/support/commands.js` file ```js -require('@cypress/snapshot')() +require('@cypress/snapshot').register() ``` This registers a new command to create new snapshot or compare value to old snapshot diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 97ae1ec..3e68689 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -1,2 +1,2 @@ // register .snapshot() command -require('../..')() +require('../..').register() diff --git a/src/index.js b/src/index.js index 4c1e9d7..de70c4a 100644 --- a/src/index.js +++ b/src/index.js @@ -59,8 +59,7 @@ function registerCypressSnapshot () { storeSnapshot = initStore(store) } - global.before(() => { - cy.log('before all tests') + global.before(function loadSnapshots () { cy .readFile(SNAPSHOT_FILENAME, 'utf-8', { log: false }) .then(evaluateLoadedSnapShots) @@ -154,9 +153,8 @@ function registerCypressSnapshot () { Cypress.Commands.add('snapshot', { prevSubject: true }, snapshot) - global.after(() => { + global.after(function saveSnapshots () { if (storeSnapshot) { - cy.log('saving snapshots') const snapshots = storeSnapshot() console.log('%d snapshot(s) on finish', countSnapshots(snapshots)) console.log(snapshots) @@ -167,6 +165,10 @@ function registerCypressSnapshot () { cy.writeFile(SNAPSHOT_FILENAME, str, 'utf-8', { log: false }) } }) + + return snapshot } -module.exports = registerCypressSnapshot +module.exports = { + register: registerCypressSnapshot +} diff --git a/src/snapshot-spec.js b/src/snapshot-spec.js index d0aa2ed..f89fc3c 100644 --- a/src/snapshot-spec.js +++ b/src/snapshot-spec.js @@ -1,12 +1,16 @@ 'use strict' /* eslint-env mocha */ -const snapshot = require('.') +const api = require('.') const la = require('lazy-ass') const is = require('check-more-types') describe('@cypress/snapshot', () => { - it('is a function', () => { - la(is.fn(snapshot)) + it('is an object', () => { + la(is.object(api)) + }) + + it('has register', () => { + la(is.fn(api.register)) }) })