Skip to content

Commit

Permalink
fix(test): update karma jasmine test to properly fail tests if verifi…
Browse files Browse the repository at this point in the history
…cation fails.

* Allow 'singleRun: false' by clearing interactions between tests
* Config file to test Chrome
  • Loading branch information
mefellows committed Mar 2, 2017
1 parent 98a6380 commit 802d5dc
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 4 deletions.
43 changes: 39 additions & 4 deletions karma/jasmine/client-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
beforeAll(function(done) {
client = example.createClient('http://localhost:1234')
provider = Pact({ consumer: 'Karma Jasmine', provider: 'Hello' })

// required for slower Travis CI environment
setTimeout(function () { done() }, 2000)

// Required if run with `singleRun: false`
provider.removeInteractions()
})

afterAll(function (done) {
Expand Down Expand Up @@ -47,7 +51,14 @@
})

// verify with Pact, and reset expectations
it('successfully verifies', function() { provider.verify() })
it('successfully verifies', function(done) {
provider.verify()
.then(function(a) {
done()
}, function(e) {
done.fail(e)
})
})
})

describe("findFriendsByAgeAndChildren", function () {
Expand Down Expand Up @@ -91,7 +102,15 @@
})

// verify with Pact, and reset expectations
it('successfully verifies', function() { provider.verify() })
// verify with Pact, and reset expectations
it('successfully verifies', function(done) {
provider.verify()
.then(function(a) {
done()
}, function(e) {
done.fail(e)
})
})
})

describe("unfriendMe", function () {
Expand Down Expand Up @@ -132,7 +151,15 @@
})
})

it('successfully verifies', function() { provider.verify() })
// verify with Pact, and reset expectations
it('successfully verifies', function(done) {
provider.verify()
.then(function(a) {
done()
}, function(e) {
done.fail(e)
})
})
})

// verify with Pact, and reset expectations
Expand Down Expand Up @@ -167,7 +194,15 @@
})

// verify with Pact, and reset expectations
it('successfully verifies', function() { provider.verify() })
// verify with Pact, and reset expectations
it('successfully verifies', function(done) {
provider.verify()
.then(function(a) {
done()
}, function(e) {
done.fail(e)
})
})
})
})

Expand Down
65 changes: 65 additions & 0 deletions karma/jasmine/karma.chrome.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Karma configuration
// Generated on Thu Nov 20 2014 14:51:15 GMT+1100 (AEDT)

module.exports = function (config) {
config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '.',

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine', 'pact'],

// list of files / patterns to load in the browser
files: [
'../../dist/pact.web.js',
'client.js',
'client-spec.js'
],

// list of files to exclude
exclude: [],

// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {},

// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],

// web server port
port: 9876,

// enable / disable colors in the output (reporters and logs)
colors: true,

// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_DEBUG,

// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,

// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome_without_security'],

customLaunchers: {
Chrome_without_security: {
base: 'Chrome',
flags: ['--disable-web-security']
},
PhantomJS_without_security: {
base: 'PhantomJS',
flags: ['--web-security=no']
}
},

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
})
}

0 comments on commit 802d5dc

Please sign in to comment.