测试
¥Testing
通常,测试应该与正在测试的模块一起添加到 tests/
文件夹中。
¥In general, tests should be added within a tests/
folder alongside the modules they
are testing.
单元测试涵盖不需要调用外部 API 的模块化逻辑。
¥Unit tests cover modular logic that does not require calls to outside APIs.
如果你添加了新的逻辑,请添加单元测试。单元测试应该被称为 *.test.ts
。
¥If you add new logic, please add a unit test.
Unit tests should be called *.test.ts
.
要仅运行单元测试,请运行:
¥To run only unit tests, run:
yarn test
运行单个测试
¥Running a single test
要运行单个测试,请在工作区内运行以下命令:
¥To run a single test, run the following from within a workspace:
yarn test:single /path/to/yourtest.test.ts
这对于开发单个功能很有用。
¥This is useful for developing individual features.
集成测试涵盖需要调用外部 API(通常与其他服务集成)的逻辑。
¥Integration tests cover logic that requires making calls to outside APIs (often integration with other services).
如果你添加了对新外部 API 的支持,请添加新的集成测试。集成测试应该称为 *.int.test.ts
。
¥If you add support for a new external API, please add a new integration test.
Integration tests should be called *.int.test.ts
.
请注意,大多数集成测试都需要凭据或其他设置。你可能需要像示例 此处 一样设置一个 langchain/.env
或 libs/langchain-community/.env
文件。
¥Note that most integration tests require credentials or other setup. You will likely need to set up a langchain/.env
or libs/langchain-community/.env
file
like the example here.
我们通常建议只使用 yarn test:single
运行集成测试,但如果你想运行所有集成测试,请运行:
¥We generally recommend only running integration tests with yarn test:single
, but if you want to run all integration tests, run:
yarn test:integration