forked from w3tecch/typeorm-seeding
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
870a23d
commit a1d4e27
Showing
9 changed files
with
66 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export * from './connection' | ||
export * from './runSeeder' | ||
export * from './factory' | ||
export * from './seeder' | ||
export * from './types' | ||
export * from './useSeeders' |
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
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,8 @@ | ||
import { Seeder } from '../../src' | ||
import { UserFactory } from '../factories/User.factory' | ||
|
||
export class UserSeeder extends Seeder { | ||
async run() { | ||
await new UserFactory().createMany(10) | ||
} | ||
} |
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,12 @@ | ||
import { useSeeders } from '../../src' | ||
import { SeederImportationError } from '../../src/errors/SeederImportationError' | ||
|
||
describe(useSeeders, () => { | ||
test.only(`Should throw ${SeederImportationError.name}`, async () => { | ||
jest.mock('../seeders/User.seeder.ts', () => { | ||
throw new Error('Error') | ||
}) | ||
|
||
expect(useSeeders()).rejects.toThrowError(SeederImportationError) | ||
}) | ||
}) |
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,11 @@ | ||
import { useSeeders } from '../../src/useSeeders' | ||
|
||
describe(useSeeders, () => { | ||
test('Should import all seeders', async () => { | ||
const seeders = await useSeeders() | ||
|
||
expect(seeders).toHaveLength(1) | ||
expect(seeders[0].constructor.name).toBe('UserSeeder') | ||
}) | ||
}) | ||
|
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,23 @@ | ||
import { useSeeders } from '../../src/useSeeders' | ||
import { Seeder } from '../../src/seeder' | ||
|
||
describe(useSeeders, () => { | ||
const mockFn = jest.fn() | ||
|
||
test('Should import one seeder and execute it', async () => { | ||
jest.mock('../seeders/User.seeder.ts', () => { | ||
return { | ||
__esModule: true, | ||
default: class Test extends Seeder { | ||
async run() { | ||
mockFn() | ||
} | ||
}, | ||
} | ||
}) | ||
const seeders = await useSeeders(true, ['test/**/User.seeder.ts']) | ||
|
||
expect(seeders).toHaveLength(1) | ||
expect(mockFn).toHaveBeenCalledTimes(1) | ||
}) | ||
}) |