333
schangxiang@126.com
2025-09-19 18966e02fb573c7e2bb0c6426ed792b38b910940
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
espower-loader
================================
 
[![Build Status][travis-image]][travis-url]
[![NPM package][npm-image]][npm-url]
[![Dependency Status][depstat-image]][depstat-url]
 
Power Assert feature instrumentor on the fly.
 
 
DESCRIPTION
---------------------------------------
`espower-loader` is a Node.js module loader that enhances target sources on the fly. So you can instrument Power Assert feature without code generation for now.
 
`espower-loader` applies [espower](https://github.com/power-assert-js/espower) to target sources on loading them. `espower` manipulates assertion expression (JavaScript Code) in the form of ECMAScript AST defined in [The ESTree Spec](https://github.com/estree/estree) (formerly known as [Mozilla SpiderMonkey Parser API](https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API)), to instrument power-assert feature into the code. `espower-loader` also adjusts line and column number in stack traces by using [source-map-support](https://github.com/evanw/node-source-map-support) module.
 
Pull-requests, issue reports and patches are always welcomed. See [power-assert](https://github.com/power-assert-js/power-assert) project for more documentation.
 
 
FYI: You may be interested in [intelli-espower-loader](https://github.com/power-assert-js/intelli-espower-loader) to go one step further. With [intelli-espower-loader](https://github.com/power-assert-js/intelli-espower-loader), you don't need to create loader file (like `enable-power-assert.js`). Just define test directory in `package.json` wow!
 
 
EXAMPLE
---------------------------------------
 
You can instrument `power-assert` without code generation (e.g. without using `grunt-espower`,`gulp-espower`, and so on).
 
For mocha, Just add `--require` option.
 
    $ mocha --require ./path/to/enable-power-assert test/some_test_using_powerassert.js
 
where `enable-power-assert.js` somewhere in your project is,
 
```javascript
require('espower-loader')({
    pattern: '{src,test}/**/*.js'
});
```
 
You can specify options for `espower` module explicitly.
 
```javascript
require('espower-loader')({
 
    // directory where match starts with
    cwd: process.cwd(),
 
    // glob pattern using minimatch module
    pattern: '{src,test}/**/*.js',
 
    // options for espower module
    espowerOptions: {
        patterns: [
            'assert(value, [message])',
            'assert.ok(value, [message])',
            'assert.equal(actual, expected, [message])',
            'assert.notEqual(actual, expected, [message])',
            'assert.strictEqual(actual, expected, [message])',
            'assert.notStrictEqual(actual, expected, [message])',
            'assert.deepEqual(actual, expected, [message])',
            'assert.notDeepEqual(actual, expected, [message])',
            'assert.deepStrictEqual(actual, expected, [message])',
            'assert.notDeepStrictEqual(actual, expected, [message])'
        ]
    }
});
```
 
 
OUR SUPPORT POLICY
---------------------------------------
 
We support Node under maintenance. In other words, we stop supporting old Node version when [their maintenance ends](https://github.com/nodejs/LTS).
 
This means that any other environment is not supported.
 
NOTE: If espower-source works in any of the unsupported environments, it is purely coincidental and has no bearing on future compatibility. Use at your own risk.
 
 
CHANGELOG
---------------------------------------
See [CHANGELOG](https://github.com/power-assert-js/espower-loader/blob/master/CHANGELOG.md)
 
 
AUTHOR
---------------------------------------
* [Takuto Wada](https://github.com/twada)
 
 
CONTRIBUTORS
---------------------------------------
* [Eward Song (shepherdwind)](https://github.com/shepherdwind)
* [Haoliang Gao (popomore)](https://github.com/popomore)
 
 
LICENSE
---------------------------------------
Licensed under the [MIT](https://github.com/power-assert-js/espower-loader/blob/master/MIT-LICENSE.txt) license.
 
 
[npm-url]: https://npmjs.org/package/espower-loader
[npm-image]: https://badge.fury.io/js/espower-loader.svg
 
[travis-url]: https://travis-ci.org/power-assert-js/espower-loader
[travis-image]: https://secure.travis-ci.org/power-assert-js/espower-loader.svg?branch=master
 
[depstat-url]: https://gemnasium.com/power-assert-js/espower-loader
[depstat-image]: https://gemnasium.com/power-assert-js/espower-loader.svg