Skip to content

Commit

Permalink
♻ Use more generic server address naming
Browse files Browse the repository at this point in the history
  • Loading branch information
wwilsman committed Mar 19, 2021
1 parent 834f6a5 commit 65c843a
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/cli-exec/src/commands/exec/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/percy.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default class Percy {
}

// Snapshot server API address
apiAddress() {
address() {
return `http://localhost:${this.port}`;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/core/test/percy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk-utils/index.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-utils/test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk-utils/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down

0 comments on commit 65c843a

Please sign in to comment.