Skip to content

Commit

Permalink
Merge pull request #168 from angrykoala/dev
Browse files Browse the repository at this point in the history
0.9.1
  • Loading branch information
angrykoala authored Jul 4, 2018
2 parents afa5721 + aae7883 commit 3e43bb0
Show file tree
Hide file tree
Showing 23 changed files with 657 additions and 377 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
0.9.1 / 2018-07-04
==================

* Webworker module and assertions
* Bug with request mocks remove and override fixed
* Logo link fixed in readme

0.9.0 / 2018-06-24
==================

Expand Down
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Wendigo
<img src="logo/light.svg" align="right" width="150px">
<img src="https://user-images.githubusercontent.com/5960567/41823576-2f7cb71a-7802-11e8-8714-521cb38b42c0.png" align="right" width="150px">


_by @angrykoala_
Expand Down Expand Up @@ -44,6 +44,7 @@ await browser.assert.text("#my-modal", "Button Clicked");
* [Console](#console)
* [LocalStorage](#localstorage)
* [Requests](#requests)
* [Webworkers](#webworkers)
* [Errors](#errors)
* [Examples](#examples)
* [Development](#development)
Expand Down Expand Up @@ -631,6 +632,17 @@ await browser.assert.console({
});
```

**webworker(options, msg?)**
Assert that at least one webworker is running, the following options can be passes:
* `url`: Matches only the webworkers with given url
* `count`: Matches exactly the given number of webworkers running.

```js
await browser.assert.webworker({url: "foo.js"}); // At least one webworker with given url running
await browser.assert.webworker(); // at least one webworker running
await browser.assert.webworker({count: 0}); // No webworkers running
```

### Negative assertions
Most of the browser assertions have a negative version that can be used with `browser.assert.not`. Most of the "not" assertions are simply the inverse of the positive version.

Expand Down Expand Up @@ -1129,6 +1141,18 @@ await browser.assert.request.method("POST").url("localhost:8000/api");

> Negative assertions are not supported for requests
## Webworkers
The webworkers module allows to retrieve all the webworkers in the current page:

**all()**
Returns all the webworkers currently executing in the page. Each webworker will have the following properties:

* _url_: Returns the webworker file url
* _worker_: Returns the [Puppeteer's Worker instance](https://pptr.dev/#?product=Puppeteer&version=v1.5.0&show=api-class-worker)




## Errors
Wendigo errors can be accessed through `Wendigo.Errors`. These Errors will be thrown by Wendigo browser:

Expand Down
2 changes: 1 addition & 1 deletion lib/browser_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const path = require('path');
const ErrorFactory = require('./errors/error_factory');
const config = require('../config');
const DomElement = require('./dom_element');
const DomElement = require('./models/dom_element');

const injectionScriptsPath = config.injectionScripts.path;
const injectionScripts = config.injectionScripts.files;
Expand Down
2 changes: 1 addition & 1 deletion lib/mixins/browser_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"use strict";

const ErrorFactory = require('../errors/error_factory');
const DomElement = require('../dom_element');
const DomElement = require('../models/dom_element');
const utils = require('../utils');

module.exports = function BrowserActionsMixin(s) {
Expand Down
2 changes: 1 addition & 1 deletion lib/mixins/browser_queries.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

const DomElement = require('../dom_element');
const DomElement = require('../models/dom_element');
const ErrorFactory = require('../errors/error_factory');

module.exports = function BrowserQueriesMixin(s) {
Expand Down
File renamed without changes.
95 changes: 95 additions & 0 deletions lib/models/request_mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
"use strict";

const EventEmitter = require('events');
const URL = require('url').URL;

const ErrorFactory = require('../errors/error_factory');
const utils = require('../utils');


module.exports = class RequestMock {
constructor(url, options) {
this._setURL(url);
this._response = {
status: options.status,
headers: options.headers,
contentType: options.contentType,
body: this._processBody(options.body)
};
this.delay = options.delay || 0;
this.method = options.method;
if(options.queryString || typeof options.queryString === "string") this.queryString = utils.parseQueryString(options.queryString);
this._auto = options.auto !== false;
this._timesCalled = 0;
this._events = new EventEmitter();
}

get called() {
return this._timesCalled > 0;
}

get timesCalled() {
return this._timesCalled;
}

get response() {
return this._response;
}

get assert() {
return {
called: this._assertCalled.bind(this)
};
}

get immediate() {
return this.delay === 0;
}

get auto() {
return this._auto;
}

onTrigger(cb) {
this._events.once("respond", cb);
}

trigger() {
if(this.auto) throw ErrorFactory.generateFatalError(`Cannot trigger auto request mock.`);
this._events.emit("respond");
}

increaseCalled() {
this._timesCalled++;
}

_assertCalled(times, msg) {
if(typeof times === 'number') {
if(times !== this._timesCalled) {
if(!msg) msg = `Mock of ${this.url} not called ${times} times.`;
throw ErrorFactory.generateAssertionError(msg, this._timesCalled, times);
}
} else if(!this.called) {
if(!msg) msg = `Mock of ${this.url} not called.`;
throw ErrorFactory.generateAssertionError(msg);
}
}

_processBody(rawBody) {
if(typeof rawBody === "object") {
return JSON.stringify(rawBody);
} else return rawBody;
}

_setURL(url) {
if(url instanceof RegExp) {
this.url = url;
} else {
url = new URL(url);
this.url = `${url.origin}${url.pathname}`;
if(url.search) {
this.queryString = utils.parseQueryString(url);
}
}
}
};
11 changes: 11 additions & 0 deletions lib/models/webworker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use strict";

module.exports = class WebWoker {
constructor(ww) {
this.worker = ww;
}

get url() {
return this.worker.url();
}
};
25 changes: 25 additions & 0 deletions lib/modules/assertions/browser_assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,31 @@ module.exports = class BrowserAssertions extends BrowserModule {
}
/* eslint-enable complexity */

/* eslint-disable complexity */
webworker(options, msg) {
if(!options) options = {};
let workers = this._browser.webworkers.all();
let urlMsg = "";
if(options.url) {
urlMsg = ` with url "${options.url}"`;
workers = workers.filter((w) => {
return w.url === options.url;
});
}
if(options.count !== undefined) {
if(workers.length !== options.count) {
if(!msg) msg = `Expected ${options.count} webworkers running${urlMsg}, ${workers.length} found.`;
return assertUtils.rejectAssertion(msg);
}
} else {
if(workers.length === 0) {
if(!msg) msg = `Expected at least 1 webworker running${urlMsg}, 0 found.`;
return assertUtils.rejectAssertion(msg);
}
}
}
/* eslint-enable complexity */

};

/* eslint-enable max-lines */
17 changes: 17 additions & 0 deletions lib/modules/browser_webworkers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";

const BrowserModule = require('./browser_module');
const WebWorker = require('../models/webworker');

module.exports = class BrowserWebWorkers extends BrowserModule {
constructor(browser) {
super(browser);
}

all() {
return this._browser.page.workers().map((ww) => {
return new WebWorker(ww);
});
}

};
Loading

0 comments on commit 3e43bb0

Please sign in to comment.