File tree Expand file tree Collapse file tree 2 files changed +48
-3
lines changed Expand file tree Collapse file tree 2 files changed +48
-3
lines changed Original file line number Diff line number Diff line change 1
1
import { describe , it , expect } from "vitest" ;
2
- import { parseRawArgs , findAutoMdBlocks } from "../src/_parse" ;
2
+ import { parseRawArgs , findBlocks } from "../src/_parse" ;
3
3
4
4
describe ( "parseRawArgs" , ( ) => {
5
5
const tests = [
@@ -19,7 +19,7 @@ describe("parseRawArgs", () => {
19
19
}
20
20
} ) ;
21
21
22
- describe ( "findAutoMdBlocks " , ( ) => {
22
+ describe ( "findBlocks " , ( ) => {
23
23
const fixture = `
24
24
<!-- automd:pm-x args=. -->
25
25
(a)
@@ -43,7 +43,7 @@ describe("findAutoMdBlocks", () => {
43
43
} ) ;
44
44
45
45
it ( "should find all blocks" , ( ) => {
46
- const blocks = findAutoMdBlocks ( fixture ) ;
46
+ const blocks = findBlocks ( fixture ) ;
47
47
expect ( blocks [ 0 ] ) . toMatchObject ( mkBlock ( "pm-x" , "args=." , "(a)" ) ) ;
48
48
expect ( blocks [ 1 ] ) . toMatchObject (
49
49
mkBlock ( "pm-install" , "dev no-auto" , "(b)" ) ,
Original file line number Diff line number Diff line change
1
+ import { describe , it , expect } from "vitest" ;
2
+ import { transform } from "../src" ;
3
+
4
+ describe ( "transform" , ( ) => {
5
+ it ( "basic transform works" , async ( ) => {
6
+ const input = `
7
+ <!-- automd:test foo=bar -->
8
+ <!-- /automd -->
9
+ ` . trim ( ) ;
10
+
11
+ const result = await transform ( input , {
12
+ generators : {
13
+ test : {
14
+ name : "test" ,
15
+ generate ( { args } ) {
16
+ return { contents : JSON . stringify ( { args } ) } ;
17
+ } ,
18
+ } ,
19
+ } ,
20
+ } ) ;
21
+
22
+ expect ( result . hasChanged ) . toBe ( true ) ;
23
+ expect ( result . contents ) . toMatchInlineSnapshot ( `
24
+ "<!-- automd:test foo=bar -->
25
+
26
+ {"args":{"foo":"bar"}}
27
+
28
+ <!-- /automd -->"
29
+ ` ) ;
30
+
31
+ expect ( result . updates ) . toHaveLength ( 1 ) ;
32
+ expect ( result . updates [ 0 ] . block ) . toMatchInlineSnapshot ( `
33
+ {
34
+ "contents": "
35
+ ",
36
+ "generator": "test",
37
+ "loc": {
38
+ "end": 29,
39
+ "start": 28,
40
+ },
41
+ "rawArgs": "foo=bar",
42
+ }
43
+ ` ) ;
44
+ } ) ;
45
+ } ) ;
You can’t perform that action at this time.
0 commit comments