generated from unjs/template
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.test.ts
43 lines (33 loc) · 1.18 KB
/
index.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import MagicString, { SourceMap } from 'magic-string'
import { describe, expect, it } from 'vitest'
import { MagicSFC, createSourceLocation, proxyBlock } from '../src'
describe('Magic SFC', () => {
it('Can create the class', () => {
const sfc = new MagicSFC('<script setup>let test: string</script>')
expect(sfc.toString()).toBe('<script setup>let test: string</script>')
})
it('Can create the class from a MagicString', () => {
const ms = new MagicString('<script setup>let test: string</script>')
const sfc = new MagicSFC(ms)
expect(sfc.toString()).toBe('<script setup>let test: string</script>')
})
it('Can get a sourcemap', () => {
const sfc = new MagicSFC('<script setup>let test: string</script>')
expect(sfc.getSourcemap()).toBeInstanceOf(SourceMap)
})
it('Can access custom properties from proxified block', () => {
const source = '<script setup>let test: string</script>'
const block = proxyBlock(
new MagicString(source),
{
loc: createSourceLocation(source),
type: 'style',
lang: 'postcss',
attrs: {
lang: 'postcss',
},
},
)
expect(block.type).toBe('style')
})
})