Skip to content

Commit 3108106

Browse files
committed
test(@angular-devkit/build-webpack): build and test with Bazel
1 parent f6d626a commit 3108106

File tree

28 files changed

+147
-122
lines changed

28 files changed

+147
-122
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Copyright Google Inc. All Rights Reserved.
2+
#
3+
# Use of this source code is governed by an MIT-style license that can be
4+
# found in the LICENSE file at https://angular.io/license
5+
6+
licenses(["notice"]) # MIT
7+
8+
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
9+
load("@npm_bazel_jasmine//:index.bzl", "jasmine_node_test")
10+
load("@npm_bazel_typescript//:index.bzl", "ts_library")
11+
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
12+
load("//tools:ts_json_schema.bzl", "ts_json_schema")
13+
14+
package(default_visibility = ["//visibility:public"])
15+
16+
ts_json_schema(
17+
name = "webpack_schema",
18+
src = "src/webpack/schema.json",
19+
)
20+
21+
ts_json_schema(
22+
name = "webpack_dev_server_schema",
23+
src = "src/webpack-dev-server/schema.json",
24+
)
25+
26+
ts_library(
27+
name = "build_webpack",
28+
srcs = glob(
29+
include = ["src/**/*.ts"],
30+
exclude = [
31+
"src/test-utils.ts",
32+
"src/**/*_spec.ts",
33+
],
34+
) + [
35+
"//packages/angular_devkit/build_webpack:src/webpack/schema.ts",
36+
"//packages/angular_devkit/build_webpack:src/webpack-dev-server/schema.ts",
37+
],
38+
data = glob(
39+
include = [
40+
"package.json",
41+
"builders.json",
42+
"src/webpack/schema.json",
43+
"src/webpack-dev-server/schema.json",
44+
],
45+
),
46+
devmode_module = "commonjs",
47+
devmode_target = "es2018",
48+
module_name = "@angular-devkit/build-webpack",
49+
module_root = "src/index.d.ts",
50+
deps = [
51+
"//packages/angular_devkit/architect",
52+
"//packages/angular_devkit/core",
53+
"@npm//@types/node",
54+
"@npm//@types/webpack",
55+
"@npm//@types/webpack-dev-server",
56+
"@npm//rxjs",
57+
"@npm//webpack",
58+
"@npm//webpack-dev-server",
59+
],
60+
)
61+
62+
ts_library(
63+
name = "build_webpack_test_lib",
64+
testonly = True,
65+
srcs = glob(
66+
include = [
67+
"src/test-utils.ts",
68+
"src/**/*_spec.ts",
69+
],
70+
),
71+
data = glob(
72+
include = [
73+
"test/**/*",
74+
],
75+
),
76+
devmode_module = "commonjs",
77+
devmode_target = "es2018",
78+
tsconfig = "//:tsconfig-test.json",
79+
deps = [
80+
":build_webpack",
81+
"//packages/angular_devkit/architect",
82+
"//packages/angular_devkit/architect/node",
83+
"//packages/angular_devkit/architect/testing",
84+
"//packages/angular_devkit/core",
85+
"//packages/angular_devkit/core/node",
86+
"//packages/ngtools/webpack",
87+
"@npm//@angular/common",
88+
"@npm//@angular/compiler",
89+
"@npm//@angular/compiler-cli",
90+
"@npm//@angular/core",
91+
"@npm//@angular/platform-browser",
92+
"@npm//@angular/platform-browser-dynamic",
93+
"@npm//@types/jasmine",
94+
"@npm//@types/node",
95+
"@npm//@types/node-fetch",
96+
"@npm//node-fetch",
97+
"@npm//raw-loader",
98+
"@npm//tslib",
99+
"@npm//zone.js",
100+
],
101+
)
102+
103+
jasmine_node_test(
104+
name = "build_webpack_test",
105+
srcs = [":build_webpack_test_lib"],
106+
# Turns off nodejs require patches and turns on the linker, which sets up up node_modules
107+
# so that standard node module resolution work.
108+
templated_args = ["--nobazel_patch_module_resolver"],
109+
deps = [
110+
"@npm//jasmine",
111+
"@npm//source-map",
112+
],
113+
)
114+
115+
pkg_npm(
116+
name = "npm_package",
117+
deps = [
118+
":build_webpack",
119+
],
120+
)
121+
122+
pkg_tar(
123+
name = "npm_package_archive",
124+
srcs = [":npm_package"],
125+
extension = "tar.gz",
126+
strip_prefix = "./npm_package",
127+
tags = ["manual"],
128+
)

