From aae863cd862c28fa9d88ea6a736101e20d59516e Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Wed, 18 Sep 2019 11:24:12 -0700 Subject: [PATCH] chore: minimize the delta --- e2e/less/BUILD.bazel | 12 ++- e2e/less/package.json | 2 +- e2e/less/test.js | 7 ++ e2e/less/yarn.lock | 6 +- e2e/stylus/BUILD.bazel | 12 ++- e2e/stylus/package.json | 2 +- e2e/stylus/test.js | 7 ++ internal/golden_file_test/bin.js | 14 +-- .../golden_file_test/golden_file_test.bzl | 2 +- internal/node/test/BUILD.bazel | 12 --- internal/node/test/npm_bin.spec.js | 6 +- package.json | 1 - yarn.lock | 96 ++----------------- 13 files changed, 46 insertions(+), 133 deletions(-) create mode 100644 e2e/less/test.js create mode 100644 e2e/stylus/test.js diff --git a/e2e/less/BUILD.bazel b/e2e/less/BUILD.bazel index 7146e6fd1a..77ce9f3c14 100644 --- a/e2e/less/BUILD.bazel +++ b/e2e/less/BUILD.bazel @@ -1,4 +1,4 @@ -load("@build_bazel_rules_nodejs//internal/golden_file_test:golden_file_test.bzl", "golden_file_test") +load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_test") load("@npm//less:index.bzl", "lessc") lessc( @@ -17,10 +17,14 @@ lessc( ], ) -golden_file_test( +nodejs_test( name = "test", - actual = "test.css", - golden = "golden.css", + data = [ + "golden.css", + "test.js", + ":styles", + ], + entry_point = ":test.js", ) # For testing from the root workspace of this repository with bazel_integration_test. diff --git a/e2e/less/package.json b/e2e/less/package.json index ace37a1c48..4a4f779783 100644 --- a/e2e/less/package.json +++ b/e2e/less/package.json @@ -5,6 +5,6 @@ "@bazel/less": "latest" }, "scripts": { - "test": "bazel test ..." + "test": "bazel test ..." } } diff --git a/e2e/less/test.js b/e2e/less/test.js new file mode 100644 index 0000000000..a002c670db --- /dev/null +++ b/e2e/less/test.js @@ -0,0 +1,7 @@ +const fs = require('fs'); +const expected = fs.readFileSync(require.resolve('e2e_less/golden.css'), 'utf-8'); +const actual = fs.readFileSync(require.resolve('e2e_less/test.css'), 'utf-8'); +if (expected !== actual) { + console.error(`FAILED. Expected\n${expected}\n but was\n${actual}`); + process.exitCode = 1; +} diff --git a/e2e/less/yarn.lock b/e2e/less/yarn.lock index c0d67ae708..394e6a924a 100644 --- a/e2e/less/yarn.lock +++ b/e2e/less/yarn.lock @@ -3,9 +3,9 @@ "@bazel/less@latest": - version "0.37.0" - resolved "https://registry.yarnpkg.com/@bazel/less/-/less-0.37.0.tgz#d309dad692c59ad346069f8f22980334030a4024" - integrity sha512-9HIROy2QQchGcbJH8pRj4dIO2ok5YeyDFi93BrehjLG1zf1pehdrhl6oyn/98rf+DyBnuG1WRX/D6GNQWlYo0Q== + version "0.37.1" + resolved "https://registry.yarnpkg.com/@bazel/less/-/less-0.37.1.tgz#915bd08f3f164b106639482ce3feebac30f63773" + integrity sha512-Ch+wN17E4CF5Gk7eX+mJ/i42LHXwDvDe6WMFHxBD0zwY3Omi/DozGYcaM+byCKSmssiPKK4g//d4ZIljVCsdfQ== dependencies: less "^3.9.0" diff --git a/e2e/stylus/BUILD.bazel b/e2e/stylus/BUILD.bazel index e15ab89dbc..aabd2a4716 100644 --- a/e2e/stylus/BUILD.bazel +++ b/e2e/stylus/BUILD.bazel @@ -1,4 +1,4 @@ -load("@build_bazel_rules_nodejs//internal/golden_file_test:golden_file_test.bzl", "golden_file_test") +load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_test") load("@npm//stylus:index.bzl", "stylus") stylus( @@ -18,10 +18,14 @@ stylus( ], ) -golden_file_test( +nodejs_test( name = "test", - actual = "test.css", - golden = "golden.css", + data = [ + "golden.css", + "test.js", + ":styles", + ], + entry_point = ":test.js", ) # For testing from the root workspace of this repository with bazel_integration_test. diff --git a/e2e/stylus/package.json b/e2e/stylus/package.json index 7d7a9beee9..1e79efd076 100644 --- a/e2e/stylus/package.json +++ b/e2e/stylus/package.json @@ -5,6 +5,6 @@ "@bazel/stylus": "latest" }, "scripts": { - "test": "bazel test ..." + "test": "bazel test ..." } } diff --git a/e2e/stylus/test.js b/e2e/stylus/test.js new file mode 100644 index 0000000000..961ccd9efe --- /dev/null +++ b/e2e/stylus/test.js @@ -0,0 +1,7 @@ +const fs = require('fs'); +const expected = fs.readFileSync(require.resolve('e2e_stylus/golden.css'), 'utf-8'); +const actual = fs.readFileSync(require.resolve('e2e_stylus/test.css'), 'utf-8'); +if (expected !== actual) { + console.error(`FAILED. Expected\n${expected}\n but was\n${actual}`); + process.exitCode = 1; +} diff --git a/internal/golden_file_test/bin.js b/internal/golden_file_test/bin.js index 2a847099b2..f40560cd60 100644 --- a/internal/golden_file_test/bin.js +++ b/internal/golden_file_test/bin.js @@ -1,5 +1,6 @@ const fs = require('fs'); const path = require('path'); +const unidiff = require('unidiff'); function main(args) { const [mode, golden_no_debug, golden_debug, actual] = args; @@ -15,17 +16,8 @@ function main(args) { console.error(`Replaced ${path.join(process.cwd(), golden)}`); } else if (mode === '--verify') { // Generated does not match golden - let prettyDiff = - 'Install the unidiff package and add golden_file_test(data=["@npm//unidiff"]) to see an inline diff.'; - try { - const unidiff = require('unidiff'); - const diff = unidiff.diffLines(goldenContents, actualContents); - prettyDiff = unidiff.formatLines(diff, {aname: golden, bname: actual}); - } catch (e) { - if (e.code !== 'THING') { - throw new Error(e.code); - } - } + const diff = unidiff.diffLines(goldenContents, actualContents); + const prettyDiff = unidiff.formatLines(diff, {aname: golden, bname: actual}); throw new Error(`Actual output doesn't match golden file: ${prettyDiff} diff --git a/internal/golden_file_test/golden_file_test.bzl b/internal/golden_file_test/golden_file_test.bzl index a5f26ef2fe..f7d091da45 100644 --- a/internal/golden_file_test/golden_file_test.bzl +++ b/internal/golden_file_test/golden_file_test.bzl @@ -7,7 +7,7 @@ def golden_file_test(name, golden, actual, **kwargs): Use `golden_debug` if the actual output changes when DEBUG is set. """ - data = [golden, actual] + data = [golden, actual, "@npm//unidiff"] golden_debug = kwargs.pop("golden_debug", []) if golden_debug: diff --git a/internal/node/test/BUILD.bazel b/internal/node/test/BUILD.bazel index 4a2cbcc761..078746b81b 100644 --- a/internal/node/test/BUILD.bazel +++ b/internal/node/test/BUILD.bazel @@ -163,15 +163,3 @@ nodejs_test( data = ["minified.js"], entry_point = "npm_bin.spec.js", ) - -npm_bin( - name = "run_closure", - srcs = ["terser_input.js"], - outs = ["closure-minified.js"], - args = [ - "--platform=native", - "--js=$(location terser_input.js)", - "--js_output_file=$(location closure-minified.js)", - ], - package = "google-closure-compiler", -) diff --git a/internal/node/test/npm_bin.spec.js b/internal/node/test/npm_bin.spec.js index eb3fd59e3b..1aa20b6068 100644 --- a/internal/node/test/npm_bin.spec.js +++ b/internal/node/test/npm_bin.spec.js @@ -1,11 +1,7 @@ const fs = require('fs'); const path = require('path'); -const content = fs.readFileSync( - path.join( - process.env['TEST_SRCDIR'], 'build_bazel_rules_nodejs', 'internal', 'node', 'test', - 'minified.js'), - 'utf-8'); +const content = fs.readFileSync(path.join(require.resolve(__dirname + '/minified.js')), 'utf-8'); if (!content.includes('{console.error("thing")}')) { console.error(content); process.exitCode = 1; diff --git a/package.json b/package.json index c5bdbafdd0..f9ce82e563 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,6 @@ "conventional-changelog-cli": "^2.0.21", "core-util-is": "^1.0.2", "date-fns": "1.30.1", - "google-closure-compiler": "^20190909.0.0", "hello": "file:./tools/npm_packages/hello", "husky": "1.3.1", "is-builtin-module": "3.0.0", diff --git a/yarn.lock b/yarn.lock index 71fa46d965..68285372e5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1151,7 +1151,7 @@ chalk@2.3.1: escape-string-regexp "^1.0.5" supports-color "^5.2.0" -chalk@2.4.2, chalk@2.x, chalk@^2.0.1, chalk@^2.3.0, chalk@^2.4.2: +chalk@2.4.2, chalk@^2.0.1, chalk@^2.3.0, chalk@^2.4.2: version "2.4.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== @@ -1263,30 +1263,11 @@ cliui@^5.0.0: strip-ansi "^5.2.0" wrap-ansi "^5.1.0" -clone-buffer@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/clone-buffer/-/clone-buffer-1.0.0.tgz#e3e25b207ac4e701af721e2cb5a16792cac3dc58" - integrity sha1-4+JbIHrE5wGvch4staFnksrD3Fg= - -clone-stats@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/clone-stats/-/clone-stats-1.0.0.tgz#b3782dff8bb5474e18b9b6bf0fdfe782f8777680" - integrity sha1-s3gt/4u1R04Yuba/D9/ngvh3doA= - -clone@^2.1.1, clone@^2.1.2: +clone@^2.1.2: version "2.1.2" resolved "https://registry.yarnpkg.com/clone/-/clone-2.1.2.tgz#1b7f4b9f591f1e8f83670401600345a02887435f" integrity sha1-G39Ln1kfHo+DZwQBYANFoCiHQ18= -cloneable-readable@^1.0.0: - version "1.1.3" - resolved "https://registry.yarnpkg.com/cloneable-readable/-/cloneable-readable-1.1.3.tgz#120a00cb053bfb63a222e709f9683ea2e11d8cec" - integrity sha512-2EF8zTQOxYq70Y4XKtorQupqF0m49MBz2/yf5Bj+MHjvpG3Hy7sImifnqD6UA+TKYxeSV+u6qqQPawN5UvnpKQ== - dependencies: - inherits "^2.0.1" - process-nextick-args "^2.0.0" - readable-stream "^2.3.5" - code-point-at@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77" @@ -2450,47 +2431,6 @@ globby@^5.0.0: pify "^2.0.0" pinkie-promise "^2.0.0" -google-closure-compiler-java@^20190909.0.0: - version "20190909.0.0" - resolved "https://registry.yarnpkg.com/google-closure-compiler-java/-/google-closure-compiler-java-20190909.0.0.tgz#de0211e706186631b6e419840559f8026fb08dcf" - integrity sha512-Cz58+hW7XxFQ8KHenfP9eH2FqvGJ1ikcSebHihgqAg1Pfy8ZzxWUBZYEwOGqV0Kzcbb1NN79n0UMd2ZNfWb19w== - -google-closure-compiler-js@^20190909.0.0: - version "20190909.0.0" - resolved "https://registry.yarnpkg.com/google-closure-compiler-js/-/google-closure-compiler-js-20190909.0.0.tgz#0738952e17a7041949583ee1304735c56f0f344b" - integrity sha512-x8PcAL5H5VxkOJ/jYdAYxwdwbIvClGW7IxzyOH2NMvBNVP6AbpJ24SCODQSA0qhMbCs45JyY3TJ9s2wH2NuzUA== - -google-closure-compiler-linux@^20190909.0.0: - version "20190909.0.0" - resolved "https://registry.yarnpkg.com/google-closure-compiler-linux/-/google-closure-compiler-linux-20190909.0.0.tgz#4c447a41da0d7fc317af785b023916ee231eef73" - integrity sha512-4mTUVhrkjS4d4LREqOWIwPT4lfbUJAs5nh9gTJ7vHtBxa8aE08ynGPz4zhO9gYpRb3mDVYd7BHA2dvJWtFRiDw== - -google-closure-compiler-osx@^20190909.0.0: - version "20190909.0.0" - resolved "https://registry.yarnpkg.com/google-closure-compiler-osx/-/google-closure-compiler-osx-20190909.0.0.tgz#521b2ed7571c054739803d13a7785b764aab6239" - integrity sha512-DvIr6gd7BfIpptSfLihEGwCHKlcwssHC+pt1duagRPfmgezp8GeJvAvbZIS/+Ud77zRFz+wcwQWsTvwyZSwklQ== - -google-closure-compiler-windows@^20190909.0.0: - version "20190909.0.0" - resolved "https://registry.yarnpkg.com/google-closure-compiler-windows/-/google-closure-compiler-windows-20190909.0.0.tgz#295bb667fe830b71dde6ee88b0af4cd36cf5dbd0" - integrity sha512-9N+7ocubt+cNI1q2395ZZ2fQouLeAudLGpYYMLYzNPfrfENvPWX+Zbk7A0gSqUzRLn+tD0SfpRcxmvajw7o2VA== - -google-closure-compiler@^20190909.0.0: - version "20190909.0.0" - resolved "https://registry.yarnpkg.com/google-closure-compiler/-/google-closure-compiler-20190909.0.0.tgz#d5c6d68380a5234e4645d6e6a45bc5c9badfdfa0" - integrity sha512-Mh1IKgp72HBgEeWQ5RDZHGj0w3vhEJsIaWptqSWEr7muinBv/0Xq5g1pxCvXX7LPfSH7vL+1Indzt1OxwfTXwQ== - dependencies: - chalk "2.x" - google-closure-compiler-java "^20190909.0.0" - google-closure-compiler-js "^20190909.0.0" - minimist "1.x" - vinyl "2.x" - vinyl-sourcemaps-apply "^0.2.0" - optionalDependencies: - google-closure-compiler-linux "^20190909.0.0" - google-closure-compiler-osx "^20190909.0.0" - google-closure-compiler-windows "^20190909.0.0" - graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.3: version "4.2.2" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.2.tgz#6f0952605d0140c1cfdb138ed005775b92d67b02" @@ -3513,7 +3453,7 @@ minimist@0.0.8: resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" integrity sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0= -minimist@1.x, minimist@^1.1.3, minimist@^1.2.0: +minimist@^1.1.3, minimist@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284" integrity sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ= @@ -4140,7 +4080,7 @@ prettier@^1.7.4: resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.18.2.tgz#6823e7c5900017b4bd3acf46fe9ac4b4d7bda9ea" integrity sha512-OeHeMc0JhFE9idD4ZdtNibzY0+TPHSpSSb9h8FqtP+YnoZZ1sl8Vc9b1sasjfymH3SonAF4QcA2+mzHPhMvIiw== -process-nextick-args@^2.0.0, process-nextick-args@~2.0.0: +process-nextick-args@~2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2" integrity sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag== @@ -4375,7 +4315,7 @@ read-pkg@^4.0.1: parse-json "^4.0.0" pify "^3.0.0" -"readable-stream@1 || 2", readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.6, readable-stream@^2.1.5, readable-stream@^2.2.2, readable-stream@^2.3.3, readable-stream@^2.3.5, readable-stream@^2.3.6, readable-stream@~2.3.6: +"readable-stream@1 || 2", readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.6, readable-stream@^2.1.5, readable-stream@^2.2.2, readable-stream@^2.3.3, readable-stream@^2.3.6, readable-stream@~2.3.6: version "2.3.6" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.6.tgz#b11c27d88b8ff1fbe070643cf94b0c79ae1b0aaf" integrity sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw== @@ -4474,11 +4414,6 @@ repeating@^2.0.0: dependencies: is-finite "^1.0.0" -replace-ext@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/replace-ext/-/replace-ext-1.0.0.tgz#de63128373fcbf7c3ccfa4de5a480c45a67958eb" - integrity sha1-3mMSg3P8v3w8z6TeWkgMRaZ5WOs= - request@^2.83.0, request@^2.87.0: version "2.88.0" resolved "https://registry.yarnpkg.com/request/-/request-2.88.0.tgz#9c2fca4f7d35b592efe57c7f0a55e81052124fef" @@ -4898,7 +4833,7 @@ source-map@0.1.x: dependencies: amdefine ">=0.0.4" -source-map@^0.5.1, source-map@^0.5.6: +source-map@^0.5.6: version "0.5.7" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc" integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w= @@ -5595,25 +5530,6 @@ verror@1.10.0: core-util-is "1.0.2" extsprintf "^1.2.0" -vinyl-sourcemaps-apply@^0.2.0: - version "0.2.1" - resolved "https://registry.yarnpkg.com/vinyl-sourcemaps-apply/-/vinyl-sourcemaps-apply-0.2.1.tgz#ab6549d61d172c2b1b87be5c508d239c8ef87705" - integrity sha1-q2VJ1h0XLCsbh75cUI0jnI74dwU= - dependencies: - source-map "^0.5.1" - -vinyl@2.x: - version "2.2.0" - resolved "https://registry.yarnpkg.com/vinyl/-/vinyl-2.2.0.tgz#d85b07da96e458d25b2ffe19fece9f2caa13ed86" - integrity sha512-MBH+yP0kC/GQ5GwBqrTPTzEfiiLjta7hTtvQtbxBgTeSXsmKQRQecjibMbxIXzVT3Y9KJK+drOz1/k+vsu8Nkg== - dependencies: - clone "^2.1.1" - clone-buffer "^1.0.0" - clone-stats "^1.0.0" - cloneable-readable "^1.0.0" - remove-trailing-separator "^1.0.1" - replace-ext "^1.0.0" - vm-browserify@^1.0.1: version "1.1.0" resolved "https://registry.yarnpkg.com/vm-browserify/-/vm-browserify-1.1.0.tgz#bd76d6a23323e2ca8ffa12028dc04559c75f9019"