diff --git a/packages/twenty-front/jest-failures-only-reporter.cjs b/packages/twenty-front/jest-failures-only-reporter.cjs new file mode 100644 index 0000000000..4b652da3e3 --- /dev/null +++ b/packages/twenty-front/jest-failures-only-reporter.cjs @@ -0,0 +1,88 @@ +class JestFailuresOnlyReporter { + constructor() { + this._failures = []; + } + + onTestResult(_test, testResult) { + if (testResult.numFailingTests === 0 && !testResult.testExecError) { + return; + } + + const relativePath = testResult.testFilePath.replace( + process.cwd() + '/', + '', + ); + + process.stderr.write(`\n\x1b[31mFAIL\x1b[0m ${relativePath}\n`); + + if (testResult.failureMessage) { + process.stderr.write(testResult.failureMessage + '\n'); + } + + if (testResult.testExecError) { + process.stderr.write( + `\n Runtime error: ${testResult.testExecError.message}\n`, + ); + } + + this._failures.push({ path: relativePath, testResult }); + } + + onRunComplete(_testContexts, aggregatedResults) { + const { + numPassedTestSuites, + numFailedTestSuites, + numTotalTestSuites, + numPassedTests, + numFailedTests, + numTotalTests, + } = aggregatedResults; + + process.stderr.write('\n'); + + if (this._failures.length > 0) { + process.stderr.write( + `\x1b[31m${'='.repeat(60)}\x1b[0m\n` + + `\x1b[31m FAILED TEST SUITES SUMMARY\x1b[0m\n` + + `\x1b[31m${'='.repeat(60)}\x1b[0m\n\n`, + ); + + for (const failure of this._failures) { + process.stderr.write(` \x1b[31m✕\x1b[0m ${failure.path}\n`); + + const failedTests = failure.testResult.testResults.filter( + (result) => result.status === 'failed', + ); + + for (const failedTest of failedTests) { + process.stderr.write(` \x1b[31m→\x1b[0m ${failedTest.fullName}\n`); + } + + process.stderr.write('\n'); + } + + process.stderr.write(`\x1b[31m${'='.repeat(60)}\x1b[0m\n\n`); + } + + const suiteSummary = + `Test Suites: ` + + (numFailedTestSuites > 0 + ? `\x1b[31m${numFailedTestSuites} failed\x1b[0m, ` + : '') + + (numPassedTestSuites > 0 + ? `\x1b[32m${numPassedTestSuites} passed\x1b[0m, ` + : '') + + `${numTotalTestSuites} total`; + + const testSummary = + `Tests: ` + + (numFailedTests > 0 ? `\x1b[31m${numFailedTests} failed\x1b[0m, ` : '') + + (numPassedTests > 0 ? `\x1b[32m${numPassedTests} passed\x1b[0m, ` : '') + + `${numTotalTests} total`; + + process.stderr.write(suiteSummary + '\n'); + process.stderr.write(testSummary + '\n'); + } +} + +module.exports = JestFailuresOnlyReporter; diff --git a/packages/twenty-front/jest.config.mjs b/packages/twenty-front/jest.config.mjs index a3f9102023..82279f3fe8 100644 --- a/packages/twenty-front/jest.config.mjs +++ b/packages/twenty-front/jest.config.mjs @@ -9,6 +9,8 @@ const __dirname = dirname(__filename); const tsConfigPath = resolve(__dirname, './tsconfig.json'); const tsConfig = JSON.parse(readFileSync(tsConfigPath, 'utf8')); +const isCI = process.env.CI === 'true'; + // oxlint-disable-next-line no-undef process.env.TZ = 'GMT'; // oxlint-disable-next-line no-undef @@ -17,6 +19,7 @@ const jestConfig = { // For more information please have a look to official docs https://jestjs.io/docs/configuration/#prettierpath-string // Prettier v3 will should be supported in jest v30 https://github.com/jestjs/jest/releases/tag/v30.0.0-alpha.1 prettierPath: null, + ...(isCI && { reporters: ['./jest-failures-only-reporter.cjs'] }), displayName: 'twenty-front', preset: '../../jest.preset.js', setupFilesAfterEnv: ['./setupTests.ts'],