|
1 |
| -var fs = require('fs'); |
2 |
| -var codecov = require("../lib/codecov"); |
3 |
| -var execSync = require('child_process').execSync; |
| 1 | +var fs = require('fs') |
| 2 | +var codecov = require('../lib/codecov') |
| 3 | +var execSync = require('child_process').execSync |
4 | 4 |
|
5 |
| -var isWindows = process.platform.match(/win32/) || process.platform.match(/win64/); |
6 |
| -var pathSeparator = !isWindows ? '/' : '\\'; |
| 5 | +var isWindows = |
| 6 | + process.platform.match(/win32/) || process.platform.match(/win64/) |
| 7 | +var pathSeparator = !isWindows ? '/' : '\\' |
7 | 8 |
|
8 |
| -describe("Codecov", function(){ |
9 |
| - beforeEach(function(){ |
| 9 | +describe('Codecov', function() { |
| 10 | + beforeEach(function() { |
10 | 11 | try {
|
11 |
| - fs.unlinkSync('.bowerrc'); |
| 12 | + fs.unlinkSync('.bowerrc') |
12 | 13 | } catch (e) {}
|
13 |
| - }); |
| 14 | + }) |
14 | 15 |
|
15 |
| - after(function(){ |
| 16 | + after(function() { |
16 | 17 | try {
|
17 |
| - fs.unlinkSync('.bowerrc'); |
| 18 | + fs.unlinkSync('.bowerrc') |
18 | 19 | } catch (e) {}
|
19 |
| - }); |
20 |
| - |
21 |
| - it("can get a token passed via env variable", function(){ |
22 |
| - this.timeout(10000); |
23 |
| - process.env.codecov_token = 'abc123'; |
24 |
| - expect(codecov.upload({options: {dump: true}}).query.token).to.eql('abc123'); |
25 |
| - delete process.env.codecov_token; |
26 |
| - process.env.CODECOV_TOKEN = 'ABC123'; |
27 |
| - expect(codecov.upload({options: {dump: true}}).query.token).to.eql('ABC123'); |
28 |
| - }); |
29 |
| - |
30 |
| - it("can get a token passed in cli", function(){ |
31 |
| - expect(codecov.upload({options: {dump: true, token: 'qwerty'}}).query.token).to.eql('qwerty'); |
32 |
| - }); |
33 |
| - |
34 |
| - it("can auto detect reports", function(){ |
35 |
| - var res = codecov.upload({options: {dump: true}}); |
36 |
| - expect(res.files[0].split(pathSeparator).pop()).to.eql('example.coverage.txt'); |
37 |
| - expect(res.body).to.contain('this file is intentionally left blank'); |
38 |
| - }); |
39 |
| - |
40 |
| - it("can specify report in cli", function(){ |
41 |
| - var res = codecov.upload({options: {dump: true, file: 'test' + pathSeparator + 'example.coverage.txt'}}); |
42 |
| - expect(res.files[0].split(pathSeparator).pop()).to.eql('example.coverage.txt'); |
43 |
| - expect(res.body).to.contain('this file is intentionally left blank'); |
44 |
| - }); |
45 |
| - |
46 |
| - it("can specify report in cli fail", function(){ |
47 |
| - var res = codecov.upload({options: {dump: true, file: 'notreal.txt'}}); |
48 |
| - expect(res.debug).to.contain('failed: notreal.txt'); |
49 |
| - }); |
| 20 | + }) |
| 21 | + |
| 22 | + it('can get a token passed via env variable', function() { |
| 23 | + this.timeout(10000) |
| 24 | + process.env.codecov_token = 'abc123' |
| 25 | + expect(codecov.upload({ options: { dump: true } }).query.token).to.eql( |
| 26 | + 'abc123' |
| 27 | + ) |
| 28 | + delete process.env.codecov_token |
| 29 | + process.env.CODECOV_TOKEN = 'ABC123' |
| 30 | + expect(codecov.upload({ options: { dump: true } }).query.token).to.eql( |
| 31 | + 'ABC123' |
| 32 | + ) |
| 33 | + }) |
| 34 | + |
| 35 | + it('can get a token passed in cli', function() { |
| 36 | + expect( |
| 37 | + codecov.upload({ options: { dump: true, token: 'qwerty' } }).query.token |
| 38 | + ).to.eql('qwerty') |
| 39 | + }) |
| 40 | + |
| 41 | + it('can auto detect reports', function() { |
| 42 | + var res = codecov.upload({ options: { dump: true } }) |
| 43 | + expect(res.files[0].split(pathSeparator).pop()).to.eql( |
| 44 | + 'example.coverage.txt' |
| 45 | + ) |
| 46 | + expect(res.body).to.contain('this file is intentionally left blank') |
| 47 | + }) |
| 48 | + |
| 49 | + it('can specify report in cli', function() { |
| 50 | + var res = codecov.upload({ |
| 51 | + options: { |
| 52 | + dump: true, |
| 53 | + file: 'test' + pathSeparator + 'example.coverage.txt' |
| 54 | + } |
| 55 | + }) |
| 56 | + expect(res.files[0].split(pathSeparator).pop()).to.eql( |
| 57 | + 'example.coverage.txt' |
| 58 | + ) |
| 59 | + expect(res.body).to.contain('this file is intentionally left blank') |
| 60 | + }) |
| 61 | + |
| 62 | + it('can specify report in cli fail', function() { |
| 63 | + var res = codecov.upload({ options: { dump: true, file: 'notreal.txt' } }) |
| 64 | + expect(res.debug).to.contain('failed: notreal.txt') |
| 65 | + }) |
50 | 66 |
|
51 | 67 | // it("can detect .bowerrc with directory", function(){
|
52 | 68 | // fs.writeFileSync('.bowerrc', '{"directory": "test"}');
|
53 | 69 | // var res = codecov.upload({options: {dump: true}});
|
54 | 70 | // expect(res.files).to.eql([]);
|
55 | 71 | // });
|
56 | 72 |
|
57 |
| - it("can detect .bowerrc without directory", function(){ |
58 |
| - fs.writeFileSync('.bowerrc', '{"key": "value"}'); |
59 |
| - var res = codecov.upload({options: {dump: true}}); |
60 |
| - expect(res.files[0].split(pathSeparator).pop()).to.eql('example.coverage.txt'); |
61 |
| - expect(res.body).to.contain('this file is intentionally left blank'); |
62 |
| - }); |
63 |
| - |
64 |
| - it("can disable search", function(){ |
65 |
| - var res = codecov.upload({options: {dump: true, disable: 'search'}}); |
66 |
| - expect(res.debug).to.contain('disabled search'); |
67 |
| - expect(res.files).to.eql([]); |
68 |
| - }); |
69 |
| - |
70 |
| - it("can disable gcov", function(){ |
71 |
| - var res = codecov.upload({options: {dump: true, disable: 'gcov'}}); |
72 |
| - console.log(res.debug); |
73 |
| - expect(res.debug).to.contain('disabled gcov'); |
74 |
| - }); |
75 |
| - |
76 |
| - it("can disable detection", function(){ |
77 |
| - var res = codecov.upload({options: {dump: true, disable: 'detect'}}); |
78 |
| - expect(res.debug).to.contain('disabled detect'); |
79 |
| - }); |
80 |
| - |
81 |
| - it("can get build from cli args", function(){ |
82 |
| - var res = codecov.upload({options: {dump: true, build: 'value'}}); |
83 |
| - expect(res.query.build).to.eql('value'); |
84 |
| - }); |
85 |
| - |
86 |
| - it("can get commit from cli args", function(){ |
87 |
| - var res = codecov.upload({options: {dump: true, commit: 'value'}}); |
88 |
| - expect(res.query.commit).to.eql('value'); |
89 |
| - }); |
90 |
| - |
91 |
| - it("can get branch from cli args", function(){ |
92 |
| - var res = codecov.upload({options: {dump: true, branch: 'value'}}); |
93 |
| - expect(res.query.branch).to.eql('value'); |
94 |
| - }); |
95 |
| - |
96 |
| - it("can get slug from cli args", function(){ |
97 |
| - var res = codecov.upload({options: {dump: true, slug: 'value'}}); |
98 |
| - expect(res.query.slug).to.eql('value'); |
99 |
| - }); |
100 |
| - |
101 |
| - it("can get flags from cli args", function(){ |
102 |
| - var res = codecov.upload({options: {dump: true, flags: 'value'}}); |
103 |
| - expect(res.query.flags).to.eql('value'); |
104 |
| - }); |
105 |
| - |
106 |
| - it("can include env in cli", function(){ |
107 |
| - process.env.HELLO = 'world'; |
108 |
| - var res = codecov.upload({options: {dump: true, env: 'HELLO,VAR1'}}); |
109 |
| - expect(res.body).to.contain('HELLO=world\n'); |
110 |
| - expect(res.body).to.contain('VAR1=\n'); |
111 |
| - }); |
112 |
| - |
113 |
| - it("can include env in env", function(){ |
114 |
| - process.env.HELLO = 'world'; |
115 |
| - process.env.CODECOV_ENV = 'HELLO,VAR1'; |
116 |
| - var res = codecov.upload({options: {dump: true, env: 'VAR2'}}); |
117 |
| - expect(res.body).to.contain('HELLO=world\n'); |
118 |
| - expect(res.body).to.contain('VAR1=\n'); |
119 |
| - expect(res.body).to.contain('VAR2=\n'); |
120 |
| - }); |
121 |
| - |
122 |
| - it("can have custom args for gcov", function(){ |
123 |
| - var res = codecov.upload({options: {dump: true, |
124 |
| - 'gcov-root': 'folder/path', |
125 |
| - 'gcov-glob': 'ignore/this/folder', |
126 |
| - 'gcov-exec': 'llvm-gcov', |
127 |
| - 'gcov-args': '-o'}}); |
128 |
| - if(!isWindows) { |
129 |
| - expect(res.debug).to.contain('find folder/path -type f -name \'*.gcno\' -not -path \'ignore/this/folder\' -exec llvm-gcov -o {} +'); |
| 73 | + it('can detect .bowerrc without directory', function() { |
| 74 | + fs.writeFileSync('.bowerrc', '{"key": "value"}') |
| 75 | + var res = codecov.upload({ options: { dump: true } }) |
| 76 | + expect(res.files[0].split(pathSeparator).pop()).to.eql( |
| 77 | + 'example.coverage.txt' |
| 78 | + ) |
| 79 | + expect(res.body).to.contain('this file is intentionally left blank') |
| 80 | + }) |
| 81 | + |
| 82 | + it('can disable search', function() { |
| 83 | + var res = codecov.upload({ options: { dump: true, disable: 'search' } }) |
| 84 | + expect(res.debug).to.contain('disabled search') |
| 85 | + expect(res.files).to.eql([]) |
| 86 | + }) |
| 87 | + |
| 88 | + it('can disable gcov', function() { |
| 89 | + var res = codecov.upload({ options: { dump: true, disable: 'gcov' } }) |
| 90 | + console.log(res.debug) |
| 91 | + expect(res.debug).to.contain('disabled gcov') |
| 92 | + }) |
| 93 | + |
| 94 | + it('can disable detection', function() { |
| 95 | + var res = codecov.upload({ options: { dump: true, disable: 'detect' } }) |
| 96 | + expect(res.debug).to.contain('disabled detect') |
| 97 | + }) |
| 98 | + |
| 99 | + it('can get build from cli args', function() { |
| 100 | + var res = codecov.upload({ options: { dump: true, build: 'value' } }) |
| 101 | + expect(res.query.build).to.eql('value') |
| 102 | + }) |
| 103 | + |
| 104 | + it('can get commit from cli args', function() { |
| 105 | + var res = codecov.upload({ options: { dump: true, commit: 'value' } }) |
| 106 | + expect(res.query.commit).to.eql('value') |
| 107 | + }) |
| 108 | + |
| 109 | + it('can get branch from cli args', function() { |
| 110 | + var res = codecov.upload({ options: { dump: true, branch: 'value' } }) |
| 111 | + expect(res.query.branch).to.eql('value') |
| 112 | + }) |
| 113 | + |
| 114 | + it('can get slug from cli args', function() { |
| 115 | + var res = codecov.upload({ options: { dump: true, slug: 'value' } }) |
| 116 | + expect(res.query.slug).to.eql('value') |
| 117 | + }) |
| 118 | + |
| 119 | + it('can get flags from cli args', function() { |
| 120 | + var res = codecov.upload({ options: { dump: true, flags: 'value' } }) |
| 121 | + expect(res.query.flags).to.eql('value') |
| 122 | + }) |
| 123 | + |
| 124 | + it('can include env in cli', function() { |
| 125 | + process.env.HELLO = 'world' |
| 126 | + var res = codecov.upload({ options: { dump: true, env: 'HELLO,VAR1' } }) |
| 127 | + expect(res.body).to.contain('HELLO=world\n') |
| 128 | + expect(res.body).to.contain('VAR1=\n') |
| 129 | + }) |
| 130 | + |
| 131 | + it('can include env in env', function() { |
| 132 | + process.env.HELLO = 'world' |
| 133 | + process.env.CODECOV_ENV = 'HELLO,VAR1' |
| 134 | + var res = codecov.upload({ options: { dump: true, env: 'VAR2' } }) |
| 135 | + expect(res.body).to.contain('HELLO=world\n') |
| 136 | + expect(res.body).to.contain('VAR1=\n') |
| 137 | + expect(res.body).to.contain('VAR2=\n') |
| 138 | + }) |
| 139 | + |
| 140 | + it('can have custom args for gcov', function() { |
| 141 | + var res = codecov.upload({ |
| 142 | + options: { |
| 143 | + dump: true, |
| 144 | + 'gcov-root': 'folder/path', |
| 145 | + 'gcov-glob': 'ignore/this/folder', |
| 146 | + 'gcov-exec': 'llvm-gcov', |
| 147 | + 'gcov-args': '-o' |
| 148 | + } |
| 149 | + }) |
| 150 | + if (!isWindows) { |
| 151 | + expect(res.debug).to.contain( |
| 152 | + "find folder/path -type f -name '*.gcno' -not -path 'ignore/this/folder' -exec llvm-gcov -o {} +" |
| 153 | + ) |
130 | 154 | } else {
|
131 |
| - expect(res.debug).to.contain('for /f "delims=" %g in (\'dir /a-d /b /s *.gcno ^| findstr /i /v ignore/this/folder\') do llvm-gcov -o %g'); |
| 155 | + expect(res.debug).to.contain( |
| 156 | + 'for /f "delims=" %g in (\'dir /a-d /b /s *.gcno ^| findstr /i /v ignore/this/folder\') do llvm-gcov -o %g' |
| 157 | + ) |
132 | 158 | }
|
133 |
| - }); |
| 159 | + }) |
134 | 160 |
|
135 | 161 | it('should have the correct version number', function() {
|
136 | 162 | var version = require('../package.json').version
|
137 | 163 | expect(codecov.version).to.eql('v' + version)
|
138 | 164 | })
|
139 |
| - |
140 |
| - |
141 |
| -}); |
| 165 | +}) |
0 commit comments