Skip to content

Commit bad9750

Browse files
committed
test(@angular-devkit/schematics): add bazel tests
1 parent cfb31a7 commit bad9750

File tree

4 files changed

+116
-35
lines changed

4 files changed

+116
-35
lines changed

packages/angular_devkit/schematics/BUILD

Lines changed: 102 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,24 @@
55
package(default_visibility = ["//visibility:public"])
66

77
load("//tools:defaults.bzl", "ts_library")
8+
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")
89

910
licenses(["notice"]) # MIT License
1011

12+
# @angular-devkit/schematics
13+
1114
ts_library(
1215
name = "schematics",
1316
srcs = glob(
1417
include = ["src/**/*.ts"],
1518
exclude = [
1619
"src/**/*_spec.ts",
20+
"src/**/*_spec_large.ts",
1721
"src/**/*_benchmark.ts",
1822
],
1923
),
2024
module_name = "@angular-devkit/schematics",
21-
module_root = "src",
25+
module_root = "src/index.d.ts",
2226
deps = [
2327
"//packages/angular_devkit/core",
2428
"//packages/angular_devkit/core:node", # TODO: get rid of this for 6.0
@@ -28,6 +32,38 @@ ts_library(
2832
],
2933
)
3034

35+
ts_library(
36+
name = "schematics_test_lib",
37+
srcs = glob(
38+
include = [
39+
"src/**/*_spec.ts",
40+
"src/**/*_spec_large.ts",
41+
],
42+
exclude = [
43+
# Instances of extended errors are showing Error as the constructor instead.
44+
# TODO(@filipesilva): figure out why that is.
45+
"src/rules/call_spec.ts",
46+
],
47+
),
48+
deps = [
49+
":schematics",
50+
"//packages/angular_devkit/core",
51+
"//packages/angular_devkit/core:node",
52+
"@rxjs",
53+
"@rxjs//operators",
54+
# @typings: jasmine
55+
# @typings: node
56+
],
57+
)
58+
59+
jasmine_node_test(
60+
name = "schematics_test",
61+
srcs = [":schematics_test_lib"],
62+
)
63+
64+
65+
# @angular-devkit/schematics/tasks
66+
3167
ts_library(
3268
name = "tasks",
3369
srcs = glob(
@@ -38,8 +74,7 @@ ts_library(
3874
],
3975
),
4076
module_name = "@angular-devkit/schematics/tasks",
41-
module_root = "tasks",
42-
tsconfig = "//:tsconfig.json",
77+
module_root = "tasks/index.d.ts",
4378
deps = [
4479
":schematics",
4580
"//packages/angular_devkit/core",
@@ -53,72 +88,115 @@ ts_library(
5388
)
5489

5590
ts_library(
56-
name = "tools",
91+
name = "tasks_test_lib",
5792
srcs = glob(
58-
include = ["tools/**/*.ts"],
93+
include = [
94+
"tasks/**/*_spec.ts",
95+
"tasks/**/*_spec_large.ts",
96+
],
5997
exclude = [
60-
"tools/**/*_spec.ts",
61-
"tools/**/*_benchmark.ts",
98+
# Disabled because 'collection.json' cannot be resolved in bazel.
99+
# TODO(@filipesilva): figure out how to make data files resolve correctly.
100+
"tasks/tslint-fix/executor_spec.ts",
62101
],
63102
),
64-
module_name = "@angular-devkit/schematics/tools",
65-
module_root = "tools",
66103
deps = [
67-
":schematics",
68104
":tasks",
105+
":testing",
106+
":schematics",
69107
"//packages/angular_devkit/core",
70108
"//packages/angular_devkit/core:node",
109+
"//packages/angular_devkit/core:node_testing",
71110
"@rxjs",
72111
"@rxjs//operators",
112+
# @typings: jasmine
73113
# @typings: node
74114
],
75115
)
76116

117+
118+
# Disabled since we are excluding the only test in tasks.
119+
# jasmine_node_test(
120+
# name = "tasks_test",
121+
# srcs = [":tasks_test_lib"],
122+
# data = [
123+
# "tasks/tslint-fix/test/collection.json"
124+
# ],
125+
# )
126+
127+
128+
# @angular-devkit/schematics/tools
129+
77130
ts_library(
78-
name = "testing",
131+
name = "tools",
79132
srcs = glob(
80-
include = ["testing/**/*.ts"],
81-
exclude = [],
133+
include = ["tools/**/*.ts"],
134+
exclude = [
135+
"tools/**/*_spec.ts",
136+
"tools/**/*_benchmark.ts",
137+
],
82138
),
83-
module_name = "@angular-devkit/schematics/testing",
84-
module_root = "testing",
139+
module_name = "@angular-devkit/schematics/tools",
140+
module_root = "tools/index.d.ts",
85141
deps = [
86142
":schematics",
87143
":tasks",
88-
":tools",
89144
"//packages/angular_devkit/core",
145+
"//packages/angular_devkit/core:node",
90146
"@rxjs",
91147
"@rxjs//operators",
148+
# @typings: node
92149
],
93150
)
94151

95152
ts_library(
96-
name = "spec",
153+
name = "tools_test_lib",
97154
srcs = glob(
98-
include = ["src/**/*_spec.ts"],
155+
include = [
156+
"tools/**/*_spec.ts",
157+
"tools/**/*_spec_large.ts",
158+
],
159+
exclude = [
160+
# The node resolve spec uses the _devKitRoot global, which isn't available in Bazel.
161+
# TODO(@filipesilva): figure out an alternative to that global.
162+
"tools/file-system-engine-host_spec.ts",
163+
],
99164
),
100165
deps = [
166+
":tools",
167+
":tasks",
101168
":schematics",
102169
"//packages/angular_devkit/core",
170+
"//packages/angular_devkit/core:node",
103171
"@rxjs",
104172
"@rxjs//operators",
105173
# @typings: jasmine
174+
# @typings: node
106175
],
107176
)
108177

178+
jasmine_node_test(
179+
name = "tools_test",
180+
srcs = [":tools_test_lib"],
181+
)
182+
183+
184+
# @angular-devkit/schematics/testing
185+
109186
ts_library(
110-
name = "tools_spec",
187+
name = "testing",
111188
srcs = glob(
112-
include = ["tools/**/*_spec.ts"],
189+
include = ["testing/**/*.ts"],
190+
exclude = [],
113191
),
192+
module_name = "@angular-devkit/schematics/testing",
193+
module_root = "testing/index.d.ts",
114194
deps = [
115195
":schematics",
196+
":tasks",
116197
":tools",
117198
"//packages/angular_devkit/core",
118-
"//packages/angular_devkit/core:node",
119199
"@rxjs",
120200
"@rxjs//operators",
121-
# @typings: jasmine
122-
# @typings: node
123201
],
124-
)
202+
)

packages/angular_devkit/schematics/src/sink/host_spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// tslint:disable:no-implicit-dependencies
99
import { normalize, virtualFs } from '@angular-devkit/core';
1010
import { HostSink } from '@angular-devkit/schematics';
11-
import { fileBufferToString } from '../../../core/src/virtual-fs/host';
1211
import { HostCreateTree, HostTree } from '../tree/host-tree';
1312
import { optimize } from '../tree/static';
1413

@@ -133,7 +132,7 @@ describe('FileSystemSink', () => {
133132
.toPromise()
134133
.then(() => {
135134
expect(host.sync.read(normalize('/file0')).toString()).toBe('hello');
136-
expect(fileBufferToString(host.sync.read(normalize('/file1')))).toBe('world');
135+
expect(virtualFs.fileBufferToString(host.sync.read(normalize('/file1')))).toBe('world');
137136
})
138137
.then(done, done.fail);
139138
});

packages/angular_devkit/schematics/tasks/tslint-fix/executor_spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
// tslint:disable:no-implicit-dependencies
9-
import { getSystemPath, normalize, virtualFs } from '@angular-devkit/core';
9+
import { getSystemPath, logging, normalize, virtualFs } from '@angular-devkit/core';
1010
import { TempScopedNodeJsSyncHost } from '@angular-devkit/core/node/testing';
1111
import { HostTree } from '@angular-devkit/schematics';
1212
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
@@ -52,7 +52,7 @@ describe('TsLintTaskExecutor', () => {
5252
testRunner.runSchematicAsync('run-task', null, tree),
5353
new Observable<void>(obs => {
5454
process.chdir(getSystemPath(host.root));
55-
testRunner.logger.subscribe(x => messages.push(x.message));
55+
testRunner.logger.subscribe((x: logging.LogEntry) => messages.push(x.message));
5656
testRunner.engine.executePostTasks().subscribe(obs);
5757
}).pipe(
5858
catchError(() => {
@@ -88,7 +88,7 @@ describe('TsLintTaskExecutor', () => {
8888
testRunner.runSchematicAsync('custom-rule', { shouldPass: true }, tree),
8989
new Observable<void>(obs => {
9090
process.chdir(getSystemPath(host.root));
91-
testRunner.logger.subscribe(x => messages.push(x.message));
91+
testRunner.logger.subscribe((x: logging.LogEntry) => messages.push(x.message));
9292
testRunner.engine.executePostTasks().subscribe(obs);
9393
}),
9494
).toPromise().then(done, done.fail);
@@ -113,7 +113,7 @@ describe('TsLintTaskExecutor', () => {
113113
testRunner.runSchematicAsync('custom-rule', { shouldPass: false }, tree),
114114
new Observable<void>(obs => {
115115
process.chdir(getSystemPath(host.root));
116-
testRunner.logger.subscribe(x => messages.push(x.message));
116+
testRunner.logger.subscribe((x: logging.LogEntry) => messages.push(x.message));
117117
testRunner.engine.executePostTasks().subscribe(obs);
118118
}).pipe(
119119
catchError(() => {

packages/angular_devkit/schematics/tools/export-ref_spec.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,32 @@ import { ExportStringRef } from './export-ref';
1111

1212

1313
describe('ExportStringRef', () => {
14+
// Depending on how the package is built the module might be either .js or .ts.
15+
// To make expectations easier, we strip the extension.
16+
const stripExtension = (p: string) => p.replace(/\.(j|t)s$/, '');
17+
1418
it('works', () => {
1519
// META
1620
const ref = new ExportStringRef('./export-ref#ExportStringRef', __dirname);
1721
expect(ref.ref).toBe(ExportStringRef);
1822
expect(ref.path).toBe(__dirname);
19-
expect(ref.module).toBe(path.join(__dirname, 'export-ref.ts'));
23+
expect(stripExtension(ref.module)).toBe(path.join(__dirname, 'export-ref'));
2024
});
2125

2226
it('works without an inner ref', () => {
2327
// META
2428
const ref = new ExportStringRef(path.join(__dirname, 'export-ref'));
2529
expect(ref.ref).toBe(undefined);
2630
expect(ref.path).toBe(__dirname);
27-
expect(ref.module).toBe(path.join(__dirname, 'export-ref.ts'));
31+
expect(stripExtension(ref.module)).toBe(path.join(__dirname, 'export-ref'));
2832
});
2933

3034
it('returns the exports', () => {
3135
// META
3236
const ref = new ExportStringRef('./export-ref#ExportStringRef', __dirname, false);
3337
expect(ref.ref).toEqual({ ExportStringRef });
3438
expect(ref.path).toBe(__dirname);
35-
expect(ref.module).toBe(path.join(__dirname, 'export-ref.ts'));
39+
expect(stripExtension(ref.module)).toBe(path.join(__dirname, 'export-ref'));
3640
});
3741

3842
it('works on package names', () => {
@@ -42,13 +46,13 @@ describe('ExportStringRef', () => {
4246
);
4347
expect(ref.ref).toEqual(CollectionCannotBeResolvedException);
4448
expect(ref.path).toBe(__dirname);
45-
expect(ref.module).toBe(path.join(__dirname, 'index.ts'));
49+
expect(stripExtension(ref.module)).toBe(path.join(__dirname, 'index'));
4650
});
4751

4852
it('works on directory', () => {
4953
// META
5054
const ref = new ExportStringRef(__dirname);
5155
expect(ref.path).toBe(__dirname);
52-
expect(ref.module).toBe(path.join(__dirname, 'index.ts'));
56+
expect(stripExtension(ref.module)).toBe(path.join(__dirname, 'index'));
5357
});
5458
});

0 commit comments

Comments
 (0)