Skip to content

Commit

Permalink
Bump ava (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonyfaris authored Nov 24, 2021
1 parent f7cf7c1 commit 4a7d602
Show file tree
Hide file tree
Showing 4 changed files with 314 additions and 782 deletions.
5 changes: 5 additions & 0 deletions .changeset/curly-donkeys-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'prettier-plugin-astro': patch
---

Bump ava
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@rollup/plugin-commonjs": "^21.0.0",
"@rollup/plugin-node-resolve": "^13.0.5",
"@types/prettier": "^2.4.1",
"ava": "4.0.0-alpha.2",
"ava": "https://github.com/avajs/ava.git#main",
"eslint": "^8.0.0",
"eslint-plugin-ava": "^13.0.0",
"eslint-plugin-node": "^11.1.0",
Expand Down
117 changes: 63 additions & 54 deletions test/test-utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import prettier from 'prettier';
import { fileURLToPath } from 'url';
import { promises as fs } from 'fs';
import { Macro } from 'ava';
import test from 'ava';

/**
* format the contents of an astro file
Expand Down Expand Up @@ -73,56 +73,65 @@ async function getMarkdownFiles(name: string) {
/**
* Macro for testing fixtures
*/
export const Prettier: Macro<[string]> = async (t, name) => {
const [src, out] = await getFiles(name);
t.not(src, out, 'Unformated file and formated file are the same');

const options = await getOptions(name);

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

/**
* Macro title function for nice formatting
*/
Prettier.title = (title, name) => `${title}:
- input: fixtures/${name}/input.astro
- output: fixtures/${name}/output.astro`;

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

const options = await getOptions(name);

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

PrettierUnaltered.title = Prettier.title;

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

const options = await getOptions(name);

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

PrettierMarkdown.title = (title, name) => `${title}:
- input: fixtures/${name}/input.md
- output: fixtures/${name}/output.md`;
export const Prettier = test.macro({
async exec(t, name: string) {
const [src, out] = await getFiles(name);
t.not(src, out, 'Unformated file and formated file are the same');

const options = await getOptions(name);

const formatted = format(src, options);
t.is(formatted, out, 'Incorrect formating');
// test that our formatting is idempotent
const formattedTwice = format(formatted, options);
t.is(formatted, formattedTwice, 'Formatting is not idempotent');
},
/**
* Macro title function for nice formatting
*/
title(title, name) {
return `${title}:
- input: fixtures/in/${name}.astro
- output: fixtures/out/${name}.astro`;
},
});

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

const options = await getOptions(name);

const formatted = format(src, options);
t.is(formatted, out, 'Incorrect formating');
// test that our formatting is idempotent
const formattedTwice = format(formatted);
t.is(formatted, formattedTwice, 'Formatting is not idempotent');
},
title(title, name) {
return `${title}:
- input: fixtures/in/${name}.astro
- output: fixtures/out/${name}.astro`;
},
});

export const PrettierMarkdown = test.macro({
async exec(t, name: string) {
const [src, out] = await getMarkdownFiles(name);
t.not(src, out, 'Unformated file and formated file are the same');

const options = await getOptions(name);

const formatted = markdownFormat(src, options);
t.is(formatted, out, 'Incorrect formating');
// test that our formatting is idempotent
const formattedTwice = markdownFormat(formatted, options);
t.is(formatted, formattedTwice, 'Formatting is not idempotent');
},
title(title, name) {
return `${title}:
- input: fixtures/in/${name}.astro
- output: fixtures/out/${name}.astro`;
},
});
Loading

0 comments on commit 4a7d602

Please sign in to comment.