Skip to content

Commit

Permalink
Add jasmine & protractor integration tests #82
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaudan committed Jan 15, 2017
1 parent 6c9bec4 commit b279afb
Show file tree
Hide file tree
Showing 34 changed files with 147 additions and 13 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
loglevel = silent
13 changes: 12 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions examples/node/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
loglevel = silent
5 changes: 4 additions & 1 deletion examples/node/spec/helpers/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}));
1 change: 1 addition & 0 deletions examples/protractor/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
loglevel = silent
2 changes: 0 additions & 2 deletions examples/protractor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
5 changes: 2 additions & 3 deletions examples/protractor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions examples/protractor/protractor.conf.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -22,6 +24,9 @@ exports.config = {
jasmine.getEnv().addReporter(new SpecReporter({
spec: {
displayStacktrace: true
},
summary: {
displayDuration: false
}
}));
}
Expand Down
1 change: 1 addition & 0 deletions examples/typescript/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
loglevel = silent
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
40 changes: 40 additions & 0 deletions spec/integration/integration.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});
56 changes: 56 additions & 0 deletions spec/resources/node-example.out
Original file line number Diff line number Diff line change
@@ -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).
6 changes: 6 additions & 0 deletions spec/resources/node-protractor.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Spec started

angularjs homepage
✓ should greet the named user

Executed 1 of 1 spec SUCCESS.
9 changes: 9 additions & 0 deletions spec/support/jasmine-integration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"spec_dir": "spec",
"spec_files": [
"integration/**/*.spec.js"
],
"helpers": [
"helpers/**/*.js"
]
}
3 changes: 1 addition & 2 deletions spec/support/jasmine.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"spec_dir": "spec",
"spec_files": [
"**/*.spec.js",
"**/*.spec.coffee"
"unit/**/*.spec.js"
],
"helpers": [
"helpers/**/*.js"
Expand Down
3 changes: 1 addition & 2 deletions spec/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"target": "es5"
},
"include": [
"./**/*.ts",
"../typings/**/*.ts"
"./**/*.ts"
]
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit b279afb

Please sign in to comment.