Skip to content

Commit

Permalink
add ability to have custom options in formatting tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseskinner committed Aug 18, 2020
1 parent cec7a25 commit 00ecbbd
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions test/formatting/index.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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);
}

0 comments on commit 00ecbbd

Please sign in to comment.