Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate test cases into mocha test runner #1545

Merged
merged 3 commits into from
Mar 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ cache:
env:
global:
- CXX=g++-4.8
- alias jasmine=./node_modules/.bin/jasmine
- alias tsc=./node_modules/.bin/tsc

before_install:
Expand All @@ -31,10 +30,10 @@ install:
- npm install && npm run lint

script:
- npm run build_spec && npm run test_jasmine && node ./node_modules/markdown-doctest/bin/cmd.js
- npm run build_spec && npm run test_mocha && node ./node_modules/markdown-doctest/bin/cmd.js
- npm run check_circular_dependencies
- npm run cover

after_success:
- npm run cover
- cat ./coverage/coverage-remapped.lcov | ./node_modules/coveralls/bin/coveralls.js
- '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && [ -n "${SAUCE_ACCESS_KEY}" ] && npm run test_karma || false'
#- '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && [ -n "${SAUCE_ACCESS_KEY}" ] && npm run test_karma || false'
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"build_closure_kitchensink": "Minify Global kitchenSink build using closure compiler",
"build_global": "Build Global package, then minify core & kitchensink build",
"build_perf": "Build CJS & Global build, run macro performance test",
"build_test": "Build CJS package & test spec, execute jasmine test runner",
"build_test": "Build CJS package & test spec, execute mocha test runner",
"build_cover": "Run lint to current code, build CJS & test spec, execute test coverage",
"build_docs": "Build ES6 & global package, create documentation using it",
"build_spec": "Build test specs",
Expand All @@ -41,9 +41,9 @@
"lint": "Run lint against everything",
"perf": "Run macro performance benchmark",
"perf_micro": "Run micro performance benchmark",
"test_jasmine": "Execute jasmine test runner against existing test spec build",
"test_mocha": "Execute mocha test runner against existing test spec build",
"test_karma": "Execute karma test runner against existing test spec build",
"test": "Clean up existing test spec build, build test spec and execute jasmine test runner",
"test": "Clean up existing test spec build, build test spec and execute mocha test runner",
"tests2png": "Generate marble diagram image from test spec",
"watch": "Watch codebase, trigger compile when source code changes"
},
Expand All @@ -57,7 +57,7 @@
"build_closure_kitchensink": "java -jar ./node_modules/google-closure-compiler/compiler.jar --js ./dist/global/Rx.KitchenSink.umd.js --language_in ECMASCRIPT5 --create_source_map ./dist/global/Rx.KitchenSink.umd.min.js.map --js_output_file ./dist/global/Rx.KitchenSink.umd.min.js",
"build_global": "rm -rf ./dist/global && mkdirp ./dist/global && node tools/make-umd-bundle.js && node tools/make-system-bundle.js && npm-run-all build_closure_core build_closure_kitchensink",
"build_perf": "webdriver-manager update && npm-run-all build_cjs build_global perf",
"build_test": "rm -rf ./dist/ && npm-run-all lint build_cjs clean_spec build_spec test_jasmine",
"build_test": "rm -rf ./dist/ && npm-run-all lint build_cjs clean_spec build_spec test_mocha",
"build_cover": "rm -rf ./dist/ && npm-run-all lint build_cjs build_spec cover",
"build_docs": "npm-run-all build_es6 build_global tests2png && esdoc -c esdoc.json",
"build_spec": "tsc --project ./spec --pretty",
Expand All @@ -70,11 +70,11 @@
"copy_src_cjs": "mkdirp ./dist/cjs/src && cp -r ./src/* ./dist/cjs/src",
"copy_src_es6": "mkdirp ./dist/es6/src && cp -r ./src/* ./dist/es6/src",
"commit": "git-cz",
"compile_dist_amd": "tsc ./typings/main.d.ts ./dist/amd/src/Rx.ts ./dist/amd/src/Rx.KitchenSink.ts ./dist/amd/src/Rx.DOM.ts ./dist/amd/src/add/observable/of.ts -m amd --sourceMap --outDir ./dist/amd --target ES5 --diagnostics --pretty --noImplicitAny --suppressImplicitAnyIndexErrors",
"compile_dist_cjs": "tsc ./typings/main.d.ts ./dist/cjs/src/Rx.ts ./dist/cjs/src/Rx.KitchenSink.ts ./dist/cjs/src/Rx.DOM.ts ./dist/cjs/src/add/observable/of.ts -m commonjs --sourceMap --outDir ./dist/cjs --target ES5 -d --diagnostics --pretty --noImplicitAny --suppressImplicitAnyIndexErrors",
"compile_dist_amd": "tsc typings/main/ambient/es6-shim/index.d.ts ./dist/amd/src/Rx.ts ./dist/amd/src/Rx.KitchenSink.ts ./dist/amd/src/Rx.DOM.ts ./dist/amd/src/add/observable/of.ts -m amd --sourceMap --outDir ./dist/amd --target ES5 --diagnostics --pretty --noImplicitAny --suppressImplicitAnyIndexErrors",
"compile_dist_cjs": "tsc typings/main/ambient/es6-shim/index.d.ts ./dist/cjs/src/Rx.ts ./dist/cjs/src/Rx.KitchenSink.ts ./dist/cjs/src/Rx.DOM.ts ./dist/cjs/src/add/observable/of.ts -m commonjs --sourceMap --outDir ./dist/cjs --target ES5 -d --diagnostics --pretty --noImplicitAny --suppressImplicitAnyIndexErrors",
"compile_dist_es6": "tsc ./dist/es6/src/Rx.ts ./dist/es6/src/Rx.KitchenSink.ts ./dist/es6/src/Rx.DOM.ts ./dist/es6/src/add/observable/of.ts -m es2015 --sourceMap --outDir ./dist/es6 --target ES6 -d --diagnostics --pretty --noImplicitAny --suppressImplicitAnyIndexErrors",
"cover": "npm-run-all cover_test cover_remapping",
"cover_test": "istanbul cover -x \"*-spec.js index.js *-helper.js spec-js/helpers/*\" ./node_modules/jasmine/bin/jasmine.js",
"cover_test": "rm -rf dist/cjs && tsc typings/main/ambient/es6-shim/index.d.ts src/Rx.ts src/Rx.KitchenSink.ts src/Rx.DOM.ts src/add/observable/of.ts -m commonjs --outDir dist/cjs --sourceMap --target ES5 -d && istanbul cover -x \"spec-js/**/*\" ./node_modules/mocha/bin/_mocha -- --opts spec/support/default.opts spec-js",
"cover_remapping": "remap-istanbul -i coverage/coverage.json -o coverage/coverage-remapped.json && remap-istanbul -i coverage/coverage.json -o coverage/coverage-remapped.lcov -t lcovonly && remap-istanbul -i coverage/coverage.json -o coverage/coverage-remapped -t html",
"generate_packages": "node .make-packages.js",
"lint_perf": "eslint perf/",
Expand All @@ -85,10 +85,10 @@
"perf_micro": "node ./perf/micro/index.js",
"prepublish": "rm -rf ./typings && typings install && npm run build_all",
"publish_docs": "./publish_docs.sh",
"test_jasmine": "jasmine",
"test_mocha": "mocha --opts spec/support/default.opts spec-js",
"test_karma": "karma start karma.conf.js",
"test": "npm-run-all clean_spec build_spec test_jasmine clean_spec",
"tests2png": "npm run build_spec && mkdirp tmp/docs/img && mkdirp spec-js/support && cp spec/support/*.json spec-js/support/ && jasmine JASMINE_CONFIG_PATH=spec/support/tests2png.json",
"test": "npm-run-all clean_spec build_spec test_mocha clean_spec",
"tests2png": "npm run build_spec && mkdirp tmp/docs/img && mkdirp spec-js/support && cp spec/support/*.json spec-js/support/ && mocha --opts spec/support/tests2png.opts spec-js",
"watch": "watch \"echo triggering build && npm run build_test && echo build completed\" src -d -u -w=15"
},
"repository": {
Expand Down Expand Up @@ -144,6 +144,7 @@
"benchmark": "^2.1.0",
"benchpress": "2.0.0-beta.1",
"browserify": "13.0.0",
"chai": "^3.5.0",
"color": "^0.11.1",
"colors": "1.1.2",
"commitizen": "^2.7.2",
Expand All @@ -159,26 +160,25 @@
"gzip-size": "^3.0.0",
"http-server": "^0.9.0",
"istanbul": "0.4.2",
"jasmine": "2.4.1",
"jasmine-ajax": "3.2.0",
"jasmine-core": "2.4.1",
"karma": "^0.13.22",
"karma-browserify": "5.0.2",
"karma-chrome-launcher": "0.2.2",
"karma-jasmine": "0.3.7",
"karma-sauce-launcher": "^0.3.1",
"lodash": "^4.6.1",
"madge": "^0.5.3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have to replace this with karma-mocha?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR doesn't include browser test configuration update as noted. May need track it separately.

"markdown-doctest": "^0.3.2",
"minimist": "^1.2.0",
"mkdirp": "^0.5.1",
"mocha": "^2.4.5",
"npm-run-all": "^1.5.3",
"npm-scripts-info": "^0.3.4",
"platform": "^1.3.1",
"promise": "^7.1.1",
"protractor": "^3.1.1",
"remap-istanbul": "0.5.1",
"rx": "latest",
"sinon": "^1.17.3",
"sinon-chai": "^2.8.0",
"systemjs": "^0.19.24",
"systemjs-builder": "^0.10.6",
"tslint": "^3.5.0",
Expand Down
77 changes: 39 additions & 38 deletions spec/Notification-spec.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
import {expect} from 'chai';
import * as Rx from '../dist/cjs/Rx';
declare const expectObservable;

declare const expectObservable;
const Notification = Rx.Notification;

/** @test {Notification} */
describe('Notification', () => {
it('should exist', () => {
expect(Notification).toBeDefined();
expect(typeof Notification).toBe('function');
expect(Notification).exist;
expect(Notification).to.be.a('function');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, I'm sorry you had to go through each of these assertions. Could have used something like https://github.com/crysalead-js/chai-jasmine. Did you try that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was aware but didn't tempted quite especially given repo is somewhat inactive state. Updating assertion actually wasn't that hard, just simple replace.

});

describe('createNext', () => {
it('should return a Notification', () => {
const n = Notification.createNext('test');
expect(n instanceof Notification).toBe(true);
expect(n.value).toBe('test');
expect(n.kind).toBe('N');
expect(typeof n.exception).toBe('undefined');
expect(n.hasValue).toBe(true);
expect(n instanceof Notification).to.be.true;
expect(n.value).to.equal('test');
expect(n.kind).to.equal('N');
expect(n.exception).to.be.a('undefined');
expect(n.hasValue).to.be.true;
});
});

describe('createError', () => {
it('should return a Notification', () => {
const n = Notification.createError('test');
expect(n instanceof Notification).toBe(true);
expect(typeof n.value).toBe('undefined');
expect(n.kind).toBe('E');
expect(n.exception).toBe('test');
expect(n.hasValue).toBe(false);
expect(n instanceof Notification).to.be.true;
expect(n.value).to.be.a('undefined');
expect(n.kind).to.equal('E');
expect(n.exception).to.equal('test');
expect(n.hasValue).to.be.false;
});
});

describe('createComplete', () => {
it('should return a Notification', () => {
const n = Notification.createComplete();
expect(n instanceof Notification).toBe(true);
expect(typeof n.value).toBe('undefined');
expect(n.kind).toBe('C');
expect(typeof n.exception).toBe('undefined');
expect(n.hasValue).toBe(false);
expect(n instanceof Notification).to.be.true;
expect(n.value).to.be.a('undefined');
expect(n.kind).to.equal('C');
expect(n.exception).to.be.a('undefined');
expect(n.hasValue).to.be.false;
});
});

Expand Down Expand Up @@ -67,28 +68,28 @@ describe('Notification', () => {
const first = Notification.createNext(value);
const second = Notification.createNext(value);

expect(first).not.toBe(second);
expect(first).not.to.equal(second);
});

it('should create new error Notification', () => {
const first = Notification.createError();
const second = Notification.createError();

expect(first).not.toBe(second);
expect(first).not.to.equal(second);
});

it('should return static next Notification reference without value', () => {
const first = Notification.createNext(undefined);
const second = Notification.createNext(undefined);

expect(first).toBe(second);
expect(first).to.equal(second);
});

it('should return static complete Notification reference', () => {
const first = Notification.createComplete();
const second = Notification.createComplete();

expect(first).toBe(second);
expect(first).to.equal(second);
});
});

Expand All @@ -104,7 +105,7 @@ describe('Notification', () => {
throw 'should not be called';
});

expect(invoked).toBe(true);
expect(invoked).to.be.true;
});

