Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
node tests: Break up password tests.
Steve Howelld1e0aa1aa524
diff --git a/frontend_tests/node_tests/password.js b/frontend_tests/node_tests/password.jsindex 103c9877dc1..582234f2d06 100644--- a/frontend_tests/node_tests/password.js+++ b/frontend_tests/node_tests/password.js@@ -2,14 +2,29 @@const {strict: assert} = require("assert");-const {set_global, zrequire} = require("../zjsunit/namespace");+const {set_global, with_field, zrequire} = require("../zjsunit/namespace");const {run_test} = require("../zjsunit/test");set_global("zxcvbn", require("zxcvbn"));const common = zrequire("common");-run_test("basics", () => {+function password_field(min_length, min_guesses) {+ const self = {};++ self.data = (field) => {+ if (field === "minLength") {+ return min_length;+ } else if (field === "minGuesses") {+ return min_guesses;+ }+ throw new Error(`Unknown field ${field}`);+ };++ return self;+}++run_test("basics w/progress bar", () => {let accepted;let password;let warning;@@ -35,21 +50,6 @@ run_test("basics", () => {return self;})();- function password_field(min_length, min_guesses) {- const self = {};-- self.data = (field) => {- if (field === "minLength") {- return min_length;- } else if (field === "minGuesses") {- return min_guesses;- }- throw new Error(`Unknown field ${field}`);- };-- return self;- }-password = "z!X4@S_&";accepted = common.password_quality(password, bar, password_field(10, 80000));assert(!accepted);@@ -72,11 +72,20 @@ run_test("basics", () => {assert.equal(bar.added_class, "bar-danger");warning = common.password_warning(password, password_field(6));assert.equal(warning, 'Repeats like "aaa" are easy to guess');+});- set_global("zxcvbn", undefined);- password = "aaaaaaaa";- accepted = common.password_quality(password, bar, password_field(6, 1e100));- assert(accepted === undefined);- warning = common.password_warning(password, password_field(6));- assert(warning === undefined);+run_test("zxcvbn undefined", () => {+ // According to common.js, we load zxcvbn.js asynchronously, so the+ // variable might not be set. This just gets line coverage on the+ // defensive code.++ const password = "aaaaaaaa";+ const progress_bar = undefined;++ with_field(global, "zxcvbn", undefined, () => {+ const accepted = common.password_quality(password, progress_bar, password_field(6, 1e100));+ assert(accepted === undefined);+ const warning = common.password_warning(password, password_field(6));+ assert(warning === undefined);+ });});