From 37c75d44240c33484ecffa69bdb9a20e06bc74e5 Mon Sep 17 00:00:00 2001 From: Peter Date: Sat, 27 Jul 2024 10:52:51 +0200 Subject: [PATCH] test: create dedicated sqlite db for each test suite (#1066) --- package.json | 2 +- test/data/typeorm/utils.ts | 6 +++--- test/unit/seeder/factory.spec.ts | 6 +++--- test/unit/seeder/seeder.spec.ts | 6 +++--- writable/.gitignore | 3 +++ 5 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 writable/.gitignore diff --git a/package.json b/package.json index d5fc736f..500cbf22 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "build:watch": "npm run build -- --watch", "commit": "npx git-cz", "test": "jest --config ./test/jest.config.js", - "test:coverage": "cross-env NODE_ENV=test jest --config ./test/jest.config.js --coverage --runInBand", + "test:coverage": "cross-env NODE_ENV=test jest --config ./test/jest.config.js --coverage", "lint": "eslint --ext .js,.vue,.ts ./src ./test", "lint:fix": "npm run lint -- --fix", "docs:dev": "vitepress dev docs --temp .temp", diff --git a/test/data/typeorm/utils.ts b/test/data/typeorm/utils.ts index 96c648ef..b40b4923 100644 --- a/test/data/typeorm/utils.ts +++ b/test/data/typeorm/utils.ts @@ -7,10 +7,10 @@ import { } from '../../../src'; import { createDataSourceOptions } from './factory'; -export async function setupTestDatabase() : Promise { +export async function setupFsDataSource(name: string) : Promise { const options = createDataSourceOptions(); Object.assign(options, { - database: 'test/data/typeorm/db.sqlite', + database: `writable/${name}.sqlite`, }); await createDatabase({ @@ -25,7 +25,7 @@ export async function setupTestDatabase() : Promise { return dataSource; } -export async function destroyTestDatabase(dataSource: DataSource) { +export async function destroyTestFsDataSource(dataSource: DataSource) { await dataSource.destroy(); const { options } = dataSource; diff --git a/test/unit/seeder/factory.spec.ts b/test/unit/seeder/factory.spec.ts index 65b5ccc0..3231555e 100644 --- a/test/unit/seeder/factory.spec.ts +++ b/test/unit/seeder/factory.spec.ts @@ -1,17 +1,17 @@ import type { DataSource } from 'typeorm'; import { useSeederFactory } from '../../../src'; import { User } from '../../data/entity/user'; -import { destroyTestDatabase, setupTestDatabase } from '../../data/typeorm/utils'; +import { destroyTestFsDataSource, setupFsDataSource } from '../../data/typeorm/utils'; import '../../data/factory/user'; describe('src/seeder/factory/index.ts', () => { let dataSource : DataSource; beforeEach(async () => { - dataSource = await setupTestDatabase(); + dataSource = await setupFsDataSource('factory'); }); afterEach(async () => { - await destroyTestDatabase(dataSource); + await destroyTestFsDataSource(dataSource); }); it('should create & save seed', async () => { diff --git a/test/unit/seeder/seeder.spec.ts b/test/unit/seeder/seeder.spec.ts index 567c3cc9..4c09af60 100644 --- a/test/unit/seeder/seeder.spec.ts +++ b/test/unit/seeder/seeder.spec.ts @@ -6,7 +6,7 @@ import { } from '../../../src'; import type { SeederEntity } from '../../../src'; import { User } from '../../data/entity/user'; -import { destroyTestDatabase, setupTestDatabase } from '../../data/typeorm/utils'; +import { destroyTestFsDataSource, setupFsDataSource } from '../../data/typeorm/utils'; import '../../data/factory/user'; import UserSeeder from '../../data/seed/user'; @@ -14,11 +14,11 @@ describe('src/seeder/index.ts', () => { let dataSource : DataSource; beforeEach(async () => { - dataSource = await setupTestDatabase(); + dataSource = await setupFsDataSource('seeder'); }); afterEach(async () => { - await destroyTestDatabase(dataSource); + await destroyTestFsDataSource(dataSource); }); it('should seed with data-source options', async () => { diff --git a/writable/.gitignore b/writable/.gitignore new file mode 100644 index 00000000..94548af5 --- /dev/null +++ b/writable/.gitignore @@ -0,0 +1,3 @@ +* +*/ +!.gitignore