-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprojectDataProvider.test.ts
130 lines (116 loc) · 4.85 KB
/
projectDataProvider.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import * as vscode from 'vscode';
import * as chai from 'chai';
import * as sinon from 'sinon';
import * as sinonChai from 'sinon-chai';
import * as fs from 'fs';
import * as paths from 'path';
import * as child_process from 'child_process';
import { ProjectDataProvider } from '../src/ProjectDataProvider';
const expect = chai.expect;
chai.use(sinonChai);
suite('projectDataProvider Modules', () => {
let sandbox: sinon.SinonSandbox;
setup(() => {
sandbox = sinon.createSandbox();
});
teardown(() => {
sandbox.restore();
});
test('effectivef8Pom should return success', async () => {
let workspaceFolder = vscode.workspace.workspaceFolders[0];
let stubExec = sandbox
.stub(child_process, 'exec')
.yields(null, 'success', 'success');
let effectivef8PomPR = await ProjectDataProvider.effectivef8Pom(
workspaceFolder.uri.fsPath
);
expect(effectivef8PomPR).contains('target/dependencies.txt');
expect(stubExec).callCount(1);
});
test('effectivef8Package should return error', () => {
let workspaceFolder = vscode.workspace.workspaceFolders[0];
let stubGetDependencyVersion = sandbox
.stub(ProjectDataProvider, 'getDependencyVersion')
.rejects(false);
ProjectDataProvider.effectivef8Package(workspaceFolder.uri.fsPath);
expect(stubGetDependencyVersion).callCount(1);
});
test('effectivef8Package should return success', async () => {
let workspaceFolder = vscode.workspace.workspaceFolders[0];
let stubGetDependencyVersion = sandbox
.stub(ProjectDataProvider, 'getDependencyVersion')
.resolves(true);
let stubFormPackagedependencyNpmList = sandbox
.stub(ProjectDataProvider, 'formPackagedependencyNpmList')
.resolves('sample');
await ProjectDataProvider.effectivef8Package(workspaceFolder.uri.fsPath);
expect(stubGetDependencyVersion).callCount(1);
expect(stubFormPackagedependencyNpmList).callCount(1);
});
test('formPackagedependencyNpmList should return error', () => {
let workspaceFolder = vscode.workspace.workspaceFolders[0];
let vscodeRootpath = paths.join(workspaceFolder.uri.fsPath);
let stubReadFile = sandbox.stub(fs, 'readFile').yields('err');
ProjectDataProvider.formPackagedependencyNpmList(vscodeRootpath);
expect(stubReadFile).callCount(1);
});
test('formPackagedependencyNpmList should return success', () => {
let workspaceFolder = vscode.workspace.workspaceFolders[0];
let vscodeRootpath = paths.join(workspaceFolder.uri.fsPath);
let sampleBody = { status: 'success' };
let stubReadFile = sandbox
.stub(fs, 'readFile')
.yields(null, JSON.stringify(sampleBody));
let stubWriteFile = sandbox.stub(fs, 'writeFile').yields(null, true);
ProjectDataProvider.formPackagedependencyNpmList(vscodeRootpath);
expect(stubReadFile).callCount(1);
expect(stubWriteFile).callCount(1);
});
test('formPackagedependencyNpmList fail while writing file', () => {
let workspaceFolder = vscode.workspace.workspaceFolders[0];
let vscodeRootpath = paths.join(workspaceFolder.uri.fsPath);
let sampleBody = { status: 'success' };
let stubReadFile = sandbox
.stub(fs, 'readFile')
.yields(null, JSON.stringify(sampleBody));
let stubWriteFile = sandbox.stub(fs, 'writeFile').yields('err');
ProjectDataProvider.formPackagedependencyNpmList(vscodeRootpath);
expect(stubReadFile).callCount(1);
expect(stubWriteFile).callCount(1);
});
test('getDependencyVersion should return success', async () => {
let workspaceFolder = vscode.workspace.workspaceFolders[0];
let vscodeRootpath = paths.join(workspaceFolder.uri.fsPath);
let stubExec = sandbox
.stub(child_process, 'exec')
.yields(null, 'success', 'success');
sandbox.stub(fs, 'existsSync').returns(true);
let depVersionPromise = await ProjectDataProvider.getDependencyVersion(
'path/samplenodeapp/'
);
expect(depVersionPromise).equals(true);
expect(stubExec).callCount(1);
});
test('effectivef8Pypi should return success', async () => {
let workspaceFolder = vscode.workspace.workspaceFolders[0];
let stubExec = sandbox
.stub(child_process, 'exec')
.yields(null, 'success', 'success');
let effectivef8PypiPR = await ProjectDataProvider.effectivef8Pypi(
workspaceFolder.uri.fsPath
);
expect(effectivef8PypiPR).contains('target/pylist.json');
expect(stubExec).called;
});
test('effectivef8Golang should return success', async () => {
let workspaceFolder = vscode.workspace.workspaceFolders[0];
let stubExec = sandbox
.stub(child_process, 'exec')
.yields(null, 'success', 'success');
let effectivef8GolangPR = await ProjectDataProvider.effectivef8Golang(
paths.join(workspaceFolder.uri.fsPath, "go.mod")
);
expect(effectivef8GolangPR).contains('target/golist.json');
expect(stubExec).callCount(1);
});
});