forked from redwoodjs/redwood
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request redwoodjs#691 from RobertBroersma/rb-api-test
Allow configuring test database
- Loading branch information
Showing
5 changed files
with
43 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
// used by cli `rw test` command | ||
// note: roodDir is a workaround for jest working directory weirdness | ||
|
||
const path = require('path') | ||
|
||
module.exports = { | ||
resolver: 'jest-directory-named-resolver', | ||
rootDir: process.cwd(), | ||
setupFilesAfterEnv: [path.resolve(__dirname, './jest.setup.api.js')], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const path = require('path') | ||
|
||
const camelCase = require('lodash/camelCase') | ||
const { getPaths } = require('@redwoodjs/internal') | ||
|
||
const redwoodPaths = getPaths() | ||
|
||
const { db } = require(path.join(redwoodPaths.api.src, 'lib', 'db')) | ||
|
||
/** | ||
* Loop through all db models and clear the tables before every test | ||
*/ | ||
beforeEach(async () => { | ||
for (let model of db.dmmf.datamodel.models) { | ||
await db[camelCase(model.name)].deleteMany() | ||
} | ||
}) | ||
|
||
afterAll(async () => { | ||
await db.disconnect() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters