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 @@ -20,7 +20,6 @@ import {
ResultKind,
} from '../../../application/results';
import { NormalizedUnitTestBuilderOptions } from '../../options';
import { findTests, getTestEntrypoints } from '../../test-discovery';
import type { TestExecutor } from '../api';
import { setupBrowserConfiguration } from './browser-provider';
import { createVitestPlugins } from './plugins';
Expand Down Expand Up @@ -191,7 +190,7 @@ export class VitestExecutor implements TestExecutor {
reporters: reporters ?? ['default'],
outputFile,
watch,
coverage: generateCoverageOption(codeCoverage),
coverage: generateCoverageOption(codeCoverage, this.projectName),
...debugOptions,
},
{
Expand All @@ -208,6 +207,7 @@ export class VitestExecutor implements TestExecutor {

function generateCoverageOption(
codeCoverage: NormalizedUnitTestBuilderOptions['codeCoverage'],
projectName: string,
): VitestCoverageOption {
if (!codeCoverage) {
return {
Expand All @@ -218,6 +218,7 @@ function generateCoverageOption(
return {
enabled: true,
excludeAfterRemap: true,
reportsDirectory: toPosixPath(path.join('coverage', projectName)),
// Special handling for `exclude`/`reporters` due to an undefined value causing upstream failures
...(codeCoverage.exclude ? { exclude: codeCoverage.exclude } : {}),
...(codeCoverage.reporters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {

const { result } = await harness.executeOnce();
expect(result?.success).toBeTrue();
const summary = harness.readFile('coverage/coverage-final.json');
const summary = harness.readFile('coverage/test/coverage-final.json');
expect(summary).toContain('src/app/error.ts"');
});

Expand All @@ -44,7 +44,7 @@ describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {

const { result } = await harness.executeOnce();
expect(result?.success).toBeTrue();
const summary = harness.readFile('coverage/coverage-final.json');
const summary = harness.readFile('coverage/test/coverage-final.json');
expect(summary).not.toContain('src/app/error.ts"');
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {

const { result } = await harness.executeOnce();
expect(result?.success).toBeTrue();
expect(harness.hasFile('coverage/coverage-summary.json')).toBeTrue();
expect(harness.hasFile('coverage/test/coverage-summary.json')).toBeTrue();
});

it('should generate multiple reports when specified', async () => {
Expand All @@ -41,8 +41,8 @@ describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {

const { result } = await harness.executeOnce();
expect(result?.success).toBeTrue();
expect(harness.hasFile('coverage/coverage-summary.json')).toBeTrue();
expect(harness.hasFile('coverage/lcov.info')).toBeTrue();
expect(harness.hasFile('coverage/test/coverage-summary.json')).toBeTrue();
expect(harness.hasFile('coverage/test/lcov.info')).toBeTrue();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {

const { result } = await harness.executeOnce();
expect(result?.success).toBeTrue();
expect(harness.hasFile('coverage/index.html')).toBeFalse();
expect(harness.hasFile('coverage/test/index.html')).toBeFalse();
});

it('should generate a code coverage report when codeCoverage is true', async () => {
Expand All @@ -39,7 +39,7 @@ describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {

const { result } = await harness.executeOnce();
expect(result?.success).toBeTrue();
expect(harness.hasFile('coverage/index.html')).toBeTrue();
expect(harness.hasFile('coverage/test/index.html')).toBeTrue();
});
});
});
6 changes: 3 additions & 3 deletions packages/angular/build/src/builders/unit-test/tests/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { readFileSync } from 'node:fs';
import path from 'node:path';
import { BuilderHarness } from '../../../../../../../modules/testing/builder/src';
import {
ApplicationBuilderOptions as AppilicationSchema,
ApplicationBuilderOptions as ApplicationSchema,
buildApplication,
} from '../../../builders/application';
import { Schema } from '../schema';
Expand All @@ -33,7 +33,7 @@ export const APPLICATION_BUILDER_INFO = Object.freeze({
* Contains all required application builder fields.
* Also disables progress reporting to minimize logging output.
*/
export const APPLICATION_BASE_OPTIONS = Object.freeze<AppilicationSchema>({
export const APPLICATION_BASE_OPTIONS = Object.freeze<ApplicationSchema>({
index: 'src/index.html',
browser: 'src/main.ts',
outputPath: 'dist',
Expand Down Expand Up @@ -84,7 +84,7 @@ let applicationSchema: json.schema.JsonSchema | undefined;
*/
export function setupApplicationTarget<T>(
harness: BuilderHarness<T>,
extraOptions?: Partial<AppilicationSchema>,
extraOptions?: Partial<ApplicationSchema>,
): void {
applicationSchema ??= JSON.parse(
readFileSync(APPLICATION_BUILDER_INFO.schemaPath, 'utf8'),
Expand Down