Skip to content

Commit

Permalink
Better logging + Optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu2301 committed Jul 20, 2023
1 parent ac66561 commit db64076
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ tests/
*.log
.env
tsconfig.json
*.config.ts
16 changes: 9 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ const enabled = Object.values(agents).some((agent) => agent);
export default class CustomReporter implements Reporter {
private outputFile: string;

onInit(ctx: Vitest): void {
async onInit(ctx: Vitest) {
if (!enabled) return;

console.log('Custom reporter enabled. Using these agents:');
for (const [agent, available] of Object.entries(agents)) {
if (available) console.log(` - ${agent}`);
}

this.outputFile = (typeof ctx.config.outputFile === 'string'
? ctx.config.outputFile
: ctx.config.outputFile?.html
Expand All @@ -42,9 +47,9 @@ export default class CustomReporter implements Reporter {
fs.rmSync(this.outputFile, { recursive: true, force: true });
} else console.log('HTML reporter not enabled.');

console.log('Custom reporter enabled. Using these agents:');
for (const [agent, available] of Object.entries(agents)) {
if (available) console.log(` - ${agent}`);
if (notionAvailable) {
console.log('Setting up Notion database...');
await setupNotionDatabases();
}
}

Expand All @@ -57,9 +62,6 @@ export default class CustomReporter implements Reporter {
let changes: Changes | undefined;

if (notionAvailable) {
console.log('Setting up Notion database...');
await setupNotionDatabases();

console.log('Updating Notion database...');
changes = await updateNotionTestsDB(files);
} else console.log('No Notion config provided. Skipping update.');
Expand Down
4 changes: 3 additions & 1 deletion src/notion/NotionDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ export default class NotionDatabase<RequiredProps extends RequiredProperties> {
]) => {
if (!tablePropsTypes[propName]) return {
propName: propName,
requiredType: requiredPropType,
issue: 'missing',
};

Expand All @@ -371,6 +372,7 @@ export default class NotionDatabase<RequiredProps extends RequiredProperties> {
}).filter((issue) => issue !== null) as (
{
propName: PropertyName<RequiredProps>;
requiredType: PropertyType<RequiredProps>;
issue: 'missing';
} | {
propName: PropertyName<RequiredProps>;
Expand All @@ -384,7 +386,7 @@ export default class NotionDatabase<RequiredProps extends RequiredProperties> {
logger.error([
' Invalid schema:',
...issues.map((issue) => {
if (issue.issue === 'missing') return ` - Missing property '${issue.propName}'`;
if (issue.issue === 'missing') return ` - Missing property '${issue.propName}' (type: ${issue.requiredType}))`;
return ` - Invalid type for property '${issue.propName}': expected '${issue.requiredType}', got '${issue.propType}'`;
}),
].join('\n'));
Expand Down

0 comments on commit db64076

Please sign in to comment.