Implementation:Puppeteer Puppeteer NgSchematics Files Util
| Property | Value |
|---|---|
| sources | packages/ng-schematics/src/schematics/utils/files.ts |
| domains | Angular Schematics, File Generation, Template Processing |
| last_updated | 2026-02-12 00:00 GMT |
Overview
Description
The NgSchematics Files Util module provides utility functions for generating and managing schematic template files in Angular projects configured with Puppeteer. It handles the creation of E2E test infrastructure files by applying Angular schematic templates with project-specific variables.
The module provides the following key functions:
- addFilesToProjects -- Iterates over all application projects and applies file templates to each one
- addFilesSingle -- Generates files for a single project by resolving template variables (base URL, TypeScript config path, project root) and applying Angular schematic template processing with
mergeWith,apply,applyTemplates, andmove - addCommonFiles -- Adds common test infrastructure files from the
./files/commontemplate directory - addFrameworkFiles -- Adds test runner-specific files from the
./files/{testRunner}template directory - hasE2ETester -- Checks if any project already has an
e2earchitect target configured - getNgCommandName -- Returns
'e2e'if no existing E2E tester is configured, or'puppeteer'if one exists
Template variables resolved include the project's base URL (protocol, host, port with SSL detection), relative path to the workspace tsconfig, and project root path.
Usage
This module is used by both the ng-add and e2e schematics to generate files from schematic templates into the appropriate project directories.
Code Reference
Source Location
packages/ng-schematics/src/schematics/utils/files.ts
Signature
export interface FilesOptions {
options: {
testRunner: TestRunner;
port: number;
name?: string;
exportConfig?: boolean;
ext?: string;
route?: string;
};
applyPath: string;
relativeToWorkspacePath: string;
movePath?: string;
}
export function addFilesToProjects(
projects: Record<string, AngularProject>,
options: FilesOptions,
): Rule;
export function addFilesSingle(
name: string,
project: AngularProject,
options: FilesOptions,
): Rule;
export function addCommonFiles(
projects: Record<string, AngularProject>,
filesOptions: Omit<FilesOptions, 'applyPath' | 'relativeToWorkspacePath'>,
): Rule;
export function addFrameworkFiles(
projects: Record<string, AngularProject>,
filesOptions: Omit<FilesOptions, 'applyPath' | 'relativeToWorkspacePath'>,
): Rule;
export function hasE2ETester(
projects: Record<string, AngularProject>,
): boolean;
export function getNgCommandName(
projects: Record<string, AngularProject>,
): string;
Import
import {
addCommonFiles,
addFrameworkFiles,
hasE2ETester,
getNgCommandName,
} from '../utils/files.js';
I/O Contract
Inputs
| Parameter | Type | Description |
|---|---|---|
| projects | Record<string, AngularProject> |
Map of Angular project names to their configuration objects |
| options.testRunner | TestRunner |
Selected test runner (Jasmine, Jest, Mocha, Node) |
| options.port | number |
Development server port number |
| options.name | string (optional) |
Test spec name for file generation |
| options.ext | string (optional) |
File extension (e2e or test)
|
| options.route | string (optional) |
Application route for the test |
| applyPath | string |
Path to the schematic template directory |
| relativeToWorkspacePath | string |
Relative path suffix from project to workspace root |
| movePath | string (optional) |
Subdirectory within the project to place generated files |
Outputs
| Function | Return Type | Description |
|---|---|---|
| addFilesToProjects | Rule |
Chained Angular schematic Rule that generates files for all projects |
| addFilesSingle | Rule |
Angular schematic Rule that generates files for a single project |
| addCommonFiles | Rule |
Rule that applies common templates from ./files/common
|
| addFrameworkFiles | Rule |
Rule that applies runner-specific templates from ./files/{testRunner}
|
| hasE2ETester | boolean |
Whether any project has an existing e2e architect target
|
| getNgCommandName | string |
'e2e' or 'puppeteer' based on existing configuration
|
Usage Examples
import {addCommonFiles, addFrameworkFiles, getNgCommandName} from '../utils/files.js';
import {TestRunner} from '../utils/types.js';
// Add common test files to all projects
const commonRule = addCommonFiles(projects, {
options: {
testRunner: TestRunner.Jest,
port: 4200,
ext: 'e2e',
},
});
// Add Jest-specific configuration files
const frameworkRule = addFrameworkFiles(projects, {
options: {
testRunner: TestRunner.Jest,
port: 4200,
},
});
// Determine the Angular CLI command name
const cmdName = getNgCommandName(projects);
// => 'e2e' (if no existing e2e tester) or 'puppeteer' (if one exists)