Skip to content

Commit

Permalink
chore: remove all faker usages from source folder
Browse files Browse the repository at this point in the history
BREAKING CHANGE Faker is not available anymore as function param
  • Loading branch information
jorgebodega committed Jan 6, 2022
1 parent 40f21c8 commit 1e14718
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isPromiseLike } from './utils/isPromiseLike'

export abstract class Factory<Entity> {
private mapFunction?: (entity: Entity) => void
protected abstract definition(faker: typeof Faker): Entity
protected abstract definition(): Entity

/**
* This function is used to alter the generated values of entity, before it
Expand Down Expand Up @@ -56,7 +56,7 @@ export abstract class Factory<Entity> {
}

private async makeEntity(overrideParams: Partial<Entity>, isSeeding: boolean) {
const entity = this.definition(Faker)
const entity = this.definition()

if (this.mapFunction) this.mapFunction(entity)

Expand Down
14 changes: 1 addition & 13 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
import * as Faker from 'faker'
import { ConnectionOptions as TypeORMConnectionOptions, ObjectType } from 'typeorm'
import { Factory } from './factory'

/**
* FactoryFunction is the function, which generate a new filled entity
*/
export type FactoryFunction<Entity> = (faker: typeof Faker) => Entity

/**
* Factory gets the EntityFactory to the given Entity and pass the context along
*/
export type EntityFactory = <Entity>(entity: ObjectType<Entity>) => Factory<Entity>
import type { ConnectionOptions as TypeORMConnectionOptions } from 'typeorm'

/**
* Constructor of the seed class
Expand Down
4 changes: 2 additions & 2 deletions test/factories/Pet.factory.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as Faker from 'faker'
import * as faker from 'faker'
import { Factory } from '../../src/factory'
import { Pet } from '../entities/Pet.entity'
import { UserFactory } from './User.factory'

export class PetFactory extends Factory<Pet> {
protected definition(faker: typeof Faker): Pet {
protected definition(): Pet {
const pet = new Pet()

pet.name = faker.name.findName()
Expand Down
4 changes: 2 additions & 2 deletions test/factories/User.factory.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as Faker from 'faker'
import * as faker from 'faker'
import { Factory } from '../../src/factory'
import { User } from '../entities/User.entity'

export class UserFactory extends Factory<User> {
protected definition(faker: typeof Faker): User {
protected definition(): User {
const user = new User()

user.name = faker.name.findName()
Expand Down
2 changes: 0 additions & 2 deletions test/jest-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,3 @@ jest.mock('../ormconfig.ts', () => [
seeds: ['test/seeders/**/*.seed.ts'],
},
])

process.on('unhandledRejection', () => void 0)

0 comments on commit 1e14718

Please sign in to comment.