Skip to content

Commit e17cc66

Browse files
filipesilvahansl
authored andcommitted
test(@angular-devkit/schematics): add bazel tests
1 parent a6028a7 commit e17cc66

File tree

3 files changed

+118
-31
lines changed

3 files changed

+118
-31
lines changed

packages/angular_devkit/schematics/BUILD

Lines changed: 108 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,18 +32,51 @@ 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+
":testing",
51+
"//packages/angular_devkit/core",
52+
"//packages/angular_devkit/core:node",
53+
"@rxjs",
54+
"@rxjs//operators",
55+
# @typings: jasmine
56+
# @typings: node
57+
],
58+
)
59+
60+
jasmine_node_test(
61+
name = "schematics_test",
62+
srcs = [":schematics_test_lib"],
63+
)
64+
65+
66+
# @angular-devkit/schematics/tasks
67+
3168
ts_library(
3269
name = "tasks",
3370
srcs = glob(
3471
include = ["tasks/**/*.ts"],
3572
exclude = [
3673
"tasks/**/*_spec.ts",
3774
"tasks/**/*_benchmark.ts",
75+
"tasks/tslint-fix/test/**/*",
3876
],
3977
),
4078
module_name = "@angular-devkit/schematics/tasks",
41-
module_root = "tasks",
42-
tsconfig = "//:tsconfig.json",
79+
module_root = "tasks/index.d.ts",
4380
deps = [
4481
":schematics",
4582
"//packages/angular_devkit/core",
@@ -53,73 +90,120 @@ ts_library(
5390
)
5491

5592
ts_library(
56-
name = "tools",
93+
name = "tasks_test_lib",
5794
srcs = glob(
58-
include = ["tools/**/*.ts"],
95+
include = [
96+
"tasks/**/*_spec.ts",
97+
"tasks/**/*_spec_large.ts",
98+
"tasks/tslint-fix/test/**/*.ts",
99+
],
59100
exclude = [
60-
"tools/**/*_spec.ts",
61-
"tools/**/*_benchmark.ts",
101+
# Disabled because 'collection.json' cannot be resolved in bazel.
102+
# TODO(@filipesilva): figure out how to make data files resolve correctly.
103+
"tasks/tslint-fix/executor_spec.ts",
62104
],
63105
),
64-
module_name = "@angular-devkit/schematics/tools",
65-
module_root = "tools",
106+
data = [
107+
"tasks/tslint-fix/test/collection.json",
108+
],
66109
deps = [
67-
":schematics",
68110
":tasks",
111+
":testing",
112+
":schematics",
69113
"//packages/angular_devkit/core",
70114
"//packages/angular_devkit/core:node",
115+
"//packages/angular_devkit/core:node_testing",
71116
"@rxjs",
72117
"@rxjs//operators",
118+
# @typings: jasmine
73119
# @typings: node
74120
],
75121
)
76122

123+
124+
# Disabled since we are excluding the only test in tasks.
125+
# jasmine_node_test(
126+
# name = "tasks_test",
127+
# srcs = [":tasks_test_lib"],
128+
# )
129+
130+
131+
# @angular-devkit/schematics/tools
132+
77133
ts_library(
78-
name = "testing",
134+
name = "tools",
79135
srcs = glob(
80-
include = ["testing/**/*.ts"],
81-
exclude = [],
136+
include = ["tools/**/*.ts"],
137+
exclude = [
138+
"tools/**/*_spec.ts",
139+
"tools/**/*_benchmark.ts",
140+
],
82141
),
83-
module_name = "@angular-devkit/schematics/testing",
84-
module_root = "testing",
142+
module_name = "@angular-devkit/schematics/tools",
143+
module_root = "tools/index.d.ts",
85144
deps = [
86145
":schematics",
87146
":tasks",
88-
":tools",
89147
"//packages/angular_devkit/core",
148+
"//packages/angular_devkit/core:node",
90149
"@rxjs",
91150
"@rxjs//operators",
151+
# @typings: node
92152
],
93153
)
94154

95155
ts_library(
96-
name = "spec",
156+
name = "tools_test_lib",
97157
srcs = glob(
98-
include = ["src/**/*_spec.ts"],
158+
include = [
159+
"tools/**/*_spec.ts",
160+
"tools/**/*_spec_large.ts",
161+
],
162+
exclude = [
163+
# The node resolve spec uses the _devKitRoot global, which isn't available in Bazel.
164+
# TODO(@filipesilva): figure out an alternative to that global.
165+
"tools/file-system-engine-host_spec.ts",
166+
],
167+
),
168+
data = glob(
169+
include = ["tools/test/file-system-engine-host/**/collection.json"],
99170
),
100171
deps = [
172+
":tools",
173+
":tasks",
101174
":schematics",
102175
":testing",
103176
"//packages/angular_devkit/core",
177+
"//packages/angular_devkit/core:node",
104178
"@rxjs",
105179
"@rxjs//operators",
106180
# @typings: jasmine
181+
# @typings: node
107182
],
108183
)
109184

185+
jasmine_node_test(
186+
name = "tools_test",
187+
srcs = [":tools_test_lib"],
188+
)
189+
190+
191+
# @angular-devkit/schematics/testing
192+
110193
ts_library(
111-
name = "tools_spec",
194+
name = "testing",
112195
srcs = glob(
113-
include = ["tools/**/*_spec.ts"],
196+
include = ["testing/**/*.ts"],
197+
exclude = [],
114198
),
199+
module_name = "@angular-devkit/schematics/testing",
200+
module_root = "testing/index.d.ts",
115201
deps = [
116202
":schematics",
203+
":tasks",
117204
":tools",
118205
"//packages/angular_devkit/core",
119-
"//packages/angular_devkit/core:node",
120206
"@rxjs",
121207
"@rxjs//operators",
122-
# @typings: jasmine
123-
# @typings: node
124208
],
125-
)
209+
)

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/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)