| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4a080b6 commit feb41cc
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -236,6 +236,7 @@ export type UnitTestBuilderOptions = { | |||
| 236 | 236 | isolate?: boolean; | |
| 237 | 237 | listTests?: boolean; | |
| 238 | 238 | outputFile?: string; | |
| 239 | + polyfills?: string[]; | ||
| 239 | 240 | progress?: boolean; | |
| 240 | 241 | providersFile?: string; | |
| 241 | 242 | quiet?: boolean; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -323,6 +323,9 @@ export async function* execute( | |||
| 323 | 323 | const applicationBuildOptions = { | |
| 324 | 324 | ...buildTargetOptions, | |
| 325 | 325 | ...runnerBuildOptions, | |
| 326 | + ...(normalizedOptions.polyfills !== undefined | ||
| 327 | + ? { polyfills: normalizedOptions.polyfills } | ||
| 328 | + : {}), | ||
| 326 | 329 | watch: normalizedOptions.watch, | |
| 327 | 330 | progress: normalizedOptions.buildProgress ?? buildTargetOptions.progress, | |
| 328 | 331 | quiet: normalizedOptions.quiet, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -77,6 +77,7 @@ export async function normalizeOptions( | |||
| 77 | 77 | runnerConfig, | |
| 78 | 78 | isolate, | |
| 79 | 79 | splitting = true, | |
| 80 | + polyfills, | ||
| 80 | 81 | } = options; | |
| 81 | 82 | ||
| 82 | 83 | if (ui && runner !== Runner.Vitest) { | |
@@ -158,6 +159,7 @@ export async function normalizeOptions( | |||
| 158 | 159 | dumpVirtualFiles: options.dumpVirtualFiles, | |
| 159 | 160 | listTests: options.listTests, | |
| 160 | 161 | preserveSymlinks, | |
| 162 | + polyfills, | ||
| 161 | 163 | runnerConfig: | |
| 162 | 164 | typeof runnerConfig === 'string' | |
| 163 | 165 | ? runnerConfig.length === 0 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -76,7 +76,7 @@ export class KarmaExecutor implements TestExecutor { | |||
| 76 | 76 | const karmaOptions: KarmaBuilderOptions = { | |
| 77 | 77 | karmaConfig, | |
| 78 | 78 | tsConfig: unitTestOptions.tsConfig ?? buildTargetOptions.tsConfig, | |
| 79 | - polyfills: injectTestingPolyfills(buildTargetOptions.polyfills), | ||
| 79 | + polyfills: injectTestingPolyfills(unitTestOptions.polyfills ?? buildTargetOptions.polyfills), | ||
| 80 | 80 | assets: buildTargetOptions.assets, | |
| 81 | 81 | scripts: buildTargetOptions.scripts, | |
| 82 | 82 | styles: buildTargetOptions.styles, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -178,7 +178,7 @@ function getZoneTestingStrategy( | |||
| 178 | 178 | return 'dynamic-zone'; | |
| 179 | 179 | } | |
| 180 | 180 | ||
| 181 | - return 'dynamic'; | ||
| 181 | + return 'none'; | ||
| 182 | 182 | } catch { | |
| 183 | 183 | return 'none'; | |
| 184 | 184 | } | |
@@ -256,6 +256,7 @@ export async function getVitestBuildOptions( | |||
| 256 | 256 | ||
| 257 | 257 | const buildOptions: Partial<ApplicationBuilderInternalOptions> = { | |
| 258 | 258 | ...baseBuildOptions, | |
| 259 | + ...(options.polyfills !== undefined ? { polyfills: options.polyfills } : {}), | ||
| 259 | 260 | watch, | |
| 260 | 261 | incrementalResults: watch, | |
| 261 | 262 | index: false, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -265,6 +265,14 @@ | |||
| 265 | 265 | "description": "Specifies the path to a TypeScript file that provides an array of Angular providers for the test environment. The file must contain a default export of the provider array.", | |
| 266 | 266 | "minLength": 1 | |
| 267 | 267 | }, | |
| 268 | + "polyfills": { | ||
| 269 | + "description": "A list of polyfills to include in the build. Can be a full path for a file, relative to the current workspace or module specifier. Example: 'zone.js'. If not specified, polyfills will be inherited from the build target.", | ||
| 270 | + "type": "array", | ||
| 271 | + "items": { | ||
| 272 | + "type": "string", | ||
| 273 | + "uniqueItems": true | ||
| 274 | + } | ||
| 275 | + }, | ||
| 268 | 276 | "setupFiles": { | |
| 269 | 277 | "type": "array", | |
| 270 | 278 | "items": { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,96 @@ | |||
| 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: "polyfills"', () => { | ||
| 19 | + beforeEach(async () => { | ||
| 20 | + setupApplicationTarget(harness); | ||
| 21 | + }); | ||
| 22 | + | ||
| 23 | + it('should include polyfills specified on test target', async () => { | ||
| 24 | + await harness.writeFiles({ | ||
| 25 | + 'src/custom-polyfill.js': `globalThis['CUSTOM_POLYFILL_RAN'] = true;`, | ||
| 26 | + 'src/app/app.component.spec.ts': ` | ||
| 27 | + import { describe, expect, test } from 'vitest'; | ||
| 28 | + describe('Polyfill Test', () => { | ||
| 29 | + test('should have run test polyfill', () => { | ||
| 30 | + expect((globalThis as any)['CUSTOM_POLYFILL_RAN']).toBe(true); | ||
| 31 | + }); | ||
| 32 | + });`, | ||
| 33 | + }); | ||
| 34 | + | ||
| 35 | + harness.useTarget('test', { | ||
| 36 | + ...BASE_OPTIONS, | ||
| 37 | + polyfills: ['src/custom-polyfill.js'], | ||
| 38 | + }); | ||
| 39 | + | ||
| 40 | + const { result } = await harness.executeOnce(); | ||
| 41 | + expect(result?.success).toBeTrue(); | ||
| 42 | + }); | ||
| 43 | + | ||
| 44 | + it('should override buildTarget polyfills when polyfills is specified on test target', async () => { | ||
| 45 | + setupApplicationTarget(harness, { | ||
| 46 | + polyfills: ['src/app-polyfill.js'], | ||
| 47 | + }); | ||
| 48 | + | ||
| 49 | + await harness.writeFiles({ | ||
| 50 | + 'src/app-polyfill.js': `globalThis['APP_POLYFILL_RAN'] = true;`, | ||
| 51 | + 'src/test-polyfill.js': `globalThis['TEST_POLYFILL_RAN'] = true;`, | ||
| 52 | + 'src/app/app.component.spec.ts': ` | ||
| 53 | + import { describe, expect, test } from 'vitest'; | ||
| 54 | + describe('Polyfill Override Test', () => { | ||
| 55 | + test('should have run test polyfill and not app polyfill', () => { | ||
| 56 | + expect((globalThis as any)['TEST_POLYFILL_RAN']).toBe(true); | ||
| 57 | + expect((globalThis as any)['APP_POLYFILL_RAN']).toBeUndefined(); | ||
| 58 | + }); | ||
| 59 | + });`, | ||
| 60 | + }); | ||
| 61 | + | ||
| 62 | + harness.useTarget('test', { | ||
| 63 | + ...BASE_OPTIONS, | ||
| 64 | + polyfills: ['src/test-polyfill.js'], | ||
| 65 | + }); | ||
| 66 | + | ||
| 67 | + const { result } = await harness.executeOnce(); | ||
| 68 | + expect(result?.success).toBeTrue(); | ||
| 69 | + }); | ||
| 70 | + | ||
| 71 | + it('should allow overriding buildTarget polyfills with an empty array', async () => { | ||
| 72 | + setupApplicationTarget(harness, { | ||
| 73 | + polyfills: ['src/app-polyfill.js'], | ||
| 74 | + }); | ||
| 75 | + | ||
| 76 | + await harness.writeFiles({ | ||
| 77 | + 'src/app-polyfill.js': `globalThis['APP_POLYFILL_RAN'] = true;`, | ||
| 78 | + 'src/app/app.component.spec.ts': ` | ||
| 79 | + import { describe, expect, test } from 'vitest'; | ||
| 80 | + describe('Empty Polyfill Override Test', () => { | ||
| 81 | + test('should not have run app polyfill', () => { | ||
| 82 | + expect((globalThis as any)['APP_POLYFILL_RAN']).toBeUndefined(); | ||
| 83 | + }); | ||
| 84 | + });`, | ||
| 85 | + }); | ||
| 86 | + | ||
| 87 | + harness.useTarget('test', { | ||
| 88 | + ...BASE_OPTIONS, | ||
| 89 | + polyfills: [], | ||
| 90 | + }); | ||
| 91 | + | ||
| 92 | + const { result } = await harness.executeOnce(); | ||
| 93 | + expect(result?.success).toBeTrue(); | ||
| 94 | + }); | ||
| 95 | + }); | ||
| 96 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments