diff --git a/modules/testing/builder/projects/hello-world-app/karma.conf.js b/modules/testing/builder/projects/hello-world-app/karma.conf.js index 1cf153a1da81..7d5f7c8d98f5 100644 --- a/modules/testing/builder/projects/hello-world-app/karma.conf.js +++ b/modules/testing/builder/projects/hello-world-app/karma.conf.js @@ -23,9 +23,6 @@ module.exports = function(config) { require('karma-coverage'), require('@angular-devkit/build-angular/plugins/karma'), ], - client: { - clearContext: false, // leave Jasmine Spec Runner output visible in browser - }, jasmineHtmlReporter: { suppressAll: true // removes the duplicated traces }, diff --git a/modules/testing/builder/src/builder-harness.ts b/modules/testing/builder/src/builder-harness.ts index 092206698f83..ec4973efa021 100644 --- a/modules/testing/builder/src/builder-harness.ts +++ b/modules/testing/builder/src/builder-harness.ts @@ -263,7 +263,7 @@ export class BuilderHarness { } const logs: logging.LogEntry[] = []; - context.logger.subscribe((e) => logs.push(e)); + const logger$ = context.logger.subscribe((e) => logs.push(e)); return observableFrom(this.schemaRegistry.compile(this.builderInfo.optionSchema)).pipe( mergeMap((validator) => validator(targetOptions)), @@ -302,6 +302,7 @@ export class BuilderHarness { }), finalize(() => { this.watcherNotifier = undefined; + logger$.unsubscribe(); for (const teardown of context.teardowns) { // eslint-disable-next-line @typescript-eslint/no-floating-promises diff --git a/modules/testing/builder/src/test-utils.ts b/modules/testing/builder/src/test-utils.ts index 126af073b726..f41cb42d1ea6 100644 --- a/modules/testing/builder/src/test-utils.ts +++ b/modules/testing/builder/src/test-utils.ts @@ -24,8 +24,8 @@ import { import path from 'node:path'; import { firstValueFrom } from 'rxjs'; -// Default timeout for large specs is 2.5 minutes. -jasmine.DEFAULT_TIMEOUT_INTERVAL = 150000; +// Default timeout for large specs is 60s. +jasmine.DEFAULT_TIMEOUT_INTERVAL = 60_000; export const workspaceRoot = join(normalize(__dirname), `../projects/hello-world-app/`); export const host = new TestProjectHost(workspaceRoot); diff --git a/packages/angular/build/BUILD.bazel b/packages/angular/build/BUILD.bazel index e46c2da6fcee..69d8ac3e2dd8 100644 --- a/packages/angular/build/BUILD.bazel +++ b/packages/angular/build/BUILD.bazel @@ -291,15 +291,15 @@ ts_project( jasmine_test( name = "application_integration_tests", - size = "large", + size = "medium", data = [":application_integration_test_lib"], flaky = True, - shard_count = 20, + shard_count = 25, ) jasmine_test( name = "dev-server_integration_tests", - size = "large", + size = "medium", data = [":dev-server_integration_test_lib"], flaky = True, shard_count = 10, @@ -307,7 +307,7 @@ jasmine_test( jasmine_test( name = "karma_integration_tests", - size = "large", + size = "medium", data = [":karma_integration_test_lib"], env = { # TODO: Replace Puppeteer downloaded browsers with Bazel-managed browsers, @@ -320,9 +320,9 @@ jasmine_test( jasmine_test( name = "unit-test_integration_tests", - size = "large", + size = "small", data = [":unit-test_integration_test_lib"], - shard_count = 10, + shard_count = 5, ) genrule( diff --git a/packages/angular/build/src/builders/application/tests/options/output-path_spec.ts b/packages/angular/build/src/builders/application/tests/options/output-path_spec.ts index f8d4513c7de7..b6c72b9bee58 100644 --- a/packages/angular/build/src/builders/application/tests/options/output-path_spec.ts +++ b/packages/angular/build/src/builders/application/tests/options/output-path_spec.ts @@ -10,30 +10,30 @@ import { buildApplication } from '../../index'; import { APPLICATION_BUILDER_INFO, BASE_OPTIONS, describeBuilder } from '../setup'; describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => { - beforeEach(async () => { - // Add a global stylesheet media file - await harness.writeFile('src/styles.css', `h1 { background: url('./spectrum.png')}`); - // Add a component stylesheet media file - await harness.writeFile('src/app/abc.svg', ''); - await harness.writeFile('src/app/app.component.css', `h2 { background: url('./abc.svg')}`); - - // Enable SSR - await harness.modifyFile('src/tsconfig.app.json', (content) => { - const tsConfig = JSON.parse(content); - tsConfig.files ??= []; - tsConfig.files.push('main.server.ts', 'server.ts'); + describe('Option: "outputPath"', () => { + beforeEach(async () => { + // Add a global stylesheet media file + await harness.writeFile('src/styles.css', `h1 { background: url('./spectrum.png')}`); + // Add a component stylesheet media file + await harness.writeFile('src/app/abc.svg', ''); + await harness.writeFile('src/app/app.component.css', `h2 { background: url('./abc.svg')}`); + + // Enable SSR + await harness.modifyFile('src/tsconfig.app.json', (content) => { + const tsConfig = JSON.parse(content); + tsConfig.files ??= []; + tsConfig.files.push('main.server.ts', 'server.ts'); + + return JSON.stringify(tsConfig); + }); - return JSON.stringify(tsConfig); + // Application server code is not needed in this test + await harness.writeFile('src/main.server.ts', `console.log('Hello!');`); + await harness.writeFile('src/server.ts', `console.log('Hello!');`); }); - // Application server code is not needed in this test - await harness.writeFile('src/main.server.ts', `console.log('Hello!');`); - await harness.writeFile('src/server.ts', `console.log('Hello!');`); - }); - - describe('Option: "outputPath"', () => { - describe(`when option value is is a string`, () => { - beforeEach(() => { + describe('when option value is a string', () => { + it('should emit browser, media and server files in their respective directories', async () => { harness.useTarget('build', { ...BASE_OPTIONS, polyfills: [], @@ -44,34 +44,20 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => { entry: 'src/server.ts', }, }); - }); - it(`should emit browser bundles in 'browser' directory`, async () => { const { result } = await harness.executeOnce(); expect(result?.success).toBeTrue(); harness.expectFile('dist/browser/main.js').toExist(); - }); - - it(`should emit media files in 'browser/media' directory`, async () => { - const { result } = await harness.executeOnce(); - expect(result?.success).toBeTrue(); - harness.expectFile('dist/browser/media/spectrum.png').toExist(); harness.expectFile('dist/browser/media/abc.svg').toExist(); - }); - - it(`should emit server bundles in 'server' directory`, async () => { - const { result } = await harness.executeOnce(); - expect(result?.success).toBeTrue(); - harness.expectFile('dist/server/server.mjs').toExist(); }); }); - describe(`when option value is an object`, () => { + describe('when option value is an object', () => { describe(`'media' is set to 'resources'`, () => { - beforeEach(() => { + it('should emit browser, media and server files in their respective directories', async () => { harness.useTarget('build', { ...BASE_OPTIONS, polyfills: [], @@ -85,33 +71,19 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => { entry: 'src/server.ts', }, }); - }); - it(`should emit browser bundles in 'browser' directory`, async () => { const { result } = await harness.executeOnce(); expect(result?.success).toBeTrue(); harness.expectFile('dist/browser/main.js').toExist(); - }); - - it(`should emit media files in 'browser/resource' directory`, async () => { - const { result } = await harness.executeOnce(); - expect(result?.success).toBeTrue(); - harness.expectFile('dist/browser/resource/spectrum.png').toExist(); harness.expectFile('dist/browser/resource/abc.svg').toExist(); - }); - - it(`should emit server bundles in 'server' directory`, async () => { - const { result } = await harness.executeOnce(); - expect(result?.success).toBeTrue(); - harness.expectFile('dist/server/server.mjs').toExist(); }); }); describe(`'media' is set to ''`, () => { - beforeEach(() => { + it('should emit browser, media and server files in their respective directories', async () => { harness.useTarget('build', { ...BASE_OPTIONS, polyfills: [], @@ -125,36 +97,20 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => { entry: 'src/server.ts', }, }); - }); - it(`should emit browser bundles in 'browser' directory`, async () => { const { result } = await harness.executeOnce(); expect(result?.success).toBeTrue(); harness.expectFile('dist/browser/main.js').toExist(); - }); - - it(`should emit media files in 'browser' directory`, async () => { - const { result } = await harness.executeOnce(); - expect(result?.success).toBeTrue(); - harness.expectFile('dist/browser/spectrum.png').toExist(); harness.expectFile('dist/browser/abc.svg').toExist(); - - // Component CSS should not be considered media - harness.expectFile('dist/browser/app.component.css').toNotExist(); - }); - - it(`should emit server bundles in 'server' directory`, async () => { - const { result } = await harness.executeOnce(); - expect(result?.success).toBeTrue(); - harness.expectFile('dist/server/server.mjs').toExist(); + harness.expectFile('dist/browser/app.component.css').toNotExist(); }); }); describe(`'server' is set to 'node-server'`, () => { - beforeEach(() => { + it('should emit browser, media and server files in their respective directories', async () => { harness.useTarget('build', { ...BASE_OPTIONS, polyfills: [], @@ -168,33 +124,19 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => { entry: 'src/server.ts', }, }); - }); - it(`should emit browser bundles in 'browser' directory`, async () => { const { result } = await harness.executeOnce(); expect(result?.success).toBeTrue(); harness.expectFile('dist/browser/main.js').toExist(); - }); - - it(`should emit media files in 'browser/media' directory`, async () => { - const { result } = await harness.executeOnce(); - expect(result?.success).toBeTrue(); - harness.expectFile('dist/browser/media/spectrum.png').toExist(); harness.expectFile('dist/browser/media/abc.svg').toExist(); - }); - - it(`should emit server bundles in 'node-server' directory`, async () => { - const { result } = await harness.executeOnce(); - expect(result?.success).toBeTrue(); - harness.expectFile('dist/node-server/server.mjs').toExist(); }); }); describe(`'browser' is set to 'public'`, () => { - beforeEach(() => { + it('should emit browser, media and server files in their respective directories', async () => { harness.useTarget('build', { ...BASE_OPTIONS, polyfills: [], @@ -208,51 +150,19 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => { entry: 'src/server.ts', }, }); - }); - it(`should emit browser bundles in 'public' directory`, async () => { const { result } = await harness.executeOnce(); expect(result?.success).toBeTrue(); harness.expectFile('dist/public/main.js').toExist(); - }); - - it(`should emit media files in 'public/media' directory`, async () => { - const { result } = await harness.executeOnce(); - expect(result?.success).toBeTrue(); - harness.expectFile('dist/public/media/spectrum.png').toExist(); harness.expectFile('dist/public/media/abc.svg').toExist(); - }); - - it(`should emit server bundles in 'server' directory`, async () => { - const { result } = await harness.executeOnce(); - expect(result?.success).toBeTrue(); - harness.expectFile('dist/server/server.mjs').toExist(); }); }); describe(`'browser' is set to ''`, () => { - it(`should emit browser bundles in '' directory`, async () => { - harness.useTarget('build', { - ...BASE_OPTIONS, - polyfills: [], - server: 'src/main.server.ts', - outputPath: { - base: 'dist', - browser: '', - }, - ssr: false, - }); - - const { result } = await harness.executeOnce(); - expect(result?.success).toBeTrue(); - - harness.expectFile('dist/main.js').toExist(); - }); - - it(`should emit media files in 'media' directory`, async () => { + it('should emit browser and media files in the root output directory when ssr is disabled', async () => { harness.useTarget('build', { ...BASE_OPTIONS, polyfills: [], @@ -268,11 +178,12 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => { const { result } = await harness.executeOnce(); expect(result?.success).toBeTrue(); + harness.expectFile('dist/main.js').toExist(); harness.expectFile('dist/media/spectrum.png').toExist(); harness.expectFile('dist/media/abc.svg').toExist(); }); - it(`should error when ssr is enabled`, async () => { + it('should error when ssr is enabled', async () => { harness.useTarget('build', { ...BASE_OPTIONS, polyfills: [], @@ -298,8 +209,8 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => { }); }); - describe(`'server' is set ''`, () => { - beforeEach(() => { + describe(`'server' is set to ''`, () => { + it('should emit browser, media and server files in their respective directories', async () => { harness.useTarget('build', { ...BASE_OPTIONS, polyfills: [], @@ -313,27 +224,13 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => { entry: 'src/server.ts', }, }); - }); - it(`should emit browser bundles in 'browser' directory`, async () => { const { result } = await harness.executeOnce(); expect(result?.success).toBeTrue(); harness.expectFile('dist/browser/main.js').toExist(); - }); - - it(`should emit media files in 'browser/media' directory`, async () => { - const { result } = await harness.executeOnce(); - expect(result?.success).toBeTrue(); - harness.expectFile('dist/browser/media/spectrum.png').toExist(); harness.expectFile('dist/browser/media/abc.svg').toExist(); - }); - - it(`should emit server bundles in '' directory`, async () => { - const { result } = await harness.executeOnce(); - expect(result?.success).toBeTrue(); - harness.expectFile('dist/server.mjs').toExist(); }); }); diff --git a/packages/angular/build/src/builders/application/tests/options/polyfills_spec.ts b/packages/angular/build/src/builders/application/tests/options/polyfills_spec.ts index 290ea281208d..8b5cc3a09ab3 100644 --- a/packages/angular/build/src/builders/application/tests/options/polyfills_spec.ts +++ b/packages/angular/build/src/builders/application/tests/options/polyfills_spec.ts @@ -16,71 +16,75 @@ const testsVariants: [suitName: string, baseUrl: string | undefined][] = [ ]; describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => { - for (const [suitName, baseUrl] of testsVariants) { - describe(suitName, () => { - beforeEach(async () => { - await harness.modifyFile('tsconfig.json', (content) => { - const tsconfig = JSON.parse(content); - tsconfig.compilerOptions.baseUrl = baseUrl; - - return JSON.stringify(tsconfig); - }); - }); - - it('uses a provided TypeScript file', async () => { - harness.useTarget('build', { - ...BASE_OPTIONS, - polyfills: ['src/polyfills.ts'], + describe('Option: polyfills', () => { + for (const [suitName, baseUrl] of testsVariants) { + describe(suitName, () => { + beforeEach(async () => { + await harness.writeFile('src/main.ts', 'console.log("TEST");'); + + await harness.modifyFile('tsconfig.json', (content) => { + const tsconfig = JSON.parse(content); + tsconfig.compilerOptions.baseUrl = baseUrl; + + return JSON.stringify(tsconfig); + }); }); - const { result } = await harness.executeOnce(); + it('uses a provided TypeScript file', async () => { + harness.useTarget('build', { + ...BASE_OPTIONS, + polyfills: ['src/polyfills.ts'], + }); - expect(result?.success).toBe(true); - - harness.expectFile('dist/browser/polyfills.js').toExist(); - }); + const { result } = await harness.executeOnce(); - it('uses a provided JavaScript file', async () => { - await harness.writeFile('src/polyfills.js', `console.log('main');`); + expect(result?.success).toBe(true); - harness.useTarget('build', { - ...BASE_OPTIONS, - polyfills: ['src/polyfills.js'], + harness.expectFile('dist/browser/polyfills.js').toExist(); }); - const { result } = await harness.executeOnce(); + it('uses a provided JavaScript file', async () => { + await harness.writeFile('src/polyfills.js', `console.log('main');`); - expect(result?.success).toBe(true); + harness.useTarget('build', { + ...BASE_OPTIONS, + polyfills: ['src/polyfills.js'], + }); - harness.expectFile('dist/browser/polyfills.js').content.toContain(`console.log("main")`); - }); + const { result } = await harness.executeOnce(); + + expect(result?.success).toBe(true); - it('fails and shows an error when file does not exist', async () => { - harness.useTarget('build', { - ...BASE_OPTIONS, - polyfills: ['src/missing.ts'], + harness.expectFile('dist/browser/polyfills.js').content.toContain(`console.log("main")`); }); - const { result, logs } = await harness.executeOnce({ outputLogsOnFailure: false }); + it('fails and shows an error when file does not exist', async () => { + harness.useTarget('build', { + ...BASE_OPTIONS, + polyfills: ['src/missing.ts'], + }); - expect(result?.success).toBe(false); - expect(logs).toContain( - jasmine.objectContaining({ message: jasmine.stringMatching('Could not resolve') }), - ); + const { result, logs } = await harness.executeOnce({ outputLogsOnFailure: false }); - harness.expectFile('dist/browser/polyfills.js').toNotExist(); - }); + expect(result?.success).toBe(false); + expect(logs).toContain( + jasmine.objectContaining({ message: jasmine.stringMatching('Could not resolve') }), + ); - it('resolves module specifiers in array', async () => { - harness.useTarget('build', { - ...BASE_OPTIONS, - polyfills: ['zone.js', 'zone.js/testing'], + harness.expectFile('dist/browser/polyfills.js').toNotExist(); }); - const { result } = await harness.executeOnce(); - expect(result?.success).toBeTrue(); - harness.expectFile('dist/browser/polyfills.js').toExist(); + it('resolves module specifiers in array', async () => { + harness.useTarget('build', { + ...BASE_OPTIONS, + polyfills: ['zone.js', 'zone.js/testing'], + }); + + const { result } = await harness.executeOnce(); + expect(result?.success).toBeTrue(); + harness.expectFile('dist/browser/polyfills.js').toExist(); + }); }); - }); - } + } + }); }); diff --git a/packages/angular_devkit/build_angular/src/builders/app-shell/app-shell_spec.ts b/packages/angular_devkit/build_angular/src/builders/app-shell/app-shell_spec.ts index 468bdb6ff2bd..6ee544305b06 100644 --- a/packages/angular_devkit/build_angular/src/builders/app-shell/app-shell_spec.ts +++ b/packages/angular_devkit/build_angular/src/builders/app-shell/app-shell_spec.ts @@ -13,6 +13,15 @@ import { createArchitect, host } from '../../testing/test-utils'; describe('AppShell Builder', () => { const target = { project: 'app', target: 'app-shell' }; let architect: Architect; + const originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; + + beforeAll(() => { + jasmine.DEFAULT_TIMEOUT_INTERVAL = 100_000; + }); + + afterAll(() => { + jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; + }); beforeEach(async () => { await host.initialize().toPromise(); diff --git a/packages/angular_devkit/build_angular/src/builders/ng-packagr/works_spec.ts b/packages/angular_devkit/build_angular/src/builders/ng-packagr/works_spec.ts index 06609780b8b8..4bf1ac2dec91 100644 --- a/packages/angular_devkit/build_angular/src/builders/ng-packagr/works_spec.ts +++ b/packages/angular_devkit/build_angular/src/builders/ng-packagr/works_spec.ts @@ -19,14 +19,21 @@ import { } from '@angular-devkit/core'; import { debounceTime, map, take, tap } from 'rxjs'; -// Default timeout for large specs is 2.5 minutes. -jasmine.DEFAULT_TIMEOUT_INTERVAL = 150000; - describe('NgPackagr Builder', () => { const workspaceRoot = join(normalize(__dirname), `../../../test/hello-world-lib/`); const host = new TestProjectHost(workspaceRoot); let architect: Architect; + const originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; + + beforeAll(() => { + jasmine.DEFAULT_TIMEOUT_INTERVAL = 80_000; + }); + + afterAll(() => { + jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; + }); + beforeEach(async () => { await host.initialize().toPromise(); diff --git a/packages/angular_devkit/build_angular/src/builders/prerender/works_spec.ts b/packages/angular_devkit/build_angular/src/builders/prerender/works_spec.ts index 4d26c6049542..8c55c923d02d 100644 --- a/packages/angular_devkit/build_angular/src/builders/prerender/works_spec.ts +++ b/packages/angular_devkit/build_angular/src/builders/prerender/works_spec.ts @@ -11,6 +11,16 @@ import { join, normalize, virtualFs } from '@angular-devkit/core'; import { createArchitect, host } from '../../testing/test-utils'; describe('Prerender Builder', () => { + const originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; + + beforeAll(() => { + jasmine.DEFAULT_TIMEOUT_INTERVAL = 100_000; + }); + + afterAll(() => { + jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; + }); + const target = { project: 'app', target: 'prerender' }; let architect: Architect; diff --git a/packages/angular_devkit/build_angular/test/hello-world-lib/projects/lib/karma.conf.js b/packages/angular_devkit/build_angular/test/hello-world-lib/projects/lib/karma.conf.js index fe024ed63ee2..5573d103b26e 100644 --- a/packages/angular_devkit/build_angular/test/hello-world-lib/projects/lib/karma.conf.js +++ b/packages/angular_devkit/build_angular/test/hello-world-lib/projects/lib/karma.conf.js @@ -20,9 +20,6 @@ module.exports = function (config) { require('karma-coverage-istanbul-reporter'), require('@angular-devkit/build-angular/plugins/karma') ], - client: { - clearContext: false // leave Jasmine Spec Runner output visible in browser - }, jasmineHtmlReporter: { suppressAll: true // removes the duplicated traces },