mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	When we were preparing the conversion to ES modules in 2019, the primary obstacle was that the Node tests extensively relied on the ability to reach into modules and mutate their CommonJS exports in order to mock things. ES module bindings are not mutable, so in commit173c9cee42we added babel-plugin-rewire-ts as a kludgy transpilation-based workaround for this to unblock the conversion. However, babel-plugin-rewire-ts is slow, buggy, nonstandard, confusing, and unmaintained. It’s incompatible with running our ES modules as native ES modules, and prevents us from taking advantage of modern tools for ES modules. So we want to excise all use of __Rewire__ (and the disallow_rewire, override_rewire helper functions that rely on it) from the tests and remove babel-plugin-rewire-ts. Commits64abdc199eande17ba5260a(#20730) prepared for this by letting us see where __Rewire__ is being used. Now we go through and remove most of the uses that are easy to remove without modifying the production code at all. Signed-off-by: Anders Kaseorg <anders@zulip.com>
		
			
				
	
	
		
			71 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			71 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
"use strict";
 | 
						|
 | 
						|
const {strict: assert} = require("assert");
 | 
						|
 | 
						|
const {mock_esm, zrequire} = require("../zjsunit/namespace");
 | 
						|
const {run_test} = require("../zjsunit/test");
 | 
						|
const $ = require("../zjsunit/zjquery");
 | 
						|
 | 
						|
const list_widget = mock_esm("../../static/js/list_widget");
 | 
						|
const muted_users_ui = mock_esm("../../static/js/muted_users_ui");
 | 
						|
 | 
						|
const settings_muted_users = zrequire("settings_muted_users");
 | 
						|
const muted_users = zrequire("muted_users");
 | 
						|
const people = zrequire("people");
 | 
						|
 | 
						|
const noop = () => {};
 | 
						|
 | 
						|
run_test("settings", ({override}) => {
 | 
						|
    people.add_active_user({user_id: 5, email: "five@zulip.com", full_name: "Feivel Fiverson"});
 | 
						|
    muted_users.add_muted_user(5, 1577836800);
 | 
						|
    let populate_list_called = false;
 | 
						|
    override(list_widget, "create", ($container, list) => {
 | 
						|
        assert.deepEqual(list, [
 | 
						|
            {
 | 
						|
                date_muted_str: "Jan\u00A001,\u00A02020",
 | 
						|
                user_id: 5,
 | 
						|
                user_name: "Feivel Fiverson",
 | 
						|
            },
 | 
						|
        ]);
 | 
						|
        populate_list_called = true;
 | 
						|
    });
 | 
						|
 | 
						|
    settings_muted_users.reset();
 | 
						|
    assert.equal(settings_muted_users.loaded, false);
 | 
						|
 | 
						|
    settings_muted_users.set_up();
 | 
						|
    assert.equal(settings_muted_users.loaded, true);
 | 
						|
    assert.ok(populate_list_called);
 | 
						|
 | 
						|
    const unmute_click_handler = $("body").get_on_handler("click", ".settings-unmute-user");
 | 
						|
    assert.equal(typeof unmute_click_handler, "function");
 | 
						|
 | 
						|
    const event = {
 | 
						|
        stopPropagation: noop,
 | 
						|
    };
 | 
						|
 | 
						|
    const $unmute_button = $.create("settings-unmute-user");
 | 
						|
    const $fake_row = $('tr[data-user-id="5"]');
 | 
						|
    $unmute_button.closest = (opts) => {
 | 
						|
        assert.equal(opts, "tr");
 | 
						|
        return $fake_row;
 | 
						|
    };
 | 
						|
 | 
						|
    let row_attribute_fetched = false;
 | 
						|
    $fake_row.attr = (opts) => {
 | 
						|
        assert.equal(opts, "data-user-id");
 | 
						|
        row_attribute_fetched += 1;
 | 
						|
        return "5";
 | 
						|
    };
 | 
						|
 | 
						|
    let unmute_user_called = false;
 | 
						|
    muted_users_ui.unmute_user = (user_id) => {
 | 
						|
        assert.equal(user_id, 5);
 | 
						|
        unmute_user_called = true;
 | 
						|
    };
 | 
						|
 | 
						|
    unmute_click_handler.call($unmute_button, event);
 | 
						|
    assert.ok(unmute_user_called);
 | 
						|
    assert.ok(row_attribute_fetched);
 | 
						|
});
 |