From 73b7cdf95dbe2559381c205eeb968a59f4c4eeaa Mon Sep 17 00:00:00 2001 From: Christian Budde Christensen Date: Sun, 21 Feb 2016 10:33:14 +0100 Subject: [PATCH] test(reporter): Add mocha test Add a test of the karma-mocha-reporter. Testing that it outputs correctly. --- package.json | 2 ++ test/e2e/mocharepoter.feature | 48 ++++++++++++++++++++++++++++++++++ test/e2e/steps/core_steps.js | 4 +++ test/e2e/support/mocha/plus.js | 5 ++++ test/e2e/support/mocha/test.js | 10 +++++++ 5 files changed, 69 insertions(+) create mode 100644 test/e2e/mocharepoter.feature create mode 100644 test/e2e/support/mocha/plus.js create mode 100644 test/e2e/support/mocha/test.js diff --git a/package.json b/package.json index e39f62535..d2641ad18 100644 --- a/package.json +++ b/package.json @@ -316,6 +316,7 @@ "json3": "^3.3.2", "karma-browserify": "^5.0.1", "karma-browserstack-launcher": "^0.1.10", + "karma-chai": "^0.1.0", "karma-chrome-launcher": "*", "karma-coffee-preprocessor": "*", "karma-commonjs": "*", @@ -327,6 +328,7 @@ "karma-junit-reporter": "*", "karma-live-preprocessor": "*", "karma-mocha": "0.2.1", + "karma-mocha-reporter": "^1.2.0", "karma-ng-scenario": "*", "karma-phantomjs-launcher": "*", "karma-qunit": "*", diff --git a/test/e2e/mocharepoter.feature b/test/e2e/mocharepoter.feature new file mode 100644 index 000000000..92261509f --- /dev/null +++ b/test/e2e/mocharepoter.feature @@ -0,0 +1,48 @@ +Feature: Mocha reporter + In order to use Karma + As a person who wants to write great tests + I want to be able to use the mocha reporter. + + Scenario: Execute a test in PhantomJS with colors + Given a configuration with: + """ + files = ['mocha/plus.js', 'mocha/test.js']; + browsers = ['PhantomJS']; + frameworks = ['mocha', 'chai'] + colors = true + plugins = [ + 'karma-jasmine', + 'karma-phantomjs-launcher', + 'karma-mocha-reporter', + 'karma-mocha', + 'karma-chai' + ]; + reporters = ['mocha']; + """ + When I start Karma + Then it passes with like: + """ + 2 tests completed + """ + + Scenario: Execute a test in PhantomJS with no-colors + Given a configuration with: + """ + files = ['mocha/plus.js', 'mocha/test.js']; + browsers = ['PhantomJS']; + frameworks = ['mocha', 'chai'] + colors = false + plugins = [ + 'karma-jasmine', + 'karma-phantomjs-launcher', + 'karma-mocha-reporter', + 'karma-mocha', + 'karma-chai' + ]; + reporters = ['mocha']; + """ + When I start Karma + Then it passes with like: + """ + ✔ 2 tests completed + """ \ No newline at end of file diff --git a/test/e2e/steps/core_steps.js b/test/e2e/steps/core_steps.js index de79e6f6d..ca3815b24 100644 --- a/test/e2e/steps/core_steps.js +++ b/test/e2e/steps/core_steps.js @@ -154,6 +154,10 @@ module.exports = function coreSteps () { return callback() } + if (like && actualOutput.indexOf(expectedOutput) >= 0) { + return callback() + } + if (actualOutput.indexOf(expectedOutput) === 0) { return callback() } diff --git a/test/e2e/support/mocha/plus.js b/test/e2e/support/mocha/plus.js new file mode 100644 index 000000000..d7fd9e84e --- /dev/null +++ b/test/e2e/support/mocha/plus.js @@ -0,0 +1,5 @@ +/* eslint-disable no-unused-vars */ +// Some code under test +function plus (a, b) { + return a + b +} diff --git a/test/e2e/support/mocha/test.js b/test/e2e/support/mocha/test.js new file mode 100644 index 000000000..2f0dde3ab --- /dev/null +++ b/test/e2e/support/mocha/test.js @@ -0,0 +1,10 @@ +/* globals plus */ +describe('plus', function () { + it('should pass', function () { + expect(true).to.be.true + }) + + it('should work', function () { + expect(plus(1, 2)).to.equal(3) + }) +})