Skip to content

Commit 434cce1

Browse files
committed
fix tests
1 parent aaa04aa commit 434cce1

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/core/transform.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ import { ParsedMeta, ParsedStory, parse } from './parser'
1111
export async function transform(code: string) {
1212
let result = ''
1313
const { resolvedScript, meta, stories, docs } = parse(code)
14+
const isTS = resolvedScript?.lang === 'ts'
1415
if (resolvedScript) {
15-
const isTS = resolvedScript.lang === 'ts'
16-
const plugins: ParserPlugin[] = isTS ? ['typescript'] : []
17-
result += rewriteDefault(resolvedScript.content, '_sfc_main', plugins)
16+
const babelPlugins: ParserPlugin[] = isTS ? ['typescript'] : []
17+
result += rewriteDefault(resolvedScript.content, '_sfc_main', babelPlugins)
1818
result += '\n'
1919
} else {
2020
result += 'const _sfc_main = {}\n'
2121
}
2222
result += await transformTemplate({ meta, stories, docs }, resolvedScript)
23-
result = organizeImports(result)
23+
result = await organizeImports(result, isTS)
2424
return result
2525

2626
/*
@@ -151,10 +151,10 @@ function generateStoryImport(
151151
};`
152152
}
153153

154-
function organizeImports(result: string): string {
154+
async function organizeImports(result: string, isTS: boolean): Promise<string> {
155155
// Use prettier to organize imports
156-
return prettierFormat(result, {
157-
parser: 'babel',
156+
return await prettierFormat(result, {
157+
parser: isTS ? 'typescript' : 'babel',
158158
plugins: ['prettier-plugin-organize-imports'],
159159
})
160160
}

test/index.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ describe('transform', () => {
325325
p: \\"p\\",
326326
},
327327
_provideComponents(),
328-
props.components
328+
props.components,
329329
);
330330
return _jsxs(_Fragment, {
331331
children: [
@@ -343,14 +343,14 @@ describe('transform', () => {
343343
const { wrapper: MDXLayout } = Object.assign(
344344
{},
345345
_provideComponents(),
346-
props.components
346+
props.components,
347347
);
348348
return MDXLayout
349349
? _jsx(
350350
MDXLayout,
351351
Object.assign({}, props, {
352352
children: _jsx(_createMdxContent, props),
353-
})
353+
}),
354354
)
355355
: _createMdxContent(props);
356356
}
@@ -464,7 +464,7 @@ describe('transform', () => {
464464
_createElementVNode(\\"h1\\", null, _toDisplayString($setup.headingText)),
465465
_createElementVNode(\\"p\\", null, _toDisplayString($setup.paragraph)),
466466
],
467-
64 /* STABLE_FRAGMENT */
467+
64 /* STABLE_FRAGMENT */,
468468
)
469469
);
470470
}
@@ -491,7 +491,7 @@ describe('transform', () => {
491491
_createElementVNode(\\"h1\\", null, _toDisplayString($setup.headingText)),
492492
_createElementVNode(\\"p\\", null, _toDisplayString($setup.paragraph)),
493493
],
494-
64 /* STABLE_FRAGMENT */
494+
64 /* STABLE_FRAGMENT */,
495495
)
496496
);
497497
}

0 commit comments

Comments
 (0)