Skip to content

Commit

Permalink
test: minor refactoring, preparing for new status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
senyai committed Nov 17, 2024
1 parent bbad412 commit c6e4ec2
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/test/suite/branchSuite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export function BranchSuite(this: Suite): void {
sinon.match.array.startsWith(['branch', 'new', 'trunk', 'current'])
);
const updateStub = execStub
.withArgs(sinon.match.array.startsWith(['update']))
.withArgs(sinon.match.array.startsWith(['update', 'trunk']))
.resolves(fakeExecutionResult());

await commands.executeCommand('fossil.branch');
Expand Down
16 changes: 5 additions & 11 deletions src/test/suite/commandSuites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as fs from 'fs/promises';
import { OpenedRepository, ResourceStatus } from '../../openedRepository';
import { Suite, before, Func, Test } from 'mocha';
import { toFossilUri } from '../../uri';
import { Reason } from '../../fossilExecutable';

declare module 'mocha' {
interface TestFunction {
Expand Down Expand Up @@ -167,19 +168,13 @@ export function StatusSuite(this: Suite): void {
await fs.writeFile(unlink_path, '/etc/passwd');

// NOT A FILE
const not_file_path = Uri.joinPath(uri, 'not_file').fsPath;
await fs.writeFile(not_file_path, 'not_file_path');
await openedRepository.exec(['add', not_file_path]);
await openedRepository.exec([
'commit',
not_file_path,
'-m',
'added not_file',
]);
const not_file_path = (
await add('not_file', 'not_file_path', 'added not_file')
).fsPath;
await fs.unlink(not_file_path);
await fs.mkdir(not_file_path);

await repository.updateModelState();
await repository.updateModelState('Test' as Reason);
assertGroups(repository, {
working: [
[executable_path, ResourceStatus.MODIFIED],
Expand All @@ -189,7 +184,6 @@ export function StatusSuite(this: Suite): void {
[not_file_path, ResourceStatus.MISSING],
],
});
new Map();
await fs.rmdir(not_file_path);
}).timeout(20000);

Expand Down
9 changes: 7 additions & 2 deletions src/test/suite/commitSuite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,18 @@ export function CommitSuite(this: Suite): void {

test('Commit empty message', async () => {
const repository = getRepository();
assertGroups(repository, {});
const uri = Uri.joinPath(rootUri, 'empty_commit.txt');
await fs.writeFile(uri.fsPath, 'content');

const execStub = getExecStub(this.ctx.sandbox);
await repository.updateModelState();
const resource = repository.untrackedGroup.getResource(uri);
await repository.updateModelState('Test' as Reason);
assertGroups(repository, {
untracked: [[uri.fsPath, ResourceStatus.EXTRA]],
});

const resource = repository.untrackedGroup.getResource(uri);
assert.ok(resource);
await commands.executeCommand('fossil.add', resource);
assertGroups(repository, {
staging: [[uri.fsPath, ResourceStatus.ADDED]],
Expand Down
15 changes: 12 additions & 3 deletions src/test/suite/renameSuite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import { Reason } from '../../fossilExecutable';

export function RenameSuite(this: Suite): void {
let rootUri: Uri;
const config = () => workspace.getConfiguration('fossil');

before(async () => {
await config().update('enableRenaming', true);
await cleanupFossil(getRepository());
rootUri = workspace.workspaceFolders![0].uri;
});
Expand Down Expand Up @@ -57,7 +59,6 @@ export function RenameSuite(this: Suite): void {
const repository = getRepository();
assertGroups(repository, {}, "Previous test didn't cleanup or failed");

const config = () => workspace.getConfiguration('fossil');
assert.equal(config().get('enableRenaming'), true, 'contract');
const execStub = getExecStub(this.ctx.sandbox);
const oldFilename = 'do_not_show.txt';
Expand Down Expand Up @@ -87,6 +88,14 @@ export function RenameSuite(this: Suite): void {
['status', '--differ', '--merge'],
'file rename event' as Reason
);

// renaming triggers an async event, that is not awaited. await it.
for (let i = 0; i < 200; ++i) {
if (sim.callCount != 0) {
break;
}
await delay(5);
}
sinon.assert.calledOnceWithExactly(
sim,
'"do_not_show.txt" was renamed to "test_failed.txt" on ' +
Expand All @@ -99,11 +108,11 @@ export function RenameSuite(this: Suite): void {
"Don't show again"
);

for (let i = 1; i < 100; ++i) {
for (let i = 1; i < 200; ++i) {
if (config().get('enableRenaming') === false) {
break;
}
await delay(i * 11);
await delay(5);
}
assert.equal(config().get('enableRenaming'), false, 'no update');
await config().update('enableRenaming', true);
Expand Down
6 changes: 3 additions & 3 deletions src/test/suite/resourceActionsSuite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ export function resourceActionsSuite(this: Suite): void {
await fs.writeFile(uri.fsPath, 'fossil_add');

const repository = getRepository();
await repository.updateModelState();
await repository.updateModelState('Test' as Reason);
const resource = repository.untrackedGroup.getResource(uri);
assert.ok(resource);

await commands.executeCommand('fossil.add', resource);
await repository.updateModelState();
await repository.updateModelState('Test' as Reason);
assert.ok(!repository.untrackedGroup.includesUri(uri));
assert.ok(repository.stagingGroup.includesUri(uri));
}).timeout(5000);
Expand All @@ -81,7 +81,7 @@ export function resourceActionsSuite(this: Suite): void {
let statusStub = fakeFossilStatus(execStub, 'EXTRA a.txt\nEXTRA b.txt');

const repository = getRepository();
await repository.updateModelState('test' as Reason);
await repository.updateModelState('Test' as Reason);
sinon.assert.calledOnce(statusStub);
assertGroups(repository, {
untracked: [
Expand Down
26 changes: 25 additions & 1 deletion src/test/suite/stateSuite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,15 @@ export function UpdateSuite(this: Suite): void {

export function StashSuite(this: Suite): void {
let uri: Uri;
/**
* Create a file and stash it
*/
before(() => {
uri = Uri.joinPath(workspace.workspaceFolders![0].uri, 'stash.txt');
});

test('Save', async () => {
const repository = getRepository();
uri = Uri.joinPath(workspace.workspaceFolders![0].uri, 'stash.txt');
await fs.writeFile(uri.fsPath, 'stash me');

const sib = this.ctx.sandbox.stub(window, 'showInputBox');
Expand All @@ -307,6 +312,9 @@ export function StashSuite(this: Suite): void {
});
}).timeout(6000);

/**
* Apply previously stashed item, while keeping it in the list
*/
test('Apply', async () => {
const execStub = getExecStub(this.ctx.sandbox);
const stashApply = execStub.withArgs(['stash', 'apply', '1']);
Expand All @@ -328,12 +336,16 @@ export function StashSuite(this: Suite): void {
});
}).timeout(6000);

/**
* Remove previously created stash from the list
*/
test('Drop', async () => {
const execStub = getExecStub(this.ctx.sandbox);
const stashApply = execStub.withArgs(['stash', 'drop', '1']);
const sqp = this.ctx.sandbox.stub(window, 'showQuickPick');
sqp.onFirstCall().callsFake(items => {
assert.ok(items instanceof Array);
assert.equal(items.length, 1);
assert.match(
items[0].label,
/\$\(circle-outline\) 1 • [a-f0-9]{12}/
Expand All @@ -344,8 +356,17 @@ export function StashSuite(this: Suite): void {
});
await commands.executeCommand('fossil.stashDrop');
sinon.assert.calledOnce(stashApply);
sinon.assert.calledOnce(sqp);

const repository = getRepository();
assertGroups(repository, {
working: [[uri.fsPath, ResourceStatus.ADDED]],
});
}).timeout(6000);

/**
* Stash a file ant then pop this stash
*/
test('Pop', async () => {
const execStub = getExecStub(this.ctx.sandbox);
const repository = getRepository();
Expand All @@ -361,6 +382,9 @@ export function StashSuite(this: Suite): void {
const stashPop = execStub.withArgs(['stash', 'pop']);
await commands.executeCommand('fossil.stashPop');
sinon.assert.calledOnce(stashPop);
assertGroups(repository, {
working: [[uri.fsPath, ResourceStatus.ADDED]],
});
}).timeout(15000);

test('Snapshot', async () => {
Expand Down

0 comments on commit c6e4ec2

Please sign in to comment.