Skip to content

Commit

Permalink
fix: failing tests & issue with prettier inside tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xeho91 committed Jun 6, 2024
1 parent 7881a71 commit efeeaf8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/parser/analyse/Story/children.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe(getStoryChildrenRawSource.name, () => {
const svelteASTNodes = await extractSvelteASTNodes({ ast });
const { storyComponents } = svelteASTNodes;
const component = storyComponents[0].component;
const rawSource = getStoryChildrenRawSource({
const rawSource = await getStoryChildrenRawSource({
component,
svelteASTNodes,
originalCode: code,
Expand Down Expand Up @@ -66,7 +66,7 @@ describe(getStoryChildrenRawSource.name, () => {
const svelteASTNodes = await extractSvelteASTNodes({ ast });
const { storyComponents } = svelteASTNodes;
const component = storyComponents[0].component;
const rawSource = getStoryChildrenRawSource({
const rawSource = await getStoryChildrenRawSource({
component,
svelteASTNodes,
originalCode: code,
Expand Down Expand Up @@ -107,7 +107,7 @@ describe(getStoryChildrenRawSource.name, () => {
const svelteASTNodes = await extractSvelteASTNodes({ ast });
const { storyComponents } = svelteASTNodes;
const component = storyComponents[0].component;
const rawSource = getStoryChildrenRawSource({
const rawSource = await getStoryChildrenRawSource({
component,
svelteASTNodes,
originalCode: code,
Expand All @@ -134,7 +134,7 @@ describe(getStoryChildrenRawSource.name, () => {
const svelteASTNodes = await extractSvelteASTNodes({ ast });
const { storyComponents } = svelteASTNodes;
const component = storyComponents[0].component;
const rawSource = getStoryChildrenRawSource({
const rawSource = await getStoryChildrenRawSource({
component,
svelteASTNodes,
originalCode: code,
Expand Down Expand Up @@ -165,7 +165,7 @@ describe(getStoryChildrenRawSource.name, () => {
const svelteASTNodes = await extractSvelteASTNodes({ ast });
const { storyComponents } = svelteASTNodes;
const component = storyComponents[0].component;
const rawSource = getStoryChildrenRawSource({
const rawSource = await getStoryChildrenRawSource({
component,
svelteASTNodes,
originalCode: code,
Expand Down Expand Up @@ -196,7 +196,7 @@ describe(getStoryChildrenRawSource.name, () => {
const svelteASTNodes = await extractSvelteASTNodes({ ast });
const { storyComponents } = svelteASTNodes;
const component = storyComponents[0].component;
const rawSource = getStoryChildrenRawSource({
const rawSource = await getStoryChildrenRawSource({
component,
svelteASTNodes,
originalCode: code,
Expand Down Expand Up @@ -237,7 +237,7 @@ describe(getStoryChildrenRawSource.name, () => {
const svelteASTNodes = await extractSvelteASTNodes({ ast });
const { storyComponents } = svelteASTNodes;
const component = storyComponents[0].component;
const rawSource = getStoryChildrenRawSource({
const rawSource = await getStoryChildrenRawSource({
component,
svelteASTNodes,
originalCode: code,
Expand Down
13 changes: 10 additions & 3 deletions src/parser/analyse/Story/children.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Component, SnippetBlock } from 'svelte/compiler';
import { format } from 'prettier';

import { getDefineMetaComponentValue } from '../meta/component-identifier.js';

Expand Down Expand Up @@ -206,11 +205,19 @@ async function getSnippetBlockBodyRawCode(originalCode: string, node: SnippetBlo
}

async function prettifyCodeSlice(rawCode: string) {
const { format } = await import('prettier');

/**
* FIXME: Perhaps we don't need to prettify the code at this point, and do it at runtime instead?
*/
return await format(rawCode, {
plugins: ['prettier-plugin-svelte'],
const formatted = await format(rawCode, {
plugins: [
// @ts-expect-error FIXME: Upstream issue?
import('prettier-plugin-svelte'),
],
parser: 'svelte',
});

// NOTE: Remove trailing new line
return formatted.replace(/\n$/, '');
}

0 comments on commit efeeaf8

Please sign in to comment.