major: call .register() on the module, close #7

This commit is contained in:
Gleb Bahmutov 2017-12-13 16:00:57 -05:00
parent d3d1bc3c54
commit fe03042087
4 changed files with 16 additions and 10 deletions

View file

@ -20,7 +20,7 @@ npm install --save-dev @cypress/snapshot
After installing, add the following to your `cypress/support/commands.js` file After installing, add the following to your `cypress/support/commands.js` file
```js ```js
require('@cypress/snapshot')() require('@cypress/snapshot').register()
``` ```
This registers a new command to create new snapshot or compare value to old snapshot This registers a new command to create new snapshot or compare value to old snapshot

View file

@ -1,2 +1,2 @@
// register .snapshot() command // register .snapshot() command
require('../..')() require('../..').register()

View file

@ -59,8 +59,7 @@ function registerCypressSnapshot () {
storeSnapshot = initStore(store) storeSnapshot = initStore(store)
} }
global.before(() => { global.before(function loadSnapshots () {
cy.log('before all tests')
cy cy
.readFile(SNAPSHOT_FILENAME, 'utf-8', { log: false }) .readFile(SNAPSHOT_FILENAME, 'utf-8', { log: false })
.then(evaluateLoadedSnapShots) .then(evaluateLoadedSnapShots)
@ -154,9 +153,8 @@ function registerCypressSnapshot () {
Cypress.Commands.add('snapshot', { prevSubject: true }, snapshot) Cypress.Commands.add('snapshot', { prevSubject: true }, snapshot)
global.after(() => { global.after(function saveSnapshots () {
if (storeSnapshot) { if (storeSnapshot) {
cy.log('saving snapshots')
const snapshots = storeSnapshot() const snapshots = storeSnapshot()
console.log('%d snapshot(s) on finish', countSnapshots(snapshots)) console.log('%d snapshot(s) on finish', countSnapshots(snapshots))
console.log(snapshots) console.log(snapshots)
@ -167,6 +165,10 @@ function registerCypressSnapshot () {
cy.writeFile(SNAPSHOT_FILENAME, str, 'utf-8', { log: false }) cy.writeFile(SNAPSHOT_FILENAME, str, 'utf-8', { log: false })
} }
}) })
return snapshot
} }
module.exports = registerCypressSnapshot module.exports = {
register: registerCypressSnapshot
}

View file

@ -1,12 +1,16 @@
'use strict' 'use strict'
/* eslint-env mocha */ /* eslint-env mocha */
const snapshot = require('.') const api = require('.')
const la = require('lazy-ass') const la = require('lazy-ass')
const is = require('check-more-types') const is = require('check-more-types')
describe('@cypress/snapshot', () => { describe('@cypress/snapshot', () => {
it('is a function', () => { it('is an object', () => {
la(is.fn(snapshot)) la(is.object(api))
})
it('has register', () => {
la(is.fn(api.register))
}) })
}) })