Skip to content
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 @@ -25,6 +25,7 @@ import * as path from 'path';
import { Observable, Subscriber, catchError, defaultIfEmpty, from, of, switchMap } from 'rxjs';
import { Configuration } from 'webpack';
import { ExecutionTransformer } from '../../transforms';
import { normalizeFileReplacements } from '../../utils';
import { OutputHashing } from '../browser-esbuild/schema';
import { findTests, getTestEntrypoints } from './find-tests';
import { Schema as KarmaBuilderOptions } from './schema';
Expand Down Expand Up @@ -400,17 +401,24 @@ async function initializeApplication(
index: false,
outputHashing: OutputHashing.None,
optimization: false,
sourceMap: {
scripts: true,
styles: true,
vendor: true,
},
sourceMap: options.codeCoverage
? {
scripts: true,
styles: true,
vendor: true,
}
: options.sourceMap,
instrumentForCoverage,
styles: options.styles,
scripts: options.scripts,
polyfills,
webWorkerTsConfig: options.webWorkerTsConfig,
watch: options.watch ?? !karmaOptions.singleRun,
stylePreprocessorOptions: options.stylePreprocessorOptions,
inlineStyleLanguage: options.inlineStyleLanguage,
fileReplacements: options.fileReplacements
? normalizeFileReplacements(options.fileReplacements, './')
: undefined,
};

// Build tests with `application` builder, using test files as entry points.
Expand Down Expand Up @@ -447,6 +455,16 @@ async function initializeApplication(
};

karmaOptions.files ??= [];
if (options.scripts?.length) {
// This should be more granular to support named bundles.
// However, it replicates the behavior of the Karma Webpack-based builder.
karmaOptions.files.push({
pattern: `${outputPath}/scripts.js`,
watched: false,
type: 'js',
});
}

karmaOptions.files.push(
// Serve global setup script.
{ pattern: `${outputPath}/${mainName}.js`, type: 'module', watched: false },
Expand Down
26 changes: 0 additions & 26 deletions tests/legacy-cli/e2e/tests/misc/karma-error-paths.ts

This file was deleted.

4 changes: 2 additions & 2 deletions tests/legacy-cli/e2e/tests/test/test-scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export default async function () {

// prepare global scripts test files
await writeMultipleFiles({
'src/string-script.js': `stringScriptGlobal = 'string-scripts.js';`,
'src/input-script.js': `inputScriptGlobal = 'input-scripts.js';`,
'src/string-script.js': `globalThis.stringScriptGlobal = 'string-scripts.js';`,
'src/input-script.js': `globalThis.inputScriptGlobal = 'input-scripts.js';`,
'src/typings.d.ts': `
declare var stringScriptGlobal: any;
declare var inputScriptGlobal: any;
Expand Down
21 changes: 14 additions & 7 deletions tests/legacy-cli/e2e/tests/test/test-sourcemap.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import assert from 'node:assert';
import { getGlobalVariable } from '../../utils/env';
import { writeFile } from '../../utils/fs';
import { ng } from '../../utils/process';
import { assertIsError } from '../../utils/utils';

export default async function () {
if (getGlobalVariable('argv')['esbuild']) {
// TODO: enable once this is fixed when using the esbuild builder.
return;
}

await writeFile(
'src/app/app.component.spec.ts',
`
it('show fail', () => {
it('should fail', () => {
expect(undefined).toBeTruthy();
});
`,
Expand All @@ -16,18 +24,17 @@ export default async function () {
await ng('test', '--no-watch', '--source-map');
throw new Error('ng test should have failed.');
} catch (error) {
if (!(error instanceof Error && error.message.includes('app.component.spec.ts'))) {
throw error;
}
assertIsError(error);
assert.match(error.message, /src\/app\/app\.component\.spec\.ts/);
assert.doesNotMatch(error.message, /_karma_webpack_/);
}

// when sourcemaps are 'off' the stacktrace won't point to the spec.ts file.
try {
await ng('test', '--no-watch', '--no-source-map');
throw new Error('ng test should have failed.');
} catch (error) {
if (!(error instanceof Error && error.message.includes('main.js'))) {
throw error;
}
assertIsError(error);
assert.match(error.message, /main\.js/);
}
}
3 changes: 3 additions & 0 deletions tests/legacy-cli/e2e/utils/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ export async function useCIChrome(projectName: string, projectDir = ''): Promise
const project = workspaceJson.projects[projectName];
const appTargets = project.targets || project.architect;
appTargets.test.options.browsers = 'ChromeHeadlessNoSandbox';
appTargets.test.options.builderMode = getGlobalVariable('argv')['esbuild']
? 'application'
: 'browser';
});
}

Expand Down
Loading