tests: Rename the Node tests to *.cjs.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2024-11-12 22:05:32 -08:00
committed by Tim Abbott
parent 30eabb9d6c
commit 687f1b1651
180 changed files with 531 additions and 530 deletions

View File

@@ -381,9 +381,9 @@ node test fixtures and our OpenAPI documentation.
#### Node testing
Once you've completed backend testing, be sure to add an example event
in `web/tests/lib/events.js`, a test of the
in `web/tests/lib/events.cjs`, a test of the
`server_events_dispatch.js` code for that event in
`web/tests/dispatch.test.js`, and verify your example
`web/tests/dispatch.test.cjs`, and verify your example
against the two versions of the schema that you declared above using
`tools/check-schemas`.

View File

@@ -41,7 +41,7 @@ message is sent). As a result, we try to make sure that
The Python-Markdown implementation is tested by
`zerver/tests/test_markdown.py`, and the marked.js implementation and
`markdown.contains_backend_only_syntax` are tested by
`web/tests/markdown.test.js`.
`web/tests/markdown.test.cjs`.
A shared set of fixed test data ("test fixtures") is present in
`zerver/tests/fixtures/markdown_test_cases.json`, and is automatically used

View File

@@ -18,7 +18,7 @@ name when debugging something.
The JS unit tests are written to work with node. You can find them
in `web/tests`. Here is an example test from
`web/tests/stream_data.test.js`:
`web/tests/stream_data.test.cjs`:
```js
(function test_get_by_id() {
@@ -45,7 +45,7 @@ there are, you should strive to follow the patterns of the existing tests
and add your own tests.
A good first test to read is
[example1.js](https://github.com/zulip/zulip/blob/main/web/tests/example1.test.js).
[example1.test.cjs](https://github.com/zulip/zulip/blob/main/web/tests/example1.test.cjs).
(And then there are several other example files.)
## How the node tests work
@@ -60,10 +60,10 @@ those slow down the tests a lot, and often don't add much value.
Instead, the preferred model for our unit tests is to mock DOM
manipulations (which in Zulip are almost exclusively done via
`jQuery`) using a custom library
[zjquery](https://github.com/zulip/zulip/blob/main/web/tests/lib/zjquery.js).
[zjquery](https://github.com/zulip/zulip/blob/main/web/tests/lib/zjquery.cjs).
The
[unit test file](https://github.com/zulip/zulip/blob/main/web/tests/zjquery.test.js)
[unit test file](https://github.com/zulip/zulip/blob/main/web/tests/zjquery.test.cjs)
for `zjquery` is designed to be also serve as nice documentation for
how to use `zjquery`, and is **highly recommended reading** for anyone
working on or debugging the Zulip node tests.
@@ -149,7 +149,7 @@ narrow_state.stream = function () {
## Creating new test modules
The test runner (`index.js`) automatically runs all .js files in the
The test runner (`index.cjs`) automatically runs all .test.cjs files in the
`web/tests` directory, so you can simply start editing a file
in that directory to create a new test.
@@ -278,7 +278,7 @@ These instructions assume you're using the Vagrant development environment.
1. **Set the `Node.js interpreter path` to `/usr/local/bin/node`**
1. Hit `OK` 2 times to get back to the `Run/Debug Configurations` window.
1. Under `Working Directory` select the root `zulip` directory.
1. Under `JavaScript file`, enter `web/tests/lib/index.js`
1. Under `JavaScript file`, enter `web/tests/lib/index.cjs`
-- this is the root script for Zulip's node unit tests.
Congratulations! You've now set up the integration.
@@ -288,7 +288,7 @@ Congratulations! You've now set up the integration.
To use Webstorm to debug a given node test file, do the following:
1. Under `Application parameters` choose the node test file that you
are trying to test (e.g., `web/tests/message_store.test.js`).
are trying to test (e.g., `web/tests/message_store.test.cjs`).
1. Under `Path Mappings`, set `Project Root` to `/srv/zulip`
(i.e. where the `zulip` Git repository is mounted in the Vagrant guest).
1. Use the WebStorm debugger; see [this overview][webstorm-debugging]

View File

@@ -62,7 +62,7 @@ organization in Zulip). The following files are involved in the process:
- `web/e2e-tests/admin.test.ts`: end-to-end tests for the organization
admin settings pages.
- `web/tests/dispatch.test.js`
- `web/tests/dispatch.test.cjs`
**Documentation**
@@ -668,11 +668,11 @@ frontend tests: [node-based unit tests](../testing/testing-with-node.md) and
At the minimum, if you created a new function to update UI in
`settings_org.ts`, you will need to mock that function in
`web/tests/dispatch.test.js`. Add the name of the UI
`web/tests/dispatch.test.cjs`. Add the name of the UI
function you created to the following object with `noop` as the value:
```js
// web/tests/dispatch.test.js
// web/tests/dispatch.test.cjs
set_global('settings_org', {
update_email_change_display: noop,