Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test macro 'PrettierMarkdown' #30

Merged
merged 2 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix test macro 'PrettierMarkdown'
  • Loading branch information
antonyfaris committed Oct 8, 2021
commit c2be3eb15f40a325d19e6db79c13f4c16ef7ed5a
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 the same'); // the output should be unchanged
antonyfaris marked this conversation as resolved.
Show resolved Hide resolved

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