diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-05-28 00:38:50 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-05-28 00:40:43 +0200 |
commit | 7fff4499fd915bcea3fa93b1aa8b35f4fe7a6027 (patch) | |
tree | 6de9a1aebd150a23b7f8c273ec657a5d0a18fe3e /node_modules/@ava | |
parent | 963b7a41feb29cc4be090a2446bdfe0c1f1bcd81 (diff) |
add linting (and some initial fixes)
Diffstat (limited to 'node_modules/@ava')
30 files changed, 1464 insertions, 0 deletions
diff --git a/node_modules/@ava/babel-plugin-throws-helper/index.js b/node_modules/@ava/babel-plugin-throws-helper/index.js new file mode 100644 index 000000000..e370480f1 --- /dev/null +++ b/node_modules/@ava/babel-plugin-throws-helper/index.js @@ -0,0 +1,70 @@ +'use strict'; + +module.exports = babelCore => { + const t = babelCore.types; + const wrapArg = babelCore.template('(START(t, ASSERTION, FILE, LINE), END(t, ARG))'); + const helpers = babelCore.template(`function START(t, assertion, file, line) { + if (t._throwsArgStart) { + t._throwsArgStart(assertion, file, line); + } +} + +function END(t, arg) { + if (t._throwsArgEnd) { + t._throwsArgEnd(); + } + + return arg; +}`); + + const assertionVisitor = { + CallExpression(path, state) { + const callee = path.get('callee'); + if (!callee.isMemberExpression() || !callee.get('object').isIdentifier({name: 't'}) || !callee.get('property').isIdentifier()) { + return; + } + + const assertion = callee.get('property').get('name').node; + if (assertion !== 'throws' && assertion !== 'notThrows') { + return; + } + + const arg0 = path.node.arguments[0]; + if (!(arg0 && arg0.loc && (typeof arg0.start === 'number') && (typeof arg0.end === 'number'))) { + return; + } + + // Wrap the argument expression, so that the stack trace of the assertion + // isn't affected. + path.node.arguments[0] = wrapArg(Object.assign({ + ARG: arg0, + ASSERTION: t.stringLiteral(assertion), + FILE: t.stringLiteral(state.file.opts.filename), + LINE: t.numericLiteral(arg0.loc.start.line) + }, this.installHelper())).expression; + } + }; + + return { + visitor: { + Program(path, state) { + const START = t.identifier(path.scope.generateUid('avaThrowsHelperStart')); + const END = t.identifier(path.scope.generateUid('avaThrowsHelperEnd')); + const helperIdentifiers = {START, END}; + + let created = false; + path.traverse(assertionVisitor, { + installHelper() { + if (!created) { + created = true; + path.unshiftContainer('body', helpers(helperIdentifiers)); + } + + return helperIdentifiers; + }, + file: state.file + }); + } + } + }; +}; diff --git a/node_modules/@ava/babel-plugin-throws-helper/license b/node_modules/@ava/babel-plugin-throws-helper/license new file mode 100644 index 000000000..ad5d021ed --- /dev/null +++ b/node_modules/@ava/babel-plugin-throws-helper/license @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) James Talmage <james@talmage.io> (github.com/jamestalmage) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/node_modules/@ava/babel-plugin-throws-helper/package.json b/node_modules/@ava/babel-plugin-throws-helper/package.json new file mode 100644 index 000000000..83dbf4659 --- /dev/null +++ b/node_modules/@ava/babel-plugin-throws-helper/package.json @@ -0,0 +1,35 @@ +{ + "name": "@ava/babel-plugin-throws-helper", + "version": "2.0.0", + "description": "Babel plugin for protecting against improper use of `t.throws()` in AVA", + "license": "MIT", + "repository": "avajs/babel-plugin-throws-helper", + "author": { + "name": "James Talmage", + "email": "james@talmage.io", + "url": "github.com/jamestalmage" + }, + "engines": { + "node": ">=4" + }, + "scripts": { + "test": "xo && ava", + "preversion": "WRITE_EXAMPLES=1 npm run test && git add example-output.md" + }, + "files": [ + "index.js" + ], + "keywords": [ + "babel-plugin", + "babel", + "helper", + "ava", + "assertion", + "throws" + ], + "devDependencies": { + "ava": "^0.18.2", + "babel-core": "^6.7.5", + "xo": "^0.17.0" + } +} diff --git a/node_modules/@ava/babel-plugin-throws-helper/readme.md b/node_modules/@ava/babel-plugin-throws-helper/readme.md new file mode 100644 index 000000000..faa91d49d --- /dev/null +++ b/node_modules/@ava/babel-plugin-throws-helper/readme.md @@ -0,0 +1,33 @@ +# babel-plugin-throws-helper [](https://travis-ci.org/avajs/babel-plugin-throws-helper) + +> Babel plugin for protecting against improper use of `t.throws()` in [AVA](https://ava.li) + +Probably not useful except as an internal plugin for the AVA test runner. + +[Genesis of the idea.](https://github.com/sindresorhus/eslint-plugin-ava/issues/75) + +## Issue + +> I've seen a lot of incorrect use of the throws assertion in other test runner and even done the mistake myself sometimes. Now I'm beginning to see it with AVA too, so would be nice to be preemptive about it. +> +> People don't realize they need to wrap their call in a function, so many end up doing `t.throws(foo())` instead of `t.throws(() => foo());`. It's an easy mistake to make. + +The difficulty is that `t.throws(foo())` is allowed if `foo()` returns a promise or a function. There is no good way to differentiate between the two at runtime. So providing a good error message is going to take some AST transform magic. + + +## Solution + +See [`example-output.md`](example-output.md) for the transformation this plugin performs. + +The example output can be generated by calling: + +``` +$ WRITE_EXAMPLES=1 ava +``` + +Contributors should not commit new examples. They will be regenerated as part of the release process. + + +## License + +MIT © [James Talmage](https://github.com/jamestalmage) diff --git a/node_modules/@ava/babel-preset-stage-4/index.js b/node_modules/@ava/babel-preset-stage-4/index.js new file mode 100644 index 000000000..823db53ef --- /dev/null +++ b/node_modules/@ava/babel-preset-stage-4/index.js @@ -0,0 +1,9 @@ +'use strict'; +/* eslint-disable import/no-dynamic-require */ +function buildPreset() { + const plugins = require(`./plugins/best-match`) + .map(module => require(module)); + + return {plugins}; +} +module.exports = buildPreset; diff --git a/node_modules/@ava/babel-preset-stage-4/license b/node_modules/@ava/babel-preset-stage-4/license new file mode 100644 index 000000000..060edd7f2 --- /dev/null +++ b/node_modules/@ava/babel-preset-stage-4/license @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) Mark Wubben <mark@novemberborn.net> (novemberborn.net) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/node_modules/@ava/babel-preset-stage-4/node_modules/package-hash/LICENSE b/node_modules/@ava/babel-preset-stage-4/node_modules/package-hash/LICENSE new file mode 100644 index 000000000..ee1e36789 --- /dev/null +++ b/node_modules/@ava/babel-preset-stage-4/node_modules/package-hash/LICENSE @@ -0,0 +1,14 @@ +ISC License (ISC) +Copyright (c) 2016, Mark Wubben + +Permission to use, copy, modify, and/or distribute this software for any purpose +with or without fee is hereby granted, provided that the above copyright notice +and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. diff --git a/node_modules/@ava/babel-preset-stage-4/node_modules/package-hash/README.md b/node_modules/@ava/babel-preset-stage-4/node_modules/package-hash/README.md new file mode 100644 index 000000000..211a1b6e0 --- /dev/null +++ b/node_modules/@ava/babel-preset-stage-4/node_modules/package-hash/README.md @@ -0,0 +1,72 @@ +# package-hash + +Generates a hash for an installed npm package, useful for salting caches. +[AVA](https://github.com/sindresorhus/ava) for example caches precompiled test +files. It generates a salt for its cache based on the various packages that are +used when compiling the test files. + +`package-hash` can generate an appropriate hash based on the package location +(on disk) and the `package.json` file. This hash is salted with a hash +for the `package-hash` itself. + +`package-hash` can detect when the package-to-be-hashed is a Git repository. In +the AVA example this is useful when you're debugging one of the packages used to +compile the test files. You can clone it locally and use `npm link` so AVA can +find the clone. The hash will include the HEAD (`.git/HEAD`) and its +corresponding ref (e.g. `.git/refs/heads/master`), any packed refs +(`.git/packed-refs`), as well as the diff (`git diff`) for any non-committed +changes. This makes it really easy to test your changes without having to +explicitly clear the cache in the parent project. + +## Installation + +```console +$ npm install --save package-hash +``` + +## Usage + +```js +const sync = require('package-hash').sync + +const hash = sync(require.resolve('babel-core/package.json')) +``` + +`sync()` can be called with a directory or file path. File paths are translated +to directories using +[`path.dirname()`](https://nodejs.org/api/path.html#path_path_dirname_p). The +path must exist. A `package.json` must exist within the directory. + +To get the path to an npm package it's best to use +`require.resolve('the-name/package.json')`, since `require.resolve('the-name')` +may resolve to a subdirectory of the package. + +You can provide multiple paths: + +```js +const hash = sync([ + require.resolve('babel-core/package.json'), + require.resolve('babel-preset-es2015/package.json') +]) +``` + +An optional salt value can also be provided: + +```js +const hash = sync(require.resolve('babel-core/package.json'), 'salt value') +``` + +Currently only a synchronous interface is available. + +## API + +### `sync(paths, salt?)` + +`paths: string | string[]` ➜ can be a single directory or file path, or an array of paths. + +`salt: Array | Buffer | Object | string` ➜ optional. If an `Array` or `Object` (not `null`) it is first converted to a JSON string. + +## Compatibility + +`package-hash` has been tested with Node 0.10 and above, including Windows +support. Note that `git diff` support is not available in Node 0.10. diff --git a/node_modules/@ava/babel-preset-stage-4/node_modules/package-hash/index.js b/node_modules/@ava/babel-preset-stage-4/node_modules/package-hash/index.js new file mode 100644 index 000000000..ff3d61b89 --- /dev/null +++ b/node_modules/@ava/babel-preset-stage-4/node_modules/package-hash/index.js @@ -0,0 +1,125 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; + +exports.sync = sync; + +var _child_process = require('child_process'); + +var _fs = require('fs'); + +var _path = require('path'); + +var _md5Hex = require('md5-hex'); + +var _md5Hex2 = _interopRequireDefault(_md5Hex); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function tryReadFileSync(file) { + try { + return (0, _fs.readFileSync)(file); + } catch (err) { + return null; + } +} + +var TEN_MEBIBYTE = 1024 * 1024 * 10; + +var git = { + tryGetRef: function (dir, head) { + var m = /^ref: (.+)$/.exec(head.toString('utf8').trim()); + if (!m) return null; + + return tryReadFileSync((0, _path.join)(dir, '.git', m[1])); + }, + tryGetDiff: function (dir) { + if (!_child_process.execFileSync) return null; + + try { + // Attempt to get consistent output no matter the platform. Diff both + // staged and unstaged changes. + return (0, _child_process.execFileSync)('git', ['--no-pager', 'diff', 'HEAD', '--no-color', '--no-ext-diff'], { + cwd: dir, + maxBuffer: TEN_MEBIBYTE, + env: _extends({}, process.env, { + // Force the GIT_DIR to prevent git from diffing a parent repository + // in case the directory isn't actually a repository. + GIT_DIR: (0, _path.join)(dir, '.git') + }), + // Ignore stderr. + stdio: ['ignore', 'pipe', 'ignore'] + }); + } catch (err) { + return null; + } + } +}; + +function addPackageData(inputs, path) { + var dir = (0, _fs.statSync)(path).isDirectory() ? path : (0, _path.dirname)(path); + inputs.push(dir); + + var pkg = (0, _fs.readFileSync)((0, _path.join)(dir, 'package.json')); + inputs.push(pkg); + + var head = tryReadFileSync((0, _path.join)(dir, '.git', 'HEAD')); + if (head) { + inputs.push(head); + + var packed = tryReadFileSync((0, _path.join)(dir, '.git', 'packed-refs')); + if (packed) inputs.push(packed); + + var ref = git.tryGetRef(dir, head); + if (ref) inputs.push(ref); + + var diff = git.tryGetDiff(dir); + if (diff) inputs.push(diff); + } +} + +function computeHash(paths, pepper, salt) { + var inputs = []; + if (pepper) inputs.push(pepper); + + if (typeof salt !== 'undefined') { + if (Buffer.isBuffer(salt) || typeof salt === 'string') { + inputs.push(salt); + } else if (typeof salt === 'object' && salt !== null) { + inputs.push(JSON.stringify(salt)); + } else { + throw new TypeError('Salt must be an Array, Buffer, Object or string'); + } + } + + for (var i = 0; i < paths.length; i++) { + addPackageData(inputs, paths[i]); + } + + return (0, _md5Hex2.default)(inputs); +} + +var ownHash = null; +function sync(paths, salt) { + if (!ownHash) { + // Memoize the hash for package-hash itself. + ownHash = new Buffer(computeHash([__dirname]), 'hex'); + } + + if (paths === __dirname && typeof salt === 'undefined') { + // Special case that allow the pepper value to be obtained. Mainly here for + // testing purposes. + return ownHash.toString('hex'); + } + + if (Array.isArray(paths)) { + return computeHash(paths, ownHash, salt); + } else { + return computeHash([paths], ownHash, salt); + } +} +//# sourceMappingURL=index.js.map
\ No newline at end of file diff --git a/node_modules/@ava/babel-preset-stage-4/node_modules/package-hash/index.js.map b/node_modules/@ava/babel-preset-stage-4/node_modules/package-hash/index.js.map new file mode 100644 index 000000000..eeac1a048 --- /dev/null +++ b/node_modules/@ava/babel-preset-stage-4/node_modules/package-hash/index.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["src/index.js"],"names":[],"mappings":"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","file":"index.js","sourcesContent":["import { execFileSync } from 'child_process'\nimport { readFileSync, statSync } from 'fs'\nimport { dirname, join } from 'path'\n\nimport md5hex from 'md5-hex'\n\nfunction tryReadFileSync (file) {\n try {\n return readFileSync(file)\n } catch (err) {\n return null\n }\n}\n\nconst TEN_MEBIBYTE = 1024 * 1024 * 10\n\nconst git = {\n tryGetRef (dir, head) {\n const m = /^ref: (.+)$/.exec(head.toString('utf8').trim())\n if (!m) return null\n\n return tryReadFileSync(join(dir, '.git', m[1]))\n },\n\n tryGetDiff (dir) {\n if (!execFileSync) return null\n\n try {\n // Attempt to get consistent output no matter the platform. Diff both\n // staged and unstaged changes.\n return execFileSync('git', ['--no-pager', 'diff', 'HEAD', '--no-color', '--no-ext-diff'], {\n cwd: dir,\n maxBuffer: TEN_MEBIBYTE,\n env: Object.assign({}, process.env, {\n // Force the GIT_DIR to prevent git from diffing a parent repository\n // in case the directory isn't actually a repository.\n GIT_DIR: join(dir, '.git')\n }),\n // Ignore stderr.\n stdio: ['ignore', 'pipe', 'ignore']\n })\n } catch (err) {\n return null\n }\n }\n}\n\nfunction addPackageData (inputs, path) {\n const dir = statSync(path).isDirectory() ? path : dirname(path)\n inputs.push(dir)\n\n const pkg = readFileSync(join(dir, 'package.json'))\n inputs.push(pkg)\n\n const head = tryReadFileSync(join(dir, '.git', 'HEAD'))\n if (head) {\n inputs.push(head)\n\n const packed = tryReadFileSync(join(dir, '.git', 'packed-refs'))\n if (packed) inputs.push(packed)\n\n const ref = git.tryGetRef(dir, head)\n if (ref) inputs.push(ref)\n\n const diff = git.tryGetDiff(dir)\n if (diff) inputs.push(diff)\n }\n}\n\nfunction computeHash (paths, pepper, salt) {\n const inputs = []\n if (pepper) inputs.push(pepper)\n\n if (typeof salt !== 'undefined') {\n if (Buffer.isBuffer(salt) || typeof salt === 'string') {\n inputs.push(salt)\n } else if (typeof salt === 'object' && salt !== null) {\n inputs.push(JSON.stringify(salt))\n } else {\n throw new TypeError('Salt must be an Array, Buffer, Object or string')\n }\n }\n\n for (let i = 0; i < paths.length; i++) {\n addPackageData(inputs, paths[i])\n }\n\n return md5hex(inputs)\n}\n\nlet ownHash = null\nexport function sync (paths, salt) {\n if (!ownHash) {\n // Memoize the hash for package-hash itself.\n ownHash = new Buffer(computeHash([__dirname]), 'hex')\n }\n\n if (paths === __dirname && typeof salt === 'undefined') {\n // Special case that allow the pepper value to be obtained. Mainly here for\n // testing purposes.\n return ownHash.toString('hex')\n }\n\n if (Array.isArray(paths)) {\n return computeHash(paths, ownHash, salt)\n } else {\n return computeHash([paths], ownHash, salt)\n }\n}\n"]}
\ No newline at end of file diff --git a/node_modules/@ava/babel-preset-stage-4/node_modules/package-hash/package.json b/node_modules/@ava/babel-preset-stage-4/node_modules/package-hash/package.json new file mode 100644 index 000000000..0ff36dedf --- /dev/null +++ b/node_modules/@ava/babel-preset-stage-4/node_modules/package-hash/package.json @@ -0,0 +1,74 @@ +{ + "name": "package-hash", + "version": "1.2.0", + "description": "Generates a hash for an installed npm package, useful for salting caches", + "main": "index.js", + "files": [ + "index.js", + "index.js.map" + ], + "scripts": { + "clean": "rimraf index.js index.js.map", + "prebuild": "npm run clean", + "build": "babel src --out-dir ./ --source-maps", + "prepublish": "npm run build", + "lint": "as-i-preach", + "unpack-fixtures": "node scripts/unpack-fixtures.js", + "pregenerate-fixture-index": "npm run unpack-fixtures", + "generate-fixture-index": "node scripts/generate-fixture-index.js", + "pretest": "npm run unpack-fixtures", + "test": "ava", + "posttest": "npm run lint", + "coverage": "nyc npm test", + "watch:build": "npm run build -- --watch", + "watch:test": "npm run test -- --watch" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/novemberborn/package-hash.git" + }, + "author": "Mark Wubben (https://novemberborn.net/)", + "license": "ISC", + "bugs": { + "url": "https://github.com/novemberborn/package-hash/issues" + }, + "homepage": "https://github.com/novemberborn/package-hash#readme", + "dependencies": { + "md5-hex": "^1.3.0" + }, + "devDependencies": { + "@novemberborn/as-i-preach": "^2.0.1", + "ava": "^0.14.0", + "babel-cli": "^6.7.5", + "babel-plugin-transform-es2015-block-scoping": "^6.7.1", + "babel-plugin-transform-es2015-modules-commonjs": "^6.7.4", + "babel-plugin-transform-es2015-shorthand-properties": "^6.5.0", + "babel-plugin-transform-object-assign": "^6.5.0", + "babel-plugin-transform-strict-mode": "^6.6.5", + "nyc": "^6.4.0", + "proxyquire": "^1.7.4", + "rimraf": "^2.5.2", + "tar": "^2.2.1" + }, + "babel": { + "plugins": [ + "transform-object-assign", + "transform-es2015-block-scoping", + "transform-es2015-modules-commonjs", + "transform-es2015-shorthand-properties", + "transform-strict-mode" + ] + }, + "nyc": { + "cache": true, + "exclude": [ + "scripts", + "test" + ], + "reporter": [ + "html", + "lcov", + "text" + ] + } +} diff --git a/node_modules/@ava/babel-preset-stage-4/package-hash.js b/node_modules/@ava/babel-preset-stage-4/package-hash.js new file mode 100644 index 000000000..ed9e2969f --- /dev/null +++ b/node_modules/@ava/babel-preset-stage-4/package-hash.js @@ -0,0 +1,7 @@ +'use strict'; +const packageHash = require('package-hash'); + +const plugins = require('./plugins/best-match') + .map(module => require.resolve(`${module}/package.json`)); + +module.exports = packageHash.sync([require.resolve('./package.json')].concat(plugins)); diff --git a/node_modules/@ava/babel-preset-stage-4/package.json b/node_modules/@ava/babel-preset-stage-4/package.json new file mode 100644 index 000000000..3d0b5a5ab --- /dev/null +++ b/node_modules/@ava/babel-preset-stage-4/package.json @@ -0,0 +1,61 @@ +{ + "name": "@ava/babel-preset-stage-4", + "version": "1.0.0", + "description": "Efficiently applies the minimum of transforms to run stage 4 code on Node.js 4 and 6", + "main": "index.js", + "files": [ + "index.js", + "package-hash.js", + "plugins" + ], + "scripts": { + "test": "ava", + "posttest": "xo", + "coverage": "nyc npm test" + }, + "engines": { + "node": ">=4" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/avajs/babel-preset-stage-4.git" + }, + "keywords": [ + "ava", + "babel-preset" + ], + "author": "Mark Wubben (https://novemberborn.net/)", + "license": "MIT", + "bugs": { + "url": "https://github.com/avajs/babel-preset-stage-4/issues" + }, + "homepage": "https://github.com/avajs/babel-preset-stage-4#readme", + "devDependencies": { + "ava": "^0.17.0", + "coveralls": "^2.11.15", + "nyc": "^10.1.2", + "proxyquire": "^1.7.10", + "xo": "^0.17.1" + }, + "dependencies": { + "babel-plugin-check-es2015-constants": "^6.8.0", + "babel-plugin-syntax-trailing-function-commas": "^6.20.0", + "babel-plugin-transform-async-to-generator": "^6.16.0", + "babel-plugin-transform-es2015-destructuring": "^6.19.0", + "babel-plugin-transform-es2015-function-name": "^6.9.0", + "babel-plugin-transform-es2015-modules-commonjs": "^6.18.0", + "babel-plugin-transform-es2015-parameters": "^6.21.0", + "babel-plugin-transform-es2015-spread": "^6.8.0", + "babel-plugin-transform-es2015-sticky-regex": "^6.8.0", + "babel-plugin-transform-es2015-unicode-regex": "^6.11.0", + "babel-plugin-transform-exponentiation-operator": "^6.8.0", + "package-hash": "^1.2.0" + }, + "nyc": { + "reporter": [ + "html", + "lcov", + "text" + ] + } +} diff --git a/node_modules/@ava/babel-preset-stage-4/plugins/4.json b/node_modules/@ava/babel-preset-stage-4/plugins/4.json new file mode 100644 index 000000000..fff34682a --- /dev/null +++ b/node_modules/@ava/babel-preset-stage-4/plugins/4.json @@ -0,0 +1,13 @@ +[ + "babel-plugin-check-es2015-constants", + "babel-plugin-syntax-trailing-function-commas", + "babel-plugin-transform-async-to-generator", + "babel-plugin-transform-es2015-destructuring", + "babel-plugin-transform-es2015-function-name", + "babel-plugin-transform-es2015-modules-commonjs", + "babel-plugin-transform-es2015-parameters", + "babel-plugin-transform-es2015-spread", + "babel-plugin-transform-es2015-sticky-regex", + "babel-plugin-transform-es2015-unicode-regex", + "babel-plugin-transform-exponentiation-operator" +] diff --git a/node_modules/@ava/babel-preset-stage-4/plugins/6.json b/node_modules/@ava/babel-preset-stage-4/plugins/6.json new file mode 100644 index 000000000..ffd1f7601 --- /dev/null +++ b/node_modules/@ava/babel-preset-stage-4/plugins/6.json @@ -0,0 +1,6 @@ +[ + "babel-plugin-syntax-trailing-function-commas", + "babel-plugin-transform-async-to-generator", + "babel-plugin-transform-es2015-modules-commonjs", + "babel-plugin-transform-exponentiation-operator" +] diff --git a/node_modules/@ava/babel-preset-stage-4/plugins/best-match.js b/node_modules/@ava/babel-preset-stage-4/plugins/best-match.js new file mode 100644 index 000000000..8743e1b07 --- /dev/null +++ b/node_modules/@ava/babel-preset-stage-4/plugins/best-match.js @@ -0,0 +1,15 @@ +'use strict'; +/* eslint-disable import/no-dynamic-require, import/no-unresolved */ +const process = require('process'); + +function getClosestVersion() { + const version = parseFloat(process.versions.node); + if (version >= 6) { + return 6; + } + + // Node.js 4 is the minimal supported version. + return 4; +} + +module.exports = require(`./${getClosestVersion()}.json`); diff --git a/node_modules/@ava/babel-preset-stage-4/readme.md b/node_modules/@ava/babel-preset-stage-4/readme.md new file mode 100644 index 000000000..4003d6442 --- /dev/null +++ b/node_modules/@ava/babel-preset-stage-4/readme.md @@ -0,0 +1,34 @@ +# @ava/babel-preset-stage-4 + +A [Babel] preset for use with [AVA]. Aspires to bring ECMAScript stage 4 +proposals to AVA's test and helper files. + +Efficiently applies the minimum of transforms to run stage 4 code on Node.js 4 +and 6. + +Built-ins are not added or extended, so features like Proxies, +`Array.prototype.includes` or `String.prototype.padStart` will only be available +if the Node.js version running the tests supports it. Consult [node.green] for +details. + +Sometimes a particular feature is *mostly* implemented in Node.js. In that case +transforms are not applied. This applies to `new.target` and iterator closing, +which are not supported in Node.js 4 even though classes and iterators are. + +## Install + +```console +$ npm install --save @ava/babel-preset-stage-4 +``` + +## Usage + +Add `@ava/stage-4` to your [Babel] presets. + +Require `@ava/babel-preset-stage-4/package-hash` to get a combined hash for the +installed version of the preset, as well as the plugins that were selected for +the active Node.js version. + +[AVA]: https://ava.li +[Babel]: https://babeljs.io/ +[node.green]: http://node.green/ diff --git a/node_modules/@ava/babel-preset-transform-test-files/espower-patterns.json b/node_modules/@ava/babel-preset-transform-test-files/espower-patterns.json new file mode 100644 index 000000000..832309a5f --- /dev/null +++ b/node_modules/@ava/babel-preset-transform-test-files/espower-patterns.json @@ -0,0 +1,8 @@ +[ + "t.truthy(value, [message])", + "t.falsy(value, [message])", + "t.true(value, [message])", + "t.false(value, [message])", + "t.regex(contents, regex, [message])", + "t.notRegex(contents, regex, [message])" +] diff --git a/node_modules/@ava/babel-preset-transform-test-files/index.js b/node_modules/@ava/babel-preset-transform-test-files/index.js new file mode 100644 index 000000000..7af76c7e1 --- /dev/null +++ b/node_modules/@ava/babel-preset-transform-test-files/index.js @@ -0,0 +1,17 @@ +'use strict'; +const ESPOWER_PATTERNS = require('./espower-patterns.json'); + +module.exports = (context, options) => { + const plugins = []; + + if (!options || options.powerAssert !== false) { + plugins.push(require('babel-plugin-espower/create')(context, { + embedAst: true, + patterns: ESPOWER_PATTERNS + })); + } + + plugins.push(require('@ava/babel-plugin-throws-helper')); + + return {plugins}; +}; diff --git a/node_modules/@ava/babel-preset-transform-test-files/license b/node_modules/@ava/babel-preset-transform-test-files/license new file mode 100644 index 000000000..060edd7f2 --- /dev/null +++ b/node_modules/@ava/babel-preset-transform-test-files/license @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) Mark Wubben <mark@novemberborn.net> (novemberborn.net) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/node_modules/@ava/babel-preset-transform-test-files/package.json b/node_modules/@ava/babel-preset-transform-test-files/package.json new file mode 100644 index 000000000..6ce914164 --- /dev/null +++ b/node_modules/@ava/babel-preset-transform-test-files/package.json @@ -0,0 +1,47 @@ +{ + "name": "@ava/babel-preset-transform-test-files", + "version": "3.0.0", + "description": "Babel preset for use with AVA test files", + "license": "MIT", + "repository": "avajs/babel-preset-transform-test-files", + "author": "Mark Wubben (https://novemberborn.net)", + "publishConfig": { + "access": "public" + }, + "engines": { + "node": ">=4" + }, + "scripts": { + "test": "xo && ava", + "posttest": "xo", + "coverage": "nyc npm test" + }, + "files": [ + "index.js", + "espower-patterns.json", + "package-hash.js" + ], + "keywords": [ + "ava", + "babel-preset" + ], + "dependencies": { + "@ava/babel-plugin-throws-helper": "^2.0.0", + "babel-plugin-espower": "^2.3.2" + }, + "devDependencies": { + "ava": "^0.18.2", + "babel-core": "^6.21.0", + "coveralls": "^2.11.15", + "empower-core": "^0.6.1", + "nyc": "^10.1.2", + "xo": "^0.18.1" + }, + "nyc": { + "reporter": [ + "html", + "lcov", + "text" + ] + } +} diff --git a/node_modules/@ava/babel-preset-transform-test-files/readme.md b/node_modules/@ava/babel-preset-transform-test-files/readme.md new file mode 100644 index 000000000..eba6dc701 --- /dev/null +++ b/node_modules/@ava/babel-preset-transform-test-files/readme.md @@ -0,0 +1,34 @@ +# @ava/babel-preset-transform-test-files [](https://travis-ci.org/avajs/babel-preset-transform-test-files) + +> [Babel] preset for use with [AVA] test files + +Currently contains: + +- [`babel-plugin-espower`](https://github.com/power-assert-js/babel-plugin-espower) and the patterns that should be enhanced +- [`@ava/babel-plugin-throws-helper`](https://github.com/avajs/babel-plugin-throws-helper/) + + +## Install + +```console +$ npm install --save @ava/babel-preset-transform-test-files +``` + + +## Usage + +Add `@ava/transform-test-files` to your [Babel] presets. You can disable `babel-plugin-espower` by setting the `powerAssert` option to `false`: + +```json +{ + "presets": [ + ["@ava/transform-test-files", {"powerAsssert": false}] + ] +} +``` + +Require `@ava/babel-preset-transform-test-files/package-hash` to get a combined hash for the installed version of the preset, as well as the plugins used. + + +[AVA]: https://ava.li +[Babel]: https://babeljs.io diff --git a/node_modules/@ava/pretty-format/.npmignore b/node_modules/@ava/pretty-format/.npmignore new file mode 100644 index 000000000..a2dd48210 --- /dev/null +++ b/node_modules/@ava/pretty-format/.npmignore @@ -0,0 +1,3 @@ +__tests__ +perf +.travis.yml diff --git a/node_modules/@ava/pretty-format/LICENSE.md b/node_modules/@ava/pretty-format/LICENSE.md new file mode 100755 index 000000000..42a40bb10 --- /dev/null +++ b/node_modules/@ava/pretty-format/LICENSE.md @@ -0,0 +1,15 @@ +## ISC License + +Copyright (c) 2016, James Kyle <me@thejameskyle.com> + +Permission to use, copy, modify, and/or distribute this software for any purpose +with or without fee is hereby granted, provided that the above copyright notice +and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. diff --git a/node_modules/@ava/pretty-format/README.md b/node_modules/@ava/pretty-format/README.md new file mode 100755 index 000000000..57e24fc79 --- /dev/null +++ b/node_modules/@ava/pretty-format/README.md @@ -0,0 +1,134 @@ +# @ava/pretty-format [](https://travis-ci.org/avajs/pretty-format) + +> Stringify any JavaScript value. + +- Supports [all built-in JavaScript types](#type-support) +- [Blazingly fast](https://gist.github.com/thejameskyle/2b04ffe4941aafa8f970de077843a8fd) (similar performance to v8's `JSON.stringify` and significantly faster than Node's `util.format`) +- Plugin system for extending with custom types (i.e. [`ReactTestComponent`](#reacttestcomponent-plugin)) + + +## Installation + +```sh +$ npm install @ava/pretty-format +``` + +## Usage + +```js +var prettyFormat = require('pretty-format'); + +var obj = { property: {} }; +obj.circularReference = obj; +obj[Symbol('foo')] = 'foo'; +obj.map = new Map(); +obj.map.set('prop', 'value'); +obj.array = [1, NaN, Infinity]; + +console.log(prettyFormat(obj)); +``` + +**Result:** + +```js +Object { + "property": Object {}, + "circularReference": [Circular], + "map": Map { + "prop" => "value" + }, + "array": Array [ + 1, + NaN, + Infinity + ], + Symbol(foo): "foo" +} +``` + +#### Type Support + +`Object`, `Array`, `ArrayBuffer`, `DataView`, `Float32Array`, `Float64Array`, `Int8Array`, `Int16Array`, `Int32Array`, `Uint8Array`, `Uint8ClampedArray`, `Uint16Array`, `Uint32Array`, `arguments`, `Boolean`, `Date`, `Error`, `Function`, `Infinity`, `Map`, `NaN`, `null`, `Number`, `RegExp`, `Set`, `String`, `Symbol`, `undefined`, `WeakMap`, `WeakSet` + +### API + +```js +console.log(prettyFormat(object)); +console.log(prettyFormat(object, options)); +``` + +Options: + +* **`callToJSON`**<br> + Type: `boolean`, default: `true`<br> + Call `toJSON()` on passed object. +* **`indent`**<br> + Type: `number`, default: `2`<br> + Number of spaces for indentation. +* **`maxDepth`**<br> + Type: `number`, default: `Infinity`<br> + Print only this number of levels. +* **`min`**<br> + Type: `boolean`, default: `false`<br> + Print without whitespace. +* **`plugins`**<br> + Type: `array`, default: `[]`<br> + Plugins (see the next section). +* **`printFunctionName`**<br> + Type: `boolean`, default: `true`<br> + Print function names or just `[Function]`. +* **`escapeRegex`**<br> + Type: `boolean`, default: `false`<br> + Escape special characters in regular expressions. +* **`highlight`**<br> + Type: `boolean`, default: `false`<br> + Highlight syntax for terminal (works only with `ReactTestComponent` and `ReactElement` plugins. +* **`theme`**<br> + Type: `object`, default: `{tag: 'cyan', content: 'reset'...}`<br> + Syntax highlight theme.<br> + Uses [ansi-styles colors](https://github.com/chalk/ansi-styles#colors) + `reset` for no color.<br> + Available types: `tag`, `content`, `prop` and `value`. + +### Plugins + +Pretty format also supports adding plugins: + +```js +var fooPlugin = { + test: function(val) { + return val && val.hasOwnProperty('foo'); + }, + print: function(val, print, indent) { + return 'Foo: ' + print(val.foo); + } +}; + +var obj = { foo: { bar: {} } }; + +prettyFormat(obj, { + plugins: [fooPlugin] +}); +// Foo: Object { +// "bar": Object {} +// } +``` + +#### `ReactTestComponent` and `ReactElement` plugins + +```js +var prettyFormat = require('pretty-format'); +var reactTestPlugin = require('pretty-format/plugins/ReactTestComponent'); +var reactElementPlugin = require('pretty-format/plugins/ReactElement'); + +var React = require('react'); +var renderer = require('react-test-renderer'); + +var jsx = React.createElement('h1', null, 'Hello World'); + +prettyFormat(renderer.create(jsx).toJSON(), { + plugins: [reactTestPlugin, reactElementPlugin] +}); +// <h1> +// Hello World +// </h1> +``` diff --git a/node_modules/@ava/pretty-format/index.js b/node_modules/@ava/pretty-format/index.js new file mode 100644 index 000000000..b9fc698d8 --- /dev/null +++ b/node_modules/@ava/pretty-format/index.js @@ -0,0 +1,397 @@ +'use strict'; + +const keyword = require('esutils').keyword; +const style = require('ansi-styles'); +const printString = require('./printString'); + +const toString = Object.prototype.toString; +const toISOString = Date.prototype.toISOString; +const errorToString = Error.prototype.toString; +const regExpToString = RegExp.prototype.toString; +const symbolToString = Symbol.prototype.toString; + +const SYMBOL_REGEXP = /^Symbol\((.*)\)(.*)$/; +const NEWLINE_REGEXP = /\n/ig; + +const getSymbols = Object.getOwnPropertySymbols || (obj => []); + +function isToStringedArrayType(toStringed) { + return ( + toStringed === '[object Array]' || + toStringed === '[object ArrayBuffer]' || + toStringed === '[object DataView]' || + toStringed === '[object Float32Array]' || + toStringed === '[object Float64Array]' || + toStringed === '[object Int8Array]' || + toStringed === '[object Int16Array]' || + toStringed === '[object Int32Array]' || + toStringed === '[object Uint8Array]' || + toStringed === '[object Uint8ClampedArray]' || + toStringed === '[object Uint16Array]' || + toStringed === '[object Uint32Array]' + ); +} + +function printNumber(val) { + if (val != +val) return 'NaN'; + const isNegativeZero = val === 0 && (1 / val) < 0; + return isNegativeZero ? '-0' : '' + val; +} + +function printFunction(val, printFunctionName) { + if (!printFunctionName) { + return '[Function]'; + } else if (val.name === '') { + return '[Function anonymous]' + } else { + return '[Function ' + val.name + ']'; + } +} + +function printSymbol(val) { + return symbolToString.call(val).replace(SYMBOL_REGEXP, 'Symbol($1)'); +} + +function printError(val) { + return '[' + errorToString.call(val) + ']'; +} + +function printBasicValue(val, printFunctionName, escapeRegex, colors) { + if (val === true || val === false) return colors.boolean.open + val + colors.boolean.close; + if (val === undefined) return colors.misc.open + 'undefined' + colors.misc.close; + if (val === null) return colors.misc.open + 'null' + colors.misc.close; + + const typeOf = typeof val; + + if (typeOf === 'number') return colors.number.open + printNumber(val) + colors.number.close; + if (typeOf === 'string') return colors.string.open + '"' + printString(val) + '"' + colors.string.close; + if (typeOf === 'function') return colors.function.open + printFunction(val, printFunctionName) + colors.function.close; + if (typeOf === 'symbol') return colors.symbol.open + printSymbol(val) + colors.symbol.close; + + const toStringed = toString.call(val); + + if (toStringed === '[object WeakMap]') return colors.label.open + 'WeakMap ' + colors.label.close + colors.bracket.open + '{}' + colors.bracket.close; + if (toStringed === '[object WeakSet]') return colors.label.open + 'WeakSet ' + colors.label.close + colors.bracket.open + '{}' + colors.bracket.close; + if (toStringed === '[object Function]' || toStringed === '[object GeneratorFunction]') return colors.function.open + printFunction(val, printFunctionName) + colors.function.close; + if (toStringed === '[object Symbol]') return colors.symbol.open + printSymbol(val) + colors.symbol.close; + if (toStringed === '[object Date]') return colors.date.open + toISOString.call(val) + colors.date.close; + if (toStringed === '[object Error]') return colors.error.open + printError(val) + colors.error.close; + if (toStringed === '[object RegExp]') { + if (escapeRegex) { + return colors.regex.open + printString(regExpToString.call(val)) + colors.regex.close; + } + return colors.regex.open + regExpToString.call(val) + colors.regex.close; + }; + if (toStringed === '[object Arguments]' && val.length === 0) return colors.label.open + 'Arguments ' + colors.label.close + colors.bracket.open + '[]' + colors.bracket.close; + if (isToStringedArrayType(toStringed) && val.length === 0) return val.constructor.name + colors.bracket.open + ' []' + colors.bracket.close; + + if (val instanceof Error) return colors.error.open + printError(val) + colors.error.close; + + return false; +} + +function printList(list, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors) { + let body = ''; + + if (list.length) { + body += edgeSpacing; + + const innerIndent = prevIndent + indent; + + for (let i = 0; i < list.length; i++) { + body += innerIndent + print(list[i], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); + + if (i < list.length - 1) { + body += colors.comma.open + ',' + colors.comma.close + spacing; + } + } + + body += (min ? '' : colors.comma.open + ',' + colors.comma.close) + edgeSpacing + prevIndent; + } + + return colors.bracket.open + '[' + colors.bracket.close + body + colors.bracket.open + ']' + colors.bracket.close; +} + +function printArguments(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors) { + return colors.label.open + (min ? '' : 'Arguments ') + colors.label.close + printList(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); +} + +function printArray(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors) { + return colors.label.open + (min ? '' : val.constructor.name + ' ') + colors.label.close + printList(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); +} + +function printKey(key, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors) { + const typeOf = typeof key; + if (typeOf === 'string') { + if (keyword.isIdentifierNameES6(key, true)) return colors.key.open + key + colors.key.close; + if (/^\d+$/.test(key)) return colors.key.open + key + colors.key.close; + return colors.key.open + '"' + printString(key) + '"' + colors.key.close; + } + if (typeOf === 'symbol') return colors.key.open + printSymbol(key) + colors.key.close; + + return print(key, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); +} + +function printMap(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors) { + let result = colors.label.open + 'Map ' + colors.label.close + colors.bracket.open + '{' + colors.bracket.close; + const iterator = val.entries(); + let current = iterator.next(); + + if (!current.done) { + result += edgeSpacing; + + const innerIndent = prevIndent + indent; + + while (!current.done) { + const key = printKey(current.value[0], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); + const value = print(current.value[1], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); + + result += innerIndent + key + ' => ' + value; + + current = iterator.next(); + + if (!current.done) { + result += colors.comma.open + ',' + colors.comma.close + spacing; + } + } + + result += (min ? '' : colors.comma.open + ',' + colors.comma.close) + edgeSpacing + prevIndent; + } + + return result + colors.bracket.open + '}' + colors.bracket.close; +} + +function printObject(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors) { + const constructor = min ? '' : (val.constructor ? val.constructor.name + ' ' : 'Object '); + let result = colors.label.open + constructor + colors.label.close + colors.bracket.open + '{' + colors.bracket.close; + let keys = Object.keys(val).sort(); + const symbols = getSymbols(val); + + if (symbols.length) { + keys = keys + .filter(key => !(typeof key === 'symbol' || toString.call(key) === '[object Symbol]')) + .concat(symbols); + } + + if (keys.length) { + result += edgeSpacing; + + const innerIndent = prevIndent + indent; + + for (let i = 0; i < keys.length; i++) { + const key = keys[i]; + const name = printKey(key, indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); + const value = print(val[key], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); + + result += innerIndent + name + ': ' + value; + + if (i < keys.length - 1) { + result += colors.comma.open + ',' + colors.comma.close + spacing; + } + } + + result += (min ? '' : colors.comma.open + ',' + colors.comma.close) + edgeSpacing + prevIndent; + } + + return result + colors.bracket.open + '}' + colors.bracket.close; +} + +function printSet(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors) { + let result = colors.label.open + 'Set ' + colors.label.close + colors.bracket.open + '{' + colors.bracket.close; + const iterator = val.entries(); + let current = iterator.next(); + + if (!current.done) { + result += edgeSpacing; + + const innerIndent = prevIndent + indent; + + while (!current.done) { + result += innerIndent + print(current.value[1], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); + + current = iterator.next(); + + if (!current.done) { + result += colors.comma.open + ',' + colors.comma.close + spacing; + } + } + + result += (min ? '' : colors.comma.open + ',' + colors.comma.close) + edgeSpacing + prevIndent; + } + + return result + colors.bracket.open + '}' + colors.bracket.close; +} + +function printComplexValue(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors) { + refs = refs.slice(); + if (refs.indexOf(val) > -1) { + return '[Circular]'; + } else { + refs.push(val); + } + + currentDepth++; + + const hitMaxDepth = currentDepth > maxDepth; + + if (callToJSON && !hitMaxDepth && val.toJSON && typeof val.toJSON === 'function') { + return print(val.toJSON(), indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); + } + + const toStringed = toString.call(val); + if (toStringed === '[object Arguments]') { + return hitMaxDepth ? '[Arguments]' : printArguments(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); + } else if (isToStringedArrayType(toStringed)) { + return hitMaxDepth ? '[Array]' : printArray(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); + } else if (toStringed === '[object Map]') { + return hitMaxDepth ? '[Map]' : printMap(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); + } else if (toStringed === '[object Set]') { + return hitMaxDepth ? '[Set]' : printSet(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); + } else if (typeof val === 'object') { + return hitMaxDepth ? '[Object]' : printObject(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); + } +} + +function printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors) { + let match = false; + let plugin; + + for (let p = 0; p < plugins.length; p++) { + plugin = plugins[p]; + + if (plugin.test(val)) { + match = true; + break; + } + } + + if (!match) { + return false; + } + + function boundPrint(val) { + return print(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); + } + + function boundIndent(str) { + const indentation = prevIndent + indent; + return indentation + str.replace(NEWLINE_REGEXP, '\n' + indentation); + } + + const opts = { + edgeSpacing: edgeSpacing, + spacing: spacing + }; + return plugin.print(val, boundPrint, boundIndent, opts, colors); +} + +function print(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors) { + const basic = printBasicValue(val, printFunctionName, escapeRegex, colors); + if (basic) return basic; + + const plugin = printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); + if (plugin) return plugin; + + return printComplexValue(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); +} + +const DEFAULTS = { + callToJSON: true, + indent: 2, + maxDepth: Infinity, + min: false, + plugins: [], + printFunctionName: true, + escapeRegex: false, + highlight: false, + theme: { + tag: 'cyan', + content: 'reset', + prop: 'yellow', + value: 'green', + number: 'yellow', + string: 'red', + date: 'red', + symbol: 'red', + regex: 'red', + function: 'blue', + error: 'red', + boolean: 'yellow', + label: 'blue', + bracket: 'grey', + comma: 'grey', + misc: 'grey', + key: 'reset' + } +}; + +function validateOptions(opts) { + Object.keys(opts).forEach(key => { + if (!DEFAULTS.hasOwnProperty(key)) { + throw new Error('prettyFormat: Invalid option: ' + key); + } + }); + + if (opts.min && opts.indent !== undefined && opts.indent !== 0) { + throw new Error('prettyFormat: Cannot run with min option and indent'); + } +} + +function normalizeOptions(opts) { + const result = {}; + + Object.keys(DEFAULTS).forEach(key => + result[key] = opts.hasOwnProperty(key) ? opts[key] : DEFAULTS[key] + ); + + if (result.min) { + result.indent = 0; + } + + return result; +} + +function createIndent(indent) { + return new Array(indent + 1).join(' '); +} + +function prettyFormat(val, opts) { + if (!opts) { + opts = DEFAULTS; + } else { + validateOptions(opts) + opts = normalizeOptions(opts); + } + + let colors = {}; + Object.keys(opts.theme).forEach(key => { + if (opts.highlight) { + colors[key] = style[opts.theme[key]]; + } else { + colors[key] = {open: '', close: ''}; + } + }); + + let indent; + let refs; + const prevIndent = ''; + const currentDepth = 0; + const spacing = opts.min ? ' ' : '\n'; + const edgeSpacing = opts.min ? '' : '\n'; + + if (opts && opts.plugins.length) { + indent = createIndent(opts.indent); + refs = []; + var pluginsResult = printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, opts.maxDepth, currentDepth, opts.plugins, opts.min, opts.callToJSON, opts.printFunctionName, opts.escapeRegex, colors); + if (pluginsResult) return pluginsResult; + } + + var basicResult = printBasicValue(val, opts.printFunctionName, opts.escapeRegex, colors); + if (basicResult) return basicResult; + + if (!indent) indent = createIndent(opts.indent); + if (!refs) refs = []; + return printComplexValue(val, indent, prevIndent, spacing, edgeSpacing, refs, opts.maxDepth, currentDepth, opts.plugins, opts.min, opts.callToJSON, opts.printFunctionName, opts.escapeRegex, colors); +} + +module.exports = prettyFormat; diff --git a/node_modules/@ava/pretty-format/package.json b/node_modules/@ava/pretty-format/package.json new file mode 100644 index 000000000..9cd6a7b19 --- /dev/null +++ b/node_modules/@ava/pretty-format/package.json @@ -0,0 +1,29 @@ +{ + "name": "@ava/pretty-format", + "version": "1.1.0", + "description": "Stringify any JavaScript value", + "license": "MIT", + "repository": "avajs/pretty-format", + "author": "James Kyle <me@thejameskyle.com>", + "publishConfig": { + "access": "public" + }, + "scripts": { + "test": "jest", + "perf": "node perf/test.js" + }, + "dependencies": { + "ansi-styles": "^2.2.1", + "esutils": "^2.0.2" + }, + "devDependencies": { + "chalk": "^1.1.3", + "jest": "^15.1.1", + "left-pad": "^1.1.1", + "react": "15.3.0" + }, + "jest": { + "testEnvironment": "node", + "verbose": true + } +} diff --git a/node_modules/@ava/pretty-format/plugins/ReactElement.js b/node_modules/@ava/pretty-format/plugins/ReactElement.js new file mode 100644 index 000000000..0acd7ea10 --- /dev/null +++ b/node_modules/@ava/pretty-format/plugins/ReactElement.js @@ -0,0 +1,83 @@ +'use strict'; + +const printString = require('../printString'); + +const reactElement = Symbol.for('react.element'); + +function traverseChildren(opaqueChildren, cb) { + if (Array.isArray(opaqueChildren)) { + opaqueChildren.forEach(child => traverseChildren(child, cb)); + } else if (opaqueChildren != null && opaqueChildren !== false) { + cb(opaqueChildren); + } +} + +function printChildren(flatChildren, print, indent, colors, opts) { + return flatChildren.map(node => { + if (typeof node === 'object') { + return printElement(node, print, indent, colors, opts); + } else if (typeof node === 'string') { + return printString(colors.content.open + node + colors.content.close); + } else { + return print(node); + } + }).join(opts.edgeSpacing); +} + +function printProps(props, print, indent, colors, opts) { + return Object.keys(props).sort().map(name => { + if (name === 'children') { + return ''; + } + + const prop = props[name]; + let printed = print(prop); + + if (typeof prop !== 'string') { + if (printed.indexOf('\n') !== -1) { + printed = '{' + opts.edgeSpacing + indent(indent(printed) + opts.edgeSpacing + '}'); + } else { + printed = '{' + printed + '}'; + } + } + + return opts.spacing + indent(colors.prop.open + name + colors.prop.close + '=') + colors.value.open + printed + colors.value.close; + }).join(''); +} + +function printElement(element, print, indent, colors, opts) { + let result = colors.tag.open + '<'; + let elementName; + if (typeof element.type === 'string') { + elementName = element.type; + } else if (typeof element.type === 'function') { + elementName = element.type.displayName || element.type.name || 'Unknown'; + } else { + elementName = 'Unknown'; + } + result += elementName + colors.tag.close; + result += printProps(element.props, print, indent, colors, opts); + + const opaqueChildren = element.props.children; + if (opaqueChildren) { + let flatChildren = []; + traverseChildren(opaqueChildren, child => { + flatChildren.push(child); + }); + const children = printChildren(flatChildren, print, indent, colors, opts); + result += colors.tag.open + '>' + colors.tag.close + opts.edgeSpacing + indent(children) + opts.edgeSpacing + colors.tag.open + '</' + elementName + '>' + colors.tag.close; + } else { + result += colors.tag.open + ' />' + colors.tag.close; + } + + return result; +} + +module.exports = { + test(object) { + return object && object.$$typeof === reactElement; + }, + print(val, print, indent, opts, colors) { + return printElement(val, print, indent, colors, opts); + } +}; diff --git a/node_modules/@ava/pretty-format/plugins/ReactTestComponent.js b/node_modules/@ava/pretty-format/plugins/ReactTestComponent.js new file mode 100644 index 000000000..7d7c79c65 --- /dev/null +++ b/node_modules/@ava/pretty-format/plugins/ReactTestComponent.js @@ -0,0 +1,58 @@ +'use strict'; + +const printString = require('../printString'); + +const reactTestInstance = Symbol.for('react.test.json'); + +function printChildren(children, print, indent, colors, opts) { + return children.map(child => printInstance(child, print, indent, colors, opts)).join(opts.edgeSpacing); +} + +function printProps(props, print, indent, colors, opts) { + return Object.keys(props).sort().map(name => { + const prop = props[name]; + let printed = print(prop); + + if (typeof prop !== 'string') { + if (printed.indexOf('\n') !== -1) { + printed = '{' + opts.edgeSpacing + indent(indent(printed) + opts.edgeSpacing + '}'); + } else { + printed = '{' + printed + '}'; + } + } + + return opts.spacing + indent(colors.prop.open + name + colors.prop.close + '=') + colors.value.open + printed + colors.value.close; + }).join(''); +} + +function printInstance(instance, print, indent, colors, opts) { + if (typeof instance == 'number') { + return print(instance); + } else if (typeof instance === 'string') { + return printString(colors.content.open + instance + colors.content.close); + } + + let result = colors.tag.open + '<' + instance.type + colors.tag.close; + + if (instance.props) { + result += printProps(instance.props, print, indent, colors, opts); + } + + if (instance.children) { + const children = printChildren(instance.children, print, indent, colors, opts); + result += colors.tag.open + '>' + colors.tag.close + opts.edgeSpacing + indent(children) + opts.edgeSpacing + colors.tag.open + '</' + instance.type + '>' + colors.tag.close; + } else { + result += colors.tag.open + ' />' + colors.tag.close; + } + + return result; +} + +module.exports = { + test(object) { + return object && object.$$typeof === reactTestInstance; + }, + print(val, print, indent, opts, colors) { + return printInstance(val, print, indent, colors, opts); + } +}; diff --git a/node_modules/@ava/pretty-format/printString.js b/node_modules/@ava/pretty-format/printString.js new file mode 100644 index 000000000..bf5ea0313 --- /dev/null +++ b/node_modules/@ava/pretty-format/printString.js @@ -0,0 +1,7 @@ +'use strict'; + +const ESCAPED_CHARACTERS = /(\\|\"|\')/g; + +module.exports = function printString(val) { + return val.replace(ESCAPED_CHARACTERS, '\\$1'); +} |