Skip to content

Commit 802d5dc

Browse files
committed
fix(test): update karma jasmine test to properly fail tests if verification fails.
* Allow 'singleRun: false' by clearing interactions between tests * Config file to test Chrome
1 parent 98a6380 commit 802d5dc

2 files changed

Lines changed: 104 additions & 4 deletions

File tree

karma/jasmine/client-spec.js

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88
beforeAll(function(done) {
99
client = example.createClient('http://localhost:1234')
1010
provider = Pact({ consumer: 'Karma Jasmine', provider: 'Hello' })
11+
1112
// required for slower Travis CI environment
1213
setTimeout(function () { done() }, 2000)
14+
15+
// Required if run with `singleRun: false`
16+
provider.removeInteractions()
1317
})
1418

1519
afterAll(function (done) {
@@ -47,7 +51,14 @@
4751
})
4852

4953
// verify with Pact, and reset expectations
50-
it('successfully verifies', function() { provider.verify() })
54+
it('successfully verifies', function(done) {
55+
provider.verify()
56+
.then(function(a) {
57+
done()
58+
}, function(e) {
59+
done.fail(e)
60+
})
61+
})
5162
})
5263

5364
describe("findFriendsByAgeAndChildren", function () {
@@ -91,7 +102,15 @@
91102
})
92103

93104
// verify with Pact, and reset expectations
94-
it('successfully verifies', function() { provider.verify() })
105+
// verify with Pact, and reset expectations
106+
it('successfully verifies', function(done) {
107+
provider.verify()
108+
.then(function(a) {
109+
done()
110+
}, function(e) {
111+
done.fail(e)
112+
})
113+
})
95114
})
96115

97116
describe("unfriendMe", function () {
@@ -132,7 +151,15 @@
132151
})
133152
})
134153

135-
it('successfully verifies', function() { provider.verify() })
154+
// verify with Pact, and reset expectations
155+
it('successfully verifies', function(done) {
156+
provider.verify()
157+
.then(function(a) {
158+
done()
159+
}, function(e) {
160+
done.fail(e)
161+
})
162+
})
136163
})
137164

138165
// verify with Pact, and reset expectations
@@ -167,7 +194,15 @@
167194
})
168195

169196
// verify with Pact, and reset expectations
170-
it('successfully verifies', function() { provider.verify() })
197+
// verify with Pact, and reset expectations
198+
it('successfully verifies', function(done) {
199+
provider.verify()
200+
.then(function(a) {
201+
done()
202+
}, function(e) {
203+
done.fail(e)
204+
})
205+
})
171206
})
172207
})
173208

karma/jasmine/karma.chrome.conf.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Karma configuration
2+
// Generated on Thu Nov 20 2014 14:51:15 GMT+1100 (AEDT)
3+
4+
module.exports = function (config) {
5+
config.set({
6+
7+
// base path that will be used to resolve all patterns (eg. files, exclude)
8+
basePath: '.',
9+
10+
// frameworks to use
11+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
12+
frameworks: ['jasmine', 'pact'],
13+
14+
// list of files / patterns to load in the browser
15+
files: [
16+
'../../dist/pact.web.js',
17+
'client.js',
18+
'client-spec.js'
19+
],
20+
21+
// list of files to exclude
22+
exclude: [],
23+
24+
// preprocess matching files before serving them to the browser
25+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
26+
preprocessors: {},
27+
28+
// test results reporter to use
29+
// possible values: 'dots', 'progress'
30+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
31+
reporters: ['progress'],
32+
33+
// web server port
34+
port: 9876,
35+
36+
// enable / disable colors in the output (reporters and logs)
37+
colors: true,
38+
39+
// level of logging
40+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
41+
logLevel: config.LOG_DEBUG,
42+
43+
// enable / disable watching file and executing tests whenever any file changes
44+
autoWatch: true,
45+
46+
// start these browsers
47+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
48+
browsers: ['Chrome_without_security'],
49+
50+
customLaunchers: {
51+
Chrome_without_security: {
52+
base: 'Chrome',
53+
flags: ['--disable-web-security']
54+
},
55+
PhantomJS_without_security: {
56+
base: 'PhantomJS',
57+
flags: ['--web-security=no']
58+
}
59+
},
60+
61+
// Continuous Integration mode
62+
// if true, Karma captures browsers, runs the tests and exits
63+
singleRun: false
64+
})
65+
}

0 commit comments

Comments
 (0)