From f57df3cf8a5038af04ae861877aca3a1eda8f2fc Mon Sep 17 00:00:00 2001 From: vsavkin Date: Fri, 20 May 2016 13:22:57 -0700 Subject: [PATCH] chore: set up test and build infrastructure --- modules/@angular/router/.gitignore | 5 ++ modules/@angular/router/LICENSE | 21 +++++ modules/@angular/router/karma-test-shim.js | 87 +++++++++++++++++++ modules/@angular/router/karma.conf.js | 49 +++++++++++ modules/@angular/router/package.json | 68 +++++++++++++++ modules/@angular/router/src/router.ts | 1 + modules/@angular/router/test/router.spec.ts | 7 ++ .../router/tools/rewrite-published-package.js | 17 ++++ modules/@angular/router/tsconfig.json | 20 +++++ .../@angular/router/tsconfig.publish.es5.json | 19 ++++ .../@angular/router/tsconfig.publish.es6.json | 18 ++++ modules/@angular/router/tsd.json | 12 +++ 12 files changed, 324 insertions(+) create mode 100644 modules/@angular/router/.gitignore create mode 100644 modules/@angular/router/LICENSE create mode 100644 modules/@angular/router/karma-test-shim.js create mode 100644 modules/@angular/router/karma.conf.js create mode 100644 modules/@angular/router/package.json create mode 100644 modules/@angular/router/src/router.ts create mode 100644 modules/@angular/router/test/router.spec.ts create mode 100644 modules/@angular/router/tools/rewrite-published-package.js create mode 100644 modules/@angular/router/tsconfig.json create mode 100644 modules/@angular/router/tsconfig.publish.es5.json create mode 100644 modules/@angular/router/tsconfig.publish.es6.json create mode 100644 modules/@angular/router/tsd.json diff --git a/modules/@angular/router/.gitignore b/modules/@angular/router/.gitignore new file mode 100644 index 0000000000..8833d1c5fe --- /dev/null +++ b/modules/@angular/router/.gitignore @@ -0,0 +1,5 @@ +node_modules/ +dist/ +typings/ +npm-debug.log +.idea/ \ No newline at end of file diff --git a/modules/@angular/router/LICENSE b/modules/@angular/router/LICENSE new file mode 100644 index 0000000000..81ce7966e9 --- /dev/null +++ b/modules/@angular/router/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2016 Google, Inc. http://angular.io + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/modules/@angular/router/karma-test-shim.js b/modules/@angular/router/karma-test-shim.js new file mode 100644 index 0000000000..17c1caa62c --- /dev/null +++ b/modules/@angular/router/karma-test-shim.js @@ -0,0 +1,87 @@ +/*global jasmine, __karma__, window*/ +Error.stackTraceLimit = Infinity; +jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; + +__karma__.loaded = function () { +}; + + +function isJsFile(path) { + return path.slice(-3) == '.js'; +} + +function isSpecFile(path) { + return path.slice(-7) == 'spec.js'; +} + +function isBuiltFile(path) { + var builtPath = '/base/dist/'; + return isJsFile(path) && (path.substr(0, builtPath.length) == builtPath); +} + +var allSpecFiles = Object.keys(window.__karma__.files) + .filter(isSpecFile) + .filter(isBuiltFile); + +// Load our SystemJS configuration. +System.config({ + baseURL: '/base' +}); + +System.config( + { + map: { + 'rxjs': 'node_modules/rxjs', + '@angular': 'node_modules/@angular', + 'app': 'dist' + }, + packages: { + 'app': { + main: 'main.js', + defaultExtension: 'js' + }, + '@angular/core': { + main: 'index.js', + defaultExtension: 'js' + }, + '@angular/compiler': { + main: 'index.js', + defaultExtension: 'js' + }, + '@angular/common': { + main: 'index.js', + defaultExtension: 'js' + }, + '@angular/platform-browser': { + main: 'index.js', + defaultExtension: 'js' + }, + '@angular/platform-browser-dynamic': { + main: 'index.js', + defaultExtension: 'js' + }, + 'rxjs': { + main: 'Rx.js', + defaultExtension: 'js' + } + } + }); + +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); \ No newline at end of file diff --git a/modules/@angular/router/karma.conf.js b/modules/@angular/router/karma.conf.js new file mode 100644 index 0000000000..6abac67477 --- /dev/null +++ b/modules/@angular/router/karma.conf.js @@ -0,0 +1,49 @@ +// Karma configuration +module.exports = function(config) { + config.set({ + + basePath: '', + + frameworks: ['jasmine'], + + files: [ + // Polyfills. + 'node_modules/es6-shim/es6-shim.js', + + 'node_modules/reflect-metadata/Reflect.js', + + // System.js for module loading + 'node_modules/systemjs/dist/system-polyfills.js', + 'node_modules/systemjs/dist/system.src.js', + + // Zone.js dependencies + 'node_modules/zone.js/dist/zone.js', + 'node_modules/zone.js/dist/jasmine-patch.js', + 'node_modules/zone.js/dist/async-test.js', + + // RxJs. + { pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false }, + { pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false }, + + + {pattern: 'karma-test-shim.js', included: true, watched: true}, + {pattern: 'built/test/matchers.js', included: true, watched: true}, + + // paths loaded via module imports + // Angular itself + {pattern: 'node_modules/@angular/**/*.js', included: false, watched: true}, + {pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: true}, + + {pattern: 'dist/**/*.js', included: false, watched: true}, + {pattern: 'dist/**/*.js.map', included: false, watched: false} + ], + + reporters: ['mocha'], + port: 9876, + colors: true, + logLevel: config.LOG_INFO, + autoWatch: true, + browsers: ['Chrome'], + singleRun: false + }) +}; \ No newline at end of file diff --git a/modules/@angular/router/package.json b/modules/@angular/router/package.json new file mode 100644 index 0000000000..36908838da --- /dev/null +++ b/modules/@angular/router/package.json @@ -0,0 +1,68 @@ +{ + "name": "vladivostok", + "version": "0.9.1", + "description": "", + "main": "./dist/router.js", + "jsnext:main": "./dist/es6/router.js", + "scripts": { + "karma": "karma start", + "test": "npm run build; karma start", + "build_watch": "rm -rf dist; tsc -w", + "build": "rm -rf dist; tsc", + "build_npm": "rm -rf dist && tsc -p tsconfig.publish.es5.json && tsc -p tsconfig.publish.es6.json", + "postbuild_npm": "cp package.json README.md dist/ && npm run rewrite_npm_package", + "rewrite_npm_package": "node --harmony_destructuring tools/rewrite-published-package.js", + "build_bundle": "cp -r src router && tsc typings/tsd.d.ts src/router.ts --rootDir . --module system -t es5 --outFile dist/bundles/router.js --moduleResolution node --emitDecoratorMetadata --experimentalDecorators" + }, + "keywords": [ + "angular2", + "angular", + "router" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/angular/vladivostok.git" + }, + "author": "vsavkin", + "license": "MIT", + "bugs": { + "url": "https://github.com/angular/vladivostok/issues" + }, + "homepage": "https://github.com/angular/vladivostok#readme", + "dependencies": { + "@angular/core": "2.0.0-rc.1", + "@angular/platform-browser": "2.0.0-rc.1", + "@angular/common": "2.0.0-rc.1", + "@angular/compiler": "2.0.0-rc.1", + "@angular/platform-browser-dynamic": "2.0.0-rc.1", + "rxjs": "5.0.0-beta.6" + }, + "devDependencies": { + "es6-module-loader": "^0.17.10", + "es6-shim": "^0.35.0", + "gulp": "^3.9.0", + "gulp-jasmine": "^2.2.1", + "gulp-typescript": "^2.10.0", + "http-server": "^0.8.5", + "jasmine": "^2.4.1", + "jasmine-core": "^2.4.1", + "json": "^9.0.3", + "karma": "^0.13.19", + "karma-chrome-launcher": "^0.2.2", + "karma-firefox-launcher": "^0.1.7", + "karma-jasmine": "^0.3.6", + "karma-mocha-reporter": "^2.0.2", + "karma-systemjs": "^0.10.0", + "parse5": "^1.3.2", + "protractor": "3.0.0", + "reflect-metadata": "0.1.2", + "systemjs": "^0.19.16", + "systemjs-builder": "^0.15.7", + "traceur": "0.0.96", + "tsd": "^0.6.5", + "typescript": "1.8.9", + "typings": "^0.6.2", + "zone.js": "^0.6.6" + }, + "typings": "dist/router.d.ts" +} \ No newline at end of file diff --git a/modules/@angular/router/src/router.ts b/modules/@angular/router/src/router.ts new file mode 100644 index 0000000000..4ad8593add --- /dev/null +++ b/modules/@angular/router/src/router.ts @@ -0,0 +1 @@ +export const X = 100; \ No newline at end of file diff --git a/modules/@angular/router/test/router.spec.ts b/modules/@angular/router/test/router.spec.ts new file mode 100644 index 0000000000..e149bda8ef --- /dev/null +++ b/modules/@angular/router/test/router.spec.ts @@ -0,0 +1,7 @@ +import {X} from '../src/router'; + +describe("Test", () => { + it("test", () => { + expect(X).toEqual(5); + }); +}); diff --git a/modules/@angular/router/tools/rewrite-published-package.js b/modules/@angular/router/tools/rewrite-published-package.js new file mode 100644 index 0000000000..924ecd5ca6 --- /dev/null +++ b/modules/@angular/router/tools/rewrite-published-package.js @@ -0,0 +1,17 @@ +/** + * Rewrite the package.json that gets published to npm. + * * Change main to point to router.js instead of dist/router.js + * * Change angular2 to be a peer dependency + */ +var fs = require('fs'); +var srcPackage = require('../package.json'); +var [MAIN, JSNEXT_MAIN] = ['main', 'jsnext:main'].map(k => srcPackage[k].replace('/dist/', '/')); +var outPackage = Object.assign({}, srcPackage, { + peerDependencies: srcPackage.dependencies, + main: MAIN, + typings: "router.d.ts", + "jsnext:main": JSNEXT_MAIN, + dependencies: undefined +}); + +fs.writeFileSync('./dist/package.json', JSON.stringify(outPackage, null, 2)); \ No newline at end of file diff --git a/modules/@angular/router/tsconfig.json b/modules/@angular/router/tsconfig.json new file mode 100644 index 0000000000..c73203ecaa --- /dev/null +++ b/modules/@angular/router/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "module": "commonjs", + "target": "es5", + "noImplicitAny": false, + "outDir": "dist", + "rootDir": ".", + "sourceMap": true, + "sourceRoot": "./", + "declaration": true, + "removeComments": true + }, + "files": [ + "src/router.ts", + "test/router.spec.ts", + "typings/tsd" + ] +} \ No newline at end of file diff --git a/modules/@angular/router/tsconfig.publish.es5.json b/modules/@angular/router/tsconfig.publish.es5.json new file mode 100644 index 0000000000..8b5bd27471 --- /dev/null +++ b/modules/@angular/router/tsconfig.publish.es5.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "module": "commonjs", + "target": "es5", + "noImplicitAny": false, + "outDir": "dist", + "rootDir": "src", + "sourceMap": true, + "sourceRoot": "./", + "declaration": true, + "removeComments": true + }, + "files": [ + "src/router.ts", + "typings/tsd.d.ts" + ] +} \ No newline at end of file diff --git a/modules/@angular/router/tsconfig.publish.es6.json b/modules/@angular/router/tsconfig.publish.es6.json new file mode 100644 index 0000000000..1f03068c17 --- /dev/null +++ b/modules/@angular/router/tsconfig.publish.es6.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "target": "es6", + "noImplicitAny": false, + "outDir": "dist/es6", + "rootDir": "src", + "sourceMap": true, + "sourceRoot": "./", + "declaration": true, + "removeComments": true, + "moduleResolution": "node" + }, + "files": [ + "src/router.ts" + ] +} \ No newline at end of file diff --git a/modules/@angular/router/tsd.json b/modules/@angular/router/tsd.json new file mode 100644 index 0000000000..212a4543f8 --- /dev/null +++ b/modules/@angular/router/tsd.json @@ -0,0 +1,12 @@ +{ + "version": "v4", + "repo": "borisyankov/DefinitelyTyped", + "ref": "master", + "path": "typings", + "bundle": "typings/tsd.d.ts", + "installed": { + "jasmine/jasmine.d.ts": { + "commit": "e0abafb1a6ff652f7ff967120e312d5c1916eaef" + } + } +}