Skip to content

Commit

Permalink
update generator.js and integration.test
Browse files Browse the repository at this point in the history
- generator.js: setLogLevel in the construction of the generator
- integration.test: use log.debug = jest.fn() and expect(log.debug)
  • Loading branch information
lmgyuan committed May 21, 2024
1 parent 5e49121 commit a23636a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ class Generator {
}
});
});
// PR 1162: set log level during construction to avoid asynchronous issues
this.setLogLevel();
}

/**
Expand Down Expand Up @@ -196,7 +198,8 @@ class Generator {
async generate(asyncapiDocument, parseOptions = {}) {
this.validateAsyncAPIDocument(asyncapiDocument);
await this.setupOutput();
this.setLogLevel();
// PR 1162: always set log level during construction to avoid asynchronous issues
// this.setLogLevel();

await this.installAndSetupTemplate();
await this.configureTemplateWorkflow(parseOptions);
Expand Down
7 changes: 4 additions & 3 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ describe('Integration testing generateFromFile() to make sure the result of the
});

it('should ignore specified files with noOverwriteGlobs', async () => {
const logSpyDebug = jest.spyOn(log, 'debug').mockImplementation(() => {});
// const logSpyDebug = jest.spyOn(log, 'debug').mockImplementation(() => {});
log.debug = jest.fn();

const outputDir = generateFolderName();
// Manually create a file to test if it's not overwritten
Expand All @@ -94,8 +95,8 @@ describe('Integration testing generateFromFile() to make sure the result of the
// Check if the files have been overwritten
await expect(fileContent).toBe(testContent);
// Check if the log debug message was printed
await expect(logSpyDebug).toHaveBeenCalledWith(`noOverwriteGlobs matched`);
await expect(logSpyDebug).toHaveBeenCalledWith(`Skipping overwrite for: ${testFilePath}`);
await expect(log.debug).toHaveBeenCalledWith(`noOverwriteGlobs matched`);
await expect(log.debug).toHaveBeenCalledWith(`Skipping overwrite for: ${testFilePath}`);
console.log('All console.log calls:');

// Print all console.log calls
Expand Down

0 comments on commit a23636a

Please sign in to comment.