Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

build: add 'update' option for Vitest runner and corresponding tests #32262

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

Open
mistrykaran91 wants to merge 1 commit into angular:main
base: main
Choose a base branch
Loading
from mistrykaran91:fix/add-update-option-vitest
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
1 change: 1 addition & 0 deletions goldens/public-api/angular/build/index.api.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ export type UnitTestBuilderOptions = {
setupFiles?: string[];
tsConfig?: string;
ui?: boolean;
update?: boolean;
watch?: boolean;
};

Expand Down
7 changes: 6 additions & 1 deletion packages/angular/build/src/builders/unit-test/options.ts
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* @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);
});

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

AltStyle によって変換されたページ (->オリジナル) /