generated from unplugin/unplugin-starter
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement transform of simple cases
- Loading branch information
1 parent
b14378c
commit 3a8fed2
Showing
4 changed files
with
169 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<template> | ||
<Story> | ||
test | ||
</Story> | ||
<Stories> | ||
<Story title="Primary"> | ||
<span>test</span> | ||
</Story> | ||
</Stories> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<template> | ||
<Stories> | ||
<Story title="Primary"> | ||
hello | ||
</Story> | ||
<Story title="Secondary"> | ||
world | ||
</Story> | ||
</Stories> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,76 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { compileTemplate, parse } from 'vue/compiler-sfc' | ||
import { transform } from '../src/core/transform' | ||
|
||
describe('index', () => { | ||
it('hi vitest', () => { | ||
expect(1).toBe(1) | ||
describe('transform', () => { | ||
it('handles one simple story', () => { | ||
const code = '<template><Stories><Story title="Primary">hello</Story></Stories></template>' | ||
const result = transform(code) | ||
expect(result).toMatchInlineSnapshot(` | ||
"export default { | ||
//component: MyComponent, | ||
//decorators: [ ... ], | ||
//parameters: { ... } | ||
} | ||
function renderPrimary(_ctx, _cache) { | ||
return \\"hello\\" | ||
} | ||
export const Primary = renderPrimary" | ||
`) | ||
}) | ||
it('extracts title from Stories', () => { | ||
const code = '<template><Stories title="test"><Story title="Primary">hello</Story></Stories></template>' | ||
const result = transform(code) | ||
expect(result).toMatchInlineSnapshot(` | ||
"export default { | ||
title: 'test', | ||
//component: MyComponent, | ||
//decorators: [ ... ], | ||
//parameters: { ... } | ||
} | ||
function renderPrimary(_ctx, _cache) { | ||
return \\"hello\\" | ||
} | ||
export const Primary = renderPrimary" | ||
`) | ||
}) | ||
it('throws error if story does not have a title', () => { | ||
const code = '<template><Stories><Story>hello</Story></Stories></template>' | ||
expect(() => transform(code)).toThrowErrorMatchingInlineSnapshot('"Story is missing a title"') | ||
}) | ||
it('handles multiple stories', () => { | ||
const code = ` | ||
<template> | ||
<Stories> | ||
<Story title="Primary">hello</Story> | ||
<Story title="Secondary">world</Story> | ||
</Stories> | ||
</template>` | ||
const result = transform(code) | ||
expect(result).toMatchInlineSnapshot(` | ||
"export default { | ||
//component: MyComponent, | ||
//decorators: [ ... ], | ||
//parameters: { ... } | ||
} | ||
function renderPrimary(_ctx, _cache) { | ||
return \\"hello\\" | ||
} | ||
export const Primary = renderPrimary | ||
function renderSecondary(_ctx, _cache) { | ||
return \\"world\\" | ||
} | ||
export const Secondary = renderSecondary" | ||
`) | ||
}, | ||
) | ||
}) |