Skip to content

Commit

Permalink
feat: return sfc descriptor when a content is added to watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
ktsn committed Mar 11, 2018
1 parent cd63e75 commit ad0d757
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/diff-watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { SFCBlock, parseComponent, SFCDescriptor } from './index'
export class SFCDiffWatcher {
private prevMap: Record<string, SFCDescriptor> = {}

add(filename: string, content: string): void {
this.prevMap[filename] = parseComponent(content)
add(filename: string, content: string): SFCDescriptor {
return (this.prevMap[filename] = parseComponent(content))
}

remove(filename: string): void {
Expand Down
19 changes: 18 additions & 1 deletion test/diff-watcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,24 @@ describe('Diff Watcher', () => {
expect(mock2).toHaveBeenCalled()
})

it('should remove fron watcher', () => {
it('should return descriptor when add to watcher', () => {
const watcher = createDiffWatcher()
const code = `
<template>Hi</template>
<script>export default {}</script>
<style>p { color: red; }</style>
<docs># Hello</docs>
`

const desc = watcher.add('test.vue', code)
expect(desc.template!.content).toBe('Hi')
expect(desc.script!.content).toBe('export default {}')
expect(desc.styles[0].content).toBe('p { color: red; }')
expect(desc.customBlocks[0].type).toBe('docs')
expect(desc.customBlocks[0].content).toBe('# Hello')
})

it('should remove from watcher', () => {
const watcher = createDiffWatcher()

watcher.add('test.vue', '<template>Hi</template>')
Expand Down

0 comments on commit ad0d757

Please sign in to comment.