1
1
var util = require ( 'util' ) ;
2
- var path = require ( 'path' )
2
+ var path = require ( 'path' ) ;
3
3
var fs = require ( 'fs' ) ;
4
4
var webdriver = require ( 'selenium-webdriver' ) ;
5
5
var remote = require ( 'selenium-webdriver/remote' ) ;
@@ -25,7 +25,7 @@ var config = {
25
25
showColors : true ,
26
26
includeStackTrace : true
27
27
}
28
- }
28
+ } ;
29
29
30
30
var originalOnComplete = config . jasmineNodeOpts . onComplete ;
31
31
@@ -59,11 +59,57 @@ var printVersion = function () {
59
59
process . exit ( 0 ) ;
60
60
} ;
61
61
62
+ var requirePlugin = function ( name ) {
63
+ util . puts ( 'Loading plugin: ' + name ) ;
64
+ try {
65
+ return require ( name ) ;
66
+ } catch ( e ) {
67
+ if ( e . code === 'MODULE_NOT_FOUND' && e . message . indexOf ( name ) !== - 1 ) {
68
+ throw new Error ( 'Cannot find plugin: ' + name ) ;
69
+ } else {
70
+ throw new Error ( 'Error during loading ' + name + ' plugin: ' + e . message ) ;
71
+ }
72
+ }
73
+ } ;
74
+
75
+ var preprocess = function ( originalPath , preprocessors ) {
76
+ var env = process . env ;
77
+ var tmp = env . TMPDIR || env . TMP || env . TEMP || '/tmp' ;
78
+ var contentPath = tmp + '/' + path . basename ( originalPath ) + '.js' ;
79
+
80
+ var nextPreprocessor = function ( content ) {
81
+ if ( ! preprocessors . length ) {
82
+ return fs . writeFileSync ( contentPath , content ) ;
83
+ }
84
+
85
+ preprocessors . shift ( ) ( originalPath , content , nextPreprocessor ) ;
86
+ } ;
87
+
88
+ nextPreprocessor ( fs . readFileSync ( originalPath ) . toString ( ) ) ;
89
+
90
+ return contentPath ;
91
+ } ;
92
+
62
93
var run = function ( ) {
63
94
if ( config . jasmineNodeOpts . specFolders ) {
64
95
throw new Error ( 'Using config.jasmineNodeOpts.specFolders is deprecated ' +
65
96
'in Protractor 0.6.0. Please switch to config.specs.' ) ;
66
97
}
98
+
99
+ var plugins = [ ] ;
100
+ var preprocessors = [ ] ;
101
+ if ( config . plugins ) {
102
+ plugins = config . plugins ;
103
+ for ( var i = 0 ; i < plugins . length ; ++ i ) {
104
+ var plugin = requirePlugin ( plugins [ i ] ) ;
105
+ for ( key in plugin ) {
106
+ if ( key . substring ( 0 , 13 ) == "preprocessor:" ) {
107
+ preprocessors . push ( plugin [ key ] ) ;
108
+ }
109
+ }
110
+ }
111
+ }
112
+
67
113
// Check the specs.
68
114
// TODO(ralphj): Interpret patterns from the specs, e.g.
69
115
// 'specs/*.js'
@@ -74,7 +120,10 @@ var run = function() {
74
120
if ( ! fs . existsSync ( specs [ i ] ) ) {
75
121
throw new Error ( 'Test file ' + specs [ i ] + ' not found.' ) ;
76
122
}
123
+
124
+ specs [ i ] = preprocess ( specs [ i ] , preprocessors ) ;
77
125
}
126
+
78
127
minijn . addSpecs ( specs ) ;
79
128
80
129
if ( config . sauceUser && config . sauceKey ) {
0 commit comments