generated from ony3000/node-library-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from ony3000/fix-compound-component
Correctly extract name of compound component
- Loading branch information
Showing
13 changed files
with
1,151 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { format } from 'prettier'; | ||
import type { Fixture } from 'test-settings'; | ||
import { baseOptions } from 'test-settings'; | ||
import { describe, expect, test } from 'vitest'; | ||
|
||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import * as thisPlugin from '@/packages/v2-plugin'; | ||
|
||
const options = { | ||
...baseOptions, | ||
plugins: [thisPlugin], | ||
parser: 'babel', | ||
endingPosition: 'absolute', | ||
}; | ||
|
||
const fixtures: Fixture[] = [ | ||
{ | ||
name: 'component composition', | ||
input: ` | ||
export const Overlay = () => { | ||
return ( | ||
<Dialog.Overlay className="bg-popover backdrop-opacity-disabled focus:ring-0 fixed inset-0 z-50 h-screen w-screen" /> | ||
); | ||
}; | ||
`, | ||
output: `export const Overlay = () => { | ||
return ( | ||
<Dialog.Overlay | ||
className="bg-popover backdrop-opacity-disabled focus:ring-0 fixed inset-0 | ||
z-50 h-screen w-screen" | ||
/> | ||
); | ||
}; | ||
`, | ||
}, | ||
{ | ||
name: 'double composition', | ||
input: ` | ||
export const Overlay = () => { | ||
return ( | ||
<Foo.Dialog.Overlay className="bg-popover backdrop-opacity-disabled focus:ring-0 fixed inset-0 z-50 h-screen w-screen" /> | ||
); | ||
}; | ||
`, | ||
output: `export const Overlay = () => { | ||
return ( | ||
<Foo.Dialog.Overlay | ||
className="bg-popover backdrop-opacity-disabled focus:ring-0 fixed inset-0 | ||
z-50 h-screen w-screen" | ||
/> | ||
); | ||
}; | ||
`, | ||
}, | ||
{ | ||
name: 'triple composition', | ||
input: ` | ||
export const Overlay = () => { | ||
return ( | ||
<Foo.Bar.Dialog.Overlay className="bg-popover backdrop-opacity-disabled focus:ring-0 fixed inset-0 z-50 h-screen w-screen" /> | ||
); | ||
}; | ||
`, | ||
output: `export const Overlay = () => { | ||
return ( | ||
<Foo.Bar.Dialog.Overlay | ||
className="bg-popover backdrop-opacity-disabled focus:ring-0 fixed inset-0 | ||
z-50 h-screen w-screen" | ||
/> | ||
); | ||
}; | ||
`, | ||
}, | ||
]; | ||
|
||
describe.each(fixtures)('$name', ({ input, output, options: fixtureOptions }) => { | ||
const fixedOptions = { | ||
...options, | ||
...(fixtureOptions ?? {}), | ||
}; | ||
const formattedText = format(input, fixedOptions); | ||
|
||
test('expectation', () => { | ||
expect(formattedText).toBe(output); | ||
}); | ||
|
||
test.runIf(formattedText === output)('consistency', () => { | ||
const doubleFormattedText = format(formattedText, fixedOptions); | ||
|
||
expect(doubleFormattedText).toBe(formattedText); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { format } from 'prettier'; | ||
import type { Fixture } from 'test-settings'; | ||
import { baseOptions } from 'test-settings'; | ||
import { describe, expect, test } from 'vitest'; | ||
|
||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import * as thisPlugin from '@/packages/v2-plugin'; | ||
|
||
const options = { | ||
...baseOptions, | ||
plugins: [thisPlugin], | ||
parser: 'babel', | ||
endingPosition: 'absolute-with-indent', | ||
}; | ||
|
||
const fixtures: Fixture[] = [ | ||
{ | ||
name: 'component composition', | ||
input: ` | ||
export const Overlay = () => { | ||
return ( | ||
<Dialog.Overlay className="bg-popover backdrop-opacity-disabled focus:ring-0 fixed inset-0 z-50 h-screen w-screen" /> | ||
); | ||
}; | ||
`, | ||
output: `export const Overlay = () => { | ||
return ( | ||
<Dialog.Overlay | ||
className="bg-popover backdrop-opacity-disabled focus:ring-0 fixed inset-0 | ||
z-50 h-screen w-screen" | ||
/> | ||
); | ||
}; | ||
`, | ||
}, | ||
{ | ||
name: 'double composition', | ||
input: ` | ||
export const Overlay = () => { | ||
return ( | ||
<Foo.Dialog.Overlay className="bg-popover backdrop-opacity-disabled focus:ring-0 fixed inset-0 z-50 h-screen w-screen" /> | ||
); | ||
}; | ||
`, | ||
output: `export const Overlay = () => { | ||
return ( | ||
<Foo.Dialog.Overlay | ||
className="bg-popover backdrop-opacity-disabled focus:ring-0 fixed inset-0 | ||
z-50 h-screen w-screen" | ||
/> | ||
); | ||
}; | ||
`, | ||
}, | ||
{ | ||
name: 'triple composition', | ||
input: ` | ||
export const Overlay = () => { | ||
return ( | ||
<Foo.Bar.Dialog.Overlay className="bg-popover backdrop-opacity-disabled focus:ring-0 fixed inset-0 z-50 h-screen w-screen" /> | ||
); | ||
}; | ||
`, | ||
output: `export const Overlay = () => { | ||
return ( | ||
<Foo.Bar.Dialog.Overlay | ||
className="bg-popover backdrop-opacity-disabled focus:ring-0 fixed inset-0 | ||
z-50 h-screen w-screen" | ||
/> | ||
); | ||
}; | ||
`, | ||
}, | ||
]; | ||
|
||
describe.each(fixtures)('$name', ({ input, output, options: fixtureOptions }) => { | ||
const fixedOptions = { | ||
...options, | ||
...(fixtureOptions ?? {}), | ||
}; | ||
const formattedText = format(input, fixedOptions); | ||
|
||
test('expectation', () => { | ||
expect(formattedText).toBe(output); | ||
}); | ||
|
||
test.runIf(formattedText === output)('consistency', () => { | ||
const doubleFormattedText = format(formattedText, fixedOptions); | ||
|
||
expect(doubleFormattedText).toBe(formattedText); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { format } from 'prettier'; | ||
import type { Fixture } from 'test-settings'; | ||
import { baseOptions } from 'test-settings'; | ||
import { describe, expect, test } from 'vitest'; | ||
|
||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import * as thisPlugin from '@/packages/v2-plugin'; | ||
|
||
const options = { | ||
...baseOptions, | ||
plugins: [thisPlugin], | ||
parser: 'babel', | ||
endingPosition: 'relative', | ||
}; | ||
|
||
const fixtures: Fixture[] = [ | ||
{ | ||
name: 'component composition', | ||
input: ` | ||
export const Overlay = () => { | ||
return ( | ||
<Dialog.Overlay className="bg-popover backdrop-opacity-disabled focus:ring-0 fixed inset-0 z-50 h-screen w-screen" /> | ||
); | ||
}; | ||
`, | ||
output: `export const Overlay = () => { | ||
return ( | ||
<Dialog.Overlay | ||
className="bg-popover backdrop-opacity-disabled focus:ring-0 fixed inset-0 z-50 h-screen | ||
w-screen" | ||
/> | ||
); | ||
}; | ||
`, | ||
}, | ||
{ | ||
name: 'double composition', | ||
input: ` | ||
export const Overlay = () => { | ||
return ( | ||
<Foo.Dialog.Overlay className="bg-popover backdrop-opacity-disabled focus:ring-0 fixed inset-0 z-50 h-screen w-screen" /> | ||
); | ||
}; | ||
`, | ||
output: `export const Overlay = () => { | ||
return ( | ||
<Foo.Dialog.Overlay | ||
className="bg-popover backdrop-opacity-disabled focus:ring-0 fixed inset-0 z-50 h-screen | ||
w-screen" | ||
/> | ||
); | ||
}; | ||
`, | ||
}, | ||
{ | ||
name: 'triple composition', | ||
input: ` | ||
export const Overlay = () => { | ||
return ( | ||
<Foo.Bar.Dialog.Overlay className="bg-popover backdrop-opacity-disabled focus:ring-0 fixed inset-0 z-50 h-screen w-screen" /> | ||
); | ||
}; | ||
`, | ||
output: `export const Overlay = () => { | ||
return ( | ||
<Foo.Bar.Dialog.Overlay | ||
className="bg-popover backdrop-opacity-disabled focus:ring-0 fixed inset-0 z-50 h-screen | ||
w-screen" | ||
/> | ||
); | ||
}; | ||
`, | ||
}, | ||
]; | ||
|
||
describe.each(fixtures)('$name', ({ input, output, options: fixtureOptions }) => { | ||
const fixedOptions = { | ||
...options, | ||
...(fixtureOptions ?? {}), | ||
}; | ||
const formattedText = format(input, fixedOptions); | ||
|
||
test('expectation', () => { | ||
expect(formattedText).toBe(output); | ||
}); | ||
|
||
test.runIf(formattedText === output)('consistency', () => { | ||
const doubleFormattedText = format(formattedText, fixedOptions); | ||
|
||
expect(doubleFormattedText).toBe(formattedText); | ||
}); | ||
}); |
Oops, something went wrong.