Fix JS tests

PiperOrigin-RevId: 545743271
This commit is contained in:
Evgenii Kliuchnikov 2023-07-05 18:49:09 +00:00 committed by Evgenii Kliuchnikov
parent 11b8d7cb8a
commit dd3eb162b0
3 changed files with 84 additions and 4 deletions

View File

@ -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",
"@io_bazel_rules_closure//closure/library:testing",
],
)
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",
":test_data_js",
],
)

View File

@ -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]);
}
});

35
js/jasmine-polyfill.js Normal file
View File

@ -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);
}