Skip to content

Commit

Permalink
format before evaluating test
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianGonz97 committed Nov 10, 2024
1 parent 650ede7 commit 047c549
Show file tree
Hide file tree
Showing 41 changed files with 106 additions and 85 deletions.
2 changes: 0 additions & 2 deletions .prettierignore

This file was deleted.

2 changes: 1 addition & 1 deletion packages/core/tests/css/common/add-at-rule/input.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.foo {
color: red;
color: red;
}
4 changes: 2 additions & 2 deletions packages/core/tests/css/common/add-at-rule/output.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@tailwind 'lib/path/file.ext';
.foo {
color: red;
color: red;
}
@tailwind 'lib/path/file1.ext'
@tailwind 'lib/path/file1.ext';
2 changes: 1 addition & 1 deletion packages/core/tests/css/common/add-comment/input.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.foo {
color: red;
color: red;
}
2 changes: 1 addition & 1 deletion packages/core/tests/css/common/add-comment/output.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.foo {
color: red;
color: red;
}
/* foo comment */
2 changes: 1 addition & 1 deletion packages/core/tests/css/common/add-imports/input.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.foo {
color: red;
color: red;
}
2 changes: 1 addition & 1 deletion packages/core/tests/css/common/add-imports/output.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import 'lib/path/file.css';
.foo {
color: red;
color: red;
}
2 changes: 1 addition & 1 deletion packages/core/tests/css/common/add-rule/input.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.foo {
color: red;
color: red;
}
7 changes: 4 additions & 3 deletions packages/core/tests/css/common/add-rule/output.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.foo {
color: red;
}.bar {
color: blue
color: red;
}
.bar {
color: blue;
}
12 changes: 9 additions & 3 deletions packages/core/tests/css/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { describe, expect, test } from 'vitest';
import { parseCss, serializeCss } from '@sveltejs/ast-tooling';
import fs from 'node:fs';
import { join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import prettier from 'prettier';
import { describe, expect, test } from 'vitest';
import { parseCss, serializeCss } from '@sveltejs/ast-tooling';

const baseDir = resolve(fileURLToPath(import.meta.url), '..');
const categoryDirectories = getDirectoryNames(baseDir);

const prettierConfig = await prettier.resolveConfig(import.meta.url);
if (!prettierConfig) throw new Error('Failed to resolve prettier config');
prettierConfig.filepath = 'output.css';

for (const categoryDirectory of categoryDirectories) {
describe(categoryDirectory, () => {
const testNames = getDirectoryNames(join(baseDir, categoryDirectory));
Expand All @@ -23,7 +28,8 @@ for (const categoryDirectory of categoryDirectories) {
module.run({ ast });

const output = serializeCss(ast);
await expect(output).toMatchFileSnapshot(`${testDirectoryPath}/output.css`);
const formattedOutput = await prettier.format(output, prettierConfig);
await expect(formattedOutput).toMatchFileSnapshot(`${testDirectoryPath}/output.css`);
});
}
});
Expand Down
3 changes: 2 additions & 1 deletion packages/core/tests/html/common/create-div/output.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<div></div><div class="foo"></div>
<div></div>
<div class="foo"></div>
<div></div>
3 changes: 2 additions & 1 deletion packages/core/tests/html/common/create-element/output.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<span></span><div class="foo"></div>
<span></span>
<div class="foo"></div>
<span></span>
12 changes: 9 additions & 3 deletions packages/core/tests/html/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { describe, expect, test } from 'vitest';
import { parseHtml, serializeHtml } from '@sveltejs/ast-tooling';
import fs from 'node:fs';
import { join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import prettier from 'prettier';
import { describe, expect, test } from 'vitest';
import { parseHtml, serializeHtml } from '@sveltejs/ast-tooling';

const baseDir = resolve(fileURLToPath(import.meta.url), '..');
const categoryDirectories = getDirectoryNames(baseDir);

const prettierConfig = await prettier.resolveConfig(import.meta.url);
if (!prettierConfig) throw new Error('Failed to resolve prettier config');
prettierConfig.filepath = 'output.html';

for (const categoryDirectory of categoryDirectories) {
describe(categoryDirectory, () => {
const testNames = getDirectoryNames(join(baseDir, categoryDirectory));
Expand All @@ -23,7 +28,8 @@ for (const categoryDirectory of categoryDirectories) {
module.run({ ast });

const output = serializeHtml(ast);
await expect(output).toMatchFileSnapshot(`${testDirectoryPath}/output.html`);
const formattedOutput = await prettier.format(output, prettierConfig);
await expect(formattedOutput).toMatchFileSnapshot(`${testDirectoryPath}/output.html`);
});
}
});
Expand Down
13 changes: 8 additions & 5 deletions packages/core/tests/js/arrays/object-array/output.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const array = [{
test: true
}, {
test2: 'string'
}];
const array = [
{
test: true
},
{
test2: 'string'
}
];
2 changes: 1 addition & 1 deletion packages/core/tests/js/arrays/string-array/output.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const array = ['test', 'test2'];
const array = ['test', 'test2'];
6 changes: 3 additions & 3 deletions packages/core/tests/js/common/jsdoc-comment/input.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function switchToLanguage(newLanguage) {
const canonicalPath = i18n.route($page.url.pathname);
const localisedPath = i18n.resolveRoute(canonicalPath, newLanguage);
goto(localisedPath);
const canonicalPath = i18n.route($page.url.pathname);
const localisedPath = i18n.resolveRoute(canonicalPath, newLanguage);
goto(localisedPath);
}
6 changes: 3 additions & 3 deletions packages/core/tests/js/common/jsdoc-comment/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @param {import("$lib/paraglide/runtime").AvailableLanguageTag} newLanguage
*/
function switchToLanguage(newLanguage) {
const canonicalPath = i18n.route($page.url.pathname);
const localisedPath = i18n.resolveRoute(canonicalPath, newLanguage);
goto(localisedPath);
const canonicalPath = i18n.route($page.url.pathname);
const localisedPath = i18n.resolveRoute(canonicalPath, newLanguage);
goto(localisedPath);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const object = {
test: 'string'
test: 'string'
};

export default object;
export default object;
4 changes: 2 additions & 2 deletions packages/core/tests/js/exports/default-export/output.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default {
test: 'string'
};
test: 'string'
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const named = {
test: 'string',
test2: "string2"
};
test: 'string',
test2: 'string2'
};
6 changes: 3 additions & 3 deletions packages/core/tests/js/exports/named-export/output.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const variable = {
test: 'string'
test: 'string'
};

