diff --git a/.github/workflows/prod-test.yml b/.github/workflows/prod-test.yml index 8e4a4b014..2c328da35 100644 --- a/.github/workflows/prod-test.yml +++ b/.github/workflows/prod-test.yml @@ -145,7 +145,7 @@ jobs: working-directory: dist/prettier run: node bin/prettier.cjs --debug-benchmark package.json 2>&1 >/dev/null | grep "Latency avg" || exit 1 - browser-test: + browser: timeout-minutes: 15 strategy: fail-fast: false @@ -191,8 +191,15 @@ jobs: name: dist path: dist - - name: Run Tests - run: yarn test:production-browser + - name: Run Tests (ESM) + env: + TEST_BUNDLE_FORMAT: esm + run: yarn test:production:browser + + - name: Run Tests (UMD) + env: + TEST_BUNDLE_FORMAT: umd + run: yarn test:production:browser cli: name: CLI diff --git a/package.json b/package.json index 7de727987..7808baec3 100644 --- a/package.json +++ b/package.json @@ -191,9 +191,11 @@ "test:production-node14": "cross-env NODE_ENV=production yarn test:node14", "test:production-standalone": "cross-env TEST_STANDALONE=1 yarn test:production", "test:production-standalone-node14": "cross-env TEST_STANDALONE=1 yarn test:production-node14", - "test:production-browser": "cross-env NODE_ENV=production TEST_RUNTIME=browser yarn test", - "test:production-browser:chrome": "cross-env TEST_RUNTIME_BROWSER=chrome yarn test:production-browser", - "test:production-browser:firefox": "cross-env TEST_RUNTIME_BROWSER=firefox yarn test:production-browser", + "test:production:browser": "cross-env TEST_RUNTIME=browser yarn test:production", + "test:production:browser:chrome": "cross-env TEST_RUNTIME_BROWSER=chrome yarn test:production:browser", + "test:production:browser:firefox": "cross-env TEST_RUNTIME_BROWSER=firefox yarn test:production:browser", + "test:production:browser:chrome:umd": "cross-env TEST_BUNDLE_FORMAT=umd yarn test:production:browser:chrome", + "test:production:browser:firefox:umd": "cross-env TEST_BUNDLE_FORMAT=umd yarn test:production:browser:firefox", "test:production-lint": "eslint dist --config=./scripts/production-eslint-config.js --quiet --format friendly", "perf": "yarn && yarn build && cross-env NODE_ENV=production node ./dist/prettier/bin/prettier.cjs", "perf:inspect": "yarn && yarn build && cross-env NODE_ENV=production node --inspect-brk ./dist/prettier/bin/prettier.cjs", diff --git a/src/standalone.js b/src/standalone.js index e5ed71f06..12401b443 100644 --- a/src/standalone.js +++ b/src/standalone.js @@ -6,7 +6,6 @@ function withPlugins( optionsArgumentIndex = 1, // Usually `options` is the 2nd argument ) { // Returns Promises to consistent with functions in `index.js` - // eslint-disable-next-line require-await return async (...args) => { const options = args[optionsArgumentIndex] ?? {}; const plugins = options.plugins ?? []; @@ -16,7 +15,7 @@ function withPlugins( plugins: Array.isArray(plugins) ? plugins : Object.values(plugins), }; - return fn(...args); + return await fn(...args); }; } diff --git a/tests/config/browser/get-browser-prettier.js b/tests/config/browser/get-browser-prettier.js index 85bf3a47e..141e8286f 100644 --- a/tests/config/browser/get-browser-prettier.js +++ b/tests/config/browser/get-browser-prettier.js @@ -3,7 +3,10 @@ import { startServer } from "./server.js"; import { requestFromNode } from "./utilities.js"; async function getBrowserPrettier() { + /** @type {"chrome" | "firefox"} */ const browserName = process.env.TEST_RUNTIME_BROWSER ?? "chrome"; + /** @type {"esm" | "umd"} */ + const prettierBundleFormat = process.env.TEST_BUNDLE_FORMAT ?? "esm"; const browser = await launchBrowser({ browser: browserName }); process.once("exit", async () => { @@ -16,14 +19,14 @@ async function getBrowserPrettier() { }); const page = await browser.newPage(); - await page.goto(server.url + "/esm.html"); + await page.goto(server.url); const proxyFunction = (accessPath, optionsIndex = 1) => requestFromNode( (...arguments_) => page.evaluate( - ([arguments_, accessPath]) => { - const prettier = globalThis.__prettier; + ([arguments_, accessPath, prettierBundleFormat]) => { + const prettier = globalThis[`__prettier_${prettierBundleFormat}`]; let function_ = prettier; for (const property of accessPath.split(".")) { function_ = function_[property]; @@ -31,7 +34,7 @@ async function getBrowserPrettier() { return function_(...arguments_); }, - [arguments_, accessPath], + [arguments_, accessPath, prettierBundleFormat], ), { browser: browserName, diff --git a/tests/config/browser/esm.html b/tests/config/browser/index.html similarity index 69% rename from tests/config/browser/esm.html rename to tests/config/browser/index.html index ad94d922d..506854947 100644 --- a/tests/config/browser/esm.html +++ b/tests/config/browser/index.html @@ -6,7 +6,10 @@
__prettier to debug in console.__prettier_esm or __prettier_umd to debug in
+ console.
+