Skip to content

Commit

Permalink
master: dependsOn triggers reload
Browse files Browse the repository at this point in the history
  • Loading branch information
Mate Pek committed Feb 1, 2022
1 parent aeab072 commit ed04a83
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

## [4.0.24]

## Changed

- `advancedExecutables.[dependsOn]` property triggers the reolad of all related executables. ([related](https://github.com/matepek/vscode-catch2-test-adapter/issues/326))

## [4.0.23] - 2022-02-01

### Changed
Expand Down
16 changes: 4 additions & 12 deletions src/AbstractExecutable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as pathlib from 'path';
import * as fs from 'fs';
import * as vscode from 'vscode';
import { EOL } from 'os';

Expand All @@ -8,7 +7,7 @@ import { AbstractTest } from './AbstractTest';
import { TaskPool } from './util/TaskPool';
import { ExecutableRunResultValue, RunningExecutable } from './RunningExecutable';
import { promisify } from 'util';
import { Version, getAbsolutePath, CancellationToken, reindentStr, parseLine } from './Util';
import { Version, getAbsolutePath, CancellationToken, reindentStr, parseLine, getModiTime } from './Util';
import {
resolveOSEnvironmentVariables,
createPythonIndexerForPathVariable,
Expand Down Expand Up @@ -432,13 +431,6 @@ export abstract class AbstractExecutable<TestT extends AbstractTest = AbstractTe
);
}

private _getModiTime(): Promise<number | undefined> {
return promisify(fs.stat)(this.shared.path).then(
stat => stat.mtimeMs,
() => undefined,
);
}

private _splitTestSetForMultirunIfEnabled(tests: readonly AbstractTest[]): (readonly AbstractTest[])[] {
const parallelizationLimit = this.shared.parallelizationPool.maxTaskCount;

Expand Down Expand Up @@ -509,7 +501,7 @@ export abstract class AbstractExecutable<TestT extends AbstractTest = AbstractTe
return this.shared.prependTestRunningArgs.concat(this._getDebugParamsInner(childrenToRun, breakOnFailure));
}

reloadTests(taskPool: TaskPool, cancellationToken: CancellationToken): Promise<void> {
reloadTests(taskPool: TaskPool, cancellationToken: CancellationToken, lastModiTime?: number): Promise<void> {
if (cancellationToken.isCancellationRequested) return Promise.resolve();

// mutually exclusive lock
Expand All @@ -519,9 +511,9 @@ export abstract class AbstractExecutable<TestT extends AbstractTest = AbstractTe

this.shared.log.info('reloadTests', this.frameworkName, this.frameworkVersion, this.shared.path);

const lastModiTime = await this._getModiTime();
lastModiTime = lastModiTime ?? (await getModiTime(this.shared.path));

if (this._lastReloadTime === undefined || lastModiTime === undefined || this._lastReloadTime !== lastModiTime) {
if (this._lastReloadTime === undefined || lastModiTime === undefined || this._lastReloadTime < lastModiTime) {
this._lastReloadTime = lastModiTime;

const prevTests = this._tests;
Expand Down
5 changes: 5 additions & 0 deletions src/ConfigOfExecGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { LoggerWrapper } from './LoggerWrapper';
import { debugBreak } from './util/DevelopmentHelper';
import { FrameworkType } from './framework/Framework';
import { readFileSync } from 'fs';
import { getModiTime } from './Util';

///

Expand Down Expand Up @@ -169,6 +170,10 @@ export class ConfigOfExecGroup implements vscode.Disposable {

w.onAll((fsPath: string): void => {
this._shared.log.info('dependsOn watcher event:', fsPath);
getModiTime(fsPath).then(modiTime => {
for (const exec of this._executables.values())
exec.reloadTests(this._shared.taskPool, this._shared.cancellationToken, modiTime);
});
//TODO:future this._shared.sendRetireEvent(this._executables.values());
});
} else {
Expand Down
7 changes: 7 additions & 0 deletions src/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,10 @@ export function getAbsolutePath(filePath: string, directories: Iterable<string>)

return filePath;
}

export function getModiTime(path: string): Promise<number | undefined> {
return promisify(fs.stat)(path).then(
stat => stat.mtimeMs,
() => undefined,
);
}

0 comments on commit ed04a83

Please sign in to comment.