Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

feat: reseed db before tests #7747

Merged
merged 7 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/server-core/src/sequelize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export default (app: Application): void => {
promiseReject = reject
})

app.setup = async function (...args: any) {
app.setup = async function (...args) {
const testModeForceRefresh = app.get('testModeForceRefresh')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than setting this manually, we can rely on appConfig.testEnabled, such that it is automatically applied every time createFeathersExpressApp is run

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to do this initially but encountered some problems. DB is also reseeded before tests (in npm run pretest) which requires process.exit(0) here. Using appConfig.testEnabled will have some problems.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh I see. Let's use the appConfig instead of feathers internal state. We can add a new configuration option with the desired functionality.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this change!


try {
await sequelize.query('SET FOREIGN_KEY_CHECKS = 0')

Expand All @@ -47,7 +49,7 @@ export default (app: Application): void => {
if (typeof (sequelizeModel as any).associate === 'function') {
;(sequelizeModel as any).associate(sequelize.models)
}
await sequelizeModel.sync({ force: forceRefresh })
await sequelizeModel.sync({ force: forceRefresh || testModeForceRefresh })

if (prepareDb) {
const columnResult = await sequelize.query(`DESCRIBE \`${model}\``)
Expand Down Expand Up @@ -82,7 +84,9 @@ export default (app: Application): void => {
const sync = await sequelize.sync()
try {
// configure seeder and seed
await seeder(app, forceRefresh, prepareDb)
if (testModeForceRefresh) logger.info('Starting seeding in testModeForceRefresh')
await seeder(app, forceRefresh || testModeForceRefresh, prepareDb)
if (testModeForceRefresh) logger.info('Finished seeding in testModeForceRefresh')
} catch (err) {
logger.error('Feathers seeding error')
logger.error(err)
Expand Down
1 change: 1 addition & 0 deletions packages/server-core/src/user/user/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('user service', () => {
let app: Application
before(async () => {
app = createFeathersExpressApp()
app.set('testModeForceRefresh', true)
await app.setup()
})
after(() => {
Expand Down