-
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.
test(seed): split out seed tests, test in parallel to main tests
- Loading branch information
1 parent
9ded4bf
commit 000a017
Showing
16 changed files
with
254 additions
and
27 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
version: '3.7' | ||
services: | ||
postgres-seed: | ||
image: postgres:12 | ||
restart: always | ||
environment: | ||
- POSTGRES_USER=medplum | ||
- POSTGRES_PASSWORD=medplum | ||
|
||
volumes: | ||
- ./postgres/postgres.conf:/usr/local/etc/postgres/postgres.conf | ||
- ./postgres/:/docker-entrypoint-initdb.d/ | ||
command: postgres -c config_file=/usr/local/etc/postgres/postgres.conf | ||
ports: | ||
- '5433:5432' |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,15 @@ | ||
import type { Config } from 'jest'; | ||
|
||
export default { | ||
testEnvironment: 'node', | ||
testTimeout: 600000, | ||
testSequencer: '<rootDir>/jest.sequencer.js', | ||
transform: { | ||
'^.+\\.(js|jsx|ts|tsx)$': 'babel-jest', | ||
}, | ||
testMatch: ['<rootDir>/src/**/*.test.ts'], | ||
moduleFileExtensions: ['ts', 'js', 'json', 'node'], | ||
coverageDirectory: 'coverage', | ||
coverageReporters: ['json', 'text'], | ||
collectCoverageFrom: ['**/src/**/*', '!**/src/__mocks__/**/*.ts', '!**/src/migrations/**/*.ts'], | ||
} satisfies Config; |
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 type { Config } from 'jest'; | ||
import defaultConfig from './jest.config'; | ||
|
||
export default { | ||
...defaultConfig, | ||
testMatch: ['<rootDir>/seed-tests/**/*.test.ts'], | ||
collectCoverageFrom: ['<rootDir>/seed-tests/**/*'], | ||
} satisfies Config; |
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,42 @@ | ||
import { Project } from '@medplum/fhirtypes'; | ||
import { initAppServices, shutdownApp } from '../src/app'; | ||
import { loadTestConfig } from '../src/config'; | ||
import { getDatabasePool } from '../src/database'; | ||
import { SelectQuery } from '../src/fhir/sql'; | ||
import { seedDatabase } from '../src/seed'; | ||
import { withTestContext } from '../src/test.setup'; | ||
|
||
describe('Seed', () => { | ||
beforeAll(async () => { | ||
console.log = jest.fn(); | ||
|
||
const config = await loadTestConfig(); | ||
config.database.port = process.env['POSTGRES_SEED_PORT'] | ||
? Number.parseInt(process.env['POSTGRES_SEED_PORT'], 10) | ||
: 5433; | ||
return withTestContext(() => initAppServices(config)); | ||
}); | ||
|
||
afterAll(async () => { | ||
await shutdownApp(); | ||
}); | ||
|
||
test('Seeder completes successfully -- serial version', async () => { | ||
// First time, seeder should run | ||
await seedDatabase({ parallel: false }); | ||
|
||
// Make sure the first project is a super admin | ||
const rows = await new SelectQuery('Project') | ||
.column('content') | ||
.where('name', '=', 'Super Admin') | ||
.execute(getDatabasePool()); | ||
expect(rows.length).toBe(1); | ||
|
||
const project = JSON.parse(rows[0].content) as Project; | ||
expect(project.superAdmin).toBe(true); | ||
expect(project.strictMode).toBe(true); | ||
|
||
// Second time, seeder should silently ignore | ||
await seedDatabase({ parallel: false }); | ||
}, 240000); | ||
}); |
12 changes: 6 additions & 6 deletions
12
packages/server/src/seed.test.ts → packages/server/seed-tests/seed.test.ts
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,4 +1,4 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"include": ["src/**/*.ts"] | ||
"include": ["src/**/*.ts", "seed-tests/seed-serial.test.ts", "seed-tests/seed.test.ts"] | ||
} |
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,16 @@ | ||
{ | ||
"$schema": "https://turborepo.org/schema.json", | ||
"extends": ["//"], | ||
"pipeline": { | ||
"test:seed:serial": { | ||
"dependsOn": ["build"], | ||
"outputs": ["coverage/**"], | ||
"inputs": ["src/**/*.tsx", "src/**/*.ts"] | ||
}, | ||
"test:seed:parallel": { | ||
"dependsOn": ["build"], | ||
"outputs": ["coverage/**"], | ||
"inputs": ["src/**/*.tsx", "src/**/*.ts"] | ||
} | ||
} | ||
} |
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