diff --git a/jest.config.js b/jest.config.js index 6eaa59da9..a27374193 100644 --- a/jest.config.js +++ b/jest.config.js @@ -7,6 +7,5 @@ module.exports = { transform: { '^.+\\.ts$': 'ts-jest' }, - verbose: true, - setupFilesAfterEnv: [`./jest/test.ts`] + verbose: true }; diff --git a/jest/test.ts b/jest/test.ts deleted file mode 100644 index d6dd801e9..000000000 --- a/jest/test.ts +++ /dev/null @@ -1,9 +0,0 @@ -// Disabled the colors to: -// - improve the performances -// - avoid to mock styles -// - avoid to have failing tests when testing the logs due to the extra text the log message will contains -// -// Note: -// If you need to debug the log colours you can remove this line temporarily -// But some tests will fail -jest.mock('ansi-styles'); diff --git a/src/classes/loggers/issue-logger.spec.ts b/src/classes/loggers/issue-logger.spec.ts index 2ff48350d..5c0f615eb 100644 --- a/src/classes/loggers/issue-logger.spec.ts +++ b/src/classes/loggers/issue-logger.spec.ts @@ -26,12 +26,17 @@ describe('IssueLogger', (): void => { }); it('should log a warning with the given message and with the issue number as prefix', (): void => { - expect.assertions(2); + expect.assertions(3); issueLogger.warning(message); expect(coreWarningSpy).toHaveBeenCalledTimes(1); - expect(coreWarningSpy).toHaveBeenCalledWith('[#8] dummy-message'); + expect(coreWarningSpy).toHaveBeenCalledWith( + expect.stringContaining('[#8]') + ); + expect(coreWarningSpy).toHaveBeenCalledWith( + expect.stringContaining('dummy-message') + ); }); }); @@ -52,12 +57,15 @@ describe('IssueLogger', (): void => { }); it('should log an information with the given message and with the issue number as prefix', (): void => { - expect.assertions(2); + expect.assertions(3); issueLogger.info(message); expect(coreInfoSpy).toHaveBeenCalledTimes(1); - expect(coreInfoSpy).toHaveBeenCalledWith('[#8] dummy-message'); + expect(coreInfoSpy).toHaveBeenCalledWith(expect.stringContaining('[#8]')); + expect(coreInfoSpy).toHaveBeenCalledWith( + expect.stringContaining('dummy-message') + ); }); }); @@ -78,17 +86,22 @@ describe('IssueLogger', (): void => { }); it('should log an error with the given message and with the issue number as prefix', (): void => { - expect.assertions(2); + expect.assertions(3); issueLogger.error(message); expect(coreErrorSpy).toHaveBeenCalledTimes(1); - expect(coreErrorSpy).toHaveBeenCalledWith('[#8] dummy-message'); + expect(coreErrorSpy).toHaveBeenCalledWith( + expect.stringContaining('[#8]') + ); + expect(coreErrorSpy).toHaveBeenCalledWith( + expect.stringContaining('dummy-message') + ); }); }); it('should prefix the message with the issue number', (): void => { - expect.assertions(2); + expect.assertions(3); message = 'dummy-message'; issue = new Issue( DefaultProcessorOptions, @@ -102,7 +115,12 @@ describe('IssueLogger', (): void => { issueLogger.warning(message); expect(coreWarningSpy).toHaveBeenCalledTimes(1); - expect(coreWarningSpy).toHaveBeenCalledWith('[#123] dummy-message'); + expect(coreWarningSpy).toHaveBeenCalledWith( + expect.stringContaining('[#123]') + ); + expect(coreWarningSpy).toHaveBeenCalledWith( + expect.stringContaining('dummy-message') + ); }); it.each` @@ -114,7 +132,7 @@ describe('IssueLogger', (): void => { `( 'should replace the special tokens "$$type" with the corresponding type', ({pull_request, replacement}): void => { - expect.assertions(2); + expect.assertions(3); message = 'The $$type will stale! $$type will soon be closed!'; issue = new Issue( DefaultProcessorOptions, @@ -130,7 +148,12 @@ describe('IssueLogger', (): void => { expect(coreWarningSpy).toHaveBeenCalledTimes(1); expect(coreWarningSpy).toHaveBeenCalledWith( - `[#8] The ${replacement} will stale! ${replacement} will soon be closed!` + expect.stringContaining(`[#8]`) + ); + expect(coreWarningSpy).toHaveBeenCalledWith( + expect.stringContaining( + `The ${replacement} will stale! ${replacement} will soon be closed!` + ) ); } ); @@ -144,7 +167,7 @@ describe('IssueLogger', (): void => { `( 'should replace the special token "$$type" with the corresponding type with first letter as uppercase', ({pull_request, replacement}): void => { - expect.assertions(2); + expect.assertions(3); message = '$$type will stale'; issue = new Issue( DefaultProcessorOptions, @@ -160,7 +183,10 @@ describe('IssueLogger', (): void => { expect(coreWarningSpy).toHaveBeenCalledTimes(1); expect(coreWarningSpy).toHaveBeenCalledWith( - `[#8] ${replacement} will stale` + expect.stringContaining(`[#8]`) + ); + expect(coreWarningSpy).toHaveBeenCalledWith( + expect.stringContaining(`${replacement} will stale`) ); } ); diff --git a/src/classes/loggers/logger.spec.ts b/src/classes/loggers/logger.spec.ts index f36d5a94d..8a36bf54e 100644 --- a/src/classes/loggers/logger.spec.ts +++ b/src/classes/loggers/logger.spec.ts @@ -25,7 +25,9 @@ describe('Logger', (): void => { logger.warning(message); expect(coreWarningSpy).toHaveBeenCalledTimes(1); - expect(coreWarningSpy).toHaveBeenCalledWith('dummy-message'); + expect(coreWarningSpy).toHaveBeenCalledWith( + expect.stringContaining('dummy-message') + ); }); }); @@ -46,7 +48,9 @@ describe('Logger', (): void => { logger.info(message); expect(coreInfoSpy).toHaveBeenCalledTimes(1); - expect(coreInfoSpy).toHaveBeenCalledWith('dummy-message'); + expect(coreInfoSpy).toHaveBeenCalledWith( + expect.stringContaining('dummy-message') + ); }); }); @@ -67,7 +71,9 @@ describe('Logger', (): void => { logger.error(message); expect(coreErrorSpy).toHaveBeenCalledTimes(1); - expect(coreErrorSpy).toHaveBeenCalledWith('dummy-message'); + expect(coreErrorSpy).toHaveBeenCalledWith( + expect.stringContaining('dummy-message') + ); }); }); }); diff --git a/tsconfig.app.json b/tsconfig.app.json index 0a2600f31..2b5d80c1f 100644 --- a/tsconfig.app.json +++ b/tsconfig.app.json @@ -1,5 +1,5 @@ { "extends": "./tsconfig.json", - "exclude": ["node_modules", "**/*.spec.ts", "jest"], + "exclude": ["node_modules", "**/*.spec.ts"], "include": ["src"] } diff --git a/tsconfig.json b/tsconfig.json index a0af4f6fb..ed2e7fe08 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,5 +8,5 @@ "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ //"sourceMap": true }, - "include": ["src", "__tests__", "jest"] + "include": ["src", "__tests__"] } diff --git a/tsconfig.spec.json b/tsconfig.spec.json index 91eeec039..14f9e85f3 100644 --- a/tsconfig.spec.json +++ b/tsconfig.spec.json @@ -1,5 +1,5 @@ { "extends": "./tsconfig.json", - "include": ["src", "__tests__", "jest"], + "include": ["src", "__tests__"], "exclude": ["node_modules"] }