Skip to content

Commit 18a09f5

Browse files
committed
feat(plugin): add plugin
1 parent 4c5c5ec commit 18a09f5

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

src/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import WebdriverIOClient from './webdriverio';
2+
3+
module.exports = (async () => {
4+
const client = new WebdriverIOClient();
5+
return client.setNgApimockCookie();
6+
})();

src/webdriverio.spec.ts

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import * as sinon from 'sinon';
2+
3+
import WebdriverIOClient from './webdriverio';
4+
5+
describe('WebdriverIOClient', () => {
6+
const BASE_URL = 'http://localhost:9000';
7+
let browserGetProcessedConfigThenFn: any;
8+
let browserSetCookieFn: sinon.SinonStub;
9+
let browserUrlFn: sinon.SinonStub;
10+
let client: WebdriverIOClient;
11+
let deferredPromise: any;
12+
let rejectFn: sinon.SinonStub;
13+
let resolveFn: sinon.SinonStub;
14+
15+
beforeAll(() => {
16+
browserGetProcessedConfigThenFn = sinon.stub();
17+
browserSetCookieFn = sinon.stub();
18+
browserUrlFn = sinon.stub();
19+
deferredPromise = {};
20+
21+
(global as any)['browser'] = {
22+
options: {
23+
baseUrl: BASE_URL
24+
},
25+
url: browserUrlFn,
26+
setCookie: browserSetCookieFn
27+
};
28+
29+
resolveFn = sinon.stub();
30+
rejectFn = sinon.stub();
31+
32+
client = new WebdriverIOClient();
33+
});
34+
35+
describe('constructor', () =>
36+
it('sets the baseUrl', () =>
37+
expect(client.baseUrl).toBe(BASE_URL + '/ngapimock')));
38+
39+
describe('openUrl', () =>
40+
it('opens the url', async () => {
41+
await client.openUrl('url');
42+
sinon.assert.calledWith(browserUrlFn, 'url');
43+
}));
44+
45+
describe('setCookie', () =>
46+
it('sets the cookie', async () => {
47+
await client.setCookie('name', 'value');
48+
sinon.assert.calledWith(browserSetCookieFn, {name: 'name', value: 'value'});
49+
}));
50+
});

src/webdriverio.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import BaseClient from '@ng-apimock/base-client';
2+
3+
/** Webdriver.io client for apimock. */
4+
class WebdriverIOClient extends BaseClient {
5+
/** Constructor.*/
6+
constructor() {
7+
super(browser.options.baseUrl);
8+
}
9+
10+
/** {@inheritDoc}. */
11+
async openUrl(url: string): Promise<any> {
12+
return await browser.url(url);
13+
}
14+
15+
/** {@inheritDoc}. */
16+
async setCookie(name: string, value: string): Promise<any> {
17+
return await browser.setCookie({name: name, value: value});
18+
}
19+
}
20+
21+
export default WebdriverIOClient;

0 commit comments

Comments
 (0)