Skip to content

Commit

Permalink
fix(test): specify filepath function
Browse files Browse the repository at this point in the history
  • Loading branch information
stayradiated committed Jan 10, 2021
1 parent fcdfea9 commit 7ec0dd5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/shim/ava-babel.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
import { mockWithContext } from 'unwire'
import * as pkgConf from 'pkg-conf'
import { Config } from 'pkg-conf'
import readPkgUp from 'read-pkg-up'

import { SRC_PATH } from '../shared/constants'

import getConfig from '../config/ava-babel'

const start = async () => {
const config = await getConfig()
const filepath = readPkgUp.sync().path

mockWithContext('pkg-conf', require.resolve('ava/cli'), () => ({
sync: (pkgName: string, opts: object) => {
if (pkgName === 'ava') {
return config
}
return pkgConf.sync(pkgName, opts)
},
filepath: () => SRC_PATH,
filepath: (c: Config) => {
if (c === config) {
return filepath
}
return pkgConf.filepath(c)
},
}))

return require('ava/cli')
Expand Down
10 changes: 9 additions & 1 deletion src/shim/ava-tsc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { mockWithContext } from 'unwire'
import * as pkgConf from 'pkg-conf'
import { Config } from 'pkg-conf'
import readPkgUp from 'read-pkg-up'

import { SRC_PATH } from '../shared/constants'

Expand All @@ -9,6 +11,7 @@ console.log('Using AVA with ts-node')

const start = async () => {
const avaConfig = await getAVAConfig()
const filepath = readPkgUp.sync().path

mockWithContext('pkg-conf', require.resolve('ava/cli'), () => ({
sync: (pkgName: string, opts: object) => {
Expand All @@ -17,7 +20,12 @@ const start = async () => {
}
return pkgConf.sync(pkgName, opts)
},
filepath: () => SRC_PATH,
filepath: (c: Config) => {
if (c === avaConfig) {
return filepath
}
return pkgConf.filepath(c)
},
}))

return require('ava/cli')
Expand Down

0 comments on commit 7ec0dd5

Please sign in to comment.