From 65c843a4296a2bd3041ccd435e3c16c9a1862403 Mon Sep 17 00:00:00 2001 From: Wil Wilsman Date: Fri, 19 Mar 2021 00:41:16 -0500 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=20Use=20more=20generic=20server=20add?= =?UTF-8?q?ress=20naming?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/cli-exec/src/commands/exec/index.js | 2 +- packages/core/src/percy.js | 2 +- packages/core/test/percy.test.js | 4 ++-- packages/sdk-utils/README.md | 2 +- packages/sdk-utils/index.js | 6 +++--- packages/sdk-utils/test/helpers.js | 2 +- packages/sdk-utils/test/index.test.js | 6 +++--- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/cli-exec/src/commands/exec/index.js b/packages/cli-exec/src/commands/exec/index.js index ed4069be1..de2858561 100644 --- a/packages/cli-exec/src/commands/exec/index.js +++ b/packages/cli-exec/src/commands/exec/index.js @@ -73,7 +73,7 @@ export class Exec extends Command { // provide SDKs with useful env vars let env = { - PERCY_CLI_API: this.percy?.apiAddress(), + PERCY_SERVER_ADDRESS: this.percy?.address(), PERCY_LOGLEVEL: logger.loglevel(), ...process.env }; diff --git a/packages/core/src/percy.js b/packages/core/src/percy.js index df3e6d629..cdd054804 100644 --- a/packages/core/src/percy.js +++ b/packages/core/src/percy.js @@ -74,7 +74,7 @@ export default class Percy { } // Snapshot server API address - apiAddress() { + address() { return `http://localhost:${this.port}`; } diff --git a/packages/core/test/percy.test.js b/packages/core/test/percy.test.js index ad8a15a8d..0bbd73cd4 100644 --- a/packages/core/test/percy.test.js +++ b/packages/core/test/percy.test.js @@ -94,9 +94,9 @@ describe('Percy', () => { }); }); - describe('#apiAddress()', () => { + describe('#address()', () => { it('returns the server API address', async () => { - expect(percy.apiAddress()).toEqual('http://localhost:5338'); + expect(percy.address()).toEqual('http://localhost:5338'); }); }); diff --git a/packages/sdk-utils/README.md b/packages/sdk-utils/README.md index be05d1aaf..e028e54e6 100644 --- a/packages/sdk-utils/README.md +++ b/packages/sdk-utils/README.md @@ -27,7 +27,7 @@ const { cliApi, loglevel, version, config } = getInfo(); #### Returned properties -- `cliApi` — CLI API address (`process.env.PERCY_CLI_API || 'http://localhost:5338'`) +- `cliApi` — CLI API address (`process.env.PERCY_SERVER_ADDRESS || 'http://localhost:5338'`) - `loglevel` — CLI log level (`process.env.PERCY_LOGLEVEL || 'info'`) The following properties are only populated after [`isPercyEnabled`](#ispercyenabled) has been diff --git a/packages/sdk-utils/index.js b/packages/sdk-utils/index.js index 16ce366bf..ffaf0e64d 100644 --- a/packages/sdk-utils/index.js +++ b/packages/sdk-utils/index.js @@ -1,11 +1,11 @@ const logger = require('@percy/logger'); // Maybe get the CLI API address from the environment -const { PERCY_CLI_API = 'http://localhost:5338' } = process.env; +const { PERCY_SERVER_ADDRESS = 'http://localhost:5338' } = process.env; // Helper to send a request to the local CLI API function request(path, { body, ...options } = {}) { - let { protocol, hostname, port, pathname, search } = new URL(PERCY_CLI_API + path); + let { protocol, hostname, port, pathname, search } = new URL(PERCY_SERVER_ADDRESS + path); options = { ...options, protocol, hostname, port, path: pathname + search }; return new Promise((resolve, reject) => { @@ -41,7 +41,7 @@ function request(path, { body, ...options } = {}) { // Returns CLI information function getInfo() { return { - cliApi: PERCY_CLI_API, + cliApi: PERCY_SERVER_ADDRESS, loglevel: logger.loglevel(), version: getInfo.version, config: getInfo.config diff --git a/packages/sdk-utils/test/helpers.js b/packages/sdk-utils/test/helpers.js index 3dfb2ec5f..9ab63a745 100644 --- a/packages/sdk-utils/test/helpers.js +++ b/packages/sdk-utils/test/helpers.js @@ -21,7 +21,7 @@ sdk.setup = async function setup() { }, 5338); // reset things - delete process.env.PERCY_CLI_API; + delete process.env.PERCY_SERVER_ADDRESS; delete process.env.PERCY_LOGLEVEL; sdk.serializeDOM = serializeDOM; logger.mock(); diff --git a/packages/sdk-utils/test/index.test.js b/packages/sdk-utils/test/index.test.js index eb035662b..641bd7b2d 100644 --- a/packages/sdk-utils/test/index.test.js +++ b/packages/sdk-utils/test/index.test.js @@ -10,13 +10,13 @@ describe('SDK Utils', () => { }); describe('getInfo()', () => { - it('returns the CLI API address as defined by PERCY_CLI_API', () => { - expect(process.env.PERCY_CLI_API).toBeUndefined(); + it('returns the CLI API address as defined by PERCY_SERVER_ADDRESS', () => { + expect(process.env.PERCY_SERVER_ADDRESS).toBeUndefined(); expect(sdk.rerequire('..').getInfo()) .toHaveProperty('cliApi', 'http://localhost:5338'); delete require.cache[require.resolve('..')]; - process.env.PERCY_CLI_API = 'http://localhost:1234'; + process.env.PERCY_SERVER_ADDRESS = 'http://localhost:1234'; expect(sdk.rerequire('..').getInfo()) .toHaveProperty('cliApi', 'http://localhost:1234'); });