Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
zulip_test: Re-export internal functions used by Puppeteer tests.
Anders Kaseorg79ac5c25b5e7
diff --git a/.eslintrc.json b/.eslintrc.jsonindex 9af047aae11..95b7c76543d 100644--- a/.eslintrc.json+++ b/.eslintrc.json@@ -118,7 +118,8 @@"files": ["frontend_tests/puppeteer_lib/**", "frontend_tests/puppeteer_tests/**"],"globals": {"$": false,- "current_msg_list": false+ "current_msg_list": false,+ "zulip_test": false}},{diff --git a/frontend_tests/puppeteer_lib/common.ts b/frontend_tests/puppeteer_lib/common.tsindex b1246180f12..6c448b05f55 100644--- a/frontend_tests/puppeteer_lib/common.ts+++ b/frontend_tests/puppeteer_lib/common.ts@@ -38,10 +38,9 @@ class CommonUtils {},async expect(page: Page, expected: string): Promise<void> {- const actual_recipients = await page.evaluate(() => {- const compose_state = window.require("./static/js/compose_state");- return compose_state.private_message_recipient();- });+ const actual_recipients = await page.evaluate(() =>+ zulip_test.private_message_recipient(),+ );assert.equal(actual_recipients, expected);},};@@ -182,20 +181,17 @@ class CommonUtils {}async get_stream_id(page: Page, stream_name: string): Promise<number> {- return await page.evaluate((stream_name: string) => {- const stream_data = window.require("./static/js/stream_data");- return stream_data.get_stream_id(stream_name);- }, stream_name);+ return await page.evaluate(+ (stream_name: string) => zulip_test.get_stream_id(stream_name),+ stream_name,+ );}async get_user_id_from_name(page: Page, name: string): Promise<number> {if (this.fullname[name] !== undefined) {name = this.fullname[name];}- return await page.evaluate((name: string) => {- const people = window.require("./static/js/people");- return people.get_user_id_from_name(name);- }, name);+ return await page.evaluate((name: string) => zulip_test.get_user_id_from_name(name), name);}async get_internal_email_from_name(page: Page, name: string): Promise<string> {@@ -203,9 +199,8 @@ class CommonUtils {name = this.fullname[name];}return await page.evaluate((fullname: string) => {- const people = window.require("./static/js/people");- const user_id = people.get_user_id_from_name(fullname);- return people.get_by_user_id(user_id).email;+ const user_id = zulip_test.get_user_id_from_name(fullname);+ return zulip_test.get_person_by_user_id(user_id).email;}, name);}@@ -293,7 +288,6 @@ class CommonUtils {- does it look to have beenre-rendered based on server info?*/- const rows = window.require("./static/js/rows");const last_msg = current_msg_list.last();if (last_msg === undefined) {return false;@@ -307,8 +301,8 @@ class CommonUtils {return false;}- const row = rows.last_visible();- if (rows.id(row) !== last_msg.id) {+ const row = zulip_test.last_visible_row();+ if (zulip_test.row_id(row) !== last_msg.id) {return false;}@@ -373,10 +367,7 @@ class CommonUtils {}// Close the compose box after sending the message.- await page.evaluate(() => {- const compose_actions = window.require("./static/js/compose_actions");- compose_actions.cancel();- });+ await page.evaluate(() => zulip_test.cancel_compose());// Make sure the compose box is closed.await page.waitForSelector("#compose-textarea", {hidden: true});}diff --git a/frontend_tests/puppeteer_tests/07-navigation.ts b/frontend_tests/puppeteer_tests/07-navigation.tsindex 20c5f66b0e4..b9c07700637 100644--- a/frontend_tests/puppeteer_tests/07-navigation.ts+++ b/frontend_tests/puppeteer_tests/07-navigation.ts@@ -57,10 +57,7 @@ async function test_reload_hash(page: Page): Promise<void> {const initial_hash = await page.evaluate(() => window.location.hash);- await page.evaluate(() => {- const reload = window.require("./static/js/reload");- reload.initiate({immediate: true});- });+ await page.evaluate(() => zulip_test.initiate_reload({immediate: true}));await page.waitForSelector("#zfilt", {visible: true});const page_load_time = await page.evaluate(() => page_params.page_load_time);@@ -75,10 +72,7 @@ async function navigation_tests(page: Page): Promise<void> {await navigate_to_settings(page);- const verona_id = await page.evaluate(() => {- const stream_data = window.require("./static/js/stream_data");- return stream_data.get_stream_id("Verona");- });+ const verona_id = await page.evaluate(() => zulip_test.get_stream_id("Verona"));const verona_narrow = `narrow/stream/${verona_id}-Verona`;await navigate_to(page, verona_narrow, "message_feed_container");diff --git a/frontend_tests/puppeteer_tests/09-mention.ts b/frontend_tests/puppeteer_tests/09-mention.tsindex 9dd60f392ad..b0d1fdf75bd 100644--- a/frontend_tests/puppeteer_tests/09-mention.ts+++ b/frontend_tests/puppeteer_tests/09-mention.ts@@ -19,14 +19,12 @@ async function test_mention(page: Page): Promise<void> {await common.ensure_enter_does_not_send(page);console.log("Checking for all everyone warning");- const stream_size = await page.evaluate(() => {- const stream_data = window.require("./static/js/stream_data");- return stream_data.get_subscriber_count(stream_data.get_sub("Verona").stream_id);- });+ const stream_size = await page.evaluate(() =>+ zulip_test.get_subscriber_count(zulip_test.get_sub("Verona").stream_id),+ );const threshold = await page.evaluate(() => {- const compose = window.require("./static/js/compose");- compose.set_wildcard_mention_large_stream_threshold(5);- return compose.wildcard_mention_large_stream_threshold;+ zulip_test.set_wildcard_mention_large_stream_threshold(5);+ return zulip_test.wildcard_mention_large_stream_threshold;});assert(stream_size > threshold);await page.click("#compose-send-button");diff --git a/static/js/bundles/app.js b/static/js/bundles/app.jsindex c765146648a..f20fac312ca 100644--- a/static/js/bundles/app.js+++ b/static/js/bundles/app.js@@ -39,6 +39,7 @@ import "../settings_profile_fields";import "../settings";import "../ui_init";import "../desktop_integration";+import "../zulip_test";// Import stylesdiff --git a/static/js/global.d.ts b/static/js/global.d.tsindex ecd0c084cff..a5ddd778c39 100644--- a/static/js/global.d.ts+++ b/static/js/global.d.ts@@ -25,6 +25,7 @@ declare let ui: any;declare let unread: any;declare let unread_ops: any;declare let widgetize: any;+declare let zulip_test: any;interface JQuery {expectOne(): JQuery;diff --git a/static/js/zulip_test.js b/static/js/zulip_test.jsnew file mode 100644index 00000000000..3be1d2bef7c--- /dev/null+++ b/static/js/zulip_test.js@@ -0,0 +1,14 @@+// This module, exposed through the zulip_test global variable,+// re-exports certain internal functions so they can be used by the+// Puppeteer tests. It should not be used in the code itself.++export {+ set_wildcard_mention_large_stream_threshold,+ wildcard_mention_large_stream_threshold,+} from "./compose";+export {private_message_recipient} from "./compose_state";+export {get_stream_id, get_sub, get_subscriber_count} from "./stream_data";+export {get_by_user_id as get_person_by_user_id, get_user_id_from_name} from "./people";+export {last_visible as last_visible_row, id as row_id} from "./rows";+export {cancel as cancel_compose} from "./compose_actions";+export {initiate as initiate_reload} from "./reload";diff --git a/tools/test-js-with-node b/tools/test-js-with-nodeindex dcf56cee161..17b52a8b6a5 100755--- a/tools/test-js-with-node+++ b/tools/test-js-with-node@@ -164,6 +164,7 @@ EXEMPT_FILES = {"static/js/zcommand.js","static/js/zform.js","static/js/zulip.js",+ "static/js/zulip_test.js",}parser = argparse.ArgumentParser(USAGE)diff --git a/webpack.config.ts b/webpack.config.tsindex 9a5517190d6..137404f671c 100644--- a/webpack.config.ts+++ b/webpack.config.ts@@ -37,6 +37,11 @@ export default (_env: unknown, argv: {mode?: string}): webpack.Configuration[] =),module: {rules: [+ {+ test: require.resolve("./static/js/zulip_test"),+ loader: "expose-loader",+ options: {exposes: "zulip_test"},+ },{test: require.resolve("./tools/debug-require"),loader: "expose-loader",