From c21e1a972c0a75acc3f695d7822deb17c86f2000 Mon Sep 17 00:00:00 2001 From: Yonatan Date: Sat, 12 Nov 2016 21:05:55 +0200 Subject: [PATCH 1/3] fix(karma): Enable test of global scripts Fixes https://github.com/angular/angular-cli/issues/2897 --- packages/angular-cli/tasks/test.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/packages/angular-cli/tasks/test.ts b/packages/angular-cli/tasks/test.ts index 56ba9e1c1d87..7b4ce2831957 100644 --- a/packages/angular-cli/tasks/test.ts +++ b/packages/angular-cli/tasks/test.ts @@ -28,6 +28,27 @@ export default Task.extend({ // Assign additional karmaConfig options to the local ngapp config options.configFile = karmaConfig; + options.files = [ + { pattern: './src/test.ts', watched: false } + ]; + + // get the project's global scripts + const scripts = this.project.ngConfig.config.apps[0].scripts; + // if scripts exist, we should add them to Karma files + if (scripts.length){ + // add each script to the files array + options.files.push.apply(options.files, scripts.map((script) => { + // if script has node modules in it, we assume it is something local + // otherwise we just take it as a URL + + if (script.indexOf('node_modules') > -1){ + //script = path.resolve(path.join(rootPath, script)); + script = script.replace('..', '.'); + } + + return { pattern: script, watched: false, included: true, served: true }; + })); + } // :shipit: const karmaServer = new karma.Server(options, resolve); karmaServer.start(); From 636460194eeea64c465ca04ecd141c1d3c0cd387 Mon Sep 17 00:00:00 2001 From: Yonatan Date: Sat, 12 Nov 2016 21:27:39 +0200 Subject: [PATCH 2/3] Fix linting --- packages/angular-cli/tasks/test.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/angular-cli/tasks/test.ts b/packages/angular-cli/tasks/test.ts index 7b4ce2831957..305813316563 100644 --- a/packages/angular-cli/tasks/test.ts +++ b/packages/angular-cli/tasks/test.ts @@ -2,14 +2,14 @@ const Task = require('../ember-cli/lib/models/task'); import * as path from 'path'; // require dependencies within the target project -function requireDependency(root: string, moduleName: string) { +function requireDependency(root:string, moduleName:string) { const packageJson = require(path.join(root, 'node_modules', moduleName, 'package.json')); const main = path.normalize(packageJson.main); return require(path.join(root, 'node_modules', moduleName, main)); } export default Task.extend({ - run: function (options: any) { + run: function (options:any) { const projectRoot = this.project.root; return new Promise((resolve) => { const karma = requireDependency(projectRoot, 'karma'); @@ -29,24 +29,24 @@ export default Task.extend({ options.configFile = karmaConfig; options.files = [ - { pattern: './src/test.ts', watched: false } + {pattern: './src/test.ts', watched: false} ]; // get the project's global scripts const scripts = this.project.ngConfig.config.apps[0].scripts; // if scripts exist, we should add them to Karma files - if (scripts.length){ + if (scripts.length) { // add each script to the files array - options.files.push.apply(options.files, scripts.map((script) => { + options.files.push.apply(options.files, scripts.map((script:any) => { // if script has node modules in it, we assume it is something local // otherwise we just take it as a URL - if (script.indexOf('node_modules') > -1){ - //script = path.resolve(path.join(rootPath, script)); + if (script.indexOf('node_modules') > -1) { + // script = path.resolve(path.join(rootPath, script)); script = script.replace('..', '.'); } - return { pattern: script, watched: false, included: true, served: true }; + return {pattern: script, watched: false, included: true, served: true}; })); } // :shipit: From be381139bc2ff3b39bc2ef338b29723e21fe9c08 Mon Sep 17 00:00:00 2001 From: Yonatan Date: Sat, 12 Nov 2016 21:29:30 +0200 Subject: [PATCH 3/3] Some more linting issues --- packages/angular-cli/tasks/test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/angular-cli/tasks/test.ts b/packages/angular-cli/tasks/test.ts index 305813316563..43527b5ac5cf 100644 --- a/packages/angular-cli/tasks/test.ts +++ b/packages/angular-cli/tasks/test.ts @@ -2,14 +2,14 @@ const Task = require('../ember-cli/lib/models/task'); import * as path from 'path'; // require dependencies within the target project -function requireDependency(root:string, moduleName:string) { +function requireDependency(root: string, moduleName: string) { const packageJson = require(path.join(root, 'node_modules', moduleName, 'package.json')); const main = path.normalize(packageJson.main); return require(path.join(root, 'node_modules', moduleName, main)); } export default Task.extend({ - run: function (options:any) { + run: function (options: any) { const projectRoot = this.project.root; return new Promise((resolve) => { const karma = requireDependency(projectRoot, 'karma'); @@ -37,7 +37,7 @@ export default Task.extend({ // if scripts exist, we should add them to Karma files if (scripts.length) { // add each script to the files array - options.files.push.apply(options.files, scripts.map((script:any) => { + options.files.push.apply(options.files, scripts.map((script: any) => { // if script has node modules in it, we assume it is something local // otherwise we just take it as a URL