Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: create dedicated sqlite db for each test suite #1066

Merged
merged 1 commit into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions test/data/typeorm/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
} from '../../../src';
import { createDataSourceOptions } from './factory';

export async function setupTestDatabase() : Promise<DataSource> {
export async function setupFsDataSource(name: string) : Promise<DataSource> {
const options = createDataSourceOptions();
Object.assign(options, {
database: 'test/data/typeorm/db.sqlite',
database: `writable/${name}.sqlite`,
});

await createDatabase({
Expand All @@ -25,7 +25,7 @@ export async function setupTestDatabase() : Promise<DataSource> {
return dataSource;
}

export async function destroyTestDatabase(dataSource: DataSource) {
export async function destroyTestFsDataSource(dataSource: DataSource) {
await dataSource.destroy();

const { options } = dataSource;
Expand Down
6 changes: 3 additions & 3 deletions test/unit/seeder/factory.spec.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
6 changes: 3 additions & 3 deletions test/unit/seeder/seeder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ 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';

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 () => {
Expand Down
3 changes: 3 additions & 0 deletions writable/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
*/
!.gitignore
Loading