-
Notifications
You must be signed in to change notification settings - Fork 313
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 #1312 from automatisch/global-test-hooks
feat: Add global hooks for jest
- Loading branch information
Showing
8 changed files
with
57 additions
and
14 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
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,8 @@ | ||
import { Knex } from 'knex'; | ||
|
||
declare global { | ||
declare namespace globalThis { | ||
// eslint-disable-next-line no-var | ||
var knex: Knex; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,17 @@ | ||
import { client as knex } from '../../src/config/database'; | ||
|
||
global.beforeAll(async () => { | ||
global.knex = knex; | ||
}); | ||
|
||
global.beforeEach(async function () { | ||
this.transaction = await global.knex.transaction(); | ||
}); | ||
|
||
global.afterEach(async function () { | ||
await this.transaction.rollback(); | ||
}); | ||
|
||
global.afterAll(async () => { | ||
global.knex.destroy(); | ||
}); |
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,5 @@ | ||
const exitProcess = (): void => { | ||
process.exit(0); | ||
}; | ||
|
||
export default exitProcess; |
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,2 +1,22 @@ | ||
import './check-env-file'; | ||
import './create-database'; | ||
import { createDatabaseAndUser } from '../../bin/database/utils'; | ||
import { client as knex } from '../../src/config/database'; | ||
import logger from '../../src/helpers/logger'; | ||
|
||
const createAndMigrateDatabase = async () => { | ||
await createDatabaseAndUser(); | ||
const migrator = knex.migrate; | ||
|
||
await migrator.latest(); | ||
|
||
logger.info(`Completed database migrations for the test database.`); | ||
}; | ||
|
||
createAndMigrateDatabase() | ||
.then(() => { | ||
process.exit(0); | ||
}) | ||
.catch((error) => { | ||
logger.error(error); | ||
process.exit(1); | ||
}); |