Skip to content

Commit

Permalink
renaming format-test.js to run-format-test.js and run_spec to runForm…
Browse files Browse the repository at this point in the history
…atTest
  • Loading branch information
Janther committed Aug 16, 2024
1 parent 86e335e commit 45a7360
Show file tree
Hide file tree
Showing 65 changed files with 93 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
},
"extends": ["airbnb-base", "prettier"],
"globals": {
"run_spec": false
"runFormatTest": "readonly"
},
"parserOptions": {
"ecmaVersion": "latest",
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (TEST_STANDALONE) {

export default {
runner: 'jest-light-runner',
setupFiles: ['<rootDir>/tests/config/setup.js'],
setupFiles: ['<rootDir>/tests/config/format-test-setup.js'],
snapshotSerializers: [
'jest-snapshot-serializer-raw',
'jest-snapshot-serializer-ansi'
Expand Down
3 changes: 3 additions & 0 deletions tests/config/format-test-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import runFormatTest from "./run-format-test.js";

globalThis.runFormatTest = runFormatTest;
4 changes: 2 additions & 2 deletions tests/config/require-standalone.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = {
};
prettier.formatWithCursor($$$input, options);
`,
{ $$$input: input, $$$options: options, ...sandbox }
{ $$$input: input, $$$options: options, ...sandbox },
);
},

Expand All @@ -57,7 +57,7 @@ module.exports = {
$$$options: options,
$$$devOptions: devOptions,
...sandbox,
}
},
);
},
},
Expand Down
14 changes: 8 additions & 6 deletions tests/config/format-test.js → tests/config/run-format-test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import fs from "node:fs";
import path from "node:path";
import url from "node:url";

import createEsmUtils from "esm-utils";

import getPrettier from "./get-prettier.js";
import compileContract from "./utils/compile-contract.js";
import createSnapshot from "./utils/create-snapshot.js";
import visualizeEndOfLine from "./utils/visualize-end-of-line.js";
import consistentEndOfLine from "./utils/consistent-end-of-line.js";
import createSnapshot from "./utils/create-snapshot.js";
import stringifyOptionsForTitle from "./utils/stringify-options-for-title.js";
import visualizeEndOfLine from "./utils/visualize-end-of-line.js";

const { __dirname } = createEsmUtils(import.meta);

Expand Down Expand Up @@ -112,7 +114,7 @@ const isTestDirectory = (dirname, name) =>
path.join(__dirname, "../format", name) + path.sep,
);

function runSpec(fixtures, parsers, options) {
function runFormatTest(fixtures, parsers, options) {
let { importMeta, snippets = [] } = fixtures.importMeta
? fixtures
: { importMeta: fixtures };
Expand Down Expand Up @@ -326,15 +328,15 @@ async function runTest({
if (!shouldSkipEolTest(code, formatResult.options)) {
for (const eol of ["\r\n", "\r"]) {
const { eolVisualizedOutput: output } = await format(
code.replace(/\n/g, eol),
code.replace(/\n/gu, eol),
formatOptions,
);
// Only if `endOfLine: "auto"` the result will be different
const expected =
formatOptions.endOfLine === "auto"
? visualizeEndOfLine(
// All `code` use `LF`, so the `eol` of result is always `LF`
formatResult.outputWithCursor.replace(/\n/g, eol),
formatResult.outputWithCursor.replace(/\n/gu, eol),
)
: formatResult.eolVisualizedOutput;
expect(output).toEqual(expected);
Expand Down Expand Up @@ -452,4 +454,4 @@ async function format(originalText, originalOptions) {
};
}

export default runSpec;
export default runFormatTest;
3 changes: 0 additions & 3 deletions tests/config/setup.js

This file was deleted.

2 changes: 1 addition & 1 deletion tests/format/AddressPayable/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
2 changes: 1 addition & 1 deletion tests/format/AllSolidityFeatures/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
2 changes: 1 addition & 1 deletion tests/format/AllSolidityFeaturesV0.4.26/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse'], { compiler: '0.4.26' });
runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.4.26' });
2 changes: 1 addition & 1 deletion tests/format/Arrays/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
2 changes: 1 addition & 1 deletion tests/format/Assembly/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
2 changes: 1 addition & 1 deletion tests/format/AssemblyV0.4.26/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse'], { compiler: '0.4.26' });
runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.4.26' });
2 changes: 1 addition & 1 deletion tests/format/BasicIterator/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse'], { compiler: '0.4.26' });
runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.4.26' });
2 changes: 1 addition & 1 deletion tests/format/BinaryOperators/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse'], { compiler: '0.5.8' });
runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.5.8' });
12 changes: 6 additions & 6 deletions tests/format/BreakingChangesV0.7.4/format.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
run_spec(import.meta, ['solidity-parse'], { compiler: '0.7.4' });
run_spec(import.meta, ['solidity-parse'], {
runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.7.4' });
runFormatTest(import.meta, ['solidity-parse'], {
compiler: '0.7.4',
bracketSpacing: true
});
run_spec(import.meta, ['solidity-parse'], { compiler: '0.7.3' });
run_spec(import.meta, ['solidity-parse'], {
runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.7.3' });
runFormatTest(import.meta, ['solidity-parse'], {
compiler: '0.7.3',
bracketSpacing: true
});
run_spec(import.meta, ['solidity-parse']);
run_spec(import.meta, ['solidity-parse'], {
runFormatTest(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse'], {
bracketSpacing: true
});
6 changes: 3 additions & 3 deletions tests/format/BreakingChangesV0.8.0/format.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
run_spec(import.meta, ['solidity-parse']);
run_spec(import.meta, ['solidity-parse'], { compiler: '0.8.0' });
run_spec(import.meta, ['solidity-parse'], { compiler: '0.7.0' });
runFormatTest(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.8.0' });
runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.7.0' });
2 changes: 1 addition & 1 deletion tests/format/Comments/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse'], { compiler: '0.4.24' });
runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.4.24' });
2 changes: 1 addition & 1 deletion tests/format/Conditional/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
2 changes: 1 addition & 1 deletion tests/format/Constructors/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
2 changes: 1 addition & 1 deletion tests/format/ContractDefinitions/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
2 changes: 1 addition & 1 deletion tests/format/CustomErrors/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
4 changes: 2 additions & 2 deletions tests/format/EnumDefinitions/format.test.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
run_spec(import.meta, ['solidity-parse']);
run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true });
runFormatTest(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse'], { bracketSpacing: true });
2 changes: 1 addition & 1 deletion tests/format/Etc/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
8 changes: 4 additions & 4 deletions tests/format/ExperimentalTernaries/format.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
run_spec(import.meta, ['solidity-parse']);
run_spec(import.meta, ['solidity-parse'], { experimentalTernaries: true });
run_spec(import.meta, ['solidity-parse'], {
runFormatTest(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse'], { experimentalTernaries: true });
runFormatTest(import.meta, ['solidity-parse'], {
experimentalTernaries: true,
tabWidth: 1
});
run_spec(import.meta, ['solidity-parse'], {
runFormatTest(import.meta, ['solidity-parse'], {
experimentalTernaries: true,
useTabs: true
});
2 changes: 1 addition & 1 deletion tests/format/ForStatements/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
4 changes: 2 additions & 2 deletions tests/format/FunctionCalls/format.test.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
run_spec(import.meta, ['solidity-parse']);
run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true });
runFormatTest(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse'], { bracketSpacing: true });
2 changes: 1 addition & 1 deletion tests/format/FunctionDefinitions/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse'], { compiler: '0.8.0' });
runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.8.0' });
2 changes: 1 addition & 1 deletion tests/format/FunctionDefinitionsV0.5.0/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse'], { compiler: '0.5.0' });
runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.5.0' });
4 changes: 2 additions & 2 deletions tests/format/HexLiteral/format.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
run_spec(import.meta, ['solidity-parse'], {
runFormatTest(import.meta, ['solidity-parse'], {
compiler: '0.8.6',
singleQuote: true
});
run_spec(import.meta, ['solidity-parse'], {
runFormatTest(import.meta, ['solidity-parse'], {
compiler: '0.8.6',
singleQuote: false
});
2 changes: 1 addition & 1 deletion tests/format/IfStatements/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
2 changes: 1 addition & 1 deletion tests/format/Immutable/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
4 changes: 2 additions & 2 deletions tests/format/ImportDirective/format.test.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
run_spec(import.meta, ['solidity-parse']);
run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true });
runFormatTest(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse'], { bracketSpacing: true });
2 changes: 1 addition & 1 deletion tests/format/Inbox/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
2 changes: 1 addition & 1 deletion tests/format/IndexOf/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse'], { compiler: '0.4.26' });
runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.4.26' });
2 changes: 1 addition & 1 deletion tests/format/IndexRangeAccess/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
2 changes: 1 addition & 1 deletion tests/format/InheritanceSpecifier/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
2 changes: 1 addition & 1 deletion tests/format/Issues/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
4 changes: 2 additions & 2 deletions tests/format/Libraries/format.test.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
run_spec(import.meta, ['solidity-parse']);
run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true });
runFormatTest(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse'], { bracketSpacing: true });
2 changes: 1 addition & 1 deletion tests/format/Markdown/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['markdown']);
runFormatTest(import.meta, ['markdown']);
2 changes: 1 addition & 1 deletion tests/format/MemberAccess/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
2 changes: 1 addition & 1 deletion tests/format/ModifierDefinitions/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
2 changes: 1 addition & 1 deletion tests/format/ModifierInvocations/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse'], { compiler: '0.8.0' });
runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.8.0' });
2 changes: 1 addition & 1 deletion tests/format/MultipartStrings/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
4 changes: 2 additions & 2 deletions tests/format/NameValueExpression/format.test.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
run_spec(import.meta, ['solidity-parse']);
run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true });
runFormatTest(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse'], { bracketSpacing: true });
2 changes: 1 addition & 1 deletion tests/format/NumberLiteral/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
2 changes: 1 addition & 1 deletion tests/format/Ownable/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
2 changes: 1 addition & 1 deletion tests/format/Parentheses/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse'], { compiler: '0.8.6' });
runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.8.6' });
2 changes: 1 addition & 1 deletion tests/format/Pragma/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
2 changes: 1 addition & 1 deletion tests/format/PrettierIgnore/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
2 changes: 1 addition & 1 deletion tests/format/Proxy/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse'], { compiler: '0.4.24' });
runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.4.24' });
2 changes: 1 addition & 1 deletion tests/format/RespectDefaultOptions/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['babel']);
runFormatTest(import.meta, ['babel']);
2 changes: 1 addition & 1 deletion tests/format/SampleCrowdsale/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
2 changes: 1 addition & 1 deletion tests/format/SimpleAuction/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
2 changes: 1 addition & 1 deletion tests/format/SimpleStorage/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
2 changes: 1 addition & 1 deletion tests/format/SplittableCommodity/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
2 changes: 1 addition & 1 deletion tests/format/StateVariableDeclarations/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
2 changes: 1 addition & 1 deletion tests/format/StringLiteral/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
2 changes: 1 addition & 1 deletion tests/format/StyleGuide/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse'], { compiler: '0.5.0' });
runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.5.0' });
2 changes: 1 addition & 1 deletion tests/format/TryCatch/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
2 changes: 1 addition & 1 deletion tests/format/Tuples/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
2 changes: 1 addition & 1 deletion tests/format/TypeDefinition/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
2 changes: 1 addition & 1 deletion tests/format/WhileStatements/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);
6 changes: 3 additions & 3 deletions tests/format/WrongCompiler/format.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Should warn twice
run_spec(import.meta, ['solidity-parse'], { compiler: '0.8.4' });
runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.8.4' });
// Should warn once
run_spec(import.meta, ['solidity-parse'], {
runFormatTest(import.meta, ['solidity-parse'], {
compiler: 'v0.7.5-nightly.2020.11.9+commit.41f50365'
});
// Should not warn
run_spec(import.meta, ['solidity-parse'], {
runFormatTest(import.meta, ['solidity-parse'], {
compiler: 'v0.7.3+commit.9bfce1f6'
});
4 changes: 2 additions & 2 deletions tests/format/quotes/format.test.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
run_spec(import.meta, ['solidity-parse'], { singleQuote: true });
run_spec(import.meta, ['solidity-parse'], { singleQuote: false });
runFormatTest(import.meta, ['solidity-parse'], { singleQuote: true });
runFormatTest(import.meta, ['solidity-parse'], { singleQuote: false });
2 changes: 1 addition & 1 deletion tests/format/strings/format.test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(import.meta, ['solidity-parse']);
runFormatTest(import.meta, ['solidity-parse']);

0 comments on commit 45a7360

Please sign in to comment.