Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
beforeEach(() => {
// Allow testing if we _really_ would send tracking requests
telemetry.track.and.callThrough();
telemetry.turnOn.and.callThrough();
telemetry.turnOff.and.callThrough();
spyOn(Insight.prototype, 'track').and.callThrough();
spyOn(Insight.prototype, '_save');
spyOnProperty(Insight.prototype, 'optOut', 'get')
.and.callFake(() => isOptedOut);
spyOnProperty(Insight.prototype, 'optOut', 'set')
.and.callFake(x => { isOptedOut = x; });
// Set a normal opted-in user as default
spyOn(telemetry, 'isCI').and.returnValue(false);
isOptedOut = false;
});
beforeEach(() => {
telemetry = rewire('../src/telemetry');
insight = telemetry.__get__('insight');
// Prevent any settings from being persisted during testing
insight.config = {
get (key) { return this[key]; },
set (key, val) { this[key] = val; }
};
for (const key in insight.config) {
spyOn(insight.config, key).and.callThrough();
}
// Prevent tracking anything during testing
spyOn(Insight.prototype, '_save');
// Prevent prompts during testing
spyOn(Insight.prototype, 'askPermission');
});
}
callback();
};
Insight.prototype._track = function() {
if (this._options['dry-run']) {
if(!stopTracking) {
this.track('dry-run');
stopTracking = true;
}
} else {
this.track.apply(this, arguments);
}
};
Insight.prototype.askPermissionAndTrack = function(options) {
this._options = options;
return when.promise(function(resolve) {
if (this.optOut === undefined) {
this.askPermission(null, function() {
this._initialTrack(resolve);
}.bind(this));
} else {
this._initialTrack(resolve);
}
}.bind(this));
};
module.exports = new Insight({
trackingCode: 'UA-65084890-1',
pkg: pkg
});
var stopTracking;
Insight.prototype._initialTrack = function(callback) {
if (!this.optOut) {
this._track(
'config',
this._options['non-interactive'] ? 'non-interactive' : 'interactive',
this._options.increment,
this._options.dist.repo ? 'distRepo' : 'no-distRepo',
this._options.npm.private ? 'private' : 'public'
);
}
callback();
};
Insight.prototype._track = function() {
if (this._options['dry-run']) {
if(!stopTracking) {
this.track('dry-run');
stopTracking = true;
}
} else {
this.track.apply(this, arguments);
}
};
Insight.prototype.askPermissionAndTrack = function(options) {
this._options = options;
return when.promise(function(resolve) {
if (this.optOut === undefined) {
this.askPermission(null, function() {
this._initialTrack(resolve);
var Insight = require('insight'),
when = require('when'),
pkg = require('../package.json');
var stopTracking;
Insight.prototype._initialTrack = function(callback) {
if (!this.optOut) {
this._track(
'config',
this._options['non-interactive'] ? 'non-interactive' : 'interactive',
this._options.increment,
this._options.dist.repo ? 'distRepo' : 'no-distRepo',
this._options.npm.private ? 'private' : 'public'
);
}
callback();
};
Insight.prototype._track = function() {
if (this._options['dry-run']) {
if(!stopTracking) {
this.track('dry-run');
return cli(['node', 'cordova', 'platform', 'add', 'ios']).then(() => {
expect(telemetry.track).toHaveBeenCalledWith('platform', 'add', 'successful');
expect(Insight.prototype.track).toHaveBeenCalled();
expect(Insight.prototype._save).toHaveBeenCalled();
});
});
beforeEach(() => {
spyOn(Insight.prototype, 'track');
});