@@ -6,78 +6,125 @@ var RSVP = require('ember-cli/lib/ext/promise');
6
6
var assert = require ( 'ember-cli/tests/helpers/assert' ) ;
7
7
8
8
describe ( 'build plugin' , function ( ) {
9
- var subject ;
9
+ var subject , mockUi , config ;
10
10
11
- before ( function ( ) {
11
+ beforeEach ( function ( ) {
12
12
subject = require ( '../../index' ) ;
13
+ mockUi = {
14
+ messages : [ ] ,
15
+ write : function ( ) { } ,
16
+ writeLine : function ( message ) {
17
+ this . messages . push ( message ) ;
18
+ }
19
+ } ;
13
20
} ) ;
14
21
15
22
it ( 'has a name' , function ( ) {
16
- var result = subject . createDeployPlugin ( {
23
+ var plugin = subject . createDeployPlugin ( {
17
24
name : 'test-plugin'
18
25
} ) ;
19
26
20
- assert . equal ( result . name , 'test-plugin' ) ;
27
+ assert . equal ( plugin . name , 'test-plugin' ) ;
21
28
} ) ;
22
29
23
30
it ( 'implements the correct hooks' , function ( ) {
24
- var result = subject . createDeployPlugin ( {
31
+ var plugin = subject . createDeployPlugin ( {
25
32
name : 'test-plugin'
26
33
} ) ;
27
34
28
- assert . equal ( typeof result . configure , 'function' ) ;
29
- assert . equal ( typeof result . build , 'function' ) ;
35
+ assert . equal ( typeof plugin . configure , 'function' ) ;
36
+ assert . equal ( typeof plugin . build , 'function' ) ;
30
37
} ) ;
31
38
32
39
describe ( 'configure hook' , function ( ) {
33
- it ( 'resolves if config is ok' , function ( ) {
34
- var plugin = subject . createDeployPlugin ( {
35
- name : 'build'
40
+ var plugin , context ;
41
+ describe ( 'without providing config' , function ( ) {
42
+ beforeEach ( function ( ) {
43
+ config = { } ;
44
+ plugin = subject . createDeployPlugin ( {
45
+ name : 'build'
46
+ } ) ;
47
+ context = {
48
+ ui : mockUi ,
49
+ config : config
50
+ } ;
51
+ plugin . beforeHook ( context ) ;
36
52
} ) ;
53
+ it ( 'warns about missing optional config' , function ( ) {
54
+ plugin . configure ( context ) ;
55
+ var messages = mockUi . messages . reduce ( function ( previous , current ) {
56
+ if ( / - M i s s i n g c o n f i g : \s .* , u s i n g d e f a u l t : \s / . test ( current ) ) {
57
+ previous . push ( current ) ;
58
+ }
59
+
60
+ return previous ;
61
+ } , [ ] ) ;
62
+
63
+ assert . equal ( messages . length , 2 ) ;
64
+ } ) ;
65
+
66
+ it ( 'adds default config to the config object' , function ( ) {
67
+ plugin . configure ( context ) ;
68
+ assert . isDefined ( config . build . environment ) ;
69
+ assert . isDefined ( config . build . outputPath ) ;
70
+ } ) ;
71
+ } ) ;
37
72
38
- var context = {
39
- deployment : {
40
- ui : { write : function ( ) { } , writeLine : function ( ) { } } ,
41
- config : {
73
+ describe ( 'with a build environment and outputPath provided' , function ( ) {
74
+ beforeEach ( function ( ) {
75
+ config = {
76
+ build : {
77
+ environment : 'development' ,
78
+ outputPath : 'tmp/dist-deploy'
42
79
}
43
- }
44
- } ;
45
- return assert . isFulfilled ( plugin . configure . call ( plugin , context ) ) ;
80
+ } ;
81
+ plugin = subject . createDeployPlugin ( {
82
+ name : 'build'
83
+ } ) ;
84
+ context = {
85
+ ui : mockUi ,
86
+ config : config
87
+ } ;
88
+ plugin . beforeHook ( context ) ;
89
+ } ) ;
90
+ it ( 'does not warn about missing optional config' , function ( ) {
91
+ plugin . configure ( context ) ;
92
+ var messages = mockUi . messages . reduce ( function ( previous , current ) {
93
+ if ( / - M i s s i n g c o n f i g : \s .* , u s i n g d e f a u l t : \s / . test ( current ) ) {
94
+ previous . push ( current ) ;
95
+ }
96
+
97
+ return previous ;
98
+ } , [ ] ) ;
99
+ assert . equal ( messages . length , 0 ) ;
100
+ } ) ;
46
101
} ) ;
47
102
} ) ;
48
103
49
104
describe ( 'build hook' , function ( ) {
50
- var plugin ;
51
- var context ;
105
+ var plugin , context ;
52
106
53
107
beforeEach ( function ( ) {
54
108
plugin = subject . createDeployPlugin ( {
55
109
name : 'build'
56
110
} ) ;
57
111
58
112
context = {
59
- redisClient : {
60
- upload : function ( ) {
61
- return RSVP . resolve ( 'redis-key' ) ;
62
- }
63
- } ,
64
- tag : 'some-tag' ,
65
- deployment : {
66
- ui : { write : function ( ) { } , writeLine : function ( ) { } } ,
67
- project : { name : function ( ) { return 'test-project' ; } , addons : [ ] , root : 'tests/dummy' } ,
68
- config : {
69
- build : {
70
- buildEnv : 'development' ,
71
- outputPath : 'tmp/dist-deploy' ,
72
- }
113
+ ui : mockUi ,
114
+ project : { name : function ( ) { return 'test-project' ; } , addons : [ ] , root : 'tests/dummy' } ,
115
+ config : {
116
+ build : {
117
+ buildEnv : 'development' ,
118
+ outputPath : 'tmp/dist-deploy' ,
73
119
}
74
120
}
75
121
} ;
122
+ plugin . beforeHook ( context ) ;
76
123
} ) ;
77
124
78
- it ( 'builds the app and returns distDir and distFiles' , function ( done ) {
125
+ it ( 'builds the app and resolves with distDir and distFiles' , function ( done ) {
79
126
this . timeout ( 50000 ) ;
80
- return assert . isFulfilled ( plugin . build . call ( plugin , context ) )
127
+ return assert . isFulfilled ( plugin . build ( context ) )
81
128
. then ( function ( result ) {
82
129
assert . deepEqual ( result , {
83
130
distDir : 'tmp/dist-deploy' ,
0 commit comments