Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -881,9 +881,19 @@ exports.cookies.clear = function(name, done) {
*/

exports.cookies.clearAll = function(done) {
debug('cookies.clearAll()')
this.child.call('cookie.clearAll', done)
}

/**
* Flush cookies
*/

exports.cookies.flush = function(done) {
debug('cookies.flush()')
this.child.call('cookie.flush', done)
}

/**
* Authentication
*/
Expand Down
11 changes: 11 additions & 0 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,17 @@ app.on('ready', function() {
)
})

/**
* Flush cookies
*/

parent.respondTo('cookie.flush', function(done) {
win.webContents.session.cookies.flushStore(function(err) {
if (err) return done(err)
return done()
})
})

/**
* Add custom functionality
*/
Expand Down
37 changes: 37 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,43 @@ describe('Nightmare', function() {
cookies.length.should.equal(0)
})

it('cookies.flush() should flush cookies to dist', function*() {
nightmare = Nightmare({
webPreferences: { partition: 'persist:test-partition' }
})

yield nightmare.goto(fixture('cookie'))

// set expirationDate to make a non-session cookie
var expiration = new Date()
expiration.setHours(expiration.getHours() + 6)

yield nightmare.cookies.set({
name: 'flushedcookie',
value: 'hello',
path: '/',
expirationDate: expiration.getTime()
})

var cookies = yield nightmare.cookies.get()
cookies.length.should.equal(1)

yield nightmare.cookies.flush()

yield nightmare.end()

nightmare = Nightmare({
webPreferences: { partition: 'persist:test-partition' }
})

yield nightmare.goto(fixture('cookie'))

cookies = yield nightmare.cookies.get({ url: null })
cookies.length.should.equal(1)

yield nightmare.cookies.clearAll()
})

it('should return a proper error', function*() {
try {
yield nightmare.goto(fixture('cookie')).cookies.set({
Expand Down