Skip to content
Merged
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
4 changes: 0 additions & 4 deletions tests/e2e/tests/test/test-scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import { updateJsonFile } from '../../utils/project';
import { expectToFail } from '../../utils/utils';

export default async function () {
// TODO(architect): Delete this test. It is now in devkit/build-angular.

await ng('test', '--watch=false');

// prepare global scripts test files
await writeMultipleFiles({
'src/string-script.js': `globalThis.stringScriptGlobal = 'string-scripts.js';`,
Expand Down
15 changes: 3 additions & 12 deletions tests/e2e/tests/vite/reuse-dep-optimization-cache.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
import assert from 'node:assert';
import { findFreePort } from '../../utils/network';
import {
execAndWaitForOutputToMatch,
killAllProcesses,
ng,
waitForAnyProcessOutputToMatch,
} from '../../utils/process';
import { execAndWaitForOutputToMatch, killAllProcesses, ng } from '../../utils/process';

export default async function () {
await ng('cache', 'clean');
await ng('cache', 'on');

const port = await findFreePort();
const serveReady = execAndWaitForOutputToMatch(
await execAndWaitForOutputToMatch(
'ng',
['serve', '--port', `${port}`],
/Application bundle generation complete/,
/dependencies optimized/,
// Use CI:0 to force caching
{ ...process.env, DEBUG: 'vite:deps', CI: '0', NO_COLOR: 'true' },
);

// Note: Don't await `serveReady` before, as otherwise we might not see
// the dependencies optimized output. There is some debouncing for `ng serve`
// going on that could cause this.
await Promise.all([serveReady, waitForAnyProcessOutputToMatch(/dependencies optimized/, 10_000)]);
const response = await fetch(`http://localhost:${port}/main.js`);

assert(response.ok, `Expected 'response.ok' to be 'true'.`);
Expand Down
109 changes: 95 additions & 14 deletions tests/e2e/tests/vitest/larger-project.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { ng } from '../../utils/process';
import { applyVitestBuilder } from '../../utils/vitest';
import assert from 'node:assert';
import { mkdir, writeFile } from 'node:fs/promises';
import { dirname } from 'node:path';
import { installPackage } from '../../utils/packages';
import { ng } from '../../utils/process';
import { applyVitestBuilder } from '../../utils/vitest';

export default async function () {
await applyVitestBuilder();
Expand Down Expand Up @@ -39,31 +41,110 @@ export default async function () {
}

async function generateArtifactsInBatches(artifactCount: number): Promise<void> {
const BATCH_SIZE = 5;
let commands: Promise<any>[] = [];
const files: { [path: string]: string } = {};

for (let i = 0; i < artifactCount; i++) {
const type = i % 3;
const name = `test-artifact-${i}`;
let generateType: string;

switch (type) {
case 0:
generateType = 'component';
files[`src/app/${name}/${name}.ts`] = `
import { Component } from '@angular/core';

@Component({
selector: 'app-${name}',
template: '',
})
export class TestArtifact${i}Component {}
`;
files[`src/app/${name}/${name}.spec.ts`] = `
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TestArtifact${i}Component } from './${name}';

describe('TestArtifact${i}Component', () => {
let component: TestArtifact${i}Component;
let fixture: ComponentFixture<TestArtifact${i}Component>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [TestArtifact${i}Component],
}).compileComponents();

fixture = TestBed.createComponent(TestArtifact${i}Component);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
`;
break;
case 1:
generateType = 'service';
files[`src/app/${name}.ts`] = `
import { Injectable } from '@angular/core';

@Injectable({
providedIn: 'root',
})
export class TestArtifact${i}Service {}
`;
files[`src/app/${name}.spec.ts`] = `
import { TestBed } from '@angular/core/testing';
import { TestArtifact${i}Service } from './${name}';

describe('TestArtifact${i}Service', () => {
let service: TestArtifact${i}Service;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(TestArtifact${i}Service);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
`;
break;
default:
generateType = 'pipe';
break;
}
files[`src/app/${name}-pipe.ts`] = `
import { Pipe, PipeTransform } from '@angular/core';

commands.push(ng('generate', generateType, name, '--skip-tests=false'));
@Pipe({
name: 'testArtifact${i}',
})
export class TestArtifact${i}Pipe implements PipeTransform {
transform(value: unknown): unknown {
return null;
}
}
`;
files[`src/app/${name}-pipe.spec.ts`] = `
import { TestArtifact${i}Pipe } from './${name}-pipe';

if (commands.length === BATCH_SIZE || i === artifactCount - 1) {
await Promise.all(commands);
commands = [];
describe('TestArtifact${i}Pipe', () => {
it('create an instance', () => {
const pipe = new TestArtifact${i}Pipe();
expect(pipe).toBeTruthy();
});
});
`;
break;
}
}

const entries = Object.entries(files);
const CONCURRENCY_LIMIT = 100;
for (let i = 0; i < entries.length; i += CONCURRENCY_LIMIT) {
const chunk = entries.slice(i, i + CONCURRENCY_LIMIT);
await Promise.all(
chunk.map(async ([filePath, content]) => {
await mkdir(dirname(filePath), { recursive: true });
await writeFile(filePath, content.trim());
}),
);
}
}
2 changes: 1 addition & 1 deletion tests/e2e/utils/puppeteer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function executeBrowserTest(options: BrowserTestOptions = {}) {
const browser = await launch({
executablePath: process.env['CHROME_BIN'],
headless: true,
args: ['--no-sandbox'],
args: ['--no-sandbox', '--disable-dev-shm-usage', '--disable-gpu'],
});
try {
const page = await browser.newPage();
Expand Down