Only require db when necessary

This commit is contained in:
Julia Friesel
2018-06-11 15:04:20 +02:00
parent 9922b2e7b8
commit 05ea9b3ce2
+7 -2
View File
@@ -1,10 +1,15 @@
import * as joda from 'js-joda' import * as joda from 'js-joda'
import { bleedingDaysSortedByDate as bleedingDaysSortedByDateView} from './db'
const LocalDate = joda.LocalDate const LocalDate = joda.LocalDate
export default function config(opts = {}) { export default function config(opts = {}) {
const bleedingDaysSortedByDate = opts.bleedingDaysSortedByDate || bleedingDaysSortedByDateView let bleedingDaysSortedByDate
if (!opts.bleedingDaysSortedByDate) {
// we only want to require (and run) the db module when not running the tests
bleedingDaysSortedByDate = require('./db').bleedingDaysSortedByDate
} else {
bleedingDaysSortedByDate = opts.bleedingDaysSortedByDate
}
const maxBreakInBleeding = opts.maxBreakInBleeding || 1 const maxBreakInBleeding = opts.maxBreakInBleeding || 1
return function getCycleDayNumber(targetDateString) { return function getCycleDayNumber(targetDateString) {