Skip to content

Commit 6b3e05c

Browse files
authored
Share test utilities (#843)
Split test fixtures into `@simple-git/test-utils`, depend on the package directly in integration tests and share through unit tests fixtures Remove outer fixtures, reuse `@simple-git/test-utils` in unit test fixtures
1 parent a975980 commit 6b3e05c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+196
-166
lines changed

.changeset/heavy-pumpkins-work.md

Lines changed: 6 additions & 0 deletions

packages/test-utils/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export * from './src/create-test-context';
2+
export * from './src/expectations';
3+
export * from './src/instance';
4+
export * from './src/like';
5+
export * from './src/wait';
6+
7+
export * from './src/setup/setup-conflicted';
8+
export * from './src/setup/setup-files';
9+
export * from './src/setup/setup-init';

packages/test-utils/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "@simple-git/test-utils",
3+
"version": "0.0.0",
4+
"private": true,
5+
"peerDependencies": {
6+
"simple-git": "^3.12.0"
7+
}
8+
}

simple-git/test/__fixtures__/create-test-context.ts renamed to packages/test-utils/src/create-test-context.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { join } from 'path';
22
import { existsSync, mkdir, mkdtemp, realpathSync, writeFile, WriteFileOptions } from 'fs';
3-
import { SimpleGit } from '../../typings';
4-
import { newSimpleGit } from './instance';
3+
import { simpleGit, SimpleGit } from 'simple-git';
54

65
export interface SimpleGitTestContext {
76
/** Creates a directory under the repo root at the given path(s) */
@@ -85,7 +84,7 @@ export async function createTestContext(): Promise<SimpleGitTestContext> {
8584
return realpathSync(context.root);
8685
},
8786
get git() {
88-
return newSimpleGit(root);
87+
return simpleGit(root);
8988
},
9089
};
9190

simple-git/test/__fixtures__/expectations.ts renamed to packages/test-utils/src/expectations.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { GitError } from '../../src/lib/errors/git-error';
2-
import { GitResponseError } from '../../src/lib/errors/git-response-error';
1+
import { GitError, GitResponseError } from "simple-git";
32

43
/**
54
* Convenience for asserting the type and message of a `GitError`
@@ -15,12 +14,8 @@ import { GitResponseError } from '../../src/lib/errors/git-response-error';
1514
export function assertGitError(
1615
errorInstance: Error | unknown,
1716
message: string | RegExp,
18-
errorConstructor?: any
17+
errorConstructor: any = GitError
1918
) {
20-
if (!errorConstructor) {
21-
errorConstructor = GitError;
22-
}
23-
2419
expect(errorInstance).toBeInstanceOf(errorConstructor);
2520
expect(errorInstance).toHaveProperty('message', expect.stringMatching(message));
2621
}

packages/test-utils/src/instance.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { simpleGit as newSimpleGit } from 'simple-git';
2+
3+
export { newSimpleGit };

simple-git/test/__fixtures__/setup-conflicted.ts renamed to packages/test-utils/src/setup/setup-conflicted.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SimpleGitTestContext } from './create-test-context';
1+
import { SimpleGitTestContext } from '../create-test-context';
22

33
export const FIRST_BRANCH = 'first';
44
export const SECOND_BRANCH = 'second';

simple-git/test/__fixtures__/setup-files.ts renamed to packages/test-utils/src/setup/setup-files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SimpleGitTestContext } from './create-test-context';
1+
import { SimpleGitTestContext } from '../create-test-context';
22

33
export async function setUpFilesAdded(
44
{ git, files }: SimpleGitTestContext,

simple-git/test/__fixtures__/setup-init.ts renamed to packages/test-utils/src/setup/setup-init.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { SimpleGit } from '../../typings';
2-
import { SimpleGitTestContext } from './create-test-context';
1+
import { SimpleGit } from 'simple-git';
2+
import { SimpleGitTestContext } from '../create-test-context';
33

44
export const GIT_USER_NAME = 'Simple Git Tests';
55
export const GIT_USER_EMAIL = 'tests@simple-git.dev';

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy