* Support command tests
This commit is contained in:
Shi Chen 2021-07-28 15:09:35 +08:00 коммит произвёл GitHub
Родитель 706c085c2f
Коммит 1c727b0510
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
29 изменённых файлов: 3019 добавлений и 179 удалений

150
.github/workflows/build.yml поставляемый
Просмотреть файл

@ -1,150 +0,0 @@
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
linux:
name: Linux
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
- name: Setup Build Environment
run: |
sudo apt-get update
sudo apt-get install -y libxkbfile-dev pkg-config libsecret-1-dev libxss1 dbus xvfb libgtk-3-0 libgbm1
sudo /usr/bin/Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
sleep 3
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: '11'
- name: Setup Node.js environment
uses: actions/setup-node@v2
with:
node-version: 12
- name: Install Node.js modules
run: npm install
- name: Install Gulp
run: npm install -g gulp
- name: Install VSCE
run: npm install -g vsce
- name: Lint
run: gulp tslint
- name: Checkstyle
run: gulp checkstyle
- name: Build OSGi bundle
run: npm run build-server
- name: Build VSIX file
run: vsce package
- name: Test extension
run: DISPLAY=:99 npm test
- name: Print language server Log if job failed
if: ${{ failure() }}
run: find $HOME/.config/Code/User/workspaceStorage/*/redhat.java/jdt_ws/.metadata/.log -print -exec cat '{}' \;;
windows:
name: Windows
runs-on: windows-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: '11'
- name: Setup Node.js environment
uses: actions/setup-node@v2
with:
node-version: 12
- name: Install Node.js modules
run: npm install
- name: Install Gulp
run: npm install -g gulp --force
- name: Install VSCE
run: npm install -g vsce
- name: Lint
run: gulp tslint
- name: Checkstyle
run: gulp checkstyle
- name: Build OSGi bundle
run: npm run build-server
- name: Build VSIX file
run: vsce package
- name: Test extension
run: npm test
- name: Print language server Log if job failed
if: ${{ failure() }}
run: Get-ChildItem -Path $env:APPDATA/Code/User/workspaceStorage/*/redhat.java/jdt_ws/.metadata/.log | cat
darwin:
name: macOS
runs-on: macos-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: '11'
- name: Setup Node.js environment
uses: actions/setup-node@v2
with:
node-version: 12
- name: Install Node.js modules
run: npm install
- name: Install Gulp
run: npm install -g gulp
- name: Install VSCE
run: npm install -g vsce
- name: Lint
run: gulp tslint
- name: Checkstyle
run: gulp checkstyle
- name: Build OSGi bundle
run: npm run build-server
- name: Build VSIX file
run: vsce package
- name: Test extension
run: npm test
- name: Print language server Log if job failed
if: ${{ failure() }}
run: find $HOME/Library/Application\ Support/Code/User/workspaceStorage/*/redhat.java/jdt_ws/.metadata/.log -print -exec cat '{}' \;;

54
.github/workflows/linux.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,54 @@
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
linux:
name: Linux
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
- name: Setup Build Environment
run: |
sudo apt-get update
sudo apt-get install -y libxkbfile-dev pkg-config libsecret-1-dev libxss1 dbus xvfb libgtk-3-0 libgbm1
sudo /usr/bin/Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
sleep 3
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: '11'
- name: Setup Node.js environment
uses: actions/setup-node@v2
with:
node-version: 12
- name: Install Node.js modules
run: npm install
- name: Install Gulp
run: npm install -g gulp
- name: Install VSCE
run: npm install -g vsce
- name: Build OSGi bundle
run: npm run build-server
- name: Build VSIX file
run: vsce package
- name: Test extension
run: DISPLAY=:99 npm test
- name: Print language server Log if job failed
if: ${{ failure() }}
run: find $HOME/.config/Code/User/workspaceStorage/*/redhat.java/jdt_ws/.metadata/.log -print -exec cat '{}' \;;

54
.github/workflows/linuxUI.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,54 @@
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
linuxUI:
name: Linux-UI
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
- name: Setup Build Environment
run: |
sudo apt-get update
sudo apt-get install -y libxkbfile-dev pkg-config libsecret-1-dev libxss1 dbus xvfb libgtk-3-0 libgbm1
sudo /usr/bin/Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
sleep 3
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: '11'
- name: Setup Node.js environment
uses: actions/setup-node@v2
with:
node-version: 12
- name: Install Node.js modules
run: npm install
- name: Install Gulp
run: npm install -g gulp
- name: Install VSCE
run: npm install -g vsce
- name: Build OSGi bundle
run: npm run build-server
- name: Build VSIX file
run: vsce package
- name: Test extension
run: DISPLAY=:99 npm run test-ui
- name: Print language server Log
if: ${{ failure() }}
run: find ./test-resources/settings/User/workspaceStorage/*/redhat.java/jdt_ws/.metadata/.log -print -exec cat '{}' \;;

47
.github/workflows/macOS.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,47 @@
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
darwin:
name: macOS
runs-on: macos-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: '11'
- name: Setup Node.js environment
uses: actions/setup-node@v2
with:
node-version: 12
- name: Install Node.js modules
run: npm install
- name: Install Gulp
run: npm install -g gulp
- name: Install VSCE
run: npm install -g vsce
- name: Build OSGi bundle
run: npm run build-server
- name: Build VSIX file
run: vsce package
- name: Test extension
run: npm test
- name: Print language server Log if job failed
if: ${{ failure() }}
run: find $HOME/Library/Application\ Support/Code/User/workspaceStorage/*/redhat.java/jdt_ws/.metadata/.log -print -exec cat '{}' \;;

