particle-api-js 9.1.1 → 9.3.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.
package/package.json CHANGED
@@ -1,17 +1,19 @@
1
1
  {
2
2
  "name": "particle-api-js",
3
- "version": "9.1.1",
3
+ "version": "9.3.0",
4
4
  "description": "Particle API Client",
5
5
  "main": "lib/Particle.js",
6
6
  "scripts": {
7
7
  "babel-watch": "babel src -d lib --watch --source-maps",
8
8
  "prepublish": "npm run lint && npm run compile",
9
9
  "compile": "babel src -sd lib",
10
- "test": "npm run lint && npm run test:node",
11
- "test:node": "mocha test/ -R spec --compilers js:babel-register",
10
+ "test": "npm run lint && npm run test:unit",
11
+ "test:ci": "npm run lint && npm run test:unit -- --forbid-only && npm run coverage",
12
+ "test:unit": "mocha test/ -R spec --compilers js:babel-register",
13
+ "test:unit:silent": "npm run test:unit > tmp/test-unit-log.txt 2>&1",
12
14
  "test:browser": "karma start --single-run",
13
- "test:watch": "npm run test:node -- --watch",
14
- "cover": "istanbul cover ./node_modules/.bin/_mocha test/ -- -R spec --compilers js:babel-register",
15
+ "test:watch": "npm run test:unit -- --watch",
16
+ "coverage": "nyc --reporter=text --include='src/**/*.js' --temp-dir=./tmp/ --check-coverage --lines 50 npm run test:unit:silent",
15
17
  "lint": "eslint . --ext .js --format unix --ignore-path .gitignore --ignore-pattern \"dist/*\"",
16
18
  "lint:fix": "npm run lint -- --fix",
17
19
  "docs": "documentation build src/Particle.js --shallow -g -f md -o docs/api.md",
@@ -58,7 +60,6 @@
58
60
  "documentation": "^4.0.0-rc.1",
59
61
  "eslint": "^5.16.0",
60
62
  "eslint-config-particle": "^2.2.1",
61
- "istanbul": "1.0.0-alpha.2",
62
63
  "karma": "^1.1.1",
63
64
  "karma-browserify": "^5.1.0",
64
65
  "karma-chai": "^0.1.0",
@@ -68,6 +69,7 @@
68
69
  "karma-mocha": "^1.1.1",
69
70
  "minifyify": "^7.3.1",
70
71
  "mocha": "^2.5.1",
72
+ "nyc": "^15.1.0",
71
73
  "should": "^9.0.0",
72
74
  "sinon": "^7.2.5",
73
75
  "sinon-as-promised": "^4.0.3",
@@ -84,5 +86,9 @@
84
86
  "browser": {
85
87
  "http": "stream-http",
86
88
  "https": "stream-http"
89
+ },
90
+ "engines": {
91
+ "node": ">=12.x",
92
+ "npm": "8.x"
87
93
  }
88
94
  }
@@ -1,8 +1,30 @@
1
1
  import { sinon, expect } from './test-setup';
2
2
  import Agent from '../src/Agent.js';
3
3
 
4
-
5
4
  describe('Agent', () => {
5
+ beforeEach(() => {
6
+ sinon.restore();
7
+ });
8
+
9
+ describe('constructor', () => {
10
+ it('calls setBaseUrl', () => {
11
+ const baseUrl = 'https://foo.com';
12
+ sinon.stub(Agent.prototype, 'setBaseUrl');
13
+ const agent = new Agent(baseUrl);
14
+ expect(agent.setBaseUrl).to.have.property('callCount', 1);
15
+ expect(agent.setBaseUrl.firstCall.args).to.have.lengthOf(1);
16
+ expect(agent.setBaseUrl.firstCall.args[0]).to.eql(baseUrl);
17
+ });
18
+
19
+ it('creates a prefix function instance property from the supplied baseUrl (via setBaseUrl)', () => {
20
+ const agent = new Agent();
21
+ expect(agent.prefix).to.be.a('Function');
22
+ // Note: validating specific .prefix function behavior seems hard without proxyquire
23
+ // and this test seems sufficient
24
+ // and redundant with the 'build request uses prefix if provided' test below
25
+ });
26
+ });
27
+
6
28
  describe('sanitize files', () => {
7
29
  it('can call sanitize will falsy value', () => {
8
30
  const agent = new Agent();
@@ -56,8 +56,8 @@ describe('Client', () => {
56
56
 
57
57
  describe('downloadFile', () => {
58
58
  it('delegates to api', () => {
59
- api.downloadFile = () => Promise.resolve('delegated');
60
- return expect(client.downloadFile('url')).to.eventually.equal('delegated');
59
+ api.downloadFile = ({ uri }) => Promise.resolve(`${uri} delegated`);
60
+ return expect(client.downloadFile('uri')).to.eventually.equal('uri delegated');
61
61
  });
62
62
  });
63
63
 
@@ -29,6 +29,7 @@ particle.getEventStream({ deviceId: 'mine', auth })
29
29
  })
30
30
  .catch((err) => {
31
31
  console.error(err);
32
+ process.exit(1);
32
33
  });
33
34
  /* eslint-enable no-console */
34
35
 
@@ -2701,4 +2701,19 @@ describe('ParticleAPI', () => {
2701
2701
  });
2702
2702
  });
2703
2703
  });
2704
+
2705
+ describe('setBaseUrl(baseUrl)', () => {
2706
+ afterEach(() => {
2707
+ sinon.restore();
2708
+ });
2709
+
2710
+ it('calls agent.setBaseUrl', () => {
2711
+ const baseUrl = 'foo';
2712
+ sinon.stub(api.agent, 'setBaseUrl');
2713
+ api.setBaseUrl(baseUrl);
2714
+ expect(api.agent.setBaseUrl).to.have.property('callCount', 1);
2715
+ expect(api.agent.setBaseUrl.firstCall.args).to.have.lengthOf(1);
2716
+ expect(api.agent.setBaseUrl.firstCall.args[0]).to.eql(baseUrl);
2717
+ });
2718
+ });
2704
2719
  });
package/.travis.yml DELETED
@@ -1,34 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - 6
4
- - 8
5
- - 10
6
- cache:
7
- directories:
8
- - node_modules
9
- sudo: false
10
- services:
11
- - xvfb
12
- install:
13
- - npm -g install npm@5.10
14
- - npm install
15
- - npm prune
16
- script: "./travis_tests.sh"
17
- after_success:
18
- - npm run coveralls
19
- jobs:
20
- include:
21
- - node_js: 8
22
- env: TEST_SUITE=browser
23
- - stage: npm release
24
- script: echo "Publishing to npm..."
25
- node_js: 8
26
- if: tag =~ ^v\d+\.\d+\.\d+$
27
- deploy:
28
- provider: npm
29
- email: engineering+npm@particle.io
30
- api_key:
31
- secure: JzhJNTYb5bZmETc+MN7ivqeXTSUPMJ+ImGtiSXMFPNGnZc8PSwp82Q9Yx+cvno/8sSGaisleIcWDJ/4d9Vq6fNVchftu2tjCIauRUaQUf07tvO2bXW9HWmTaYCpySmvHsZD+v3FFOPEyWwkHWBGO0pQnlWOlPeJrzrpyp006uoh7shefK147zKwwUmZKJC0/VDbGOyWXeDXe1C0AapwxFovTaINir4OROmPCrmUX0ZzWQqWn6edyYZHMDDLLrAIywqiuj1f7MU5M4y+0lILVm0SC79x7fIm6ZnIk+V1KxbNYN1zrKAFLkGSRpVXbNPUULT/jxVFn+ThcSNidQf3cI5kX6sXfQLN8ue7MfMAYCcL3JZ4W0LkrsYn4RqC5t8D4VATTqsNMUn+oUDzgDm8NL8hW+RaE9hLkXEGz9NjMpXie4JThcJt/To6NEGDMd0hvzBcvKTG34xgsitM1XBnOe6uk/L4lx058hRshnIxHkctyvVQ/dZfHrRfTz6CkfC3UhSaw7ufKxBCceDId/DM2WDL2eUyy+ruJTbWhjbJv/GUBhR69atYriEqGmRmZSiA5nvj2+vTT6yrD0RbHi/CqhiEMFcZf3DI+mIrjXjmbvdKdt0cDUHazxxGSmU3S0EV+Qdvbv1pZxU/049WAnJWiwxwXHdpl9T6jZLw2e8d/xYs=
32
- skip_cleanup: true
33
- on:
34
- tags: true
package/travis_tests.sh DELETED
@@ -1,11 +0,0 @@
1
- #!/bin/bash
2
- # Run different test suites on Travis depending on environment variables
3
- set -ev
4
- if [ "${TEST_SUITE}" = "browser" ]; then
5
- # Load display for browser tests
6
- export DISPLAY=:99.0
7
- npm run build
8
- npm run test:browser
9
- else
10
- npm run test
11
- fi