Skip to content

Commit

Permalink
feat: provide your own implementation of babel (#25)
Browse files Browse the repository at this point in the history
* feat: provide your own implementation of babel

* docs(babel): update options to add babel

* chore(eslint): fix eslint errors
  • Loading branch information
Kent C. Dodds committed Jun 2, 2018
1 parent c628efb commit cb230ec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ specified `title` property or the `pluginName`.

Read more about test objects below.

#### babel

Use this to provide your own implementation of babel. This is particularly
useful if you want to use a different version of babel than what's included
in this package.

#### ...rest

The rest of the options you provide will be [`lodash.merge`][lodash.merge]d
Expand Down
15 changes: 12 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fs from 'fs'
import pathExists from 'path-exists'
import merge from 'lodash.merge'
import invariant from 'invariant'
import * as babel from 'babel-core'
import * as babelCore from 'babel-core'
import stripIndent from 'strip-indent'
import {oneLine} from 'common-tags'

Expand All @@ -22,8 +22,10 @@ const fullDefaultConfig = {

function pluginTester(
{
/* istanbul ignore next (TODO: write a test for this) */
babel = babelCore,
plugin = requiredParam('plugin'),
pluginName = getPluginName(plugin),
pluginName = getPluginName(plugin, babel),
title: describeBlockTitle = pluginName,
pluginOptions,
tests,
Expand All @@ -41,6 +43,7 @@ function pluginTester(
title: describeBlockTitle,
fixtures,
filename,
babel,
...rest,
})
}
Expand Down Expand Up @@ -209,6 +212,7 @@ function testFixtures({
title: describeBlockTitle,
fixtures,
filename,
babel,
...rest
}) {
describe(`${describeBlockTitle} fixtures`, () => {
Expand Down Expand Up @@ -306,7 +310,7 @@ function requiredParam(name) {
throw new Error(`${name} is a required parameter.`)
}

function getPluginName(plugin) {
function getPluginName(plugin, babel) {
let name
try {
name = plugin(babel).name
Expand All @@ -323,3 +327,8 @@ function getPluginName(plugin) {
invariant(name, 'The `pluginName` must be inferable or provided.')
return name
}

/*
eslint
complexity: "off"
*/

0 comments on commit cb230ec

Please sign in to comment.