1
1
import { describe , it } from 'mocha'
2
2
import { expect } from 'chai'
3
- import { readFile } from 'fs-extra'
4
3
import { join } from 'path'
5
-
4
+ import { readFile } from '../src/utils'
6
5
import remotes from './data/remotes'
7
6
import commits from './data/commits'
8
7
import commitsNoRemote from './data/commits-no-remote'
@@ -24,7 +23,7 @@ const options = {
24
23
25
24
describe ( 'fetchCommits' , ( ) => {
26
25
it ( 'fetches commits' , async ( ) => {
27
- const gitLog = await readFile ( join ( __dirname , 'data' , 'git-log.txt' ) , 'utf-8' )
26
+ const gitLog = await readFile ( join ( __dirname , 'data' , 'git-log.txt' ) )
28
27
mock ( 'cmd' , ( ) => gitLog )
29
28
expect ( await fetchCommits ( remotes . github , options ) ) . to . deep . equal ( commits )
30
29
unmock ( 'cmd' )
@@ -33,44 +32,44 @@ describe('fetchCommits', () => {
33
32
34
33
describe ( 'parseCommits' , ( ) => {
35
34
it ( 'parses commits' , async ( ) => {
36
- const gitLog = await readFile ( join ( __dirname , 'data' , 'git-log.txt' ) , 'utf-8' )
35
+ const gitLog = await readFile ( join ( __dirname , 'data' , 'git-log.txt' ) )
37
36
expect ( parseCommits ( gitLog , remotes . github , options ) ) . to . deep . equal ( commits )
38
37
} )
39
38
40
39
it ( 'parses commits without remote' , async ( ) => {
41
- const gitLog = await readFile ( join ( __dirname , 'data' , 'git-log.txt' ) , 'utf-8' )
40
+ const gitLog = await readFile ( join ( __dirname , 'data' , 'git-log.txt' ) )
42
41
expect ( parseCommits ( gitLog , null , options ) ) . to . deep . equal ( commitsNoRemote )
43
42
} )
44
43
45
44
it ( 'parses bitbucket commits' , async ( ) => {
46
- const gitLog = await readFile ( join ( __dirname , 'data' , 'git-log.txt' ) , 'utf-8' )
45
+ const gitLog = await readFile ( join ( __dirname , 'data' , 'git-log.txt' ) )
47
46
const commits = parseCommits ( gitLog , remotes . bitbucket )
48
47
expect ( commits [ 0 ] . href ) . to . equal ( 'https://bitbucket.org/user/repo/commits/2401ee4706e94629f48830bab9ed5812c032734a' )
49
48
} )
50
49
51
50
it ( 'supports startingCommit option' , async ( ) => {
52
- const gitLog = await readFile ( join ( __dirname , 'data' , 'git-log.txt' ) , 'utf-8' )
51
+ const gitLog = await readFile ( join ( __dirname , 'data' , 'git-log.txt' ) )
53
52
const options = { startingCommit : '17fbef87e82889f01d8257900f7edc55b05918a2' }
54
53
expect ( parseCommits ( gitLog , remotes . github , options ) ) . to . have . length ( 10 )
55
54
} )
56
55
57
56
it ( 'supports ignoreCommitPattern option' , async ( ) => {
58
- const gitLog = await readFile ( join ( __dirname , 'data' , 'git-log.txt' ) , 'utf-8' )
57
+ const gitLog = await readFile ( join ( __dirname , 'data' , 'git-log.txt' ) )
59
58
const options = { ignoreCommitPattern : 'Second commit' }
60
59
const result = parseCommits ( gitLog , remotes . github , options )
61
60
expect ( result ) . to . have . length ( commits . length - 1 )
62
61
expect ( JSON . stringify ( result ) ) . to . not . contain ( 'Second commit' )
63
62
} )
64
63
65
64
it ( 'supports breakingPattern option' , async ( ) => {
66
- const gitLog = await readFile ( join ( __dirname , 'data' , 'git-log.txt' ) , 'utf-8' )
65
+ const gitLog = await readFile ( join ( __dirname , 'data' , 'git-log.txt' ) )
67
66
const options = { breakingPattern : 'Some breaking change' }
68
67
const result = parseCommits ( gitLog , remotes . github , options )
69
68
expect ( result . filter ( c => c . breaking ) ) . to . have . length ( 1 )
70
69
} )
71
70
72
71
it ( 'supports replaceText option' , async ( ) => {
73
- const gitLog = await readFile ( join ( __dirname , 'data' , 'git-log.txt' ) , 'utf-8' )
72
+ const gitLog = await readFile ( join ( __dirname , 'data' , 'git-log.txt' ) )
74
73
const options = {
75
74
replaceText : {
76
75
'breaking' : '**BREAKING**'
@@ -82,7 +81,7 @@ describe('parseCommits', () => {
82
81
83
82
it ( 'invalid startingCommit throws an error' , done => {
84
83
const options = { startingCommit : 'not-a-hash' }
85
- readFile ( join ( __dirname , 'data' , 'git-log.txt' ) , 'utf-8' )
84
+ readFile ( join ( __dirname , 'data' , 'git-log.txt' ) )
86
85
. then ( gitLog => parseCommits ( gitLog , remotes . github , options ) )
87
86
. then ( ( ) => done ( 'Should throw an error' ) )
88
87
. catch ( ( ) => done ( ) )
0 commit comments