From b29d8ff852f9764031aeffefc56fac6eaf7f9d42 Mon Sep 17 00:00:00 2001 From: fisker Date: Wed, 16 Aug 2023 16:55:56 +0800 Subject: [PATCH 1/2] Convert tests to ES Modules --- .eslintrc.yml | 8 ++++++-- tests/array/jsfmt.spec.js | 4 ++-- tests/arrowfunc/jsfmt.spec.js | 2 +- tests/assign/jsfmt.spec.js | 2 +- tests/assignref/jsfmt.spec.js | 2 +- tests/attributes-trail-comma/jsfmt.spec.js | 2 +- tests/attributes/jsfmt.spec.js | 2 +- tests/bin/jsfmt.spec.js | 2 +- tests/block/jsfmt.spec.js | 2 +- tests/boolean/jsfmt.spec.js | 2 +- tests/brace-style/jsfmt.spec.js | 8 ++++---- tests/break/jsfmt.spec.js | 2 +- tests/call/jsfmt.spec.js | 2 +- tests/case/jsfmt.spec.js | 2 +- tests/cast/jsfmt.spec.js | 2 +- tests/class/jsfmt.spec.js | 4 ++-- tests/classconstant/jsfmt.spec.js | 2 +- tests/clone/jsfmt.spec.js | 2 +- tests/closure/jsfmt.spec.js | 2 +- tests/comments/jsfmt.spec.js | 2 +- tests/constant/jsfmt.spec.js | 2 +- tests/continue/jsfmt.spec.js | 2 +- tests/declare/jsfmt.spec.js | 2 +- tests/do/jsfmt.spec.js | 2 +- tests/echo/jsfmt.spec.js | 2 +- tests/empty/jsfmt.spec.js | 2 +- tests/encapsed/jsfmt.spec.js | 4 ++-- tests/enum/jsfmt.spec.js | 2 +- tests/errors/jsfmt.spec.js | 2 +- tests/eval/jsfmt.spec.js | 2 +- tests/exit/jsfmt.spec.js | 2 +- tests/extensions/jsfmt.spec.js | 2 +- tests/for/jsfmt.spec.js | 2 +- tests/foreach/jsfmt.spec.js | 2 +- tests/formatting/jsfmt.spec.js | 2 +- tests/functions/jsfmt.spec.js | 4 ++-- tests/global/jsfmt.spec.js | 2 +- tests/goto/jsfmt.spec.js | 2 +- tests/halt/jsfmt.spec.js | 2 +- tests/identifier-and-reference/jsfmt.spec.js | 2 +- tests/if/jsfmt.spec.js | 2 +- tests/ignore/jsfmt.spec.js | 2 +- tests/include/jsfmt.spec.js | 2 +- tests/inline/jsfmt.spec.js | 2 +- tests/insert-pragma/jsfmt.spec.js | 6 +++--- tests/interface/jsfmt.spec.js | 4 ++-- tests/intersection-types/jsfmt.spec.js | 2 +- tests/isset/jsfmt.spec.js | 2 +- tests/kitchen_sink/jsfmt.spec.js | 4 ++-- tests/list/jsfmt.spec.js | 4 ++-- tests/magic/jsfmt.spec.js | 2 +- tests/markdown/jsfmt.spec.js | 2 +- tests/match/jsfmt.spec.js | 4 ++-- tests/member_chain/jsfmt.spec.js | 2 +- tests/method/jsfmt.spec.js | 2 +- tests/namedarguments/jsfmt.spec.js | 2 +- tests/namespace/jsfmt.spec.js | 2 +- tests/new/jsfmt.spec.js | 2 +- tests/newline/jsfmt.spec.js | 6 +++--- tests/nowdoc/jsfmt.spec.js | 4 ++-- tests/nullsafepropertylookup/jsfmt.spec.js | 2 +- tests/number/jsfmt.spec.js | 2 +- tests/offsetlookup/jsfmt.spec.js | 2 +- tests/package.json | 5 +++++ tests/parameter/jsfmt.spec.js | 2 +- tests/parens/jsfmt.spec.js | 2 +- tests/preserve_line/jsfmt.spec.js | 2 +- tests/print/jsfmt.spec.js | 2 +- tests/program/jsfmt.spec.js | 2 +- tests/property/jsfmt.spec.js | 2 +- tests/propertylookup/jsfmt.spec.js | 2 +- tests/propertystatement/jsfmt.spec.js | 2 +- tests/require-pragma/jsfmt.spec.js | 6 +++--- tests/retif/jsfmt.spec.js | 2 +- tests/return/jsfmt.spec.js | 2 +- tests/shebang/jsfmt.spec.js | 2 +- tests/silent/jsfmt.spec.js | 2 +- tests/statement/jsfmt.spec.js | 2 +- tests/static/jsfmt.spec.js | 2 +- tests/staticlookup/jsfmt.spec.js | 2 +- tests/string-double-quote/jsfmt.spec.js | 2 +- tests/string-single-quote/jsfmt.spec.js | 2 +- tests/string/jsfmt.spec.js | 2 +- tests/switch/jsfmt.spec.js | 2 +- tests/syntax-error/jsfmt.spec.js | 4 ++-- tests/sys/jsfmt.spec.js | 2 +- tests/trailing_comma_func/jsfmt.spec.js | 4 ++-- tests/trailing_commas/jsfmt.spec.js | 10 +++++----- tests/trailing_whitespace/jsfmt.spec.js | 2 +- tests/traitalias/jsfmt.spec.js | 2 +- tests/traits/jsfmt.spec.js | 4 ++-- tests/traituse/jsfmt.spec.js | 2 +- tests/uniontypes/jsfmt.spec.js | 2 +- tests/unset/jsfmt.spec.js | 2 +- tests/use/jsfmt.spec.js | 2 +- tests/variable/jsfmt.spec.js | 2 +- tests/variadic/jsfmt.spec.js | 2 +- tests/while/jsfmt.spec.js | 2 +- tests/yield/jsfmt.spec.js | 2 +- tests_config/get_engine.js | 21 +++++++++++--------- tests_config/package.json | 5 +++++ tests_config/run_spec.js | 14 ++++++------- 102 files changed, 157 insertions(+), 140 deletions(-) create mode 100644 tests/package.json create mode 100644 tests_config/package.json diff --git a/.eslintrc.yml b/.eslintrc.yml index 57a6e779f..f62d29428 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -39,9 +39,13 @@ rules: - never - exceptRange: true overrides: - - files: "tests/**/*.js" + - files: "{tests,tests_config}/**/*.js" + parserOptions: + sourceType: "module" rules: - strict: off + # Turned off temporarily since we add a package.json without dependencies in these dirs + import/no-extraneous-dependencies: off + - files: "tests/**/*.js" globals: run_spec: true - files: "build/*.js" diff --git a/tests/array/jsfmt.spec.js b/tests/array/jsfmt.spec.js index 3073bc63a..d43490aab 100644 --- a/tests/array/jsfmt.spec.js +++ b/tests/array/jsfmt.spec.js @@ -1,2 +1,2 @@ -run_spec(__dirname, ["php"]); -run_spec(__dirname, ["php"], { phpVersion: "5.3" }); +run_spec(import.meta, ["php"]); +run_spec(import.meta, ["php"], { phpVersion: "5.3" }); diff --git a/tests/arrowfunc/jsfmt.spec.js b/tests/arrowfunc/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/arrowfunc/jsfmt.spec.js +++ b/tests/arrowfunc/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/assign/jsfmt.spec.js b/tests/assign/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/assign/jsfmt.spec.js +++ b/tests/assign/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/assignref/jsfmt.spec.js b/tests/assignref/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/assignref/jsfmt.spec.js +++ b/tests/assignref/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/attributes-trail-comma/jsfmt.spec.js b/tests/attributes-trail-comma/jsfmt.spec.js index 8fd98a9ac..b6511ba4e 100644 --- a/tests/attributes-trail-comma/jsfmt.spec.js +++ b/tests/attributes-trail-comma/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"], { trailingCommaPHP: true, phpVersion: "8.0" }); +run_spec(import.meta, ["php"], { trailingCommaPHP: true, phpVersion: "8.0" }); diff --git a/tests/attributes/jsfmt.spec.js b/tests/attributes/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/attributes/jsfmt.spec.js +++ b/tests/attributes/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/bin/jsfmt.spec.js b/tests/bin/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/bin/jsfmt.spec.js +++ b/tests/bin/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/block/jsfmt.spec.js b/tests/block/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/block/jsfmt.spec.js +++ b/tests/block/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/boolean/jsfmt.spec.js b/tests/boolean/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/boolean/jsfmt.spec.js +++ b/tests/boolean/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/brace-style/jsfmt.spec.js b/tests/brace-style/jsfmt.spec.js index 09a6fcb5c..8ac8c68a1 100644 --- a/tests/brace-style/jsfmt.spec.js +++ b/tests/brace-style/jsfmt.spec.js @@ -1,4 +1,4 @@ -run_spec(__dirname, ["php"]); -run_spec(__dirname, ["php"], { braceStyle: "psr-2" }); -run_spec(__dirname, ["php"], { braceStyle: "per-cs" }); -run_spec(__dirname, ["php"], { braceStyle: "1tbs" }); +run_spec(import.meta, ["php"]); +run_spec(import.meta, ["php"], { braceStyle: "psr-2" }); +run_spec(import.meta, ["php"], { braceStyle: "per-cs" }); +run_spec(import.meta, ["php"], { braceStyle: "1tbs" }); diff --git a/tests/break/jsfmt.spec.js b/tests/break/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/break/jsfmt.spec.js +++ b/tests/break/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/call/jsfmt.spec.js b/tests/call/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/call/jsfmt.spec.js +++ b/tests/call/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/case/jsfmt.spec.js b/tests/case/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/case/jsfmt.spec.js +++ b/tests/case/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/cast/jsfmt.spec.js b/tests/cast/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/cast/jsfmt.spec.js +++ b/tests/cast/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/class/jsfmt.spec.js b/tests/class/jsfmt.spec.js index 5378de169..4d43d0cbd 100644 --- a/tests/class/jsfmt.spec.js +++ b/tests/class/jsfmt.spec.js @@ -1,3 +1,3 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); // see https://github.com/prettier/plugin-php/issues/107 -// run_spec(__dirname, ["php"], { openingBraceNewLine: false }); +// run_spec(import.meta, ["php"], { openingBraceNewLine: false }); diff --git a/tests/classconstant/jsfmt.spec.js b/tests/classconstant/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/classconstant/jsfmt.spec.js +++ b/tests/classconstant/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/clone/jsfmt.spec.js b/tests/clone/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/clone/jsfmt.spec.js +++ b/tests/clone/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/closure/jsfmt.spec.js b/tests/closure/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/closure/jsfmt.spec.js +++ b/tests/closure/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/comments/jsfmt.spec.js b/tests/comments/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/comments/jsfmt.spec.js +++ b/tests/comments/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/constant/jsfmt.spec.js b/tests/constant/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/constant/jsfmt.spec.js +++ b/tests/constant/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/continue/jsfmt.spec.js b/tests/continue/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/continue/jsfmt.spec.js +++ b/tests/continue/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/declare/jsfmt.spec.js b/tests/declare/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/declare/jsfmt.spec.js +++ b/tests/declare/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/do/jsfmt.spec.js b/tests/do/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/do/jsfmt.spec.js +++ b/tests/do/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/echo/jsfmt.spec.js b/tests/echo/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/echo/jsfmt.spec.js +++ b/tests/echo/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/empty/jsfmt.spec.js b/tests/empty/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/empty/jsfmt.spec.js +++ b/tests/empty/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/encapsed/jsfmt.spec.js b/tests/encapsed/jsfmt.spec.js index e2d819801..5279179f2 100644 --- a/tests/encapsed/jsfmt.spec.js +++ b/tests/encapsed/jsfmt.spec.js @@ -1,2 +1,2 @@ -run_spec(__dirname, ["php"]); -run_spec(__dirname, ["php"], { phpVersion: "7.3" }); +run_spec(import.meta, ["php"]); +run_spec(import.meta, ["php"], { phpVersion: "7.3" }); diff --git a/tests/enum/jsfmt.spec.js b/tests/enum/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/enum/jsfmt.spec.js +++ b/tests/enum/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/errors/jsfmt.spec.js b/tests/errors/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/errors/jsfmt.spec.js +++ b/tests/errors/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/eval/jsfmt.spec.js b/tests/eval/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/eval/jsfmt.spec.js +++ b/tests/eval/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/exit/jsfmt.spec.js b/tests/exit/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/exit/jsfmt.spec.js +++ b/tests/exit/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/extensions/jsfmt.spec.js b/tests/extensions/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/extensions/jsfmt.spec.js +++ b/tests/extensions/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/for/jsfmt.spec.js b/tests/for/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/for/jsfmt.spec.js +++ b/tests/for/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/foreach/jsfmt.spec.js b/tests/foreach/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/foreach/jsfmt.spec.js +++ b/tests/foreach/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/formatting/jsfmt.spec.js b/tests/formatting/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/formatting/jsfmt.spec.js +++ b/tests/formatting/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/functions/jsfmt.spec.js b/tests/functions/jsfmt.spec.js index 5378de169..4d43d0cbd 100644 --- a/tests/functions/jsfmt.spec.js +++ b/tests/functions/jsfmt.spec.js @@ -1,3 +1,3 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); // see https://github.com/prettier/plugin-php/issues/107 -// run_spec(__dirname, ["php"], { openingBraceNewLine: false }); +// run_spec(import.meta, ["php"], { openingBraceNewLine: false }); diff --git a/tests/global/jsfmt.spec.js b/tests/global/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/global/jsfmt.spec.js +++ b/tests/global/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/goto/jsfmt.spec.js b/tests/goto/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/goto/jsfmt.spec.js +++ b/tests/goto/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/halt/jsfmt.spec.js b/tests/halt/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/halt/jsfmt.spec.js +++ b/tests/halt/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/identifier-and-reference/jsfmt.spec.js b/tests/identifier-and-reference/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/identifier-and-reference/jsfmt.spec.js +++ b/tests/identifier-and-reference/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/if/jsfmt.spec.js b/tests/if/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/if/jsfmt.spec.js +++ b/tests/if/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/ignore/jsfmt.spec.js b/tests/ignore/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/ignore/jsfmt.spec.js +++ b/tests/ignore/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/include/jsfmt.spec.js b/tests/include/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/include/jsfmt.spec.js +++ b/tests/include/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/inline/jsfmt.spec.js b/tests/inline/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/inline/jsfmt.spec.js +++ b/tests/inline/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/insert-pragma/jsfmt.spec.js b/tests/insert-pragma/jsfmt.spec.js index 1a328b63e..c1683e70b 100644 --- a/tests/insert-pragma/jsfmt.spec.js +++ b/tests/insert-pragma/jsfmt.spec.js @@ -1,3 +1,3 @@ -run_spec(__dirname, ["php"], { insertPragma: true, endOfLine: "cr" }); -run_spec(__dirname, ["php"], { insertPragma: true, endOfLine: "crlf" }); -run_spec(__dirname, ["php"], { insertPragma: true, endOfLine: "lf" }); +run_spec(import.meta, ["php"], { insertPragma: true, endOfLine: "cr" }); +run_spec(import.meta, ["php"], { insertPragma: true, endOfLine: "crlf" }); +run_spec(import.meta, ["php"], { insertPragma: true, endOfLine: "lf" }); diff --git a/tests/interface/jsfmt.spec.js b/tests/interface/jsfmt.spec.js index 5378de169..4d43d0cbd 100644 --- a/tests/interface/jsfmt.spec.js +++ b/tests/interface/jsfmt.spec.js @@ -1,3 +1,3 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); // see https://github.com/prettier/plugin-php/issues/107 -// run_spec(__dirname, ["php"], { openingBraceNewLine: false }); +// run_spec(import.meta, ["php"], { openingBraceNewLine: false }); diff --git a/tests/intersection-types/jsfmt.spec.js b/tests/intersection-types/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/intersection-types/jsfmt.spec.js +++ b/tests/intersection-types/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/isset/jsfmt.spec.js b/tests/isset/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/isset/jsfmt.spec.js +++ b/tests/isset/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/kitchen_sink/jsfmt.spec.js b/tests/kitchen_sink/jsfmt.spec.js index 2e1965334..efafecaf4 100644 --- a/tests/kitchen_sink/jsfmt.spec.js +++ b/tests/kitchen_sink/jsfmt.spec.js @@ -1,2 +1,2 @@ -run_spec(__dirname, ["php"]); -// run_spec(__dirname, ["php"], { openingBraceNewLine: false }); +run_spec(import.meta, ["php"]); +// run_spec(import.meta, ["php"], { openingBraceNewLine: false }); diff --git a/tests/list/jsfmt.spec.js b/tests/list/jsfmt.spec.js index 935da6579..c0ec8a1fc 100644 --- a/tests/list/jsfmt.spec.js +++ b/tests/list/jsfmt.spec.js @@ -1,2 +1,2 @@ -run_spec(__dirname, ["php"]); -run_spec(__dirname, ["php"], { phpVersion: "7.1" }); +run_spec(import.meta, ["php"]); +run_spec(import.meta, ["php"], { phpVersion: "7.1" }); diff --git a/tests/magic/jsfmt.spec.js b/tests/magic/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/magic/jsfmt.spec.js +++ b/tests/magic/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/markdown/jsfmt.spec.js b/tests/markdown/jsfmt.spec.js index 4503e4a25..6c898223a 100644 --- a/tests/markdown/jsfmt.spec.js +++ b/tests/markdown/jsfmt.spec.js @@ -1,4 +1,4 @@ -run_spec(__dirname, ["markdown"], { +run_spec(import.meta, ["markdown"], { plugins: global.STANDALONE ? [require("prettier/parser-markdown")] : [], proseWrap: "always", tabWidth: 4, diff --git a/tests/match/jsfmt.spec.js b/tests/match/jsfmt.spec.js index c3743e711..97399d8f1 100644 --- a/tests/match/jsfmt.spec.js +++ b/tests/match/jsfmt.spec.js @@ -1,8 +1,8 @@ -run_spec(__dirname, ["php"], { +run_spec(import.meta, ["php"], { trailingCommaPHP: false, phpVersion: "8.0", }); -run_spec(__dirname, ["php"], { +run_spec(import.meta, ["php"], { trailingCommaPHP: true, phpVersion: "8.0", }); diff --git a/tests/member_chain/jsfmt.spec.js b/tests/member_chain/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/member_chain/jsfmt.spec.js +++ b/tests/member_chain/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/method/jsfmt.spec.js b/tests/method/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/method/jsfmt.spec.js +++ b/tests/method/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/namedarguments/jsfmt.spec.js b/tests/namedarguments/jsfmt.spec.js index cc787638c..d22c24d29 100644 --- a/tests/namedarguments/jsfmt.spec.js +++ b/tests/namedarguments/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"], { phpVersion: "8.0" }); +run_spec(import.meta, ["php"], { phpVersion: "8.0" }); diff --git a/tests/namespace/jsfmt.spec.js b/tests/namespace/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/namespace/jsfmt.spec.js +++ b/tests/namespace/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/new/jsfmt.spec.js b/tests/new/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/new/jsfmt.spec.js +++ b/tests/new/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/newline/jsfmt.spec.js b/tests/newline/jsfmt.spec.js index e79d21a9b..4096c5dc5 100644 --- a/tests/newline/jsfmt.spec.js +++ b/tests/newline/jsfmt.spec.js @@ -1,3 +1,3 @@ -run_spec(__dirname, ["php"], { endOfLine: "cr" }); -run_spec(__dirname, ["php"], { endOfLine: "crlf" }); -run_spec(__dirname, ["php"], { endOfLine: "lf" }); +run_spec(import.meta, ["php"], { endOfLine: "cr" }); +run_spec(import.meta, ["php"], { endOfLine: "crlf" }); +run_spec(import.meta, ["php"], { endOfLine: "lf" }); diff --git a/tests/nowdoc/jsfmt.spec.js b/tests/nowdoc/jsfmt.spec.js index e2d819801..5279179f2 100644 --- a/tests/nowdoc/jsfmt.spec.js +++ b/tests/nowdoc/jsfmt.spec.js @@ -1,2 +1,2 @@ -run_spec(__dirname, ["php"]); -run_spec(__dirname, ["php"], { phpVersion: "7.3" }); +run_spec(import.meta, ["php"]); +run_spec(import.meta, ["php"], { phpVersion: "7.3" }); diff --git a/tests/nullsafepropertylookup/jsfmt.spec.js b/tests/nullsafepropertylookup/jsfmt.spec.js index cc787638c..d22c24d29 100644 --- a/tests/nullsafepropertylookup/jsfmt.spec.js +++ b/tests/nullsafepropertylookup/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"], { phpVersion: "8.0" }); +run_spec(import.meta, ["php"], { phpVersion: "8.0" }); diff --git a/tests/number/jsfmt.spec.js b/tests/number/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/number/jsfmt.spec.js +++ b/tests/number/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/offsetlookup/jsfmt.spec.js b/tests/offsetlookup/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/offsetlookup/jsfmt.spec.js +++ b/tests/offsetlookup/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/package.json b/tests/package.json new file mode 100644 index 000000000..f80fdd058 --- /dev/null +++ b/tests/package.json @@ -0,0 +1,5 @@ +{ + "//": "Remove this file after we migrate to ESM.", + "description": "Make Node.js treat .js files in this directory as module", + "type": "module" +} \ No newline at end of file diff --git a/tests/parameter/jsfmt.spec.js b/tests/parameter/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/parameter/jsfmt.spec.js +++ b/tests/parameter/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/parens/jsfmt.spec.js b/tests/parens/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/parens/jsfmt.spec.js +++ b/tests/parens/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/preserve_line/jsfmt.spec.js b/tests/preserve_line/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/preserve_line/jsfmt.spec.js +++ b/tests/preserve_line/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/print/jsfmt.spec.js b/tests/print/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/print/jsfmt.spec.js +++ b/tests/print/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/program/jsfmt.spec.js b/tests/program/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/program/jsfmt.spec.js +++ b/tests/program/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/property/jsfmt.spec.js b/tests/property/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/property/jsfmt.spec.js +++ b/tests/property/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/propertylookup/jsfmt.spec.js b/tests/propertylookup/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/propertylookup/jsfmt.spec.js +++ b/tests/propertylookup/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/propertystatement/jsfmt.spec.js b/tests/propertystatement/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/propertystatement/jsfmt.spec.js +++ b/tests/propertystatement/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/require-pragma/jsfmt.spec.js b/tests/require-pragma/jsfmt.spec.js index cbd3dbfe7..78361cfff 100644 --- a/tests/require-pragma/jsfmt.spec.js +++ b/tests/require-pragma/jsfmt.spec.js @@ -1,3 +1,3 @@ -run_spec(__dirname, ["php"], { requirePragma: true, endOfLine: "cr" }); -run_spec(__dirname, ["php"], { requirePragma: true, endOfLine: "crlf" }); -run_spec(__dirname, ["php"], { requirePragma: true, endOfLine: "lf" }); +run_spec(import.meta, ["php"], { requirePragma: true, endOfLine: "cr" }); +run_spec(import.meta, ["php"], { requirePragma: true, endOfLine: "crlf" }); +run_spec(import.meta, ["php"], { requirePragma: true, endOfLine: "lf" }); diff --git a/tests/retif/jsfmt.spec.js b/tests/retif/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/retif/jsfmt.spec.js +++ b/tests/retif/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/return/jsfmt.spec.js b/tests/return/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/return/jsfmt.spec.js +++ b/tests/return/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/shebang/jsfmt.spec.js b/tests/shebang/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/shebang/jsfmt.spec.js +++ b/tests/shebang/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/silent/jsfmt.spec.js b/tests/silent/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/silent/jsfmt.spec.js +++ b/tests/silent/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/statement/jsfmt.spec.js b/tests/statement/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/statement/jsfmt.spec.js +++ b/tests/statement/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/static/jsfmt.spec.js b/tests/static/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/static/jsfmt.spec.js +++ b/tests/static/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/staticlookup/jsfmt.spec.js b/tests/staticlookup/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/staticlookup/jsfmt.spec.js +++ b/tests/staticlookup/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/string-double-quote/jsfmt.spec.js b/tests/string-double-quote/jsfmt.spec.js index 9b730dc4f..de5550203 100644 --- a/tests/string-double-quote/jsfmt.spec.js +++ b/tests/string-double-quote/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"], { singleQuote: false }); +run_spec(import.meta, ["php"], { singleQuote: false }); diff --git a/tests/string-single-quote/jsfmt.spec.js b/tests/string-single-quote/jsfmt.spec.js index 251ce04bb..cfd1c798f 100644 --- a/tests/string-single-quote/jsfmt.spec.js +++ b/tests/string-single-quote/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"], { singleQuote: true }); +run_spec(import.meta, ["php"], { singleQuote: true }); diff --git a/tests/string/jsfmt.spec.js b/tests/string/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/string/jsfmt.spec.js +++ b/tests/string/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/switch/jsfmt.spec.js b/tests/switch/jsfmt.spec.js index e395434ee..8829c872f 100644 --- a/tests/switch/jsfmt.spec.js +++ b/tests/switch/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["php"]); +run_spec(import.meta, ["php"]); diff --git a/tests/syntax-error/jsfmt.spec.js b/tests/syntax-error/jsfmt.spec.js index 11b12c317..b712c6c85 100644 --- a/tests/syntax-error/jsfmt.spec.js +++ b/tests/syntax-error/jsfmt.spec.js @@ -1,5 +1,5 @@ -const { prettier, plugin } = require("../../tests_config/get_engine"); -const stripAnsi = require("strip-ansi"); +import { prettier, plugin } from "../../tests_config/get_engine.js"; +import stripAnsi from "strip-ansi"; async function raiseSyntaxError() { await prettier.format(`"; const RANGE_START_PLACEHOLDER = "<<>>"; const RANGE_END_PLACEHOLDER = "<<>>"; -const { prettier, plugin } = require("./get_engine"); +global.run_spec = (importMeta, parsers, options) => { + const dirname = path.dirname(url.fileURLToPath(importMeta.url)); -global.run_spec = (dirname, parsers, options) => { options = Object.assign({}, options, { plugins: [plugin, ...((options && options.plugins) || [])], }); From 5ce5d5691b921bd19895af30c1fe4b29aea60998 Mon Sep 17 00:00:00 2001 From: fisker Date: Wed, 16 Aug 2023 16:57:27 +0800 Subject: [PATCH 2/2] final_new_line --- tests/package.json | 2 +- tests_config/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/package.json b/tests/package.json index f80fdd058..0038dff32 100644 --- a/tests/package.json +++ b/tests/package.json @@ -2,4 +2,4 @@ "//": "Remove this file after we migrate to ESM.", "description": "Make Node.js treat .js files in this directory as module", "type": "module" -} \ No newline at end of file +} diff --git a/tests_config/package.json b/tests_config/package.json index f80fdd058..0038dff32 100644 --- a/tests_config/package.json +++ b/tests_config/package.json @@ -2,4 +2,4 @@ "//": "Remove this file after we migrate to ESM.", "description": "Make Node.js treat .js files in this directory as module", "type": "module" -} \ No newline at end of file +}