it('should invoke on error', () => {
Expand All @@ -118,7 +119,7 @@ describe('Notification', () => {
throw 'should not be called';
});

expect(invoked).toBe(true);
expect(invoked).to.be.true;
});

it('should invoke on complete', () => {
Expand All @@ -132,7 +133,7 @@ describe('Notification', () => {
invoked = true;
});

expect(invoked).toBe(true);
expect(invoked).to.be.true;
});
});

Expand All @@ -142,7 +143,7 @@ describe('Notification', () => {
let observed = false;
const n = Notification.createNext(value);
const observer = Rx.Subscriber.create((x: string) => {
expect(x).toBe(value);
expect(x).to.equal(value);
observed = true;
}, (err: any) => {
throw 'should not be called';
Expand All @@ -151,7 +152,7 @@ describe('Notification', () => {
});

n.accept(observer);
expect(observed).toBe(true);
expect(observed).to.be.true;
});

it('should accept observer for error Notification', () => {
Expand All @@ -166,7 +167,7 @@ describe('Notification', () => {
});

n.accept(observer);
expect(observed).toBe(true);
expect(observed).to.be.true;
});

it('should accept observer for complete Notification', () => {
Expand All @@ -181,7 +182,7 @@ describe('Notification', () => {
});

n.accept(observer);
expect(observed).toBe(true);
expect(observed).to.be.true;
});

it('should accept function for next Notification', () => {
Expand All @@ -190,14 +191,14 @@ describe('Notification', () => {
const n = Notification.createNext(value);

n.accept((x: string) => {
expect(x).toBe(value);
expect(x).to.equal(value);
observed = true;
}, (err: any) => {
throw 'should not be called';
}, () => {
throw 'should not be called';
});
expect(observed).toBe(true);
expect(observed).to.be.true;
});

it('should accept function for error Notification', () => {
Expand All @@ -208,12 +209,12 @@ describe('Notification', () => {
n.accept((x: any) => {
throw 'should not be called';
}, (err: any) => {
expect(err).toBe(error);
expect(err).to.equal(error);
observed = true;
}, () => {
throw 'should not be called';
});
expect(observed).toBe(true);
expect(observed).to.be.true;
});

it('should accept function for complete Notification', () => {
Expand All @@ -227,7 +228,7 @@ describe('Notification', () => {
}, () => {
observed = true;
});
expect(observed).toBe(true);
expect(observed).to.be.true;
});
});

Expand All @@ -237,7 +238,7 @@ describe('Notification', () => {
let observed = false;
const n = Notification.createNext(value);
const observer = Rx.Subscriber.create((x: string) => {
expect(x).toBe(value);
expect(x).to.equal(value);
observed = true;
}, (err: any) => {
throw 'should not be called';
Expand All @@ -246,7 +247,7 @@ describe('Notification', () => {
});

n.observe(observer);
expect(observed).toBe(true);
expect(observed).to.be.true;
});

it('should observe for error Notification', () => {
Expand All @@ -261,7 +262,7 @@ describe('Notification', () => {
});

n.observe(observer);
expect(observed).toBe(true);
expect(observed).to.be.true;
});

it('should observe for complete Notification', () => {
Expand All @@ -276,7 +277,7 @@ describe('Notification', () => {
});

n.observe(observer);
expect(observed).toBe(true);
expect(observed).to.be.true;
});
});
});
Loading