test: add teardown dependency to clean db after tests
This commit is contained in:
@@ -44,6 +44,14 @@ and it should install the associated browsers for the test running. For more inf
|
||||
|
||||
We recommend using [Playwright Test for VSCode](https://marketplace.visualstudio.com/items?itemName=ms-playwright.playwright) maintained by Microsoft. This lets you run playwright tests from within the code editor, giving you access to additional tools, such as easily running subsets of tests.
|
||||
|
||||
[Global setup and teardown](https://playwright.dev/docs/test-global-setup-teardown) are part of the tests.
|
||||
|
||||
By running `yarn test` setup and teardown actions will take place.
|
||||
|
||||
If you need to setup Admin account (if you didn't seed the DB with the admin account or have clean DB) you should run `auth.setup.js` file.
|
||||
|
||||
If you want to clean the database (drop tables) and perform required migrations run `global.teardown.js`.
|
||||
|
||||
# Test failures
|
||||
|
||||
If there are failing tests in the test suite, this can be caused by a myriad of reasons, but one of the best places to start is either running the test in a headed browser, looking at the associated trace file for the failed test, or checking out the output of a failed GitHub Action.
|
||||
|
25
packages/e2e-tests/knexfile.js
Normal file
25
packages/e2e-tests/knexfile.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const fileExtension = 'js';
|
||||
|
||||
const knexConfig = {
|
||||
client: 'pg',
|
||||
connection: {
|
||||
host: process.env.POSTGRES_HOST,
|
||||
user: process.env.POSTGRES_USERNAME,
|
||||
port: process.env.POSTGRES_PORT,
|
||||
password: process.env.POSTGRES_PASSWORD,
|
||||
database: process.env.POSTGRES_DATABASE
|
||||
},
|
||||
searchPath: ['public'],
|
||||
pool: { min: 0, max: 20 },
|
||||
migrations: {
|
||||
directory: '../../packages/backend/src/db/migrations/',
|
||||
extension: fileExtension,
|
||||
loadExtensions: [`.${fileExtension}`],
|
||||
},
|
||||
seeds: {
|
||||
directory: '../../packages/backend/src/db/seeds',
|
||||
},
|
||||
...(process.env.APP_ENV === 'test' ? knexSnakeCaseMappers() : {}),
|
||||
};
|
||||
|
||||
export default knexConfig;
|
@@ -45,6 +45,11 @@ module.exports = defineConfig({
|
||||
{
|
||||
name: 'setup',
|
||||
testMatch: /.*\.setup\.js/,
|
||||
teardown: 'teardown',
|
||||
},
|
||||
{
|
||||
name: 'teardown',
|
||||
testMatch: /.*\.teardown\.js/,
|
||||
},
|
||||
{
|
||||
name: 'chromium',
|
||||
|
@@ -1,8 +1,6 @@
|
||||
const { publicTest: setup, expect } = require('../../fixtures/index');
|
||||
|
||||
setup.describe.serial('Admin setup page', () => {
|
||||
setup.skip(!process.env.CI);
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
setup('should not be able to login if admin is not created', async ({ page, adminSetupPage, loginPage }) => {
|
||||
await expect(async () => {
|
||||
|
12
packages/e2e-tests/tests/global.teardown.js
Normal file
12
packages/e2e-tests/tests/global.teardown.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const { publicTest } = require('../fixtures');
|
||||
import knex from 'knex';
|
||||
import knexConfig from '../knexfile.js';
|
||||
|
||||
publicTest.describe('restore db', () => {
|
||||
publicTest('clean db and perform migrations', async () => {
|
||||
const knexClient = knex(knexConfig)
|
||||
const migrator = knexClient.migrate;
|
||||
await migrator.rollback({}, true);
|
||||
await migrator.latest();
|
||||
})
|
||||
});
|
Reference in New Issue
Block a user