Skip to content

Commit 468f180

Browse files
committed
build: update integration tests to use first-party packages
Updates integration tests to work with the linked first-party packages.
1 parent fa73902 commit 468f180

File tree

7 files changed

+28
-95
lines changed

7 files changed

+28
-95
lines changed

integration/BUILD.bazel

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
1+
load("@npm2//:defs.bzl", "npm_link_all_packages")
22

33
package(default_visibility = ["//visibility:public"])
44

5-
# JavaScript library that exposes a script for retrieving all NPM packages
6-
# available in the runfiles of an action.
7-
js_library(
8-
name = "npm-packages-from-runfiles",
9-
srcs = ["npm-packages-from-runfiles.mjs"],
10-
)
5+
npm_link_all_packages()

integration/linker/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ js_test(
1010
"//:node_modules/@babel/core",
1111
"//:node_modules/chalk",
1212
"//:node_modules/glob",
13-
"//integration:npm-packages-from-runfiles",
1413
"//src/cdk:npm_package",
1514
"//src/cdk-experimental:npm_package",
1615
"//src/google-maps:npm_package",

integration/npm-packages-from-runfiles.mjs

Lines changed: 0 additions & 38 deletions
This file was deleted.

integration/package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
{}
1+
{
2+
"dependencies": {
3+
"@angular/cdk": "workspace:*",
4+
"@angular/cdk-experimental": "workspace:*",
5+
"@angular/material": "workspace:*",
6+
"@angular/material-experimental": "workspace:*",
7+
"@angular/google-maps": "workspace:*",
8+
"@angular/youtube-player": "workspace:*"
9+
}
10+
}

integration/ts-compat/BUILD.bazel

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("@bazel_skylib//rules:write_file.bzl", "write_file")
2-
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")
2+
load("@aspect_rules_js//js:defs.bzl", "js_test")
33
load("//integration/ts-compat:import-all-entry-points.bzl", "generate_import_all_entry_points_file")
44

55
package(default_visibility = ["//visibility:public"])
@@ -18,24 +18,23 @@ typescript_version_packages = [
1818

1919
# Generates a NodeJS test for each configured TypeScript version.
2020
[
21-
nodejs_test(
21+
js_test(
2222
name = ts_pkg_name,
2323
args = [ts_pkg_name],
24+
chdir = package_name(),
2425
data = [
2526
"helpers.mjs",
2627
"test.mjs",
2728
":import-all-entry-points-file",
28-
"//integration:npm-packages-from-runfiles",
29-
"//src/cdk:npm_package",
30-
"//src/cdk-experimental:npm_package",
31-
"//src/google-maps:npm_package",
32-
"//src/material:npm_package",
33-
"//src/material-experimental:npm_package",
34-
"//src/youtube-player:npm_package",
35-
"@npm//@bazel/runfiles",
36-
"@npm//shelljs",
37-
"@npm//%s" % ts_pkg_name,
38-
"@npm//@types/node",
29+
"//:node_modules/shelljs",
30+
"//integration:node_modules/@angular/cdk",
31+
"//integration:node_modules/@angular/cdk-experimental",
32+
"//integration:node_modules/@angular/google-maps",
33+
"//integration:node_modules/@angular/material",
34+
"//integration:node_modules/@angular/material-experimental",
35+
"//integration:node_modules/@angular/youtube-player",
36+
"//:node_modules/%s" % ts_pkg_name,
37+
"//:node_modules/@types/node",
3938
],
4039
entry_point = "test.mjs",
4140
)

integration/ts-compat/helpers.mjs

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
1-
import {join} from 'path';
2-
import {unlinkSync} from 'fs';
1+
import path from 'path';
32
import shelljs from 'shelljs';
43
import {fork} from 'child_process';
5-
import {getNpmPackagesFromRunfiles} from '../npm-packages-from-runfiles.mjs';
6-
import {runfiles} from '@bazel/runfiles';
74

85
// Exit if any command fails.
96
shelljs.set('-e');
107

11-
// List of NPM packages that have been built for the current test target.
12-
const npmPackages = getNpmPackagesFromRunfiles();
13-
// Path to the node modules of the workspace.
14-
const nodeModulesDir = runfiles.resolve('npm/node_modules');
158
// Path to the generated file that imports all entry-points.
16-
const testFilePath = runfiles.resolveWorkspaceRelative(
17-
'integration/ts-compat/import-all-entry-points.ts',
18-
);
9+
const testFilePath = path.resolve('./import-all-entry-points.ts');
1910

2011
/**
2112
* Runs the TypeScript compatibility test with the specified tsc binary. The
@@ -24,42 +15,20 @@ const testFilePath = runfiles.resolveWorkspaceRelative(
2415
*/
2516
export async function runTypeScriptCompatibilityTest(tscBinPath) {
2617
return new Promise((resolve, reject) => {
27-
const angularDir = join(nodeModulesDir, '@angular/');
28-
29-
// Create the `node_modules/@angular` directory in case it's not present.
30-
shelljs.mkdir('-p', angularDir);
31-
32-
// Symlink npm packages into `node_modules/` so that the project can
33-
// be compiled without path mappings (simulating a real project).
34-
for (const {name, pkgPath} of npmPackages) {
35-
console.info(`Linking "@angular/${name}" into node modules..`);
36-
shelljs.ln('-sf', pkgPath, join(angularDir, name));
37-
}
38-
3918
const tscArgs = [
4019
'--strict',
4120
// Disables automatic type resolution. In non-sandbox environments, the node modules
4221
// are accessible and types could end up as part of the program.
4322
'--types',
4423
'--lib',
4524
'es2015,dom',
46-
// Ensures that `node_modules` can be resolved. By default, in sandbox environments the
47-
// node modules cannot be resolved because they are wrapped in the `npm/node_modules` folder
48-
'--baseUrl',
49-
nodeModulesDir,
5025
testFilePath,
5126
];
5227
// Run `tsc` to compile the project. The stdout/stderr output is inherited, so that
5328
// warnings and errors are printed to the console.
5429
const tscProcess = fork(tscBinPath, tscArgs, {stdio: 'inherit'});
5530

5631
tscProcess.on('exit', exitCode => {
57-
// Remove symlinks to keep a clean repository state.
58-
for (const {name} of npmPackages) {
59-
console.info(`Removing link for "@angular/${name}"..`);
60-
unlinkSync(join(angularDir, name));
61-
shelljs.rm('-rf', join(angularDir, name));
62-
}
6332
exitCode === 0 ? resolve() : reject();
6433
});
6534
});

integration/ts-compat/test.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
* by a Bazel `nodejs_test` target and relies on Bazel runfile resolution.
55
*/
66

7-
import {runfiles} from '@bazel/runfiles';
87
import {runTypeScriptCompatibilityTest} from './helpers.mjs';
8+
import path from 'path';
99

1010
const [pkgName] = process.argv.slice(2);
1111
if (!pkgName) {
1212
console.error('No TypeScript package specified. Exiting..');
1313
process.exit(1);
1414
}
1515

16-
const tscBin = runfiles.resolve(`npm/node_modules/${pkgName}/bin/tsc`);
16+
const tscBin = path.resolve(`../../node_modules/${pkgName}/bin/tsc`);
1717

1818
runTypeScriptCompatibilityTest(tscBin).catch(e => {
1919
console.error(e);

0 commit comments

Comments
 (0)