| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -242,6 +242,7 @@ export type UnitTestBuilderOptions = { | |||
| 242 | 242 | setupFiles?: string[]; | |
| 243 | 243 | tsConfig?: string; | |
| 244 | 244 | ui?: boolean; | |
| 245 | + update?: boolean; | ||
| 245 | 246 | watch?: boolean; | |
| 246 | 247 | }; | |
| 247 | 248 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -54,12 +54,16 @@ export async function normalizeOptions( | |||
| 54 | 54 | const buildTargetSpecifier = options.buildTarget ?? `::development`; | |
| 55 | 55 | const buildTarget = targetFromTargetString(buildTargetSpecifier, projectName, 'build'); | |
| 56 | 56 | ||
| 57 | - const { runner, browsers, progress, filter, browserViewport, ui, runnerConfig } = options; | ||
| 57 | + const { runner, browsers, progress, filter, browserViewport, ui, runnerConfig, update } = options; | ||
| 58 | 58 | ||
| 59 | 59 | if (ui && runner !== Runner.Vitest) { | |
| 60 | 60 | throw new Error('The "ui" option is only available for the "vitest" runner.'); | |
| 61 | 61 | } | |
| 62 | 62 | ||
| 63 | + if (update && runner !== Runner.Vitest) { | ||
| 64 | + throw new Error('The "update" option is only available for the "vitest" runner.'); | ||
| 65 | + } | ||
| 66 | + | ||
| 63 | 67 | const [width, height] = browserViewport?.split('x').map(Number) ?? []; | |
| 64 | 68 | ||
| 65 | 69 | let tsConfig = options.tsConfig; | |
@@ -132,6 +136,7 @@ export async function normalizeOptions( | |||
| 132 | 136 | ? true | |
| 133 | 137 | : path.resolve(workspaceRoot, runnerConfig) | |
| 134 | 138 | : runnerConfig, | |
| 139 | + update: update ?? false, | ||
| 135 | 140 | }; | |
| 136 | 141 | } | |
| 137 | 142 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -238,6 +238,7 @@ export class VitestExecutor implements TestExecutor { | |||
| 238 | 238 | watch, | |
| 239 | 239 | ...(typeof ui === 'boolean' ? { ui } : {}), | |
| 240 | 240 | ...debugOptions, | |
| 241 | + update: this.options.update, | ||
| 241 | 242 | }, | |
| 242 | 243 | { | |
| 243 | 244 | // Note `.vitest` is auto appended to the path. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -269,6 +269,11 @@ | |||
| 269 | 269 | "description": "Dumps build output files to the `.angular/cache` directory for debugging purposes.", | |
| 270 | 270 | "default": false, | |
| 271 | 271 | "visible": false | |
| 272 | + }, | ||
| 273 | + "update": { | ||
| 274 | + "type": "boolean", | ||
| 275 | + "description": "Updates test snapshots to match the current test output. This option is only available for the Vitest runner.", | ||
| 276 | + "default": false | ||
| 272 | 277 | } | |
| 273 | 278 | }, | |
| 274 | 279 | "additionalProperties": false, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,55 @@ | |||
| 1 | + /** | ||
| 2 | + * @license | ||
| 3 | + * Copyright Google LLC All Rights Reserved. | ||
| 4 | + * | ||
| 5 | + * Use of this source code is governed by an MIT-style license that can be | ||
| 6 | + * found in the LICENSE file at https://angular.dev/license | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | + import { execute } from '../../index'; | ||
| 10 | + import { | ||
| 11 | + BASE_OPTIONS, | ||
| 12 | + describeBuilder, | ||
| 13 | + UNIT_TEST_BUILDER_INFO, | ||
| 14 | + setupApplicationTarget, | ||
| 15 | + } from '../setup'; | ||
| 16 | + | ||
| 17 | + describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => { | ||
| 18 | + describe('Option: "update"', () => { | ||
| 19 | + beforeEach(() => { | ||
| 20 | + setupApplicationTarget(harness); | ||
| 21 | + }); | ||
| 22 | + | ||
| 23 | + it('should work with update flag enabled', async () => { | ||
| 24 | + harness.useTarget('test', { | ||
| 25 | + ...BASE_OPTIONS, | ||
| 26 | + update: true, | ||
| 27 | + }); | ||
| 28 | + | ||
| 29 | + const { result } = await harness.executeOnce(); | ||
| 30 | + | ||
| 31 | + expect(result?.success).toBeTrue(); | ||
| 32 | + }); | ||
| 33 | + | ||
| 34 | + it('should work with update flag disabled', async () => { | ||
| 35 | + harness.useTarget('test', { | ||
| 36 | + ...BASE_OPTIONS, | ||
| 37 | + update: false, | ||
| 38 | + }); | ||
| 39 | + | ||
| 40 | + const { result } = await harness.executeOnce(); | ||
| 41 | + | ||
| 42 | + expect(result?.success).toBeTrue(); | ||
| 43 | + }); | ||
| 44 | + | ||
| 45 | + it('should work without update flag (default)', async () => { | ||
| 46 | + harness.useTarget('test', { | ||
| 47 | + ...BASE_OPTIONS, | ||
| 48 | + }); | ||
| 49 | + | ||
| 50 | + const { result } = await harness.executeOnce(); | ||
| 51 | + | ||
| 52 | + expect(result?.success).toBeTrue(); | ||
| 53 | + }); | ||
| 54 | + }); | ||
| 55 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments