Skip to content

Initial Web Test Runner Implementation #25860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 3, 2024
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
"@typescript-eslint/eslint-plugin": "6.17.0",
"@typescript-eslint/parser": "6.17.0",
"@vitejs/plugin-basic-ssl": "1.0.2",
"@web/test-runner": "^0.17.3",
"@yarnpkg/lockfile": "1.1.0",
"ajv": "8.12.0",
"ajv-formats": "2.1.1",
Expand Down
1 change: 1 addition & 0 deletions packages/angular/cli/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ CLI_SCHEMA_DATA = [
"//packages/angular_devkit/build_angular:src/builders/dev-server/schema.json",
"//packages/angular_devkit/build_angular:src/builders/extract-i18n/schema.json",
"//packages/angular_devkit/build_angular:src/builders/jest/schema.json",
"//packages/angular_devkit/build_angular:src/builders/web-test-runner/schema.json",
"//packages/angular_devkit/build_angular:src/builders/karma/schema.json",
"//packages/angular_devkit/build_angular:src/builders/ng-packagr/schema.json",
"//packages/angular_devkit/build_angular:src/builders/prerender/schema.json",
Expand Down
23 changes: 23 additions & 0 deletions packages/angular/cli/lib/config/workspace-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@
"@angular-devkit/build-angular:ng-packagr",
"@angular-devkit/build-angular:prerender",
"@angular-devkit/build-angular:jest",
"@angular-devkit/build-angular:web-test-runner",
"@angular-devkit/build-angular:protractor",
"@angular-devkit/build-angular:server",
"@angular-devkit/build-angular:ssr-dev-server"
Expand Down Expand Up @@ -564,6 +565,28 @@
}
}
},
{
"type": "object",
"additionalProperties": false,
"properties": {
"builder": {
"const": "@angular-devkit/build-angular:web-test-runner"
},
"defaultConfiguration": {
"type": "string",
"description": "A default named configuration to use when a target configuration is not provided."
},
"options": {
"$ref": "../../../../angular_devkit/build_angular/src/builders/web-test-runner/schema.json"
},
"configurations": {
"type": "object",
"additionalProperties": {
"$ref": "../../../../angular_devkit/build_angular/src/builders/web-test-runner/schema.json"
}
}
}
},
{
"type": "object",
"additionalProperties": false,
Expand Down
13 changes: 8 additions & 5 deletions packages/angular_devkit/build_angular/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ ts_json_schema(
src = "src/builders/prerender/schema.json",
)

ts_json_schema(
name = "web_test_runner_schema",
src = "src/builders/web-test-runner/schema.json",
)

ts_library(
name = "build_angular",
package_name = "@angular-devkit/build-angular",
Expand Down Expand Up @@ -106,6 +111,7 @@ ts_library(
"//packages/angular_devkit/build_angular:src/builders/protractor/schema.ts",
"//packages/angular_devkit/build_angular:src/builders/server/schema.ts",
"//packages/angular_devkit/build_angular:src/builders/ssr-dev-server/schema.ts",
"//packages/angular_devkit/build_angular:src/builders/web-test-runner/schema.ts",
],
data = glob(
include = [
Expand Down Expand Up @@ -156,6 +162,7 @@ ts_library(
"@npm//@types/text-table",
"@npm//@types/watchpack",
"@npm//@vitejs/plugin-basic-ssl",
"@npm//@web/test-runner",
"@npm//ajv",
"@npm//ansi-colors",
"@npm//autoprefixer",
Expand Down Expand Up @@ -228,6 +235,7 @@ ts_library(
":build_angular_test_utils",
"//packages/angular_devkit/architect/testing",
"//packages/angular_devkit/core",
"@npm//fast-glob",
"@npm//prettier",
"@npm//typescript",
"@npm//webpack",
Expand Down Expand Up @@ -367,11 +375,6 @@ LARGE_SPECS = {
},
"prerender": {},
"browser-esbuild": {},
"jest": {
"extra_deps": [
"@npm//fast-glob",
],
},
"ssr-dev-server": {
"extra_deps": [
"@npm//@types/browser-sync",
Expand Down
5 changes: 5 additions & 0 deletions packages/angular_devkit/build_angular/builders.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
"schema": "./src/builders/karma/schema.json",
"description": "Run Karma unit tests."
},
"web-test-runner": {
"implementation": "./src/builders/web-test-runner",
"schema": "./src/builders/web-test-runner/schema.json",
"description": "Run unit tests with Web Test Runner."
},
"protractor": {
"implementation": "./src/builders/protractor",
"schema": "./src/builders/protractor/schema.json",
Expand Down
4 changes: 4 additions & 0 deletions packages/angular_devkit/build_angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"@angular/localize": "^17.0.0 || ^17.1.0-next.0",
"@angular/platform-server": "^17.0.0 || ^17.1.0-next.0",
"@angular/service-worker": "^17.0.0 || ^17.1.0-next.0",
"@web/test-runner": "^0.17.3",
"browser-sync": "^3.0.2",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
Expand All @@ -98,6 +99,9 @@
"@angular/service-worker": {
"optional": true
},
"@web/test-runner": {
"optional": true
},
"browser-sync": {
"optional": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,9 @@ function normalizeEntryPoints(
? parsedEntryPoint.name
: path.join(parsedEntryPoint.dir, parsedEntryPoint.name);

// Get the full file path to the entry point input.
const entryPointPath = path.isAbsolute(entryPoint)
? entryPoint
: path.join(workspaceRoot, entryPoint);
// Get the full file path to a relative entry point input. Leave bare specifiers alone so they are resolved as modules.
const isRelativePath = entryPoint.startsWith('.');
const entryPointPath = isRelativePath ? path.join(workspaceRoot, entryPoint) : entryPoint;

// Check for conflicts with previous entry points.
const existingEntryPointPath = entryPointPaths[entryPointName];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import { execFile as execFileCb } from 'child_process';
import * as path from 'path';
import { promisify } from 'util';
import { colors } from '../../utils/color';
import { findTestFiles } from '../../utils/test-files';
import { buildApplicationInternal } from '../application';
import { ApplicationBuilderInternalOptions } from '../application/options';
import { OutputHashing } from '../browser-esbuild/schema';
import { normalizeOptions } from './options';
import { Schema as JestBuilderSchema } from './schema';
import { findTestFiles } from './test-files';

const execFile = promisify(execFileCb);

Expand Down Expand Up @@ -55,7 +55,7 @@ export default createBuilder(
}

// Build all the test files.
const testFiles = await findTestFiles(options, context.workspaceRoot);
const testFiles = await findTestFiles(options.include, options.exclude, context.workspaceRoot);
const jestGlobal = path.join(__dirname, 'jest-global.mjs');
const initTestBed = path.join(__dirname, 'init-test-bed.mjs');
const buildResult = await build(context, {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import { BuilderContext } from '@angular-devkit/architect';
import { Schema as WtrBuilderOptions } from './schema';

const UNSUPPORTED_OPTIONS: Array<keyof WtrBuilderOptions> = [
'main',
'assets',
'scripts',
'styles',
'inlineStyleLanguage',
'stylePreprocessorOptions',
'sourceMap',
'progress',
'poll',
'preserveSymlinks',
'browsers',
'codeCoverage',
'codeCoverageExclude',
'fileReplacements',
'webWorkerTsConfig',
'watch',
];

/** Logs a warning for any unsupported options specified. */
export function logBuilderStatusWarnings(options: WtrBuilderOptions, ctx: BuilderContext) {
// Validate supported options
for (const unsupportedOption of UNSUPPORTED_OPTIONS) {
const value = (options as unknown as WtrBuilderOptions)[unsupportedOption];

if (value === undefined || value === false) {
continue;
}
if (Array.isArray(value) && value.length === 0) {
continue;
}
if (typeof value === 'object' && Object.keys(value).length === 0) {
continue;
}

ctx.logger.warn(`The '${unsupportedOption}' option is not yet supported by this builder.`);
}
}
Loading