Skip to content

Commit 61aeac4

Browse files
committed
tests: remove use of test workspace module
1 parent d8543d3 commit 61aeac4

File tree

4 files changed

+28
-39
lines changed

4 files changed

+28
-39
lines changed

src/lib/git.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const parseGitTags = (tagsString: null | string): string[] => {
7272
/**
7373
* Get tags at the given commit or HEAD by default.
7474
*/
75-
export async function gitGetTags(git: Simple, opts?: { ref?: string }): Promise<string[]> {
75+
export const gitGetTags = async (git: Simple, opts?: { ref?: string }): Promise<string[]> => {
7676
const ref = opts?.ref ?? `HEAD`
7777
const tagsString: string | null = await git.tag({ '--points-at': ref })
7878
const tags = parseGitTags(tagsString)
@@ -82,7 +82,7 @@ export async function gitGetTags(git: Simple, opts?: { ref?: string }): Promise<
8282
/**
8383
* Get all tags in the git repo.
8484
*/
85-
export async function gitGetTagsInRepo(git: Simple): Promise<string[]> {
85+
export const gitGetTagsInRepo = async (git: Simple): Promise<string[]> => {
8686
const tagsString: string | null = await git.raw([`tag`])
8787
if (tagsString === null) return []
8888
const tags = tagsString
@@ -96,7 +96,7 @@ export async function gitGetTagsInRepo(git: Simple): Promise<string[]> {
9696
* Reset a git repository to its last commit, removing staged files, cleaning
9797
* dirty working directory, etc.
9898
*/
99-
export async function gitReset(git: Simple): Promise<void> {
99+
export const gitReset = async (git: Simple): Promise<void> => {
100100
await Promise.all([
101101
git.raw([`clean`, `-d`, `-x`, `-f`]),
102102
gitDeleteAllTagsInRepo(git),

tests/__lib/helpers.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ import * as proc from '../../src/lib/proc'
22
import { errorFromMaybeError } from '../../src/lib/utils'
33
import * as WS from '../__lib/workspace'
44
import { Octokit } from '@octokit/rest'
5-
import * as Path from 'path'
65
import { format } from 'util'
76

87
/**
98
* Reset the environment before each test, allowing each test to modify it to
109
* its needs.
1110
*/
12-
export function resetEnvironmentBeforeEachTest() {
11+
export const resetEnvironmentBeforeEachTest = () => {
1312
const originalEnvironment = Object.assign({}, process.env)
1413
beforeEach(() => {
1514
process.env = Object.assign({}, originalEnvironment)
@@ -19,7 +18,7 @@ export function resetEnvironmentBeforeEachTest() {
1918
/**
2019
* Helper for creating a specialized workspace
2120
*/
22-
export function createContext(name: string) {
21+
export const createContext = (name: string) => {
2322
const ws = addOctokitToWorkspace(
2423
addDripipToWorkspace(
2524
WS.createWorkspace({
@@ -99,7 +98,7 @@ type DripipRunnerOptions = proc.RunOptions & {
9998
/**
10099
* Return the raw proc result
101100
*
102-
* @default false
101+
* @defaultValue false
103102
*/
104103
raw?: boolean
105104
/**
@@ -146,8 +145,8 @@ function createDripipRunner(cwd: string, pathToProject: string) {
146145
}\n\nThe underlying cli result was:\n\n${format(result)}`
147146
)
148147
}
149-
})
150-
}
148+
});
149+
};
151150
}
152151

153152
export { createDripipRunner }

tests/_setup.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,3 @@
1-
import * as Context from './__lib/helpers'
2-
import * as WS from './__lib/workspace'
3-
41
// make system tests deterministic. Without this they would react to users'
52
// machines' ~/.npmrc file contents.
63
process.env.NPM_TOKEN = `foobar`
7-
8-
declare global {
9-
export const createContext: typeof Context.createContext
10-
export const createWorkspace: typeof WS.createWorkspace
11-
namespace NodeJS {
12-
interface Global {
13-
createContext: typeof Context.createContext
14-
createWorkspace: typeof WS.createWorkspace
15-
}
16-
}
17-
}
18-
19-
//@ts-expect-error
20-
global.createContext = Context.createContext
21-
//@ts-expect-error
22-
global.createWorkspace = WS.createWorkspace

tests/git.spec.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
import * as Git from '../src/lib/git'
2+
import { fixture } from './__providers__/fixture'
3+
import { git } from './__providers__/git'
4+
import { konn, providers } from 'konn'
5+
import createGit from 'simple-git/promise'
26

3-
const ws = createWorkspace({
4-
name: `system-git`,
5-
})
7+
const ctx = konn()
8+
.useBeforeAll(providers.dir())
9+
.useBeforeAll(git())
10+
.useBeforeEach(fixture({ use: `git-init`, into: `.git` }))
11+
.done()
612

713
describe(`streamLog`, () => {
814
it(`streams commits from newest to oldest`, async () => {
9-
await Git.gitCreateEmptyCommit(ws.git, `work 1`)
10-
await ws.git.addTag(`tag-1`)
11-
await Git.gitCreateEmptyCommit(ws.git, `work 2`)
12-
await ws.git.addTag(`tag-2`)
13-
await Git.gitCreateEmptyCommit(ws.git, `work 3`)
14-
await ws.git.addTag(`tag-3a`)
15-
await ws.git.addTag(`tag-3b`)
15+
await ctx.git.commit(`initial commit`)
16+
const git = createGit(ctx.fs.cwd())
17+
await Git.gitCreateEmptyCommit(git, `work 1`)
18+
await ctx.git.tag(`tag-1`)
19+
await Git.gitCreateEmptyCommit(git, `work 2`)
20+
await ctx.git.tag(`tag-2`)
21+
await Git.gitCreateEmptyCommit(git, `work 3`)
22+
await ctx.git.tag(`tag-3a`)
23+
await ctx.git.tag(`tag-3b`)
24+
// console.log(await ctx.git.log())
1625
const entries = []
17-
for await (const entry of Git.streamLog({ cwd: ws.dir.path })) {
26+
for await (const entry of Git.streamLog({ cwd: ctx.fs.cwd() })) {
1827
entries.push(entry)
1928
}
2029
entries.forEach((e) => (e.sha = `__sha__`))

0 commit comments

Comments
 (0)