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
```js
require('@cypress/snapshot')()
require('@cypress/snapshot').register()
```
This registers a new command to create new snapshot or compare value to old snapshot

View file

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

View file

@ -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
}

View file

@ -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))
})
})