Skip to content

Commit

Permalink
Fix test macro 'PrettierMarkdown' (#30)
Browse files Browse the repository at this point in the history
Co-authored-by: Caleb Jasik <calebjasik@jasik.xyz>
  • Loading branch information
antonyfaris and jasikpark authored Oct 8, 2021
1 parent 695fc07 commit 8820423
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .changeset/blue-birds-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'prettier-plugin-astro': patch
---

Fix test macro 'PrettierMarkdown'
18 changes: 9 additions & 9 deletions test/astro-prettier.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ const getMarkdownFiles = async (name) => {
*/
const Prettier = async (t, name) => {
const [src, out] = await getFiles(name);
t.not(src, out);
t.not(src, out, 'Unformated file and formated file are the same');

const formatted = format(src);
t.is(formatted, out);
t.is(formatted, out, 'Incorrect formating');
// test that our formatting is idempotent
const formattedTwice = format(formatted);
t.is(formatted, formattedTwice);
t.is(formatted, formattedTwice, 'Formatting is not idempotent');
};

/**
Expand All @@ -50,26 +50,26 @@ Prettier.title = (title, name) => `${title}:

const PrettierUnaltered = async (t, name) => {
const [src, out] = await getFiles(name);
t.is(src, out); // the output should be unchanged
t.is(src, out, 'Unformated file and formated file are not the same'); // the output should be unchanged

const formatted = format(src);
t.is(formatted, out);
t.is(formatted, out, 'Incorrect formating');
// test that our formatting is idempotent
const formattedTwice = format(formatted);
t.is(formatted, formattedTwice);
t.is(formatted, formattedTwice, 'Formatting is not idempotent');
};

PrettierUnaltered.title = Prettier.title;

const PrettierMarkdown = async (t, name) => {
const [src, out] = await getMarkdownFiles(name);
t.not(src, out);
t.not(src, out, 'Unformated file and formated file are the same');

const formatted = markdownFormat(src);
t.not(formatted, out);
t.is(formatted, out, 'Incorrect formating');
// test that our formatting is idempotent
const formattedTwice = markdownFormat(formatted);
t.is(formatted, formattedTwice);
t.is(formatted, formattedTwice, 'Formatting is not idempotent');
};

PrettierMarkdown.title = (title, name) => `${title}:
Expand Down
24 changes: 8 additions & 16 deletions test/fixtures/out/embedded-in-markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,9 @@ For best results, you should only have one `<style>` tag per-Astro component. Th
<!-- Astro Page CSS example -->
<html>
<head>
<style>
...;
</style>
<style> ...; </style>
</head>
<body>
...
</body>
<body> ... </body>
</html>
```

Expand Down Expand Up @@ -123,7 +119,6 @@ Astro components can define local variables inside of the Frontmatter script. An
---
const name = "Your name here";
---
<div>
<h1>Hello {name}!</h1>
</div>
Expand All @@ -149,7 +144,6 @@ const name = "Your name here";
---
const items = ["Dog", "Cat", "Platipus"];
---
<ul>
{items.map((item) => <li>{item}</li>)}
</ul>
Expand Down Expand Up @@ -182,9 +176,8 @@ export interface Props {
}
const { greeting = "Hello", name } = Astro.props;
---
<div>
<h1>{greeting}, {name}!</h1>
<h1>{greeting}, {name}!</h1>
</div>
```

Expand All @@ -195,7 +188,8 @@ const { greeting = "Hello", name } = Astro.props;
```astro
<!-- Example: MyComponent.astro -->
<div id="my-component">
<slot /> <!-- children will go here -->
<slot />
<!-- children will go here -->
</div>
<!-- Usage -->
Expand Down Expand Up @@ -255,9 +249,9 @@ An Astro component template can render as many top-level elements as you'd like.

```astro
<!-- An Astro component can contain multiple top-level HTML elements: -->
<div id="a" />
<div id="b" />
<div id="c" />
<div id="a"></div>
<div id="b"></div>
<div id="c"></div>
```

When working inside a JSX expression, however, you must wrap multiple elements inside of a **Fragment**. Fragments let you render a set of elements without adding extra nodes to the DOM. This is required in JSX expressions because of a limitation of JavaScript: You can never `return` more than one thing in a JavaScript function or expression. Using a Fragment solves this problem.
Expand All @@ -268,7 +262,6 @@ A Fragment must open with `<>` and close with `</>`. Don't worry if you forget t
---
const items = ["Dog", "Cat", "Platipus"];
---
<ul>
{items.map((item) => <>
<li>Red {item}</li>
Expand Down Expand Up @@ -326,7 +319,6 @@ The recommended approach is to place files within `public/*`. This references a
// ✅ Correct: references src/thumbnail.png
import thumbnailSrc from "./thumbnail.png";
---
<img src={thumbnailSrc} />
```

Expand Down

0 comments on commit 8820423

Please sign in to comment.