diff --git a/packages/angular_devkit/build_angular/src/angular-cli-files/plugins/karma.ts b/packages/angular_devkit/build_angular/src/angular-cli-files/plugins/karma.ts index ca4958baf4a9..adbda0f12dab 100644 --- a/packages/angular_devkit/build_angular/src/angular-cli-files/plugins/karma.ts +++ b/packages/angular_devkit/build_angular/src/angular-cli-files/plugins/karma.ts @@ -19,6 +19,7 @@ import { getWebpackStatsConfig } from '../models/webpack-configs/stats'; import { createConsoleLogger } from '@angular-devkit/core/node'; import { logging } from '@angular-devkit/core'; import { WebpackTestOptions } from '../models/build-options'; +import { normalizeSourceMaps } from '../../utils/index'; /** * Enumerate needed (but not require/imported) dependencies from this file @@ -78,7 +79,7 @@ const init: any = (config: any, emitter: any, customFileHandlers: any) => { } // Add a reporter that fixes sourcemap urls. - if (options.sourceMap.scripts) { + if (normalizeSourceMaps(options.sourceMap).scripts) { config.reporters.unshift('@angular-devkit/build-angular--sourcemap-reporter'); // Code taken from https://github.com/tschaub/karma-source-map-support. diff --git a/tests/legacy-cli/e2e/tests/test/test-sourcemap.ts b/tests/legacy-cli/e2e/tests/test/test-sourcemap.ts index 1963cfbd7bef..7bf102e0820a 100644 --- a/tests/legacy-cli/e2e/tests/test/test-sourcemap.ts +++ b/tests/legacy-cli/e2e/tests/test/test-sourcemap.ts @@ -1,8 +1,14 @@ import { writeFile } from '../../utils/fs'; -import { execAndWaitForOutputToMatch, killAllProcesses } from '../../utils/process'; +import { ng } from '../../utils/process'; import { updateJsonFile } from '../../utils/project'; export default async function () { + await writeFile('src/app/app.component.spec.ts', ` + it('show fail', () => { + expect(undefined).toBeTruthy(); + }); + `); + await updateJsonFile('angular.json', configJson => { const appArchitect = configJson.projects['test-project'].architect; appArchitect.test.options.sourceMap = { @@ -10,20 +16,43 @@ export default async function () { }; }); - await writeFile('src/app/app.component.spec.ts', ` - it('show fail', () => { - expect(undefined).toBeTruthy(); - }); - `); + // when sourcemaps are 'on' the stacktrace will point to the spec.ts file. + try { + await ng('test', '--watch', 'false'); + throw new Error('ng test should have failed.'); + } catch (error) { + if (!error.message.includes('app.component.spec.ts')) { + throw error; + }; + } - // when sourcemaps are not working the stacktrace won't point to the spec.ts file. + await updateJsonFile('angular.json', configJson => { + const appArchitect = configJson.projects['test-project'].architect; + appArchitect.test.options.sourceMap = true; + }); + + // when sourcemaps are 'on' the stacktrace will point to the spec.ts file. try { - await execAndWaitForOutputToMatch( - 'ng', - ['test', '--watch', 'false'], - /app\.component\.spec\.ts/, - ); - } finally { - killAllProcesses(); + await ng('test', '--watch', 'false'); + throw new Error('ng test should have failed.'); + } catch (error) { + if (!error.message.includes('app.component.spec.ts')) { + throw error; + }; + } + + await updateJsonFile('angular.json', configJson => { + const appArchitect = configJson.projects['test-project'].architect; + appArchitect.test.options.sourceMap = false; + }); + + // when sourcemaps are 'off' the stacktrace won't point to the spec.ts file. + try { + await ng('test', '--watch', 'false'); + throw new Error('ng test should have failed.'); + } catch (error) { + if (!error.message.includes('main.js')) { + throw error; + }; } }