Skip to content

Commit

Permalink
feat: add fakerjs
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jun 20, 2020
1 parent d494f13 commit fe0febe
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 31 deletions.
14 changes: 2 additions & 12 deletions adonis-typings/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

declare module '@ioc:Adonis/Lucid/Factory' {
import faker from 'faker'
import { OneOrMany } from '@ioc:Adonis/Lucid/DatabaseQueryBuilder'
import { TransactionClientContract } from '@ioc:Adonis/Lucid/Database'
import { LucidRow, LucidModel, ModelAttributes } from '@ioc:Adonis/Lucid/Model'
Expand Down Expand Up @@ -98,18 +99,7 @@ declare module '@ioc:Adonis/Lucid/Factory' {
* as well.
*/
export interface FactoryContextContract {
faker: {
lorem: {
sentence (count?: number): string,
},
internet: {
password (): string,
},
},
sequence: {
username: string,
email: string,
},
faker: typeof faker,
isStubbed: boolean,
$trx: TransactionClientContract | undefined
}
Expand Down
4 changes: 2 additions & 2 deletions example/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ User.create({ id: '1', username: 'virk' })
User.create({ id: '1', username: 'virk' })
User.create({ id: '1' })

const F = Factory.define(User, (state) => {
const F = Factory.define(User, ({ faker }) => {
return {
username: state.sequence.username,
username: faker.internet.userName(),
}
})

Expand Down
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@
"dependencies": {
"@poppinss/hooks": "^1.0.5",
"@poppinss/utils": "^2.2.6",
"@types/faker": "^4.1.12",
"cli-table3": "^0.6.0",
"fast-deep-equal": "^3.1.1",
"faker": "^4.1.0",
"kleur": "^3.0.3",
"knex": "^0.21.1",
"knex-dynamic-connection": "^1.0.5",
Expand Down
18 changes: 1 addition & 17 deletions src/Factory/FactoryContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,7 @@ import { FactoryContextContract } from '@ioc:Adonis/Lucid/Factory'
import { TransactionClientContract } from '@ioc:Adonis/Lucid/Database'

export class FactoryContext implements FactoryContextContract {
public faker = {
lorem: {
sentence (_?: number): string {
return ''
},
},
internet: {
password () {
return ''
},
},
}

public sequence = {
username: 'string',
email: 'string',
}
public faker = {}

constructor (
public isStubbed: boolean,
Expand Down

0 comments on commit fe0febe

Please sign in to comment.