From 7ec0dd5bf66ddbea5694e295bdeb0a47cfc86c0f Mon Sep 17 00:00:00 2001 From: George Czabania <1140167+stayradiated@users.noreply.github.com> Date: Sun, 10 Jan 2021 18:21:29 +1300 Subject: [PATCH] fix(test): specify filepath function --- src/shim/ava-babel.ts | 11 ++++++++++- src/shim/ava-tsc.ts | 10 +++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/shim/ava-babel.ts b/src/shim/ava-babel.ts index 8443dba..6948626 100644 --- a/src/shim/ava-babel.ts +++ b/src/shim/ava-babel.ts @@ -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' @@ -7,6 +9,8 @@ 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') { @@ -14,7 +18,12 @@ const start = async () => { } return pkgConf.sync(pkgName, opts) }, - filepath: () => SRC_PATH, + filepath: (c: Config) => { + if (c === config) { + return filepath + } + return pkgConf.filepath(c) + }, })) return require('ava/cli') diff --git a/src/shim/ava-tsc.ts b/src/shim/ava-tsc.ts index b0f0f9e..c8e72a6 100644 --- a/src/shim/ava-tsc.ts +++ b/src/shim/ava-tsc.ts @@ -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' @@ -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) => { @@ -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')