From 94b139600d58585d2d77d7128d1b031d22a9e2f2 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Mon, 31 Dec 2018 18:57:29 +0100 Subject: [PATCH] build: run moment adapter tests with bazel --- src/material-moment-adapter/BUILD.bazel | 27 +++++++++++++++++-- src/material-moment-adapter/require-config.js | 7 +++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/material-moment-adapter/require-config.js diff --git a/src/material-moment-adapter/BUILD.bazel b/src/material-moment-adapter/BUILD.bazel index 7e5896cccdec..66f475058f0d 100644 --- a/src/material-moment-adapter/BUILD.bazel +++ b/src/material-moment-adapter/BUILD.bazel @@ -1,6 +1,6 @@ package(default_visibility=["//visibility:public"]) -load("//tools:defaults.bzl", "ng_module", "ng_package") +load("//tools:defaults.bzl", "ng_module", "ng_package", "ng_web_test_suite", "ng_test_library") load("//:packages.bzl", "ROLLUP_GLOBALS") ng_module( @@ -11,7 +11,6 @@ ng_module( "@angular//packages/core", "@matdeps//moment", "//src/lib/core", - "//src/lib/testing", ], # Explicitly specify the tsconfig that is also used by Gulp. We need to explicitly use this # tsconfig because in order to import Moment with TypeScript, we need some special options @@ -19,6 +18,30 @@ ng_module( tsconfig = ":tsconfig-build.json", ) +ng_test_library( + name = "moment_adapter_test_sources", + srcs = glob(["**/*.spec.ts"]), + deps = [ + "//src/lib/core", + "//src/lib/testing", + "@matdeps//moment", + ":material-moment-adapter", + ], +) + +ng_web_test_suite( + name = "unit_tests", + deps = [ + ":require-config.js", + ":moment_adapter_test_sources" + ], + # We need to load Moment statically since it is not a named AMD module and needs to + # be manually configured through "require.js" which is used by "ts_web_test_suite". + static_files = [ + "@matdeps//moment", + ], +) + ng_package( name = "npm_package", srcs = ["package.json"], diff --git a/src/material-moment-adapter/require-config.js b/src/material-moment-adapter/require-config.js new file mode 100644 index 000000000000..df7af57ec34c --- /dev/null +++ b/src/material-moment-adapter/require-config.js @@ -0,0 +1,7 @@ +// Require.js is being used by the karma bazel rules and needs to be configured to properly +// load AMD modules which are not explicitly named in their output bundle. +require.config({ + paths: { + 'moment': '/base/matdeps/node_modules/moment/min/moment-with-locales.min' + } +});