From b279afbb746d6d0754584adbb0e536da976e7431 Mon Sep 17 00:00:00 2001 From: Bastien Caudan Date: Sun, 15 Jan 2017 12:37:21 +0100 Subject: [PATCH] Add jasmine & protractor integration tests #82 --- .npmrc | 1 + .travis.yml | 13 ++++- CHANGELOG.md | 1 + README.md | 1 + examples/node/.npmrc | 1 + examples/node/spec/helpers/reporter.js | 5 +- examples/protractor/.npmrc | 1 + examples/protractor/README.md | 2 - examples/protractor/package.json | 5 +- examples/protractor/protractor.conf.js | 5 ++ examples/typescript/.npmrc | 1 + package.json | 3 + spec/integration/integration.spec.ts | 40 +++++++++++++ spec/resources/node-example.out | 56 +++++++++++++++++++ spec/resources/node-protractor.out | 6 ++ spec/support/jasmine-integration.json | 9 +++ spec/support/jasmine.json | 3 +- spec/tsconfig.json | 3 +- spec/{ => unit}/colors-display.spec.ts | 0 spec/{ => unit}/configuration-parser.spec.ts | 4 +- spec/{ => unit}/custom-processor.spec.ts | 0 spec/{ => unit}/default-display.spec.ts | 0 spec/{ => unit}/display-duration.spec.ts | 0 .../{ => unit}/display-error-messages.spec.ts | 0 spec/{ => unit}/display-failed-spec.spec.ts | 0 .../display-failures-summary.spec.ts | 0 spec/{ => unit}/display-pending-spec.spec.ts | 0 .../display-pending-summary.spec.ts | 0 spec/{ => unit}/display-stacktrace.spec.ts | 0 .../display-successes-summary.spec.ts | 0 .../display-successful-spec.spec.ts | 0 spec/{ => unit}/display-suite-number.spec.ts | 0 spec/{ => unit}/duration-format.spec.ts | 0 spec/{ => unit}/spec-result-prefixes.spec.ts | 0 34 files changed, 147 insertions(+), 13 deletions(-) create mode 100644 .npmrc create mode 100644 examples/node/.npmrc create mode 100644 examples/protractor/.npmrc create mode 100644 examples/typescript/.npmrc create mode 100644 spec/integration/integration.spec.ts create mode 100644 spec/resources/node-example.out create mode 100644 spec/resources/node-protractor.out create mode 100644 spec/support/jasmine-integration.json rename spec/{ => unit}/colors-display.spec.ts (100%) rename spec/{ => unit}/configuration-parser.spec.ts (87%) rename spec/{ => unit}/custom-processor.spec.ts (100%) rename spec/{ => unit}/default-display.spec.ts (100%) rename spec/{ => unit}/display-duration.spec.ts (100%) rename spec/{ => unit}/display-error-messages.spec.ts (100%) rename spec/{ => unit}/display-failed-spec.spec.ts (100%) rename spec/{ => unit}/display-failures-summary.spec.ts (100%) rename spec/{ => unit}/display-pending-spec.spec.ts (100%) rename spec/{ => unit}/display-pending-summary.spec.ts (100%) rename spec/{ => unit}/display-stacktrace.spec.ts (100%) rename spec/{ => unit}/display-successes-summary.spec.ts (100%) rename spec/{ => unit}/display-successful-spec.spec.ts (100%) rename spec/{ => unit}/display-suite-number.spec.ts (100%) rename spec/{ => unit}/duration-format.spec.ts (100%) rename spec/{ => unit}/spec-result-prefixes.spec.ts (100%) diff --git a/.npmrc b/.npmrc new file mode 100644 index 00000000..66205aa3 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +loglevel = silent diff --git a/.travis.yml b/.travis.yml index b2c792f8..f854ad90 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,16 @@ +sudo: required +dist: trusty +addons: + apt: + sources: + - google-chrome + packages: + - google-chrome-stable language: node_js node_js: - '6.5' script: - - npm run coveralls + - npm run coveralls && npm run test:integration +before_install: + - export DISPLAY=:99.0 + - sh -e /etc/init.d/xvfb start diff --git a/CHANGELOG.md b/CHANGELOG.md index caf87079..1013f9ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Unreleased * Add an option to remove duration from execution summary. +* Add jasmine & protractor integration tests [#82](https://github.com/bcaudan/jasmine-spec-reporter/issues/82) # 3.1.0 diff --git a/README.md b/README.md index ffcc216a..d4bb94dd 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ You can customize the output of the reporter yourself: [see how](docs/customize- * install dependencies: `npm install` * compile sources: `npm run tsc` * launch unit tests: `npm test` +* launch integration tests: `npm test:integration` # Contribution diff --git a/examples/node/.npmrc b/examples/node/.npmrc new file mode 100644 index 00000000..66205aa3 --- /dev/null +++ b/examples/node/.npmrc @@ -0,0 +1 @@ +loglevel = silent diff --git a/examples/node/spec/helpers/reporter.js b/examples/node/spec/helpers/reporter.js index 30866d72..d76bc03f 100644 --- a/examples/node/spec/helpers/reporter.js +++ b/examples/node/spec/helpers/reporter.js @@ -3,6 +3,9 @@ const SpecReporter = require('jasmine-spec-reporter').SpecReporter; jasmine.getEnv().clearReporters(); // remove default reporter logs jasmine.getEnv().addReporter(new SpecReporter({ // add jasmine-spec-reporter spec: { - displayPending: true + displayPending: true, + }, + summary: { + displayDuration: false, } })); diff --git a/examples/protractor/.npmrc b/examples/protractor/.npmrc new file mode 100644 index 00000000..66205aa3 --- /dev/null +++ b/examples/protractor/.npmrc @@ -0,0 +1 @@ +loglevel = silent diff --git a/examples/protractor/README.md b/examples/protractor/README.md index 8c780ab3..20ab63d6 100644 --- a/examples/protractor/README.md +++ b/examples/protractor/README.md @@ -37,7 +37,5 @@ You can find an example in this directory: ```bash npm install -npm run webdriver-update # if needed -npm run webdriver-start npm test ``` diff --git a/examples/protractor/package.json b/examples/protractor/package.json index d584153a..4485d368 100644 --- a/examples/protractor/package.json +++ b/examples/protractor/package.json @@ -3,9 +3,8 @@ "version": "1.0.0", "description": "a protractor example", "scripts": { - "webdriver-update": "node node_modules/protractor/bin/webdriver-manager update", - "webdriver-start": "node node_modules/protractor/bin/webdriver-manager start", - "test": "node node_modules/protractor/bin/protractor protractor.conf.js" + "postinstall": "webdriver-manager update", + "test": "protractor protractor.conf.js" }, "author": "Bastien Caudan", "license": "Apache-2.0", diff --git a/examples/protractor/protractor.conf.js b/examples/protractor/protractor.conf.js index f50e440b..768b211f 100644 --- a/examples/protractor/protractor.conf.js +++ b/examples/protractor/protractor.conf.js @@ -1,4 +1,6 @@ let SpecReporter = require('jasmine-spec-reporter').SpecReporter; +// https://github.com/angular/protractor/issues/1451 +require('protractor/built/logger').Logger.logLevel = 1; exports.config = { framework: 'jasmine2', @@ -22,6 +24,9 @@ exports.config = { jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true + }, + summary: { + displayDuration: false } })); } diff --git a/examples/typescript/.npmrc b/examples/typescript/.npmrc new file mode 100644 index 00000000..66205aa3 --- /dev/null +++ b/examples/typescript/.npmrc @@ -0,0 +1 @@ +loglevel = silent diff --git a/package.json b/package.json index 5cd4e362..5296a1f3 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,9 @@ "prepublish": "tsc", "pretest": "tsc && tsc -p spec/tsconfig.json", "test": "jasmine", + "test:integration": "npm run pretest && npm run update-examples && jasmine JASMINE_CONFIG_PATH=spec/support/jasmine-integration.json", "posttest": "npm run lint", + "update-examples": "(cd examples/node && rm -rf node_modules && npm install) && (cd examples/protractor && rm -rf node_modules && npm install)", "lint": "tslint -c tslint.json 'src/**/*.ts' && tslint -c tslint.json 'spec/**/*.ts'", "coverage": "npm run pretest && rm -rf coverage && istanbul cover jasmine && npm run remap-coverage", "remap-coverage": "remap-istanbul -i coverage/coverage.json -o coverage/lcov-ts.info -t lcovonly && remap-istanbul -i coverage/coverage.json -o coverage/html-report -t html", @@ -40,6 +42,7 @@ "@types/jasmine": "2.5.40", "@types/node": "6.0.58", "coveralls": "2.11.15", + "diff": "3.2.0", "istanbul": "0.4.5", "jasmine": "2.5.2", "jasmine-core": "2.5.2", diff --git a/spec/integration/integration.spec.ts b/spec/integration/integration.spec.ts new file mode 100644 index 00000000..d58fc6c1 --- /dev/null +++ b/spec/integration/integration.spec.ts @@ -0,0 +1,40 @@ +import { exec } from "child_process"; +import { readFileSync } from "fs"; +const JsDiff = require("diff"); + +// https://github.com/jasmine/jasmine-npm/issues/85 +process.env.JASMINE_CONFIG_PATH = "spec/support/jasmine.json"; +const TIMEOUT_INCREASED = 120000; + +const filter = (diff) => { + const value = (element) => { + return element.value; + }; + const added = diff.filter((element) => { + return element.added === true; + }).map(value); + const removed = diff.filter((element) => { + return element.removed === true; + }).map(value); + return { added, removed }; +}; + +describe("Integration", () => { + it("with jasmine-npm should be ok", (done) => { + exec("cd examples/node && npm test", (error, stdout) => { + const expected = readFileSync("spec/resources/node-example.out", { encoding: "utf-8" }); + const { added, removed } = filter(JsDiff.diffLines(expected, stdout)); + expect(added).toEqual(removed); + done(); + }); + }, TIMEOUT_INCREASED); + + it("with protractor should be ok", (done) => { + exec("cd examples/protractor && npm test", (error, stdout) => { + const expected = readFileSync("spec/resources/node-protractor.out", { encoding: "utf-8" }); + const { added, removed } = filter(JsDiff.diffLines(expected, stdout)); + expect(added).toEqual(removed); + done(); + }); + }, TIMEOUT_INCREASED); +}); diff --git a/spec/resources/node-example.out b/spec/resources/node-example.out new file mode 100644 index 00000000..15cfa87d --- /dev/null +++ b/spec/resources/node-example.out @@ -0,0 +1,56 @@ +Spec started + + first suite + ✓ should be ok + * should be pending + ✗ should failed + - Expected true to be false. + ✓ should be ok + + second suite + * should be pending + ✓ should be ok + + first child suite + + first grandchild suite + ✗ should failed + - Expected true to be false. + - Expected true to be false. + ✗ should failed + - Expected true to be false. + ✓ should be ok + + second grandchild suite + ✗ should failed + - Expected true to be false. + ✓ should be ok + +************************************************** +* Failures * +************************************************** + +1) first suite should failed + - Expected true to be false. + +2) second suite first child suite first grandchild suite should failed + - Expected true to be false. + - Expected true to be false. + +3) second suite first child suite first grandchild suite should failed + - Expected true to be false. + +4) second suite first child suite second grandchild suite should failed + - Expected true to be false. + +************************************************** +* Pending * +************************************************** + +1) first suite should be pending + will work soon + +2) second suite should be pending + Temporarily disabled with xit + +Executed 9 of 11 specs (4 FAILED) (2 PENDING). diff --git a/spec/resources/node-protractor.out b/spec/resources/node-protractor.out new file mode 100644 index 00000000..2315fc57 --- /dev/null +++ b/spec/resources/node-protractor.out @@ -0,0 +1,6 @@ +Spec started + + angularjs homepage + ✓ should greet the named user + +Executed 1 of 1 spec SUCCESS. diff --git a/spec/support/jasmine-integration.json b/spec/support/jasmine-integration.json new file mode 100644 index 00000000..c233fc80 --- /dev/null +++ b/spec/support/jasmine-integration.json @@ -0,0 +1,9 @@ +{ + "spec_dir": "spec", + "spec_files": [ + "integration/**/*.spec.js" + ], + "helpers": [ + "helpers/**/*.js" + ] +} diff --git a/spec/support/jasmine.json b/spec/support/jasmine.json index b2502def..40950d2c 100644 --- a/spec/support/jasmine.json +++ b/spec/support/jasmine.json @@ -1,8 +1,7 @@ { "spec_dir": "spec", "spec_files": [ - "**/*.spec.js", - "**/*.spec.coffee" + "unit/**/*.spec.js" ], "helpers": [ "helpers/**/*.js" diff --git a/spec/tsconfig.json b/spec/tsconfig.json index 8321a519..e3ad4238 100644 --- a/spec/tsconfig.json +++ b/spec/tsconfig.json @@ -4,7 +4,6 @@ "target": "es5" }, "include": [ - "./**/*.ts", - "../typings/**/*.ts" + "./**/*.ts" ] } diff --git a/spec/colors-display.spec.ts b/spec/unit/colors-display.spec.ts similarity index 100% rename from spec/colors-display.spec.ts rename to spec/unit/colors-display.spec.ts diff --git a/spec/configuration-parser.spec.ts b/spec/unit/configuration-parser.spec.ts similarity index 87% rename from spec/configuration-parser.spec.ts rename to spec/unit/configuration-parser.spec.ts index f61da476..8fc10634 100644 --- a/spec/configuration-parser.spec.ts +++ b/spec/unit/configuration-parser.spec.ts @@ -1,5 +1,5 @@ -import { ConfigurationParser } from "../built/configuration-parser"; -import { TestProcessor } from "./helpers/test-processor"; +import { ConfigurationParser } from "../../built/configuration-parser"; +import { TestProcessor } from "../helpers/test-processor"; describe("Configuration parser", () => { it("should have a default configuration", () => { diff --git a/spec/custom-processor.spec.ts b/spec/unit/custom-processor.spec.ts similarity index 100% rename from spec/custom-processor.spec.ts rename to spec/unit/custom-processor.spec.ts diff --git a/spec/default-display.spec.ts b/spec/unit/default-display.spec.ts similarity index 100% rename from spec/default-display.spec.ts rename to spec/unit/default-display.spec.ts diff --git a/spec/display-duration.spec.ts b/spec/unit/display-duration.spec.ts similarity index 100% rename from spec/display-duration.spec.ts rename to spec/unit/display-duration.spec.ts diff --git a/spec/display-error-messages.spec.ts b/spec/unit/display-error-messages.spec.ts similarity index 100% rename from spec/display-error-messages.spec.ts rename to spec/unit/display-error-messages.spec.ts diff --git a/spec/display-failed-spec.spec.ts b/spec/unit/display-failed-spec.spec.ts similarity index 100% rename from spec/display-failed-spec.spec.ts rename to spec/unit/display-failed-spec.spec.ts diff --git a/spec/display-failures-summary.spec.ts b/spec/unit/display-failures-summary.spec.ts similarity index 100% rename from spec/display-failures-summary.spec.ts rename to spec/unit/display-failures-summary.spec.ts diff --git a/spec/display-pending-spec.spec.ts b/spec/unit/display-pending-spec.spec.ts similarity index 100% rename from spec/display-pending-spec.spec.ts rename to spec/unit/display-pending-spec.spec.ts diff --git a/spec/display-pending-summary.spec.ts b/spec/unit/display-pending-summary.spec.ts similarity index 100% rename from spec/display-pending-summary.spec.ts rename to spec/unit/display-pending-summary.spec.ts diff --git a/spec/display-stacktrace.spec.ts b/spec/unit/display-stacktrace.spec.ts similarity index 100% rename from spec/display-stacktrace.spec.ts rename to spec/unit/display-stacktrace.spec.ts diff --git a/spec/display-successes-summary.spec.ts b/spec/unit/display-successes-summary.spec.ts similarity index 100% rename from spec/display-successes-summary.spec.ts rename to spec/unit/display-successes-summary.spec.ts diff --git a/spec/display-successful-spec.spec.ts b/spec/unit/display-successful-spec.spec.ts similarity index 100% rename from spec/display-successful-spec.spec.ts rename to spec/unit/display-successful-spec.spec.ts diff --git a/spec/display-suite-number.spec.ts b/spec/unit/display-suite-number.spec.ts similarity index 100% rename from spec/display-suite-number.spec.ts rename to spec/unit/display-suite-number.spec.ts diff --git a/spec/duration-format.spec.ts b/spec/unit/duration-format.spec.ts similarity index 100% rename from spec/duration-format.spec.ts rename to spec/unit/duration-format.spec.ts diff --git a/spec/spec-result-prefixes.spec.ts b/spec/unit/spec-result-prefixes.spec.ts similarity index 100% rename from spec/spec-result-prefixes.spec.ts rename to spec/unit/spec-result-prefixes.spec.ts