@@ -1016,41 +1016,175 @@ describe('compiler', function() {
1016
1016
} ) ;
1017
1017
1018
1018
describe ( 'for mixins' , function ( ) {
1019
- function verifyMixinIsFoundViaMixinDirs ( sourceFile , mixinDirs ) {
1020
- var appJS = appdir . writeFileSync ( sourceFile , '' ) ;
1019
+ describe ( ' - mixinDirs' , function ( ) {
1020
+ function verifyMixinIsFoundViaMixinDirs ( sourceFile , mixinDirs ) {
1021
+ var appJS = appdir . writeFileSync ( sourceFile , '' ) ;
1021
1022
1022
- var instructions = boot . compile ( {
1023
- appRootDir : appdir . PATH ,
1024
- mixinDirs : mixinDirs
1023
+ var instructions = boot . compile ( {
1024
+ appRootDir : appdir . PATH ,
1025
+ mixinDirs : mixinDirs
1026
+ } ) ;
1027
+
1028
+ expect ( instructions . mixins [ 0 ] . sourceFile ) . to . eql ( appJS ) ;
1029
+ }
1030
+
1031
+ it ( 'supports `mixinDirs` option' , function ( ) {
1032
+ verifyMixinIsFoundViaMixinDirs ( 'custom-mixins/other.js' ,
1033
+ [ './custom-mixins' ] ) ;
1025
1034
} ) ;
1026
1035
1027
- expect ( instructions . mixins [ 0 ] . sourceFile ) . to . eql ( appJS ) ;
1028
- }
1036
+ it ( 'resolves relative path in `mixinDirs` option' , function ( ) {
1037
+ verifyMixinIsFoundViaMixinDirs ( 'custom-mixins/other.js' ,
1038
+ [ './custom-mixins' ] ) ;
1039
+ } ) ;
1029
1040
1030
- it ( 'supports `mixinDirs` option' , function ( ) {
1031
- verifyMixinIsFoundViaMixinDirs ( 'mixins/other.js' , [ './mixins' ] ) ;
1041
+ it ( 'resolves module relative path in `mixinDirs` option' , function ( ) {
1042
+ verifyMixinIsFoundViaMixinDirs ( 'node_modules/custom-mixins/other.js' ,
1043
+ [ 'custom-mixins' ] ) ;
1044
+ } ) ;
1032
1045
} ) ;
1033
1046
1034
- it ( 'resolves relative path in `mixinDirs` option' , function ( ) {
1035
- verifyMixinIsFoundViaMixinDirs ( 'custom-mixins/vehicle.js' ,
1036
- [ './custom-mixins' ] ) ;
1037
- } ) ;
1047
+ describe ( ' - mixinSources' , function ( ) {
1048
+ beforeEach ( function ( ) {
1049
+ appdir . createConfigFilesSync ( { } , { } , {
1050
+ Car : { dataSource : 'db' }
1051
+ } ) ;
1052
+ appdir . writeConfigFileSync ( 'models/car.json' , {
1053
+ name : 'Car' ,
1054
+ mixins : { 'TimeStamps' : { } }
1055
+ } ) ;
1056
+ } ) ;
1057
+
1058
+ function verifyMixinIsFoundViaMixinSources ( sourceFile , mixinSources ) {
1059
+ var appJS = appdir . writeFileSync ( sourceFile , '' ) ;
1060
+
1061
+ var instructions = boot . compile ( {
1062
+ appRootDir : appdir . PATH ,
1063
+ mixinSources : mixinSources
1064
+ } ) ;
1065
+
1066
+ expect ( instructions . mixins [ 0 ] . sourceFile ) . to . eql ( appJS ) ;
1067
+ }
1068
+
1069
+ it ( 'supports `mixinSources` option' , function ( ) {
1070
+ verifyMixinIsFoundViaMixinSources ( 'mixins/time-stamps.js' ,
1071
+ [ './mixins' ] ) ;
1072
+ } ) ;
1073
+
1074
+ it ( 'resolves relative path in `mixinSources` option' , function ( ) {
1075
+ verifyMixinIsFoundViaMixinSources ( 'custom-mixins/time-stamps.js' ,
1076
+ [ './custom-mixins' ] ) ;
1077
+ } ) ;
1078
+
1079
+ it ( 'resolves module relative path in `mixinSources` option' ,
1080
+ function ( ) {
1081
+ verifyMixinIsFoundViaMixinSources (
1082
+ 'node_modules/custom-mixins/time-stamps.js' ,
1083
+ [ 'custom-mixins' ] ) ;
1084
+ } ) ;
1085
+
1086
+ it ( 'supports `mixins` option in `model-config.json`' , function ( ) {
1087
+ appdir . createConfigFilesSync ( { } , { } , {
1088
+ _meta : {
1089
+ mixins : [ './custom-mixins' ]
1090
+ } ,
1091
+ Car : {
1092
+ dataSource : 'db'
1093
+ }
1094
+ } ) ;
1095
+
1096
+ var appJS = appdir . writeFileSync ( 'custom-mixins/time-stamps.js' , '' ) ;
1097
+ var instructions = boot . compile ( appdir . PATH ) ;
1098
+ expect ( instructions . mixins [ 0 ] . sourceFile ) . to . eql ( appJS ) ;
1099
+ } ) ;
1038
1100
1039
- it ( 'resolves module relative path in `mixinDirs` option' , function ( ) {
1040
- verifyMixinIsFoundViaMixinDirs ( 'node_modules/custom-mixins/vehicle.js' ,
1041
- [ 'custom-mixins' ] ) ;
1101
+ it ( 'sets by default `mixinSources` to `mixins` directory' , function ( ) {
1102
+ var appJS = appdir . writeFileSync ( 'mixins/time-stamps.js' , '' ) ;
1103
+ var instructions = boot . compile ( appdir . PATH ) ;
1104
+ expect ( instructions . mixins [ 0 ] . sourceFile ) . to . eql ( appJS ) ;
1105
+ } ) ;
1106
+
1107
+ it ( 'loads only mixins used by models' , function ( ) {
1108
+ var appJS = appdir . writeFileSync ( 'mixins/time-stamps.js' , '' ) ;
1109
+ appdir . writeFileSync ( 'mixins/foo.js' , '' ) ;
1110
+
1111
+ var instructions = boot . compile ( appdir . PATH ) ;
1112
+ expect ( instructions . mixins ) . to . have . length ( 1 ) ;
1113
+ expect ( instructions . mixins [ 0 ] . sourceFile ) . to . eql ( appJS ) ;
1114
+ } ) ;
1115
+
1116
+ it ( 'loads mixins from model using mixin name in JSON file' , function ( ) {
1117
+ var appJS = appdir . writeFileSync ( 'mixins/time-stamps.js' , '' ) ;
1118
+ appdir . writeConfigFileSync ( 'mixins/time-stamps.json' , {
1119
+ name : 'Timestamping'
1120
+ } ) ;
1121
+
1122
+ appdir . writeConfigFileSync ( 'models/car.json' , {
1123
+ name : 'Car' ,
1124
+ mixins : { 'Timestamping' : { } }
1125
+ } ) ;
1126
+
1127
+ var instructions = boot . compile ( appdir . PATH ) ;
1128
+ expect ( instructions . mixins ) . to . have . length ( 1 ) ;
1129
+ expect ( instructions . mixins [ 0 ] . sourceFile ) . to . eql ( appJS ) ;
1130
+ } ) ;
1131
+
1132
+ it ( 'loads mixin only once for dirs common to mixinDirs & mixinSources' ,
1133
+ function ( ) {
1134
+ var appJS = appdir . writeFileSync ( 'custom-mixins/time-stamps.js' , '' ) ;
1135
+
1136
+ var options = {
1137
+ appRootDir : appdir . PATH ,
1138
+ mixinDirs : [ './custom-mixins' ] ,
1139
+ mixinSources : [ './custom-mixins' ]
1140
+ } ;
1141
+
1142
+ var instructions = boot . compile ( options ) ;
1143
+ expect ( instructions . mixins ) . to . have . length ( 1 ) ;
1144
+ expect ( instructions . mixins [ 0 ] . sourceFile ) . to . eql ( appJS ) ;
1145
+ } ) ;
1146
+
1147
+ it ( 'loads mixin from mixinSources, when it is also found in mixinDirs' ,
1148
+ function ( ) {
1149
+ appdir . writeFileSync ( 'mixinDir/time-stamps.js' , '' ) ;
1150
+ var appJS = appdir . writeFileSync ( 'mixinSource/time-stamps.js' , '' ) ;
1151
+
1152
+ var options = {
1153
+ appRootDir : appdir . PATH ,
1154
+ mixinDirs : [ './mixinDir' ] ,
1155
+ mixinSources : [ './mixinSource' ]
1156
+ } ;
1157
+
1158
+ var instructions = boot . compile ( options ) ;
1159
+ expect ( instructions . mixins ) . to . have . length ( 1 ) ;
1160
+ expect ( instructions . mixins [ 0 ] . sourceFile ) . to . eql ( appJS ) ;
1161
+ } ) ;
1162
+
1163
+ it ( 'loads mixin from the most recent mixin definition' , function ( ) {
1164
+ appdir . writeFileSync ( 'mixins1/time-stamps.js' , '' ) ;
1165
+ var mixins2 = appdir . writeFileSync ( 'mixins2/time-stamps.js' , '' ) ;
1166
+
1167
+ var options = {
1168
+ appRootDir : appdir . PATH ,
1169
+ mixinSources : [ './mixins1' , './mixins2' ]
1170
+ } ;
1171
+
1172
+ var instructions = boot . compile ( options ) ;
1173
+ expect ( instructions . mixins ) . to . have . length ( 1 ) ;
1174
+ expect ( instructions . mixins [ 0 ] . sourceFile ) . to . eql ( mixins2 ) ;
1175
+ } ) ;
1042
1176
} ) ;
1043
1177
1044
1178
describe ( 'name normalization' , function ( ) {
1045
1179
var options ;
1046
1180
beforeEach ( function ( ) {
1047
- options = { appRootDir : appdir . PATH , mixinDirs : [ './mixins' ] } ;
1181
+ options = { appRootDir : appdir . PATH , mixinDirs : [ './custom- mixins' ] } ;
1048
1182
1049
- appdir . writeFileSync ( 'mixins/foo.js' , '' ) ;
1050
- appdir . writeFileSync ( 'mixins/time-stamps.js' , '' ) ;
1051
- appdir . writeFileSync ( 'mixins/camelCase.js' , '' ) ;
1052
- appdir . writeFileSync ( 'mixins/PascalCase.js' , '' ) ;
1053
- appdir . writeFileSync ( 'mixins/space name.js' , '' ) ;
1183
+ appdir . writeFileSync ( 'custom- mixins/foo.js' , '' ) ;
1184
+ appdir . writeFileSync ( 'custom- mixins/time-stamps.js' , '' ) ;
1185
+ appdir . writeFileSync ( 'custom- mixins/camelCase.js' , '' ) ;
1186
+ appdir . writeFileSync ( 'custom- mixins/PascalCase.js' , '' ) ;
1187
+ appdir . writeFileSync ( 'custom- mixins/space name.js' , '' ) ;
1054
1188
} ) ;
1055
1189
1056
1190
it ( 'supports classify' , function ( ) {
@@ -1146,15 +1280,15 @@ describe('compiler', function() {
1146
1280
} ) ;
1147
1281
1148
1282
it ( 'extends definition from JSON with same file name' , function ( ) {
1149
- var appJS = appdir . writeFileSync ( 'mixins/foo-bar.js' , '' ) ;
1283
+ var appJS = appdir . writeFileSync ( 'custom- mixins/foo-bar.js' , '' ) ;
1150
1284
1151
- appdir . writeConfigFileSync ( 'mixins/foo-bar.json' , {
1285
+ appdir . writeConfigFileSync ( 'custom- mixins/foo-bar.json' , {
1152
1286
description : 'JSON file name same as JS file name' } ) ;
1153
- appdir . writeConfigFileSync ( 'mixins/FooBar.json' , {
1287
+ appdir . writeConfigFileSync ( 'custom- mixins/FooBar.json' , {
1154
1288
description : 'JSON file name same as normalized name of mixin' } ) ;
1155
1289
1156
1290
var options = { appRootDir : appdir . PATH ,
1157
- mixinDirs : [ './mixins' ] ,
1291
+ mixinDirs : [ './custom- mixins' ] ,
1158
1292
normalization : 'classify' } ;
1159
1293
var instructions = boot . compile ( options ) ;
1160
1294
@@ -1166,7 +1300,6 @@ describe('compiler', function() {
1166
1300
}
1167
1301
] ) ;
1168
1302
} ) ;
1169
-
1170
1303
} ) ;
1171
1304
} ) ;
1172
1305
0 commit comments