Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny-Robinson committed Oct 12, 2020
1 parent bc745c6 commit 14254a2
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions tests/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,21 @@ describe('components', () => {
});
});

it('should all be exported from the index file', () => {
it('should all be exported from the index file with their props', () => {
components.forEach(filePath => {
const content = fs.readFileSync(filePath, UTF8);

const defaultExport = MATCHES_DEFAULT_EXPORT.exec(content);

if (!defaultExport) {
throw new Error(`No default export in component at ${filePath}`);
}

if (!fs.existsSync(INDEX_FILE_PATH)) {
throw new Error(`Could not find index file at ${INDEX_FILE_PATH}`);
}

const indexContent = fs.readFileSync(INDEX_FILE_PATH, UTF8);

const indexRegex = new RegExp(
`^export\\s+{\\s+default\\s+as\\s+${defaultExport[1]},?\\s+}\\s+from\\s+'[a-z/.-]+';$`,
`^export\\s+{\\s+default\\s+as\\s+${defaultExport[1]},?\\s+${defaultExport[1]}Props,?\\s+}\\s+from\\s+'[a-z/.-]+';$`,
'm'
);

if (!indexRegex.test(indexContent)) {
throw new Error(
`Component ${defaultExport[1]} is not exported from default at ${INDEX_FILE_PATH}`
Expand Down

0 comments on commit 14254a2

Please sign in to comment.