forked from ionic-team/ionic-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstats.spec.js
More file actions
69 lines (51 loc) · 2.04 KB
/
stats.spec.js
File metadata and controls
69 lines (51 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
var Q = require('q'),
// IonicStats = require('../lib/ionic/stats').IonicStats,
IonicStatsModule,
IonicStats,
IonicConfig = require('../lib/ionic/config'),
path = require('path'),
rewire = require('rewire');
describe('Stats', function() {
beforeEach(function() {
IonicStatsModule = rewire('../lib/ionic/stats');
IonicStats = IonicStatsModule.IonicStats;
});
it('should have stats defined', function() {
expect(IonicStats).toBeDefined();
});
describe('#t', function() {
it('should not track if process.argv is less than 3', function() {
var oldprocessargv = process.argv;
process.argv = ['node', 'bin/ionic'];
spyOn(IonicStats, 'mp');
var configSpy = createSpyObj('ionicConfig', ['get']);
configSpy.get.andReturn(true);
IonicStatsModule.__set__('ionicConfig', configSpy);
IonicStats.t();
expect(configSpy.get).not.toHaveBeenCalled();
expect(IonicStats.mp).not.toHaveBeenCalled();
process.argv = oldprocessargv;
});
it('should not track stats if opted out', function() {
var configSpy = createSpyObj('ionicConfig', ['get']);
configSpy.get.andReturn(true);
spyOn(IonicStatsModule, 'getVersion').andReturn({version: '1.6.4'});
IonicStatsModule.__set__('ionicConfig', configSpy);
IonicStats.t();
expect(configSpy.get).toHaveBeenCalled();
});
it('should track the correct command', function() {
var oldprocessargv = process.argv;
process.argv = ['node', 'bin/ionic', 'start', 'foldername'];
var packageJson = { version: '1.6.4' };
spyOn(IonicStats, 'mp');
spyOn(IonicStatsModule, 'getVersion').andReturn(packageJson);
var configSpy = createSpyObj('ionicConfig', ['get']);
configSpy.get.andReturn(false);
IonicStatsModule.__set__('ionicConfig', configSpy);
IonicStats.t();
expect(IonicStats.mp).toHaveBeenCalledWith('start', { cli_version: packageJson.version, email: false, account_id: false });
process.argv = oldprocessargv;
});
});
});