Skip to content

Commit

Permalink
chore(builtin): add missing testing for browserify vendored binary
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle committed Jul 12, 2019
1 parent 42268bc commit b6bb475
Show file tree
Hide file tree
Showing 5 changed files with 15,494 additions and 12,198 deletions.
20 changes: 19 additions & 1 deletion internal/npm_install/test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test", "nodejs_binary")
load("@build_bazel_rules_nodejs//internal/npm_install:npm_umd_bundle.bzl", "npm_umd_bundle")

filegroup(
name = "goldens",
Expand All @@ -7,7 +8,7 @@ filegroup(

jasmine_node_test(
name = "test",
srcs = glob(["*.spec.js"]),
srcs = ["generate_build_file.spec.js"],
data = [
":check.js",
":goldens",
Expand All @@ -31,3 +32,20 @@ nodejs_binary(
entry_point = ":update_golden.js",
install_source_map_support = False,
)

npm_umd_bundle(
name = "some-bundle",
package_name = "some-package-name",
entry_point = "@npm//:node_modules/minimist/index.js",
package = "@npm//minimist",
)

jasmine_node_test(
name = "browserify_test",
srcs = ["browserify.spec.js"],
data = [
":some-package-name.umd.js",
"//internal/npm_install:browserify-wrapped",
"@npm//jasmine",
],
)
16 changes: 16 additions & 0 deletions internal/npm_install/test/browserify.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const fs = require('fs');
const mainFile = 'build_bazel_rules_nodejs/third_party/github.com/browserify/browserify/index.min.js';

describe('our bundled, vendored browserify binary', () => {
it('should preserve licenses', () => {
const idxFile = fs.readFileSync(require.resolve(mainFile), {encoding: 'utf-8'});
expect(idxFile).toContain('Copyright Joyent');
expect(idxFile).toMatch(/Copyright \d+ Mozilla/);
expect(idxFile).toContain('Feross Aboukhadijeh');
});
it('should work', () => {
const minimistUmd = require('build_bazel_rules_nodejs/internal/npm_install/test/some-package-name.umd.js');
const result = minimistUmd('h');
expect(result._[0]).toBe('h');
});
});
2 changes: 1 addition & 1 deletion scripts/vendor_browserify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ echo "Copy LICENSE"
cp -f ./node_modules/browserify/LICENSE ./third_party/github.com/browserify/browserify

echo "Minifying browserify with tserver"
./node_modules/.bin/terser --compress --mangle --comments '/(^!|@license|@preserve)/' -- third_party/github.com/browserify/browserify/index.js > third_party/github.com/browserify/browserify/index.min.js
./node_modules/.bin/terser --compress --mangle --comments '/(^!|@license|@preserve|Copyright)/' -- third_party/github.com/browserify/browserify/index.js > third_party/github.com/browserify/browserify/index.min.js

Loading

0 comments on commit b6bb475

Please sign in to comment.