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