Skip to content

Commit

Permalink
feat: allow to pass custom locale for faker
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-R44 committed Sep 20, 2022
1 parent ff174c7 commit eba90d0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bin/test.ts
Expand Up @@ -26,7 +26,7 @@ configure({
files: ['tests/**/*.spec.ts'],
plugins: [
database({ database: connectionConfig }),
factorio({ database: connectionConfig }),
factorio({ database: connectionConfig, locale: 'fr' }),
expect(),
],
reporters: [specReporter({ stackLinesCount: 2 })],
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/config.ts
@@ -1,4 +1,6 @@
import knex from 'knex'
import { faker } from '@faker-js/faker'
import type { UsableLocale } from '@faker-js/faker'
import type { Knex } from 'knex'
import type { FactorioConfig } from './contracts'

Expand All @@ -14,7 +16,9 @@ export const factorioConfig = {
*
* Returns a function that can be used to clean up the connection.
*/
export const defineFactorioConfig = (options: FactorioConfig) => {
export const defineFactorioConfig = (options: FactorioConfig & { locale?: UsableLocale }) => {
faker.locale = options.locale || faker.locale

factorioConfig.knex = knex(options.database)

return () => {
Expand Down
5 changes: 2 additions & 3 deletions packages/japa-plugin/src/index.ts
@@ -1,9 +1,8 @@
import { defineFactorioConfig } from '@julr/factorio'
import type { Knex } from 'knex'
import type { PluginFn } from '@japa/runner'

export function factorio({ database }: { database: Knex.Config }): PluginFn {
const disconnect = defineFactorioConfig({ database })
export function factorio(options: Parameters<typeof defineFactorioConfig>[0]): PluginFn {
const disconnect = defineFactorioConfig(options)

return async function (config) {
config.teardown.push(disconnect)
Expand Down

0 comments on commit eba90d0

Please sign in to comment.