From 980c2da700c683dcd7ea654677c75c26a38deb08 Mon Sep 17 00:00:00 2001 From: Scott Twiname Date: Wed, 11 Dec 2024 14:47:48 +1300 Subject: [PATCH] Testing, exit with non-zero code if tests fail (#2624) * Testing, exit with non-zero code if tests fail * Update changelog --- packages/node-core/CHANGELOG.md | 2 ++ packages/node-core/src/indexer/testing.service.ts | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/node-core/CHANGELOG.md b/packages/node-core/CHANGELOG.md index 54df13d625..a2a7870679 100644 --- a/packages/node-core/CHANGELOG.md +++ b/packages/node-core/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed +- If any tests fail with the `test` subcommand the exit code will now be 1 instead of 0 (#2624) ## [16.0.0] - 2024-12-04 ### Removed diff --git a/packages/node-core/src/indexer/testing.service.ts b/packages/node-core/src/indexer/testing.service.ts index 71a5a2a256..6f497e03f8 100644 --- a/packages/node-core/src/indexer/testing.service.ts +++ b/packages/node-core/src/indexer/testing.service.ts @@ -32,7 +32,10 @@ export abstract class TestingService { private totalPassedTests = 0; private totalFailedTests = 0; - constructor(protected nodeConfig: NodeConfig, protected project: ISubqueryProject) { + constructor( + protected nodeConfig: NodeConfig, + protected project: ISubqueryProject + ) { const projectPath = this.project.root; // find all paths to test files const testFiles = this.findAllTestFiles(path.join(projectPath, 'dist')); @@ -64,7 +67,7 @@ export abstract class TestingService { await indexerManager.indexBlock(block, this.getDsWithHandler(handler)); } - async run() { + async run(): Promise { if (Object.keys(this.tests).length !== 0) { for (const sandboxIndex in this.tests) { const tests = this.tests[sandboxIndex]; @@ -171,5 +174,9 @@ export abstract class TestingService { logger.info(chalk.bold.white(`Total tests: ${this.totalTests}`)); logger.info(chalk.bold.green(`Passing tests: ${this.totalPassedTests}`)); logger.info(chalk.bold.red(`Failing tests: ${this.totalFailedTests}`)); + + if (this.totalFailedTests > 0) { + process.exit(1); + } } }