export const variable2 = {
test2: 'string2'
};
test2: 'string2'
};
6 changes: 3 additions & 3 deletions packages/core/tests/js/functions/arrow-function/output.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
() => console.log('foo');

() => {
console.log('foo');
console.log('bar');
};
console.log('foo');
console.log('bar');
};
2 changes: 1 addition & 1 deletion packages/core/tests/js/functions/function-call/output.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function foo(bar: string) {
console.log(bar);
}
foo("bar");
foo('bar');
2 changes: 1 addition & 1 deletion packages/core/tests/js/imports/default-import/output.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import MyPackage from 'package';
import MyPackage from 'package';
2 changes: 1 addition & 1 deletion packages/core/tests/js/imports/empty-import/output.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import 'package/file.css';
import './relativ/file.css';
import './relativ/file.css';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import { namedOne } from "package";
import { namedOne } from 'package';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import { namedOne, namedTwo } from "package";
import { namedOne, namedTwo } from 'package';
2 changes: 1 addition & 1 deletion packages/core/tests/js/imports/named-import/output.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { Handle } from '@sveltejs/kit';
import { namedOne } from 'package';
import { namedOne } from 'package';
2 changes: 1 addition & 1 deletion packages/core/tests/js/imports/namespaced-import/output.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import * as bar from './some-file';
import * as foo from 'package';
import * as foo from 'package';
12 changes: 9 additions & 3 deletions packages/core/tests/js/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { describe, expect, test } from 'vitest';
import { parseScript, serializeScript } from '@sveltejs/ast-tooling';
import fs from 'node:fs';
import { join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import prettier from 'prettier';
import { describe, expect, test } from 'vitest';
import { parseScript, serializeScript } from '@sveltejs/ast-tooling';

const baseDir = resolve(fileURLToPath(import.meta.url), '..');
const categoryDirectories = getDirectoryNames(baseDir);

const prettierConfig = await prettier.resolveConfig(import.meta.url);
if (!prettierConfig) throw new Error('Failed to resolve prettier config');
prettierConfig.filepath = 'output.ts';

for (const categoryDirectory of categoryDirectories) {
describe(categoryDirectory, () => {
const testNames = getDirectoryNames(join(baseDir, categoryDirectory));
Expand All @@ -23,7 +28,8 @@ for (const categoryDirectory of categoryDirectories) {
module.run({ ast });

const output = serializeScript(ast, input);
await expect(output).toMatchFileSnapshot(`${testDirectoryPath}/output.ts`);
const formattedOutput = await prettier.format(output, prettierConfig);
await expect(formattedOutput).toMatchFileSnapshot(`${testDirectoryPath}/output.ts`);
});
}
});
Expand Down
6 changes: 3 additions & 3 deletions packages/core/tests/js/object/create/output.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const empty = {};

