-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.ts
86 lines (73 loc) · 2.91 KB
/
tests.ts
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import * as path from 'path';
import * as rimraf from 'rimraf';
import { expect } from 'chai';
import Wrapper, { events } from './index';
const os = require('os');
const binTarget = path.join(__dirname, 'bin');
const platform = os.platform();
let wrapperInstance;
const source = (version) => `https://dist.ipfs.io/fs-repo-migrations/v${version}/fs-repo-migrations_v${version}_${platform}-amd64.tar.gz`;
describe('Wrapper', function () {
this.timeout(90000);
before(function () {
wrapperInstance = new Wrapper().src(source('1.4.0'), platform, 'x64')
.dest(binTarget).use('fs-repo-migrations');
});
beforeEach(function (done) {
wrapperInstance.downloadProgress.removeAllListeners(events.DOWNLOAD_PROGRESS);
rimraf(binTarget, function () {
done();
});
});
it('should emit DOWNLOAD_PROGRESS', function (done) {
wrapperInstance.downloadProgress.on(events.DOWNLOAD_PROGRESS, (stats) => {
expect(stats).to.have.property('total');
expect(stats).to.have.property('completed');
expect(stats).to.have.property('resource');
if (stats.total === stats.completed) {
done();
}
});
wrapperInstance.run(['-v'], function (err) {
expect(err).to.not.exist;
});
});
it('should emit DOWNLOAD_STARTED', function (done) {
let downloadTriggered = false;
wrapperInstance.downloadProgress.once(events.DOWNLOAD_STARTED, () => {
downloadTriggered = true;
});
wrapperInstance.downloadProgress.on(events.DOWNLOAD_PROGRESS, (stats) => {
expect(downloadTriggered).to.be.true;
expect(stats).to.have.property('total');
expect(stats).to.have.property('completed');
expect(stats).to.have.property('resource');
if (stats.total === stats.completed) {
done();
}
});
wrapperInstance.run(['-v'], function (err) {
expect(err).to.not.exist;
});
});
it('should throw error when platform is not supported', function (done) {
wrapperInstance = new Wrapper().src(source('1.4.0'), 'win32', 'x64')
.dest(binTarget).use('fs-repo-migrations/fs-repo-migrations');
wrapperInstance.run(['-v'], function (err) {
expect(err).to.exist;
done();
});
})
it('should throw error when source doest not exist', function (done) {
wrapperInstance = new Wrapper().src(source('1.4.0') + '1231', 'win32', 'x64')
.dest(binTarget).use('fs-repo-migrations/fs-repo-migrations');
wrapperInstance.run(['-v'], function (err) {
expect(err).to.exist;
done();
});
wrapperInstance.downloadProgress.once(events.DOWNLOAD_ERROR, (err) => {
console.log(err);
expect(err).to.exist;
});
})
});