Skip to content

Commit

Permalink
integrate Karma tests as part of the build
Browse files Browse the repository at this point in the history
  • Loading branch information
tarciosaraiva committed Jul 9, 2016
1 parent 1ebba0f commit a60d1d3
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 47 deletions.
30 changes: 18 additions & 12 deletions karma/jasmine/client-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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) {
Expand All @@ -40,7 +43,7 @@
done()
})
.catch(function (err) {
done(err)
done.fail(err)
})
});
});
Expand Down Expand Up @@ -70,7 +73,8 @@
}, { min: 1 })
}
}
}).then(function () { done() });
})
.then(function () { done() }, function (err) { done.fail(err) })
})

it("should return some friends", function(done) {
Expand All @@ -82,7 +86,7 @@
done()
})
.catch(function (err) {
done(err)
done.fail(err)
})
});
});
Expand All @@ -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) {
Expand All @@ -115,7 +120,7 @@
done()
})
.catch(function (err) {
done(err)
done.fail(err)
})
});

Expand All @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion karma/jasmine/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 1 addition & 7 deletions karma/jasmine/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -56,7 +50,7 @@ module.exports = function (config) {
customLaunchers: {
PhantomJS_without_security: {
base: 'PhantomJS',
flags: ['--web-security=false']
flags: ['--web-security=no']
}
},

Expand Down
36 changes: 17 additions & 19 deletions karma/mocha/client-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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'])
Expand Down Expand Up @@ -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()
Expand All @@ -139,7 +136,8 @@
willRespondWith: {
status: 404
}
}).then(function () { done() })
})
.then(function () { done() }, function (err) { done(err) })
})

it("returns an error message", function (done) {
Expand Down
6 changes: 1 addition & 5 deletions karma/mocha/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -55,7 +51,7 @@ module.exports = function (config) {
customLaunchers: {
PhantomJS_without_security: {
base: 'PhantomJS',
flags: ['--web-security=false']
flags: ['--web-security=no']
}
},

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit a60d1d3

Please sign in to comment.