Skip to content
Open
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
7 changes: 6 additions & 1 deletion packages/angular/build/src/builders/unit-test/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@ export async function normalizeOptions(
const buildTargetSpecifier = options.buildTarget ?? `::development`;
const buildTarget = targetFromTargetString(buildTargetSpecifier, projectName, 'build');

const { runner, browsers, progress, filter, browserViewport, ui, runnerConfig } = options;
const { runner, browsers, progress, filter, browserViewport, ui, runnerConfig, update } = options;

if (ui && runner !== Runner.Vitest) {
throw new Error('The "ui" option is only available for the "vitest" runner.');
}

if (update && runner !== Runner.Vitest) {
throw new Error('The "update" option is only available for the "vitest" runner.');
}

const [width, height] = browserViewport?.split('x').map(Number) ?? [];

let tsConfig = options.tsConfig;
Expand Down Expand Up @@ -132,6 +136,7 @@ export async function normalizeOptions(
? true
: path.resolve(workspaceRoot, runnerConfig)
: runnerConfig,
update: update ?? false,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ export class VitestExecutor implements TestExecutor {
watch,
...(typeof ui === 'boolean' ? { ui } : {}),
...debugOptions,
update: this.options.update,
},
{
// Note `.vitest` is auto appended to the path.
Expand Down
5 changes: 5 additions & 0 deletions packages/angular/build/src/builders/unit-test/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@
"description": "Dumps build output files to the `.angular/cache` directory for debugging purposes.",
"default": false,
"visible": false
},
"update": {
"type": "boolean",
"description": "Updates test snapshots to match the current test output. This option is only available for the Vitest runner.",
"default": false
}
},
"additionalProperties": false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/

import { execute } from '../../index';
import {
BASE_OPTIONS,
describeBuilder,
UNIT_TEST_BUILDER_INFO,
setupApplicationTarget,
} from '../setup';

describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
describe('Option: "update"', () => {
beforeEach(() => {
setupApplicationTarget(harness);
});

describe('Vitest Runner', () => {
it('should work with update flag enabled', async () => {
harness.useTarget('test', {
...BASE_OPTIONS,
update: true,
});

const { result } = await harness.executeOnce();

expect(result?.success).toBeTrue();
});

it('should work with update flag disabled', async () => {
harness.useTarget('test', {
...BASE_OPTIONS,
update: false,
});

const { result } = await harness.executeOnce();

expect(result?.success).toBeTrue();
});

it('should work without update flag (default)', async () => {
harness.useTarget('test', {
...BASE_OPTIONS,
});

const { result } = await harness.executeOnce();

expect(result?.success).toBeTrue();
});
});

describe('Karma Runner', () => {
it('should throw an error when update is used with karma', async () => {
harness.useTarget('test', {
...BASE_OPTIONS,
runner: 'karma',
update: true,
});

const { result, error } = await harness.executeOnce({ outputLogsOnException: false });

expect(result).toBeUndefined();
expect(error?.message).toContain(
'The "update" option is only available for the "vitest" runner.',
);
});
});
});
});