Skip to content

Commit 27c306b

Browse files
authored
test: Add unit tests for exporting jar (#485)
1 parent 341ac5b commit 27c306b

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

test/gradle/.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"java.server.launchMode": "Standard"
2+
"java.server.launchMode": "Standard",
3+
"java.import.gradle.version": "6.8"
34
}

test/maven-suite/exportJar.test.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
import * as assert from "assert";
5+
import * as cp from "child_process";
6+
import * as fse from "fs-extra";
7+
import { suiteTeardown } from "mocha";
8+
import * as path from "path";
9+
import { Task, TaskEndEvent, tasks, workspace } from "vscode";
10+
import { setupTestEnv } from "../shared";
11+
12+
// tslint:disable: only-arrow-functions
13+
const folderPath: string = workspace.workspaceFolders![0].uri.fsPath;
14+
const jarFileName: string = "maven.jar";
15+
const testFolder: string = path.join(folderPath, "test");
16+
17+
suite("Export Jar Tests", () => {
18+
19+
suiteSetup(setupTestEnv);
20+
21+
test("Can export jar correctly", async function() {
22+
const vscodeTasks: Task[] = await tasks.fetchTasks();
23+
const exportJarTask: Task | undefined = vscodeTasks.find((t: Task) => t.name === "java: exportjar:maven");
24+
assert.ok(exportJarTask !== undefined);
25+
26+
await new Promise<void>(async (resolve) => {
27+
tasks.onDidEndTask((e: TaskEndEvent) => {
28+
if (e.execution.task.name === exportJarTask?.name) {
29+
return resolve();
30+
}
31+
});
32+
await tasks.executeTask(exportJarTask!);
33+
});
34+
35+
const isFileExist: boolean = await fse.pathExists(path.join(folderPath, jarFileName));
36+
assert.ok(isFileExist);
37+
38+
await fse.ensureDir(testFolder);
39+
cp.execSync("jar -xvf ../maven.jar", {
40+
cwd: testFolder,
41+
});
42+
43+
const isManifestExist: boolean = await fse.pathExists(path.join(testFolder, "META-INF", "MANIFEST.MF"));
44+
assert.ok(isManifestExist);
45+
const isClassFileExist: boolean = await fse.pathExists(path.join(testFolder, "com", "mycompany", "app", "App.class"));
46+
assert.ok(isClassFileExist);
47+
});
48+
49+
suiteTeardown(async function() {
50+
await fse.remove(path.join(folderPath, jarFileName));
51+
await fse.remove(testFolder);
52+
});
53+
});

test/maven/.vscode/tasks.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "java",
6+
"label": "java: exportjar:maven",
7+
"mainClass": "com.mycompany.app.App",
8+
"targetPath": "${workspaceFolder}/${workspaceFolderBasename}.jar",
9+
"elements": [
10+
"${compileOutput}",
11+
"${dependencies}"
12+
],
13+
"problemMatcher": []
14+
}
15+
]
16+
}

0 commit comments

Comments
 (0)