diff --git a/karma/jasmine/client-spec.js b/karma/jasmine/client-spec.js index c1f57cd06..eba1b2690 100644 --- a/karma/jasmine/client-spec.js +++ b/karma/jasmine/client-spec.js @@ -5,14 +5,16 @@ var client, projectsProvider; - // ugly but works... guess would be good to bring jasmine-beforeAll - beforeEach(function() { - client = example.createClient('http://localhost:1234'); + beforeAll(function(done) { + client = example.createClient('http://localhost:1234') projectsProvider = Pact({ consumer: 'Karma Jasmine', provider: 'Hello' }) + // required for slower Travis CI environment + setTimeout(function () { done() }, 2000) }); - afterEach(function (done) { - projectsProvider.finalize().then(function () { done() }) + afterAll(function (done) { + projectsProvider.finalize() + .then(function () { done() }, function (err) { done.fail(err) }) }); describe("sayHello", function () { @@ -28,7 +30,8 @@ headers: { "Content-Type": "application/json" }, body: { reply: "Hello" } } - }).then(function () { done() }); + }) + .then(function () { done() }, function (err) { done.fail(err) }) }) it("should say hello", function(done) { @@ -40,7 +43,7 @@ done() }) .catch(function (err) { - done(err) + done.fail(err) }) }); }); @@ -70,7 +73,8 @@ }, { min: 1 }) } } - }).then(function () { done() }); + }) + .then(function () { done() }, function (err) { done.fail(err) }) }) it("should return some friends", function(done) { @@ -82,7 +86,7 @@ done() }) .catch(function (err) { - done(err) + done.fail(err) }) }); }); @@ -103,7 +107,8 @@ headers: { "Content-Type": "application/json" }, body: { reply: "Bye" } } - }).then(function () { done() }); + }) + .then(function () { done() }, function (err) { done.fail(err) }) }) it("should unfriend me", function(done) { @@ -115,7 +120,7 @@ done() }) .catch(function (err) { - done(err) + done.fail(err) }) }); @@ -131,7 +136,8 @@ willRespondWith: { status: 404 } - }).then(function () { done() }) + }) + .then(function () { done() }, function (err) { done.fail(err) }) }) it("returns an error message", function (done) { diff --git a/karma/jasmine/client.js b/karma/jasmine/client.js index 0e3368b5c..51baeb2d2 100644 --- a/karma/jasmine/client.js +++ b/karma/jasmine/client.js @@ -11,7 +11,6 @@ var example = example || {}; }; this.sayHello = function() { - debugger //Makes a synchronous request var xhr = new XMLHttpRequest(); xhr.open('GET', localBaseUrl + '/sayHello', false); diff --git a/karma/jasmine/karma.conf.js b/karma/jasmine/karma.conf.js index d993b6ee0..80e66956a 100644 --- a/karma/jasmine/karma.conf.js +++ b/karma/jasmine/karma.conf.js @@ -11,14 +11,8 @@ module.exports = function (config) { // available frameworks: https://npmjs.org/browse/keyword/karma-adapter frameworks: ['jasmine', 'pact'], - // pact config - pact: {}, - // list of files / patterns to load in the browser files: [ - // if you are using this example to setup your own project load pact from the node_modules directory - // i.e. node_modules/pact-consumer-js-dsl/dist/pact-consumer-js-dsl.js - './node_modules/es6-promise/dist/es6-promise.js', '../../dist/pact.web.js', 'client.js', 'client-spec.js' @@ -56,7 +50,7 @@ module.exports = function (config) { customLaunchers: { PhantomJS_without_security: { base: 'PhantomJS', - flags: ['--web-security=false'] + flags: ['--web-security=no'] } }, diff --git a/karma/mocha/client-spec.js b/karma/mocha/client-spec.js index 35d6a3552..faa6c0597 100644 --- a/karma/mocha/client-spec.js +++ b/karma/mocha/client-spec.js @@ -5,11 +5,17 @@ var client, projectsProvider; - // ugly but works... guess would be good to bring jasmine-beforeAll - beforeEach(function() { + before(function(done) { client = example.createClient('http://localhost:1234'); projectsProvider = Pact({ consumer: 'Karma Mocha', provider: 'Hello' }) - }); + // required for slower Travis CI environment + setTimeout(function () { done() }, 1000) + }) + + after(function (done) { + projectsProvider.finalize() + .then(function () { done() }, function (err) { done(err) }) + }) describe("sayHello", function () { beforeEach(function (done) { @@ -24,11 +30,8 @@ headers: { "Content-Type": "application/json" }, body: { reply: "Hello" } } - }).then(function () { done() }) - }) - - afterEach(function (done) { - projectsProvider.finalize().then(function () { done() }) + }) + .then(function () { done() }, function (err) { done(err) }) }) it("should say hello", function(done) { @@ -69,13 +72,10 @@ }, { min: 1 }) } } - }).then(function () { done() }) + }) + .then(function () { done() }, function (err) { done(err) }) }) - afterEach(function (done) { - projectsProvider.finalize().then(function () { done() }) - }); - it("should return some friends", function(done) { //Run the tests client.findFriendsByAgeAndChildren('33', ['Mary Jane', 'James']) @@ -106,13 +106,10 @@ headers: { "Content-Type": "application/json" }, body: { reply: "Bye" } } - }).then(function () { done() }) + }) + .then(function () { done() }, function (err) { done(err) }) }) - afterEach(function (done) { - projectsProvider.finalize().then(function () { done() }) - }); - it("should unfriend me", function(done) { //Run the tests client.unfriendMe() @@ -139,7 +136,8 @@ willRespondWith: { status: 404 } - }).then(function () { done() }) + }) + .then(function () { done() }, function (err) { done(err) }) }) it("returns an error message", function (done) { diff --git a/karma/mocha/karma.conf.js b/karma/mocha/karma.conf.js index 031f0259a..0d5808e38 100644 --- a/karma/mocha/karma.conf.js +++ b/karma/mocha/karma.conf.js @@ -11,13 +11,9 @@ module.exports = function (config) { // available frameworks: https://npmjs.org/browse/keyword/karma-adapter frameworks: ['mocha', 'chai', 'pact'], - // pact config - pact: {}, - // list of files / patterns to load in the browser files: [ // if you are using this example to setup your own project load pact from the node_modules directory - // i.e. node_modules/pact-consumer-js-dsl/dist/pact-consumer-js-dsl.js '../../dist/pact.web.js', 'client.js', 'client-spec.js' @@ -55,7 +51,7 @@ module.exports = function (config) { customLaunchers: { PhantomJS_without_security: { base: 'PhantomJS', - flags: ['--web-security=false'] + flags: ['--web-security=no'] } }, diff --git a/package.json b/package.json index bc314b47e..a569830d4 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "postdist": "npm t", "test": "./node_modules/.bin/babel-node ./node_modules/.bin/isparta cover ./node_modules/.bin/_mocha -- ./test", "test:karma:jasmine": "./node_modules/.bin/karma start ./karma/jasmine/karma.conf.js", - "test:karma:mocha": "./node_modules/.bin/karma start ./karma/mocha/karma.conf.js" + "test:karma:mocha": "./node_modules/.bin/karma start ./karma/mocha/karma.conf.js", + "posttest": "npm run test:karma:jasmine && npm run test:karma:mocha" }, "repository": { "type": "git", @@ -105,10 +106,9 @@ "json-loader": "0.5.4", "karma": "1.1.0", "karma-chai": "0.1.0", - "karma-chrome-launcher": "1.0.1", "karma-jasmine": "1.0.2", "karma-mocha": "1.1.1", - "karma-pact": "0.0.3", + "karma-pact": "0.0.5", "karma-phantomjs-launcher": "1.0.1", "mocha": "2.5.3", "nock": "8.0.0",