Skip to content

Commit

Permalink
Update npm_install/test test to include multiple build files
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan committed Sep 24, 2018
1 parent 0c642ce commit b1e58c6
Show file tree
Hide file tree
Showing 19 changed files with 314 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
bazel-*
node_modules
internal/npm_install/test/wksp/*
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ node_repositories(
"//examples/rollup:package.json",
"@program_example//:package.json",
"//internal/test:package.json",
"//internal/npm_install/test:package.json",
"//internal/npm_install/test/wksp:package.json",
],
preserve_symlinks = True,
)
Expand Down
17 changes: 6 additions & 11 deletions internal/npm_install/test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test", "nodejs_binary")

filegroup(
name = "node_modules",
srcs = glob(["node_modules/**"]),
)

jasmine_node_test(
name = "test",
srcs = glob(["*.spec.js"]),
data = [
":BUILD.bazel.golden",
"//internal/npm_install/test/wksp:goldens",
"//internal/npm_install/test/wksp:node_modules",
":check.js",
":node_modules",
":yarn.lock",
],
node_modules = ":node_modules",
node_modules = "//internal/npm_install/test/wksp:node_modules",
deps = ["//internal/npm_install:generate_build_file"],
)

nodejs_binary(
name = "test.accept",
data = [
":BUILD.bazel.golden",
"//internal/npm_install/test/wksp:goldens",
"//internal/npm_install/test/wksp:node_modules",
":check.js",
":node_modules",
":update_golden.js",
":yarn.lock",
"//internal/npm_install:generate_build_file",
],
entry_point = "build_bazel_rules_nodejs/internal/npm_install/test/update_golden.js",
install_source_map_support = False,
node_modules = ":node_modules",
node_modules = "//internal/npm_install/test/wksp:node_modules",
)
19 changes: 13 additions & 6 deletions internal/npm_install/test/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ const fs = require('fs');
const path = require('path');
const unidiff = require('unidiff')

const actual = 'BUILD.bazel';
const golden = 'BUILD.bazel.golden';

function check(updateGolden = false) {
function check(actual, updateGolden = false) {
// We must change the directory to the BUILD file path
// so the generator is able to run
process.chdir(path.dirname(__filename));
process.chdir(path.posix.join(path.dirname(__filename), 'wksp'));

// Run the BUILD file generator
generator.main();
Expand All @@ -24,6 +21,7 @@ function check(updateGolden = false) {
.replace(/[\n]+/g, '\n');

// Load the golden file for comparison
const golden = path.posix.join('golden', actual + '.golden');
const goldenContents = fs.readFileSync(golden, {encoding: 'utf-8'}).replace(/\r\n/g, '\n');

// Check if actualContents matches golden file
Expand All @@ -48,4 +46,13 @@ Update the golden file:
}
}

module.exports = check;
module.exports = {
check,
files: [
'BUILD.bazel', '@gregmagolan/BUILD.bazel', '@gregmagolan/test-a/BUILD.bazel',
'@gregmagolan/test-b/BUILD.bazel', 'jasmine/BUILD.bazel', 'unidiff/BUILD.bazel',
'node_modules/@gregmagolan/BUILD.bazel', 'node_modules/@gregmagolan/test-a/BUILD.bazel',
'node_modules/@gregmagolan/test-b/BUILD.bazel', 'node_modules/jasmine/BUILD.bazel',
'node_modules/unidiff/BUILD.bazel'
],
};
6 changes: 3 additions & 3 deletions internal/npm_install/test/generate_build_file.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const check = require('./check');
const {check, files} = require('./check');

describe('build file generator', () => {
it('should produce a BUILD file from the node_modules file structure', () => {
check();
it('should produce a BUILD files from the node_modules file structure', () => {
files.forEach(file => check(file));
});
});
4 changes: 2 additions & 2 deletions internal/npm_install/test/update_golden.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const check = require('./check');
const {check, files} = require('./check');

check(true);
files.forEach(file => check(file, true));
11 changes: 11 additions & 0 deletions internal/npm_install/test/wksp/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package(default_visibility = ["//visibility:public"])

filegroup(
name = "node_modules",
srcs = glob(["node_modules/**"]),
)

filegroup(
name = "goldens",
srcs = glob(["golden/**"])
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

package(default_visibility = ["//visibility:public"])
alias(
name = "@gregmagolan",
actual = "//node_modules/@gregmagolan",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

package(default_visibility = ["//visibility:public"])
alias(
name = "test-a",
actual = "//node_modules/@gregmagolan/test-a",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

package(default_visibility = ["//visibility:public"])
alias(
name = "test-b",
actual = "//node_modules/@gregmagolan/test-b",
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ filegroup(
"//node_modules/@gregmagolan/test-b:test-b__files",
"//node_modules/@yarnpkg/lockfile:lockfile__files",
],
tags = ["NODE_MODULE_MARKER"],
)
filegroup(
name = "node_modules_lite",
Expand All @@ -46,10 +45,8 @@ filegroup(
"//node_modules/@gregmagolan/test-b:test-b__lite",
"//node_modules/@yarnpkg/lockfile:lockfile__lite",
],
tags = ["NODE_MODULE_MARKER"],
)
filegroup(
name = "node_modules_bin",
srcs = glob(["node_modules/.bin/*"]),
tags = ["NODE_MODULE_MARKER"],
)
10 changes: 10 additions & 0 deletions internal/npm_install/test/wksp/golden/jasmine/BUILD.bazel.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

package(default_visibility = ["//visibility:public"])
alias(
name = "jasmine",
actual = "//node_modules/jasmine",
)
alias(
name = "jasmine__bin",
actual = "//node_modules/jasmine:jasmine__bin",
)

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b1e58c6

Please sign in to comment.