@@ -2,12 +2,53 @@ import fixtures from 'fixturez';
2
2
import * as builds from '../builds' ;
3
3
const f = fixtures ( __dirname ) ;
4
4
5
+ test ( 'builds.getAllDownloadsSlugs' , async ( ) => {
6
+ const cwd = f . copy ( 'with-builds' ) ;
7
+ const downloadedSlugs = await builds . getAllDownloadedSlugs ( cwd ) ;
8
+ expect ( downloadedSlugs . length ) . toBe ( 2 ) ;
9
+ expect ( downloadedSlugs ) . toEqual ( expect . arrayContaining ( [
10
+ 'bitbucket:atlassian/build-stats' ,
11
+ 'travis:boltpkg/bolt'
12
+ ] ) ) ;
13
+ } ) ;
14
+
5
15
test ( 'builds.getBuildDir()' , async ( ) => {
6
16
let cwd = f . copy ( 'testRepo' ) ;
7
17
let dirPath = await builds . getBuildDir ( cwd , 'bitbucket' , 'test' , 'test-repo' ) ;
8
18
expect ( dirPath ) . toMatch ( / t e s t R e p o \/ \. d a t a \/ b i t b u c k e t \/ t e s t \/ t e s t - r e p o \/ b u i l d s / ) ;
9
19
} ) ;
10
20
11
- test . todo ( 'builds.getHistory()' ) ;
12
- test . todo ( 'builds.findLongest()' ) ;
13
- test . todo ( 'builds.toTimeRanges()' ) ;
21
+ test ( 'builds.getHistory()' , async ( ) => {
22
+ const cwd = f . copy ( 'with-builds' ) ;
23
+ const history = await builds . getHistory ( cwd , 'bitbucket' , 'atlassian' , 'build-stats' , {
24
+ branch : '*' ,
25
+ result : '*'
26
+ } ) ;
27
+ expect ( history . length ) . toBe ( 10 ) ;
28
+ } ) ;
29
+ test ( 'builds.findLongest()' , async ( ) => {
30
+ const cwd = f . copy ( 'with-builds' ) ;
31
+ const allBuilds = await builds . getHistory ( cwd , 'bitbucket' , 'atlassian' , 'build-stats' , {
32
+ branch : '*' ,
33
+ result : '*'
34
+ } ) ;
35
+
36
+ const longestBuild = builds . findLongest ( allBuilds ) ;
37
+ expect ( longestBuild . id ) . toBe ( '7' )
38
+ } ) ;
39
+
40
+ test ( 'builds.toTimeRanges()' , async ( ) => {
41
+ const cwd = f . copy ( 'with-builds' ) ;
42
+ const allBuilds = await builds . getHistory ( cwd , 'bitbucket' , 'atlassian' , 'build-stats' , {
43
+ branch : '*' ,
44
+ result : '*'
45
+ } ) ;
46
+
47
+ const ranges = builds . toTimeRanges ( allBuilds , {
48
+ period : 365 , // period of 365 days/ 1 year
49
+ last : 100 // last 100 years
50
+ } ) ;
51
+
52
+ // One of the fixtures build is from 1900, so it should be excluded
53
+ expect ( ranges [ 0 ] . length ) . toBe ( 9 ) ;
54
+ } ) ;
0 commit comments