From dd3eb162b071dbceb227d29bd523a37aff712219 Mon Sep 17 00:00:00 2001 From: Evgenii Kliuchnikov Date: Wed, 5 Jul 2023 18:49:09 +0000 Subject: Fix JS tests PiperOrigin-RevId: 545743271 --- js/BUILD | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- js/decode_synth_test.js | 5 +++-- js/jasmine-polyfill.js | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 js/jasmine-polyfill.js diff --git a/js/BUILD b/js/BUILD index 19d2a39..d74e42c 100644 --- a/js/BUILD +++ b/js/BUILD @@ -19,6 +19,18 @@ closure_js_library( ], ) +closure_js_library( + name = "jasmine-polyfill", + srcs = ["jasmine-polyfill.js"], + suppress = [ + "JSC_MISSING_JSDOC", + "JSC_UNKNOWN_EXPR_TYPE", + "JSC_MISSING_PROVIDE", + ], + deps = ["@io_bazel_rules_closure//closure/library:testing"], + testonly = True, +) + # Do NOT use this artifact; it is for test purposes only. closure_js_library( name = "decode", @@ -28,13 +40,45 @@ closure_js_library( ) closure_js_test( - name = "all_tests", + name = "decode_test", srcs = ["decode_test.js"], entry_points = ["decode_test.js"], suppress = ["moduleLoad"], deps = [ ":decode", + ":jasmine-polyfill", + ":polyfill", + ], +) + +closure_js_test( + name = "decode_synth_test", + srcs = ["decode_synth_test.js"], + entry_points = ["decode_synth_test.js"], + suppress = ["moduleLoad"], + deps = [ + ":decode", + ":jasmine-polyfill", + ":polyfill", + ], +) + +closure_js_library( + name = "test_data_js", + testonly = True, + srcs = ["test_data.js"], + suppress = ["lintChecks"], +) + +closure_js_test( + name = "bundle_test", + srcs = ["bundle_test.js"], + entry_points = ["bundle_test.js"], + suppress = ["moduleLoad"], + deps = [ + ":decode", + ":jasmine-polyfill", ":polyfill", - "@io_bazel_rules_closure//closure/library:testing", + ":test_data_js", ], ) diff --git a/js/decode_synth_test.js b/js/decode_synth_test.js index d321a88..34ab537 100644 --- a/js/decode_synth_test.js +++ b/js/decode_synth_test.js @@ -2289,7 +2289,8 @@ testZeroCostLiterals() { describe("DecodeSynthTest", () => { const testNames = Object.keys(allTests); for (let i = 0; i < testNames.length; ++i) { - const testName = testNames[i]; - it(testName, allTests[testName]); + const key = testNames[i]; + const testName = key.replace(/\$/g, ''); + it(testName, allTests[key]); } }); diff --git a/js/jasmine-polyfill.js b/js/jasmine-polyfill.js new file mode 100644 index 0000000..69d7ec4 --- /dev/null +++ b/js/jasmine-polyfill.js @@ -0,0 +1,35 @@ +goog.require('goog.testing.TestCase'); +goog.require('goog.testing.asserts'); +goog.require('goog.testing.jsunit'); + +let test_case_; + +function describe(caseName, callback) { + test_case_ = new goog.testing.TestCase(caseName); + callback(); + window['G_testRunner'].initialize(test_case_); +} + +function it(testName, callback) { + test_case_.add(new goog.testing.TestCase.Test(testName, callback)); +} + +/** + * @param {*} actual + * @constructor + */ +function Expect(actual) { + this.actual = actual; +} + +Expect.prototype.toEqual = function(expected) { + assertEquals(expected, this.actual); +}; + +/** + * @param {*} actual + * @returns {!Expect} + */ +function expect(actual) { + return new Expect(actual); +} -- cgit v1.1