Skip to content

Commit

Permalink
test: add snapshot test for generators
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 12, 2024
1 parent 7c31f11 commit affd5ee
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 15 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
"scripts": {
"automd": "jiti src/cli.ts",
"build": "pnpm automd && unbuild",
"dev": "vitest",
"play": "pnpm automd --dir playground",
"dev": "vitest -u",
"lint": "eslint --cache --ext .ts,.js,.mjs,.cjs . && prettier -c src",
"lint:fix": "eslint --cache --ext .ts,.js,.mjs,.cjs . --fix && prettier -c src -w",
"prepack": "pnpm build",
Expand Down Expand Up @@ -59,4 +58,4 @@
"vitest": "^1.2.2"
},
"packageManager": "pnpm@8.15.1"
}
}
2 changes: 0 additions & 2 deletions playground/automd.config.ts

This file was deleted.

21 changes: 21 additions & 0 deletions test/fixture/INPUT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Automd built-in generator fixtures

## `badges`

<!-- automd:badges -->
<!-- /automd -->

## `pm-x`

<!-- automd:pm-x args=. -->
<!-- /automd -->

## `pm-install`

<!-- automd:pm-install dev separate-->
<!-- /automd -->

## `jsdocs`

<!-- automd:jsdocs -->
<!-- /automd -->
19 changes: 9 additions & 10 deletions playground/README.md → test/fixture/OUTPUT.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
# automd playground
# Automd built-in generator fixtures

<!-- automd:bagdges -->
<!-- /automd -->
## `badges`

<!-- automd:badges color=yellow name=defu codecov bundlephobia -->
<!-- automd:badges -->

[![npm version](https://flat.badgen.net/npm/v/defu?color=yellow)](https://npmjs.com/package/defu)
[![npm downloads](https://flat.badgen.net/npm/dm/defu?color=yellow)](https://npmjs.com/package/defu)
[![bundle size](https://flat.badgen.net/bundlephobia/minzip/defu?color=yellow)](https://bundlephobia.com/package/defu)
[![codecov](https://flat.badgen.net/codecov/c/github/unjs/automd?color=yellow)](https://codecov.io/gh/unjs/automd)
[![npm version](https://flat.badgen.net/npm/v/automd)](https://npmjs.com/package/automd)
[![npm downloads](https://flat.badgen.net/npm/dm/automd)](https://npmjs.com/package/automd)

<!-- /automd -->

## Usage
## `pm-x`

<!-- automd:pm-x args=. -->

Expand All @@ -29,6 +26,8 @@ bunx automd@0.2.0 .

<!-- /automd -->

## `pm-install`

<!-- automd:pm-install dev separate-->

```sh
Expand Down Expand Up @@ -58,7 +57,7 @@ bun install -D automd@^0.2.0

<!-- /automd -->

## Utils
## `jsdocs`

<!-- automd:jsdocs -->

Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions test/generators.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { fileURLToPath } from "node:url";
import { readFile } from "node:fs/promises";
import { join } from "node:path";
import { expect, it } from "vitest";
import { transform } from "../src/transform";

it("generator snapshots", async () => {
const fixtureDir = fileURLToPath(new URL("fixture", import.meta.url));

const input = await readFile(join(fixtureDir, "INPUT.md"), "utf8");
const result = await transform(input, { dir: fixtureDir });

expect(result.contents).toMatchFileSnapshot(`fixture/OUTPUT.md`);
});

0 comments on commit affd5ee

Please sign in to comment.