Skip to content

Commit

Permalink
✨ Add core method to return local server address
Browse files Browse the repository at this point in the history
  • Loading branch information
wwilsman committed Sep 2, 2020
1 parent be12952 commit ccb80f9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/core/src/percy.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ export default class Percy {
return log.loglevel(level);
}

// Snapshot server API address
apiAddress() {
let { address } = this.server?.address() || {};
address = address?.includes(':') ? `[${address}]` : address;
return address && `http://${address}:${this.port}/percy`;
}

// Returns a boolean indicating if this instance is running.
isRunning() {
return this.#running;
Expand Down
11 changes: 11 additions & 0 deletions packages/core/test/percy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ describe('Percy', () => {
});
});

describe('#apiAddress()', () => {
it('returns undefined when the server is not running', () => {
expect(percy.apiAddress()).toBeUndefined();
});

it('returns the server API address when it is running', async () => {
await percy.start();
expect(percy.apiAddress()).toEqual('http://[::]:5338/percy');
});
});

describe('#start()', () => {
it('creates a build', async () => {
await expect(percy.start()).resolves.toBeUndefined();
Expand Down

0 comments on commit ccb80f9

Please sign in to comment.