Skip to content

Commit dd01d8b

Browse files
merceyzKent C. Dodds
authored andcommitted
fix: support all babelrc files (#54)
1 parent c848bfe commit dd01d8b

File tree

8 files changed

+32
-9
lines changed

8 files changed

+32
-9
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
plugins: [
3+
require.resolve("@babel/plugin-syntax-jsx")
4+
]
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default <div></div>;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
plugins: [
3+
require.resolve("@babel/plugin-syntax-jsx")
4+
]
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default <div></div>;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"plugins": [
3+
"@babel/plugin-syntax-jsx"
4+
]
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default <div></div>;

src/__tests__/index.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,13 @@ test('can pass tests in fixtures relative to the filename', async () => {
301301
tests: null,
302302
}),
303303
)
304-
expect(describeSpy).toHaveBeenCalledTimes(5)
305-
expect(itSpy).toHaveBeenCalledTimes(10)
304+
expect(describeSpy).toHaveBeenCalledTimes(6)
305+
expect(itSpy).toHaveBeenCalledTimes(13)
306306

307307
expect(itSpy.mock.calls).toEqual([
308+
[`cjs`, expect.any(Function)],
309+
[`js`, expect.any(Function)],
310+
[`normal`, expect.any(Function)],
308311
[`changed`, expect.any(Function)],
309312
[`jsx support`, expect.any(Function)],
310313
[`nested a`, expect.any(Function)],
@@ -612,7 +615,7 @@ test('allows formatting fixtures results', async () => {
612615
formatResult: formatResultSpy,
613616
}),
614617
)
615-
expect(formatResultSpy).toHaveBeenCalledTimes(11)
618+
expect(formatResultSpy).toHaveBeenCalledTimes(14)
616619
})
617620

618621
test('works with a formatter adding a empty line', async () => {
@@ -624,7 +627,7 @@ test('works with a formatter adding a empty line', async () => {
624627
formatResult: formatResultSpy,
625628
}),
626629
)
627-
expect(formatResultSpy).toHaveBeenCalledTimes(11)
630+
expect(formatResultSpy).toHaveBeenCalledTimes(14)
628631
})
629632

630633
test('gets options from options.json files when using fixtures', async () => {
@@ -656,7 +659,7 @@ test('gets options from options.json files when using fixtures', async () => {
656659
}),
657660
)
658661

659-
expect(optionRootFoo).toHaveBeenCalledTimes(10)
662+
expect(optionRootFoo).toHaveBeenCalledTimes(13)
660663
expect(optionFoo).toHaveBeenCalledTimes(2)
661664
expect(optionBar).toHaveBeenCalledTimes(1)
662665
})
@@ -701,10 +704,10 @@ test('appends to root plugins array', async () => {
701704
}),
702705
)
703706

704-
expect(optionRootFoo).toHaveBeenCalledTimes(10)
707+
expect(optionRootFoo).toHaveBeenCalledTimes(13)
705708
expect(optionFoo).toHaveBeenCalledTimes(2)
706709
expect(optionBar).toHaveBeenCalledTimes(1)
707-
expect(programVisitor).toHaveBeenCalledTimes(11)
710+
expect(programVisitor).toHaveBeenCalledTimes(14)
708711
})
709712

710713
test('endOfLine - default', async () => {

src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,9 @@ const createFixtureTests = (fixturesDir, options) => {
303303
...rest
304304
} = options
305305

306-
const babelRcPath = path.join(fixtureDir, '.babelrc')
306+
const hasBabelrc = ['.babelrc', '.babelrc.js', '.babelrc.cjs'].some(
307+
babelrc => fs.existsSync(path.join(fixtureDir, babelrc)),
308+
)
307309

308310
const {babelOptions} = mergeWith(
309311
{},
@@ -322,7 +324,7 @@ const createFixtureTests = (fixturesDir, options) => {
322324
],
323325
// if they have a babelrc, then we'll let them use that
324326
// otherwise, we'll just use our simple config
325-
babelrc: fs.existsSync(babelRcPath),
327+
babelrc: hasBabelrc,
326328
},
327329
},
328330
rest,

0 commit comments

Comments
 (0)