forked from angular/components
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdefaults2.bzl
130 lines (118 loc) · 4.3 KB
/
defaults2.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
load("@aspect_rules_jasmine//jasmine:defs.bzl", _jasmine_test = "jasmine_test")
load("@aspect_rules_js//npm:defs.bzl", _npm_package = "npm_package")
load("@devinfra//bazel/http-server:index.bzl", _http_server = "http_server")
load("@devinfra//bazel/spec-bundling:index_rjs.bzl", _spec_bundle = "spec_bundle")
load("@rules_angular//src/ng_project:index.bzl", _ng_project = "ng_project")
load("@rules_angular//src/ng_package/text_replace:index.bzl", _text_replace = "text_replace")
load("@rules_browsers//src/protractor_test:index.bzl", "protractor_test")
load("//tools/bazel:module_name.bzl", "compute_module_name")
load("//tools/bazel:ts_project_interop.bzl", _ts_project = "ts_project")
load("//tools/bazel:web_test_suite.bzl", _ng_web_test_suite = "ng_web_test_suite")
load("//:packages.bzl", "NO_STAMP_NPM_PACKAGE_SUBSTITUTIONS", "NPM_PACKAGE_SUBSTITUTIONS")
spec_bundle = _spec_bundle
http_server = _http_server
ng_web_test_suite = _ng_web_test_suite
def npm_package(name, srcs = [], **kwargs):
_text_replace(
name = "%s_substituted" % name,
srcs = srcs,
substitutions = select({
"//tools:stamp": NPM_PACKAGE_SUBSTITUTIONS,
"//conditions:default": NO_STAMP_NPM_PACKAGE_SUBSTITUTIONS,
}),
)
_npm_package(
name = name,
srcs = srcs + [
"%s_substituted" % name,
],
replace_prefixes = {
"%s_substituted" % name: "/",
},
allow_overwrites = True,
**kwargs
)
def ts_project(
name,
source_map = True,
testonly = False,
tsconfig = None,
**kwargs):
if tsconfig == None and native.package_name().startswith("src"):
tsconfig = "//src:test-tsconfig" if testonly else "//src:build-tsconfig"
_ts_project(
name,
source_map = source_map,
module_name = compute_module_name(testonly),
testonly = testonly,
tsconfig = tsconfig,
**kwargs
)
# TODO(devversion): Partner with ISE team to support `rules_js` here.
# if False and not testonly:
# _make_tsec_test(kwargs["name"])
def ng_project(
name,
source_map = True,
testonly = False,
tsconfig = None,
**kwargs):
if tsconfig == None and native.package_name().startswith("src"):
tsconfig = "//src:test-tsconfig" if testonly else "//src:build-tsconfig"
_ts_project(
name,
source_map = source_map,
module_name = compute_module_name(testonly),
rule_impl = _ng_project,
testonly = testonly,
tsconfig = tsconfig,
**kwargs
)
# TODO(devversion): Partner with ISE team to support `rules_js` here.
# if False and not testonly:
# _make_tsec_test(kwargs["name"])
def jasmine_test(name, data = [], args = [], **kwargs):
# Create relative path to root, from current package dir. Necessary as
# we change the `chdir` below to the package directory.
relative_to_root = "/".join([".."] * len(native.package_name().split("/")))
_jasmine_test(
name = name,
node_modules = "//:node_modules",
chdir = native.package_name(),
fixed_args = [
"--require=%s/node_modules/source-map-support/register.js" % relative_to_root,
"**/*spec.js",
"**/*spec.mjs",
"**/*spec.cjs",
] + args,
data = data + [
"//:node_modules/source-map-support",
],
**kwargs
)
def protractor_web_test_suite(name, deps, **kwargs):
spec_bundle(
name = "%s_bundle" % name,
deps = deps,
external = ["protractor", "selenium-webdriver"],
)
protractor_test(
name = name,
deps = [":%s_bundle" % name],
extra_config = {
"useAllAngular2AppRoots": True,
"allScriptsTimeout": 120000,
"getPageTimeout": 120000,
"jasmineNodeOpts": {
"defaultTimeoutInterval": 120000,
},
# Since we want to use async/await we don't want to mix up with selenium's promise
# manager. In order to enforce this, we disable the promise manager.
"SELENIUM_PROMISE_MANAGER": False,
},
data = [
"//:node_modules/protractor",
"//:node_modules/selenium-webdriver",
],
**kwargs
)