forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.test.ts
More file actions
68 lines (56 loc) · 3 KB
/
helpers.test.ts
File metadata and controls
68 lines (56 loc) · 3 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
//
// Note: This example test is leveraging the Mocha test framework.
// Please refer to their documentation on https://mochajs.org/ for help.
//
// Place this right on top
import { initialize } from './../initialize';
// The module 'assert' provides assertion methods from node
import * as assert from 'assert';
// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import { createDeferred, isNotInstalledError } from '../../client/common/helpers';
// Defines a Mocha test suite to group tests of similar kind together
suite('Deferred', () => {
test('Resolve', done => {
const valueToSent = new Date().getTime();
const def = createDeferred<number>();
def.promise.then(value => {
assert.equal(value, valueToSent);
assert.equal(def.resolved, true, 'resolved property value is not `true`');
}).then(done).catch(done);
assert.equal(def.resolved, false, 'Promise is resolved even when it should not be');
assert.equal(def.rejected, false, 'Promise is rejected even when it should not be');
assert.equal(def.completed, false, 'Promise is completed even when it should not be');
def.resolve(valueToSent);
assert.equal(def.resolved, true, 'Promise is not resolved even when it should not be');
assert.equal(def.rejected, false, 'Promise is rejected even when it should not be');
assert.equal(def.completed, true, 'Promise is not completed even when it should not be');
});
test('Reject', done => {
const errorToSend = new Error('Something');
const def = createDeferred<number>();
def.promise.then(value => {
assert.fail(value, 'Error', 'Was expecting promise to get rejected, however it was resolved', '');
done();
}).catch(reason => {
assert.equal(reason, errorToSend, 'Error received is not the same');
done();
}).catch(done);
assert.equal(def.resolved, false, 'Promise is resolved even when it should not be');
assert.equal(def.rejected, false, 'Promise is rejected even when it should not be');
assert.equal(def.completed, false, 'Promise is completed even when it should not be');
def.reject(errorToSend);
assert.equal(def.resolved, false, 'Promise is resolved even when it should not be');
assert.equal(def.rejected, true, 'Promise is not rejected even when it should not be');
assert.equal(def.completed, true, 'Promise is not completed even when it should not be');
});
test('isNotInstalledError', done => {
const error = new Error('something is not installed');
assert.equal(isNotInstalledError(error), false, 'Standard error');
(error as any).code = 'ENOENT';
assert.equal(isNotInstalledError(error), true, 'ENOENT error code not detected');
(error as any).code = 127;
assert.equal(isNotInstalledError(error), true, '127 error code not detected');
done();
});
});