pryv 2.4.7 → 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
 
@@ -382,45 +381,20 @@ describe('Connection', () => {
382
381
 
383
382
  if (typeof window === 'undefined') {
384
383
  describe('Browser mock', function () {
385
- const isNotAvailable = {
386
- URL: global.URL == null,
387
- URLSearchParams: global.URLSearchParams == null,
388
- fetch: global.fetch == null
389
- };
390
384
  beforeEach(function () {
391
- const browser = new Browser();
392
- browser.visit('./');
393
- global.document = browser.document;
394
- global.window = browser.window;
395
- global.location = browser.location;
396
- function fetch (...args) {
397
- return browser.fetch(...args);
398
- }
399
- if (isNotAvailable.fetch) global.fetch = fetch;
400
- if (isNotAvailable.URL) global.URL = URL;
401
- 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;
402
389
  });
403
390
 
404
391
  afterEach(function () {
405
392
  delete global.document;
406
393
  delete global.window;
407
394
  delete global.location;
408
- if (isNotAvailable.fetch) delete global.fetch;
409
- if (isNotAvailable.URL) delete global.URL;
410
- if (isNotAvailable.URLSearchParams) delete global.URLSearchParams;
411
- });
412
-
413
- it(' without fetch', async () => {
414
- delete global.fetch;
415
- const queryParams = { fromTime: 0, toTime: now, limit: 10000 };
416
- let eventsCount = 0;
417
- function forEachEvent (event) { eventsCount++; }
418
- const res = await conn.getEventsStreamed(queryParams, forEachEvent);
419
- expect(eventsCount).to.equal(res.eventsCount);
420
395
  });
421
396
 
422
- // HACK: skip until a solution is found to Zombie's `fetch()` not accepting URLs
423
- xit(' with fetch', async () => {
397
+ it(' with fetch', async () => {
424
398
  const queryParams = { fromTime: 0, toTime: now, limit: 10000 };
425
399
  let eventsCount = 0;
426
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 () {