Skip to content

Commit 5911952

Browse files
committed
✅ Switch from JSHint to ESLint
1 parent 64ed4e8 commit 5911952

File tree

8 files changed

+194
-129
lines changed

8 files changed

+194
-129
lines changed

.eslintrc.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
root: true
2+
extends: 'semistandard'
3+
rules:
4+
indent:
5+
- error
6+
- 4
7+
camelcase: off
8+
padded-blocks: off
9+
operator-linebreak: off
10+
no-throw-literal: off

.jshintrc

-30
This file was deleted.

package.json

+15-3
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,22 @@
2828
"author": "Adobe PhoneGap Team",
2929
"license": "Apache-2.0",
3030
"scripts": {
31-
"test": "jasmine-node --color spec"
31+
"test": "npm run eslint && jasmine-node --color spec",
32+
"eslint": "node node_modules/eslint/bin/eslint www && node node_modules/eslint/bin/eslint src && node node_modules/eslint/bin/eslint tests"
3233
},
3334
"devDependencies": {
34-
"jasmine-node": "1.14.5",
35-
"pluginpub": "^0.0.6"
35+
"eslint-config-semistandard": "^11.0.0",
36+
"eslint-config-standard": "^10.2.1",
37+
"eslint-plugin-import": "^2.7.0",
38+
"eslint-plugin-node": "^5.1.1",
39+
"eslint-plugin-promise": "^3.5.0",
40+
"eslint-plugin-standard": "^3.0.1",
41+
"husky": "^0.10.1",
42+
"eslint": "^4.0.0",
43+
"jasmine-node": "^1.14.5",
44+
"pluginpub": "^0.0.8"
45+
},
46+
"dependencies": {
47+
"eslint": "^4.4.1"
3648
}
3749
}

spec/helper/cordova.js

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/* global cordova:true */
2+
3+
/*!
4+
* Module dependencies.
5+
*/
6+
7+
/**
8+
* cordova.js for node.
9+
*
10+
* Think of this as cordova-node, which would be simliar to cordova-android
11+
* or cordova-browser. The purpose of this module is to enable testing
12+
* of a plugin's JavaScript interface.
13+
*
14+
* When this module is first required, it will insert a global cordova
15+
* instance, which can hijack cordova-specific commands within the pluin's
16+
* implementation.
17+
*
18+
* Remember to require this module before the plugin that you want to test.
19+
*
20+
* Example:
21+
*
22+
* var cordova = require('./helper/cordova'),
23+
* myPlugin = require('../www/myPlugin');
24+
*/
25+
26+
module.exports = global.cordova = cordova = {
27+
28+
/**
29+
* cordova.require Mock.
30+
*
31+
* Hijacks all cordova.requires. By default, it returns an empty function.
32+
* You can define your own implementation of each required module before
33+
* or after it has been required.
34+
*
35+
* See `cordova.required` to learn how to add your own module implemtnation.
36+
*/
37+
38+
require: function(moduleId) {
39+
// define a default function if it doesn't exist
40+
if (!cordova.required[moduleId]) {
41+
cordova.required[moduleId] = function() {};
42+
}
43+
// create a new module mapping between the module Id and cordova.required.
44+
return new ModuleMap(moduleId);
45+
},
46+
47+
/**
48+
* Cordova module implementations.
49+
*
50+
* A key-value hash, where the key is the module such as 'cordova/exec'
51+
* and the value is the function or object returned.
52+
*
53+
* For example:
54+
*
55+
* var exec = require('cordova/exec');
56+
*
57+
* Will map to:
58+
*
59+
* cordova.required['cordova/exec'];
60+
*/
61+
62+
required: {
63+
// populated at runtime
64+
}
65+
};
66+
67+
/**
68+
* Module Mapper.
69+
*
70+
* Returns a function that when executed will lookup the implementation
71+
* in cordova.required[id].
72+
*
73+
* @param {String} moduleId is the module name/path, such as 'cordova/exec'
74+
* @return {Function}.
75+
*/
76+
77+
function ModuleMap(moduleId) {
78+
return function() {
79+
// lookup and execute the module's mock implementation, passing
80+
// in any parameters that were provided.
81+
return cordova.required[moduleId].apply(this, arguments);
82+
};
83+
}

tests/tests.js

