Skip to content

Commit

Permalink
feat: inclide local dependenciies in test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Apr 20, 2021
1 parent c5f79e8 commit 6260392
Show file tree
Hide file tree
Showing 2 changed files with 254 additions and 27 deletions.
12 changes: 11 additions & 1 deletion core/instrument/src/babel/extract-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,17 @@ const componentRelatedMetrics = async (
);
}
if (jest !== false && component.request) {
const testResults = await extractTests([component.request], jest);
const componetFolder = path.dirname(component.request);
const dependents = component.localDependencies
? Object.keys(component.localDependencies)
.filter(f => f.startsWith(`.${path.sep}`))
.map(f => path.resolve(componetFolder, f))
: [];
console.log(dependents);
const testResults = await extractTests(
[component.request, ...dependents],
jest,
);
if (testResults) {
component.jest = testResults;
}
Expand Down
269 changes: 243 additions & 26 deletions core/instrument/test/jest-tests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,208 @@ describe('component-tests', () => {
beforeAll(() => {
setLogOptions({ logLevel: 'none' });
});
it('Catalog', async () => {
it('Table', async () => {
const tests = await extractTests([
path.resolve(__dirname, '../../../ui/components/src/Table/Table.tsx'),
path.resolve(
__dirname,
'../../../plugins/addon-catalog/src/Catalog/Catalog.tsx',
'../../../ui/components/src/Table/TableFilter.tsx',
),
path.resolve(
__dirname,
'../../../ui/components/src/Table/TableGrouping.tsx',
),
path.resolve(
__dirname,
'../../../ui/components/src/Table/TablePagination.tsx',
),
path.resolve(
__dirname,
'../../../ui/components/src/Table/TableRowSelection.tsx',
),
path.resolve(
__dirname,
'../../../ui/components/src/Table/useTableLayout.ts',
),
]);
expect(tests).toMatchObject({
results: [
{
leaks: false,
testFilePath: 'Catalog.test.ts',
testFilePath: 'Table.test.ts',
testResults: [
{
ancestorTitles: ['Catalog'],
ancestorTitles: ['Table'],
failureDetails: [],
failureMessages: [],
fullName: 'Catalog overview',
fullName: 'Table overview',
location: null,
numPassingAsserts: 0,
status: 'passed',
title: 'overview',
},
{
ancestorTitles: ['Table'],
failureDetails: [],
failureMessages: [],
fullName: 'Table noHeader',
location: null,
numPassingAsserts: 0,
status: 'passed',
title: 'noHeader',
},
{
ancestorTitles: ['Table'],
failureDetails: [],
failureMessages: [],
fullName: 'Table sortable',
location: null,
numPassingAsserts: 0,
status: 'passed',
title: 'sortable',
},
{
ancestorTitles: ['Table'],
failureDetails: [],
failureMessages: [],
fullName: 'Table filterable',
location: null,
numPassingAsserts: 0,
status: 'passed',
title: 'filterable',
},
{
ancestorTitles: ['Table'],
failureDetails: [],
failureMessages: [],
fullName: 'Table grouping',
location: null,
numPassingAsserts: 0,
status: 'passed',
title: 'grouping',
},
{
ancestorTitles: ['Table'],
failureDetails: [],
failureMessages: [],
fullName: 'Table editing',
numPassingAsserts: 0,
status: 'passed',
title: 'editing',
},
{
ancestorTitles: ['Table'],
failureDetails: [],
failureMessages: [],
fullName: 'Table rowSelect',
location: null,
numPassingAsserts: 0,
status: 'passed',
title: 'rowSelect',
},
{
ancestorTitles: ['Table'],
failureDetails: [],
failureMessages: [],
fullName: 'Table pagination',
location: null,
numPassingAsserts: 0,
status: 'passed',
title: 'pagination',
},
],
},
],
coverage: {
'Catalog.tsx': {
'Table.tsx': {
lines: {
total: 9,
covered: 9,
total: 51,
covered: 50,
skipped: 0,
pct: 100,
pct: 98.04,
},
functions: {
total: 1,
total: 10,
covered: 7,
skipped: 0,
pct: 70,
},
statements: {
total: 56,
covered: 55,
skipped: 0,
pct: 98.21,
},
branches: {
total: 49,
covered: 40,
skipped: 0,
pct: 81.63,
},
},
'TableFilter.tsx': {
lines: {
total: 6,
covered: 5,
skipped: 0,
pct: 83.33,
},
functions: {
total: 2,
covered: 1,
skipped: 0,
pct: 50,
},
statements: {
total: 6,
covered: 5,
skipped: 0,
pct: 83.33,
},
branches: {
total: 4,
covered: 1,
skipped: 0,
pct: 25,
},
},
'TableGrouping.tsx': {
lines: {
total: 20,
covered: 19,
skipped: 0,
pct: 95,
},
functions: {
total: 8,
covered: 8,
skipped: 0,
pct: 100,
},
statements: {
total: 21,
covered: 20,
skipped: 0,
pct: 95.24,
},
branches: {
total: 20,
covered: 15,
skipped: 0,
pct: 75,
},
},
'TableRowSelection.tsx': {
lines: {
total: 8,
covered: 8,
skipped: 0,
pct: 100,
},
functions: {
total: 5,
covered: 5,
skipped: 0,
pct: 100,
},
statements: {
Expand All @@ -59,27 +223,80 @@ describe('component-tests', () => {
pct: 100,
},
},
'useTableLayout.ts': {
lines: {
total: 7,
covered: 7,
skipped: 0,
pct: 100,
},
functions: {
total: 3,
covered: 3,
skipped: 0,
pct: 100,
},
statements: {
total: 8,
covered: 8,
skipped: 0,
pct: 100,
},
branches: {
total: 4,
covered: 4,
skipped: 0,
pct: 100,
},
},
'TablePagination.tsx': {
lines: {
total: 17,
covered: 9,
skipped: 0,
pct: 52.94,
},
functions: {
total: 10,
covered: 3,
skipped: 0,
pct: 30,
},
statements: {
total: 18,
covered: 10,
skipped: 0,
pct: 55.56,
},
branches: {
total: 24,
covered: 8,
skipped: 0,
pct: 33.33,
},
},
},
});
}, 100000);
it('ComponentCard', async () => {

it('Catalog', async () => {
const tests = await extractTests([
path.resolve(
__dirname,
'../../../plugins/addon-catalog/src/ComponentCard/ComponentCard.tsx',
'../../../plugins/addon-catalog/src/Catalog/Catalog.tsx',
),
]);
expect(tests).toMatchObject({
results: [
{
leaks: false,
testFilePath: 'ComponentCard.test.ts',
testFilePath: 'Catalog.test.ts',
testResults: [
{
ancestorTitles: ['ComponentCard'],
ancestorTitles: ['Catalog'],
failureDetails: [],
failureMessages: [],
fullName: 'ComponentCard overview',
fullName: 'Catalog overview',
location: null,
numPassingAsserts: 0,
status: 'passed',
Expand All @@ -89,12 +306,12 @@ describe('component-tests', () => {
},
],
coverage: {
'ComponentCard.tsx': {
'Catalog.tsx': {
lines: {
total: 20,
covered: 19,
total: 9,
covered: 9,
skipped: 0,
pct: 95,
pct: 100,
},
functions: {
total: 1,
Expand All @@ -103,22 +320,22 @@ describe('component-tests', () => {
pct: 100,
},
statements: {
total: 21,
covered: 20,
total: 10,
covered: 10,
skipped: 0,
pct: 95.24,
pct: 100,
},
branches: {
total: 44,
covered: 25,
total: 0,
covered: 0,
skipped: 0,
pct: 56.82,
pct: 100,
},
},
},
});
}, 100000);
it('ComponentCard', async () => {
it('Header', async () => {
const tests = await extractTests([
path.resolve(__dirname, '../../../ui/components/src/Header/Header.tsx'),
]);
Expand Down

0 comments on commit 6260392

Please sign in to comment.