Skip to content

Commit e6c219f

Browse files
André NevesKent C. Dodds
André Neves
authored and
Kent C. Dodds
committed
feat(fixtures): allow formatting fixtures results (#39)
1 parent f3d7b5b commit e6c219f

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

.all-contributorsrc

+10
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@
6969
"code",
7070
"test"
7171
]
72+
},
73+
{
74+
"login": "andrefgneves",
75+
"name": "André Neves",
76+
"avatar_url": "https://avatars2.githubusercontent.com/u/3869532?v=4",
77+
"profile": "http://andreneves.work",
78+
"contributions": [
79+
"code",
80+
"test"
81+
]
7282
}
7383
],
7484
"repoType": "github"

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Utilities for testing babel plugins
99
[![downloads][downloads-badge]][npm-stat]
1010
[![MIT License][license-badge]][license]
1111

12-
[![All Contributors](https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square)](#contributors)
12+
[![All Contributors](https://img.shields.io/badge/all_contributors-7-orange.svg?style=flat-square)](#contributors)
1313
[![PRs Welcome][prs-badge]][prs]
1414
[![Donate][donate-badge]][donate]
1515
[![Code of Conduct][coc-badge]][coc]
@@ -463,8 +463,8 @@ Thanks goes to these people ([emoji key][emojis]):
463463

464464
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
465465
<!-- prettier-ignore -->
466-
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;" alt="Kent C. Dodds"/><br /><sub><b>Kent C. Dodds</b></sub>](https://kentcdodds.com)<br />[💻](https://github.com/babel-utils/babel-plugin-tester/commits?author=kentcdodds "Code") [📖](https://github.com/babel-utils/babel-plugin-tester/commits?author=kentcdodds "Documentation") [🚇](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/babel-utils/babel-plugin-tester/commits?author=kentcdodds "Tests") | [<img src="https://avatars3.githubusercontent.com/u/952783?v=3" width="100px;" alt="james kyle"/><br /><sub><b>james kyle</b></sub>](http://thejameskyle.com/)<br />[💻](https://github.com/babel-utils/babel-plugin-tester/commits?author=thejameskyle "Code") [📖](https://github.com/babel-utils/babel-plugin-tester/commits?author=thejameskyle "Documentation") [👀](#review-thejameskyle "Reviewed Pull Requests") [⚠️](https://github.com/babel-utils/babel-plugin-tester/commits?author=thejameskyle "Tests") | [<img src="https://avatars1.githubusercontent.com/u/1894628?v=3" width="100px;" alt="Brad Bohen"/><br /><sub><b>Brad Bohen</b></sub>](https://github.com/bbohen)<br />[🐛](https://github.com/babel-utils/babel-plugin-tester/issues?q=author%3Abbohen "Bug reports") | [<img src="https://avatars0.githubusercontent.com/u/1295580?v=3" width="100px;" alt="Kyle Welch"/><br /><sub><b>Kyle Welch</b></sub>](http://www.krwelch.com)<br />[💻](https://github.com/babel-utils/babel-plugin-tester/commits?author=kwelch "Code") [📖](https://github.com/babel-utils/babel-plugin-tester/commits?author=kwelch "Documentation") [⚠️](https://github.com/babel-utils/babel-plugin-tester/commits?author=kwelch "Tests") | [<img src="https://avatars3.githubusercontent.com/u/6680299?v=4" width="100px;" alt="kontrollanten"/><br /><sub><b>kontrollanten</b></sub>](https://github.com/kontrollanten)<br />[💻](https://github.com/babel-utils/babel-plugin-tester/commits?author=kontrollanten "Code") | [<img src="https://avatars3.githubusercontent.com/u/117921?v=4" width="100px;" alt="Rubén Norte"/><br /><sub><b>Rubén Norte</b></sub>](https://github.com/rubennorte)<br />[💻](https://github.com/babel-utils/babel-plugin-tester/commits?author=rubennorte "Code") [⚠️](https://github.com/babel-utils/babel-plugin-tester/commits?author=rubennorte "Tests") |
467-
| :---: | :---: | :---: | :---: | :---: | :---: |
466+
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;" alt="Kent C. Dodds"/><br /><sub><b>Kent C. Dodds</b></sub>](https://kentcdodds.com)<br />[💻](https://github.com/babel-utils/babel-plugin-tester/commits?author=kentcdodds "Code") [📖](https://github.com/babel-utils/babel-plugin-tester/commits?author=kentcdodds "Documentation") [🚇](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/babel-utils/babel-plugin-tester/commits?author=kentcdodds "Tests") | [<img src="https://avatars3.githubusercontent.com/u/952783?v=3" width="100px;" alt="james kyle"/><br /><sub><b>james kyle</b></sub>](http://thejameskyle.com/)<br />[💻](https://github.com/babel-utils/babel-plugin-tester/commits?author=thejameskyle "Code") [📖](https://github.com/babel-utils/babel-plugin-tester/commits?author=thejameskyle "Documentation") [👀](#review-thejameskyle "Reviewed Pull Requests") [⚠️](https://github.com/babel-utils/babel-plugin-tester/commits?author=thejameskyle "Tests") | [<img src="https://avatars1.githubusercontent.com/u/1894628?v=3" width="100px;" alt="Brad Bohen"/><br /><sub><b>Brad Bohen</b></sub>](https://github.com/bbohen)<br />[🐛](https://github.com/babel-utils/babel-plugin-tester/issues?q=author%3Abbohen "Bug reports") | [<img src="https://avatars0.githubusercontent.com/u/1295580?v=3" width="100px;" alt="Kyle Welch"/><br /><sub><b>Kyle Welch</b></sub>](http://www.krwelch.com)<br />[💻](https://github.com/babel-utils/babel-plugin-tester/commits?author=kwelch "Code") [📖](https://github.com/babel-utils/babel-plugin-tester/commits?author=kwelch "Documentation") [⚠️](https://github.com/babel-utils/babel-plugin-tester/commits?author=kwelch "Tests") | [<img src="https://avatars3.githubusercontent.com/u/6680299?v=4" width="100px;" alt="kontrollanten"/><br /><sub><b>kontrollanten</b></sub>](https://github.com/kontrollanten)<br />[💻](https://github.com/babel-utils/babel-plugin-tester/commits?author=kontrollanten "Code") | [<img src="https://avatars3.githubusercontent.com/u/117921?v=4" width="100px;" alt="Rubén Norte"/><br /><sub><b>Rubén Norte</b></sub>](https://github.com/rubennorte)<br />[💻](https://github.com/babel-utils/babel-plugin-tester/commits?author=rubennorte "Code") [⚠️](https://github.com/babel-utils/babel-plugin-tester/commits?author=rubennorte "Tests") | [<img src="https://avatars2.githubusercontent.com/u/3869532?v=4" width="100px;" alt="André Neves"/><br /><sub><b>André Neves</b></sub>](http://andreneves.work)<br />[💻](https://github.com/babel-utils/babel-plugin-tester/commits?author=andrefgneves "Code") [⚠️](https://github.com/babel-utils/babel-plugin-tester/commits?author=andrefgneves "Tests") |
467+
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
468468

469469
<!-- ALL-CONTRIBUTORS-LIST:END -->
470470

src/__tests__/index.js

+11
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,17 @@ test('allows formatting the result', async () => {
603603
expect(formatResultSpy).toHaveBeenCalledWith(simpleTest)
604604
})
605605

606+
test('allows formatting fixtures results', async () => {
607+
const formatResultSpy = jest.fn(r => r)
608+
await runPluginTester(
609+
getOptions({
610+
fixtures: getFixturePath('fixtures'),
611+
formatResult: formatResultSpy,
612+
}),
613+
)
614+
expect(formatResultSpy).toHaveBeenCalledTimes(7)
615+
})
616+
606617
function getOptions(overrides) {
607618
return {
608619
pluginName: 'captains-log',

src/index.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,14 @@ const createFixtureTests = (fixturesDir, options) => {
225225

226226
const ext = /\.ts$/.test(codePath) ? '.ts' : '.js'
227227
it(blockTitle, () => {
228-
const {plugin, pluginOptions, fixtureOutputName, babel, ...rest} = options
228+
const {
229+
plugin,
230+
pluginOptions,
231+
fixtureOutputName,
232+
babel,
233+
formatResult = r => r,
234+
...rest
235+
} = options
229236

230237
const babelRcPath = path.join(fixtureDir, '.babelrc')
231238

@@ -242,7 +249,9 @@ const createFixtureTests = (fixturesDir, options) => {
242249
},
243250
rest,
244251
)
245-
const actual = babel.transformFileSync(codePath, babelOptions).code.trim()
252+
const actual = formatResult(
253+
babel.transformFileSync(codePath, babelOptions).code.trim(),
254+
)
246255

247256
const outputPath = path.join(fixtureDir, `${fixtureOutputName}${ext}`)
248257

0 commit comments

Comments
 (0)