47
.github/workflows/macOSUI.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,47 @@
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
darwinUI:
name: macOS-UI
runs-on: macos-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: '11'
- name: Setup Node.js environment
uses: actions/setup-node@v2
with:
node-version: 12
- name: Install Node.js modules
run: npm install
- name: Install Gulp
run: npm install -g gulp
- name: Install VSCE
run: npm install -g vsce
- name: Build OSGi bundle
run: npm run build-server
- name: Build VSIX file
run: vsce package
- name: Test extension
run: npm run test-ui
- name: Print language server Log if job failed
if: ${{ failure() }}
run: find ./test-resources/settings/User/workspaceStorage/*/redhat.java/jdt_ws/.metadata/.log -print -exec cat '{}' \;;

47
.github/workflows/windows.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,47 @@
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
windows:
name: Windows
runs-on: windows-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: '11'
- name: Setup Node.js environment
uses: actions/setup-node@v2
with:
node-version: 12
- name: Install Node.js modules
run: npm install
- name: Install Gulp
run: npm install -g gulp --force
- name: Install VSCE
run: npm install -g vsce
- name: Build OSGi bundle
run: npm run build-server
- name: Build VSIX file
run: vsce package
- name: Test extension
run: npm test
- name: Print language server Log if job failed
if: ${{ failure() }}
run: Get-ChildItem -Path $env:APPDATA/Code/User/workspaceStorage/*/redhat.java/jdt_ws/.metadata/.log | cat

53
.github/workflows/windowsUI.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,53 @@
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
windowsUI:
name: Windows-UI
runs-on: windows-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: '11'
- name: Setup Node.js environment
uses: actions/setup-node@v2
with:
node-version: 12
- name: Install Node.js modules
run: npm install
- name: Install Gulp
run: npm install -g gulp --force
- name: Install VSCE
run: npm install -g vsce
- name: Lint
run: gulp tslint
- name: Checkstyle
run: gulp checkstyle
- name: Build OSGi bundle
run: npm run build-server
- name: Build VSIX file
run: vsce package
- name: Test extension
run: npm run test-ui
- name: Print language server Log if job failed
if: ${{ failure() }}
run: Get-ChildItem -Path ./test-resources/settings/User/workspaceStorage/*/redhat.java/jdt_ws/.metadata/.log | cat

1
.gitignore поставляемый
Просмотреть файл

@ -12,3 +12,4 @@ packages/
dist
**/.settings
**/.checkstyle
test-resources/

30
.vscode/launch.json поставляемый
Просмотреть файл

@ -82,6 +82,34 @@
"sourceMaps": true,
"outFiles": [ "${workspaceFolder}/dist/**/*.js" ],
"preLaunchTask": "npm: compile"
}
},
{
"name": "Extension Tests - Invisible Project",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"${workspaceFolder}/test/invisible/",
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/dist/test/invisible-suite/index"
],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": [ "${workspaceFolder}/dist/**/*.js" ],
"preLaunchTask": "npm: compile"
},
{
"name": "Debug UI Command Tests",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/node_modules/vscode-extension-tester/out/cli.js",
"args": [
"setup-and-run",
"${workspaceFolder}/dist/test/ui/command.test.js",
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"preLaunchTask": "npm: compile"
},
]
}

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

@ -18,6 +18,7 @@ extension.bundle.ts
javaConfig.json
.github/**
images
test-resources
# Ignore output of code sign
server/*.md

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

@ -15,6 +15,7 @@ export { PackageRootNode } from "./src/views/packageRootNode";
export { PrimaryTypeNode } from "./src/views/PrimaryTypeNode";
export { ProjectNode } from "./src/views/projectNode";
export { WorkspaceNode } from "./src/views/workspaceNode";
export { IMainClassInfo } from "./src/exportJarSteps/ResolveMainClassExecutor";
// project view test
export { contextManager } from "./src/contextManager";

2034
package-lock.json сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -583,6 +583,7 @@
"compile": "tsc -p . && webpack --config webpack.config.js",
"watch": "webpack --mode development --watch --info-verbosity verbose",
"test": "tsc -p . && node ./dist/test/index.js",
"test-ui": "tsc -p . && node ./dist/test/ui/index.js",
"build-server": "./node_modules/.bin/gulp build_server",
"vscode:prepublish": "tsc -p ./ && webpack --mode production"
},
@ -604,6 +605,8 @@
"tslint": "^5.20.1",
"typescript": "^3.9.9",
"vscode-test": "^1.5.1",
"vscode-extension-tester": "^4.1.1",
"vscode-extension-tester-native": "^3.0.2",
"webpack": "^4.46.0",
"webpack-cli": "^3.3.12"
},

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

@ -2,6 +2,7 @@
// Licensed under the MIT license.
import * as cp from "child_process";
import * as os from "os";
import * as path from "path";
import { downloadAndUnzipVSCode, resolveCliPathFromVSCodeExecutablePath, runTests } from "vscode-test";
@ -66,9 +67,21 @@ async function main(): Promise<void> {
],
});
// Run test for invisible project
await runTests({
vscodeExecutablePath,
extensionDevelopmentPath,
extensionTestsPath: path.resolve(__dirname, "./invisible-suite"),
launchArgs: [
path.join(__dirname, "..", "..", "test", "invisible"),
"--disable-workspace-trust",
],
});
process.exit(0);
} catch (err) {
process.stdout.write(`${err}${os.EOL}`);
process.exit(1);
}
}

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

@ -0,0 +1,41 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import * as glob from "glob";
import * as Mocha from "mocha";
import * as path from "path";
export function run(): Promise<void> {
// Create the mocha test
const mocha = new Mocha({
ui: "tdd",
color: true,
timeout: 1 * 60 * 1000,
});
const testsRoot = __dirname;
return new Promise((c, e) => {
glob("**/**.test.js", { cwd: testsRoot }, (err, files) => {
if (err) {
return e(err);
}
// Add files to the test suite
files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f)));
try {
// Run the mocha test
mocha.run((failures) => {
if (failures > 0) {
e(new Error(`${failures} tests failed.`));
} else {
c();
}
});
} catch (err) {
e(err);
}
});
});
}

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

