From 61aeac46c001b2f4d08ef5a68366e70310ede09e Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Tue, 8 Mar 2022 04:11:14 +0000 Subject: [PATCH] tests: remove use of test workspace module --- src/lib/git.ts | 6 +++--- tests/__lib/helpers.ts | 11 +++++------ tests/_setup.ts | 19 ------------------- tests/git.spec.ts | 31 ++++++++++++++++++++----------- 4 files changed, 28 insertions(+), 39 deletions(-) diff --git a/src/lib/git.ts b/src/lib/git.ts index 18cbc5b3..5f0db78f 100644 --- a/src/lib/git.ts +++ b/src/lib/git.ts @@ -72,7 +72,7 @@ const parseGitTags = (tagsString: null | string): string[] => { /** * Get tags at the given commit or HEAD by default. */ -export async function gitGetTags(git: Simple, opts?: { ref?: string }): Promise { +export const gitGetTags = async (git: Simple, opts?: { ref?: string }): Promise => { const ref = opts?.ref ?? `HEAD` const tagsString: string | null = await git.tag({ '--points-at': ref }) const tags = parseGitTags(tagsString) @@ -82,7 +82,7 @@ export async function gitGetTags(git: Simple, opts?: { ref?: string }): Promise< /** * Get all tags in the git repo. */ -export async function gitGetTagsInRepo(git: Simple): Promise { +export const gitGetTagsInRepo = async (git: Simple): Promise => { const tagsString: string | null = await git.raw([`tag`]) if (tagsString === null) return [] const tags = tagsString @@ -96,7 +96,7 @@ export async function gitGetTagsInRepo(git: Simple): Promise { * Reset a git repository to its last commit, removing staged files, cleaning * dirty working directory, etc. */ -export async function gitReset(git: Simple): Promise { +export const gitReset = async (git: Simple): Promise => { await Promise.all([ git.raw([`clean`, `-d`, `-x`, `-f`]), gitDeleteAllTagsInRepo(git), diff --git a/tests/__lib/helpers.ts b/tests/__lib/helpers.ts index 61807841..4c1e9141 100644 --- a/tests/__lib/helpers.ts +++ b/tests/__lib/helpers.ts @@ -2,14 +2,13 @@ import * as proc from '../../src/lib/proc' import { errorFromMaybeError } from '../../src/lib/utils' import * as WS from '../__lib/workspace' import { Octokit } from '@octokit/rest' -import * as Path from 'path' import { format } from 'util' /** * Reset the environment before each test, allowing each test to modify it to * its needs. */ -export function resetEnvironmentBeforeEachTest() { +export const resetEnvironmentBeforeEachTest = () => { const originalEnvironment = Object.assign({}, process.env) beforeEach(() => { process.env = Object.assign({}, originalEnvironment) @@ -19,7 +18,7 @@ export function resetEnvironmentBeforeEachTest() { /** * Helper for creating a specialized workspace */ -export function createContext(name: string) { +export const createContext = (name: string) => { const ws = addOctokitToWorkspace( addDripipToWorkspace( WS.createWorkspace({ @@ -99,7 +98,7 @@ type DripipRunnerOptions = proc.RunOptions & { /** * Return the raw proc result * - * @default false + * @defaultValue false */ raw?: boolean /** @@ -146,8 +145,8 @@ function createDripipRunner(cwd: string, pathToProject: string) { }\n\nThe underlying cli result was:\n\n${format(result)}` ) } - }) - } + }); + }; } export { createDripipRunner } diff --git a/tests/_setup.ts b/tests/_setup.ts index 0a50c335..555c8fa0 100644 --- a/tests/_setup.ts +++ b/tests/_setup.ts @@ -1,22 +1,3 @@ -import * as Context from './__lib/helpers' -import * as WS from './__lib/workspace' - // make system tests deterministic. Without this they would react to users' // machines' ~/.npmrc file contents. process.env.NPM_TOKEN = `foobar` - -declare global { - export const createContext: typeof Context.createContext - export const createWorkspace: typeof WS.createWorkspace - namespace NodeJS { - interface Global { - createContext: typeof Context.createContext - createWorkspace: typeof WS.createWorkspace - } - } -} - -//@ts-expect-error -global.createContext = Context.createContext -//@ts-expect-error -global.createWorkspace = WS.createWorkspace diff --git a/tests/git.spec.ts b/tests/git.spec.ts index 7d640aee..8b8319f7 100644 --- a/tests/git.spec.ts +++ b/tests/git.spec.ts @@ -1,20 +1,29 @@ import * as Git from '../src/lib/git' +import { fixture } from './__providers__/fixture' +import { git } from './__providers__/git' +import { konn, providers } from 'konn' +import createGit from 'simple-git/promise' -const ws = createWorkspace({ - name: `system-git`, -}) +const ctx = konn() + .useBeforeAll(providers.dir()) + .useBeforeAll(git()) + .useBeforeEach(fixture({ use: `git-init`, into: `.git` })) + .done() describe(`streamLog`, () => { it(`streams commits from newest to oldest`, async () => { - await Git.gitCreateEmptyCommit(ws.git, `work 1`) - await ws.git.addTag(`tag-1`) - await Git.gitCreateEmptyCommit(ws.git, `work 2`) - await ws.git.addTag(`tag-2`) - await Git.gitCreateEmptyCommit(ws.git, `work 3`) - await ws.git.addTag(`tag-3a`) - await ws.git.addTag(`tag-3b`) + await ctx.git.commit(`initial commit`) + const git = createGit(ctx.fs.cwd()) + await Git.gitCreateEmptyCommit(git, `work 1`) + await ctx.git.tag(`tag-1`) + await Git.gitCreateEmptyCommit(git, `work 2`) + await ctx.git.tag(`tag-2`) + await Git.gitCreateEmptyCommit(git, `work 3`) + await ctx.git.tag(`tag-3a`) + await ctx.git.tag(`tag-3b`) + // console.log(await ctx.git.log()) const entries = [] - for await (const entry of Git.streamLog({ cwd: ws.dir.path })) { + for await (const entry of Git.streamLog({ cwd: ctx.fs.cwd() })) { entries.push(entry) } entries.forEach((e) => (e.sha = `__sha__`))