test(@angular-devkit/schematics): add bazel tests

This commit is contained in:
Filipe Silva 2018-08-03 13:50:19 +01:00 committed by Hans
parent a6028a7761
commit e17cc66f93
3 changed files with 132 additions and 45 deletions

View File

@ -5,20 +5,24 @@
package(default_visibility = ["//visibility:public"])
load("//tools:defaults.bzl", "ts_library")
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")
licenses(["notice"]) # MIT License
# @angular-devkit/schematics
ts_library(
name = "schematics",
srcs = glob(
include = ["src/**/*.ts"],
exclude = [
"src/**/*_spec.ts",
"src/**/*_spec_large.ts",
"src/**/*_benchmark.ts",
],
),
module_name = "@angular-devkit/schematics",
module_root = "src",
module_root = "src/index.d.ts",
deps = [
"//packages/angular_devkit/core",
"//packages/angular_devkit/core:node", # TODO: get rid of this for 6.0
@ -28,6 +32,39 @@ ts_library(
],
)
ts_library(
name = "schematics_test_lib",
srcs = glob(
include = [
"src/**/*_spec.ts",
"src/**/*_spec_large.ts",
],
exclude = [
# Instances of extended errors are showing Error as the constructor instead.
# TODO(@filipesilva): figure out why that is.
"src/rules/call_spec.ts",
],
),
deps = [
":schematics",
":testing",
"//packages/angular_devkit/core",
"//packages/angular_devkit/core:node",
"@rxjs",
"@rxjs//operators",
# @typings: jasmine
# @typings: node
],
)
jasmine_node_test(
name = "schematics_test",
srcs = [":schematics_test_lib"],
)
# @angular-devkit/schematics/tasks
ts_library(
name = "tasks",
srcs = glob(
@ -35,11 +72,11 @@ ts_library(
exclude = [
"tasks/**/*_spec.ts",
"tasks/**/*_benchmark.ts",
"tasks/tslint-fix/test/**/*",
],
),
module_name = "@angular-devkit/schematics/tasks",
module_root = "tasks",
tsconfig = "//:tsconfig.json",
module_root = "tasks/index.d.ts",
deps = [
":schematics",
"//packages/angular_devkit/core",
@ -52,6 +89,47 @@ ts_library(
],
)
ts_library(
name = "tasks_test_lib",
srcs = glob(
include = [
"tasks/**/*_spec.ts",
"tasks/**/*_spec_large.ts",
"tasks/tslint-fix/test/**/*.ts",
],
exclude = [
# Disabled because 'collection.json' cannot be resolved in bazel.
# TODO(@filipesilva): figure out how to make data files resolve correctly.
"tasks/tslint-fix/executor_spec.ts",
],
),
data = [
"tasks/tslint-fix/test/collection.json",
],
deps = [
":tasks",
":testing",
":schematics",
"//packages/angular_devkit/core",
"//packages/angular_devkit/core:node",
"//packages/angular_devkit/core:node_testing",
"@rxjs",
"@rxjs//operators",
# @typings: jasmine
# @typings: node
],
)
# Disabled since we are excluding the only test in tasks.
# jasmine_node_test(
# name = "tasks_test",
# srcs = [":tasks_test_lib"],
# )
# @angular-devkit/schematics/tools
ts_library(
name = "tools",
srcs = glob(
@ -62,7 +140,7 @@ ts_library(
],
),
module_name = "@angular-devkit/schematics/tools",
module_root = "tools",
module_root = "tools/index.d.ts",
deps = [
":schematics",
":tasks",
@ -74,6 +152,44 @@ ts_library(
],
)
ts_library(
name = "tools_test_lib",
srcs = glob(
include = [
"tools/**/*_spec.ts",
"tools/**/*_spec_large.ts",
],
exclude = [
# The node resolve spec uses the _devKitRoot global, which isn't available in Bazel.
# TODO(@filipesilva): figure out an alternative to that global.
"tools/file-system-engine-host_spec.ts",
],
),
data = glob(
include = ["tools/test/file-system-engine-host/**/collection.json"],
),
deps = [
":tools",
":tasks",
":schematics",
":testing",
"//packages/angular_devkit/core",
"//packages/angular_devkit/core:node",
"@rxjs",
"@rxjs//operators",
# @typings: jasmine
# @typings: node
],
)
jasmine_node_test(
name = "tools_test",
srcs = [":tools_test_lib"],
)
# @angular-devkit/schematics/testing
ts_library(
name = "testing",
srcs = glob(
@ -81,7 +197,7 @@ ts_library(
exclude = [],
),
module_name = "@angular-devkit/schematics/testing",
module_root = "testing",
module_root = "testing/index.d.ts",
deps = [
":schematics",
":tasks",
@ -90,36 +206,4 @@ ts_library(
"@rxjs",
"@rxjs//operators",
],
)
ts_library(
name = "spec",
srcs = glob(
include = ["src/**/*_spec.ts"],
),
deps = [
":schematics",
":testing",
"//packages/angular_devkit/core",
"@rxjs",
"@rxjs//operators",
# @typings: jasmine
],
)
ts_library(
name = "tools_spec",
srcs = glob(
include = ["tools/**/*_spec.ts"],
),
deps = [
":schematics",
":tools",
"//packages/angular_devkit/core",
"//packages/angular_devkit/core:node",
"@rxjs",
"@rxjs//operators",
# @typings: jasmine
# @typings: node
],
)
)

View File

@ -8,7 +8,6 @@
// tslint:disable:no-implicit-dependencies
import { normalize, virtualFs } from '@angular-devkit/core';
import { HostSink } from '@angular-devkit/schematics';
import { fileBufferToString } from '../../../core/src/virtual-fs/host';
import { HostCreateTree, HostTree } from '../tree/host-tree';
import { optimize } from '../tree/static';
@ -133,7 +132,7 @@ describe('FileSystemSink', () => {
.toPromise()
.then(() => {
expect(host.sync.read(normalize('/file0')).toString()).toBe('hello');
expect(fileBufferToString(host.sync.read(normalize('/file1')))).toBe('world');
expect(virtualFs.fileBufferToString(host.sync.read(normalize('/file1')))).toBe('world');
})
.then(done, done.fail);
});

View File

@ -11,12 +11,16 @@ import { ExportStringRef } from './export-ref';
describe('ExportStringRef', () => {
// Depending on how the package is built the module might be either .js or .ts.
// To make expectations easier, we strip the extension.
const stripExtension = (p: string) => p.replace(/\.(j|t)s$/, '');
it('works', () => {
// META
const ref = new ExportStringRef('./export-ref#ExportStringRef', __dirname);
expect(ref.ref).toBe(ExportStringRef);
expect(ref.path).toBe(__dirname);
expect(ref.module).toBe(path.join(__dirname, 'export-ref.ts'));
expect(stripExtension(ref.module)).toBe(path.join(__dirname, 'export-ref'));
});
it('works without an inner ref', () => {
@ -24,7 +28,7 @@ describe('ExportStringRef', () => {
const ref = new ExportStringRef(path.join(__dirname, 'export-ref'));
expect(ref.ref).toBe(undefined);
expect(ref.path).toBe(__dirname);
expect(ref.module).toBe(path.join(__dirname, 'export-ref.ts'));
expect(stripExtension(ref.module)).toBe(path.join(__dirname, 'export-ref'));
});
it('returns the exports', () => {
@ -32,7 +36,7 @@ describe('ExportStringRef', () => {
const ref = new ExportStringRef('./export-ref#ExportStringRef', __dirname, false);
expect(ref.ref).toEqual({ ExportStringRef });
expect(ref.path).toBe(__dirname);
expect(ref.module).toBe(path.join(__dirname, 'export-ref.ts'));
expect(stripExtension(ref.module)).toBe(path.join(__dirname, 'export-ref'));
});
it('works on package names', () => {
@ -42,13 +46,13 @@ describe('ExportStringRef', () => {
);
expect(ref.ref).toEqual(CollectionCannotBeResolvedException);
expect(ref.path).toBe(__dirname);
expect(ref.module).toBe(path.join(__dirname, 'index.ts'));
expect(stripExtension(ref.module)).toBe(path.join(__dirname, 'index'));
});
it('works on directory', () => {
// META
const ref = new ExportStringRef(__dirname);
expect(ref.path).toBe(__dirname);
expect(ref.module).toBe(path.join(__dirname, 'index.ts'));
expect(stripExtension(ref.module)).toBe(path.join(__dirname, 'index'));
});
});