feat: Support customize the classpath in test configuration (#1328)

Signed-off-by: Sheng Chen <sheche@microsoft.com>
This commit is contained in:
Sheng Chen 2021-11-03 16:56:50 +08:00 коммит произвёл GitHub
Родитель d1feb56af6
Коммит d45b33aa58
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 74 добавлений и 1 удалений

Просмотреть файл

@ -176,6 +176,30 @@
"description": "%configuration.java.test.config.workingDirectory.description%",
"default": "${workspaceFolder}"
},
"classPaths": {
"type": "array",
"items": {
"anyOf": [
{
"enum": [
"$Auto",
"$Runtime",
"$Test",
"!<path>"
],
"enumDescriptions": [
"%configuration.java.test.config.classPaths.auto.description%",
"%configuration.java.test.config.classPaths.runtime.description%",
"%configuration.java.test.config.classPaths.test.description%",
"%configuration.java.test.config.classPaths.exclude.description%"
]
},
"string"
]
},
"description": "%configuration.java.test.config.classPaths.description%",
"default": []
},
"vmArgs": {
"type": "array",
"items": {
@ -232,6 +256,30 @@
"description": "%configuration.java.test.config.workingDirectory.description%",
"default": "${workspaceFolder}"
},
"classPaths": {
"type": "array",
"items": {
"anyOf": [
{
"enum": [
"$Auto",
"$Runtime",
"$Test",
"!<path>"
],
"enumDescriptions": [
"%configuration.java.test.config.classPaths.auto.description%",
"%configuration.java.test.config.classPaths.runtime.description%",
"%configuration.java.test.config.classPaths.test.description%",
"%configuration.java.test.config.classPaths.exclude.description%"
]
},
"string"
]
},
"description": "%configuration.java.test.config.classPaths.description%",
"default": []
},
"vmargs": {
"type": "array",
"items": {

Просмотреть файл

@ -10,6 +10,11 @@
"configuration.java.test.config.item.description": "Specify the configuration item for running the tests",
"configuration.java.test.config.name.description": "Specify the name of the configuration item",
"configuration.java.test.config.workingDirectory.description": "Specify the working directory when running the tests",
"configuration.java.test.config.classPaths.description": "The classpath defined in this setting will be appended to the resolved classpath",
"configuration.java.test.config.classPaths.auto.description": "Automatically resolve the classpaths of current project",
"configuration.java.test.config.classPaths.runtime.description": "The classpaths within 'runtime' scope of current project",
"configuration.java.test.config.classPaths.test.description": "The classpaths within 'test' scope of current project",
"configuration.java.test.config.classPaths.exclude.description": "The path after '!' will be excluded from the classpaths",
"configuration.java.test.config.vmArgs.description": "Specify the extra options and system properties for the JVM",
"configuration.java.test.config.args.description": "Specify the command line arguments which will be passed to the test runner",
"configuration.java.test.config.env.description": "Specify the extra environment variables when running the tests",

Просмотреть файл

@ -10,6 +10,11 @@
"configuration.java.test.config.item.description": "设定运行测试时所用的配置项",
"configuration.java.test.config.name.description": "命名配置项",
"configuration.java.test.config.workingDirectory.description": "设定执行测试时的工作目录",
"configuration.java.test.config.classPaths.description": "通过该配置项设置的类路径会被追加到自动解析的类路径上",
"configuration.java.test.config.classPaths.auto.description": "自动从当前工程中解析类路径",
"configuration.java.test.config.classPaths.runtime.description": "当前工程中属于 runtime 作用域的类路径",
"configuration.java.test.config.classPaths.test.description": "当前工程中属于 test 作用域的类路径",
"configuration.java.test.config.classPaths.exclude.description": "'!' 之后的路径将会从类路径中去除",
"configuration.java.test.config.vmArgs.description": "设定启动 JVM 的额外选项和系统属性",
"configuration.java.test.config.args.description": "设定启动 Test Runner 时的命令行参数",
"configuration.java.test.config.env.description": "启动应用程序时自定义的环境变量",

Просмотреть файл

@ -14,6 +14,11 @@ export interface IExecutionConfig {
* @since 0.14.0
*/
workingDirectory?: string;
/**
* The classpath defined in this setting will be appended to the resolved classpath.
* @since 0.33.0
*/
classPaths?: string[]
/**
* The command line arguments which will be passed to the test runner.
* @since 0.14.0

Просмотреть файл

@ -31,6 +31,7 @@ export async function resolveLaunchConfigurationForRunner(runner: BaseRunner, te
projectName: launchArguments.projectName,
cwd: config && config.workingDirectory ? config.workingDirectory : launchArguments.workingDirectory,
classPaths: [
...config?.classPaths || [],
...launchArguments.classpath,
path.join(extensionContext.extensionPath, 'server', 'com.microsoft.java.test.runner.jar'),
path.join(extensionContext.extensionPath, 'server', 'lib'),
@ -53,7 +54,10 @@ export async function resolveLaunchConfigurationForRunner(runner: BaseRunner, te
mainClass: launchArguments.mainClass,
projectName: launchArguments.projectName,
cwd: config && config.workingDirectory ? config.workingDirectory : launchArguments.workingDirectory,
classPaths: launchArguments.classpath,
classPaths: [
...config?.classPaths || [],
...launchArguments.classpath,
],
modulePaths: launchArguments.modulepath,
args: launchArguments.programArguments,
vmArgs: launchArguments.vmArguments,

Просмотреть файл

@ -42,6 +42,10 @@ suite('JUnit Runner Analyzer Tests', () => {
};
const junitRunner = new JUnitRunner(runnerContext);
const configuration = await resolveLaunchConfigurationForRunner(junitRunner, runnerContext, {
classPaths: [
"/a/b/c.jar",
"/foo/bar.jar"
],
env: {
test: "test",
},
@ -55,5 +59,7 @@ suite('JUnit Runner Analyzer Tests', () => {
assert.strictEqual(configuration.envFile, "${workspaceFolder}/.env");
assert.strictEqual(configuration.sourcePaths?.[0], "/a/b/c.jar");
assert.strictEqual(configuration.preLaunchTask, "test");
assert.strictEqual(configuration.classPaths[0], "/a/b/c.jar");
assert.strictEqual(configuration.classPaths[1], "/foo/bar.jar");
});
});