Skip to content

Commit 352153f

Browse files
committed
test: add an integration test to verify mdc-migration against a golden (#24266)
1 parent cb72123 commit 352153f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3298
-3638
lines changed

.bazelignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ integration/yarn-pnp-compat/node_modules
2020

2121
integration/mdc-migration/.angular
2222
integration/mdc-migration/node_modules
23+
integration/mdc-migration/golden/.angular
24+
integration/mdc-migration/golden/node_modules
25+
integration/mdc-migration/sample-project/.angular
26+
integration/mdc-migration/sample-project/node_modules

integration/mdc-migration/BUILD.bazel

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,52 @@
1-
load("@bazel_skylib//lib:dicts.bzl", "dicts")
2-
load("//tools:integration.bzl", "CLI_PROJECT_MAPPINGS")
3-
load("//tools:defaults.bzl", "node_integration_test")
1+
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
2+
load("//tools:defaults.bzl", "ts_library")
3+
load(":migration-test.bzl", "migration_test")
44

5-
npmPackageMappings = dicts.add(
6-
CLI_PROJECT_MAPPINGS,
7-
{
8-
"//src/cdk:npm_package_archive": "@angular/cdk",
9-
"//src/material:npm_package_archive": "@angular/material",
10-
"//src/material-experimental:npm_package_archive": "@angular/material-experimental",
11-
},
5+
ts_library(
6+
name = "verify_golden_lib",
7+
srcs = ["verify-golden.ts"],
8+
# TODO(ESM): remove this once the Bazel NodeJS rules can handle ESM with `nodejs_binary`.
9+
devmode_module = "commonjs",
10+
deps = [
11+
"@npm//@types/node",
12+
],
13+
)
14+
15+
nodejs_binary(
16+
name = "verify_golden",
17+
data = [":verify_golden_lib"],
18+
entry_point = ":verify-golden.ts",
19+
templated_args = ["--bazel_patch_module_resolver"],
1220
)
1321

14-
node_integration_test(
22+
filegroup(
23+
name = "test_project",
24+
srcs = glob([
25+
"sample-project/**/*",
26+
]),
27+
)
28+
29+
filegroup(
30+
name = "golden_project",
31+
srcs = glob([
32+
"golden/**/*",
33+
]),
34+
)
35+
36+
migration_test(
1537
name = "test",
16-
srcs = glob(["**/*"]),
17-
commands = [
18-
# Note: We use a cache folder within the integration test as otherwise
19-
# the NPM package mapped archive would be cached in the system.
20-
# See: https://github.com/yarnpkg/yarn/issues/2165.
21-
# TODO(devversion): determine if a solution/workaround could live in the test runner.
22-
"yarn install --cache-folder .yarn_cache_folder/",
23-
"yarn ng generate @angular/material:mdc-migration -c all --tsconfig tsconfig.app.json",
24-
"yarn test",
25-
],
26-
npm_packages = npmPackageMappings,
27-
tags = [
28-
# Chromium cannot run in Sandbox. For this test, sandbox is disabled.
29-
# Additionally, we need to disable RBE as this test relies on internet
30-
# access for installing the NPM packages.
31-
"no-sandbox",
32-
"no-remote-exec",
33-
],
38+
srcs = glob([
39+
"golden/**/*",
40+
"sample-project/**/*",
41+
]),
42+
approve = False,
43+
)
44+
45+
migration_test(
46+
name = "test.approve",
47+
srcs = glob([
48+
"golden/**/*",
49+
"sample-project/**/*",
50+
]),
51+
approve = True,
3452
)

integration/mdc-migration/.gitignore renamed to integration/mdc-migration/golden/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ chrome-profiler-events*.json
3131
.history/*
3232

3333
# misc
34+
/.angular/cache
3435
/.sass-cache
3536
/connect.lock
3637
/coverage
File renamed without changes.

integration/mdc-migration/angular.json renamed to integration/mdc-migration/golden/angular.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": 1,
44
"newProjectRoot": "projects",
55
"projects": {
6-
"mdc-migration": {
6+
"sample-project": {
77
"projectType": "application",
88
"schematics": {
99
"@schematics/angular:component": {
@@ -20,7 +20,7 @@
2020
"build": {
2121
"builder": "@angular-devkit/build-angular:browser",
2222
"options": {
23-
"outputPath": "dist/mdc-migration",
23+
"outputPath": "dist/sample-project",
2424
"index": "src/index.html",
2525
"main": "src/main.ts",
2626
"polyfills": "src/polyfills.ts",
@@ -72,18 +72,18 @@
7272
"builder": "@angular-devkit/build-angular:dev-server",
7373
"configurations": {
7474
"production": {
75-
"browserTarget": "mdc-migration:build:production"
75+
"browserTarget": "sample-project:build:production"
7676
},
7777
"development": {
78-
"browserTarget": "mdc-migration:build:development"
78+
"browserTarget": "sample-project:build:development"
7979
}
8080
},
8181
"defaultConfiguration": "development"
8282
},
8383
"extract-i18n": {
8484
"builder": "@angular-devkit/build-angular:extract-i18n",
8585
"options": {
86-
"browserTarget": "mdc-migration:build"
86+
"browserTarget": "sample-project:build"
8787
}
8888
},
8989
"test": {
@@ -108,5 +108,5 @@
108108
}
109109
}
110110
},
111-
"defaultProject": "mdc-migration"
111+
"defaultProject": "sample-project"
112112
}

integration/mdc-migration/karma.conf.js renamed to integration/mdc-migration/golden/karma.conf.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
// Karma configuration file, see link for more information
22
// https://karma-runner.github.io/1.0/config/configuration-file.html
33

4-
// This code runs within Bazel where the environment does not have access to
5-
// the system Chrome browser. To workaround this we use Puppeteer to provide
6-
// a local version of Chromium that can run within Bazel.
7-
process.env.CHROME_BIN = require('puppeteer').executablePath();
8-
94
module.exports = function (config) {
105
config.set({
116
basePath: '',
@@ -30,16 +25,22 @@ module.exports = function (config) {
3025
suppressAll: true, // removes the duplicated traces
3126
},
3227
coverageReporter: {
33-
dir: require('path').join(__dirname, './coverage/mdc-migration'),
28+
dir: require('path').join(__dirname, './coverage/sample-project'),
3429
subdir: '.',
3530
reporters: [{type: 'html'}, {type: 'text-summary'}],
3631
},
32+
customLaunchers: {
33+
ChromeHeadlessNoSandbox: {
34+
base: 'ChromeHeadless',
35+
flags: ['--no-sandbox'],
36+
},
37+
},
3738
reporters: ['progress', 'kjhtml'],
3839
port: 9876,
3940
colors: true,
4041
logLevel: config.LOG_INFO,
4142
autoWatch: true,
42-
browsers: ['ChromeHeadless'],
43+
browsers: ['ChromeHeadlessNoSandbox'],
4344
singleRun: false,
4445
restartOnFileChange: true,
4546
});

0 commit comments

Comments
 (0)