{"id":13739898,"url":"https://github.com/power-assert-js/babel-plugin-espower","last_synced_at":"2025-04-07T07:10:23.076Z","repository":{"id":30480204,"uuid":"34034280","full_name":"power-assert-js/babel-plugin-espower","owner":"power-assert-js","description":"Babel plugin for power-assert","archived":false,"fork":false,"pushed_at":"2023-01-03T15:16:04.000Z","size":1502,"stargazers_count":93,"open_issues_count":9,"forks_count":5,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-31T05:08:41.680Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/power-assert-js.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-16T04:29:16.000Z","updated_at":"2024-07-16T15:15:43.000Z","dependencies_parsed_at":"2023-01-14T17:02:32.295Z","dependency_job_id":null,"html_url":"https://github.com/power-assert-js/babel-plugin-espower","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/power-assert-js%2Fbabel-plugin-espower","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/power-assert-js%2Fbabel-plugin-espower/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/power-assert-js%2Fbabel-plugin-espower/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/power-assert-js%2Fbabel-plugin-espower/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/power-assert-js","download_url":"https://codeload.github.com/power-assert-js/babel-plugin-espower/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247608151,"owners_count":20965952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T04:00:39.158Z","updated_at":"2025-04-07T07:10:23.059Z","avatar_url":"https://github.com/power-assert-js.png","language":"JavaScript","funding_links":[],"categories":["Plugins"],"sub_categories":["Testing"],"readme":"babel-plugin-espower\n================================\n\nBabel plugin for power-assert.\n\n[![Build Status][travis-image]][travis-url]\n[![NPM version][npm-image]][npm-url]\n[![Dependency Status][depstat-image]][depstat-url]\n[![License][license-image]][license-url]\n\n\nDESCRIPTION\n---------------------------------------\n\n`babel-plugin-espower` is a [Babel](https://babeljs.io/) plugin for [power-assert](https://github.com/power-assert-js/power-assert).\n\n`power-assert` provides descriptive assertion messages for your tests, like this.\n\n```\n  1) ES6 demo Destructuring and TemplateLiteral:\n\n      AssertionError:   # test/demo_test.js:7\n\n  assert(`${ alice.name } and ${ bob.name }` === `bob and alice`)\n         |   |     |             |   |       |   |\n         |   |     |             |   |       |   \"bob and alice\"\n         |   |     |             |   \"bob\"   false\n         |   |     \"alice\"       Object{name:\"bob\"}\n         |   Object{name:\"alice\"}\n         \"alice and bob\"\n\n  --- [string] `bob and alice`\n  +++ [string] `${ alice.name } and ${ bob.name }`\n  @@ -1,13 +1,13 @@\n  -bob and alice\n  +alice and bob\n```\n\nPull-requests, issue reports and patches are always welcomed. See [power-assert](https://github.com/power-assert-js/power-assert) project for more documentation.\n\n\nFYI: There's a [babel preset for all power-assert plugins](https://github.com/power-assert-js/babel-preset-power-assert)\n\n\nINSTALL\n---------------------------------------\n\n```\n$ npm install --save-dev babel-plugin-espower\n```\n\n\nCAUTION\n---------------------------------------\n\nBabel7 is incompatible with Babel6. Babel6 is incompatible with Babel5.\n\nFor Babel6, you need to use [the 2.x release of babel-plugin-espower](https://github.com/power-assert-js/babel-plugin-espower/tree/2.x).\n\n```\n$ npm install --save-dev babel-plugin-espower@2\n```\n\nFor Babel5 or lower, you need to use [the 1.x release of babel-plugin-espower](https://github.com/power-assert-js/babel-plugin-espower/tree/1.1.x).\n\n```\n$ npm install --save-dev babel-plugin-espower@1\n```\n\n\nHOW TO USE\n---------------------------------------\n\n\n### via [.babelrc](https://babeljs.io/docs/usage/babelrc/)\n\n```javascript\n{\n  \"presets\": [\n    ...\n  ],\n  \"plugins\": [\n    \"babel-plugin-espower\"\n  ]\n}\n```\n\n```\n$ babel /path/to/test/some_test.js \u003e /path/to/build/some_test.js\n```\n\nFor example, with `@babel/register` module and `.babelrc` above, you can run mocha without code generation steps.\n\n```\n$ $(npm bin)/mocha --require @babel/register test/some_test.js\n```\n\n\n### via [Babel API](https://babeljs.io/docs/usage/api/)\n\n```javascript\nvar babel = require('@babel/core');\nvar jsCode = fs.readFileSync('/path/to/test/some_test.js');\nvar transformed = babel.transform(jsCode, {\n    presets: [...],\n    plugins: ['babel-plugin-espower']\n});\nconsole.log(transformed.code);\n```\n\n\n### via [Babel Require Hook](https://babeljs.io/docs/usage/require/)\n\n```javascript\nrequire('@babel/register')({\n    presets: [...],\n    plugins: ['babel-plugin-espower']\n});\n```\n\nFor example, with `babel_hook.js` above, you can run mocha without code generation steps.\n\n```\n$ $(npm bin)/mocha --require ./babel_hook /path/to/test/demo_test.js\n```\n\n\n### with [babelify](https://github.com/babel/babelify)\n\n```javascript\nvar fs = require('fs');\nvar browserify = require('browserify');\nvar babelify = require('babelify');\nvar glob = require('glob'),\nbrowserify({ entries: glob.sync('./test/*_test.js'), debug: true })\n  .transform(babelify.configure({\n      presets: [...],\n      plugins: ['babel-plugin-espower']\n  }))\n  .bundle()\n  .on('error', function (err) { console.log('Error : ' + err.message); })\n  .pipe(fs.createWriteStream('all_test.js'));\n```\n\n```\n$ $(npm bin)/browserify -d -e ./test/*_test.js -t [ babelify --presets ... --plugins babel-plugin-espower ]\n```\n\n\n### with [babelify](https://github.com/babel/babelify) and [gulp](http://gulpjs.com/)\n\n```javascript\nvar source = require('vinyl-source-stream');\nvar browserify = require('browserify');\nvar glob = require('glob'),\ngulp.task('build_test', function() {\n    var files = glob.sync('./test/*_test.js');\n    var b = browserify({entries: files, debug: true});\n    b.transform(babelify.configure({\n        presets: [...],\n        plugins: ['babel-plugin-espower']\n    }));\n    return b.bundle()\n        .pipe(source('all_test.js'))\n        .pipe(gulp.dest('./build'));\n});\n```\n\n\n### with [babelify](https://github.com/babel/babelify) and [Karma](https://karma-runner.github.io)\n\n```javascript\nmodule.exports = function(config) {\n  config.set({\n    frameworks: ['mocha', 'browserify'],\n    files: [\n      \"test/**/*.js\"\n    ],\n    preprocessors: {\n      \"test/**/*.js\": \"browserify\"\n    },\n    browserify: {\n      debug: true,\n      transform: [\n        [\n          'babelify', {\n            presets: [...],\n            plugins: ['babel-plugin-espower']\n          }\n        ]\n      ]\n    },\n    // ...\n```\n\n\nEXAMPLE\n---------------------------------------\n\n\nFor given test file `test/demo_test.js` below,\n\n```javascript\nimport assert from 'power-assert';\n\ndescribe('ES6 demo', () =\u003e {\n\n    it('Destructuring and TemplateLiteral', () =\u003e {\n        let [alice, bob] = [ { name: 'alice' }, { name: 'bob' } ];\n        assert(`${alice.name} and ${bob.name}` === `bob and alice`);\n    });\n\n    it('ArrowFunctionExpression and SpreadElement', () =\u003e {\n        let seven = 7, ary = [4, 5];\n        assert(seven === ((v, i) =\u003e v + i)(...[...ary]));\n    });\n\n    it('Enhanced Object Literals', () =\u003e {\n        let name = 'bobby';\n        assert.deepEqual({\n            name,\n            [ `${name}'s greet` ]: `Hello, I'm ${name}`\n        }, null);\n    });\n\n});\n```\n\nprepare `babel_hook.js` to transform tests.\n\n```javascript\n{\n  \"presets\": [\n    ...\n  ],\n  \"plugins\": [\n    \"babel-plugin-espower\"\n  ]\n}\n```\n\nRun `mocha` with `--require @babel/register` option. You will see the power-assert output appears.\n\n```\n$ $(npm bin)/mocha --require @babel/register test/demo_test.js\n\n  ES6 demo\n    1) Destructuring and TemplateLiteral\n    2) ArrowFunctionExpression and SpreadElement\n    3) Enhanced Object Literals\n\n\n  0 passing\n  3 failing\n\n  1) ES6 demo Destructuring and TemplateLiteral:\n\n      AssertionError:   # test/demo_test.js:7\n\n  assert(`${ alice.name } and ${ bob.name }` === `bob and alice`)\n         |   |     |             |   |       |   |\n         |   |     |             |   |       |   \"bob and alice\"\n         |   |     |             |   \"bob\"   false\n         |   |     \"alice\"       Object{name:\"bob\"}\n         |   Object{name:\"alice\"}\n         \"alice and bob\"\n\n  --- [string] `bob and alice`\n  +++ [string] `${ alice.name } and ${ bob.name }`\n  @@ -1,13 +1,13 @@\n  -bob and alice\n  +alice and bob\n\n      at Context.\u003canonymous\u003e (test/demo_test.js:19:28)\n\n  2) ES6 demo ArrowFunctionExpression and SpreadElement:\n\n      AssertionError:   # test/demo_test.js:12\n\n  assert(seven === ((v, i) =\u003e v + i)(...[...ary]))\n         |     |   |                    |   |\n         |     |   |                    |   [4,5]\n         |     |   9                    [4,5]\n         7     false\n\n  [number] ((v, i) =\u003e v + i)(...[...ary])\n  =\u003e 9\n  [number] seven\n  =\u003e 7\n\n      at Context.\u003canonymous\u003e (test/demo_test.js:29:28)\n\n  3) ES6 demo Enhanced Object Literals:\n     AssertionError:   # test/demo_test.js:17\n\n  assert.deepEqual({name,[`${ name }'s greet`]: `Hello, I'm ${ name }`}, null)\n                   |      |   |                 |              |\n                   |      |   |                 |              \"bobby\"\n                   |      |   \"bobby\"           \"Hello, I'm bobby\"\n                   |      \"bobby's greet\"\n                   Object{name:\"bobby\",\"bobby's greet\":\"Hello, I'm bobby\"}\n\n      at Context.\u003canonymous\u003e (test/demo_test.js:40:29)\n```\n\n\nCUSTOMIZE\n---------------------------------------\n\n### by plugin options\n\nYou can customize configs such as assertion patterns via [.babelrc](https://babeljs.io/docs/usage/babelrc/)\n\n```javascript\n{\n  \"presets\": [\n    ...\n  ],\n  \"plugins\": [\n    [\"babel-plugin-espower\", {\n      \"embedAst\": true,\n      \"patterns\": [\n        \"assert.isNull(object, [message])\",\n        \"assert.same(actual, expected, [message])\",\n        \"assert.near(actual, expected, delta, [message])\"\n      ]\n    }]\n  ]\n}\n```\n\nor via [Require Hook](https://babeljs.io/docs/usage/require/).\n\n```javascript\nrequire('@babel/register')({\n    presets: [...],\n    plugins: [\n        ['babel-plugin-espower', {\n            embedAst: true,\n            patterns: [\n                'assert.isNull(object, [message])',\n                'assert.same(actual, expected, [message])',\n                'assert.near(actual, expected, delta, [message])'\n            ]\n        }]\n    ]\n});\n```\n\nor via [Babel API](https://babeljs.io/docs/usage/api/),\n\n```javascript\nvar babel = require('@babel/core');\nvar jsCode = fs.readFileSync('/path/to/test/some_test.js');\nvar transformed = babel.transform(jsCode, {\n    presets: [...],\n    plugins: [\n        ['babel-plugin-espower', {\n            embedAst: true,\n            patterns: [\n                'assert.isNull(object, [message])',\n                'assert.same(actual, expected, [message])',\n                'assert.near(actual, expected, delta, [message])'\n            ]\n        }]\n    ]\n});\nconsole.log(transformed.code);\n```\n\n#### options\n\n| type     | default value       |\n|:---------|:--------------------|\n| `object` | objects shown below |\n\nConfiguration options for `babel-plugin-espower`. If not passed, default options will be used (return value of `defaultOptions()` with default `embedAst`, `visitorKeys`, `astWhiteList`, `path`, `sourceRoot` and `sourceMap`. `visitorKeys` is value of `babel.types.VISITOR_KEYS`. `astWhiteList` is value of `babel.types.BUILDER_KEYS`. `path` is filename passed to babel. `sourceRoot` is be return value of `process.cwd()`, `sourceMap` is babel's internal SourceMap object).\n\n```javascript\n{\n    patterns: [\n        'assert(value, [message])',\n        'assert.ok(value, [message])',\n        'assert.equal(actual, expected, [message])',\n        'assert.notEqual(actual, expected, [message])',\n        'assert.strictEqual(actual, expected, [message])',\n        'assert.notStrictEqual(actual, expected, [message])',\n        'assert.deepEqual(actual, expected, [message])',\n        'assert.notDeepEqual(actual, expected, [message])',\n        'assert.deepStrictEqual(actual, expected, [message])',\n        'assert.notDeepStrictEqual(actual, expected, [message])'\n    ],\n    embedAst: true,\n    visitorKeys: babel.types.VISITOR_KEYS,\n    astWhiteList: babel.types.BUILDER_KEYS,\n    sourceRoot: process.cwd(),\n    path: file.opts.filename,\n    sourceMap: file.inputMap ? file.inputMap.toObject() : false\n}\n```\n\n#### options.embedAst\n\nIf you want to use non-ECMASCript-standard features such as JSX tags in your `assert()`, you should set `embedAst` option to `true`.\n\n```js\nassert(shallow(\u003cFoo /\u003e).is('.foo'));\n```\n\n\nCHANGELOG\n---------------------------------------\nSee [CHANGELOG](https://github.com/power-assert-js/babel-plugin-espower/blob/master/CHANGELOG.md)\n\n\nAUTHOR\n---------------------------------------\n* [Takuto Wada](https://github.com/twada)\n\n\nCONTRIBUTORS\n---------------------------------------\n* [James Talmage (jamestalmage)](https://github.com/jamestalmage)\n\n\nOUR SUPPORT POLICY\n---------------------------------------\n\nWe support Node under maintenance. In other words, we stop supporting old Node version when [their maintenance ends](https://github.com/nodejs/LTS).\n\nThis means that any other environment is not supported.\n\nNOTE: If babel-plugin-espower works in any of the unsupported environments, it is purely coincidental and has no bearing on future compatibility. Use at your own risk.\n\n\nLICENSE\n---------------------------------------\nLicensed under the [MIT](https://github.com/power-assert-js/babel-plugin-espower/blob/master/LICENSE) license.\n\n\n[npm-url]: https://npmjs.org/package/babel-plugin-espower\n[npm-image]: https://badge.fury.io/js/babel-plugin-espower.svg\n\n[travis-url]: https://travis-ci.org/power-assert-js/babel-plugin-espower\n[travis-image]: https://secure.travis-ci.org/power-assert-js/babel-plugin-espower.svg?branch=master\n\n[depstat-url]: https://gemnasium.com/power-assert-js/babel-plugin-espower\n[depstat-image]: https://gemnasium.com/power-assert-js/babel-plugin-espower.svg\n\n[license-url]: https://github.com/power-assert-js/babel-plugin-espower/blob/master/LICENSE\n[license-image]: https://img.shields.io/badge/license-MIT-brightgreen.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpower-assert-js%2Fbabel-plugin-espower","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpower-assert-js%2Fbabel-plugin-espower","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpower-assert-js%2Fbabel-plugin-espower/lists"}