Skip to content

Commit bd45a90

Browse files
committed
docs(spec): show tests in ESDocs
Add ESDoc @test tag on each *-spec.js file in order to make it show in the ESDoc page, and also tweak esdoc.json to show tests.
1 parent 2c1a794 commit bd45a90

File tree

151 files changed

+448
-370
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+448
-370
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dist/
1313
tmp/
1414
coverage/
1515
img/
16+
spec-js/
1617

1718
# Misc
1819
npm-debug.log

.markdown-doctest-setup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22
var Rx = require(__dirname);
33

4-
var marbleTesting = require('./tmp/helpers/marble-testing');
4+
var marbleTesting = require('./spec-js/helpers/marble-testing');
55

66
global.rxTestScheduler = new Rx.TestScheduler(marbleTesting.assertDeepEqual);
77

esdoc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
22
"source": "./dist/es6",
33
"destination": "./tmp/docs",
4+
"test": {
5+
"type": "mocha",
6+
"source": "./spec-js",
7+
"includes": ["(spec)\\.(js|ts)$"]
8+
},
49
"undocumentIdentifier": false,
510
"title": "RxJS",
611
"styles": ["./doc/styles/main.css"],

karma.conf.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ module.exports = function (config) {
140140
// list of files / patterns to load in the browser
141141
files: [
142142
'node_modules/babel-polyfill/dist/polyfill.js',
143-
'tmp/helpers/marble-testing.js',
144-
'tmp/helpers/test-helper.js',
145-
'tmp/helpers/ajax-helper.js',
146-
'tmp/**/*-spec.js'
143+
'spec-js/helpers/marble-testing.js',
144+
'spec-js/helpers/test-helper.js',
145+
'spec-js/helpers/ajax-helper.js',
146+
'spec-js/**/*-spec.js'
147147
],
148148

149149
// list of files to exclude
@@ -153,7 +153,7 @@ module.exports = function (config) {
153153
// preprocess matching files before serving them to the browser
154154
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
155155
preprocessors: {
156-
'tmp/**/*.js': ['browserify']
156+
'spec-js/**/*.js': ['browserify']
157157
},
158158

159159
// test results reporter to use

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@
2222
"build_perf": "npm run build_cjs && npm run build_global && webdriver-manager update && npm run perf",
2323
"build_test": "rm -rf dist/ && npm run lint && npm run build_cjs && npm run test_buildonly && npm run test_nobuild",
2424
"build_cover": "rm -rf dist/ && npm run lint && npm run build_cjs && npm run test_buildonly && npm run cover",
25-
"build_docs": "npm run build_es6 && npm run build_global && npm run tests2png && esdoc -c esdoc.json",
25+
"build_docs": "npm run build_es6 && npm run build_global && npm run test_buildonly && npm run tests2png && esdoc -c esdoc.json",
2626
"publish_docs": "./publish_docs.sh",
2727
"lint_perf": "eslint perf/",
2828
"lint_spec": "tslint -c tslint.json spec/*.ts spec/**/*.ts spec/**/**/*.ts",
2929
"lint_src": "tslint -c tslint.json src/*.ts src/**/*.ts src/**/**/*.ts",
3030
"lint": "npm run lint_src && npm run lint_spec && npm run lint_perf",
3131
"copy_src": "cp -r src/ dist/cjs/src && cp -r src/ dist/amd/src && cp -r src/ dist/es6/src",
32-
"cover": "istanbul cover -x \"*-spec.js index.js *-helper.js tmp/helpers/*\" ./node_modules/jasmine/bin/jasmine.js && npm run cover_remapping",
32+
"cover": "istanbul cover -x \"*-spec.js index.js *-helper.js spec-js/helpers/*\" ./node_modules/jasmine/bin/jasmine.js && npm run cover_remapping",
3333
"cover_remapping": "remap-istanbul -b ./ -i coverage/coverage.json -o coverage/coverage-remapped.json && remap-istanbul -b ./ -i coverage/coverage.json -o coverage/coverage-remapped.lcov -t lcovonly && remap-istanbul -b ./ -i coverage/coverage.json -o coverage/coverage-remapped -t html",
3434
"test_nobuild": "jasmine",
35-
"test_buildonly": "rm -rf tmp && tsc --project ./spec --pretty",
35+
"test_buildonly": "rm -rf spec-js && mkdirp spec-js && tsc --project ./spec --pretty",
3636
"test": "npm run test_buildonly && npm run test_nobuild",
3737
"test_karma": "karma start karma.conf.js",
38-
"tests2png": "mkdirp tmp/docs/img && cp -r spec/helpers/tests2png tmp/helpers/tests2png && jasmine JASMINE_CONFIG_PATH=spec/support/tests2png.json",
38+
"tests2png": "npm run test_buildonly && mkdirp tmp/docs/img && mkdirp spec-js/support && cp spec/support/*.json spec-js/support/ && JASMINE_CONFIG_PATH=spec/support/tests2png.json jasmine",
3939
"watch": "watch \"echo triggering build && npm run build_test && echo build completed\" src -d -u -w=15",
4040
"perf": "protractor protractor.conf.js",
4141
"perf_micro": "node ./perf/micro/index.js",

spec/Notification-spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as Rx from '../dist/cjs/Rx';
2-
import {expectObservable} from './helpers/marble-testing';
3-
import {it} from './helpers/test-helper';
2+
declare const expectObservable;
43

54
const Notification = Rx.Notification;
65

6+
/** @test {Notification} */
77
describe('Notification', () => {
88
it('should exist', () => {
99
expect(Notification).toBeDefined();

spec/Observable-spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as Rx from '../dist/cjs/Rx';
2-
import {it, DoneSignature} from './helpers/test-helper';
2+
import {DoneSignature} from './helpers/test-helper';
33

44
const Subscriber = Rx.Subscriber;
55
const Observable = Rx.Observable;
@@ -14,6 +14,7 @@ function expectFullObserver(val) {
1414
expect(typeof val.isUnsubscribed).toBe('boolean');
1515
}
1616

17+
/** @test {Observable} */
1718
describe('Observable', () => {
1819
it('should be constructed with a subscriber function', (done: DoneSignature) => {
1920
const source = new Observable(function (observer) {
@@ -280,6 +281,7 @@ describe('Observable', () => {
280281
});
281282
});
282283

284+
/** @test {Observable} */
283285
describe('Observable.create', () => {
284286
it('should create an Observable', () => {
285287
const result = Observable.create(() => {
@@ -304,6 +306,7 @@ describe('Observable.create', () => {
304306
});
305307
});
306308

309+
/** @test {Observable} */
307310
describe('Observable.lift', () => {
308311
it('should be overrideable in a custom Observable type that composes', (done: DoneSignature) => {
309312
class MyCustomObservable<T> extends Rx.Observable<T> {

spec/Scheduler-spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import * as Rx from '../dist/cjs/Rx';
2-
import {it, DoneSignature} from './helpers/test-helper';
2+
import {DoneSignature} from './helpers/test-helper';
33

44
const Scheduler = Rx.Scheduler;
55

6+
/** @test {Scheduler} */
67
describe('Scheduler.queue', () => {
78
it('should schedule things recursively', () => {
89
let call1 = false;

spec/Subject-spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import * as Rx from '../dist/cjs/Rx';
2-
import {hot, expectObservable} from './helpers/marble-testing';
3-
import {it, DoneSignature} from './helpers/test-helper';
2+
declare const {hot, expectObservable};
3+
import {DoneSignature} from './helpers/test-helper';
44

55
const Subject = Rx.Subject;
66
const Observable = Rx.Observable;
77

8+
/** @test {Subject} */
89
describe('Subject', () => {
910
it('should pump values right on through itself', (done: DoneSignature) => {
1011
const subject = new Subject();

spec/Subscriber-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as Rx from '../dist/cjs/Rx';
2-
import {it} from './helpers/test-helper';
32
const Subscriber = Rx.Subscriber;
43

4+
/** @test {Subscriber} */
55
describe('Subscriber', () => {
66
it('should have the rxSubscriber symbol', () => {
77
const sub = new Subscriber();

spec/Subscription-spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import * as Rx from '../dist/cjs/Rx';
2-
import {it, DoneSignature} from './helpers/test-helper';
2+
import {DoneSignature} from './helpers/test-helper';
33

44
const Observable = Rx.Observable;
55
const Subscription = Rx.Subscription;
66

7+
/** @test {Subscription} */
78
describe('Subscription', () => {
89
it('should not leak', (done: DoneSignature) => {
910
const tearDowns = [];

spec/helpers/test-helper.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
1111
import * as _ from 'lodash';
1212
import * as Rx from '../../dist/cjs/Rx.KitchenSink';
1313
import {root} from '../../dist/cjs/util/root';
14-
import {assertDeepEqual} from './marble-testing';
14+
import * as marbleHelpers from './marble-testing';
1515

1616
global.rxTestScheduler = null;
17+
global.cold = marbleHelpers.cold;
18+
global.hot = marbleHelpers.hot;
19+
global.time = marbleHelpers.time;
20+
global.expectObservable = marbleHelpers.expectObservable;
21+
global.expectSubscriptions = marbleHelpers.expectSubscriptions;
1722

1823
//amending type definition of jasmine which seems doesn't have this
1924
export interface DoneSignature {
@@ -25,7 +30,7 @@ const defaultAssertion: (expectation: string, assertion?: (done: DoneSignature)
2530
const singleAssertion: (expectation: string, assertion?: (done: DoneSignature) => void, timeout?: number) => void = global.fit;
2631

2732
function assertAction(done: DoneSignature, assertion: (done?: DoneSignature) => void): void {
28-
global.rxTestScheduler = new Rx.TestScheduler(assertDeepEqual);
33+
global.rxTestScheduler = new Rx.TestScheduler(marbleHelpers.assertDeepEqual);
2934
let error: any;
3035
let errorHappened: boolean = false;
3136

@@ -45,9 +50,6 @@ function assertAction(done: DoneSignature, assertion: (done?: DoneSignature) =>
4550
}
4651

4752
export function asDiagram(expectation: string): (expectation: string, assertion?: (done: DoneSignature) => void, timeout?: number) => void {
48-
if (global.it.asDiagram) {
49-
return global.it.asDiagram(expectation);
50-
}
5153
return it;
5254
}
5355

@@ -71,6 +73,12 @@ export function fit(expectation: string, assertion?: (done?: DoneSignature) => v
7173
}
7274
}
7375

76+
global.it = it;
77+
global.fit = fit;
78+
if (!global.asDiagram) {
79+
global.asDiagram = asDiagram;
80+
}
81+
7482
export function lowerCaseO<T>(...args): Rx.Observable<T> {
7583
const values = [].slice.apply(arguments);
7684

spec/helpers/tests2png/diagram-test-runner.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ var glit = global.it;
7676

7777
global.it = function (description, specFn, timeout) { };
7878

79-
global.it.asDiagram = function asDiagram(operatorLabel) {
79+
global.asDiagram = function asDiagram(operatorLabel) {
8080
return function specFnWithPainter(description, specFn) {
8181
if (specFn.length === 0) {
8282
glit(description, function () {
@@ -156,4 +156,3 @@ global.lowerCaseO = function lowerCaseO() {
156156

157157
return o;
158158
};
159-

spec/observables/ErrorObservable-spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as Rx from '../../dist/cjs/Rx.KitchenSink';
22
import {ErrorObservable} from '../../dist/cjs/observable/ErrorObservable';
3-
import {expectObservable} from '../helpers/marble-testing';
4-
import {it} from '../helpers/test-helper';
3+
declare const expectObservable: any;
54

65
declare const rxTestScheduler: Rx.TestScheduler;
76

7+
/** @test {throw} */
88
describe('ErrorObservable', () => {
99
it('should create expose a error property', () => {
1010
const e = new ErrorObservable('error');

spec/observables/IteratorObservable-spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as Rx from '../../dist/cjs/Rx.KitchenSink';
22
import {IteratorObservable} from '../../dist/cjs/observable/IteratorObservable';
3-
import {expectObservable} from '../helpers/marble-testing';
4-
import {it, DoneSignature} from '../helpers/test-helper';
3+
declare const {expectObservable};
4+
import {DoneSignature} from '../helpers/test-helper';
55

66
declare const rxTestScheduler: Rx.TestScheduler;
77

spec/observables/ScalarObservable-spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as Rx from '../../dist/cjs/Rx.KitchenSink';
22
import {ScalarObservable} from '../../dist/cjs/observable/ScalarObservable';
3-
import {it} from '../helpers/test-helper';
43

54
declare const rxTestScheduler: Rx.TestScheduler;
65

spec/observables/SubscribeOnObservable-spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as Rx from '../../dist/cjs/Rx.KitchenSink';
22
import {SubscribeOnObservable} from '../../dist/cjs/observable/SubscribeOnObservable';
3-
import {hot, expectObservable, expectSubscriptions} from '../helpers/marble-testing';
4-
import {it} from '../helpers/test-helper';
3+
declare const {hot, expectObservable, expectSubscriptions};
54

65
declare const rxTestScheduler: Rx.TestScheduler;
76

spec/observables/bindCallback-spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import * as Rx from '../../dist/cjs/Rx.KitchenSink';
2-
import {it, DoneSignature} from '../helpers/test-helper';
2+
import {DoneSignature} from '../helpers/test-helper';
33

44
declare const rxTestScheduler: Rx.TestScheduler;
55
const Observable = Rx.Observable;
66

7+
/** @test {bindCallback} */
78
describe('Observable.bindCallback', () => {
89
describe('when not scheduled', () => {
910
it('should emit one value from a callback', () => {

spec/observables/bindNodeCallback-spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import * as Rx from '../../dist/cjs/Rx.KitchenSink';
2-
import {it, DoneSignature} from '../helpers/test-helper';
2+
import {DoneSignature} from '../helpers/test-helper';
33

44
declare const rxTestScheduler: Rx.TestScheduler;
55
const Observable = Rx.Observable;
66

7+
/** @test {bindNodeCallback} */
78
describe('Observable.bindNodeCallback', () => {
89
describe('when not scheduled', () => {
910
it('should emit one value from a callback', () => {

spec/observables/combineLatest-spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import * as Rx from '../../dist/cjs/Rx.KitchenSink';
2-
import {hot, cold, expectObservable, expectSubscriptions} from '../helpers/marble-testing';
3-
import {it, DoneSignature} from '../helpers/test-helper';
2+
declare const {hot, cold, expectObservable, expectSubscriptions};
3+
import {DoneSignature} from '../helpers/test-helper';
44

55
const Observable = Rx.Observable;
66
const queueScheduler = Rx.Scheduler.queue;
77

8+
/** @test {combineLatest} */
89
describe('Observable.combineLatest', () => {
910
it('should combineLatest the provided observables', () => {
1011
const firstSource = hot('----a----b----c----|');

spec/observables/concat-spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/* globals describe, it, expect, expectObservable, expectSubscriptions, cold */
22
import * as Rx from '../../dist/cjs/Rx.KitchenSink';
3-
import {hot, cold, expectObservable, expectSubscriptions} from '../helpers/marble-testing';
4-
import {it, DoneSignature} from '../helpers/test-helper';
3+
declare const {hot, cold, expectObservable, expectSubscriptions};
4+
import {DoneSignature} from '../helpers/test-helper';
55

66
const Observable = Rx.Observable;
77
const queueScheduler = Rx.Scheduler.queue;
88

9+
/** @test {concat} */
910
describe('Observable.concat', () => {
1011
it('should emit elements from multiple sources', () => {
1112
const e1 = cold('-a-b-c-|');

spec/observables/defer-spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as Rx from '../../dist/cjs/Rx';
2-
import {hot, expectObservable, expectSubscriptions} from '../helpers/marble-testing';
3-
import {it} from '../helpers/test-helper';
2+
declare const {hot, expectObservable, expectSubscriptions};
43

54
const Observable = Rx.Observable;
65

6+
/** @test {defer} */
77
describe('Observable.defer', () => {
88
it('should create an observable from the provided observbale factory', () => {
99
const source = hot('--a--b--c--|');

spec/observables/dom/ajax-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as Rx from '../../../dist/cjs/Rx.DOM';
22
import {root} from '../../../dist/cjs/util/root';
33
import {MockXMLHttpRequest} from '../../helpers/ajax-helper';
4-
import {it} from '../../helpers/test-helper';
54

65
declare const global: any;
76

7+
/** @test {ajax} */
88
describe('Observable.ajax', () => {
99
let gXHR: XMLHttpRequest;
1010
let rXHR: XMLHttpRequest;

spec/observables/dom/webSocket-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as Rx from '../../../dist/cjs/Rx.DOM';
22
import {MockWebSocket} from '../../helpers/ajax-helper';
3-
import {it} from '../../helpers/test-helper';
43

54
declare const __root__: any;
65

@@ -18,6 +17,7 @@ function teardownMockWebSocket() {
1817
MockWebSocket.clearSockets();
1918
}
2019

20+
/** @test {webSocket} */
2121
describe('Observable.webSocket', () => {
2222
beforeEach(() => {
2323
setupMockWebSocket();

spec/observables/forkJoin-spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import * as Rx from '../../dist/cjs/Rx.KitchenSink';
2-
import {hot, expectObservable} from '../helpers/marble-testing';
3-
import {it, DoneSignature, lowerCaseO} from '../helpers/test-helper';
2+
declare const {hot, expectObservable};
3+
import {DoneSignature, lowerCaseO} from '../helpers/test-helper';
44

55
const Observable = Rx.Observable;
66

7+
/** @test {forkJoin} */
78
describe('Observable.forkJoin', () => {
89
it('should join the last values of the provided observables into an array', () => {
910
const e1 = Observable.forkJoin(

spec/observables/from-promise-spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import * as Rx from '../../dist/cjs/Rx';
2-
import {it, DoneSignature} from '../helpers/test-helper';
2+
import {DoneSignature} from '../helpers/test-helper';
33

44
declare const process: any;
55
const Observable = Rx.Observable;
66

7+
/** @test {fromPromise} */
78
describe('Observable.fromPromise', () => {
89
it('should emit one value from a resolved promise', (done: DoneSignature) => {
910
const promise = Promise.resolve(42);

0 commit comments

Comments
 (0)