Skip to content

Commit

Permalink
chore: cross-test dirs test.only support
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm committed Feb 28, 2024
1 parent 96049c6 commit 08d7a8b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 4 additions & 1 deletion test/formatting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import { format } from 'prettier';
import * as SveltePlugin from '../../src';

let dirs = readdirSync('test/formatting/samples');
const printerFilesHaveOnly = readdirSync('test/printer/samples').some(
(f) => f.endsWith('.only.html') || f.endsWith('.only.md'),
);
const endsWithOnly = (f: string): boolean => f.endsWith('.only');
const hasOnly = dirs.some(endsWithOnly);
const hasOnly = printerFilesHaveOnly || dirs.some(endsWithOnly);
dirs = !hasOnly ? dirs : dirs.filter(endsWithOnly);

if (process.env.CI && hasOnly) {
Expand Down
9 changes: 6 additions & 3 deletions test/printer/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import test from 'ava';
import { readdirSync, readFileSync, existsSync } from 'fs';
import { format } from 'prettier';
import * as SveltePlugin from '../../src'
import * as SveltePlugin from '../../src';

let files = readdirSync('test/printer/samples').filter(
(name) => name.endsWith('.html') || name.endsWith('.md'),
);
const formattingDirsHaveOnly = readdirSync('test/formatting/samples').some((d) =>
d.endsWith('.only'),
);
const endsWithOnly = (f: string): boolean => f.endsWith('.only.html') || f.endsWith('.only.md');
const hasOnly = files.some(endsWithOnly);
const hasOnly = formattingDirsHaveOnly || files.some(endsWithOnly);
files = !hasOnly ? files : files.filter(endsWithOnly);

if (process.env.CI && hasOnly) {
Expand All @@ -23,7 +26,7 @@ for (const file of files) {

test(`printer: ${file.slice(0, file.length - `.${ending}`.length)}`, async (t) => {
const actualOutput = await format(input, {
parser: (ending === 'html' ? 'svelte' : 'markdown'),
parser: ending === 'html' ? 'svelte' : 'markdown',
plugins: [SveltePlugin],
tabWidth: 4,
...options,
Expand Down

0 comments on commit 08d7a8b

Please sign in to comment.