@ -0,0 +1,59 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import * as assert from "assert";
import * as fse from "fs-extra";
import { platform } from "os";
import * as path from "path";
import * as vscode from "vscode";
import { Commands, contextManager, DependencyExplorer, PackageNode, PackageRootNode, ProjectNode } from "../../extension.bundle";
import { setupTestEnv } from "../shared";
import { sleep } from "../util";
// tslint:disable: only-arrow-functions
suite("Invisible Project View Tests", () => {
suiteSetup(setupTestEnv);
test("Can execute command java.project.refreshLibraries correctly", async function() {
if (platform() === "darwin") {
this.skip();
}
const explorer = DependencyExplorer.getInstance(contextManager.context);
let projectNode = (await explorer.dataProvider.getChildren())![0] as ProjectNode;
const projectUri = projectNode.nodeData.uri;
assert.ok(projectUri, "project node doesn't have correct uri");
const expectedUri = vscode.Uri.parse(projectUri!);
await fse.copy(path.join(expectedUri.fsPath, "libSource", "simple.jar"), path.join(expectedUri.fsPath, "lib", "simple.jar"));
await vscode.commands.executeCommand(Commands.JAVA_PROJECT_REFRESH_LIBRARIES);
await sleep(5000);
projectNode = (await explorer.dataProvider.getChildren())![0] as ProjectNode;
const packageRoots = await projectNode.getChildren();
assert.equal(packageRoots.length, 3, "length of package nodes should be 3");
const mainPackage = packageRoots[2] as PackageRootNode;
const libraryNode = (await mainPackage.getChildren())[0] as PackageNode;
assert.equal(libraryNode.nodeData.name, "simple.jar", "library name should be simple.jar");
});
test("Can execute command java.project.removeLibrary correctly", async function() {
if (platform() === "darwin") {
this.skip();
}
const explorer = DependencyExplorer.getInstance(contextManager.context);
let projectNode = (await explorer.dataProvider.getChildren())![0] as ProjectNode;
let packageRoots = await projectNode.getChildren();
assert.equal(packageRoots.length, 3, "length of package nodes should be 3");
let mainPackage = packageRoots[2] as PackageRootNode;
const libraryNode = (await mainPackage.getChildren())[0] as PackageNode;
await vscode.commands.executeCommand(Commands.JAVA_PROJECT_REMOVE_LIBRARY, libraryNode);
await sleep(5000);
projectNode = (await explorer.dataProvider.getChildren())![0] as ProjectNode;
packageRoots = await projectNode.getChildren();
assert.equal(packageRoots.length, 3, "length of package nodes should be 3");
mainPackage = packageRoots[2] as PackageRootNode;
assert.equal((await mainPackage.getChildren()).length, 0, "libraries' length should be 0");
});
});

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

@ -0,0 +1,10 @@
{
"folders": [
{
"path": "invisible"
}
],
"settings": {
"java.server.launchMode": "Standard"
}
}

5
test/invisible/.vscode/settings.json поставляемый Normal file
Просмотреть файл

@ -0,0 +1,5 @@
{
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}

Двоичные данные
test/invisible/libSource/simple.jar Normal file

Двоичный файл не отображается.

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

@ -0,0 +1,5 @@
public class App {
public static void main(String[] args) throws Exception {
System.out.println("Hello, World!");
}
}

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

