From 00ecbbd77ca139ec0beb42c0e5ecbda8ab2b7062 Mon Sep 17 00:00:00 2001 From: Jesse Skinner Date: Tue, 18 Aug 2020 15:19:09 -0400 Subject: [PATCH] add ability to have custom options in formatting tests --- test/formatting/index.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/test/formatting/index.ts b/test/formatting/index.ts index a215a2d9..870cc509 100644 --- a/test/formatting/index.ts +++ b/test/formatting/index.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import { readdirSync, readFileSync } from 'fs'; +import { readdirSync, readFileSync, existsSync } from 'fs'; import { format } from 'prettier'; const dirs = readdirSync('test/formatting/samples'); @@ -13,13 +13,24 @@ for (const dir of dirs) { `test/formatting/samples/${dir}/output.html`, 'utf-8', ).replace(/\r?\n/g, '\n'); + const options = readOptions(`test/formatting/samples/${dir}/options.json`); - test(`formatting: ${dir}`, t => { + test(`formatting: ${dir}`, (t) => { const actualOutput = format(input, { parser: 'svelte' as any, plugins: [require.resolve('../../src')], tabWidth: 4, + ...options, }); t.is(expectedOutput, actualOutput); }); } + +function readOptions(fileName: string) { + if (!existsSync(fileName)) { + return {}; + } + + const fileContents = readFileSync(fileName, 'utf-8'); + return JSON.parse(fileContents); +}