Skip to content

Commit

Permalink
Testing, exit with non-zero code if tests fail (#2624)
Browse files Browse the repository at this point in the history
* Testing, exit with non-zero code if tests fail

* Update changelog
  • Loading branch information
stwiname authored Dec 11, 2024
1 parent 09eceec commit 980c2da
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/node-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions packages/node-core/src/indexer/testing.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ export abstract class TestingService<A, SA, B, DS extends BaseDataSource> {
private totalPassedTests = 0;
private totalFailedTests = 0;

constructor(protected nodeConfig: NodeConfig, protected project: ISubqueryProject<IProjectNetworkConfig, DS>) {
constructor(
protected nodeConfig: NodeConfig,
protected project: ISubqueryProject<IProjectNetworkConfig, DS>
) {
const projectPath = this.project.root;
// find all paths to test files
const testFiles = this.findAllTestFiles(path.join(projectPath, 'dist'));
Expand Down Expand Up @@ -64,7 +67,7 @@ export abstract class TestingService<A, SA, B, DS extends BaseDataSource> {
await indexerManager.indexBlock(block, this.getDsWithHandler(handler));
}

async run() {
async run(): Promise<void> {
if (Object.keys(this.tests).length !== 0) {
for (const sandboxIndex in this.tests) {
const tests = this.tests[sandboxIndex];
Expand Down Expand Up @@ -171,5 +174,9 @@ export abstract class TestingService<A, SA, B, DS extends BaseDataSource> {
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);
}
}
}

0 comments on commit 980c2da

Please sign in to comment.