Skip to content

Commit

Permalink
test: updates tests for npm_package to include external files reposit…
Browse files Browse the repository at this point in the history
…ory files in srcs & deps
  • Loading branch information
gregmagolan authored and alexeagle committed Jul 23, 2019
1 parent 0536f16 commit 8c14866
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 3 deletions.
5 changes: 5 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ local_repository(
path = "internal/e2e/packages",
)

local_repository(
name = "internal_npm_package_test_vendored_external",
path = "internal/npm_package/test/vendored_external",
)

load("@internal_e2e_packages//:setup_workspace.bzl", "internal_e2e_packages_setup_workspace")

internal_e2e_packages_setup_workspace()
Expand Down
8 changes: 5 additions & 3 deletions internal/npm_package/npm_package.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ def create_package(ctx, deps_sources, nested_packages):
package_path = ctx.label.package

# List of dependency sources which are local to the package that defines the current
# target. We only want to package deps files which are inside of the current package.
local_deps_sources = _filter_out_external_files(ctx, deps_sources, package_path)
# target. Also include files from external repositories that explicitly specified in
# the vendor_external list. We only want to package deps files which are inside of the
# current package unless explicitely specified.
filtered_deps_sources = _filter_out_external_files(ctx, deps_sources, package_path)

args = ctx.actions.args()
args.use_param_file("%s", use_always = True)
Expand All @@ -53,7 +55,7 @@ def create_package(ctx, deps_sources, nested_packages):
args.add_joined([s.path for s in ctx.files.srcs], join_with = ",", omit_if_empty = False)
args.add(ctx.bin_dir.path)
args.add(ctx.genfiles_dir.path)
args.add_joined(local_deps_sources, join_with = ",", omit_if_empty = False)
args.add_joined(filtered_deps_sources, join_with = ",", omit_if_empty = False)
args.add_joined([p.path for p in nested_packages], join_with = ",", omit_if_empty = False)
args.add(ctx.attr.replacements)
args.add_all([ctx.outputs.pack.path, ctx.outputs.publish.path])
Expand Down
5 changes: 5 additions & 0 deletions internal/npm_package/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ npm_package(
srcs = [
"package.json",
"some_file",
"@internal_npm_package_test_vendored_external//:vendored_external_file",
],
packages = [":dependent_pkg"],
replacements = {"replace_me": "replaced"},
vendor_external = [
"internal_npm_package_test_vendored_external",
],
deps = [
":bundle.min.js",
":produces_files",
":ts_library",
"@internal_npm_package_test_vendored_external//:ts_library",
],
)

Expand Down
13 changes: 13 additions & 0 deletions internal/npm_package/test/npm_package.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ describe('npm_package srcs', () => {
it('copies files from other packages', () => {
expect(read('dependent_file')).toEqual('dependent_file content');
});
it('copies js files from ts_library', () => {
expect(read('foo.js')).toEqual('export const a = \'\';');
});
it('copies declaration files from ts_library', () => {
expect(read('foo.d.ts')).toEqual('export const a: string;');
});
Expand All @@ -34,6 +37,16 @@ describe('npm_package srcs', () => {
it('copies files from deps', () => {
expect(read('bundle.min.js')).toBe('bundle content');
});
it('copies files from external workspace if included in srcs', () => {
expect(read('vendored_external_file')).toEqual('vendored_external_file content');
});
it('copies js files from external workspace ts_library if included in vendor_external', () => {
expect(read('external.js')).toContain('exports.b = \'\';');
});
it('copies declaration files from external workspace ts_library if included in vendor_external',
() => {
expect(read('external.d.ts')).toContain('export declare const b: string;');
});
it('vendors external workspaces',
() => {
// TODO(alexeagle): there isn't a way to test this yet, because the npm_package under test
Expand Down
13 changes: 13 additions & 0 deletions internal/npm_package/test/vendored_external/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("@npm_bazel_typescript//:defaults.bzl", "ts_library")

package(default_visibility = ["//visibility:public"])

# Exported file to be consumed by test
exports_files(["vendored_external_file"])

ts_library(
name = "ts_library",
srcs = [
"external.ts",
],
)
15 changes: 15 additions & 0 deletions internal/npm_package/test/vendored_external/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2017 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

workspace(name = "internal_npm_package_test_vendored_external")
1 change: 1 addition & 0 deletions internal/npm_package/test/vendored_external/external.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const b: string = '';
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendored_external_file content

0 comments on commit 8c14866

Please sign in to comment.