Skip to content

Commit

Permalink
tests: remove use of test workspace module
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt committed Mar 8, 2022
1 parent d8543d3 commit 61aeac4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 39 deletions.
6 changes: 3 additions & 3 deletions src/lib/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]> {
export const gitGetTags = async (git: Simple, opts?: { ref?: string }): Promise<string[]> => {
const ref = opts?.ref ?? `HEAD`
const tagsString: string | null = await git.tag({ '--points-at': ref })
const tags = parseGitTags(tagsString)
Expand All @@ -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<string[]> {
export const gitGetTagsInRepo = async (git: Simple): Promise<string[]> => {
const tagsString: string | null = await git.raw([`tag`])
if (tagsString === null) return []
const tags = tagsString
Expand All @@ -96,7 +96,7 @@ export async function gitGetTagsInRepo(git: Simple): Promise<string[]> {
* Reset a git repository to its last commit, removing staged files, cleaning
* dirty working directory, etc.
*/
export async function gitReset(git: Simple): Promise<void> {
export const gitReset = async (git: Simple): Promise<void> => {
await Promise.all([
git.raw([`clean`, `-d`, `-x`, `-f`]),
gitDeleteAllTagsInRepo(git),
Expand Down
11 changes: 5 additions & 6 deletions tests/__lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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({
Expand Down Expand Up @@ -99,7 +98,7 @@ type DripipRunnerOptions = proc.RunOptions & {
/**
* Return the raw proc result
*
* @default false
* @defaultValue false
*/
raw?: boolean
/**
Expand Down Expand Up @@ -146,8 +145,8 @@ function createDripipRunner(cwd: string, pathToProject: string) {
}\n\nThe underlying cli result was:\n\n${format(result)}`
)
}
})
}
});
};
}

export { createDripipRunner }
19 changes: 0 additions & 19 deletions tests/_setup.ts
Original file line number Diff line number Diff line change
@@ -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
31 changes: 20 additions & 11 deletions tests/git.spec.ts
Original file line number Diff line number Diff line change
@@ -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__`))
Expand Down

0 comments on commit 61aeac4

Please sign in to comment.