@ -2,16 +2,62 @@
// Licensed under the MIT license.
import * as assert from "assert";
import { ContainerNode, contextManager, DependencyExplorer,
PackageNode, PackageRootNode, PrimaryTypeNode, ProjectNode } from "../../extension.bundle";
import * as clipboardy from "clipboardy";
import * as path from "path";
import * as vscode from "vscode";
import { Commands, ContainerNode, contextManager, DependencyExplorer, IMainClassInfo,
INodeData, NodeKind, PackageNode, PackageRootNode, PrimaryTypeNode, ProjectNode } from "../../extension.bundle";
import { fsPath, setupTestEnv, Uris } from "../shared";
import { sleep } from "../util";
// tslint:disable: only-arrow-functions
suite("Maven Project View Tests", () => {
suiteSetup(setupTestEnv);
test("Can node render correctly", async function() {
test("Can node render correctly in hierarchical view", async function() {
await vscode.workspace.getConfiguration("java.dependency").update("packagePresentation", "hierarchical");
await vscode.commands.executeCommand(Commands.VIEW_PACKAGE_CHANGETOHIERARCHICALPACKAGEVIEW);
await vscode.commands.executeCommand(Commands.VIEW_PACKAGE_REFRESH);
const explorer = DependencyExplorer.getInstance(contextManager.context);
const roots = await explorer.dataProvider.getChildren();
assert.equal(roots?.length, 1, "Number of root node should be 1");
const projectNode = roots![0] as ProjectNode;
assert.equal(projectNode.name, "my-app", "Project name should be \"my-app\"");
const packageRoots = await projectNode.getChildren();
assert.equal(packageRoots.length, 4, "Number of root packages should be 4");
const mainPackage = packageRoots[0] as PackageRootNode;
assert.equal(mainPackage.name, "src/main/java", "Package name should be \"src/main/java\"");
const primarySubPackages = await mainPackage.getChildren();
assert.equal(primarySubPackages.length, 1, "Number of primary subpackages should be 1");
const primarySubPackage = primarySubPackages[0] as PackageNode;
assert.equal(primarySubPackage.name, "com.mycompany", "Name of primary subpackage should be \"com.mycompany\"");
const secondarySubPackages = await primarySubPackage.getChildren();
assert.equal(secondarySubPackages.length, 2, "Number of secondary subpackages should be 1");
const firstSecondarySubPackage = secondarySubPackages[0] as PackageNode;
const secondSecondarySubPackage = secondarySubPackages[1] as PackageNode;
assert.equal(firstSecondarySubPackage.nodeData.displayName, "app", "Name of first secondary subpackage should be \"app\"");
assert.equal(secondSecondarySubPackage.nodeData.displayName, "app1", "Name of first secondary subpackage should be \"app1\"");
// validate innermost layer nodes
const classes = await firstSecondarySubPackage.getChildren();
assert.equal(classes.length, 3, "Number of main classes of first package should be 3");
const firstClass = classes[0] as PrimaryTypeNode;
const secondClass = classes[1] as PrimaryTypeNode;
const thirdClass = classes[2] as PrimaryTypeNode;
assert.equal(firstClass.name, "App", "Name of first class should be \"App\"");
assert.equal(secondClass.name, "AppToDelete", "Name of second class should be \"AppToDelete\"");
assert.equal(thirdClass.name, "AppToRename", "Name of third class should be \"AppToRename\"");
});
test("Can node render correctly in flat view", async function() {
await vscode.workspace.getConfiguration("java.dependency").update("packagePresentation", "flat");
await vscode.commands.executeCommand(Commands.VIEW_PACKAGE_CHANGETOFLATPACKAGEVIEW);
await vscode.commands.executeCommand(Commands.VIEW_PACKAGE_REFRESH);
const explorer = DependencyExplorer.getInstance(contextManager.context);
// validate root nodes
@ -36,21 +82,27 @@ suite("Maven Project View Tests", () => {
// validate package nodes
const mainSubPackages = await mainPackage.getChildren();
const testSubPackages = await testPackage.getChildren();
assert.equal(mainSubPackages.length, 1, "Number of main sub packages should be 1");
assert.equal(mainSubPackages.length, 2, "Number of main sub packages should be 2");
assert.equal(testSubPackages.length, 1, "Number of test sub packages should be 1");
const mainSubPackage = mainSubPackages[0] as PackageNode;
const firstMainSubPackage = mainSubPackages[0] as PackageNode;
const secondMainSubPackage = mainSubPackages[1] as PackageNode;
const testSubPackage = testSubPackages[0] as PackageNode;
assert.equal(mainSubPackage.name, "com.mycompany.app", "Name of subpackage should be \"com.mycompany.app\"");
assert.equal(testSubPackage.name, "com.mycompany.app", "Name of subpackage should be \"com.mycompany.app\"");
assert.equal(firstMainSubPackage.name, "com.mycompany.app", "Name of first main subpackage should be \"com.mycompany.app\"");
assert.equal(secondMainSubPackage.name, "com.mycompany.app1", "Name of second main subpackage should be \"com.mycompany.app1\"");
assert.equal(testSubPackage.name, "com.mycompany.app", "Name of test subpackage should be \"com.mycompany.app\"");
// validate innermost layer nodes
const mainClasses = await mainSubPackage.getChildren();
const mainClasses = await firstMainSubPackage.getChildren();
const testClasses = await testSubPackage.getChildren();
assert.equal(mainClasses.length, 1, "Number of main classes should be 1");
assert.equal(mainClasses.length, 3, "Number of main classes of first package should be 3");
assert.equal(testClasses.length, 1, "Number of test classes should be 1");
const mainClass = mainClasses[0] as PrimaryTypeNode;
const firstMainClass = mainClasses[0] as PrimaryTypeNode;
const secondMainClass = mainClasses[1] as PrimaryTypeNode;
const thirdMainClass = mainClasses[2] as PrimaryTypeNode;
const testClass = testClasses[0] as PrimaryTypeNode;
assert.equal(mainClass.name, "App", "Name of main class should be \"App\"");
assert.equal(firstMainClass.name, "App", "Name of first class should be \"App\"");
assert.equal(secondMainClass.name, "AppToDelete", "Name of second class should be \"AppToDelete\"");
assert.equal(thirdMainClass.name, "AppToRename", "Name of third class should be \"AppToRename\"");
assert.equal(testClass.name, "AppTest", "Name of test class should be \"AppTest\"");
});
@ -74,4 +126,97 @@ suite("Maven Project View Tests", () => {
assert.equal(fsPath(mainClass), Uris.MAVEN_MAIN_CLASS, "Main class uri incorrect");
assert.equal(fsPath(testClass), Uris.MAVEN_TEST_CLASS, "Test class uri incorrect");
});
test("Can execute command java.view.package.copyFilePath correctly", async function() {
const explorer = DependencyExplorer.getInstance(contextManager.context);
const projectNode = (await explorer.dataProvider.getChildren())![0] as ProjectNode;
const packageRoots = await projectNode.getChildren();
const mainPackage = packageRoots[0] as PackageRootNode;
const mainSubPackage = (await mainPackage.getChildren())[0] as PackageNode;
const mainClass = (await mainSubPackage.getChildren())[0] as PrimaryTypeNode;
await vscode.commands.executeCommand(Commands.VIEW_PACKAGE_COPY_FILE_PATH, mainClass);
await sleep(1000);
const content = await clipboardy.read();
const contentUri = vscode.Uri.file(content);
const dataUri = mainClass.nodeData.uri;
assert.ok(dataUri, `Class node should have correct uri`);
const expectedUri = vscode.Uri.parse(dataUri!);
assert.equal(contentUri.fsPath, expectedUri.fsPath, `File path should be copied correctly`);
});
test("Can execute command java.view.package.copyRelativeFilePath correctly", async function() {
const explorer = DependencyExplorer.getInstance(contextManager.context);
const projectNode = (await explorer.dataProvider.getChildren())![0] as ProjectNode;
const packageRoots = await projectNode.getChildren();
const mainPackage = packageRoots[0] as PackageRootNode;
const mainSubPackage = (await mainPackage.getChildren())[0] as PackageNode;
const mainClass = (await mainSubPackage.getChildren())[0] as PrimaryTypeNode;
await vscode.commands.executeCommand(Commands.VIEW_PACKAGE_COPY_RELATIVE_FILE_PATH, mainClass);
await sleep(1000);
const content = await clipboardy.read();
const dataUri = mainClass.nodeData.uri;
assert.ok(dataUri, `Class node should have correct uri`);
const expectedUri = vscode.Uri.parse(dataUri!);
const workspaceFolders = vscode.workspace.workspaceFolders;
assert.ok(workspaceFolders, `There should be valid workspace folders`);
const relativePath = path.relative(workspaceFolders![0].uri.fsPath, expectedUri.fsPath);
assert.equal(content, relativePath, `Relative file path should be copied correctly`);
});
test("Can execute command java.project.list correctly", async function() {
const workspaceFolders = vscode.workspace.workspaceFolders;
assert.ok(workspaceFolders, `There should be valid workspace folders`);
const projects = await vscode.commands.executeCommand<INodeData[]>(Commands.EXECUTE_WORKSPACE_COMMAND,
Commands.JAVA_PROJECT_LIST, workspaceFolders![0].uri.toString());
assert.equal(projects?.length, 1, "project's length should be 1");
assert.equal(projects![0].name, "my-app", "project should be my-app");
});
test("Can execute command java.getPackageData correctly", async function() {
const explorer = DependencyExplorer.getInstance(contextManager.context);
const projectNode = (await explorer.dataProvider.getChildren())![0] as ProjectNode;
const packageRoots = await projectNode.getChildren();
const mainPackage = packageRoots[0] as PackageRootNode;
const workspaceFolders = vscode.workspace.workspaceFolders;
assert.ok(workspaceFolders, `There should be valid workspace folders`);
const packages = await vscode.commands.executeCommand<INodeData[]>(Commands.EXECUTE_WORKSPACE_COMMAND,
Commands.JAVA_GETPACKAGEDATA, {
kind: NodeKind.PackageRoot,
projectUri: workspaceFolders![0].uri.toString(),
path: mainPackage.nodeData.name,
handlerIdentifier: mainPackage.nodeData.handlerIdentifier,
});
assert.equal(packages?.length, 2, "packages' length should be 2");
assert.equal(packages![0].name, "com.mycompany.app", "package[0]'s name should be com.mycompany.app");
assert.equal(packages![1].name, "com.mycompany.app1", "package[1]'s name should be com.mycompany.app1");
});
test("Can execute command java.resolvePath correctly", async function() {
const explorer = DependencyExplorer.getInstance(contextManager.context);
const projectNode = (await explorer.dataProvider.getChildren())![0] as ProjectNode;
const packageRoots = await projectNode.getChildren();
const mainPackage = packageRoots[0] as PackageRootNode;
const paths = await vscode.commands.executeCommand<INodeData[]>(Commands.EXECUTE_WORKSPACE_COMMAND,
Commands.JAVA_RESOLVEPATH, mainPackage.nodeData.uri);
assert.equal(paths?.length, 3, "paths' length should be 3");
assert.equal(paths![0].name, "src", "path[0]'s name should be src");
assert.equal(paths![1].name, "main", "path[1]'s name should be main");
assert.equal(paths![2].name, "java", "path[2]'s name should be java");
});
test("Can execute command java.project.getMainClasses correctly", async function() {
const workspaceFolders = vscode.workspace.workspaceFolders;
assert.ok(workspaceFolders, `There should be valid workspace folders`);
const mainClasses = await vscode.commands.executeCommand<IMainClassInfo[]>(Commands.EXECUTE_WORKSPACE_COMMAND,
Commands.JAVA_PROJECT_GETMAINCLASSES, workspaceFolders![0].uri.toString());
assert.equal(mainClasses?.length, 1, "mainClasses' length should be 1");
assert.equal(mainClasses![0].name, "com.mycompany.app.App", "mainClasses[0]'s name should be com.mycompany.app.App");
});
});

10
test/maven.code-workspace Normal file
Просмотреть файл

@ -0,0 +1,10 @@
{
"folders": [
{
"path": "maven"
}
],
"settings": {
"java.server.launchMode": "Standard"
}
}

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

@ -0,0 +1,5 @@
package com.mycompany.app;
public class AppToDelete {
}

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

@ -0,0 +1,5 @@
package com.mycompany.app;
public class AppToRename {
}

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

@ -0,0 +1,5 @@
package com.mycompany.app1;
public class App1 {
}

316
test/ui/command.test.ts Normal file
Просмотреть файл

@ -0,0 +1,316 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import * as assert from "assert";
import * as fse from "fs-extra";
import { platform } from "os";
import * as path from "path";
import * as seleniumWebdriver from "selenium-webdriver";
import { EditorView, InputBox, ModalDialog, SideBarView, StatusBar, TextEditor, TreeItem, Workbench } from "vscode-extension-tester";
import { DialogHandler, OpenDialog } from "vscode-extension-tester-native";
import { sleep } from "../util";
// tslint:disable: only-arrow-functions
const newProjectName = "helloworld";
const mavenProjectPath = path.join(__dirname, "..", "..", "..", "test", "maven");
const mavenWorkspacePath = path.join(__dirname, "..", "..", "..", "test", "maven.code-workspace");
const invisibleProjectPath = path.join(__dirname, "..", "..", "..", "test", "invisible");
const invisibleWorkspacePath = path.join(__dirname, "..", "..", "..", "test", "invisible.code-workspace");
const targetPath = path.join(__dirname, "..", "..", "..", "test", "newProject");
describe("Command Tests", function() {
this.timeout(60000);
before(async function() {
sleep(5000);
});
beforeEach(async function() {
await sleep(5000);
});
it("Test open maven project", async function() {
await new Workbench().executeCommand("Workspaces: Open Workspace...");
const dialog: OpenDialog = await DialogHandler.getOpenDialog();
await dialog.selectPath(mavenWorkspacePath);
await dialog.confirm();
// Close welcome editors
let editorView = new EditorView();
let editorGroups = await editorView.getEditorGroups();
for (const editorGroup of editorGroups) {
await editorGroup.closeAllEditors();
}
const settingsEditor = await new Workbench().openSettings();
const setting = await settingsEditor.findSetting("Dialog Style", "Window");
await setting.setValue("custom");
const refreshSetting = await settingsEditor.findSetting("Auto Refresh", "Java", "Dependency");
await refreshSetting.setValue(true);
const viewSetting = await settingsEditor.findSetting("Package Presentation", "Java", "Dependency");
await viewSetting.setValue("flat");
// Close setting editor
editorView = new EditorView();
editorGroups = await editorView.getEditorGroups();
for (const editorGroup of editorGroups) {
await editorGroup.closeAllEditors();
}
await sleep(1000);
const fileSections = await new SideBarView().getContent().getSections();
await fileSections[0].collapse();
await waitForImporting(1000);
});
it("Test javaProjectExplorer.focus", async function() {
await new Workbench().executeCommand("javaProjectExplorer.focus");
const section = await new SideBarView().getContent().getSection("Java Projects");
assert.ok(section.isExpanded(), `Section "Java Projects" should be expanded`);
});
(platform() === "darwin" ? it.skip : it)("Test java.view.package.linkWithFolderExplorer", async function() {
const fileSections = await new SideBarView().getContent().getSections();
await fileSections[0].expand();
const srcNode = await fileSections[0].findItem("src") as TreeItem;
await srcNode.expand();
const folderNode = await fileSections[0].findItem("main") as TreeItem;
await folderNode.expand();
const subFolderNode = await fileSections[0].findItem("app") as TreeItem;
await subFolderNode.expand();
const fileNode = await fileSections[0].findItem("App.java") as TreeItem;
await fileNode.click();
await sleep(1000);
await fileSections[0].collapse();
const section = await new SideBarView().getContent().getSection("Java Projects");
await section.expand();
const packageNode = await section.findItem("com.mycompany.app") as TreeItem;
assert.ok(await packageNode.isExpanded(), `Package node "com.mycompany.app" should be expanded`);
const classNode = await section.findItem("App") as TreeItem;
assert.ok(await classNode.isDisplayed(), `Class node "App" should be revealed`);
await packageNode.collapse();
});
(platform() === "darwin" ? it.skip : it)("Test java.view.package.unLinkWithFolderExplorer", async function() {
const section = await new SideBarView().getContent().getSection("Java Projects");
const moreActions = await section.moreActions();
const desynchronize = await moreActions?.getItem("Desynchronize with Editor");
await desynchronize?.click();
const fileSections = await new SideBarView().getContent().getSections();
await fileSections[0].expand();
const fileNode = await fileSections[0].findItem("App.java") as TreeItem;
await fileNode.click();
await sleep(1000);
await fileSections[0].collapse();
await section.expand();
const packageNode = await section.findItem("com.mycompany.app") as TreeItem;
assert.ok(!await packageNode.isExpanded(), `Package "com.mycompany.app" should not be expanded`);
});
it("Test java.view.package.newJavaClass", async function() {
const section = await new SideBarView().getContent().getSection("Java Projects");
const item = await section.findItem("my-app") as TreeItem;
assert.ok(item, `Project "my-app" should be found`);
await item.click();
const button = await item.getActionButton("New Java Class");
assert.ok(button, `Button "New Java Class" should be found`);
await button!.click();
let inputBox = await InputBox.create();
assert.ok(await inputBox.getPlaceHolder() === "Choose a source folder", `InputBox "Choose a source folder" should appear`);
const quickPick = await inputBox.findQuickPick("src/main/java");
assert.ok(quickPick, `Quickpick item "src/main/java" should be found`);
await quickPick!.click();
inputBox = await InputBox.create();
assert.ok(await inputBox.getPlaceHolder() === "Input the class name", `InputBox "Input the class name" should appear`);
await inputBox.setText("App2");
await inputBox.confirm();
await sleep(1000);
const editor = new TextEditor();
await editor.save();
assert.ok(await editor.getTitle() === "App2.java", `Editor's title should be "App2.java"`);
assert.ok(await fse.pathExists(path.join(mavenProjectPath, "src", "main", "java", "App2.java")), `"App2.java" should be created in correct path`);
await fse.remove(path.join(mavenProjectPath, "src", "main", "java", "App2.java"));
});
(platform() === "darwin" ? it.skip : it)("Test java.view.package.newPackage", async function() {
// The current UI test framework doesn't support mac title bar and context menus.
// See: https://github.com/redhat-developer/vscode-extension-tester#requirements
// So we dismiss some UI tests on mac.
const section = await new SideBarView().getContent().getSection("Java Projects");
const item = await section.findItem("my-app") as TreeItem;
await item.click();
const contextMenu = await item.openContextMenu();
const newPackageItem = await contextMenu.getItem("New Package");
assert.ok(newPackageItem, `"New Package" should be found in context menu`);
await newPackageItem!.click();
let inputBox = await InputBox.create();
const quickPick = await inputBox.findQuickPick("src/main/java");
assert.ok(quickPick, `"src/main/java" should be found in quickpick items`);
await quickPick!.click();
inputBox = await InputBox.create();
await inputBox.setText("com.mycompany.app2");
await inputBox.confirm();
await sleep(1000);
assert.ok(await fse.pathExists(path.join(mavenProjectPath, "src", "main", "java", "com", "mycompany", "app2")), `New package should be created in correct path`);
await fse.remove(path.join(mavenProjectPath, "src", "main", "java", "com", "mycompany", "app2"));
});
(platform() === "darwin" ? it.skip : it)("Test java.view.package.revealInProjectExplorer", async function() {
const fileExplorerSections = await new SideBarView().getContent().getSections();
await fileExplorerSections[0].expand();
const section = await new SideBarView().getContent().getSection("Java Projects");
const packageNode = await section.findItem("com.mycompany.app") as TreeItem;
await packageNode.click();
await packageNode.collapse();
const srcNode = await fileExplorerSections[0].findItem("src") as TreeItem;
await srcNode.expand();
const folderNode = await fileExplorerSections[0].findItem("main") as TreeItem;
await folderNode.expand();
const fileNode = await fileExplorerSections[0].findItem("App.java") as TreeItem;
const menu = await fileNode.openContextMenu();
const revealItem = await menu.getItem("Reveal in Java Project Explorer");
assert.ok(revealItem, `Item "Reveal in Java Project Explorer" should be found in context menu`);
await revealItem!.click();
const classNode = await section.findItem("App") as TreeItem;
assert.ok(await classNode.isDisplayed(), `Class Node "App" should be revealed`);
await fileExplorerSections[0].collapse();
});
(platform() === "darwin" ? it.skip : it)("Test java.view.package.renameFile", async function() {
const section = await new SideBarView().getContent().getSection("Java Projects");
await section.click();
const classNode = await section.findItem("AppToRename") as TreeItem;
await classNode.click();
const menu = await classNode.openContextMenu();
const renameItem = await menu.getItem("Rename");
assert.ok(renameItem, `"Rename" item should be found`);
await renameItem!.click();
const inputBox = await InputBox.create();
await inputBox.setText("AppRenamed");
await inputBox.confirm();
await sleep(1000);
const dialog = new ModalDialog();
const buttons = await dialog.getButtons();
for (const button of buttons) {
if (await button.getText() === "OK") {
await button.click();
break;
}
}
await sleep(5000);
const editor = new TextEditor();
await editor.save();
assert.ok(await editor.getTitle() === "AppRenamed.java", `Editor's title should be "AppRenamed.java"`);
assert.ok(await section.findItem("AppRenamed"), `Item in Java Project section should be "AppRenamed"`);
});
(platform() === "darwin" ? it.skip : it)("Test java.view.package.moveFileToTrash", async function() {
const section = await new SideBarView().getContent().getSection("Java Projects");
const classNode = await section.findItem("AppToDelete") as TreeItem;
await classNode.click();
const menu = await classNode.openContextMenu();
const deleteItem = await menu.getItem("Delete");
assert.ok(deleteItem, `"Delete" item should be found`);
await deleteItem!.click();
const dialog = new ModalDialog();
const buttons = await dialog.getButtons();
for (const button of buttons) {
if (await button.getText() === "Move to Recycle Bin") {
await button.click();
break;
}
}
await sleep(1000);
assert.ok(!await fse.pathExists(path.join(mavenProjectPath, "src", "main", "java", "AppToDelete.java")), `The source file "AppToDelete.java" should be deleted`);
});
it("Test change to invisible project", async function() {
await new Workbench().executeCommand("Workspaces: Open Workspace...");
const dialog: OpenDialog = await DialogHandler.getOpenDialog();
await dialog.selectPath(invisibleWorkspacePath);
await dialog.confirm();
await sleep(1000);
const fileExplorerSections = await new SideBarView().getContent().getSections();
const folderNode = await fileExplorerSections[0].findItem("src") as TreeItem;
await folderNode.expand();
const fileNode = await fileExplorerSections[0].findItem("App.java") as TreeItem;
await fileNode.click();
await waitForImporting(1000);
const fileSections = await new SideBarView().getContent().getSections();
await fileSections[0].collapse();
await new Workbench().executeCommand("javaProjectExplorer.focus");
});
it("Test java.project.addLibraries", async function() {
const section = await new SideBarView().getContent().getSection("Java Projects");
const projectItem = await section.findItem("invisible") as TreeItem;
await projectItem.expand();
await sleep(1000);
const referencedItem = await section.findItem("Referenced Libraries") as TreeItem;
await referencedItem.click();
const buttons = await referencedItem.getActionButtons();
await buttons[0].click();
const dialog: OpenDialog = await DialogHandler.getOpenDialog();
await dialog.selectPath(path.join(invisibleProjectPath, "libSource", "simple.jar"));
await dialog.confirm();
const simpleItem = await section.findItem("simple.jar") as TreeItem;
assert.ok(simpleItem, `Library "simple.jar" should be found`);
await simpleItem!.click();
const libraryButtons = await simpleItem!.getActionButtons();
await libraryButtons[0].click();
});
it("Test java.project.addLibraryFolders", async function() {
const section = await new SideBarView().getContent().getSection("Java Projects");
const projectItem = await section.findItem("invisible") as TreeItem;
await projectItem.expand();
await sleep(1000);
let referencedItem = await section.findItem("Referenced Libraries") as TreeItem;
await referencedItem.click();
const buttons = await referencedItem.getActionButtons();
await buttons[0].getDriver().actions()
.mouseMove(buttons[0])
.keyDown(seleniumWebdriver.Key.ALT)
.click(buttons[0])
.keyUp(seleniumWebdriver.Key.ALT)
.perform();
const dialog: OpenDialog = await DialogHandler.getOpenDialog();
await dialog.selectPath(path.join(invisibleProjectPath, "libSource"));
await dialog.confirm();
await sleep(3000);
referencedItem = await section.findItem("Referenced Libraries") as TreeItem;
await referencedItem.expand();
assert.ok(await section.findItem("simple.jar"), `Library "simple.jar" should be found`);
});
it("Test java.project.create", async function() {
await fse.remove(targetPath);
await fse.ensureDir(targetPath);
await new Workbench().executeCommand("java.project.create");
let inputBox = await InputBox.create();
const picks = await inputBox.getQuickPicks();
for (const quickPick of picks) {
if (await quickPick.getLabel() === "No build tools") {
await quickPick.click();
}
}
const dialog: OpenDialog = await DialogHandler.getOpenDialog();
await dialog.selectPath(targetPath);
await dialog.confirm();
inputBox = await InputBox.create();
await inputBox.setText(newProjectName);
await inputBox.confirm();
await sleep(5000);
assert.ok(await fse.pathExists(path.join(targetPath, newProjectName, "src", "App.java")), `The template source file should be created`);
assert.ok(await fse.pathExists(path.join(targetPath, newProjectName, "README.md")), `The template README file should be created`);
});
});
async function waitForImporting(time: number) {
await new Promise<void>(async (resolve) => {
const interval = setInterval(async () => {
const item = await new StatusBar().getItem("ServiceReady");
if (item) {
clearInterval(interval);
resolve();
}
}, time);
});
}

26
test/ui/index.ts Normal file
Просмотреть файл

@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import * as os from "os";
import * as path from "path";
import { ExTester } from "vscode-extension-tester";
async function main(): Promise<void> {
try {
// Run UI command tests
const testPath = path.join(__dirname, "command.test.js");
const exTester = new ExTester();
// The current version (4.1.1) of vscode-extension-tester doesn't support the newest VSCode version (^1.58.0)
await exTester.downloadCode("1.57.0");
await exTester.installVsix();
await exTester.installFromMarketplace("redhat.java");
await exTester.downloadChromeDriver("1.57.0");
await exTester.setupRequirements({vscodeVersion: "1.57.0"});
process.exit(await exTester.runTests(testPath, {vscodeVersion: "1.57.0"}));
} catch (err) {
process.stdout.write(`${err}${os.EOL}`);
process.exit(1);
}
}
main();

6
test/util.ts Normal file
Просмотреть файл

@ -0,0 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
export async function sleep(time: number) {
await new Promise((resolve) => setTimeout(resolve, time));
}

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

@ -18,6 +18,7 @@
},
"exclude": [
"node_modules",
".vscode-test"
".vscode-test",
"test-resources"
]
}