-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathgit-utils.spec.js
More file actions
48 lines (36 loc) · 1.58 KB
/
Copy pathgit-utils.spec.js
File metadata and controls
48 lines (36 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const { outputFile } = require('fs-extra');
const { resolve, relative, normalize } = require('path');
const { getRoot, getRelativePath, getCommitFiles } = require('./git-utils');
const { commitAll } = require('../test-env/common');
const { setupNpmTestEnv } = require('../test-env/npm');
describe('git-utils', () => {
it('gets commit files', async () => {
const gitRoot = await setupNpmTestEnv();
const filePath = resolve(gitRoot, 'projects', 'project1', 'file1.txt');
await outputFile(filePath, 'content1');
const hash = await commitAll(gitRoot, 'fix: file1');
const commitFiles = (await getCommitFiles(hash, gitRoot)).map(x =>
normalize(x)
);
expect(commitFiles).toIncludeAllMembers([relative(gitRoot, filePath)]);
});
it('gets git root from root', async () => {
const gitRoot = await setupNpmTestEnv();
const root = normalize(await getRoot(gitRoot));
expect(root).toBe(gitRoot);
});
it('gets git root from subdirectory', async () => {
const projectName = 'my-project';
const gitRoot = await setupNpmTestEnv([projectName]);
const project1Root = resolve(gitRoot, 'projects', projectName);
const root = normalize(await getRoot(project1Root));
expect(root).toBe(gitRoot);
});
it('gets relative path', async () => {
const projectName = 'my-project';
const gitRoot = await setupNpmTestEnv([projectName]);
const project1Root = resolve(gitRoot, 'projects', projectName);
const relativePath = await getRelativePath(project1Root, project1Root);
expect(relativePath).toBe(relative(gitRoot, project1Root));
});
});