Skip to content
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

fix(jasmine): can not reference runner when exports_directories_only=… #3293

Merged
merged 2 commits into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/Jasmine.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ Defaults to `None`

A label providing the `@bazel/jasmine` npm dependency.

Defaults to `"@npm//@bazel/jasmine"`
Defaults to `None`
alexeagle marked this conversation as resolved.
Show resolved Hide resolved

<h4 id="jasmine_node_test-jasmine_entry_point">jasmine_entry_point</h4>

A label providing the `@bazel/jasmine` entry point.

Defaults to `Label("@npm//@bazel/jasmine:jasmine_runner.js")`
Defaults to `None`

<h4 id="jasmine_node_test-kwargs">kwargs</h4>

Expand Down
2 changes: 1 addition & 1 deletion examples/nestjs/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ load("@build_bazel_rules_nodejs//:index.bzl", "yarn_install")

yarn_install(
name = "npm",
exports_directories_only = False,
exports_directories_only = True,
thesayyn marked this conversation as resolved.
Show resolved Hide resolved
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
)
Expand Down
14 changes: 9 additions & 5 deletions internal/npm_install/generate_build_file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@ async function generatePackageBuildFiles(pkg: Dep) {
// If there's an index.bzl in the package then copy all the package's files
// other than the BUILD file which we'll write below.
// (maybe we shouldn't copy .js though, since it belongs under node_modules?)
if (pkg._files.includes('index.bzl')) {
const hasIndexBzl = pkg._files.includes('index.bzl')
if (hasIndexBzl) {
await pkg._files.filter(f => f !== 'BUILD' && f !== 'BUILD.bazel').reduce(async (prev, file) => {
if (/^node_modules[/\\]/.test(file)) {
// don't copy over nested node_modules
Expand All @@ -406,16 +407,19 @@ async function generatePackageBuildFiles(pkg: Dep) {
await mkdirp(path.dirname(destFile));
await fs.copyFile(src, destFile);
}, Promise.resolve());
} else {
}


const indexFile = printIndexBzl(pkg);
const indexFileName = hasIndexBzl ? 'private.bzl' : 'index.bzl'
alexeagle marked this conversation as resolved.
Show resolved Hide resolved
if (indexFile.length) {
await writeFile(path.posix.join(pkg._dir, 'index.bzl'), indexFile);
await writeFile(path.posix.join(pkg._dir, indexFileName), indexFile);
buildFile += `
# For integration testing
exports_files(["index.bzl"])
exports_files(["${indexFileName}"])
`;
}
}


if (!symlinkBuildFile) {
await writeFile(
Expand Down
16 changes: 8 additions & 8 deletions internal/npm_install/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ async function generatePackageBuildFiles(pkg) {
await writeFile(path.posix.join(pkg._dir, 'bin', 'BUILD.bazel'), generateBuildFileHeader(visibility) + binBuildFile);
}
}
if (pkg._files.includes('index.bzl')) {
const hasIndexBzl = pkg._files.includes('index.bzl');
if (hasIndexBzl) {
await pkg._files.filter(f => f !== 'BUILD' && f !== 'BUILD.bazel').reduce(async (prev, file) => {
if (/^node_modules[/\\]/.test(file)) {
return;
Expand All @@ -266,15 +267,14 @@ async function generatePackageBuildFiles(pkg) {
await fs_1.promises.copyFile(src, destFile);
}, Promise.resolve());
}
else {
const indexFile = printIndexBzl(pkg);
if (indexFile.length) {
await writeFile(path.posix.join(pkg._dir, 'index.bzl'), indexFile);
buildFile += `
const indexFile = printIndexBzl(pkg);
const indexFileName = hasIndexBzl ? 'private.bzl' : 'index.bzl';
if (indexFile.length) {
await writeFile(path.posix.join(pkg._dir, indexFileName), indexFile);
buildFile += `
# For integration testing
exports_files(["index.bzl"])
exports_files(["${indexFileName}"])
`;
}
}
if (!symlinkBuildFile) {
await writeFile(path.posix.join(pkg._dir, buildFilePath), generateBuildFileHeader(visibility) + buildFile);
Expand Down
7 changes: 5 additions & 2 deletions packages/jasmine/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ stardoc(
out = "README.md",
input = "index.bzl",
tags = ["fix-windows"],
deps = [":bzl"],
deps = [
":bzl",
"//packages/jasmine/private:bzl",
],
)

nodejs_test(
Expand Down Expand Up @@ -81,7 +84,7 @@ pkg_npm(
],
build_file_content = "",
substitutions = {
"//packages/jasmine:jasmine_runner.js": "//:node_modules/@bazel/jasmine/jasmine_runner.js",
"//packages/jasmine/private:jasmine_runner_test.bzl": "//@bazel/jasmine:private.bzl",
alexeagle marked this conversation as resolved.
Show resolved Hide resolved
thesayyn marked this conversation as resolved.
Show resolved Hide resolved
},
deps = [
":README.md",
Expand Down
24 changes: 17 additions & 7 deletions packages/jasmine/jasmine_node_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ than launching a test in Karma, for example.
"""

load("@rules_nodejs//nodejs:providers.bzl", "JSModuleInfo")
load("//packages/jasmine/private:jasmine_runner_test.bzl", "jasmine_runner_test")
load("@build_bazel_rules_nodejs//internal/node:node.bzl", nodejs_test = "nodejs_test_macro")

def _js_sources_impl(ctx):
Expand Down Expand Up @@ -66,10 +67,9 @@ def jasmine_node_test(
tags = [],
config_file = None,
use_direct_specs = None,
# Replaced by pkg_npm with jasmine = "//@bazel/jasmine",
jasmine = "//packages/jasmine",
# Replaced by pkg_npm with jasmine_entry_point = "//:node_modules/@bazel/jasmine/jasmine_runner.js",
jasmine_entry_point = Label("//packages/jasmine:jasmine_runner.js"),
# Kept for backward compatibility
alexeagle marked this conversation as resolved.
Show resolved Hide resolved
jasmine = None,
jasmine_entry_point = None,
**kwargs):
"""Runs tests in NodeJS using the Jasmine test runner.

Expand Down Expand Up @@ -117,7 +117,10 @@ def jasmine_node_test(
use_direct_specs = use_direct_specs,
)

all_data = data + srcs + deps + [Label(jasmine)]
all_data = data + srcs + deps

if jasmine != None:
all_data.append(jasmine)

# BEGIN-INTERNAL
# Only used when running tests in the rules_nodejs repo.
Expand All @@ -142,13 +145,20 @@ def jasmine_node_test(
pkg = Label("%s//%s:__pkg__" % (native.repository_name(), native.package_name()))
all_data.append(pkg.relative(config_file))

nodejs_test(
kwargs = dict(
name = name,
data = all_data,
entry_point = jasmine_entry_point,
templated_args = templated_args,
testonly = 1,
expected_exit_code = expected_exit_code,
tags = tags,
**kwargs
)

if jasmine_entry_point:
nodejs_test(
entry_point = jasmine_entry_point,
**kwargs
)
else:
jasmine_runner_test(**kwargs)
3 changes: 3 additions & 0 deletions packages/jasmine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"jasmine",
"bazel"
],
"bin": {
"jasmine_runner": "jasmine_runner.js"
alexeagle marked this conversation as resolved.
Show resolved Hide resolved
},
"main": "index.js",
"dependencies": {
"jasmine-reporters": "~2.5.0",
Expand Down
10 changes: 10 additions & 0 deletions packages/jasmine/private/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

bzl_library(
name = "bzl",
srcs = glob(["*.bzl"]),
visibility = ["//packages/jasmine:__pkg__"],
deps = [
"@build_bazel_rules_nodejs//internal/node:bzl",
],
)
13 changes: 13 additions & 0 deletions packages/jasmine/private/jasmine_runner_test.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""
This file mimics what we would get when we install a npm package with bin entries. Only used when jasmine_node_test is used directly
from rnj sources and should not be published.
"""

load("@build_bazel_rules_nodejs//internal/node:node.bzl", nodejs_test = "nodejs_test_macro")

def jasmine_runner_test(**kwargs):
nodejs_test(
entry_point = "//packages/jasmine:jasmine_runner.js",
data = ["//packages/jasmine"] + kwargs.pop("data", []),
**kwargs
)