Skip to content
This repository has been archived by the owner on Apr 28, 2023. It is now read-only.

Commit

Permalink
major: call .register() on the module, close #7
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Dec 13, 2017
1 parent d3d1bc3 commit fe03042
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cypress/support/commands.js
@@ -1,2 +1,2 @@
// register .snapshot() command
require('../..')()
require('../..').register()
12 changes: 7 additions & 5 deletions src/index.js
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -167,6 +165,10 @@ function registerCypressSnapshot () {
cy.writeFile(SNAPSHOT_FILENAME, str, 'utf-8', { log: false })
}
})

return snapshot
}

module.exports = registerCypressSnapshot
module.exports = {
register: registerCypressSnapshot
}
10 changes: 7 additions & 3 deletions 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))
})
})

0 comments on commit fe03042

Please sign in to comment.