Skip to content

Commit 7c31f11

Browse files
committed
test: update tests
1 parent 2ffa57b commit 7c31f11

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

test/parse.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect } from "vitest";
2-
import { parseRawArgs, findAutoMdBlocks } from "../src/_parse";
2+
import { parseRawArgs, findBlocks } from "../src/_parse";
33

44
describe("parseRawArgs", () => {
55
const tests = [
@@ -19,7 +19,7 @@ describe("parseRawArgs", () => {
1919
}
2020
});
2121

22-
describe("findAutoMdBlocks", () => {
22+
describe("findBlocks", () => {
2323
const fixture = `
2424
<!-- automd:pm-x args=. -->
2525
(a)
@@ -43,7 +43,7 @@ describe("findAutoMdBlocks", () => {
4343
});
4444

4545
it("should find all blocks", () => {
46-
const blocks = findAutoMdBlocks(fixture);
46+
const blocks = findBlocks(fixture);
4747
expect(blocks[0]).toMatchObject(mkBlock("pm-x", "args=.", "(a)"));
4848
expect(blocks[1]).toMatchObject(
4949
mkBlock("pm-install", "dev no-auto", "(b)"),

test/transform.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
});

0 commit comments

Comments
 (0)