-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstackAnalysisModule.test.ts
106 lines (98 loc) · 3.3 KB
/
stackAnalysisModule.test.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import * as chai from 'chai';
import * as sinon from 'sinon';
import * as sinonChai from 'sinon-chai';
import * as vscode from 'vscode';
import { context } from './vscontext.mock';
import { stackanalysismodule } from '../src/stackanalysismodule';
import { ProjectDataProvider } from '../src/ProjectDataProvider';
import { multimanifestmodule } from '../src/multimanifestmodule';
import { stackAnalysisServices } from '../src/stackAnalysisService';
const expect = chai.expect;
chai.use(sinonChai);
suite('stackanalysis module', () => {
let sandbox: sinon.SinonSandbox;
let editor = {
document: {
uri: {
fsPath: '/Users/sampleNodeRepo/package.json',
path: '/Users/sampleNodeRepo/package.json',
scheme: 'file'
},
fileName: '/Users/sampleNodeRepo/package.json'
}
};
setup(() => {
sandbox = sinon.createSandbox();
});
teardown(() => {
sandbox.restore();
});
suite('stacknalysis module:', () => {
let workspaceFolder = vscode.workspace.workspaceFolders[0];
test('processStackAnalyses should call stackAnalysesLifeCycle for npm', async () => {
let spyStackAnalysesLifeCycle = sandbox.spy(
stackanalysismodule,
'stackAnalysesLifeCycle'
);
await stackanalysismodule.processStackAnalyses(
context,
workspaceFolder,
'npm'
);
expect(spyStackAnalysesLifeCycle).callCount(1);
});
test('processStackAnalyses should call stackAnalysesLifeCycle for maven', async () => {
let spyStackAnalysesLifeCycle = sandbox.spy(
stackanalysismodule,
'stackAnalysesLifeCycle'
);
await stackanalysismodule.processStackAnalyses(
context,
workspaceFolder,
'maven'
);
expect(spyStackAnalysesLifeCycle).callCount(1);
});
test('stackAnalysesLifeCycle should call chain of promises', async () => {
let stubEffectivef8Package = sandbox
.stub(ProjectDataProvider, 'effectivef8Package')
.resolves('target/npmlist.json');
let stubTriggerManifestWs = sandbox
.stub(multimanifestmodule, 'triggerManifestWs')
.resolves(true);
let stubFormManifestPayload = sandbox
.stub(multimanifestmodule, 'form_manifests_payload')
.resolves({ orgin: 'vscode', ecosystem: 'npm' });
let stubPostStackAnalysisService = sandbox
.stub(stackAnalysisServices, 'postStackAnalysisService')
.resolves('23445');
let stubGetStackAnalysisService = sandbox
.stub(stackAnalysisServices, 'getStackAnalysisService')
.resolves({ result: '23445' });
await stackanalysismodule.stackAnalysesLifeCycle(
context,
'effectivef8Package',
'path/samplenodeapp',
'maven'
);
expect(stubEffectivef8Package).callCount(1);
expect(stubTriggerManifestWs).callCount(1);
});
test('stackAnalysesLifeCycle should throw err', async () => {
let stubEffectivef8Package = sandbox
.stub(ProjectDataProvider, 'effectivef8Package')
.rejects(false);
try {
await stackanalysismodule.stackAnalysesLifeCycle(
context,
'effectivef8Package',
'path/samplenodeapp',
'maven'
);
} catch (err) {
return;
}
expect(stubEffectivef8Package).callCount(1);
});
});
});