babel-test
Advanced tools
Comparing version 0.1.1 to 0.1.2
{ | ||
"name": "babel-test", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "An opinionated library to make testing Babel plugins easier", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
# babel-test | ||
[![Build Status][build-badge]][build] | ||
[![Code Coverage][coverage-badge]][coverage] | ||
[![MIT License][license-badge]][license] | ||
[![Version][version-badge]][package] | ||
An opinionated library to make testing babel plugins easier. | ||
@@ -11,5 +16,5 @@ | ||
I also felt that the current solutions add too much abstraction and I wanted to make something simpler and opinionated. For example, the options passed to the tool are in the same format as the options passed to Babel which makes it easier to understand. I built this instead of contributing to existing tools because it's not really addressing lack of features in existing tools, just exploring a different API. | ||
I also felt that the current solutions add too much abstraction and I wanted to make something simpler. I built this instead of contributing to existing tools because it's not addressing lack of features in existing tools, but exploring a different API. | ||
The tool is fairly simple and works with [Jest](https://jestjs.io/) (recommended) or any testing framework which provides the `describe` and `it` global functions, such as [Mocha](https://mochajs.org/). | ||
The tool works with [Jest](https://jestjs.io/) (recommended) or any testing framework which provides the `describe` and `it` global functions, such as [Mocha](https://mochajs.org/). | ||
@@ -33,2 +38,3 @@ ## Installation | ||
```js | ||
import path from 'path'; | ||
import { create } from 'babel-test'; | ||
@@ -55,3 +61,3 @@ | ||
You can pass anything that babel supports to the `create` function. It'll additionally set `babelrc` and `configFile` options to `false` by default if you haven't explicitly passed it. This avoids your tests being affected by external babel configuration. | ||
The `create` function accepts the same [`options` object as Babel](https://babeljs.io/docs/en/options). It'll additionally set `babelrc` and `configFile` options to `false` by default if you haven't explicitly passed them. This avoids your tests being affected by external babel configuration. | ||
@@ -66,3 +72,3 @@ ### Testing fixtures | ||
It accepts a title for the `describe` block and the path to the directory containing the fixtures, and optionally a custom callback to configure the output file. | ||
It accepts a title for the `describe` block and the absolute path to the directory containing the fixtures. | ||
@@ -84,3 +90,3 @@ The fixtures directory should contain subdirectories with test files. Every test should contain a `code.js` file, which will be used as the input. If the transform should throw, it should have an `error.js` file. If the transform should pass, it should have an `output.js` file with the transformed code. The title for each test will be based the name of the directory. The first argument is used as the title for the describe block. | ||
You can use `fixtures.skip` and `fixtures.only`, similar to Jest's `describe.skip` and `describe.only`. To skip an individual fixture, you can rename the fixture's directory to `skip.name-of-the-fixture`, and to run a specific fixture, you can rename the fixture's directory to `only.name-of-the-fixture`. | ||
You can use `fixtures.skip` and `fixtures.only`, similar to Jest's `describe.skip` and `describe.only`. To skip an individual fixture, you can rename the fixture's directory to `skip.name-of-the-fixture`, and to run a specific fixture only, you can rename the fixture's directory to `only.name-of-the-fixture`. | ||
@@ -101,3 +107,3 @@ By default, it will compare the outputs with the files on the filesystem and you have to manually update the files in case of a mismatch. If you're using Jest, you can use the snapshot feature to automatically update the files with a keypress. ([See below](#integration-with-jest-snapshot)) on how to set it up. | ||
It accepts a title for the test and a callback containing the test. The callback will receive a `transform` function, and should return a promise if it's asynchronous. The `transform` function takes an optional second parameter containing additional [`options` for babel](https://babeljs.io/docs/en/options), useful for passing additional information such as `filename` required by some plugins. | ||
It accepts a title for the test and a callback containing the test. The callback will receive a `transform` function, and should return a promise if it's asynchronous. The `transform` function takes an optional second parameter containing additional options for Babel, useful for passing additional information such as `filename` required by some plugins. | ||
@@ -152,5 +158,32 @@ You can use `test.skip` and `test.only`, similar to Jest's `it.skip` and `it.only`. | ||
## Other solutions | ||
## Alternatives | ||
- [`babel-plugin-tester`](https://github.com/babel-utils/babel-plugin-tester) | ||
- [`@babel/helper-plugin-test-runner`](https://github.com/babel/babel/tree/master/packages/babel-helper-plugin-test-runner) | ||
## Contributing | ||
Make sure your code passes the unit tests, ESLint and TypeScript. Run the following to verify: | ||
```sh | ||
yarn test | ||
yarn lint | ||
yarn typescript | ||
``` | ||
To fix formatting errors, run the following: | ||
```sh | ||
yarn lint -- --fix | ||
``` | ||
<!-- badges --> | ||
[build-badge]: https://img.shields.io/circleci/project/github/satya164/babel-test/master.svg?style=flat-square | ||
[build]: https://circleci.com/gh/satya164/babel-test | ||
[coverage-badge]: https://img.shields.io/codecov/c/github/satya164/babel-test.svg?style=flat-square | ||
[coverage]: https://codecov.io/github/satya164/babel-test | ||
[license-badge]: https://img.shields.io/npm/l/babel-test.svg?style=flat-square | ||
[license]: https://opensource.org/licenses/MIT | ||
[version-badge]: https://img.shields.io/npm/v/babel-test.svg?style=flat-square | ||
[package]: https://www.npmjs.com/package/babel-test |
@@ -12,2 +12,12 @@ /* eslint-disable jest/no-disabled-tests, jest/no-focused-tests */ | ||
exports.create = function create(config) { | ||
// Check if `describe` and `it` globals are available and throw if not | ||
// This avoids confusion with unsupported test runners and incorect usage | ||
if (!('describe' in global && 'it' in global)) { | ||
throw new Error( | ||
`Couldn't find ${chalk.blue('describe')} and ${chalk.blue( | ||
'it' | ||
)} in the global scope. Are you using a supported test runner such as Jest (https://jestjs.io) or Mocha (https://mochajs.org)?\n` | ||
); | ||
} | ||
const transform = | ||
@@ -20,7 +30,7 @@ typeof config === 'function' | ||
code, | ||
// By default, disable reading babel config | ||
// This makes sure that the tests are self contained | ||
Object.assign( | ||
{ | ||
caller: { name: 'babel-test' }, | ||
// By default, disable reading babel config | ||
// This makes sure that the tests are self contained | ||
babelrc: false, | ||
@@ -38,2 +48,3 @@ configFile: false, | ||
.forEach(f => { | ||
// Respect skip. and only. prefixes in folder names | ||
const t = f.startsWith('skip.') | ||
@@ -40,0 +51,0 @@ ? it.skip |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17636
238
183