packages/angular_devkit/build_webpack/package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,5 @@
1414
"peerDependencies": {
1515
"webpack": "^4.6.0",
1616
"webpack-dev-server": "^3.1.4"
17-
},
18-
"devDependencies": {
19-
"webpack": "4.42.1",
20-
"webpack-dev-server": "^3.1.4"
2117
}
2218
}

packages/angular_devkit/build_webpack/src/test-utils.ts

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

packages/angular_devkit/build_webpack/src/webpack-dev-server/index_spec_large.ts renamed to packages/angular_devkit/build_webpack/src/webpack-dev-server/index_spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import fetch from 'node-fetch'; // tslint:disable-line:no-implicit-dependencies
1414
import * as path from 'path';
1515
import { DevServerBuildOutput } from './index';
1616

17-
const devkitRoot = (global as any)._DevKitRoot; // tslint:disable-line:no-any
18-
1917

2018
describe('Dev Server Builder', () => {
2119
let testArchitectHost: TestingArchitectHost;
@@ -41,7 +39,9 @@ describe('Dev Server Builder', () => {
4139
}
4240

4341
beforeEach(async () => {
44-
await createArchitect(path.join(devkitRoot, 'tests/angular_devkit/build_webpack/basic-app/'));
42+
const ngJsonPath = path.join(__dirname, '../../test/basic-app/angular.json');
43+
const workspaceRoot = path.dirname(require.resolve(ngJsonPath));
44+
await createArchitect(workspaceRoot);
4545
});
4646

4747
it('works', async () => {

packages/angular_devkit/build_webpack/src/webpack/index_spec_large.ts renamed to packages/angular_devkit/build_webpack/src/webpack/index_spec.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ import { Architect } from '@angular-devkit/architect';
99
import { WorkspaceNodeModulesArchitectHost } from '@angular-devkit/architect/node';
1010
import { TestingArchitectHost } from '@angular-devkit/architect/testing';
1111
import { join, normalize, schema, workspaces } from '@angular-devkit/core';
12-
import { NodeJsSyncHost } from '@angular-devkit/core/node';
12+
import { NodeJsSyncHost, createConsoleLogger } from '@angular-devkit/core/node';
1313
import * as path from 'path';
1414
import { BuildResult } from './index';
1515

16-
const devkitRoot = (global as any)._DevKitRoot; // tslint:disable-line:no-any
17-
1816

1917
describe('Webpack Builder basic test', () => {
2018
let testArchitectHost: TestingArchitectHost;
@@ -38,7 +36,8 @@ describe('Webpack Builder basic test', () => {
3836
}
3937

4038
describe('basic app', () => {
41-
const workspaceRoot = path.join(devkitRoot, 'tests/angular_devkit/build_webpack/basic-app/');
39+
const ngJsonPath = path.join(__dirname, '../../test/basic-app/angular.json');
40+
const workspaceRoot = path.dirname(require.resolve(ngJsonPath));
4241
const outputPath = join(normalize(workspaceRoot), 'dist');
4342

4443
beforeEach(async () => {
@@ -72,15 +71,17 @@ describe('Webpack Builder basic test', () => {
7271
});
7372

7473
describe('Angular app', () => {
75-
const workspaceRoot = path.join(devkitRoot, 'tests/angular_devkit/build_webpack/angular-app/');
76-
const outputPath = join(normalize(workspaceRoot), 'dist/');
74+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 150000;
75+
const ngJsonPath = path.join(__dirname, '../../test/angular-app/angular.json');
76+
const workspaceRoot = path.dirname(require.resolve(ngJsonPath));
77+
const outputPath = join(normalize(workspaceRoot), 'dist');
7778

7879
beforeEach(async () => {
7980
await createArchitect(workspaceRoot);
8081
});
8182

8283
it('works', async () => {
83-
const run = await architect.scheduleTarget({ project: 'app', target: 'build-webpack' });
84+
const run = await architect.scheduleTarget({ project: 'app', target: 'build-webpack' }, {}, {logger: createConsoleLogger()});
8485
const output = await run.result;
8586

8687
expect(output.success).toBe(true);

tests/angular_devkit/build_webpack/angular-app/angular.json renamed to packages/angular_devkit/build_webpack/test/angular-app/angular.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
"schematics": {},
1414
"targets": {
1515
"build-webpack": {
16-
"builder": "../../../../packages/angular_devkit/build_webpack:webpack",
16+
"builder": "../../:webpack",
1717
"options": {
1818
"webpackConfig": "webpack.config.js"
1919
}
2020
},
2121
"serve-webpack": {
22-
"builder": "../../../../packages/angular_devkit/build_webpack:webpack-dev-server",
22+
"builder": "../../:webpack-dev-server",
2323
"options": {
2424
"webpackConfig": "webpack.config.js"
2525
}

tests/angular_devkit/build_webpack/angular-app/webpack.config.js renamed to packages/angular_devkit/build_webpack/test/angular-app/webpack.config.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const projectRoot = path.resolve(__dirname, './');
88
module.exports = {
99
mode: 'development',
1010
resolve: {
11-
extensions: ['.ts', '.js']
11+
extensions: ['.ts', '.js'],
1212
},
1313
entry: {
1414
main: path.resolve(projectRoot, './src/main.ts'),
@@ -25,11 +25,9 @@ module.exports = {
2525
],
2626
module: {
2727
rules: [
28-
{ test: /\.scss$/, loaders: ['raw-loader', 'sass-loader'] },
2928
{ test: /\.css$/, loader: 'raw-loader' },
3029
{ test: /\.html$/, loader: 'raw-loader' },
31-
// require.resolve is required only because of the monorepo structure here.
32-
{ test: /\.ts$/, loader: require.resolve('@ngtools/webpack') }
30+
{ test: /\.ts$/, loader: '@ngtools/webpack' },
3331
]
3432
},
3533
devServer: {

tests/angular_devkit/build_webpack/basic-app/angular.json renamed to packages/angular_devkit/build_webpack/test/basic-app/angular.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "../../../../packages/angular_devkit/core/src/workspace/workspace-schema.json",
2+
"$schema": "../../../core/src/workspace/workspace-schema.json",
33
"version": 1,
44
"newProjectRoot": "./projects",
55
"cli": {},
@@ -13,13 +13,13 @@
1313
"schematics": {},
1414
"targets": {
1515
"build": {
16-
"builder": "../../../../packages/angular_devkit/build_webpack:webpack",
16+
"builder": "../../:webpack",
1717
"options": {
1818
"webpackConfig": "webpack.config.js"
1919
}
2020
},
2121
"serve": {
22-
"builder": "../../../../packages/angular_devkit/build_webpack:webpack-dev-server",
22+
"builder": "../../:webpack-dev-server",
2323
"options": {
2424
"webpackConfig": "webpack.config.js"
2525
}

tests/angular_devkit/build_webpack/angular-app/src/app/app.server.module.ts

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

tests/angular_devkit/build_webpack/angular-app/src/src/locale/messages.xlf

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

tests/angular_devkit/build_webpack/angular-app/src/styles.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/angular_devkit/build_webpack/basic-app/.gitignore

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

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"node_modules/**/*",
5959
"packages/_/devkit/**/*files/**/*",
6060
"packages/schematics/*/*/*files/**/*",
61+
"packages/angular_devkit/*/test/**/*",
6162
"tmp/**/*",
6263
"scripts/patches/**/*",
6364
"tests/**/*",

0 commit comments

Comments
 (0)