From ce359b4a956c5014461058e1e99d2f5400e469a1 Mon Sep 17 00:00:00 2001 From: Yaroslav Admin Date: Wed, 15 Nov 2017 19:36:54 +0100 Subject: [PATCH] fix(@angular/cli): set correct mainFields for ng test when targeting es2015 Added test fails without the fix with the error described in the linked issue. Fixes #8379 --- .../@angular/cli/models/webpack-configs/test.ts | 6 ++++++ tests/e2e/tests/test/test-target.ts | 14 ++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tests/e2e/tests/test/test-target.ts diff --git a/packages/@angular/cli/models/webpack-configs/test.ts b/packages/@angular/cli/models/webpack-configs/test.ts index 73c54824bb11..00d3942d201d 100644 --- a/packages/@angular/cli/models/webpack-configs/test.ts +++ b/packages/@angular/cli/models/webpack-configs/test.ts @@ -48,6 +48,12 @@ export function getTestConfig(wco: WebpackConfigOptions) { } return { + resolve: { + mainFields: [ + ...(wco.supportES2015 ? ['es2015'] : []), + 'browser', 'module', 'main' + ] + }, devtool: buildOptions.sourcemaps ? 'inline-source-map' : 'eval', entry: { main: path.resolve(projectRoot, appConfig.root, appConfig.test) diff --git a/tests/e2e/tests/test/test-target.ts b/tests/e2e/tests/test/test-target.ts new file mode 100644 index 000000000000..a2ff244af4ca --- /dev/null +++ b/tests/e2e/tests/test/test-target.ts @@ -0,0 +1,14 @@ +import { ng } from '../../utils/process'; +import { updateJsonFile } from '../../utils/project'; + +export default function () { + return updateJsonFile('tsconfig.json', configJson => { + const compilerOptions = configJson['compilerOptions']; + compilerOptions['target'] = 'es2015'; + }) + .then(() => updateJsonFile('src/tsconfig.spec.json', configJson => { + const compilerOptions = configJson['compilerOptions']; + compilerOptions['target'] = 'es2015'; + })) + .then(() => ng('test', '--single-run')); +}