const created = {
foo: 1,
bar: 'string'
};
foo: 1,
bar: 'string'
};
8 changes: 4 additions & 4 deletions packages/core/tests/js/object/override-property/input.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const test = {
foo: 1,
bar: 'string',
lorem: true
}
foo: 1,
bar: 'string',
lorem: true
};
8 changes: 4 additions & 4 deletions packages/core/tests/js/object/override-property/output.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const test = {
foo: 2,
bar: "string2",
lorem: false
}
foo: 2,
bar: 'string2',
lorem: false
};
4 changes: 2 additions & 2 deletions packages/core/tests/js/object/property/input.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const test = {
foo: 1
}
foo: 1
};
6 changes: 3 additions & 3 deletions packages/core/tests/js/object/property/output.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const test = {
foo: 1,
bar: "string"
}
foo: 1,
bar: 'string'
};
6 changes: 3 additions & 3 deletions packages/core/tests/js/object/remove-property/input.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const test = {
foo: 1,
bar: 'string'
}
foo: 1,
bar: 'string'
};
2 changes: 1 addition & 1 deletion packages/core/tests/js/object/remove-property/output.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const test = {}
const test = {};
4 changes: 2 additions & 2 deletions packages/core/tests/js/variables/declaration/output.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const testNumber = 2;

const testObject = {
foo: 'bar'
};
foo: 'bar'
};
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const str = "123";
const str = '123';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const str: string = "123";
const str: string = '123';
9 changes: 4 additions & 5 deletions prettier.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ const packageSortOrder = [
'keywords'
];

/** @type {import("prettier").Config} */
export default {
useTabs: true,
singleQuote: true,
trailingComma: 'none',
printWidth: 100,
endOfLine: 'lf',
plugins: ['prettier-plugin-packagejson', 'prettier-plugin-svelte'],
overrides: [
{
Expand All @@ -65,10 +67,7 @@ export default {
}
},
{
files: [
'**/CHANGELOG.md',
'packages/migrate/migrations/routes/*/samples.md'
],
files: ['**/CHANGELOG.md', 'packages/migrate/migrations/routes/*/samples.md'],
options: {
requirePragma: true
}
Expand All @@ -80,4 +79,4 @@ export default {
}
}
]
}
};

0 comments on commit 047c549

Please sign in to comment.