Skip to content

Commit

Permalink
fix: avoid running tests if nonoe for story/component
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed May 11, 2021
1 parent d5fa3bd commit 3066920
Showing 1 changed file with 38 additions and 36 deletions.
74 changes: 38 additions & 36 deletions core/instrument/src/babel/extract-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,44 +200,46 @@ const componentRelatedMetrics = async (
return found;
})
: [...getRelatedTests(component.request), ...getRelatedTests(filePath)];
const docCoverageFiles = store.doc?.testCoverage;
const coverageFiles: string[] = docCoverageFiles
? docCoverageFiles
.map(f => path.resolve(filePath, f))
.filter(f => {
const found = fs.existsSync(f);
if (!found) {
error('testCoverage file', f);
if (testFiles.length) {
const docCoverageFiles = store.doc?.testCoverage;
const coverageFiles: string[] = docCoverageFiles
? docCoverageFiles
.map(f => path.resolve(filePath, f))
.filter(f => {
const found = fs.existsSync(f);
if (!found) {
error('testCoverage file', f);
}
return found;
})
: [component.request];
//add local dependencies 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)) {
if (!docTestFiles) {
testFiles.push(fileName);
}
if (!docCoverageFiles) {
coverageFiles.push(fileName);
}
}
return found;
})
: [component.request];
//add local dependencies 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)) {
if (!docTestFiles) {
testFiles.push(fileName);
}
if (!docCoverageFiles) {
coverageFiles.push(fileName);
}
}
});
}
const testResults = await extractTests(
Array.from(new Set(testFiles)),
Array.from(new Set(coverageFiles)),
jest,
);
if (testResults) {
component.jest = testResults;
}
const testResults = await extractTests(
Array.from(new Set(testFiles)),
Array.from(new Set(coverageFiles)),
jest,
);
if (testResults) {
component.jest = testResults;
}
}
}
};
Expand Down

0 comments on commit 3066920

Please sign in to comment.