Skip to content
This repository has been archived by the owner on Jul 30, 2018. It is now read-only.

Commit

Permalink
Adding polyfills, issue #106
Browse files Browse the repository at this point in the history
  • Loading branch information
rorticus committed Sep 11, 2017
1 parent 499e736 commit 3e72e05
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 38 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"typescript": "~2.4.1"
},
"dependencies": {
"pepjs": "^0.4.2",
"tslib": "^1.7.1"
}
}
12 changes: 12 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ import * as string from './string';
import Symbol from './Symbol';
import WeakMap from './WeakMap';

`!has('es6-promise')`;
import './Promise';

`!has('es6-symbol')`;
import './Symbol';
import has from '@dojo/has/has';

if (has('host-browser')) {
require('pepjs');
require('intersection-observer');
}

export {
array,
iterator,
Expand Down
39 changes: 39 additions & 0 deletions src/util/amd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
function addIfNotPresent(packages: any[], newPackage: any) {
if (packages.some((pack) => pack.name === newPackage.name)) {
return;
}

packages.push(newPackage);
}

// tslint:disable-next-line
function shimAmdDependencies(config: any) {
let packages = config.packages || [];

addIfNotPresent(packages, {
name: 'tslib',
location: 'node_modules/tslib',
main: 'tslib'
});

addIfNotPresent(packages, {
name: 'pepjs',
location: 'node_modules/pepjs/dist',
main: 'pep'
});

addIfNotPresent(packages, {
name: 'intersection-observer',
location: 'node_modules/intersection-observer',
main: 'intersection-observer'
});

addIfNotPresent(packages, {
name: '@dojo',
location: 'node_modules/@dojo'
});

config.packages = packages;

return config;
}
14 changes: 7 additions & 7 deletions tests/functional/asyncAwait.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
</head>

<body>
<script src="../../src/util/amd.js"></script>
<script src="../../../node_modules/@dojo/loader/loader.js"></script>
<script>
require.config({
packages: [
{ name: '@dojo', location: '../../../node_modules/@dojo' }
]
});
require.config(shimAmdDependencies({
baseUrl: '../../../'
}));
require([
'./dojoPromise'
], function(main) {
'_build/src/main',
'_build/tests/functional/dojoPromise'
], function(unused, main) {
main.default(function(value) {
window.callbackValue = value;
});
Expand Down
6 changes: 3 additions & 3 deletions tests/functional/asyncAwait.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import pollUntil from '@theintern/leadfoot/helpers/pollUntil';
registerSuite('asyncAwait', {
'Async/Await with Bluebird'() {
return this.remote
.get((<any> require).toUrl('./bluebird.html'))
.get('/_build/tests/functional/bluebird.html')
.then(pollUntil(function () {
return (<any> window).callbackValue;
}, undefined, 5000), undefined)
Expand All @@ -16,7 +16,7 @@ registerSuite('asyncAwait', {

'Async/Await with Dojo'() {
return this.remote
.get((<any> require).toUrl('./asyncAwait.html'))
.get('/_build/tests/functional/asyncAwait.html')
.then(pollUntil(function () {
return (<any> window).callbackValue;
}, undefined, 5000), undefined)
Expand All @@ -27,7 +27,7 @@ registerSuite('asyncAwait', {

'Async/Await with Bluebird and Dojo'() {
return this.remote
.get((<any> require).toUrl('./bluebirdAndDojo.html'))
.get('/_build/tests/functional/bluebirdAndDojo.html')
.then(pollUntil(function () {
return (<any> window).callbackValue;
}, undefined, 5000), undefined)
Expand Down
9 changes: 7 additions & 2 deletions tests/functional/bluebird.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
</head>

<body>
<script src="../../src/util/amd.js"></script>
<script src="https://cdn.jsdelivr.net/bluebird/latest/bluebird.core.min.js"></script>
<script src="../../../node_modules/@dojo/loader/loader.js"></script>
<script>
require.config(shimAmdDependencies({
baseUrl: '../../../'
}));
require([
'./nativePromise'
], function(main) {
'_build/src/main',
'_build/tests/functional/nativePromise'
], function(unused, main) {
main.default(function(value) {
window.callbackValue = value;
});
Expand Down
14 changes: 7 additions & 7 deletions tests/functional/bluebirdAndDojo.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
</head>

<body>
<script src="../../src/util/amd.js"></script>
<script src="https://cdn.jsdelivr.net/bluebird/latest/bluebird.core.min.js"></script>
<script src="../../../node_modules/@dojo/loader/loader.js"></script>
<script>
require.config({
packages: [
{ name: '@dojo', location: '../../../node_modules/@dojo' }
]
});
require.config(shimAmdDependencies({
baseUrl: '../../../'
}));
require([
'./dojoPromise'
], function(main) {
'_build/src/main',
'_build/tests/functional/dojoPromise'
], function(unused, main) {
main.default(function(value) {
window.callbackValue = value;
});
Expand Down
20 changes: 4 additions & 16 deletions tests/intern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,15 @@ export const capabilities = {
// Maximum number of simultaneous integration tests that should be executed on the remote WebDriver service
export const maxConcurrency = 5;

// Configuration options for the module loader; any AMD configuration options supported by the specified AMD loader
// can be used here
export const loader = {
script: 'dojo2',
options: {
// Packages that should be registered with the loader in each testing environment
packages: [
{ name: 'src', location: '_build/src' },
{ name: 'tests', location: '_build/tests' },
{ name: 'dojo', location: 'node_modules/intern/node_modules/dojo' },
{ name: 'grunt-dojo2', location: 'node_modules/grunt-dojo2'},
{ name: '@dojo', location: 'node_modules/@dojo' }
]
}
export const browser = {
loader: './_build/tests/loader.js'
};

// Non-functional test suite(s) to run in each browser
export const suites = 'tests/unit/all';
export const suites = ['_build/src/main.js', '_build/tests/unit/all.js'];

// Functional test suite(s) to run in each browser once non-functional tests are completed
export const functionalSuites = 'tests/functional/all';
export const functionalSuites = '_build/tests/functional/all';

// A regular expression matching URLs to files that should not be included in code coverage analysis
export const coverage = [
Expand Down
16 changes: 16 additions & 0 deletions tests/loader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
intern.registerLoader((options) => {
return intern.loadScript('node_modules/@dojo/loader/loader.js')
.then(() => intern.loadScript('./_build/src/util/amd.js'))
.then(() => {
(<any> require).config(shimAmdDependencies({
baseUrl: options.baseUrl || intern.config.basePath,
packages: []
}));

return (modules: string[]) => {
return new Promise<void>((resolve, reject) => {
(<any> require)(modules, () => resolve());
});
};
});
});
2 changes: 1 addition & 1 deletion tests/unit/array.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as array from '../../src/array';
import has, { add as hasAdd } from '../../src/support/has';
import { Iterable, ShimIterator } from '../../src/iterator';
import 'src/Symbol';
import '../../src/Symbol';

const { registerSuite } = intern.getInterface('object');
const { assert } = intern.getPlugin('chai');
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/object.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as object from '../../src/object';
import { assign } from '../../src/object';
import 'src/Symbol';
import '../../src/Symbol';

const { registerSuite } = intern.getInterface('object');
const { assert } = intern.getPlugin('chai');
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"moduleResolution": "node",
"strictNullChecks": true,
"noImplicitThis": true,
"importHelpers": true,
"types": [ "intern" ],
"typeRoots": [
"./node_modules/@types",
Expand Down

0 comments on commit 3e72e05

Please sign in to comment.