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 3.1.0 to 3.2.0

128

dist/index.js

@@ -43,4 +43,8 @@ 'use strict';

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;

@@ -83,10 +87,84 @@

if (!testAsArray.length) {
return;
return Promise.resolve();
}
var testerConfig = (0, _lodash2.default)({}, fullDefaultConfig, rest);
describe(describeBlockTitle, function () {
testAsArray.forEach(function (testConfig, index) {
return describe(describeBlockTitle, function () {
var promises = testAsArray.map(function (testConfig, index) {
var testerWrapper = function () {
var _ref2 = _asyncToGenerator(regeneratorRuntime.mark(function _callee() {
var teardowns, returnedTeardown;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
teardowns = teardown ? [teardown] : [];
returnedTeardown = void 0;
_context.prev = 2;
_context.next = 5;
return setup();
case 5:
returnedTeardown = _context.sent;
_context.next = 12;
break;
case 8:
_context.prev = 8;
_context.t0 = _context['catch'](2);
// eslint-disable-next-line no-console
console.error('There was a problem during setup');
throw _context.t0;
case 12:
if (typeof returnedTeardown === 'function') {
teardowns.push(returnedTeardown);
}
_context.prev = 13;
tester();
case 15:
_context.prev = 15;
_context.prev = 16;
_context.next = 19;
return Promise.all(teardowns.map(function (t) {
return t();
}));
case 19:
_context.next = 25;
break;
case 21:
_context.prev = 21;
_context.t1 = _context['catch'](16);
// eslint-disable-next-line no-console
console.error('There was a problem during teardown');
// eslint-disable-next-line no-unsafe-finally
throw _context.t1;
case 25:
return _context.finish(15);
case 26:
case 'end':
return _context.stop();
}
}
}, _callee, this, [[2, 8], [13,, 15, 26], [16, 21]]);
}));
return function testerWrapper() {
return _ref2.apply(this, arguments);
};
}();
// eslint-disable-next-line complexity
if (!testConfig) {
return;
return Promise.resolve();
}

@@ -109,3 +187,6 @@

snapshot = _merge.snapshot,
error = _merge.error;
error = _merge.error,
_merge$setup = _merge.setup,
setup = _merge$setup === undefined ? noop : _merge$setup,
teardown = _merge.teardown;

@@ -116,11 +197,10 @@ (0, _assert2.default)(!skip && !only || skip !== only, 'Cannot enable both skip and only on a test');

// eslint-disable-next-line jest/no-disabled-tests
it.skip(title, tester);
return it.skip(title, testerWrapper);
} else if (only) {
// eslint-disable-next-line jest/no-focused-tests
it.only(title, tester);
return it.only(title, testerWrapper);
} else {
it(title, tester);
return it(title, testerWrapper);
}
// eslint-disable-next-line complexity
function tester() {

@@ -168,12 +248,14 @@ (0, _invariant2.default)(code, _commonTags.oneLine`

});
return Promise.all(promises);
});
}
function testFixtures(_ref2) {
var plugin = _ref2.plugin,
pluginOptions = _ref2.pluginOptions,
describeBlockTitle = _ref2.title,
fixtures = _ref2.fixtures,
filename = _ref2.filename,
rest = _objectWithoutProperties(_ref2, ['plugin', 'pluginOptions', 'title', 'fixtures', 'filename']);
function testFixtures(_ref3) {
var plugin = _ref3.plugin,
pluginOptions = _ref3.pluginOptions,
describeBlockTitle = _ref3.title,
fixtures = _ref3.fixtures,
filename = _ref3.filename,
rest = _objectWithoutProperties(_ref3, ['plugin', 'pluginOptions', 'title', 'fixtures', 'filename']);

@@ -225,9 +307,9 @@ describe(`${describeBlockTitle} fixtures`, function () {

function toTestConfig(_ref3) {
var testConfig = _ref3.testConfig,
index = _ref3.index,
plugin = _ref3.plugin,
pluginName = _ref3.pluginName,
pluginOptions = _ref3.pluginOptions,
filename = _ref3.filename;
function toTestConfig(_ref4) {
var testConfig = _ref4.testConfig,
index = _ref4.index,
plugin = _ref4.plugin,
pluginName = _ref4.pluginName,
pluginOptions = _ref4.pluginOptions,
filename = _ref4.filename;

@@ -234,0 +316,0 @@ if (typeof testConfig === 'string') {

22

package.json
{
"name": "babel-plugin-tester",
"version": "3.1.0",
"version": "3.2.0",
"description": "Utilities for testing babel plugins",

@@ -19,3 +19,3 @@ "main": "dist/index.js",

"dependencies": {
"babel-core": "^6.24.1",
"babel-core": "^6.25.0",
"common-tags": "^1.4.0",

@@ -30,4 +30,4 @@ "invariant": "^2.2.2",

"babel-cli": "^6.23.0",
"babel-jest": "^20.0.1",
"babel-preset-env": "^1.2.0",
"babel-jest": "^20.0.3",
"babel-preset-env": "^1.5.2",
"babel-preset-stage-2": "^6.22.0",

@@ -39,12 +39,12 @@ "babel-register": "^6.23.0",

"eslint": "^3.17.0",
"eslint-config-kentcdodds": "^12.0.0",
"husky": "^0.13.2",
"jest-cli": "^20.0.1",
"lint-staged": "^3.3.1",
"nps": "^5.0.3",
"eslint-config-kentcdodds": "^12.4.1",
"husky": "^0.14.1",
"jest-cli": "^20.0.4",
"lint-staged": "^4.0.0",
"nps": "^5.3.2",
"nps-utils": "^1.1.2",
"opt-cli": "^1.5.1",
"prettier-eslint-cli": "^3.1.2",
"prettier-eslint-cli": "^4.1.1",
"semantic-release": "^6.3.6",
"validate-commit-msg": "^2.11.1"
"validate-commit-msg": "^2.12.2"
},

@@ -51,0 +51,0 @@ "eslintConfig": {

@@ -237,2 +237,16 @@ # babel-plugin-tester

#### setup
If you need something set up before a particular test is run, you can do this
with `setup`. This function will be run before the test runs. It can return
a function which will be treated as a `teardown` function. It can also return
a promise. If that promise resolves to a function, that will be treated as a
`teardown` function.
#### teardown
If you set up some state, it's quite possible you want to tear it down. You can
either define this as its own property, or you can return it from the `setup`
function. This can likewise return a promise if it's asynchronous.
## Examples

@@ -246,2 +260,5 @@

// NOTE: you can use beforeAll, afterAll, beforeEach, and afterEach
// right here if you need
pluginTester({

@@ -339,2 +356,16 @@ // required

},
{
title: 'unchanged code',
setup() {
// runs before this test
return function teardown() {
// runs after this tests
}
// can also return a promise
},
teardown() {
// runs after this test
// can return a promise
},
},
],

@@ -341,0 +372,0 @@ })

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