Skip to content

Commit

Permalink
test(lib/util): Refactor snapshot tests (#13289)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov authored Dec 27, 2021
1 parent 6a26656 commit 15a1208
Show file tree
Hide file tree
Showing 15 changed files with 155 additions and 369 deletions.
47 changes: 0 additions & 47 deletions lib/util/__snapshots__/host-rules.spec.ts.snap

This file was deleted.

15 changes: 0 additions & 15 deletions lib/util/__snapshots__/markdown.spec.ts.snap

This file was deleted.

57 changes: 0 additions & 57 deletions lib/util/__snapshots__/package-rules.spec.ts.snap

This file was deleted.

19 changes: 0 additions & 19 deletions lib/util/exec/__snapshots__/index.spec.ts.snap

This file was deleted.

17 changes: 15 additions & 2 deletions lib/util/exec/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,21 @@ describe('util/exec/index', () => {
await exec(inCmd, { docker });
await exec(inCmd, { docker });

// FIXME: explicit assert condition
expect(actualCmd).toMatchSnapshot();
expect(actualCmd).toEqual([
`echo hello`,
`echo hello`,
`docker pull renovate/image`,
`docker ps --filter name=renovate_image -aq`,
`docker run --rm --name=renovate_image --label=renovate_child renovate/image bash -l -c "echo hello"`,
`docker ps --filter name=renovate_image -aq`,
`docker run --rm --name=renovate_image --label=renovate_child renovate/image bash -l -c "echo hello"`,
`echo hello`,
`echo hello`,
`docker ps --filter name=renovate_image -aq`,
`docker run --rm --name=renovate_image --label=renovate_child renovate/image bash -l -c "echo hello"`,
`docker ps --filter name=renovate_image -aq`,
`docker run --rm --name=renovate_image --label=renovate_child renovate/image bash -l -c "echo hello"`,
]);
});
it('Supports binarySource=install', async () => {
process.env = processEnv;
Expand Down
46 changes: 0 additions & 46 deletions lib/util/git/__snapshots__/index.spec.ts.snap

This file was deleted.

30 changes: 11 additions & 19 deletions lib/util/git/author.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,23 @@ describe('util/git/author', () => {
expect(parseGitAuthor('renovate@whitesourcesoftware.com')).not.toBeNull();
});
it('parses bot email', () => {
// FIXME: explicit assert condition
expect(parseGitAuthor('renovate[bot]@users.noreply.github.com'))
.toMatchInlineSnapshot(`
Object {
"address": "renovate[bot]@users.noreply.github.com",
"name": "renovate[bot]",
}
`);
expect(parseGitAuthor('renovate[bot]@users.noreply.github.com')).toEqual({
address: 'renovate[bot]@users.noreply.github.com',
name: 'renovate[bot]',
});
});
it('parses bot name and email', () => {
// FIXME: explicit assert condition
expect(
parseGitAuthor('renovate[bot] <renovate[bot]@users.noreply.github.com>')
).toMatchInlineSnapshot(`
Object {
"address": "renovate[bot]@users.noreply.github.com",
"name": "renovate[bot]",
}
`);
).toEqual({
address: 'renovate[bot]@users.noreply.github.com',
name: 'renovate[bot]',
});
});
it('escapes names', () => {
// FIXME: explicit assert condition
expect(
parseGitAuthor('name [what] <name@what.com>').name
).toMatchInlineSnapshot(`"name [what]"`);
expect(parseGitAuthor('name [what] <name@what.com>').name).toEqual(
`name [what]`
);
});
it('tries again and fails', () => {
expect(parseGitAuthor('foo<foo>')).toBeNull();
Expand Down
32 changes: 21 additions & 11 deletions lib/util/git/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,11 @@ describe('util/git/index', () => {
});
describe('getFileList()', () => {
it('should return the correct files', async () => {
// FIXME: explicit assert condition
expect(await git.getFileList()).toMatchSnapshot();
expect(await git.getFileList()).toEqual([
'file_to_delete',
'master_file',
'past_file',
]);
});
it('should exclude submodules', async () => {
const repo = Git(base.path);
Expand All @@ -124,8 +127,12 @@ describe('util/git/index', () => {
});
await git.syncGit();
expect(await fs.pathExists(tmpDir.path + '/.gitmodules')).toBeTruthy();
// FIXME: explicit assert condition
expect(await git.getFileList()).toMatchSnapshot();
expect(await git.getFileList()).toEqual([
'.gitmodules',
'file_to_delete',
'master_file',
'past_file',
]);
await repo.reset(['--hard', 'HEAD^']);
});
});
Expand Down Expand Up @@ -210,8 +217,7 @@ describe('util/git/index', () => {
const branchFiles = await git.getBranchFiles(
'renovate/branch_with_changes'
);
// FIXME: explicit assert condition
expect(branchFiles).toMatchSnapshot();
expect(branchFiles).toEqual(['some-new-file']);
});
});

Expand Down Expand Up @@ -441,8 +447,10 @@ describe('util/git/index', () => {

describe('getCommitMessages()', () => {
it('returns commit messages', async () => {
// FIXME: explicit assert condition
expect(await git.getCommitMessages()).toMatchSnapshot();
expect(await git.getCommitMessages()).toEqual([
'master message',
'past message',
]);
});
});

Expand Down Expand Up @@ -489,8 +497,10 @@ describe('util/git/index', () => {

expect(git.branchExists('test')).toBeFalsy();

// FIXME: explicit assert condition
expect(await git.getCommitMessages()).toMatchSnapshot();
expect(await git.getCommitMessages()).toEqual([
'master message',
'past message',
]);

await git.checkoutBranch('develop');

Expand All @@ -503,7 +513,7 @@ describe('util/git/index', () => {
await git.checkoutBranch('test');

const msg = await git.getCommitMessages();
expect(msg).toMatchSnapshot();
expect(msg).toEqual(['past message2', 'master message', 'past message']);
expect(msg).toContain('past message2');
});

Expand Down
Loading

0 comments on commit 15a1208

Please sign in to comment.