test: Allow assert output (#8142)
* test: Allow assert output * Use `outdent`
This commit is contained in:
1 parent
a14ba46a81
commit
f470142e16
9 files changed
+123
-218
No files matched your search
@@ -180,6 +180,7 @@
|
||||
"Kasturi",
|
||||
"Kearney",
|
||||
"Khatri",
|
||||
"l’objectif",
|
||||
"lcov",
|
||||
"libdef",
|
||||
"linearize",
|
||||
@@ -244,6 +245,7 @@
|
||||
"Okonetchnikov",
|
||||
"onwarn",
|
||||
"Oopsy",
|
||||
"outdent",
|
||||
"overparenthesization",
|
||||
"overscroll",
|
||||
"packagejson",
|
||||
@@ -328,6 +330,7 @@
|
||||
"suchipi",
|
||||
"superset",
|
||||
"supertypes",
|
||||
"Supprimer",
|
||||
"templating",
|
||||
"tempy",
|
||||
"testname",
|
||||
|
||||
@@ -105,6 +105,7 @@
|
||||
"jest-snapshot-serializer-ansi": "1.0.0",
|
||||
"jest-snapshot-serializer-raw": "1.1.0",
|
||||
"jest-watch-typeahead": "0.5.0",
|
||||
"outdent": "0.7.1",
|
||||
"prettier": "2.0.5",
|
||||
"rimraf": "3.0.2",
|
||||
"rollup": "2.7.2",
|
||||
|
||||
@@ -1,98 +1,5 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`snippet: #0 format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "flow", "typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
|
||||
=====================================output=====================================
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`snippet: #1 format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "flow", "typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
|
||||
|
||||
=====================================output=====================================
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`snippet: #2 format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "flow", "typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
=====================================output=====================================
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`snippet: #3 format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "flow", "typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
;
|
||||
=====================================output=====================================
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`snippet: #4 format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "flow", "typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
;;;;
|
||||
=====================================output=====================================
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`snippet: #5 format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "flow", "typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
;
|
||||
|
||||
=====================================output=====================================
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`snippet: #6 format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "flow", "typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
;
|
||||
|
||||
;;;
|
||||
|
||||
=====================================output=====================================
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`snippet: #7 format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "flow", "typescript"]
|
||||
|
||||
@@ -2,16 +2,18 @@ run_spec(
|
||||
{
|
||||
dirname: __dirname,
|
||||
snippets: [
|
||||
// empty
|
||||
"",
|
||||
// empty lines
|
||||
"\n",
|
||||
"\n\n\n\n",
|
||||
// semicolons
|
||||
";",
|
||||
";;;;",
|
||||
";\n",
|
||||
";\n\n;;;\n",
|
||||
...[
|
||||
// empty
|
||||
"",
|
||||
// empty lines
|
||||
"\n",
|
||||
"\n\n\n\n",
|
||||
// semicolons
|
||||
";",
|
||||
";;;;",
|
||||
";\n",
|
||||
";\n\n;;;\n",
|
||||
].map((code) => ({ code, output: "" })),
|
||||
// comments
|
||||
"// comment",
|
||||
"/* comment */",
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`test.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["flow", "typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
// Treated as whitespace in JSX
|
||||
spaces = <div>] [</div>
|
||||
tabs = <div>] [</div>
|
||||
slash_n = <div>]
|
||||
|
||||
|
||||
[</div>
|
||||
slash_r = <div>]
|
||||
|
||||
|
||||
[</div>
|
||||
|
||||
|
||||
// Not treated as whitespace in JSX
|
||||
// NOTE: Some of the space characters here won't show up in an editor,
|
||||
// but they are there!
|
||||
slash_f = <div>][</div>
|
||||
slash_v = <div>][</div>
|
||||
non_breaking_spaces = <div>] [</div>
|
||||
em_space = <div>] [</div>
|
||||
hair_space = <div>] [</div>
|
||||
zero_width_space = <div>][</div>
|
||||
real_world_non_breaking_spaces = <p>
|
||||
Supprimer l’objectif « {goal.name} » ?
|
||||
</p>
|
||||
real_world_non_breaking_spaces2 = <p>
|
||||
Supprimer l’objectif padding padding padding padding padding padding « {goal.name} » ?
|
||||
</p>
|
||||
|
||||
=====================================output=====================================
|
||||
// Treated as whitespace in JSX
|
||||
spaces = <div>] [</div>;
|
||||
tabs = <div>] [</div>;
|
||||
slash_n = <div>] [</div>;
|
||||
slash_r = <div>] [</div>;
|
||||
|
||||
// Not treated as whitespace in JSX
|
||||
// NOTE: Some of the space characters here won't show up in an editor,
|
||||
// but they are there!
|
||||
slash_f = <div>][</div>;
|
||||
slash_v = <div>][</div>;
|
||||
non_breaking_spaces = <div>] [</div>;
|
||||
em_space = <div>] [</div>;
|
||||
hair_space = <div>] [</div>;
|
||||
zero_width_space = <div>][</div>;
|
||||
real_world_non_breaking_spaces = <p>Supprimer l’objectif « {goal.name} » ?</p>;
|
||||
real_world_non_breaking_spaces2 = (
|
||||
<p>
|
||||
Supprimer l’objectif padding padding padding padding padding padding «
|
||||
{goal.name} » ?
|
||||
</p>
|
||||
);
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
@@ -1 +1,76 @@
|
||||
run_spec(__dirname, ["flow", "typescript"]);
|
||||
/* eslint-disable no-irregular-whitespace */
|
||||
const { outdent } = require("outdent");
|
||||
|
||||
run_spec(
|
||||
{
|
||||
dirname: __dirname,
|
||||
snippets: [
|
||||
{
|
||||
code: "spaces = <div>] [</div>",
|
||||
output: "spaces = <div>] [</div>;",
|
||||
},
|
||||
{
|
||||
code: "tabs = <div>] \t [</div>",
|
||||
output: "tabs = <div>] [</div>;",
|
||||
},
|
||||
{
|
||||
code: "slash_n = <div>]\n\n[</div>",
|
||||
output: "slash_n = <div>] [</div>;",
|
||||
},
|
||||
{
|
||||
code: "slash_r = <div>]\r\r[</div>",
|
||||
output: "slash_r = <div>] [</div>;",
|
||||
},
|
||||
{
|
||||
code: "slash_f = <div>]\f\f[</div>",
|
||||
output: "slash_f = <div>]\f\f[</div>;",
|
||||
},
|
||||
{
|
||||
code: "slash_v = <div>]\v\v[</div>",
|
||||
output: "slash_v = <div>]\v\v[</div>;",
|
||||
},
|
||||
{
|
||||
code: "non_breaking_spaces = <div>]\u00A0\u00A0[</div>",
|
||||
output: "non_breaking_spaces = <div>]\u00A0\u00A0[</div>;",
|
||||
},
|
||||
{
|
||||
code: "em_space = <div>]\u2003\u2003[</div>",
|
||||
output: "em_space = <div>]\u2003\u2003[</div>;",
|
||||
},
|
||||
{
|
||||
code: "hair_space = <div>]\u200a\u200a[</div>",
|
||||
output: "hair_space = <div>]\u200a\u200a[</div>;",
|
||||
},
|
||||
{
|
||||
code: "zero_width_space = <div>]\u200b\u200b[</div>",
|
||||
output: "zero_width_space = <div>]\u200b\u200b[</div>;",
|
||||
},
|
||||
{
|
||||
code: outdent`
|
||||
real_world_non_breaking_spaces = <p>
|
||||
Supprimer l’objectif «\u00A0{goal.name}\u00A0» ?
|
||||
</p>
|
||||
`,
|
||||
output: outdent`
|
||||
real_world_non_breaking_spaces = <p>Supprimer l’objectif «\u00A0{goal.name}\u00A0» ?</p>;
|
||||
`,
|
||||
},
|
||||
{
|
||||
code: outdent`
|
||||
real_world_non_breaking_spaces2 = <p>
|
||||
Supprimer l’objectif padding padding padding padding padding padding «\u00A0{goal.name}\u00A0» ?
|
||||
</p>
|
||||
`,
|
||||
output: outdent`
|
||||
real_world_non_breaking_spaces2 = (
|
||||
<p>
|
||||
Supprimer l’objectif padding padding padding padding padding padding «\u00A0
|
||||
{goal.name}\u00A0» ?
|
||||
</p>
|
||||
);
|
||||
`,
|
||||
},
|
||||
].map((test) => ({ ...test, output: test.output + "\n" })),
|
||||
},
|
||||
["flow", "typescript"]
|
||||
);
|
||||
@@ -1,28 +0,0 @@
|
||||
// Treated as whitespace in JSX
|
||||
spaces = <div>] [</div>
|
||||
tabs = <div>] [</div>
|
||||
slash_n = <div>]
|
||||
|
||||
|
||||
[</div>
|
||||
slash_r = <div>]
|
||||
|
||||
|
||||
[</div>
|
||||
|
||||
|
||||
// Not treated as whitespace in JSX
|
||||
// NOTE: Some of the space characters here won't show up in an editor,
|
||||
// but they are there!
|
||||
slash_f = <div>][</div>
|
||||
slash_v = <div>][</div>
|
||||
non_breaking_spaces = <div>] [</div>
|
||||
em_space = <div>] [</div>
|
||||
hair_space = <div>] [</div>
|
||||
zero_width_space = <div>][</div>
|
||||
real_world_non_breaking_spaces = <p>
|
||||
Supprimer l’objectif « {goal.name} » ?
|
||||
</p>
|
||||
real_world_non_breaking_spaces2 = <p>
|
||||
Supprimer l’objectif padding padding padding padding padding padding « {goal.name} » ?
|
||||
</p>
|
||||
+26
-23
@@ -73,9 +73,8 @@ global.run_spec = (fixtures, parsers, options) => {
|
||||
const snippets = (fixtures.snippets || []).map((test, index) => {
|
||||
test = typeof test === "string" ? { code: test } : test;
|
||||
return {
|
||||
...test,
|
||||
name: `snippet: ${test.name || `#${index}`}`,
|
||||
filename: test.filename,
|
||||
code: test.code,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -105,7 +104,7 @@ global.run_spec = (fixtures, parsers, options) => {
|
||||
|
||||
const stringifiedOptions = stringifyOptions(options);
|
||||
|
||||
for (const { name, filename, code } of [...files, ...snippets]) {
|
||||
for (const { name, filename, code, output } of [...files, ...snippets]) {
|
||||
describe(`${name}${
|
||||
stringifiedOptions ? ` - ${stringifiedOptions}` : ""
|
||||
}`, () => {
|
||||
@@ -153,28 +152,33 @@ global.run_spec = (fixtures, parsers, options) => {
|
||||
return;
|
||||
}
|
||||
|
||||
const output = format(input, filename, mainOptions);
|
||||
const visualizedOutput = visualizeEndOfLine(output);
|
||||
const formattedWithCursor = format(input, filename, mainOptions);
|
||||
const formatted = formattedWithCursor.replace(CURSOR_PLACEHOLDER, "");
|
||||
const visualizedOutput = visualizeEndOfLine(formattedWithCursor);
|
||||
|
||||
test("format", () => {
|
||||
expect(visualizedOutput).toEqual(
|
||||
visualizeEndOfLine(consistentEndOfLine(output))
|
||||
visualizeEndOfLine(consistentEndOfLine(formattedWithCursor))
|
||||
);
|
||||
expect(
|
||||
raw(
|
||||
createSnapshot(
|
||||
hasEndOfLine
|
||||
? visualizeEndOfLine(
|
||||
code
|
||||
.replace(RANGE_START_PLACEHOLDER, "")
|
||||
.replace(RANGE_END_PLACEHOLDER, "")
|
||||
)
|
||||
: source,
|
||||
hasEndOfLine ? visualizedOutput : output,
|
||||
{ ...baseOptions, parsers }
|
||||
if (typeof output === "string") {
|
||||
expect(formatted).toEqual(output);
|
||||
} else {
|
||||
expect(
|
||||
raw(
|
||||
createSnapshot(
|
||||
hasEndOfLine
|
||||
? visualizeEndOfLine(
|
||||
code
|
||||
.replace(RANGE_START_PLACEHOLDER, "")
|
||||
.replace(RANGE_END_PLACEHOLDER, "")
|
||||
)
|
||||
: source,
|
||||
hasEndOfLine ? visualizedOutput : formattedWithCursor,
|
||||
{ ...baseOptions, parsers }
|
||||
)
|
||||
)
|
||||
)
|
||||
).toMatchSnapshot();
|
||||
).toMatchSnapshot();
|
||||
}
|
||||
});
|
||||
|
||||
const parsersToVerify = parsers.slice(1);
|
||||
@@ -203,7 +207,6 @@ global.run_spec = (fixtures, parsers, options) => {
|
||||
});
|
||||
}
|
||||
|
||||
const formatted = output.replace(CURSOR_PLACEHOLDER, "");
|
||||
const isUnstable = unstableTests.get(filename);
|
||||
const isUnstableTest = isUnstable && isUnstable(options || {});
|
||||
if (
|
||||
@@ -219,9 +222,9 @@ global.run_spec = (fixtures, parsers, options) => {
|
||||
if (isUnstableTest) {
|
||||
// To keep eye on failed tests, this assert never supposed to pass,
|
||||
// if it fails, just remove the file from `unstableTests`
|
||||
expect(secondOutput).not.toEqual(output);
|
||||
expect(secondOutput).not.toEqual(formatted);
|
||||
} else {
|
||||
expect(secondOutput).toEqual(output);
|
||||
expect(secondOutput).toEqual(formatted);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5809,6 +5809,11 @@ os-tmpdir@~1.0.2:
|
||||
resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274"
|
||||
integrity sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=
|
||||
|
||||
outdent@0.7.1:
|
||||
version "0.7.1"
|
||||
resolved "https://registry.yarnpkg.com/outdent/-/outdent-0.7.1.tgz#e9b400443622a97760b0bc74fa3223252ccd02a2"
|
||||
integrity sha512-VjIzdUHunL74DdhcwMDt5FhNDQ8NYmTkuW0B+usIV2afS9aWT/1c9z1TsnFW349TP3nxmYeUl7Z++XpJRByvgg==
|
||||
|
||||
p-defer@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/p-defer/-/p-defer-1.0.0.tgz#9f6eb182f6c9aa8cd743004a7d4f96b196b0fb0c"
|
||||
|
||||
Reference in new issue
Block a user