Skip to content

Commit

Permalink
add tests for fetch sloc
Browse files Browse the repository at this point in the history
Summary: tsia

Reviewed By: quark-zju

Differential Revision: D57795331

fbshipit-source-id: 263f1e457bd0569e09b39beecd9d667ab4e2179e
  • Loading branch information
Ben Monro authored and facebook-github-bot committed May 25, 2024
1 parent 67e5819 commit 310477e
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions addons/isl-server/src/__tests__/Repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,78 @@ describe('Repository', () => {
});
});

describe('fetchSloc', () => {
const repoInfo: ValidatedRepoInfo = {
type: 'success',
command: 'sl',
dotdir: '/path/to/repo/.sl',
repoRoot: '/path/to/repo',
codeReviewSystem: {type: 'unknown'},
pullRequestDomain: undefined,
};

const EXAMPLE_DIFFSTAT = `
| 34 ++++++++++
www/flib/intern/entity/diff/EntPhabricatorDiffSchema.php | 11 +++
2 files changed, 45 insertions(+), 0 deletions(-)\n`;

it('parses sloc', async () => {
const repo = new Repository(repoInfo, ctx);

const execaSpy = mockExeca([[/^sl diff/, () => ({stdout: EXAMPLE_DIFFSTAT})]]);
const results = repo.fetchSignificantLinesOfCode(ctx, 'abcdef', ['generated.file']);
await expect(results).resolves.toEqual(45);
expect(execaSpy).toHaveBeenCalledWith(
'sl',
expect.arrayContaining([
'diff',
'-B',
'-X',
'**__generated__**',
'-X',
'/path/to/repo/generated.file',
'-c',
'abcdef',
]),
expect.anything(),
);
});

it('handles empty generated list', async () => {
const repo = new Repository(repoInfo, ctx);
const execaSpy = mockExeca([[/^sl diff/, () => ({stdout: EXAMPLE_DIFFSTAT})]]);
repo.fetchSignificantLinesOfCode(ctx, 'abcdef', []);
expect(execaSpy).toHaveBeenCalledWith(
'sl',
expect.arrayContaining(['diff', '-B', '-X', '**__generated__**', '-c', 'abcdef']),
expect.anything(),
);
});

it('handles multiple generated files', async () => {
const repo = new Repository(repoInfo, ctx);
const execaSpy = mockExeca([[/^sl diff/, () => ({stdout: EXAMPLE_DIFFSTAT})]]);
const generatedFiles = ['generated1.file', 'generated2.file'];
repo.fetchSignificantLinesOfCode(ctx, 'abcdef', generatedFiles);
expect(execaSpy).toHaveBeenCalledWith(
'sl',
expect.arrayContaining([
'diff',
'-B',
'-X',
'**__generated__**',
'-X',
'/path/to/repo/generated1.file',
'-X',
'/path/to/repo/generated2.file',
'-c',
'abcdef',
]),
expect.anything(),
);
});
});

describe('fetchSmartlogCommits', () => {
const repoInfo: ValidatedRepoInfo = {
type: 'success',
Expand Down

0 comments on commit 310477e

Please sign in to comment.