Skip to content

fix for #14457 - fix(@angular-devkit/build-angular): normalize sourceMap options in ka… #14466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
57 changes: 43 additions & 14 deletions tests/legacy-cli/e2e/tests/test/test-sourcemap.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,58 @@
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 = {
scripts: true,
};
});

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;
};
}
}