-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build: Add Store unit tests to Bazel #836
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,26 @@ | ||
# Marker file indicating this folder is a Bazel package. | ||
# Needed so that tsconfig.json can be referenced from BUILD rules. | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
# Needed so that tsconfig.json can be referenced from BUILD rules. | ||
exports_files(["tsconfig.json"]) | ||
|
||
# Temporary target to allow `bazel test ...` | ||
# TODO(alexeagle): remove as soon as there is any other test in the repo | ||
genrule( | ||
name = "true", | ||
outs = ["true.sh"], | ||
cmd = "echo true > $@", | ||
) | ||
|
||
sh_test( | ||
name = "tautology_test", | ||
srcs = [":true.sh"], | ||
filegroup( | ||
name = "ngrx_test_dependencies", | ||
# NB: rxjs is not in this list, because we build it from sources using the | ||
# label @rxjs//:rxjs | ||
srcs = glob(["/".join([ | ||
"node_modules", | ||
pkg, | ||
"**", | ||
ext, | ||
]) for pkg in [ | ||
"@angular", | ||
"jasmine", | ||
"jasmine-marbles", | ||
"typescript", | ||
"@types", | ||
] for ext in [ | ||
"*.js", | ||
"*.json", | ||
"*.d.ts", | ||
]]), | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
load("//tools:defaults.bzl", "ts_test_library", "jasmine_node_test") | ||
|
||
ts_test_library( | ||
name = "test_lib", | ||
srcs = glob( | ||
[ | ||
"**/*.ts", | ||
], | ||
exclude = ["ngc/**/*.ts"], | ||
), | ||
deps = [ | ||
"//modules/store", | ||
"@rxjs", | ||
], | ||
) | ||
|
||
jasmine_node_test( | ||
name = "test", | ||
deps = [ | ||
":test_lib", | ||
"//modules/store", | ||
"@rxjs", | ||
], | ||
) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,27 @@ | ||
"""Re-export of some bazel rules with repository-wide defaults.""" | ||
load("@build_bazel_rules_typescript//:defs.bzl", _ts_library = "ts_library") | ||
load("@build_bazel_rules_nodejs//:defs.bzl", _jasmine_node_test = "jasmine_node_test") | ||
|
||
def ts_library(tsconfig = None, node_modules = None, **kwargs): | ||
if not tsconfig: | ||
tsconfig = "//:tsconfig.json" | ||
if not node_modules: | ||
node_modules = "@ngrx_compiletime_deps//:node_modules" | ||
_ts_library(tsconfig = tsconfig, node_modules = node_modules, **kwargs) | ||
|
||
def ts_test_library(node_modules = None, **kwargs): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this an OK pattern of defining my own rules that just set defaults for existing rules similar to what you've done with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a macro (you can tell because you didn't call the
This looks clever and reasonable to me :) |
||
if not node_modules: | ||
node_modules = "//:ngrx_test_dependencies" | ||
ts_library(node_modules = node_modules, testonly = 1, **kwargs) | ||
|
||
def jasmine_node_test(node_modules = None, bootstrap = None, deps = [], **kwargs): | ||
if not node_modules: | ||
node_modules = "//:ngrx_test_dependencies" | ||
if not bootstrap: | ||
bootstrap = ["ngrx/tools/testing/bootstrap_node_tests.js"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It surprised me that I couldn't pass a label here and instead had to point it to a build artifact. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It ought to allow |
||
_jasmine_node_test( | ||
bootstrap = bootstrap, | ||
node_modules = node_modules, | ||
deps = ["//tools/testing:node"] + deps, | ||
**kwargs | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
load("//tools:defaults.bzl", "ts_test_library") | ||
|
||
ts_test_library( | ||
name = "node", | ||
srcs = ["bootstrap_node_tests.ts"], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'core-js/es7/reflect'; | ||
import 'zone.js/dist/zone-node.js'; | ||
import 'zone.js/dist/long-stack-trace-zone.js'; | ||
import 'zone.js/dist/proxy.js'; | ||
import 'zone.js/dist/sync-test.js'; | ||
import 'zone.js/dist/async-test.js'; | ||
import 'zone.js/dist/fake-async-test.js'; | ||
|
||
const jasmineCore: any = require('jasmine-core'); | ||
const patchedJasmine = jasmineCore.boot(jasmineCore); | ||
(global as any)['jasmine'] = patchedJasmine; | ||
|
||
jasmineCore.boot = function() { | ||
return patchedJasmine; | ||
}; | ||
|
||
import { TestBed } from '@angular/core/testing'; | ||
import { | ||
ServerTestingModule, | ||
platformServerTesting, | ||
} from '@angular/platform-server/testing'; | ||
|
||
require('zone.js/dist/jasmine-patch.js'); | ||
|
||
const originalConfigureTestingModule = TestBed.configureTestingModule; | ||
|
||
TestBed.configureTestingModule = function() { | ||
TestBed.resetTestingModule(); | ||
|
||
return originalConfigureTestingModule.apply(null, arguments); | ||
}; | ||
|
||
TestBed.initTestEnvironment(ServerTestingModule, platformServerTesting()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It isn't clear to me if I should be using the dependencies installed from running Yarn at the root or if I should do something similar to the
ngrx_compile_time_deps
for tests.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have both options.
In the case of tests, your users probably don't expect to build/run these from source. At the same time, your users would download and install the
ngrx_compiletime_deps
so it's not nice to add test-only dependencies there.I think I'd probably re-use the
node_modules
directory installed by yarn (note you can usebazel run @yarn//:yarn
to do that with Bazel's version of node and yarn).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good deal. This PR follows your suggestion and re-uses the top level
node_modules
directory for test dependencies.