snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
This commit is contained in:
77
web/tests/example1.test.cjs
Normal file
77
web/tests/example1.test.cjs
Normal file
@@ -0,0 +1,77 @@
|
||||
"use strict";
|
||||
|
||||
// This is a general tour of how to write node tests that
|
||||
// may also give you some quick insight on how the Zulip
|
||||
// browser app is constructed.
|
||||
|
||||
// The statements below are pretty typical for most node
|
||||
// tests. The reason we need these helpers will hopefully
|
||||
// become clear as you keep reading.
|
||||
const assert = require("node:assert/strict");
|
||||
|
||||
const {make_stream} = require("./lib/example_stream.cjs");
|
||||
const {make_user} = require("./lib/example_user.cjs");
|
||||
const {zrequire} = require("./lib/namespace.cjs");
|
||||
const {run_test} = require("./lib/test.cjs");
|
||||
|
||||
// We will use our special zrequire helper to import the
|
||||
// Zulip code. We use zrequire instead of require,
|
||||
// because it has some magic to clear state when we move
|
||||
// on to the next test.
|
||||
const people = zrequire("people");
|
||||
const stream_data = zrequire("stream_data");
|
||||
const util = zrequire("util");
|
||||
|
||||
// Let's start with testing a function from util.ts.
|
||||
//
|
||||
// The most basic unit tests load up code, call functions,
|
||||
// and assert truths:
|
||||
|
||||
assert.ok(!util.find_stream_wildcard_mentions("boring text"));
|
||||
assert.ok(util.find_stream_wildcard_mentions("mention @**everyone**"));
|
||||
|
||||
// Let's test with people.js next. We'll show this technique:
|
||||
// * get a false value
|
||||
// * change the data
|
||||
// * get a true value
|
||||
|
||||
const isaac = make_user({
|
||||
email: "isaac@example.com",
|
||||
user_id: 30,
|
||||
full_name: "Isaac Newton",
|
||||
});
|
||||
|
||||
// The `people` object is a very fundamental object in the
|
||||
// Zulip app. You can learn a lot more about it by reading
|
||||
// the tests in people.test.cjs in the same directory as this file.
|
||||
|
||||
// Let's exercise the code and use assert to verify it works!
|
||||
assert.ok(!people.is_known_user_id(isaac.user_id));
|
||||
people.add_active_user(isaac);
|
||||
assert.ok(people.is_known_user_id(isaac.user_id));
|
||||
|
||||
// Let's look at stream_data next, and we will start by putting
|
||||
// some data at module scope. (You could also declare this inside
|
||||
// the test, if you prefer.)
|
||||
|
||||
// We use make_stream to create a complete stream object with select
|
||||
// fields explicitly specified, and all other fields populated with
|
||||
// reasonable defaults.
|
||||
const denmark_stream = make_stream({
|
||||
color: "a1a1a1",
|
||||
name: "Denmark",
|
||||
subscribed: false,
|
||||
});
|
||||
|
||||
// We introduce the run_test helper, which mostly just causes
|
||||
// a line of output to go to the console. It does a little more than
|
||||
// that, which we will see later.
|
||||
|
||||
run_test("verify stream_data persists stream color", () => {
|
||||
stream_data.clear_subscriptions();
|
||||
assert.equal(stream_data.get_sub_by_name("Denmark"), undefined);
|
||||
stream_data.add_sub_for_tests(denmark_stream);
|
||||
const sub = stream_data.get_sub_by_name("Denmark");
|
||||
assert.equal(sub.color, "a1a1a1");
|
||||
});
|
||||
// See example2.test.cjs in this directory.
|
||||
Reference in New Issue
Block a user