├── .babelrc
├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── demo
└── person.js
├── guess.js
├── index.js
├── lib
└── babelrc-util.js
├── package.json
├── test
├── demo_test.js
├── issues
│ ├── 17
│ │ └── index.es6
│ └── 24
│ │ ├── gulpfile.js
│ │ └── index.js
├── lib
│ └── hello.js
├── person_test.js
└── tobe_instrumented
│ ├── babelrc-util-test.js
│ ├── es7_test.js
│ ├── require-esmodule-test.js
│ └── tobe_instrumented_test.js
└── test_loader
└── espower-traceur-loader.js
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["es2015", "stage-3"],
3 | "plugins": ["transform-es2015-modules-commonjs"]
4 | }
5 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ### https://raw.github.com/github/gitignore/408c616ae0ad8f4b8101d8e876b9b67ac6b14059/Node.gitignore
2 |
3 | # Logs
4 | logs
5 | *.log
6 |
7 | # Runtime data
8 | pids
9 | *.pid
10 | *.seed
11 |
12 | # Directory for instrumented libs generated by jscoverage/JSCover
13 | lib-cov
14 |
15 | # Coverage directory used by tools like istanbul
16 | coverage
17 |
18 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
19 | .grunt
20 |
21 | # node-waf configuration
22 | .lock-wscript
23 |
24 | # Compiled binary addons (http://nodejs.org/api/addons.html)
25 | build/Release
26 |
27 | # Dependency directory
28 | # Commenting this out is preferred by some people, see
29 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
30 | node_modules
31 |
32 |
33 | ### https://raw.github.com/github/gitignore/408c616ae0ad8f4b8101d8e876b9b67ac6b14059/Global/JetBrains.gitignore
34 |
35 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
36 |
37 | *.iml
38 |
39 | ## Directory-based project format:
40 | .idea/
41 | # if you remove the above rule, at least ignore the following:
42 |
43 | # User-specific stuff:
44 | # .idea/workspace.xml
45 | # .idea/tasks.xml
46 | # .idea/dictionaries
47 |
48 | # Sensitive or high-churn files:
49 | # .idea/dataSources.ids
50 | # .idea/dataSources.xml
51 | # .idea/sqlDataSources.xml
52 | # .idea/dynamic.xml
53 | # .idea/uiDesigner.xml
54 |
55 | # Gradle:
56 | # .idea/gradle.xml
57 | # .idea/libraries
58 |
59 | # Mongo Explorer plugin:
60 | # .idea/mongoSettings.xml
61 |
62 | ## File-based project format:
63 | *.ipr
64 | *.iws
65 |
66 | ## Plugin-specific files:
67 |
68 | # IntelliJ
69 | out/
70 |
71 | # mpeltonen/sbt-idea plugin
72 | .idea_modules/
73 |
74 | # JIRA plugin
75 | atlassian-ide-plugin.xml
76 |
77 | # Crashlytics plugin (for Android Studio and IntelliJ)
78 | com_crashlytics_export_strings.xml
79 | crashlytics.properties
80 | crashlytics-build.properties
81 |
82 |
83 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: false
2 | language: node_js
3 | node_js:
4 | - 'stable'
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2015 azu
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 | SOFTWARE.
20 |
21 | Includes:
22 |
23 | espower-traceur
24 | https://github.com/yosuke-furukawa/espower-traceur
25 | Copyright (c) 2014 Yosuke Furukawa
26 | Licensed under the MIT license.
27 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # espower-babel [](https://travis-ci.org/power-assert-js/espower-babel)
2 |
3 | power-assert instrumentor for [Babel](https://babeljs.io/ "Babel · The transpiler for writing next generation JavaScript").
4 |
5 | This module is wrapper of [babel-plugin-espower](https://github.com/power-assert-js/babel-plugin-espower "babel-plugin-espower").
6 |
7 | ## :warning: Deprecated :warning:
8 |
9 | espower-babel is deprecated module.
10 |
11 | Please directly use combination of [babel-register](https://www.npmjs.com/package/babel-register "babel-register") and [babel-preset-power-assert](https://github.com/power-assert-js/babel-preset-power-assert "babel-preset-power-assert").
12 |
13 | :heart: We've created migration tool: [migrate-espower-babel-to-babel-preset-power-assert](https://github.com/power-assert-js/migrate-espower-babel-to-babel-preset-power-assert "migrate-espower-babel-to-babel-preset-power-assert").
14 |
15 | `migrate-espower-babel-to-babel-preset-power-assert` migrate babel-register + babel-preset-power-assert from espower-babel.
16 |
17 | ```diff
18 | - espower-babel
19 | + babel-register
20 | + babel-preset-power-assert
21 | ```
22 |
23 | Related Issue: [Deprecated: espower-babel · Issue #27 · power-assert-js/espower-babel](https://github.com/power-assert-js/espower-babel/issues/27 "Deprecated: espower-babel · Issue #27 · power-assert-js/espower-babel")
24 |
25 | ## Purpose
26 |
27 | - Writing ES6 tests with [Babel](http://babeljs.io/)
28 | - Running tests with [power-assert](https://github.com/power-assert-js/power-assert) on the fly!
29 | - No configuration
30 |
31 | ## DESCRIPTION
32 |
33 | `espower-babel` is a Node.js module loader that instruments [power-assert](https://github.com/power-assert-js/power-assert) feature into target ECMAScript6 sources on the fly.
34 |
35 | Please note that `espower-babel` is a beta version product. Pull-requests, issue reports and patches are always welcomed. See [power-assert](http://github.com/twada/power-assert) project for more documentation.
36 |
37 | If you want to use with [Traceur](https://github.com/google/traceur-compiler "Traceur"), please see [yosuke-furukawa/espower-traceur](https://github.com/power-assert-js/espower-traceur "yosuke-furukawa/espower-traceur").
38 |
39 | ## EXAMPLE
40 |
41 | Given `test/demo_test.js`
42 |
43 | ```javascript
44 | let assert = require('power-assert')
45 |
46 | class Person {
47 | constructor(name, age) {
48 | this.name = name
49 | this.age = age
50 | }
51 | getAge() {
52 | return this.age
53 | }
54 | }
55 |
56 | describe("Person", ()=>{
57 | let alice = new Person("alice", 3)
58 | let bob = new Person("bob", 5)
59 | it("#getAge", ()=>{
60 | assert(alice.getAge() === 3)
61 | })
62 | it("#name", ()=>{
63 | assert(alice.name === "alice")
64 | })
65 | // failed
66 | it("#mistake", ()=>{
67 | assert(alice.name === bob.name)
68 | })
69 | })
70 | ```
71 |
72 | Run mocha with `--compilers js:espower-babel/guess`
73 |
74 | ```
75 | $ mocha --compilers js:espower-babel/guess test/demo_test.js
76 |
77 | ․․․
78 |
79 | 2 passing (17ms)
80 | 1 failing
81 |
82 | 1) Person #mistake:
83 | AssertionError: # test/demo_test.js:24
84 |
85 | assert(alice.name === bob.name)
86 | | | | | |
87 | | | | | "bob"
88 | | | | Person{name:"bob",age:5}
89 | | | false
90 | | "alice"
91 | Person{name:"alice",age:3}
92 |
93 | --- [string] bob.name
94 | +++ [string] alice.name
95 | @@ -1,3 +1,5 @@
96 | -bob
97 | +alice
98 | ```
99 |
100 | See the power-assert output appears!
101 |
102 |
103 | ## INSTALL
104 |
105 | $ npm install espower-babel -D
106 |
107 |
108 | ## HOW TO USE
109 |
110 | ### Zero-config mode(for testing)
111 |
112 | Edit: Babel@6 require `.babelrc`. not work on zero config.
113 |
114 | You can use directry [babel-plugin-espower](https://github.com/power-assert-js/babel-plugin-espower "babel-plugin-espower").
115 | We have a simple migration tool(work on specific case) - [migrate-espower-babel-to-babel-plugin-espower](https://github.com/azu/migrate-espower-babel-to-babel-plugin-espower "migrate-espower-babel-to-babel-plugin-espower")
116 |
117 | If your tests are located on `'test/**/*.js'`, just run mocha with `--compilers js:espower-babel/guess`
118 |
119 | $ mocha --compilers js:espower-babel/guess test/**/*.js
120 |
121 |
122 | ### If your tests are not in test dir
123 |
124 | You can set test directory in your `package.json`
125 |
126 | ```json
127 | {
128 | "name": "your-module",
129 | "description": "Your module",
130 | "version": "0.0.1",
131 | "directories": {
132 | "test": "spec/"
133 | },
134 | ...
135 | }
136 | ```
137 |
138 | Then, run mocha with `--compilers js:espower-babel/guess`
139 |
140 | $ mocha --compilers js:espower-babel/guess spec/**/*.js
141 |
142 | Note: `'espower-babel/guess'` is inspired by [intelli-espower-loader](https://github.com/power-assert-js/intelli-espower-loader)
143 |
144 | ### More customization
145 |
146 | If you want to configure more explicitly, put `espower-babel-loader.js` somewhere in your project.
147 |
148 | ```javascript
149 | require('espower-babel')({
150 | // directory where match starts with
151 | cwd: process.cwd(),
152 |
153 | // glob pattern using minimatch module
154 | pattern: 'spec/unit/**/*.js',
155 |
156 | // options for espower module
157 | espowerOptions: {
158 | patterns: [
159 | 'assert(value, [message])',
160 | 'assert.ok(value, [message])',
161 | 'assert.equal(actual, expected, [message])',
162 | 'assert.notEqual(actual, expected, [message])',
163 | 'assert.strictEqual(actual, expected, [message])',
164 | 'assert.notStrictEqual(actual, expected, [message])',
165 | 'assert.deepEqual(actual, expected, [message])',
166 | 'assert.notDeepEqual(actual, expected, [message])'
167 | ]
168 | }
169 | });
170 | ```
171 |
172 | Then, run mocha with `--require` option
173 |
174 | $ mocha --require ./path/to/espower-babel-loader spec/unit/some_test_using_powerassert.js
175 |
176 | ## Babel transform options
177 |
178 | Babel has many transform options.
179 |
180 | - [Options · Babel](https://babeljs.io/docs/usage/options/ "Options · Babel")
181 |
182 | `espower-babel` support babel transform options with [.babelrc](http://babeljs.io/docs/usage/babelrc/ "babelrc").
183 |
184 | `espower-babel` read `${cwd}/.babelrc` if exists.
185 |
186 | Also, you can manually configure babel transform options.
187 |
188 | e.g.)
189 |
190 | ```js
191 | require('espower-babel')({
192 | babelrc: {
193 | "presets": ["es2015"],
194 | "plugins": ["transform-es2015-modules-commonjs"]
195 | }
196 | })
197 | ```
198 |
199 | **Caution**:
200 |
201 | Babel 6 does not transform your code by default.
202 | It means that you must set babel config by `.babelrc` file or `babelrc` option.
203 |
204 | ### Transform all files with Babel **by default**
205 |
206 | Do limit transform files by setting `babelrc`
207 |
208 | e.g.)
209 |
210 | ```js
211 | require('espower-babel')({
212 | babelrc: {
213 | only: [
214 | "src/**/*.js"
215 | ]
216 | }
217 | })
218 | ```
219 |
220 |
221 | ## Contributing
222 |
223 | 1. Fork it!
224 | 2. Create your feature branch: `git checkout -b my-new-feature`
225 | 3. Commit your changes: `git commit -am 'Add some feature'`
226 | 4. Push to the branch: `git push origin my-new-feature`
227 | 5. Submit a pull request :D
228 |
229 | ## License
230 |
231 | MIT
232 |
233 | Includes [yosuke-furukawa/espower-traceur](https://github.com/yosuke-furukawa/espower-traceur "yosuke-furukawa/espower-traceur")
234 |
235 | ## Acknowledgements
236 |
237 | Thanks to [yosuke-furukawa/espower-traceur](https://github.com/yosuke-furukawa/espower-traceur "yosuke-furukawa/espower-traceur").
238 |
--------------------------------------------------------------------------------
/demo/person.js:
--------------------------------------------------------------------------------
1 | /* no transpile, this is */
2 | (function(global){
3 | "use strict";
4 | var Person = function(name, age){
5 | this.name = name;
6 | this.age = age;
7 | };
8 | Person.prototype.getAge = function() {
9 | return this.age;
10 | };
11 | Person.prototype.greet = function() {
12 | return "Hello! I am " + this.name + ". My age is " + this.age;
13 | };
14 | if (module && module.exports) {
15 | module.exports = Person;
16 | } else {
17 | global.Person = Person;
18 | }
19 | }(typeof global !== 'undefined' ? global : this));
20 |
21 |
--------------------------------------------------------------------------------
/guess.js:
--------------------------------------------------------------------------------
1 | const COMPILER_NAME = require('./package.json').name + '/guess';
2 | var path = require('path'),
3 | resolveBabelrc = require('./lib/babelrc-util').resolveBabelrc,
4 | pattern = 'test/**/*.js',
5 | packageData,
6 | testDir,
7 | babelrc,
8 | extension = '.js';
9 |
10 | // When guess.js is loaded in a process
11 | // with an argument like :espower-babel/guess,
12 | // such as `mocha --compilers :espower-babel/guess`,
13 | // override extension with the specified one.
14 | process.argv.forEach(function (arg) {
15 | if (arg.indexOf(':') === -1) {
16 | return;
17 | }
18 |
19 | var parts = arg.split(':');
20 | var ext = parts[0];
21 | var compilerPath = parts[1];
22 |
23 | // We should handle the relative path `./guess`
24 | // to make our very own tests work.
25 | if (compilerPath === './guess') {
26 | var compilerFullPath;
27 |
28 | try {
29 | compilerFullPath = require.resolve(compilerPath);
30 | } catch(err) {}
31 |
32 | if (compilerFullPath !== module.filename) {
33 | return;
34 | }
35 |
36 | compilerPath = COMPILER_NAME;
37 | }
38 |
39 | if (compilerPath !== COMPILER_NAME) {
40 | return;
41 | }
42 |
43 | extension = '.' + ext;
44 | });
45 |
46 | packageData = require(path.join(process.cwd(), 'package.json'));
47 | if (packageData &&
48 | typeof packageData.directories === 'object' &&
49 | typeof packageData.directories.test === 'string') {
50 | testDir = packageData.directories.test;
51 | pattern = testDir + ((testDir.lastIndexOf('/', 0) === 0) ? '' : '/') + '**/*' + extension;
52 | }
53 |
54 | babelrc = resolveBabelrc(process.cwd(), {});
55 |
56 | require('./index')({
57 | cwd: process.cwd(),
58 | pattern: pattern,
59 | babelrc: babelrc,
60 | extension: extension
61 | });
62 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var babel = require("babel-core");
3 | var shouldIgnoreByBabel = require("./lib/babelrc-util").shouldIgnoreByBabel;
4 | var fs = require("fs");
5 | var minimatch = require("minimatch");
6 | var extend = require("xtend");
7 | var createEspowerPlugin = require("babel-plugin-espower/create");
8 | var sourceMapSupport = require("source-map-support");
9 | var extensions = require.extensions,
10 | originalLoader = extensions[".js"];
11 | function espowerBabel(options) {
12 | var separator = (options.pattern.lastIndexOf('/', 0) === 0) ? '' : '/';
13 | var pattern = options.cwd + separator + options.pattern;
14 | var babelrc = options.babelrc || {};
15 | var extension = options.extension || ".js";
16 | // extend babel option
17 | babelrc = extend(babelrc, {
18 | babelrc: false,
19 | sourceMap: "both",
20 | ast: false
21 | });
22 | // attach espower option
23 | var espoweredBabelrc = useEspower(babelrc);
24 | var sourceMaps = {};
25 | // https://github.com/evanw/node-source-map-support
26 | // `sourceMaps` is the cached map object of transform by babel
27 | sourceMapSupport.install({
28 | handleUncaughtExceptions: false,
29 | retrieveSourceMap: function (source) {
30 | var map = sourceMaps && sourceMaps[source];
31 | if (map) {
32 | return {
33 | url: null,
34 | map: map
35 | };
36 | } else {
37 | return null;
38 | }
39 | }
40 | });
41 | function useEspower(babelOptions) {
42 | babelOptions.plugins = babelOptions.plugins || [];
43 | var espowerPluginExists = babelOptions.plugins.some(function (plugin) {
44 | var pluginName = typeof plugin === "string" ? plugin : plugin.key;
45 | return pluginName === "babel-plugin-espower";
46 | });
47 | if (!espowerPluginExists) {
48 | babelOptions.plugins.push(createEspowerPlugin(babel, options.espowerOptions));
49 | }
50 | return babelOptions;
51 | }
52 |
53 | extensions[extension] = function (localModule, filepath) {
54 | var result;
55 | // https://babeljs.io/docs/usage/api/
56 | babelrc.filename = filepath;
57 | // transform the other files
58 | if (shouldIgnoreByBabel(filepath, babelrc)) {
59 | originalLoader(localModule, filepath);
60 | return
61 | }
62 | // transform test files using espower's `pattern` value
63 | if (minimatch(filepath, pattern)) {
64 | result = babel.transform(fs.readFileSync(filepath, "utf-8"), espoweredBabelrc);
65 | sourceMaps[filepath] = result.map;
66 | localModule._compile(result.code, filepath);
67 | } else {
68 | result = babel.transform(fs.readFileSync(filepath, "utf-8"), babelrc);
69 | sourceMaps[filepath] = result.map;
70 | localModule._compile(result.code, filepath);
71 | }
72 | };
73 | }
74 |
75 | module.exports = espowerBabel;
76 |
--------------------------------------------------------------------------------
/lib/babelrc-util.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | var fs = require('fs');
4 | var path = require('path');
5 | var extend = require('xtend');
6 | var util = require('babel-core').util;
7 | /**
8 | * look up ".babelrc" file and merge options.
9 | * @param {string} loc the location of file
10 | * @param {Object} opts the options is merged .babelrc
11 | * @returns {Object}
12 | */
13 | function resolveBabelrc(loc, opts) {
14 | var babelrc;
15 | opts = opts !== undefined ? opts : {};
16 |
17 | try {
18 | babelrc = JSON.parse(fs.readFileSync(path.join(loc, '.babelrc'), 'utf-8'));
19 | opts = extend(babelrc, opts);
20 | } catch (e) {
21 | // not found .babelrc then ignore error
22 | }
23 |
24 | return opts;
25 | }
26 |
27 | /**
28 | * decide ignore or not by Babel's only/ignore options.
29 | * @param filename
30 | * @param babelrc
31 | * @returns {boolean}
32 | */
33 | function shouldIgnoreByBabel(filename, babelrc) {
34 | if (!babelrc.ignore && !babelrc.only) {
35 | return /node_modules/.test(filename);
36 | } else {
37 | var ignore = babelrc.ignore ? util.arrayify(babelrc.ignore, util.regexify) : null;
38 | var only = babelrc.only ? util.arrayify(babelrc.only, util.regexify) : null;
39 | return util.shouldIgnore(filename, ignore, only);
40 | }
41 | }
42 |
43 | module.exports = {
44 | resolveBabelrc: resolveBabelrc,
45 | shouldIgnoreByBabel: shouldIgnoreByBabel
46 | };
47 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "espower-babel",
3 | "description": "power-assert instrumentor for babel",
4 | "keywords": [
5 | "babel",
6 | "power-assert",
7 | "ES6",
8 | "ECMAScript",
9 | "test",
10 | "testing"
11 | ],
12 | "version": "4.0.3",
13 | "homepage": "https://github.com/power-assert-js/espower-babel/",
14 | "repository": {
15 | "type": "git",
16 | "url": "https://github.com/power-assert-js/espower-babel.git"
17 | },
18 | "main": "index.js",
19 | "files": [
20 | "index.js",
21 | "guess.js",
22 | "lib"
23 | ],
24 | "scripts": {
25 | "test:guess": "mocha --require './guess' test/**/*.js",
26 | "test:loader": "mocha --require './test_loader/espower-traceur-loader' test/**/*.js",
27 | "test:extension": "mocha test/issues/17 --compilers es6:./guess",
28 | "test:gulp": "mocha test/issues/24 --compilers js:./guess --timeout 15000",
29 | "test": "npm-run-all --parallel test:*"
30 | },
31 | "directories": {
32 | "test": "test/"
33 | },
34 | "author": "azu",
35 | "license": "MIT",
36 | "bugs": {
37 | "url": "https://github.com/power-assert-js/espower-babel/issues"
38 | },
39 | "dependencies": {
40 | "babel-core": "^6.0.0",
41 | "babel-plugin-espower": "^2.0.0",
42 | "minimatch": "^3.0.0",
43 | "source-map-support": "^0.4.0",
44 | "xtend": "^4.0.0"
45 | },
46 | "devDependencies": {
47 | "babel-plugin-transform-es2015-modules-commonjs": "^6.1.18",
48 | "babel-polyfill": "^6.1.19",
49 | "babel-preset-es2015": "^6.1.18",
50 | "babel-preset-stage-3": "^6.1.18",
51 | "expect.js": "^0.3.1",
52 | "gulp": "^3.9.0",
53 | "gulp-mocha": "^2.2.0",
54 | "mocha": "^2.1.0",
55 | "npm-run-all": "^1.4.0",
56 | "power-assert": "^1.1.0"
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/test/demo_test.js:
--------------------------------------------------------------------------------
1 | let assert = require('power-assert')
2 |
3 | class Person {
4 | constructor(name, age) {
5 | this.name = name
6 | this.age = age
7 | }
8 | getAge() {
9 | return this.age
10 | }
11 | }
12 |
13 | describe("Person", ()=>{
14 | let alice = new Person("alice", 3)
15 | let bob = new Person("bob", 5)
16 | it("#getAge", ()=>{
17 | assert(alice.getAge() === 3)
18 | })
19 | it("#name", ()=>{
20 | assert(alice.name === "alice")
21 | })
22 | // failed
23 | it("#mistake", ()=>{
24 | assert(alice.name === bob.name)
25 | })
26 | })
27 |
--------------------------------------------------------------------------------
/test/issues/17/index.es6:
--------------------------------------------------------------------------------
1 | let assert = require('power-assert')
2 |
3 | describe("Loaded compiler", ()=>{
4 | it("to be defined .es6", ()=>{
5 | assert.ok(require.extensions['.es6'])
6 | })
7 | })
--------------------------------------------------------------------------------
/test/issues/24/gulpfile.js:
--------------------------------------------------------------------------------
1 | /**
2 | * gulpfile.js for ./test/issues/24
3 | */
4 | var gulp = require('gulp');
5 | var mocha = require('gulp-mocha');
6 |
7 | // Since the `--compiers` option is not available in gulp-mocha,
8 | // registering a require hook is needed to make Mocha work with espower-babel.
9 | require('../../../guess');
10 |
11 | gulp.task('test:issue-#24', function() {
12 | // This gulp task is expected to run a espowered Mocha test successfully.
13 | return gulp.src('./test/person_test.js')
14 | .pipe(mocha());
15 | });
16 |
--------------------------------------------------------------------------------
/test/issues/24/index.js:
--------------------------------------------------------------------------------
1 | import assert from 'power-assert';
2 | import { spawn } from 'child_process';
3 |
4 | describe('Gulp', () => {
5 | it('can run a task whose name contains a colon', (done) => {
6 | const gulp = spawn('gulp', [
7 | '--gulpfile',
8 | './test/issues/24/gulpfile.js',
9 | '--cwd',
10 | '.',
11 | 'test:issue-#24'
12 | ]);
13 |
14 | gulp.on('exit', (code) => {
15 | assert(code === 0);
16 | done();
17 | });
18 | });
19 | });
20 |
--------------------------------------------------------------------------------
/test/lib/hello.js:
--------------------------------------------------------------------------------
1 | export default function hello() {
2 | return "hello";
3 | }
--------------------------------------------------------------------------------
/test/person_test.js:
--------------------------------------------------------------------------------
1 | let assert = require("power-assert")
2 | let Person = require("../demo/person")
3 |
4 | describe("Person", ()=>{
5 | let name = "Alice"
6 | let age = 4
7 | let alice = new Person(name, age)
8 | it("alice get age", ()=>{
9 | assert.equal(alice.getAge(), age)
10 | })
11 | it("alice greet", ()=>{
12 | assert.equal(alice.greet(), `Hello! I am ${name}. My age is ${age}`)
13 | })
14 | })
15 |
16 |
--------------------------------------------------------------------------------
/test/tobe_instrumented/babelrc-util-test.js:
--------------------------------------------------------------------------------
1 | // LICENSE : MIT
2 | "use strict";
3 | import assert from "power-assert"
4 | import {shouldIgnoreByBabel} from "../../lib/babelrc-util"
5 |
6 | describe("babelrc-util", function () {
7 | describe("#shouldIgnoreByBabel", function () {
8 | context("when has `only` option", function () {
9 | it("should ignore the other files", function () {
10 | assert(!shouldIgnoreByBabel("lib/a.js", {
11 | only: ["lib/*.js"]
12 | }));
13 | assert(shouldIgnoreByBabel("ignore/a.js", {
14 | only: ["lib/*.js"]
15 | }));
16 | });
17 | });
18 | context("when has `ignore` option", function () {
19 | it("should ignore by the option", function () {
20 | assert(shouldIgnoreByBabel("lib/a.js", {
21 | ignore: ["lib/*.js"]
22 | }));
23 | assert(!shouldIgnoreByBabel("only/a.js", {
24 | ignore: ["lib/*.js"]
25 | }));
26 | });
27 | });
28 | context("when has `ignore` and `only", function () {
29 | it("should follow only -> ignore", function () {
30 | assert(!shouldIgnoreByBabel("lib/a.js", {
31 | only: ["lib/*.js"],
32 | ignore: ["lib/ignore/*.js"]
33 | }));
34 | assert(shouldIgnoreByBabel("lib/ignore/a.js", {
35 | only: ["lib/*.js"],
36 | ignore: ["lib/ignore/*.js"]
37 | }));
38 | assert(shouldIgnoreByBabel("other/a.js", {
39 | only: ["lib/*.js"],
40 | ignore: ["lib/ignore/*.js"]
41 | }));
42 | });
43 | });
44 | });
45 | });
--------------------------------------------------------------------------------
/test/tobe_instrumented/es7_test.js:
--------------------------------------------------------------------------------
1 | require("babel-polyfill")
2 |
3 | let assert = require('power-assert')
4 |
5 | describe("ES7 async/await", ()=>{
6 | it("works", async()=>{
7 |
8 | assert(await Promise.resolve("OK") === "OK")
9 | })
10 | })
11 |
--------------------------------------------------------------------------------
/test/tobe_instrumented/require-esmodule-test.js:
--------------------------------------------------------------------------------
1 | // this test "hello" module which written by ES6 if transform by babel
2 | import assert from "power-assert"
3 | import fn from "../lib/hello"
4 | describe("require-esmodule", ()=> {
5 | it("should return `hello`", ()=> {
6 | assert.equal(fn(), `hello`);
7 | });
8 | });
--------------------------------------------------------------------------------
/test/tobe_instrumented/tobe_instrumented_test.js:
--------------------------------------------------------------------------------
1 | let assert = require('power-assert')
2 | let expect = require("expect.js")
3 |
4 | describe("power-assert message", function(){
5 |
6 | beforeEach(function(){
7 | this.expectPowerAssertMessage = (body, expectedLines) => {
8 | try {
9 | body()
10 | expect().fail("AssertionError should be thrown")
11 | } catch(e) {
12 | expect(e.message.split("\n").slice(2, -1).join("\n")).to.eql(expectedLines)
13 | }
14 | }
15 | })
16 |
17 | it("Nested CallExpression with BinaryExpression: assert((three * (seven * ten)) === three)", function(){
18 | let one = 1
19 | let two = 2
20 | let three = 3
21 | let seven = 7
22 | let ten = 10
23 | let expected =
24 | ` assert(three * (seven * ten) === three)
25 | | | | | | | |
26 | | | | | | | 3
27 | | | | | 10 false
28 | | | 7 70
29 | 3 210
30 |
31 | [number] three
32 | => 3
33 | [number] three * (seven * ten)
34 | => 210`
35 | this.expectPowerAssertMessage(()=>{
36 | assert(three * (seven * ten) === three)
37 | }, expected
38 | )
39 | })
40 |
41 | it("equal with Literal and Identifier: assert.equal(1, minusOne)", function(){
42 | let minusOne = -1
43 | let expected =
44 | ` assert.equal(1, minusOne)
45 | |
46 | -1 `
47 | this.expectPowerAssertMessage(()=>{
48 | assert.equal(1, minusOne)
49 | }, expected
50 | )
51 | })
52 | })
53 |
--------------------------------------------------------------------------------
/test_loader/espower-traceur-loader.js:
--------------------------------------------------------------------------------
1 | require('..')({
2 |
3 | // directory where match starts with
4 | cwd: process.cwd(),
5 |
6 | // glob pattern using minimatch module
7 | pattern: 'test/tobe_instrumented/**/*.js',
8 |
9 | // options for espower module
10 | espowerOptions: {
11 | patterns: [
12 | 'assert(value, [message])',
13 | 'assert.ok(value, [message])',
14 | 'assert.equal(actual, expected, [message])',
15 | 'assert.notEqual(actual, expected, [message])',
16 | 'assert.strictEqual(actual, expected, [message])',
17 | 'assert.notStrictEqual(actual, expected, [message])',
18 | 'assert.deepEqual(actual, expected, [message])',
19 | 'assert.notDeepEqual(actual, expected, [message])'
20 | ]
21 | },
22 | babelrc: {
23 | "presets": ["es2015", "stage-3"],
24 | "plugins": ["transform-es2015-modules-commonjs"]
25 | }
26 | });
27 |
--------------------------------------------------------------------------------