2
2
3
3
var assert = require ( 'ember-cli/tests/helpers/assert' ) ;
4
4
5
- function hooks ( plugin ) {
6
- return Object . keys ( plugin ) . filter ( function ( key ) {
7
- return ( key !== 'name' ) && ( key . charAt ( 0 ) !== '_' ) && ( typeof plugin [ key ] === 'function' ) ;
8
- } ) ;
9
- }
10
-
11
5
describe ( 'the index' , function ( ) {
12
- var subject ;
6
+ var subject , mockUi ;
13
7
14
- before ( function ( ) {
8
+ beforeEach ( function ( ) {
15
9
subject = require ( '../../index' ) ;
10
+ mockUi = {
11
+ messages : [ ] ,
12
+ write : function ( ) { } ,
13
+ writeLine : function ( message ) {
14
+ this . messages . push ( message ) ;
15
+ }
16
+ } ;
16
17
} ) ;
17
18
18
19
it ( 'has a name' , function ( ) {
@@ -28,8 +29,8 @@ describe('the index', function() {
28
29
name : 'test-plugin'
29
30
} ) ;
30
31
31
- assert . equal ( hooks ( plugin ) . length , 2 ) ;
32
- assert . sameMembers ( hooks ( plugin ) , [ 'configure' , 'didBuild' ] ) ;
32
+ assert . typeOf ( plugin . configure , 'function' ) ;
33
+ assert . typeOf ( plugin . didBuild , 'function' ) ;
33
34
} ) ;
34
35
35
36
describe ( 'configure hook' , function ( ) {
@@ -39,83 +40,93 @@ describe('the index', function() {
39
40
} ) ;
40
41
41
42
var context = {
42
- deployment : {
43
- ui : {
44
- write : function ( ) { } ,
45
- writeLine : function ( ) { }
46
- } ,
47
- config : {
48
- 'revision-key' : {
49
- type : 'file-hash' ,
50
- filePattern : 'eeee'
51
- }
43
+ ui : mockUi ,
44
+ config : {
45
+ "revision-key" : {
46
+ type : 'file-hash' ,
47
+ filePattern : 'eeee'
52
48
}
53
49
}
54
50
} ;
55
51
56
- return assert . isFulfilled ( plugin . configure . call ( plugin , context ) )
52
+ plugin . beforeHook ( context ) ;
53
+ plugin . configure ( context ) ;
54
+ assert . ok ( true ) ; // it didn't throw
57
55
} ) ;
56
+ it ( 'warns about missing optional config' , function ( ) {
57
+ var plugin = subject . createDeployPlugin ( {
58
+ name : 'revision-key'
59
+ } ) ;
58
60
59
- describe ( 'resolving data from the pipeline' , function ( ) {
60
- it ( 'resolves the config data from the context' , function ( ) {
61
- var plugin = subject . createDeployPlugin ( {
62
- name : 'revision-key'
63
- } ) ;
61
+ var context = {
62
+ ui : mockUi ,
63
+ config : {
64
+ "revision-key" : {
65
+ }
66
+ }
67
+ } ;
64
68
65
- var config = {
66
- type : 'file-hash' ,
67
- filePattern : 'eeee'
68
- } ;
69
- var context = {
70
- deployment : {
71
- ui : {
72
- write : function ( ) { } ,
73
- writeLine : function ( ) { }
74
- } ,
75
- config : {
76
- 'revision-key' : config
77
- }
78
- } ,
69
+ plugin . beforeHook ( context ) ;
70
+ plugin . configure ( context ) ;
71
+
72
+ var messages = mockUi . messages . reduce ( function ( previous , current ) {
73
+ 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 ) ) {
74
+ previous . push ( current ) ;
75
+ }
79
76
80
- distDir : 'some-dir' ,
81
- distFiles : [ 'a.js' , 'b.css' ]
82
- } ;
83
-
84
- return assert . isFulfilled ( plugin . configure . call ( plugin , context ) )
85
- . then ( function ( ) {
86
- assert . typeOf ( config . distDir , 'function' ) ;
87
- assert . typeOf ( config . distFiles , 'function' ) ;
88
- assert . equal ( config . distDir ( context ) , 'some-dir' ) ;
89
- assert . sameMembers ( config . distFiles ( context ) , [ 'a.js' , 'b.css' ] ) ;
90
- } ) ;
77
+ return previous ;
78
+ } , [ ] ) ;
79
+
80
+ assert . equal ( messages . length , 4 ) ;
81
+ } ) ;
82
+
83
+ it ( 'adds default config to the config object' , function ( ) {
84
+ var plugin = subject . createDeployPlugin ( {
85
+ name : 'revision-key'
91
86
} ) ;
87
+
88
+ var context = {
89
+ ui : mockUi ,
90
+ config : {
91
+ "revision-key" : {
92
+ }
93
+ }
94
+ } ;
95
+
96
+ plugin . beforeHook ( context ) ;
97
+ plugin . configure ( context ) ;
98
+
99
+ assert . isDefined ( context . config [ 'revision-key' ] . type ) ;
100
+ assert . isDefined ( context . config [ 'revision-key' ] . filePattern ) ;
92
101
} ) ;
93
102
} ) ;
94
103
95
104
describe ( 'didBuild hook' , function ( ) {
96
- it ( 'returns the revision key data ' , function ( ) {
105
+ it ( 'returns the revisionKey ' , function ( ) {
97
106
var plugin = subject . createDeployPlugin ( {
98
107
name : 'revision-key'
99
108
} ) ;
100
109
101
110
var context = {
102
- deployment : {
103
- ui : {
104
- write : function ( ) { } ,
105
- writeLine : function ( ) { }
106
- } ,
107
- config : {
108
- 'revision-key' : {
109
- type : 'file-hash' ,
110
- filePattern : 'index.html' ,
111
- distDir : 'tests/fixtures' ,
112
- distFiles : [ 'index.html' ] ,
111
+ distDir : 'tests/fixtures' ,
112
+ distFiles : [ 'index.html' ] ,
113
+ ui : mockUi ,
114
+ config : {
115
+ "revision-key" : {
116
+ type : 'file-hash' ,
117
+ filePattern : 'index.html' ,
118
+ distDir : function ( context ) {
119
+ return context . distDir ;
113
120
} ,
114
- }
121
+ distFiles : function ( context ) {
122
+ return context . distFiles ;
123
+ }
124
+ } ,
115
125
}
116
126
} ;
127
+ plugin . beforeHook ( context ) ;
117
128
118
- return assert . isFulfilled ( plugin . didBuild . call ( plugin , context ) )
129
+ return assert . isFulfilled ( plugin . didBuild ( context ) )
119
130
. then ( function ( result ) {
120
131
assert . equal ( result . revisionKey , 'ae1569f72495012cd5e8588e0f2f5d49' ) ;
121
132
} ) ;
0 commit comments