diff --git a/spec/helpers/polyfills.ts b/spec/helpers/polyfills.ts new file mode 100644 index 0000000000..1d5a5e2df4 --- /dev/null +++ b/spec/helpers/polyfills.ts @@ -0,0 +1,11 @@ +if (typeof Symbol !== 'function') { + let id = 0; + const symbolFn: any = (description: string) => + `Symbol_${id++} ${description} (RxJS Testing Polyfill)`; + + Symbol = symbolFn; +} + +if (!(Symbol as any).observable) { + (Symbol as any).observable = Symbol('Symbol.observable polyfill from RxJS Testing'); +} diff --git a/spec/support/coverage.opts b/spec/support/coverage.opts index dd16ba8048..2c874036c1 100644 --- a/spec/support/coverage.opts +++ b/spec/support/coverage.opts @@ -1,3 +1,4 @@ +--require spec/helpers/polyfills.ts --require spec/helpers/testScheduler-ui.ts --ui spec/helpers/testScheduler-ui.ts @@ -6,4 +7,4 @@ --globals WebSocket,FormData,XDomainRequest,ActiveXObject --recursive ---timeout 5000 \ No newline at end of file +--timeout 5000 diff --git a/spec/support/default.opts b/spec/support/default.opts index 10a6277758..6445aa55ab 100644 --- a/spec/support/default.opts +++ b/spec/support/default.opts @@ -1,3 +1,4 @@ +--require .out/spec/helpers/polyfills.ts --require .out/spec/helpers/testScheduler-ui.js --ui .out/spec/helpers/testScheduler-ui.js diff --git a/spec/support/tests2png.opts b/spec/support/tests2png.opts index 95fa6aa2ef..bb52156e4c 100644 --- a/spec/support/tests2png.opts +++ b/spec/support/tests2png.opts @@ -1,3 +1,4 @@ +--require spec-js/helpers/polyfills.ts --require source-map-support/register --require spec/helpers/tests2png/diagram-test-runner.ts --require spec/helpers/testScheduler-ui.ts @@ -6,4 +7,4 @@ --reporter dot --recursive ---timeout 5000 \ No newline at end of file +--timeout 5000 diff --git a/spec/support/webpack.mocha.config.js b/spec/support/webpack.mocha.config.js index dc4ac15129..c9e2d6b624 100644 --- a/spec/support/webpack.mocha.config.js +++ b/spec/support/webpack.mocha.config.js @@ -3,7 +3,7 @@ var path = require('path'); var glob = require('glob'); var webpack = require('webpack'); -var globPattern = 'spec-js/**/!(mocha.sauce.gruntfile|mocha.sauce.runner|webpack.mocha.config|painter|diagram-test-runner|testScheduler-ui).js'; +var globPattern = 'spec-js/**/!(mocha.sauce.gruntfile|mocha.sauce.runner|webpack.mocha.config|painter|diagram-test-runner|polyfills|testScheduler-ui).js'; var files = _.map(glob.sync(globPattern), function (x) { return path.resolve('./', x); }); @@ -18,6 +18,7 @@ module.exports = { }, entry: { + 'browser.polyfills': './spec-js/helpers/polyfills.js', 'browser.testscheduler': './spec-js/helpers/testScheduler-ui.js', 'browser.spec': files }, @@ -31,4 +32,4 @@ module.exports = { new webpack.optimize.CommonsChunkPlugin('browser.common.js'), new webpack.IgnorePlugin(/^mocha$/) ] -}; \ No newline at end of file +}; diff --git a/spec/symbol/observable-polyfilled-spec.ts b/spec/symbol/observable-polyfilled-spec.ts deleted file mode 100644 index 79891d3b5f..0000000000 --- a/spec/symbol/observable-polyfilled-spec.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { expect } from 'chai'; - -import { getSymbolObservable } from '../../src/internal/symbol/observable'; - -describe('observable symbol', () => { - it('should exist in the proper form when Symbol does not exist', () => { - let $$observable = getSymbolObservable({Symbol: undefined}); - expect($$observable).to.equal('@@observable'); - }); -}); diff --git a/spec/symbol/observable-spec.ts b/spec/symbol/observable-spec.ts deleted file mode 100644 index 62b789be1a..0000000000 --- a/spec/symbol/observable-spec.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { expect } from 'chai'; -import $$symbolObservable from 'symbol-observable'; - -import { root } from '../../src/internal/util/root'; -import { getSymbolObservable } from '../../src/internal/symbol/observable'; - -describe('observable symbol', () => { - it('should exist in the proper form', () => { - let $$observable = getSymbolObservable(root); - if (root.Symbol && root.Symbol.for) { - expect($$observable).to.equal($$symbolObservable); - } else { - expect($$observable).to.equal('@@observable'); - } - }); -}); diff --git a/src/internal/symbol/observable.ts b/src/internal/symbol/observable.ts index 4940e85123..e5b8e55ae6 100644 --- a/src/internal/symbol/observable.ts +++ b/src/internal/symbol/observable.ts @@ -1,32 +1,13 @@ import { root } from '../util/root'; -export function getSymbolObservable(context: { Symbol: SymbolConstructor; }): symbol { - let $$observable: symbol; - let Symbol = context.Symbol; - - if (typeof Symbol === 'function') { - if (Symbol.observable) { - $$observable = Symbol.observable; - } else { - $$observable = Symbol('observable'); - Symbol.observable = $$observable; - } - } else { - $$observable = '@@observable'; - } - - return $$observable; -} - -export const observable = getSymbolObservable(root); - -/** - * @deprecated use observable instead - */ -export const $$observable = observable; - +/** Symbol.observable addition */ +/* Note: This will add Symbol.observable globally for all TypeScript users, + however, we are no longer polyfilling Symbol.observable */ declare global { interface SymbolConstructor { observable: symbol; } -} \ No newline at end of file +} + +/** Symbol.observable or a string "@@observable". Used for interop */ +export const observable = typeof Symbol === 'function' && Symbol.observable || '@@observable';