From a89f92eccd4a2b9f8071e2f3fbf7f96a94b97f57 Mon Sep 17 00:00:00 2001 From: Sean Larkin Date: Sat, 16 Jul 2016 14:16:56 -0500 Subject: [PATCH 1/5] fix(): Multiple fixes for path mappings: * Removed invalid test case that was throwing path mappings tests because of a typescript bug. * Readded PathsPlugin for Path Mappings * Removed coverage preprocessor which was throwing bad type errors against ts code when it shouldn't be. * Added sourcemap support for istanbul instrumenter. Coverage files are still being generated. --- .../ng2/blueprints/ng2/files/__path__/test.ts | 16 ++++++-------- .../ng2/files/__path__/tsconfig.json | 7 +------ addon/ng2/models/webpack-build-common.ts | 7 +++++-- addon/ng2/models/webpack-build-test.ts | 3 +-- addon/ng2/tasks/test.js | 2 +- package.json | 3 ++- tests/e2e/e2e_workflow.spec.js | 21 ++++++++++--------- 7 files changed, 27 insertions(+), 32 deletions(-) diff --git a/addon/ng2/blueprints/ng2/files/__path__/test.ts b/addon/ng2/blueprints/ng2/files/__path__/test.ts index 5255aeee5d09..e61005825b11 100644 --- a/addon/ng2/blueprints/ng2/files/__path__/test.ts +++ b/addon/ng2/blueprints/ng2/files/__path__/test.ts @@ -23,18 +23,14 @@ Promise.all([ let testing = providers[0]; let testingBrowser = providers[1]; - testing.setBaseTestProviders(testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, - testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS); + testing.setBaseTestProviders( + testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, + testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS + ); }); -let testContext = require.context('../src', true, /\.spec\.ts/); - -/* - * get all the files, for each file, call the context function - * that will require the file and load it up here. Context will - * loop and require those spec files here - */ -function requireAll(requireContext) { +let testContext: any = require.context('../src', true, /\.spec\.ts/); +function requireAll(requireContext: any) { return requireContext.keys().map(requireContext); } diff --git a/addon/ng2/blueprints/ng2/files/__path__/tsconfig.json b/addon/ng2/blueprints/ng2/files/__path__/tsconfig.json index 1c55b6264b90..e0831213e64c 100644 --- a/addon/ng2/blueprints/ng2/files/__path__/tsconfig.json +++ b/addon/ng2/blueprints/ng2/files/__path__/tsconfig.json @@ -10,15 +10,10 @@ "rootDir": ".", "sourceMap": true, "target": "es5", - "mapRoot": "/", - "inlinesource": true + "mapRoot": "/" }, "compileOnSave": false, "buildOnSave": false, - "exclude": [ - "node_modules", - "bower_components" - ], "includes": [ "**.d.ts" ] diff --git a/addon/ng2/models/webpack-build-common.ts b/addon/ng2/models/webpack-build-common.ts index 146671ed5501..c41045021b8f 100644 --- a/addon/ng2/models/webpack-build-common.ts +++ b/addon/ng2/models/webpack-build-common.ts @@ -1,5 +1,5 @@ import * as webpack from 'webpack'; -import {LoaderConfig} from '../utilities/ts-path-mappings-webpack-plugin'; +import {LoaderConfig, PathsPlugin} from '../utilities/ts-path-mappings-webpack-plugin'; const path = require('path'); const ForkCheckerPlugin = require('awesome-typescript-loader').ForkCheckerPlugin; @@ -18,7 +18,10 @@ export function getWebpackCommonConfig(projectRoot: string) { resolve: { extensions: ['', '.ts', '.js'], root: path.resolve(projectRoot, './src'), - moduleDirectories: ['node_modules'] + moduleDirectories: ['node_modules'], + plugins: [ + new PathsPlugin(awesomeTypescriptLoaderConfig); + ] }, context: path.resolve(__dirname, './'), entry: { diff --git a/addon/ng2/models/webpack-build-test.ts b/addon/ng2/models/webpack-build-test.ts index 6a1d15bf4410..455b5960c6c0 100644 --- a/addon/ng2/models/webpack-build-test.ts +++ b/addon/ng2/models/webpack-build-test.ts @@ -44,7 +44,6 @@ export const getWebpackTestConfig = function(projectRoot: string) { query: { useWebpackText: true, tsconfig: path.resolve(projectRoot, './src/tsconfig.json'), - // resolveGlobs: false, module: "commonjs", target: "es5", useForkChecker: true, @@ -67,7 +66,7 @@ export const getWebpackTestConfig = function(projectRoot: string) { ], postLoaders: [ { - test: /\.(js|ts)$/, loader: 'istanbul-instrumenter-loader', + test: /\.(js|ts)$/, loader: 'sourcemap-istanbul-instrumenter-loader', exclude: [ /\.(e2e|spec)\.ts$/, /node_modules/ diff --git a/addon/ng2/tasks/test.js b/addon/ng2/tasks/test.js index 5fbbcea453e5..dcf28c2f7e55 100644 --- a/addon/ng2/tasks/test.js +++ b/addon/ng2/tasks/test.js @@ -36,7 +36,7 @@ module.exports = Task.extend({ // Single test entry file. Will run the test.ts bundle and track it. options.files = [{ pattern: './src/test.ts', watched: false }]; - options.preprocessors = { './src/test.ts': ['coverage','webpack','sourcemap'] }; + options.preprocessors = { './src/test.ts': ['webpack','sourcemap'] }; options.webpack = webpackTestConfig(projectRoot); options.webpackMiddleware = { noInfo: true, // Hide webpack output because its noisy. diff --git a/package.json b/package.json index 9894e868d372..a93ccae5ae3d 100644 --- a/package.json +++ b/package.json @@ -84,6 +84,7 @@ "shelljs": "^0.7.0", "silent-error": "^1.0.0", "source-map-loader": "^0.1.5", + "sourcemap-istanbul-instrumenter-loader": "^0.2.0", "style-loader": "^0.13.1", "stylus": "^0.54.5", "stylus-loader": "^2.1.0", @@ -97,7 +98,7 @@ "typescript": "^2.0.0", "typings": "^0.8.1", "url-loader": "^0.5.7", - "webpack": "2.1.0-beta.17", + "webpack": "2.1.0-beta.18", "webpack-dev-server": "2.1.0-beta.0", "webpack-md5-hash": "0.0.5", "webpack-merge": "^0.14.0" diff --git a/tests/e2e/e2e_workflow.spec.js b/tests/e2e/e2e_workflow.spec.js index 17679fc63532..d7c982af97f6 100644 --- a/tests/e2e/e2e_workflow.spec.js +++ b/tests/e2e/e2e_workflow.spec.js @@ -43,7 +43,7 @@ describe('Basic end-to-end Workflow', function () { this.timeout(300000); sh.exec('npm link', { silent: true }); - + return tmp.setup('./tmp').then(function () { process.chdir('./tmp'); expect(existsSync(path.join(process.cwd(), 'bin', 'ng'))); @@ -446,7 +446,7 @@ describe('Basic end-to-end Workflow', function () { }); }); - xit('Turn on path mapping in tsconfig.json and rebuild', function () { + it('Turn on path mapping in tsconfig.json and rebuild', function () { this.timeout(420000); const configFilePath = path.join(process.cwd(), 'src', 'tsconfig.json'); @@ -454,21 +454,22 @@ describe('Basic end-to-end Workflow', function () { config.compilerOptions.baseUrl = ''; - // This should fail. + // #TODO: When https://github.com/Microsoft/TypeScript/issues/9772 is fixed this should fail. config.compilerOptions.paths = { '@angular/*': [] }; fs.writeFileSync(configFilePath, JSON.stringify(config, null, 2), 'utf8'); return ng(['build']) - .catch(() => { - return true; - }) - .then((passed) => { - expect(passed).to.equal(true); - }) + // #TODO: Uncomment these lines when https://github.com/Microsoft/TypeScript/issues/9772 is fixed. + // .catch(() => { + // return true; + // }) + // .then((passed) => { + // expect(passed).to.equal(true); + // }) .then(() => { // This should succeed. config.compilerOptions.paths = { - '@angular/*': [ '*' ] + '@angular/*': [ '../node_modules/@angular/*' ] }; fs.writeFileSync(configFilePath, JSON.stringify(config, null, 2), 'utf8'); }) From 4bcf239f4b301f79490c52e365e8e106d3de39e7 Mon Sep 17 00:00:00 2001 From: Sean Larkin Date: Sat, 16 Jul 2016 15:09:01 -0500 Subject: [PATCH 2/5] fix: fix the way the build command runs for mobile tests --- addon/ng2/utilities/ts-path-mappings-webpack-plugin.ts | 3 --- tests/e2e/e2e_workflow.spec.js | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/addon/ng2/utilities/ts-path-mappings-webpack-plugin.ts b/addon/ng2/utilities/ts-path-mappings-webpack-plugin.ts index 13bdeb057703..6c35b7fd3183 100644 --- a/addon/ng2/utilities/ts-path-mappings-webpack-plugin.ts +++ b/addon/ng2/utilities/ts-path-mappings-webpack-plugin.ts @@ -183,9 +183,6 @@ export class PathsPlugin implements ResolverPlugin { this.baseUrl ); - console.log("CONFIG FILE AND BASE URL"); - console.log(this.configFilePath, this.absoluteBaseUrl); - this.mappings = []; let paths = this.options.paths || {}; Object.keys(paths).forEach(alias => { diff --git a/tests/e2e/e2e_workflow.spec.js b/tests/e2e/e2e_workflow.spec.js index d7c982af97f6..8ad2184ab7ff 100644 --- a/tests/e2e/e2e_workflow.spec.js +++ b/tests/e2e/e2e_workflow.spec.js @@ -458,7 +458,7 @@ describe('Basic end-to-end Workflow', function () { config.compilerOptions.paths = { '@angular/*': [] }; fs.writeFileSync(configFilePath, JSON.stringify(config, null, 2), 'utf8'); - return ng(['build']) + return exec(`${ngBin} build`) // #TODO: Uncomment these lines when https://github.com/Microsoft/TypeScript/issues/9772 is fixed. // .catch(() => { // return true; @@ -473,7 +473,7 @@ describe('Basic end-to-end Workflow', function () { }; fs.writeFileSync(configFilePath, JSON.stringify(config, null, 2), 'utf8'); }) - .then(() => ng(['build'])) + .then(() => exec(`${ngBin} build`) .catch(() => { expect('build failed where it should have succeeded').to.equal(''); }); From e3e637becc6b6581df0356e5433c14b828e8a914 Mon Sep 17 00:00:00 2001 From: Sean Larkin Date: Sat, 16 Jul 2016 15:09:01 -0500 Subject: [PATCH 3/5] fix: fix the way the build command runs for mobile tests --- addon/ng2/utilities/ts-path-mappings-webpack-plugin.ts | 3 --- tests/e2e/e2e_workflow.spec.js | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/addon/ng2/utilities/ts-path-mappings-webpack-plugin.ts b/addon/ng2/utilities/ts-path-mappings-webpack-plugin.ts index 13bdeb057703..6c35b7fd3183 100644 --- a/addon/ng2/utilities/ts-path-mappings-webpack-plugin.ts +++ b/addon/ng2/utilities/ts-path-mappings-webpack-plugin.ts @@ -183,9 +183,6 @@ export class PathsPlugin implements ResolverPlugin { this.baseUrl ); - console.log("CONFIG FILE AND BASE URL"); - console.log(this.configFilePath, this.absoluteBaseUrl); - this.mappings = []; let paths = this.options.paths || {}; Object.keys(paths).forEach(alias => { diff --git a/tests/e2e/e2e_workflow.spec.js b/tests/e2e/e2e_workflow.spec.js index d7c982af97f6..8ad2184ab7ff 100644 --- a/tests/e2e/e2e_workflow.spec.js +++ b/tests/e2e/e2e_workflow.spec.js @@ -458,7 +458,7 @@ describe('Basic end-to-end Workflow', function () { config.compilerOptions.paths = { '@angular/*': [] }; fs.writeFileSync(configFilePath, JSON.stringify(config, null, 2), 'utf8'); - return ng(['build']) + return exec(`${ngBin} build`) // #TODO: Uncomment these lines when https://github.com/Microsoft/TypeScript/issues/9772 is fixed. // .catch(() => { // return true; @@ -473,7 +473,7 @@ describe('Basic end-to-end Workflow', function () { }; fs.writeFileSync(configFilePath, JSON.stringify(config, null, 2), 'utf8'); }) - .then(() => ng(['build'])) + .then(() => exec(`${ngBin} build`) .catch(() => { expect('build failed where it should have succeeded').to.equal(''); }); From 0647737eb8cb879e6d585aa7c141c97b8072e106 Mon Sep 17 00:00:00 2001 From: Sean Larkin Date: Sun, 17 Jul 2016 10:15:59 -0500 Subject: [PATCH 4/5] fix: replaced promise based ng command with sh.exec to allow mappings test to run correctly against mobile --- tests/e2e/e2e_workflow.spec.js | 38 +++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/tests/e2e/e2e_workflow.spec.js b/tests/e2e/e2e_workflow.spec.js index 25276baa01fc..3864e7fc9c89 100644 --- a/tests/e2e/e2e_workflow.spec.js +++ b/tests/e2e/e2e_workflow.spec.js @@ -458,25 +458,25 @@ describe('Basic end-to-end Workflow', function () { config.compilerOptions.paths = { '@angular/*': [] }; fs.writeFileSync(configFilePath, JSON.stringify(config, null, 2), 'utf8'); - return exec(`${ngBin} build`) - // #TODO: Uncomment these lines when https://github.com/Microsoft/TypeScript/issues/9772 is fixed. - // .catch(() => { - // return true; - // }) - // .then((passed) => { - // expect(passed).to.equal(true); - // }) - .then(() => { - // This should succeed. - config.compilerOptions.paths = { - '@angular/*': [ '../node_modules/@angular/*' ] - }; - fs.writeFileSync(configFilePath, JSON.stringify(config, null, 2), 'utf8'); - }) - .then(() => exec(`${ngBin} build`)) - .catch(() => { - expect('build failed where it should have succeeded').to.equal(''); - }); + sh.exec(`${ngBin} build`); + // #TODO: Uncomment these lines when https://github.com/Microsoft/TypeScript/issues/9772 is fixed. + // .catch(() => { + // return true; + // }) + // .then((passed) => { + // expect(passed).to.equal(true); + // }) + + // This should succeed. + config.compilerOptions.paths = { + '@angular/*': [ '../node_modules/@angular/*' ] + }; + fs.writeFileSync(configFilePath, JSON.stringify(config, null, 2), 'utf8'); + sh.exec(`${ngBin} build`); + + expect(existsSync(path.join(process.cwd(), 'dist'))).to.be.equal(true); + const indexHtml = fs.readFileSync(path.join(process.cwd(), 'dist/index.html'), 'utf-8'); + expect(indexHtml).to.include('main.bundle.js'); }); it('Serve and run e2e tests after all other commands', function () { From d9ca32237b78cef04e77eb1f9024d4ed36abbdab Mon Sep 17 00:00:00 2001 From: Sean Larkin Date: Sat, 16 Jul 2016 15:09:01 -0500 Subject: [PATCH 5/5] fix: replaced promise based ng command with sh.exec to allow mappings test to run correctly against mobile --- .../ts-path-mappings-webpack-plugin.ts | 3 -- tests/e2e/e2e_workflow.spec.js | 38 +++++++++---------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/addon/ng2/utilities/ts-path-mappings-webpack-plugin.ts b/addon/ng2/utilities/ts-path-mappings-webpack-plugin.ts index 13bdeb057703..6c35b7fd3183 100644 --- a/addon/ng2/utilities/ts-path-mappings-webpack-plugin.ts +++ b/addon/ng2/utilities/ts-path-mappings-webpack-plugin.ts @@ -183,9 +183,6 @@ export class PathsPlugin implements ResolverPlugin { this.baseUrl ); - console.log("CONFIG FILE AND BASE URL"); - console.log(this.configFilePath, this.absoluteBaseUrl); - this.mappings = []; let paths = this.options.paths || {}; Object.keys(paths).forEach(alias => { diff --git a/tests/e2e/e2e_workflow.spec.js b/tests/e2e/e2e_workflow.spec.js index d7c982af97f6..3864e7fc9c89 100644 --- a/tests/e2e/e2e_workflow.spec.js +++ b/tests/e2e/e2e_workflow.spec.js @@ -458,25 +458,25 @@ describe('Basic end-to-end Workflow', function () { config.compilerOptions.paths = { '@angular/*': [] }; fs.writeFileSync(configFilePath, JSON.stringify(config, null, 2), 'utf8'); - return ng(['build']) - // #TODO: Uncomment these lines when https://github.com/Microsoft/TypeScript/issues/9772 is fixed. - // .catch(() => { - // return true; - // }) - // .then((passed) => { - // expect(passed).to.equal(true); - // }) - .then(() => { - // This should succeed. - config.compilerOptions.paths = { - '@angular/*': [ '../node_modules/@angular/*' ] - }; - fs.writeFileSync(configFilePath, JSON.stringify(config, null, 2), 'utf8'); - }) - .then(() => ng(['build'])) - .catch(() => { - expect('build failed where it should have succeeded').to.equal(''); - }); + sh.exec(`${ngBin} build`); + // #TODO: Uncomment these lines when https://github.com/Microsoft/TypeScript/issues/9772 is fixed. + // .catch(() => { + // return true; + // }) + // .then((passed) => { + // expect(passed).to.equal(true); + // }) + + // This should succeed. + config.compilerOptions.paths = { + '@angular/*': [ '../node_modules/@angular/*' ] + }; + fs.writeFileSync(configFilePath, JSON.stringify(config, null, 2), 'utf8'); + sh.exec(`${ngBin} build`); + + expect(existsSync(path.join(process.cwd(), 'dist'))).to.be.equal(true); + const indexHtml = fs.readFileSync(path.join(process.cwd(), 'dist/index.html'), 'utf-8'); + expect(indexHtml).to.include('main.bundle.js'); }); it('Serve and run e2e tests after all other commands', function () {