Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-tester

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-tester - npm Package Compare versions

Comparing version 5.5.2 to 6.0.0

dist/__mocks__/@babel/core.js

278

dist/index.js

@@ -1,45 +0,36 @@

'use strict';
"use strict";
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; };
var _assert = _interopRequireDefault(require("assert"));
var _assert = require('assert');
var _path = _interopRequireDefault(require("path"));
var _assert2 = _interopRequireDefault(_assert);
var _fs = _interopRequireDefault(require("fs"));
var _path = require('path');
var _pathExists = _interopRequireDefault(require("path-exists"));
var _path2 = _interopRequireDefault(_path);
var _lodash = _interopRequireDefault(require("lodash.merge"));
var _fs = require('fs');
var _invariant = _interopRequireDefault(require("invariant"));
var _fs2 = _interopRequireDefault(_fs);
var _stripIndent = _interopRequireDefault(require("strip-indent"));
var _pathExists = require('path-exists');
var _commonTags = require("common-tags");
var _pathExists2 = _interopRequireDefault(_pathExists);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _lodash = require('lodash.merge');
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
var _lodash2 = _interopRequireDefault(_lodash);
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
var _invariant = require('invariant');
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
var _invariant2 = _interopRequireDefault(_invariant);
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var _stripIndent = require('strip-indent');
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
var _stripIndent2 = _interopRequireDefault(_stripIndent);
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
var _commonTags = require('common-tags');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
var noop = function noop() {};
module.exports = pluginTester;
var fullDefaultConfig = {

@@ -51,15 +42,15 @@ babelOptions: {

}
};
// eslint-disable-next-line max-lines-per-function
};function pluginTester() {
function pluginTester() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var _ref$babel = _ref.babel,
babel = _ref$babel === undefined ? require('babel-core') : _ref$babel,
babel = _ref$babel === void 0 ? require('@babel/core') : _ref$babel,
_ref$plugin = _ref.plugin,
plugin = _ref$plugin === undefined ? requiredParam('plugin') : _ref$plugin,
plugin = _ref$plugin === void 0 ? requiredParam('plugin') : _ref$plugin,
_ref$pluginName = _ref.pluginName,
pluginName = _ref$pluginName === undefined ? getPluginName(plugin, babel) : _ref$pluginName,
pluginName = _ref$pluginName === void 0 ? getPluginName(plugin, babel) : _ref$pluginName,
_ref$title = _ref.title,
describeBlockTitle = _ref$title === undefined ? pluginName : _ref$title,
describeBlockTitle = _ref$title === void 0 ? pluginName : _ref$title,
pluginOptions = _ref.pluginOptions,

@@ -69,9 +60,10 @@ tests = _ref.tests,

_ref$fixtureOutputNam = _ref.fixtureOutputName,
fixtureOutputName = _ref$fixtureOutputNam === undefined ? 'output' : _ref$fixtureOutputNam,
fixtureOutputName = _ref$fixtureOutputNam === void 0 ? 'output' : _ref$fixtureOutputNam,
filename = _ref.filename,
rest = _objectWithoutProperties(_ref, ['babel', 'plugin', 'pluginName', 'title', 'pluginOptions', 'tests', 'fixtures', 'fixtureOutputName', 'filename']);
rest = _objectWithoutProperties(_ref, ["babel", "plugin", "pluginName", "title", "pluginOptions", "tests", "fixtures", "fixtureOutputName", "filename"]);
var testNumber = 1;
if (fixtures) {
testFixtures(_extends({
testFixtures(_objectSpread({
plugin,

@@ -87,48 +79,12 @@ pluginName,

}
var testAsArray = toTestArray(tests);
if (!testAsArray.length) {
return Promise.resolve();
}
var testerConfig = (0, _lodash2.default)({}, fullDefaultConfig, rest);
var testerConfig = (0, _lodash.default)({}, fullDefaultConfig, rest);
return describe(describeBlockTitle, function () {
var promises = testAsArray.map(function (testConfig) {
var testerWrapper = function () {
var _ref2 = _asyncToGenerator(function* () {
var teardowns = teardown ? [teardown] : [];
var returnedTeardown = void 0;
try {
returnedTeardown = yield setup();
} catch (e) {
// eslint-disable-next-line no-console
console.error('There was a problem during setup');
throw e;
}
if (typeof returnedTeardown === 'function') {
teardowns.push(returnedTeardown);
}
try {
tester();
} finally {
try {
yield Promise.all(teardowns.map(function (t) {
return t();
}));
} catch (e) {
// eslint-disable-next-line no-console
console.error('There was a problem during teardown');
// eslint-disable-next-line no-unsafe-finally
throw e;
}
}
});
return function testerWrapper() {
return _ref2.apply(this, arguments);
};
}();
// eslint-disable-next-line complexity
if (!testConfig) {

@@ -138,3 +94,3 @@ return Promise.resolve();

var _merge = (0, _lodash2.default)({}, testerConfig, toTestConfig(testConfig)),
var _merge = (0, _lodash.default)({}, testerConfig, toTestConfig(testConfig)),
skip = _merge.skip,

@@ -149,10 +105,10 @@ only = _merge.only,

_merge$setup = _merge.setup,
setup = _merge$setup === undefined ? noop : _merge$setup,
setup = _merge$setup === void 0 ? noop : _merge$setup,
teardown = _merge.teardown,
_merge$formatResult = _merge.formatResult,
formatResult = _merge$formatResult === undefined ? function (r) {
formatResult = _merge$formatResult === void 0 ? function (r) {
return r;
} : _merge$formatResult;
(0, _assert2.default)(!skip && !only || skip !== only, 'Cannot enable both skip and only on a test');
(0, _assert.default)(!skip && !only || skip !== only, 'Cannot enable both skip and only on a test');

@@ -169,11 +125,50 @@ if (skip) {

function testerWrapper() {
return _testerWrapper.apply(this, arguments);
} // eslint-disable-next-line complexity
function _testerWrapper() {
_testerWrapper = _asyncToGenerator(function* () {
var teardowns = teardown ? [teardown] : [];
var returnedTeardown;
try {
returnedTeardown = yield setup();
} catch (e) {
// eslint-disable-next-line no-console
console.error('There was a problem during setup');
throw e;
}
if (typeof returnedTeardown === 'function') {
teardowns.push(returnedTeardown);
}
try {
tester();
} finally {
try {
yield Promise.all(teardowns.map(function (t) {
return t();
}));
} catch (e) {
// eslint-disable-next-line no-console
console.error('There was a problem during teardown'); // eslint-disable-next-line no-unsafe-finally
throw e;
}
}
});
return _testerWrapper.apply(this, arguments);
}
function tester() {
(0, _invariant2.default)(code, _commonTags.oneLine`
(0, _invariant.default)(code, _commonTags.oneLine`
A string or object with a \`code\` or
\`fixture\` property must be provided
`);
(0, _invariant2.default)(!babelOptions.babelrc || babelOptions.filename, 'babelrc set to true, but no filename specified in babelOptions');
(0, _invariant2.default)(!snapshot || !output, '`output` cannot be provided with `snapshot: true`');
var result = void 0;
(0, _invariant.default)(!babelOptions.babelrc || babelOptions.filename, 'babelrc set to true, but no filename specified in babelOptions');
(0, _invariant.default)(!snapshot || !output, '`output` cannot be provided with `snapshot: true`');
var result;
var errored = false;

@@ -193,6 +188,6 @@

var expectedToThrowButDidNot = error && !errored;
(0, _assert2.default)(!expectedToThrowButDidNot, 'Expected to throw error, but it did not.');
(0, _assert.default)(!expectedToThrowButDidNot, 'Expected to throw error, but it did not.');
if (snapshot) {
(0, _invariant2.default)(result !== code, _commonTags.oneLine`
(0, _invariant.default)(result !== code, _commonTags.oneLine`
Code was unmodified but attempted to take a snapshot.

@@ -207,9 +202,8 @@ If the code should not be modified, set \`snapshot: false\`

} else if (typeof output === 'string') {
_assert2.default.equal(result, output, 'Output is incorrect.');
_assert.default.equal(result, output, 'Output is incorrect.');
} else {
_assert2.default.equal(result, code, 'Expected output to not change, but it did');
_assert.default.equal(result, code, 'Expected output to not change, but it did');
}
}
});
return Promise.all(promises);

@@ -220,4 +214,7 @@ });

if (typeof testConfig === 'string') {
testConfig = { code: testConfig };
testConfig = {
code: testConfig
};
}
var _testConfig = testConfig,

@@ -227,17 +224,22 @@ title = _testConfig.title,

_testConfig$code = _testConfig.code,
code = _testConfig$code === undefined ? getCode(filename, fixture) : _testConfig$code,
code = _testConfig$code === void 0 ? getCode(filename, fixture) : _testConfig$code,
_testConfig$fullTitle = _testConfig.fullTitle,
fullTitle = _testConfig$fullTitle === undefined ? title || `${testNumber++}. ${pluginName}` : _testConfig$fullTitle,
fullTitle = _testConfig$fullTitle === void 0 ? title || `${testNumber++}. ${pluginName}` : _testConfig$fullTitle,
_testConfig$output = _testConfig.output,
output = _testConfig$output === undefined ? getCode(filename, testConfig.outputFixture) || undefined : _testConfig$output,
output = _testConfig$output === void 0 ? getCode(filename, testConfig.outputFixture) || undefined : _testConfig$output,
_testConfig$pluginOpt = _testConfig.pluginOptions,
testOptions = _testConfig$pluginOpt === undefined ? pluginOptions : _testConfig$pluginOpt;
return (0, _lodash2.default)({
babelOptions: { filename: getPath(filename, fixture) }
}, testConfig, _extends({
babelOptions: { plugins: [[plugin, testOptions]] },
testOptions = _testConfig$pluginOpt === void 0 ? pluginOptions : _testConfig$pluginOpt;
return (0, _lodash.default)({
babelOptions: {
filename: getPath(filename, fixture)
}
}, testConfig, _objectSpread({
babelOptions: {
plugins: [[plugin, testOptions]]
},
title: fullTitle,
code: (0, _stripIndent2.default)(code).trim()
}, output ? { output: (0, _stripIndent2.default)(output).trim() } : {}));
code: (0, _stripIndent.default)(code).trim()
}, output ? {
output: (0, _stripIndent.default)(output).trim()
} : {}));
}

@@ -247,8 +249,11 @@ }

var createFixtureTests = function createFixtureTests(fixturesDir, options) {
_fs2.default.readdirSync(fixturesDir).forEach(function (caseName) {
var fixtureDir = _path2.default.join(fixturesDir, caseName);
var jsCodePath = _path2.default.join(fixtureDir, 'code.js');
var tsCodePath = _path2.default.join(fixtureDir, 'code.ts');
_fs.default.readdirSync(fixturesDir).forEach(function (caseName) {
var fixtureDir = _path.default.join(fixturesDir, caseName);
var jsCodePath = _path.default.join(fixtureDir, 'code.js');
var tsCodePath = _path.default.join(fixtureDir, 'code.ts');
var blockTitle = caseName.split('-').join(' ');
var codePath = _pathExists2.default.sync(jsCodePath) && jsCodePath || _pathExists2.default.sync(tsCodePath) && tsCodePath;
var codePath = _pathExists.default.sync(jsCodePath) && jsCodePath || _pathExists.default.sync(tsCodePath) && tsCodePath;

@@ -268,7 +273,7 @@ if (!codePath) {

babel = options.babel,
rest = _objectWithoutProperties(options, ['plugin', 'pluginOptions', 'fixtureOutputName', 'babel']);
rest = _objectWithoutProperties(options, ["plugin", "pluginOptions", "fixtureOutputName", "babel"]);
var babelRcPath = _path2.default.join(fixtureDir, '.babelrc');
var babelRcPath = _path.default.join(fixtureDir, '.babelrc');
var _merge2 = (0, _lodash2.default)({}, fullDefaultConfig, {
var _merge2 = (0, _lodash.default)({}, fullDefaultConfig, {
babelOptions: {

@@ -278,3 +283,3 @@ plugins: [[plugin, pluginOptions]],

// otherwise, we'll just use our simple config
babelrc: _pathExists2.default.sync(babelRcPath)
babelrc: _pathExists.default.sync(babelRcPath)
}

@@ -286,12 +291,13 @@ }, rest),

var outputPath = _path2.default.join(fixtureDir, `${fixtureOutputName}${ext}`);
var outputPath = _path.default.join(fixtureDir, `${fixtureOutputName}${ext}`);
if (!_fs2.default.existsSync(outputPath)) {
_fs2.default.writeFileSync(outputPath, actual);
if (!_fs.default.existsSync(outputPath)) {
_fs.default.writeFileSync(outputPath, actual);
return;
}
var output = _fs2.default.readFileSync(outputPath, 'utf8').trim();
var output = _fs.default.readFileSync(outputPath, 'utf8').trim();
_assert2.default.equal(actual, output, `actual output does not match ${fixtureOutputName}${ext}`);
_assert.default.equal(actual, output, `actual output does not match ${fixtureOutputName}${ext}`);
});

@@ -301,7 +307,7 @@ });

function testFixtures(_ref3) {
var describeBlockTitle = _ref3.title,
fixtures = _ref3.fixtures,
filename = _ref3.filename,
rest = _objectWithoutProperties(_ref3, ['title', 'fixtures', 'filename']);
function testFixtures(_ref2) {
var describeBlockTitle = _ref2.title,
fixtures = _ref2.fixtures,
filename = _ref2.filename,
rest = _objectWithoutProperties(_ref2, ["title", "fixtures", "filename"]);

@@ -316,11 +322,17 @@ describe(`${describeBlockTitle} fixtures`, function () {

tests = tests || []; // null/0/false are ok, so no default param
if (Array.isArray(tests)) {
return tests;
}
return Object.keys(tests).reduce(function (testsArray, key) {
var value = tests[key];
if (typeof value === 'string') {
value = { code: value };
value = {
code: value
};
}
testsArray.push(_extends({
testsArray.push(_objectSpread({
title: key

@@ -336,3 +348,4 @@ }, value));

}
return _fs2.default.readFileSync(getPath(filename, fixture), 'utf8');
return _fs.default.readFileSync(getPath(filename, fixture), 'utf8');
}

@@ -344,9 +357,11 @@

}
if (_path2.default.isAbsolute(basename)) {
if (_path.default.isAbsolute(basename)) {
return basename;
}
return _path2.default.join(_path2.default.dirname(filename), basename);
}
// eslint-disable-next-line complexity
return _path.default.join(_path.default.dirname(filename), basename);
} // eslint-disable-next-line complexity
function assertError(result, error) {

@@ -358,7 +373,7 @@ if (typeof error === 'function') {

} else if (typeof error === 'string') {
_assert2.default.equal(result.message, error, 'Error message is incorrect');
(0, _assert.default)(result.message.includes(error), 'Error message is incorrect');
} else if (error instanceof RegExp) {
(0, _assert2.default)(error.test(result.message), `Expected ${result.message} to match ${error}`);
(0, _assert.default)(error.test(result.message), `Expected ${result.message} to match ${error}`);
} else {
(0, _invariant2.default)(typeof error === 'boolean', 'The given `error` must be a function, string, boolean, or RegExp');
(0, _invariant.default)(typeof error === 'boolean', 'The given `error` must be a function, string, boolean, or RegExp');
}

@@ -372,3 +387,4 @@ }

function getPluginName(plugin, babel) {
var name = void 0;
var name;
try {

@@ -384,6 +400,6 @@ name = plugin(babel).name;

}
(0, _invariant2.default)(name, 'The `pluginName` must be inferable or provided.');
(0, _invariant.default)(name, 'The `pluginName` must be inferable or provided.');
return name;
}
/*

@@ -390,0 +406,0 @@ eslint

@@ -1,1 +0,1 @@

{"name":"babel-plugin-tester","version":"5.5.2","description":"Utilities for testing babel plugins","main":"dist/index.js","engines":{"node":"> 4","npm":"> 3"},"scripts":{"add-contributor":"kcd-scripts contributors add","build":"kcd-scripts build","lint":"kcd-scripts lint","test":"kcd-scripts test","test:update":"npm test -- --updateSnapshot --coverage","validate":"kcd-scripts validate","precommit":"kcd-scripts precommit"},"files":["dist"],"keywords":[],"author":"Kent C. Dodds <kent@doddsfamily.us> (http://kentcdodds.com/)","license":"MIT","dependencies":{"common-tags":"^1.4.0","invariant":"^2.2.2","lodash.merge":"^4.6.0","path-exists":"^3.0.0","strip-indent":"^2.0.0"},"devDependencies":{"babel-core":"^6.25.0","babel-plugin-syntax-trailing-function-commas":"^6.22.0","babel-plugin-transform-async-generator-functions":"^6.24.1","babel-plugin-transform-async-to-generator":"^6.24.1","babel-plugin-transform-object-rest-spread":"^6.26.0","babel-preset-env":"^1.5.2","kcd-scripts":"^0.42.1"},"peerDependencies":{"babel-core":"^6.0.0 || ^7.0.0-alpha || ^7.0.0-beta || ^7.0.0"},"eslintConfig":{"extends":"./node_modules/kcd-scripts/eslint.js","rules":{"jest/valid-describe":0,"max-lines":0,"semi":[2,"never"]}},"eslintIgnore":["node_modules","coverage","dist","fixtures"],"babel":{"presets":[["env",{"targets":{"node":"4.5"},"exclude":["transform-regenerator"]}]],"plugins":["babel-plugin-syntax-trailing-function-commas","transform-async-to-generator","transform-async-generator-functions","transform-object-rest-spread"]},"repository":{"type":"git","url":"https://github.com/babel-utils/babel-plugin-tester.git"},"bugs":{"url":"https://github.com/babel-utils/babel-plugin-tester/issues"},"homepage":"https://github.com/babel-utils/babel-plugin-tester#readme"}
{"name":"babel-plugin-tester","version":"6.0.0","description":"Utilities for testing babel plugins","main":"dist/index.js","engines":{"node":"> 4","npm":"> 3"},"scripts":{"add-contributor":"kcd-scripts contributors add","build":"kcd-scripts build","lint":"kcd-scripts lint","test":"kcd-scripts test","test:update":"npm test -- --updateSnapshot --coverage","validate":"kcd-scripts validate","precommit":"kcd-scripts pre-commit"},"files":["dist"],"keywords":[],"author":"Kent C. Dodds <kent@doddsfamily.us> (http://kentcdodds.com/)","license":"MIT","dependencies":{"common-tags":"^1.4.0","invariant":"^2.2.2","lodash.merge":"^4.6.0","path-exists":"^3.0.0","strip-indent":"^2.0.0"},"devDependencies":{"@babel/core":"^7.2.0","@babel/plugin-proposal-async-generator-functions":"^7.2.0","@babel/plugin-transform-async-to-generator":"^7.2.0","@babel/preset-env":"^7.2.0","kcd-scripts":"^0.49.0"},"peerDependencies":{"@babel/core":"^7.0.0"},"eslintConfig":{"extends":"./node_modules/kcd-scripts/eslint.js","rules":{"max-lines":0,"max-lines-per-function":0,"prefer-object-spread":0,"no-useless-catch":0,"babel/camelcase":0,"babel/valid-typeof":0,"babel/no-unused-expressions":0,"babel/quotes":0,"jest/prefer-todo":0}},"eslintIgnore":["node_modules","coverage","dist","fixtures"],"babel":{"presets":[["@babel/preset-env",{"targets":{"node":"4.5"},"exclude":["transform-regenerator"]}]],"plugins":["@babel/plugin-transform-async-to-generator","@babel/plugin-proposal-async-generator-functions","@babel/plugin-proposal-object-rest-spread"]},"prettier":{"printWidth":80,"bracketSpacing":false,"semi":false,"singleQuote":true,"trailingComma":"all"},"repository":{"type":"git","url":"https://github.com/babel-utils/babel-plugin-tester.git"},"bugs":{"url":"https://github.com/babel-utils/babel-plugin-tester/issues"},"homepage":"https://github.com/babel-utils/babel-plugin-tester#readme"}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc