mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
docs: clarify where to add tests (#11438)
This commit is contained in:
parent
274bdf2e1a
commit
3ffeea590f
20
DEVELOPER.md
20
DEVELOPER.md
@ -89,11 +89,11 @@ You can copy this tar into your project and run `npm install ./typeorm-x.x.x.tgz
|
||||
|
||||
## Running Tests Locally
|
||||
|
||||
It would be greatly appreciated if PRs that change code come with appropriate tests.
|
||||
It is greatly appreciated if PRs that change code come with appropriate tests.
|
||||
|
||||
To create a test for a specific issue opened on GitHub, create a file: `test/github-issues/<num>/issue-<num>.ts` where
|
||||
`<num>` is the corresponding GitHub issue. For example, if you were creating a PR to fix github issue #363, you'd
|
||||
create `test/github-issues/363/issue-363.ts`.
|
||||
To create a new test, check the [relevant functional tests](https://github.com/typeorm/typeorm/tree/master/test/functional). Depending on the test, you may need to create a new test file or modify an existing one.
|
||||
|
||||
If the test is for a specific regression or issue opened on GitHub, add a comment to the tests mentioning the issue number.
|
||||
|
||||
Most tests will benefit from using this template as a starting point:
|
||||
|
||||
@ -103,7 +103,7 @@ import { createTestingConnections, closeTestingConnections, reloadTestingDatabas
|
||||
import { DataSource } from "../../../src/data-source/DataSource"
|
||||
import { expect } from "chai";
|
||||
|
||||
describe("github issues > #<issue number> <issue title>", () => {
|
||||
describe("description of the functionality you're testing", () => {
|
||||
|
||||
let dataSources: DataSource[];
|
||||
before(async () => dataSources = await createTestingConnections({
|
||||
@ -114,18 +114,16 @@ describe("github issues > #<issue number> <issue title>", () => {
|
||||
beforeEach(() => reloadTestingDatabases(dataSources));
|
||||
after(() => closeTestingConnections(dataSources));
|
||||
|
||||
// optional: test fix for issue https://github.com/typeorm/typeorm/issues/<issue-number>
|
||||
it("should <put a detailed description of what it should do here>", () => Promise.all(dataSources.map(async dataSource => {
|
||||
|
||||
// tests go here
|
||||
|
||||
})));
|
||||
|
||||
// you can add additional tests if needed
|
||||
|
||||
// you can add additional tests if needed
|
||||
});
|
||||
```
|
||||
|
||||
If you place entities in `./entity/<entity-name>.ts` relative to your `issue-<num>.ts` file,
|
||||
If you place entities in `./entity/<entity-name>.ts` relative to your test file,
|
||||
they will automatically be loaded.
|
||||
|
||||
To run the tests, setup your environment configuration by copying `ormconfig.sample.json` into `ormconfig.json` and replacing parameters with your own. The tests will be run for each database that is defined in that file. If you're working on something that's not database specific and you want to speed things up, you can pick which objects in the file make sense for you to keep.
|
||||
@ -149,7 +147,7 @@ describe.only('your describe test', ....)
|
||||
Alternatively, you can use the `--grep` flag to pass a regex to `mocha`. Only the tests that have `describe`/`it` statements that match the regex will be run. For example:
|
||||
|
||||
```shell
|
||||
npm run test -- --grep "github issues > #363"
|
||||
npm run test -- --grep "your test name"
|
||||
```
|
||||
|
||||
### Faster developer cycle for editing code and running tests
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user