Skip to content

Commit

Permalink
fix: local dependencies require
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Apr 20, 2021
1 parent f5ad1c8 commit 506b974
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions core/instrument/src/babel/extract-component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from 'path';
import fs from 'fs';
import * as resolve from 'resolve';
import {
Component,
Expand Down Expand Up @@ -149,7 +150,8 @@ const componentRelatedMetrics = async (
component: Component,
options?: InstrumentOptions,
) => {
const { components, propsLoaders = [], jest } = options || {};
const { components, resolver: resolveOptions, propsLoaders = [], jest } =
options || {};
const componentPackage = await packageInfo(
component.name,
component.request,
Expand Down Expand Up @@ -180,16 +182,23 @@ const componentRelatedMetrics = async (
);
}
if (jest !== false && component.request) {
const componetFolder = path.dirname(component.request);
const dependents = component.localDependencies
? Object.keys(component.localDependencies)
.filter(f => f.startsWith(`.${path.sep}`))
.map(f => require.resolve(f, { paths: [componetFolder] }))
: [];
const testResults = await extractTests(
[component.request, ...dependents],
jest,
);
const componentFolder = path.dirname(component.request);
const testFiles: string[] = [component.request];
//add local dependecnies from same folder to include in coverage.
if (component.localDependencies) {
Object.keys(component.localDependencies)
.filter(f => f.startsWith(`.${path.sep}`))
.forEach(f => {
const fileName = resolve.sync(f, {
...resolveOptions,
basedir: componentFolder,
});
if (fs.existsSync(fileName)) {
testFiles.push(fileName);
}
});
}
const testResults = await extractTests(testFiles, jest);
if (testResults) {
component.jest = testResults;
}
Expand All @@ -199,7 +208,7 @@ const componentRelatedMetrics = async (
export const extractStoreComponent = async (
store: LoadingDocStore,
filePath: string,
source: string,
source?: string,
options?: InstrumentOptions,
): Promise<void> => {
if (store.doc) {
Expand Down

0 comments on commit 506b974

Please sign in to comment.