UNPKG

2.66 kBJavaScriptView Raw
1var fs = require('fs')
2var codecov = require('../lib/codecov')
3var offlineErrors = require('../lib/offline')
4
5describe('Codecov', function() {
6 beforeEach(function() {
7 try {
8 fs.unlinkSync('report.tmp')
9 } catch (e) {}
10 })
11
12 afterAll(function() {
13 try {
14 fs.unlinkSync('report.tmp')
15 } catch (e) {}
16 })
17
18 it('can get upload to v2', function(done) {
19 var self = this
20 codecov.sendToCodecovV2(
21 'https://codecov.io',
22 {
23 token: 'f881216b-b5c0-4eb1-8f21-b51887d1d506',
24 commit: 'c739768fcac68144a3a6d82305b9c4106934d31a',
25 branch: 'master',
26 },
27 'testing node-' + codecov.version,
28 function(body) {
29 expect(body).toContain(
30 'https://codecov.io/github/codecov/ci-repo/commit/c739768fcac68144a3a6d82305b9c4106934d31a'
31 )
32 done()
33 },
34 function(errCode, errMsg) {
35 if (offlineErrors.indexOf(errCode) !== -1) {
36 self.skip() // offline - we can not test upload
37 return
38 }
39 throw new Error(errMsg)
40 }
41 )
42 })
43
44 it('can get upload to v3', function(done) {
45 var self = this
46 jest.setTimeout(10000) // give this test extra time to run (default is 2000ms)
47 codecov.sendToCodecovV3(
48 'https://codecov.io',
49 {
50 token: 'f881216b-b5c0-4eb1-8f21-b51887d1d506',
51 commit: 'c739768fcac68144a3a6d82305b9c4106934d31a',
52 branch: 'master',
53 },
54 'testing node-' + codecov.version,
55 function(body) {
56 expect(body).toContain(
57 'https://codecov.io/github/codecov/ci-repo/commit/c739768fcac68144a3a6d82305b9c4106934d31a'
58 )
59 done()
60 },
61 function(errCode, errMsg) {
62 if (offlineErrors.indexOf(errCode) !== -1) {
63 self.skip() // offline - we can not test upload
64 return
65 }
66 throw new Error(errMsg)
67 }
68 )
69 })
70
71 it("upload v2 doesn't throw runtime error", function(done) {
72 expect(
73 codecov.sendToCodecovV2.bind(
74 null,
75 'https://codecov.io',
76 {
77 token: 'f881216b-b5c0-4eb1-8f21-b51887d1d506',
78 commit: 'c739768fcac68144a3a6d82305b9c4106934d31a',
79 branch: 'master',
80 },
81 'testing node-' + codecov.version,
82 function(body) {
83 expect(body).toContain(
84 'https://codecov.io/github/codecov/ci-repo/commit/c739768fcac68144a3a6d82305b9c4106934d31a'
85 )
86 done()
87 },
88 function(errCode, errMsg) {
89 if (offlineErrors.indexOf(errCode) !== -1) {
90 done()
91 }
92 throw new Error(errMsg)
93 }
94 )
95 ).not.toThrow()
96 })
97})