Skip to content

Commit cc7c544

Browse files
committed
feat: added test for deploying selected files
1 parent 6f244d0 commit cc7c544

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/testing/deployTools.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,19 @@ export const DeployToolsSuite: TestSuite = {
147147
assert.strictEqual(deleted, 1);
148148
}
149149
},
150+
{
151+
name: `Test 'Selected' deployment`, test: async () => {
152+
const filesToDeploy = [
153+
fakeProject.files![1].localPath!,
154+
fakeProject.folders![0].localPath!,
155+
]
156+
157+
const locals = await getLocalFilesInfoForSelected(filesToDeploy);
158+
const remotes = await deploy("selected", filesToDeploy);
159+
assert.strictEqual(remotes.size, 4, "Expected 1 root file and 3 files from the folder to be deployed");
160+
assertFilesInfoEquals(locals, remotes);
161+
}
162+
},
150163
{
151164
name: `postDownload test`, test: async () => {
152165
const action: Action = {
@@ -215,7 +228,7 @@ export const DeployToolsSuite: TestSuite = {
215228
},
216229
}
217230

218-
async function deploy(method: DeploymentMethod) {
231+
async function deploy(method: DeploymentMethod, selectedFiles?: vscode.Uri[]) {
219232
assert.ok(fakeProject.localPath, "No local path");
220233
assert.ok(fakeProject.remotePath, "No remote path");
221234
const workspaceFolder = vscode.workspace.getWorkspaceFolder(fakeProject.localPath);
@@ -227,7 +240,7 @@ async function deploy(method: DeploymentMethod) {
227240
`!${basename(fakeProject.localPath.path)}/**` //Allow content
228241
]);
229242

230-
assert.ok(await DeployTools.deploy({ method, remotePath: fakeProject.remotePath, workspaceFolder, ignoreRules }), `"${method}" deployment failed`);
243+
assert.ok(await DeployTools.deploy({ method, remotePath: fakeProject.remotePath, workspaceFolder, ignoreRules, selectedFiles }), `"${method}" deployment failed`);
231244
return await getRemoteFilesInfo();
232245
}
233246

@@ -265,6 +278,17 @@ async function getLocalFilesInfo() {
265278
return localFiles;
266279
}
267280

281+
async function getLocalFilesInfoForSelected(selectedFiles: vscode.Uri[]) {
282+
const localFiles = await getLocalFilesInfo();
283+
const selectedPaths = selectedFiles.map(file => posix.join(basename(fakeProject.localPath!.path), posix.relative(fakeProject.localPath!.path, file.path)));
284+
for (const path of localFiles.keys()) {
285+
if (!selectedPaths.some(selected => selected === path || path.startsWith(selected+'/'))) {
286+
localFiles.delete(path);
287+
}
288+
}
289+
return localFiles;
290+
}
291+
268292
async function getRemoteFilesInfo() {
269293
const remoteFiles: FilesInfo = new Map;
270294

0 commit comments

Comments
 (0)