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
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,21 @@ export async function setupBrowserConfiguration(
// Validate that the imported module has the expected structure
const providerFactory = providerModule[providerName];
if (typeof providerFactory === 'function') {
provider = providerFactory();
if (
providerName === 'playwright' &&
process.env['CHROME_BIN']?.includes('rules_browsers')
) {
// Use the Chrome binary from the 'rules_browsers' toolchain (via CHROME_BIN)
// for Playwright when available to ensure hermetic testing, preventing reliance
// on locally installed or NPM-managed browser versions.
provider = providerFactory({
launchOptions: {
executablePath: process.env.CHROME_BIN,
},
});
} else {
provider = providerFactory();
}
} else {
errors ??= [];
errors.push(
Expand Down
52 changes: 31 additions & 21 deletions tests/legacy-cli/e2e/tests/vitest/larger-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,7 @@ export default async function () {
// Each generated artifact will add one more test file.
const initialTestCount = 1;

// Generate a mix of components, services, and pipes
for (let i = 0; i < artifactCount; i++) {
const type = i % 3;
const name = `test-artifact-${i}`;
let generateType;

switch (type) {
case 0:
generateType = 'component';
break;
case 1:
generateType = 'service';
break;
default:
generateType = 'pipe';
break;
}

await ng('generate', generateType, name, '--skip-tests=false');
}
await generateArtifactsInBatches(artifactCount);

const totalTests = initialTestCount + artifactCount;
const expectedMessage = new RegExp(`${totalTests} passed`);
Expand All @@ -43,7 +24,6 @@ export default async function () {
// Setup for browser mode
await installPackage('playwright@1');
await installPackage('@vitest/browser-playwright@4');
await exec('npx', 'playwright', 'install', 'chromium', '--only-shell');

// Run tests in browser mode
const { stdout: browserStdout } = await ng(
Expand All @@ -58,3 +38,33 @@ export default async function () {
`Expected ${totalTests} tests to pass in browser mode.`,
);
}

async function generateArtifactsInBatches(artifactCount: number): Promise<void> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When running this locally I noticed that it was rather slow, so I went ahead and added batching.

const BATCH_SIZE = 5;
let commands: Promise<any>[] = [];

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';
break;
case 1:
generateType = 'service';
break;
default:
generateType = 'pipe';
break;
}

commands.push(ng('generate', generateType, name, '--skip-tests=false'));

if (commands.length === BATCH_SIZE || i === artifactCount - 1) {
await Promise.all(commands);
commands = [];
}
}
}
3 changes: 1 addition & 2 deletions tests/legacy-cli/e2e/tests/vitest/tslib-resolution.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { writeFile } from '../../utils/fs';
import { installPackage } from '../../utils/packages';
import { exec, ng } from '../../utils/process';
import { ng } from '../../utils/process';
import { applyVitestBuilder } from '../../utils/vitest';
import assert from 'node:assert';

export default async function () {
await applyVitestBuilder();
await installPackage('playwright@1');
await installPackage('@vitest/browser-playwright@4');
await exec('npx', 'playwright', 'install', 'chromium', '--only-shell');

// Add a custom decorator to trigger tslib usage
await writeFile(
Expand Down