31 lines
1.0 KiB
JavaScript
31 lines
1.0 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import monitorModule from '../src/main/repository-monitor.cjs';
|
|
|
|
const { RepositoryMonitor } = monitorModule;
|
|
|
|
test('repository monitor establishes a baseline and emits only on later changes', async () => {
|
|
let revision = 1;
|
|
const changes = [];
|
|
const git = {
|
|
status: async (localPath) => ({ localPath, revision }),
|
|
statusFingerprint: (status) => String(status.revision)
|
|
};
|
|
const store = { data: { preferences: { autoRefresh: true, repositoryPollSeconds: 2 } } };
|
|
const monitor = new RepositoryMonitor({ store, git, onChange: (change) => changes.push(change) });
|
|
monitor.setPaths(['/repo']);
|
|
await monitor.tick();
|
|
assert.equal(changes.length, 0);
|
|
revision = 2;
|
|
await monitor.tick();
|
|
assert.equal(changes.length, 1);
|
|
assert.equal(changes[0].reason, 'working-tree-changed');
|
|
monitor.pause('/repo');
|
|
revision = 3;
|
|
await monitor.tick();
|
|
assert.equal(changes.length, 1);
|
|
monitor.resume('/repo');
|
|
await monitor.tick();
|
|
assert.equal(changes.length, 2);
|
|
});
|