-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding documentation for --only-git * Fixing --root documentation * adding int tests for --only-git * Shuffling deck chairs and preffering exec over execFile * giving git an identity in ci Co-authored-by: github-codeowners <[email protected]>
- Loading branch information
1 parent
172061a
commit 1421baf
Showing
10 changed files
with
124 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,39 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import child_process from 'child_process'; | ||
import util from 'util'; | ||
|
||
import { v4 as uuidv4 } from 'uuid'; | ||
import fixtures from './__fixtures__/default'; | ||
import { generateProject } from './__fixtures__/project-builder.test.helper'; | ||
|
||
import util from 'util'; | ||
|
||
const exec = util.promisify(require('child_process').exec); | ||
const exec = util.promisify(child_process.exec); | ||
const writeFile = util.promisify(fs.writeFile); | ||
|
||
describe('audit', () => { | ||
const testId = uuidv4(); | ||
|
||
let testDir = 'not set'; | ||
|
||
beforeAll(async () => { | ||
testDir = await generateProject(testId, fixtures); | ||
// tslint:disable-next-line:no-console | ||
console.log(`test scratch dir: ${testDir}`); | ||
}); | ||
|
||
const runCli = async (args: string) => { | ||
return exec(`node ../../../dist/cli.js ${args}`, { cwd: testDir }); | ||
}; | ||
|
||
const gitTrackProject = async () => { | ||
await exec(`git init`, { cwd: testDir }); | ||
await exec(`git add .`, { cwd: testDir }); | ||
await exec(`git config user.email "[email protected]"`, { cwd: testDir }); | ||
await exec(`git config user.name "github-codeowners"`, { cwd: testDir }); | ||
await exec(`git commit -m "integration tests"`, { cwd: testDir }); | ||
}; | ||
|
||
const outputs = ['simple', 'jsonl', 'csv']; | ||
|
||
for (const output of outputs) { | ||
describe(output, () => { | ||
beforeEach(async () => { | ||
const testId = uuidv4(); | ||
testDir = await generateProject(testId, fixtures); | ||
}); | ||
|
||
it('should list ownership for all files', async () => { | ||
const { stdout, stderr } = await runCli(`audit -o ${output}`); | ||
expect(stdout).toMatchSnapshot('stdout'); | ||
|
@@ -49,6 +58,19 @@ describe('audit', () => { | |
expect(stderr).toMatchSnapshot('stderr'); | ||
}); | ||
|
||
it('should only consider files tracked in git root when asked', async () => { | ||
// Arrange | ||
await gitTrackProject(); | ||
await writeFile(path.resolve(testDir, 'git-untracked.txt'), 'not tracked in git'); | ||
|
||
// Act | ||
const { stdout, stderr } = await runCli(`audit -g -o ${output}`); | ||
|
||
// Assert | ||
expect(stdout).toMatchSnapshot('stdout'); | ||
expect(stderr).toMatchSnapshot('stderr'); | ||
}); | ||
|
||
it('should do all commands in combination when asked', async () => { | ||
const { stdout, stderr } = await runCli(`audit -us -r deep -o ${output}`); | ||
expect(stdout).toMatchSnapshot('stdout'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { exec } from '../../util/exec'; | ||
import { readTrackedGitFiles } from './readTrackedGitFiles'; | ||
|
||
jest.mock('../../util/exec'); | ||
const execFileMock = exec as jest.Mock; | ||
|
||
describe('readTrackedGitFiles', () => { | ||
it('should return the expected list of files when called', async () => { | ||
execFileMock.mockResolvedValue({ stdout: 'foo\nbar\n', stderr: '' }); | ||
|
||
const result = await readTrackedGitFiles('some/dir'); | ||
|
||
expect(result).toStrictEqual(['foo', 'bar']); | ||
}); | ||
|
||
it('should call git ls-files with the correct directory', async () => { | ||
execFileMock.mockResolvedValue({ stdout: '', stderr: '' }); | ||
|
||
const result = await readTrackedGitFiles('some/dir'); | ||
|
||
expect(exec).toHaveBeenCalledWith( | ||
'git ls-files', | ||
expect.objectContaining({ | ||
cwd: 'some/dir', | ||
}), | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { exec } from '../../util/exec'; | ||
|
||
export const readTrackedGitFiles = async (dir: string): Promise<string[]> => { | ||
const { stdout } = await exec('git ls-files', { cwd: dir }); | ||
return stdout.split('\n').filter(x => !!x); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { exec as realExec } from 'child_process'; | ||
import { promisify } from 'util'; | ||
|
||
export const exec = promisify(realExec); |