+24-28
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,33 @@
1919
*
2020
*/
2121
/* jshint jasmine: true */
22-
/* global navigator, done */
23-
exports.defineAutoTests = function() {
22+
/* global navigator, describe, it, expect, fail */
23+
exports.defineAutoTests = function () {
2424

25-
describe('Plugin conforms to w3c specs', function() {
25+
describe('Plugin conforms to w3c specs', function () {
2626

27-
it("navigator.mediaDevices should exist", function() {
27+
it('navigator.mediaDevices should exist', function () {
2828
expect(navigator.mediaDevices).toBeDefined();
2929
expect(typeof navigator.mediaDevices).toBe('object');
3030
expect(navigator.mediaDevices.enumerateDevices).toBeDefined();
3131
expect(typeof navigator.mediaDevices.enumerateDevices).toBe('function');
3232
// does not return ondevicechnge as defined
33-
//expect(navigator.mediaDevices.ondevicechange).toBeDefined();
33+
// expect(navigator.mediaDevices.ondevicechange).toBeDefined();
3434
expect(navigator.mediaDevices.getSupportedConstraints).toBeDefined();
3535
expect(typeof navigator.mediaDevices.getSupportedConstraints).toBe('function');
3636
expect(navigator.mediaDevices.getUserMedia).toBeDefined();
3737
expect(typeof navigator.mediaDevices.getUserMedia).toBe('function');
3838

3939
});
4040

41-
it('enumerateDevices should return a promise with attributes', function(done) {
41+
it('enumerateDevices should return a promise with attributes', function (done) {
4242
try {
4343
var promise = navigator.mediaDevices.enumerateDevices();
4444
expect(typeof promise.then).toBe('function');
45-
promise.then(function(info) {
45+
promise.then(function (info) {
4646
expect(info).toBeDefined();
4747
expect(typeof info).toBe('object');
48-
info.forEach(function(device) {
48+
info.forEach(function (device) {
4949
expect(device.deviceId).toBeDefined();
5050
expect(device.kind).toBeDefined();
5151
expect(device.label).toBeDefined();
@@ -56,7 +56,7 @@ exports.defineAutoTests = function() {
5656
expect(typeof device.groupId).toBe('string');
5757
});
5858
done();
59-
}, function(err) {
59+
}, function (err) {
6060
expect(err).toBeDefined();
6161
fail(err);
6262
done();
@@ -68,7 +68,7 @@ exports.defineAutoTests = function() {
6868

6969
});
7070

71-
it('getSupportedConstraints should return a promise with attributes', function() {
71+
it('getSupportedConstraints should return a promise with attributes', function () {
7272

7373
var support = navigator.mediaDevices.getSupportedConstraints();
7474
expect(support.width).toBeDefined();
@@ -100,14 +100,14 @@ exports.defineAutoTests = function() {
100100

101101
});
102102

103-
it('getUserMedia should return a promise with attributes', function(done) {
103+
it('getUserMedia should return a promise with attributes', function (done) {
104104
try {
105105
var constraints = {
106106
video: true
107107
};
108108
var promise = navigator.mediaDevices.getUserMedia(constraints);
109109
expect(typeof promise.then).toBe('function');
110-
promise.then(function(media) {
110+
promise.then(function (media) {
111111
expect(media).toBeDefined();
112112
expect(typeof media).toBe('object');
113113
// media.getworks with android studio
@@ -150,7 +150,7 @@ exports.defineAutoTests = function() {
150150
// expect(videoTracks[0].getCapabilities).toBeDefined();
151151
// expect(videoTracks[0].getConstraints).toBeDefined();
152152
// expect(videoTracks[0].getSettings).toBeDefined();
153-
//expect(videoTracks[0].applyConstraints).toBeDefined();
153+
// expect(videoTracks[0].applyConstraints).toBeDefined();
154154

155155
var audioTracks = media.getAudioTracks();
156156
expect(audioTracks[0].label).toBeDefined();
@@ -164,23 +164,19 @@ exports.defineAutoTests = function() {
164164
expect(audioTracks[0].onended).toBeDefined();
165165
// expect(audioTracks[0].stop).toBeDefined();
166166

167-
var tracks = media.getTracks();
168-
expect(tracks[0].label).toBeDefined();
169-
expect(tracks[0].kind).toBeDefined();
170-
expect(tracks[0].id).toBeDefined();
171-
expect(tracks[0].enabled).toBeDefined();
172-
expect(tracks[0].muted).toBeDefined();
173-
expect(tracks[0].onmute).toBeDefined();
174-
expect(tracks[0].onunmute).toBeDefined();
175-
expect(tracks[0].readyState).toBeDefined();
176-
expect(tracks[0].onended).toBeDefined();
167+
var tracks2 = media.getTracks();
168+
expect(tracks2[0].label).toBeDefined();
169+
expect(tracks2[0].kind).toBeDefined();
170+
expect(tracks2[0].id).toBeDefined();
171+
expect(tracks2[0].enabled).toBeDefined();
172+
expect(tracks2[0].muted).toBeDefined();
173+
expect(tracks2[0].onmute).toBeDefined();
174+
expect(tracks2[0].onunmute).toBeDefined();
175+
expect(tracks2[0].readyState).toBeDefined();
176+
expect(tracks2[0].onended).toBeDefined();
177177
// expect(tracks[0].stop).toBeDefined();
178-
179-
180-
181-
182178
done();
183-
}, function(err) {
179+
}, function (err) {
184180
expect(err).toBeDefined();
185181
fail(err);
186182
done();

www/android/MediaDevices.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,33 @@
2121
*/
2222
/* globals window, navigator, cordova, Promise */
2323

24-
var exec = cordova.require('cordova/exec'),
25-
utils = cordova.require('cordova/utils');
24+
var exec = cordova.require('cordova/exec');
2625

2726
var mediaDevices = {
2827
nativeMediaDevices: navigator.mediaDevices
2928
};
3029

31-
mediaDevices.getSupportedConstraints = function() {
30+
mediaDevices.getSupportedConstraints = function () {
3231
return this.nativeMediaDevices.getSupportedConstraints();
3332
};
3433

35-
mediaDevices.enumerateDevices = function() {
34+
mediaDevices.enumerateDevices = function () {
3635
return this.nativeMediaDevices.enumerateDevices();
3736
};
3837

39-
mediaDevices.getUserMedia = function(constraints) {
38+
mediaDevices.getUserMedia = function (constraints) {
4039
var mediaDevice = this.nativeMediaDevices;
4140

42-
return new Promise(function(resolve, reject) {
43-
var success = function() {
41+
return new Promise(function (resolve, reject) {
42+
var success = function () {
4443
mediaDevice.getUserMedia(constraints)
45-
.then(function(stream) {
44+
.then(function (stream) {
4645
resolve(stream);
47-
}).catch(function(error) {
46+
}).catch(function (error) {
4847
reject(error);
4948
});
5049
};
51-
var fail = function(error) {
50+
var fail = function (error) {
5251
reject(error);
5352
};
5453
exec(success, fail, 'MediaStreams', 'getUserMedia', [constraints]);

www/mediadevices.js

+11-14
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919
*
2020
*/
2121
/* globals Promise, cordova, MediaStream */
22-
var exec = cordova.require('cordova/exec'),
23-
utils = cordova.require('cordova/utils'),
24-
flagConstraints = true,
25-
flagDevices = true;
22+
var exec = cordova.require('cordova/exec');
23+
var flagConstraints = true;
24+
var flagDevices = true;
2625

2726
var mediaDevices = {
2827
_devices: null
@@ -44,8 +43,8 @@ var supportedConstraints = {
4443
'groupId': true
4544
};
4645

47-
mediaDevices.getSupportedConstraints = function() {
48-
var success = function(constraints) {
46+
mediaDevices.getSupportedConstraints = function () {
47+
var success = function (constraints) {
4948
console.log('constraints: ' + JSON.stringify(constraints));
5049
supportedConstraints = constraints;
5150
};
@@ -59,10 +58,10 @@ mediaDevices.getSupportedConstraints = function() {
5958
return supportedConstraints;
6059
};
6160

62-
mediaDevices.enumerateDevices = function() {
61+
mediaDevices.enumerateDevices = function () {
6362
var that = this;
64-
return new Promise(function(resolve, reject) {
65-
var success = function(device) {
63+
return new Promise(function (resolve, reject) {
64+
var success = function (device) {
6665
flagDevices = false;
6766
console.log('success ' + device.devices);
6867
that._devices = device.devices;
@@ -77,10 +76,9 @@ mediaDevices.enumerateDevices = function() {
7776
});
7877
};
7978

80-
81-
mediaDevices.getUserMedia = function(constraints) {
82-
return new Promise(function(resolve, reject) {
83-
var success = function(getMediaTracks) {
79+
mediaDevices.getUserMedia = function (constraints) {
80+
return new Promise(function (resolve, reject) {
81+
var success = function (getMediaTracks) {
8482
console.log('mediatrack' + getMediaTracks);
8583
var stream = new MediaStream(getMediaTracks);
8684
resolve(stream);
@@ -90,5 +88,4 @@ mediaDevices.getUserMedia = function(constraints) {
9088
});
9189
};
9290

93-
9491
module.exports = mediaDevices;

0 commit comments

Comments
 (0)