From 4b104d7cc9391bad0b34613a204738ba60df8e1b Mon Sep 17 00:00:00 2001 From: Ward Bell Date: Sat, 21 May 2016 14:31:22 -0700 Subject: [PATCH] docs(testing): update testing setup to use systemjs.config.js --- public/docs/_examples/karma-test-shim.js | 91 +++++----------- public/docs/_examples/karma.conf.js | 1 + public/docs/_examples/systemjs.config.js | 17 +-- .../docs/_examples/testing/ts/tsconfig.1.json | 7 +- public/docs/_examples/wallaby.js | 102 +++++------------- 5 files changed, 67 insertions(+), 151 deletions(-) diff --git a/public/docs/_examples/karma-test-shim.js b/public/docs/_examples/karma-test-shim.js index bc8cf372f3..ec50e1ff66 100644 --- a/public/docs/_examples/karma-test-shim.js +++ b/public/docs/_examples/karma-test-shim.js @@ -22,72 +22,33 @@ var allSpecFiles = Object.keys(window.__karma__.files) .filter(isSpecFile) .filter(isBuiltFile); -////////////////////////// -// Load our SystemJS configuration. - -// map tells the System loader where to look for things -var map = { - 'app': 'app', - - '@angular': 'node_modules/@angular', - 'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api', - 'rxjs': 'node_modules/rxjs' -}; - -// packages tells the System loader how to load when no filename and/or no extension -var packages = { - 'app': { main: 'main.js', defaultExtension: 'js' }, - 'rxjs': { defaultExtension: 'js' }, - 'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' }, -}; - -var ngPackageNames = [ - 'common', - 'compiler', - 'core', - 'http', - 'platform-browser', - 'platform-browser-dynamic', - 'router', - 'router-deprecated', - 'upgrade', -]; - -// Add package entries for angular packages -ngPackageNames.forEach(function(pkgName) { - - // Bundled (~40 requests): DOESN'T WORK IN KARMA OR WALLABY (YET?) - //packages['@angular/'+pkgName] = { main: pkgName + '.umd.js', defaultExtension: 'js' }; - - // Individual files (~300 requests): - packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' }; +System.config({ + baseURL: '/base', + packageWithIndex: true // sadly, we can't use umd packages (yet?) }); -var config = { - baseURL: '/base', - map: map, - packages: packages -} +System.import('systemjs.config.js') + .then(function () { + return Promise.all([ + System.import('@angular/core/testing'), + System.import('@angular/platform-browser-dynamic/testing') + ]) + }) + .then(function (providers) { + var testing = providers[0]; + var testingBrowser = providers[1]; -System.config(config); -////////////// + testing.setBaseTestProviders( + testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, + testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS); -Promise.all([ - System.import('@angular/core/testing'), - System.import('@angular/platform-browser-dynamic/testing') -]).then(function (providers) { - var testing = providers[0]; - var testingBrowser = providers[1]; - - testing.setBaseTestProviders( - testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, - testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS); - -}).then(function() { - // Finally, load all spec files. - // This will run the tests directly. - return Promise.all( - allSpecFiles.map(function (moduleName) { - return System.import(moduleName); - })); -}).then(__karma__.start, __karma__.error); + }) + .then(function() { + // Finally, load all spec files. + // This will run the tests directly. + return Promise.all( + allSpecFiles.map(function (moduleName) { + return System.import(moduleName); + })); + }) + .then(__karma__.start, __karma__.error); diff --git a/public/docs/_examples/karma.conf.js b/public/docs/_examples/karma.conf.js index d39e2ffac8..faa52df98e 100644 --- a/public/docs/_examples/karma.conf.js +++ b/public/docs/_examples/karma.conf.js @@ -42,6 +42,7 @@ module.exports = function(config) { {pattern: 'node_modules/@angular/**/*.js', included: false, watched: false}, {pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: false}, + {pattern: 'systemjs.config.js', included: false, watched: false}, 'karma-test-shim.js', // transpiled application & spec code paths loaded via module imports diff --git a/public/docs/_examples/systemjs.config.js b/public/docs/_examples/systemjs.config.js index 56d5f61e5f..0cdf7d40bc 100644 --- a/public/docs/_examples/systemjs.config.js +++ b/public/docs/_examples/systemjs.config.js @@ -32,15 +32,20 @@ 'upgrade', ]; - // Add package entries for angular packages - ngPackageNames.forEach(function(pkgName) { + // Individual files (~300 requests): + function packIndex(pkgName) { + packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' }; + } - // Bundled (~40 requests): + // Bundled (~40 requests): + function packUmd(pkgName) { packages['@angular/'+pkgName] = { main: pkgName + '.umd.js', defaultExtension: 'js' }; + }; - // Individual files (~300 requests): - //packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' }; - }); + var setPackageConfig = System.packageWithIndex ? packIndex : packUmd; + + // Add package entries for angular packages + ngPackageNames.forEach(setPackageConfig); var config = { map: map, diff --git a/public/docs/_examples/testing/ts/tsconfig.1.json b/public/docs/_examples/testing/ts/tsconfig.1.json index 6ee6719cb3..062cf1bcb4 100644 --- a/public/docs/_examples/testing/ts/tsconfig.1.json +++ b/public/docs/_examples/testing/ts/tsconfig.1.json @@ -9,10 +9,5 @@ "removeComments": false, "noImplicitAny": true, "suppressImplicitAnyIndexErrors": true - }, - "exclude": [ - "node_modules", - "typings/main", - "typings/main.d.ts" - ] + } } diff --git a/public/docs/_examples/wallaby.js b/public/docs/_examples/wallaby.js index 2648c2c3aa..28053a11fe 100644 --- a/public/docs/_examples/wallaby.js +++ b/public/docs/_examples/wallaby.js @@ -8,6 +8,7 @@ module.exports = function () { files: [ // System.js for module loading {pattern: 'node_modules/systemjs/dist/system.js', instrument: false}, + {pattern: 'systemjs.config.js', instrument: false}, // Polyfills {pattern: 'node_modules/core-js/client/shim.min.js', instrument: false}, @@ -38,86 +39,39 @@ module.exports = function () { bootstrap: function (wallaby) { wallaby.delayStart(); - systemConfig(); - Promise.all([ - System.import('@angular/core/testing'), - System.import('@angular/platform-browser-dynamic/testing') - ]) - .then(function (providers) { - var testing = providers[0]; - var testingBrowser = providers[1]; - - testing.setBaseTestProviders( - testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, - testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS); - - - // Load all spec files - return Promise.all(wallaby.tests.map(function (specFile) { - return System.import(specFile); - })); - }) - .then(function () { - wallaby.start(); - }) - .catch(function (e) { - setTimeout(function () { - throw e; - }, 0); + System.config({ + packageWithIndex: true // sadly, we can't use umd packages (yet?) }); - ////////////////////////// - // SystemJS configuration. - function systemConfig() { + System.import('systemjs.config.js') + .then(function () { + return Promise.all([ + System.import('@angular/core/testing'), + System.import('@angular/platform-browser-dynamic/testing') + ]) + }) + .then(function (providers) { + var testing = providers[0]; + var testingBrowser = providers[1]; - // map tells the System loader where to look for things - var map = { - 'app': 'app', + testing.setBaseTestProviders( + testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, + testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS); - '@angular': 'node_modules/@angular', - 'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api', - 'rxjs': 'node_modules/rxjs' - }; - - // packages tells the System loader how to load when no filename and/or no extension - var packages = { - 'app': { main: 'main.js', defaultExtension: 'js' }, - 'rxjs': { defaultExtension: 'js' }, - 'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' }, - }; - - var ngPackageNames = [ - 'common', - 'compiler', - 'core', - 'http', - 'platform-browser', - 'platform-browser-dynamic', - 'router', - 'router-deprecated', - 'upgrade', - ]; - - // Add package entries for angular packages - ngPackageNames.forEach(function(pkgName) { - - // Bundled (~40 requests): DOESN'T WORK IN WALLABY OR KARMA (YET?) - // packages['@angular/'+pkgName] = { main: pkgName + '.umd.js', defaultExtension: 'js' }; - - // Individual files (~300 requests): - packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' }; + // Load all spec files + return Promise.all(wallaby.tests.map(function (specFile) { + return System.import(specFile); + })); + }) + .then(function () { + wallaby.start(); + }) + .catch(function (e) { + setTimeout(function () { + throw e; + }, 0); }); - - var config = { - map: map, - packages: packages - } - - System.config(config); - } - ////////////////// } }; - };