@@ -11,6 +11,7 @@ Babel plugin for power-assert.
11
11
12
12
DESCRIPTION
13
13
---------------------------------------
14
+
14
15
` babel-plugin-espower ` is a [ Babel] ( http://babeljs.io/ ) plugin for [ power-assert] ( http://github.com/power-assert-js/power-assert ) .
15
16
16
17
` power-assert ` provides descriptive assertion messages for your tests, like this.
@@ -46,20 +47,35 @@ $ npm install --save-dev babel-plugin-espower
46
47
```
47
48
48
49
49
- HOW TO USE
50
+ CAUTION
50
51
---------------------------------------
51
52
52
-
53
- ### via [ Babel CLI] ( http://babeljs.io/docs/usage/cli/ )
53
+ Babel6 is incompatible with Babel5. For Babel 5 or lower, you need to use the 1.x release of babel-plugin-espower.
54
54
55
55
```
56
- $ $( npm bin)/babel --plugins babel-plugin-espower /path/to/test/some_test.js > /path/to/build/some_test.js
56
+ $ npm install --save-dev babel-plugin-espower@1.1.0
57
57
```
58
58
59
- or shortly,
59
+
60
+ HOW TO USE
61
+ ---------------------------------------
62
+
63
+
64
+ ### via [ .babelrc] ( http://babeljs.io/docs/usage/babelrc/ )
65
+
66
+ ``` javascript
67
+ {
68
+ " presets" : [
69
+ ...
70
+ ],
71
+ " plugins" : [
72
+ " babel-plugin-espower"
73
+ ]
74
+ }
75
+ ```
60
76
61
77
```
62
- $ $(npm bin)/ babel --plugins espower /path/to/test/some_test.js > /path/to/build/some_test.js
78
+ $ babel /path/to/test/some_test.js > /path/to/build/some_test.js
63
79
```
64
80
65
81
@@ -69,6 +85,7 @@ $ $(npm bin)/babel --plugins espower /path/to/test/some_test.js > /path/to/build
69
85
var babel = require (' babel-core' );
70
86
var jsCode = fs .readFileSync (' /path/to/test/some_test.js' );
71
87
var transformed = babel .transform (jsCode, {
88
+ presets: [... ],
72
89
plugins: [' babel-plugin-espower' ]
73
90
});
74
91
console .log (transformed .code );
@@ -78,10 +95,9 @@ console.log(transformed.code);
78
95
### via [ Babel Require Hook] ( http://babeljs.io/docs/usage/require/ )
79
96
80
97
``` javascript
81
- require (' babel/register' )({
82
- only: / test\/ tobe_instrumented/ ,
83
- plugins: [' babel-plugin-espower' ],
84
- extensions: [' .es6' , ' .js' ]
98
+ require (' babel-register' )({
99
+ presets: [... ],
100
+ plugins: [' babel-plugin-espower' ]
85
101
});
86
102
```
87
103
@@ -100,14 +116,17 @@ var browserify = require('browserify');
100
116
var babelify = require (' babelify' );
101
117
var glob = require (' glob' ),
102
118
browserify ({ entries: glob .sync (' ./test/*_test.js' ), debug: true })
103
- .transform (babelify .configure ({ plugins: [' babel-plugin-espower' ] }))
119
+ .transform (babelify .configure ({
120
+ presets: [... ],
121
+ plugins: [' babel-plugin-espower' ]
122
+ }))
104
123
.bundle ()
105
124
.on (' error' , function (err ) { console .log (' Error : ' + err .message ); })
106
125
.pipe (fs .createWriteStream (' all_test.js' ));
107
126
```
108
127
109
128
```
110
- $ $(npm bin)/browserify -d -e ./test/*_test.js -t [ babelify --plugins babel-plugin-espower ]
129
+ $ $(npm bin)/browserify -d -e ./test/*_test.js -t [ babelify --presets ... -- plugins babel-plugin-espower ]
111
130
```
112
131
113
132
@@ -121,6 +140,7 @@ gulp.task('build_test', function() {
121
140
var files = glob .sync (' ./test/*_test.js' );
122
141
var b = browserify ({entries: files, debug: true });
123
142
b .transform (babelify .configure ({
143
+ presets: [... ],
124
144
plugins: [' babel-plugin-espower' ]
125
145
}));
126
146
return b .bundle ()
@@ -145,7 +165,12 @@ module.exports = function(config) {
145
165
browserify: {
146
166
debug: true ,
147
167
transform: [
148
- [' babelify' , {plugins: [' babel-plugin-espower' ]}]
168
+ [
169
+ ' babelify' , {
170
+ presets: [... ],
171
+ plugins: [' babel-plugin-espower' ]
172
+ }
173
+ ]
149
174
]
150
175
},
151
176
// ...
@@ -156,7 +181,7 @@ EXAMPLE
156
181
---------------------------------------
157
182
158
183
159
- For given test file ` demo_test .js ` below,
184
+ For given test file ` test / demo_test .js ` below,
160
185
161
186
` ` ` javascript
162
187
import assert from ' power-assert' ;
@@ -184,16 +209,19 @@ describe('ES6 demo', () => {
184
209
});
185
210
` ` `
186
211
187
- Run ` babel ` with ` -- plugins espower ` to transform tests.
212
+ prepare ` babel_hook . js ` to transform tests.
188
213
189
- ` ` `
190
- $ $ (npm bin)/ babel -- plugins espower / path/ to/ test/ demo_test .js > / path/ to/ build/ demo_test .js
214
+ ` ` ` javascript
215
+ require (' babel-register' )({
216
+ presets: [... ], // presets of your choice
217
+ plugins: [' babel-plugin-espower' ]
218
+ });
191
219
` ` `
192
220
193
- Then run . You will see the power-assert output appears.
221
+ Run ` mocha ` with ` -- require ` option . You will see the power-assert output appears.
194
222
195
223
` ` `
196
- $ $ (npm bin)/ mocha / path / to / build / demo_test .js
224
+ $ $ (npm bin)/ mocha -- require . / babel_hook test / demo_test .js
197
225
198
226
ES6 demo
199
227
1 ) Destructuring and TemplateLiteral
@@ -222,7 +250,7 @@ $ $(npm bin)/mocha /path/to/build/demo_test.js
222
250
- bob and alice
223
251
+ alice and bob
224
252
225
- at Context.< anonymous> (build / demo_test .js : 19 : 28 )
253
+ at Context.< anonymous> (test / demo_test .js : 19 : 28 )
226
254
227
255
2 ) ES6 demo ArrowFunctionExpression and SpreadElement:
228
256
@@ -239,7 +267,7 @@ $ $(npm bin)/mocha /path/to/build/demo_test.js
239
267
[number] seven
240
268
=> 7
241
269
242
- at Context.< anonymous> (build / demo_test .js : 29 : 28 )
270
+ at Context.< anonymous> (test / demo_test .js : 29 : 28 )
243
271
244
272
3 ) ES6 demo Enhanced Object Literals:
245
273
AssertionError: # test/ demo_test .js : 17
@@ -251,7 +279,7 @@ $ $(npm bin)/mocha /path/to/build/demo_test.js
251
279
| " bobby's greet"
252
280
Object {name: " bobby" ," bobby's greet" : " Hello, I'm bobby" }
253
281
254
- at Context.< anonymous> (build / demo_test .js : 40 : 29 )
282
+ at Context.< anonymous> (test / demo_test .js : 40 : 29 )
255
283
` ` `
256
284
257
285
@@ -267,6 +295,7 @@ var babel = require('babel-core');
267
295
var createEspowerPlugin = require (' babel-plugin-espower/create' );
268
296
var jsCode = fs .readFileSync (' /path/to/test/some_test.js' );
269
297
var transformed = babel .transform (jsCode, {
298
+ presets: [... ],
270
299
plugins: [
271
300
createEspowerPlugin (babel, {
272
301
patterns: [
@@ -284,8 +313,8 @@ or via [Require Hook](http://babeljs.io/docs/usage/require/).
284
313
285
314
` ` ` javascript
286
315
var createEspowerPlugin = require (' babel-plugin-espower/create' );
287
- require (' babel/ register' )({
288
- only : / test \/ tobe_instrumented / ,
316
+ require (' babel- register' )({
317
+ presets : [ ... ] ,
289
318
plugins: [
290
319
createEspowerPlugin (babel, {
291
320
patterns: [
@@ -294,8 +323,7 @@ require('babel/register')({
294
323
' assert.near(actual, expected, delta, [message])'
295
324
]
296
325
})
297
- ],
298
- extensions: [' .es6' , ' .js' ]
326
+ ]
299
327
});
300
328
` ` `
301
329
0 commit comments