From 4933f5380f7834834eb2c93d3b6a6a971621fb12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ju=CC=88rg=20Lehni?= Date: Sat, 5 Nov 2022 21:38:46 +0100 Subject: [PATCH 1/2] Don't auto-load prettier-plugin-organize-imports in tests --- tests/common.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/common.ts b/tests/common.ts index c0b86a61..9af51ceb 100644 --- a/tests/common.ts +++ b/tests/common.ts @@ -97,6 +97,7 @@ export function compareFiles( const actual: string = format(code, { parser: 'pug', plugins: [plugin], + pluginSearchDirs: false, ...formatOptions, }); From 3d6aafd78148b0d579dab8f86420e966132b03ba Mon Sep 17 00:00:00 2001 From: "Quadflieg , Christopher" Date: Mon, 7 Nov 2022 13:30:36 +0100 Subject: [PATCH 2/2] Add tests --- tests/common.ts | 2 +- tests/issues/issue-419/formatted.pug | 4 +++ tests/issues/issue-419/issue-419.test.ts | 38 ++++++++++++++++++++++++ tests/issues/issue-419/unformatted.pug | 4 +++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tests/issues/issue-419/formatted.pug create mode 100644 tests/issues/issue-419/issue-419.test.ts create mode 100644 tests/issues/issue-419/unformatted.pug diff --git a/tests/common.ts b/tests/common.ts index 9af51ceb..62e6a13b 100644 --- a/tests/common.ts +++ b/tests/common.ts @@ -97,7 +97,7 @@ export function compareFiles( const actual: string = format(code, { parser: 'pug', plugins: [plugin], - pluginSearchDirs: false, + // pluginSearchDirs: false, ...formatOptions, }); diff --git a/tests/issues/issue-419/formatted.pug b/tests/issues/issue-419/formatted.pug new file mode 100644 index 00000000..3b1e285f --- /dev/null +++ b/tests/issues/issue-419/formatted.pug @@ -0,0 +1,4 @@ +.topic( + v-for="topic in topics", + v-delayed-unhide="{ disabled: !!selectedTopic }" +) diff --git a/tests/issues/issue-419/issue-419.test.ts b/tests/issues/issue-419/issue-419.test.ts new file mode 100644 index 00000000..971a6623 --- /dev/null +++ b/tests/issues/issue-419/issue-419.test.ts @@ -0,0 +1,38 @@ +import { compareFiles } from 'tests/common'; +import type { SpyInstance } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; + +describe('Issues', () => { + it('should log a warning when passing inline object literal to custom vue directive and pugFramework is not set', () => { + const spyConsoleWarn: SpyInstance< + [message?: any, ...optionalParams: any[]], + void + > = vi.spyOn(console, 'warn'); + + const { expected, actual } = compareFiles(__dirname); + expect(actual).toBe(expected); + + expect(spyConsoleWarn).toHaveBeenCalledWith( + 'The following expression could not be formatted correctly. Please try to fix it yourself and if there is a problem, please open a bug issue:', + 'disabled: !!selectedTopic', + ); + + spyConsoleWarn.mockRestore(); + }); + + it('should not log a warning when passing inline object literal to custom vue directive and pugFramework is set to vue', () => { + const spyConsoleWarn: SpyInstance< + [message?: any, ...optionalParams: any[]], + void + > = vi.spyOn(console, 'warn'); + + const { expected, actual } = compareFiles(__dirname, { + formatOptions: { pugFramework: 'vue' }, + }); + expect(actual).toBe(expected); + + expect(spyConsoleWarn).not.toHaveBeenCalled(); + + spyConsoleWarn.mockRestore(); + }); +}); diff --git a/tests/issues/issue-419/unformatted.pug b/tests/issues/issue-419/unformatted.pug new file mode 100644 index 00000000..e1f7c1f0 --- /dev/null +++ b/tests/issues/issue-419/unformatted.pug @@ -0,0 +1,4 @@ +.topic( + v-for="topic in topics" + v-delayed-unhide="{ disabled: !!selectedTopic }" +)