pryv 2.4.6 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,8 +2,7 @@
2
2
  * @license
3
3
  * [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
4
4
  */
5
- /* global describe, it, before, after, expect, testData, Browser */
6
- /* eslint-disable no-unused-expressions */
5
+ /* global describe, it, before, after, expect, testData, JSDOM */
7
6
 
8
7
  const utils = require('../src/utils.js');
9
8
  const Service = require('../src/Service');
@@ -13,20 +12,21 @@ describe('Browser.LoginButton', function () {
13
12
  this.timeout(15000);
14
13
 
15
14
  let auth;
16
- let removeZombie = false;
15
+ let cleanupDom = false;
17
16
  before(async function () {
18
17
  if (typeof document !== 'undefined') return; // in browser
19
- removeZombie = true;
20
- const browser = new Browser();
21
- browser.visit('./?pryvServiceInfoUrl=https://zou.zou/service/info');
22
- global.document = browser.document;
23
- global.window = browser.window;
24
- global.location = browser.location;
18
+ cleanupDom = true;
19
+ const dom = new JSDOM('<!DOCTYPE html>', {
20
+ url: 'http://localhost/?pryvServiceInfoUrl=https://zou.zou/service/info'
21
+ });
22
+ global.document = dom.window.document;
23
+ global.window = dom.window;
24
+ global.location = dom.window.location;
25
25
  global.navigator = { userAgent: 'Safari' };
26
26
  });
27
27
 
28
28
  after(async function () {
29
- if (!removeZombie) return; // in browser
29
+ if (!cleanupDom) return; // in browser
30
30
  delete global.document;
31
31
  delete global.window;
32
32
  delete global.location;
@@ -2,8 +2,7 @@
2
2
  * @license
3
3
  * [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
4
4
  */
5
- /* global describe, it, before, after, expect, Browser, pryv, testData */
6
- /* eslint-disable no-unused-expressions */
5
+ /* global describe, it, before, after, expect, JSDOM, pryv, testData */
7
6
 
8
7
  function genSettings () {
9
8
  function defaultStateChange (state) {
@@ -26,21 +25,22 @@ describe('Browser', function () {
26
25
  await testData.prepare();
27
26
  });
28
27
 
29
- let removeZombie = false;
28
+ let cleanupDom = false;
30
29
 
31
30
  before(async () => {
32
31
  if (typeof document !== 'undefined') return; // in browser
33
- removeZombie = true;
34
- const browser = new Browser();
35
- browser.visit('./?pryvServiceInfoUrl=https://zou.zou/service/info');
36
- global.document = browser.document;
37
- global.window = browser.window;
38
- global.location = browser.location;
32
+ cleanupDom = true;
33
+ const dom = new JSDOM('<!DOCTYPE html>', {
34
+ url: 'http://localhost/?pryvServiceInfoUrl=https://zou.zou/service/info'
35
+ });
36
+ global.document = dom.window.document;
37
+ global.window = dom.window;
38
+ global.location = dom.window.location;
39
39
  global.navigator = { userAgent: 'Safari' };
40
40
  });
41
41
 
42
42
  after(async () => {
43
- if (!removeZombie) return; // in browser
43
+ if (!cleanupDom) return; // in browser
44
44
  delete global.document;
45
45
  delete global.window;
46
46
  delete global.location;
@@ -2,10 +2,9 @@
2
2
  * @license
3
3
  * [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
4
4
  */
5
- /* global describe, it, xit, before, after, beforeEach, afterEach, expect, Browser, pryv, Blob, FormData */
6
- /* eslint-disable no-unused-expressions */
5
+ /* global describe, it, before, after, beforeEach, afterEach, expect, JSDOM, pryv, Blob, FormData */
7
6
 
8
- const { URL, URLSearchParams } = require('universal-url');
7
+ // URL and URLSearchParams are native in Node.js and browsers
9
8
  const cuid = require('cuid');
10
9
  const testData = require('../../../test/test-data');
11
10
 
@@ -129,8 +128,9 @@ describe('Connection', () => {
129
128
  conn.options.chunkSize = 2;
130
129
 
131
130
  let resultsReceivedCount = 0;
132
- function oneMoreResult (res) {
131
+ function oneMoreResult (res, apiCall) {
133
132
  expect(res.events).to.exist;
133
+ expect(apiCall.method).to.equal('events.get');
134
134
  resultsReceivedCount++;
135
135
  }
136
136
 
@@ -381,45 +381,20 @@ describe('Connection', () => {
381
381
 
382
382
  if (typeof window === 'undefined') {
383
383
  describe('Browser mock', function () {
384
- const isNotAvailable = {
385
- URL: global.URL == null,
386
- URLSearchParams: global.URLSearchParams == null,
387
- fetch: global.fetch == null
388
- };
389
384
  beforeEach(function () {
390
- const browser = new Browser();
391
- browser.visit('./');
392
- global.document = browser.document;
393
- global.window = browser.window;
394
- global.location = browser.location;
395
- function fetch (...args) {
396
- return browser.fetch(...args);
397
- }
398
- if (isNotAvailable.fetch) global.fetch = fetch;
399
- if (isNotAvailable.URL) global.URL = URL;
400
- if (isNotAvailable.URLSearchParams) global.URLSearchParams = URLSearchParams;
385
+ const dom = new JSDOM('<!DOCTYPE html>', { url: 'http://localhost/' });
386
+ global.document = dom.window.document;
387
+ global.window = dom.window;
388
+ global.location = dom.window.location;
401
389
  });
402
390
 
403
391
  afterEach(function () {
404
392
  delete global.document;
405
393
  delete global.window;
406
394
  delete global.location;
407
- if (isNotAvailable.fetch) delete global.fetch;
408
- if (isNotAvailable.URL) delete global.URL;
409
- if (isNotAvailable.URLSearchParams) delete global.URLSearchParams;
410
- });
411
-
412
- it(' without fetch', async () => {
413
- delete global.fetch;
414
- const queryParams = { fromTime: 0, toTime: now, limit: 10000 };
415
- let eventsCount = 0;
416
- function forEachEvent (event) { eventsCount++; }
417
- const res = await conn.getEventsStreamed(queryParams, forEachEvent);
418
- expect(eventsCount).to.equal(res.eventsCount);
419
395
  });
420
396
 
421
- // HACK: skip until a solution is found to Zombie's `fetch()` not accepting URLs
422
- xit(' with fetch', async () => {
397
+ it(' with fetch', async () => {
423
398
  const queryParams = { fromTime: 0, toTime: now, limit: 10000 };
424
399
  let eventsCount = 0;
425
400
  function forEachEvent (event) { eventsCount++; }
@@ -3,9 +3,6 @@
3
3
  * [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
4
4
  */
5
5
  /* global describe, it, before, expect, pryv, testData */
6
- /* eslint-disable no-unused-expressions */
7
-
8
- const isNode = (typeof window === 'undefined');
9
6
 
10
7
  describe('Service', function () {
11
8
  before(async function () {
@@ -81,12 +78,13 @@ describe('Service', function () {
81
78
  try {
82
79
  await pryvService.login('wrong-username', 'bobby', 'jslib-test');
83
80
  } catch (error) {
84
- let errorMessage = isNode ? 'getaddrinfo ENOTFOUND wrong' : 'Request has been terminated';
85
- if (await pryvService.isDnsLess()) {
86
- errorMessage = 'Unknown user "wrong-username"';
81
+ const isDnsLess = await pryvService.isDnsLess();
82
+ if (isDnsLess) {
83
+ expect(error.message).to.include('Unknown user');
84
+ } else {
85
+ // fetch throws 'fetch failed'
86
+ expect(error.message).to.match(/Load failed|fetch failed|getaddrinfo ENOTFOUND|Request has been terminated/);
87
87
  }
88
- const receivedMessage = error.message.slice(0, errorMessage.length);
89
- expect(receivedMessage).to.be.equal(errorMessage);
90
88
  return;
91
89
  }
92
90
  throw new Error('Should fail');
@@ -2,10 +2,10 @@
2
2
  * @license
3
3
  * [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
4
4
  */
5
- /* global describe, it, before, after, expect, Browser, pryv, testData */
5
+ /* global describe, it, before, after, expect, JSDOM, pryv, testData */
6
6
 
7
7
  describe('ServiceAssets', function () {
8
- let removeZombie = false;
8
+ let cleanupDom = false;
9
9
 
10
10
  before(async function () {
11
11
  this.timeout(15000);
@@ -14,16 +14,15 @@ describe('ServiceAssets', function () {
14
14
 
15
15
  before(async () => {
16
16
  if (typeof document !== 'undefined') return; // in browser
17
- removeZombie = true;
18
- const browser = new Browser();
19
- browser.visit('./');
20
- global.document = browser.document;
21
- global.window = browser.window;
22
- global.location = browser.location;
17
+ cleanupDom = true;
18
+ const dom = new JSDOM('<!DOCTYPE html>', { url: 'http://localhost/' });
19
+ global.document = dom.window.document;
20
+ global.window = dom.window;
21
+ global.location = dom.window.location;
23
22
  });
24
23
 
25
24
  after(async () => {
26
- if (!removeZombie) return; // in browser
25
+ if (!cleanupDom) return; // in browser
27
26
  delete global.document;
28
27
  delete global.window;
29
28
  delete global.location;
@@ -3,7 +3,6 @@
3
3
  * [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
4
4
  */
5
5
  /* global describe, it, before, expect, pryv, testData */
6
- /* eslint-disable no-unused-expressions */
7
6
 
8
7
  describe('utils', function () {
9
8
  before(async function () {