-
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.
feat: add prettier format for eslint config
- Loading branch information
1 parent
666416c
commit 47062f5
Showing
8 changed files
with
112 additions
and
91 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,4 @@ | ||
// we need to mock prettier in all tests because it doesn't work with jest | ||
// TypeError: A dynamic import callback was invoked without --experimental-vm-modules | ||
// https://github.com/prettier/prettier/issues/15769 | ||
jest.mock('prettier', () => jest.fn()); |
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,31 @@ | ||
import prettier from 'prettier'; | ||
import { getConfig } from 'src/categories/js/prettier/prettier.config'; | ||
import { defaultConfig } from 'src/categories/js/prettier/config/default.config'; | ||
import { format } from 'src/utils/javascript'; | ||
|
||
// we need to mock prettier because it doesn't work with jest | ||
// TypeError: A dynamic import callback was invoked without --experimental-vm-modules | ||
// https://github.com/prettier/prettier/issues/15769 | ||
jest.mock('prettier', () => ({ | ||
format: jest.fn(), | ||
})); | ||
const prettierMocked = jest.mocked(prettier); | ||
|
||
jest.mock('src/categories/js/prettier/prettier.config', () => ({ getConfig: jest.fn() })); | ||
const getConfigMocked = jest.mocked(getConfig); | ||
|
||
describe('format', () => { | ||
test('formats input with default config', async () => { | ||
const input = `const foo = "bar"`; | ||
const formatted = `const foo = 'bar';`; | ||
|
||
getConfigMocked.mockImplementation(() => ({ config: { printWidth: 90 } }) as typeof defaultConfig); | ||
prettierMocked.format.mockResolvedValueOnce(formatted); | ||
|
||
const actual = await format(input); | ||
const expected = formatted; | ||
|
||
expect(actual).toBe(expected); | ||
expect(prettierMocked.format).toHaveBeenCalledWith(input, { parser: 'typescript', printWidth: 90 }); | ||
}); | ||
}); |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,8 @@ | ||
import prettier from 'prettier'; | ||
import { getConfig } from 'src/categories/js/prettier/prettier.config'; | ||
|
||
export const format = async (input: string) => { | ||
const { config } = getConfig(); | ||
|
||
return await prettier.format(input, { parser: 'typescript', ...config } as prettier.Options); | ||
}; |