SERVER-125920 Introduce jstests-local CLAUDE.md (#53103)

GitOrigin-RevId: 14131f41956ea00f3f1657c651a0462834f7167f
This commit is contained in:
romanskas 2026-05-13 16:53:03 +02:00 committed by MongoDB Bot
parent a9d8aa322d
commit 2c288ee479
3 changed files with 63 additions and 4 deletions

61
jstests/AGENTS.md Normal file
View File

@ -0,0 +1,61 @@
## JavaScript Test Code Conventions
### Assertion Library
ALWAYS use our own assertion library that is defined at `src/mongo/shell/assert.js` and
automatically loaded into the global scope before running each test.
ALWAYS wrap commands with `assert.commandWorked()`, unless failures are expected and checked. Use
`assert.writeOK()` when working with legacy bulk write APIs.
Use `assert.soon()` only for asynchronous or eventually-consistent conditions.
### Mocha Style for New Test Files
Use the mocha style to structure test cases in newly added test files. The
`jstests/libs/mochalite.js` module implements `describe`, `it`, `before`, `beforeEach`, `afterEach`,
and `after`. Import only what you need. Feel free to add other mocha helper functions to
`jstests/libs/mochalite.js` if they would make the current test cleaner.
```js
import {before, describe, it} from "jstests/libs/mochalite.js";
describe("feature under test", function () {
before(function () {
/* one-time setup */
});
it("does X", function () {
/* ... */
});
});
```
### Use JSON-Conformant Object Serialization in Logs
Pass objects to the `attr` parameter of assertion and logging functions instead of concatenating
`tojson()` into the message string. Most `assert.*` functions accept an `attr` object as their last
argument.
```js
// Bad — tojson() in the message string
assert(cursor.hasOwnProperty("metrics"), "metrics missing: " + tojson(cursor));
// Good — object passed via attr
assert(cursor.hasOwnProperty("metrics"), "metrics missing", {cursor});
```
For logging:
```js
// Bad
jsTest.log.info("got cursor: " + tojson(cursor));
// Good
jsTest.log.info("got cursor", {cursor});
```
### Resource and Settings Cleanup
ALWAYS clean up resources and settings immediately after they are no longer needed. Examples of
server resources are cursors and collections. Examples of settings are server parameters and test
framework settings stored in the global `TestData` object.

1
jstests/CLAUDE.md Normal file
View File

@ -0,0 +1 @@
@AGENTS.md

View File

@ -1,9 +1,6 @@
version: 2.0.0
filters:
- "README.md":
approvers:
- 10gen/devprod-test-infrastructure
- "tags.md":
- "*.md":
approvers:
- 10gen/devprod-test-infrastructure
- "**/*analyze_shard_key*":