Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Adapt plugin to use new language test API #5

Merged
merged 50 commits into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
cc0a865
Update meta.yaml
svor Aug 5, 2020
cc402f7
update plugin
svor Aug 5, 2020
2b7300c
Merge branch 'master' of https://github.com/svor/che-java-tests
svor Aug 5, 2020
45396b7
update plugin
svor Aug 5, 2020
7086b4e
update plugin
svor Aug 7, 2020
8d72d4d
Update plugin
svor Aug 7, 2020
8d06ae3
Update meta.yaml
svor Aug 7, 2020
c8a45e3
update plugin
svor Aug 11, 2020
5b0364e
Merge branch 'master' of https://github.com/svor/che-java-tests
svor Aug 11, 2020
d01d0d1
update plugin
svor Aug 11, 2020
d053bc2
update plugin
svor Aug 11, 2020
b07cd85
update plugin
svor Aug 11, 2020
31960a0
update plugin
svor Aug 11, 2020
cdfee4f
Update tests
svor Aug 20, 2020
14e7c21
Update meta.yaml
svor Aug 20, 2020
99335eb
Update parent dir
svor Aug 20, 2020
33c44c9
Update plugin
svor Aug 20, 2020
420154f
Update meta.yaml
svor Aug 20, 2020
c119277
Update plugin
svor Aug 20, 2020
ceeedd3
Update meta.yaml
svor Aug 20, 2020
1d88f94
Update plugin
svor Aug 20, 2020
19d5ac3
Update plugin
svor Aug 20, 2020
1883357
Update devfile
svor Aug 20, 2020
b125d60
Update plugin
svor Aug 20, 2020
ac6e84a
Update plugin
svor Aug 20, 2020
f89924f
Update plugin
svor Aug 20, 2020
1f55627
Update plugin
svor Aug 20, 2020
b9a0f66
Update plugin
svor Aug 20, 2020
9a7f43f
Update plugin
svor Aug 20, 2020
3e1203e
Update plugin
svor Aug 20, 2020
d5a5ee8
Update plugin
svor Aug 20, 2020
cc2021a
Update plugin
svor Aug 20, 2020
bc1b122
Update plugin
svor Aug 20, 2020
3013961
Update plugin
svor Aug 20, 2020
1b9857f
Update plugin
svor Aug 20, 2020
df1baa6
Update plugin
svor Aug 21, 2020
306cec7
Update plugin
svor Aug 21, 2020
9e915c2
Update plugin
svor Aug 21, 2020
955f6e6
Update plugin
svor Aug 21, 2020
ebe9544
Update plugin
svor Aug 21, 2020
7408050
Update plugin
svor Aug 21, 2020
3ffb887
Update plugin
svor Aug 21, 2020
b957bf1
Adapt plugin to use new API
svor Sep 2, 2020
2462c94
code cleanup
svor Sep 2, 2020
cdeda90
fix license
svor Sep 2, 2020
ce92b64
Update plugin activation
svor Sep 3, 2020
c4de289
code cleanup
svor Sep 3, 2020
8846b85
Code cleanup
svor Sep 3, 2020
44956d9
Update src/test-reporter.ts
svor Sep 3, 2020
bdac012
Update src/test-reporter.ts
svor Sep 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,3 @@ In order to do this you'll need a few things:

The idea is that when you start a workspace with your devfile the testWorkspace will be the root of the application
and the tests will be loaded into mocha and executed against the current running workspace.

#### Possible Improvements
Currently because of https://github.com/eclipse/che/issues/15826 we are restricted on some tests we could make. For instance,
once this feature resolves we can activate the extension from inside the tests and then check whether
[vscode-java extension api](https://github.com/redhat-developer/vscode-java/blob/master/src/extension.api.ts#L14) is set to
"Started" or "Error".
Binary file modified che_java_test_theia_plugin.theia
Binary file not shown.
9 changes: 2 additions & 7 deletions devfile.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
apiVersion: 1.0.0
metadata:
name: che-java-sample-tests
projects:
- name: che-java-test-theia-plugin
source:
location: 'https://github.com/jpinkney/che-java-test-theia-plugin.git'
type: git
components:
- id: redhat/java8/latest
- id: redhat/java11/latest
type: chePlugin
- reference: https://raw.githubusercontent.com/JPinkney/Che-Java-Tests/master/meta.yaml
- reference: https://raw.githubusercontent.com/che-incubator/che-java-tests/master/meta.yaml
type: chePlugin
- type: cheEditor
id: eclipse/che-theia/next
Expand Down
7 changes: 4 additions & 3 deletions meta.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

apiVersion: v2
publisher: Red Hat
name: Java-Smoke-Test-Plugin
Expand All @@ -7,9 +8,9 @@ displayName: Java Smoke Test Plugin
title: Java-Smoke-Test-Plugin
description: This plug-in runs Java tests against vscode-java inside of your workspace
icon: https://www.eclipse.org/che/images/logo-eclipseche.svg
repository: https://github.com/jpinkney/Che-Java-Tests
repository: https://github.com/che-incubator/che-java-tests
category: Language
firstPublicationDate: "2020-01-07"
firstPublicationDate: "2020-08-20"
spec:
extensions:
- https://github.com/JPinkney/Che-Java-Tests/raw/master/che_java_test_theia_plugin.theia
- https://github.com/che-incubator/che-java-tests/raw/master/che_java_test_theia_plugin.theia
63 changes: 41 additions & 22 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*********************************************************************
* Copyright (c) 2019 Red Hat, Inc.
* Copyright (c) 2020 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -25,33 +25,52 @@ export function start(context: theia.PluginContext): void {
mocha.useColors(true);

const e = (c: any) => console.log(c);

ncp(context.extensionPath, '/projects/Che-Java-Tests', (err: any) => {
ncp(context.extensionPath, '/projects/Che-Java-Tests', async (err: any) => {
if (err) {
return console.error(err);
}

theia.workspace.findFiles('**/tests/*.test.ts', undefined).then(files => {
console.log("Found: ");
console.log(files);

// Add files to the test suite
files.forEach(f => mocha.addFile(path.resolve(f.path)));

try {
// Run the mocha test
mocha.run((failures: any) => {
if (failures > 0) {
e(new Error(`${failures} tests failed.`));
}
});
} catch (err) {
e(err);
}
});
});
await activateJavaLSPlugin();

const testFiles = await theia.workspace.findFiles('**/tests/*.test.ts', undefined)
console.log("Found: ");
console.log(testFiles);

// Add files to the test suite
testFiles.forEach(f => mocha.addFile(path.resolve(f.path)));

try {
// Run the mocha test
mocha.run((failures: any) => {
theia.window.showInformationMessage('Tests completed! See results in test.log file');
const resultFile = path.resolve('/projects', 'test.log');
theia.commands.executeCommand('file-search.openFile', resultFile)
if (failures > 0) {
e(new Error(`${failures} tests failed.`));
}
});
} catch (err) {
e(err);
}
});
}

async function activateJavaLSPlugin(): Promise<void> {
const files = await theia.workspace.findFiles('MyHelloText.java', undefined, 1);
if (files.length != 1) {
throw new Error('Cannot find java file');
}
const file = files[0];
const textDocument = await theia.workspace.openTextDocument(file);
if (!textDocument) {
throw new Error('Cannot open java file');
}
let plugin = theia.plugins.getPlugin('redhat.java');
if (plugin) {
return await plugin.activate()
} else {
throw new Error('No redhat.java plugin');
}
}

export function stop() {
Expand Down
16 changes: 13 additions & 3 deletions src/test-reporter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*********************************************************************
* Copyright (c) 2020 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/

import Mocha from 'mocha';
module.exports = StreamLogReporter;

Expand Down Expand Up @@ -25,12 +35,12 @@ function StreamLogReporter(runner: any) {
});

runner.on('end', function() {
if (failures === 0) {
if (failures > 0) {
console.log('FINISH: %d/%d', passes, passes + failures);
writeStream.write(`TESTS FAILED: ${passes}/${passes + failures}`);
writeStream.write(`TESTS FAILED: ${passes}/${passes + failures}\n`);
} else {
console.log('FINISH: %d/%d', passes, passes + failures);
writeStream.write(`TESTS PASSED: ${passes}/${passes + failures}`);
writeStream.write(`TESTS PASSED: ${passes}/${passes + failures}\n`);
}
});
}
35 changes: 17 additions & 18 deletions tests/commands.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*********************************************************************
* Copyright (c) 2019 Red Hat, Inc.
* Copyright (c) 2020 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -8,7 +8,7 @@
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/

import * as vscode from '@theia/plugin';
import * as theia from '@theia/plugin';
import { strict as assert } from 'assert';
import { closeAllOpenFiles, getSrcDocUri } from './helper';

Expand All @@ -20,40 +20,39 @@ describe('Test that vscode-java commands are working successfully', () => {

before('Make sure vscode-java is activated', async () => {
const myHelloTextURI = getSrcDocUri('MyHelloText.java');
await vscode.window.showTextDocument(myHelloTextURI);
await theia.window.showTextDocument(myHelloTextURI);
closeAllOpenFiles();
});

it('Test Java Open all log files', async () => {

// Ensure all files are closed
closeAllOpenFiles();

// Then check if the serverLog command opens the server log
await vscode.commands.executeCommand(serverLogCmd);
const isServerLogFileOpen = vscode.window.visibleTextEditors.filter(editor => editor.document.fileName === '.log');
// Then check if the serverLog command opens both the client log and the server log
await theia.commands.executeCommand(openAllLogs);
const isServerLogFileOpen = theia.window.visibleTextEditors.filter(editor => editor.document.fileName === '.log');
assert.ok(isServerLogFileOpen);
const isClientLogFileOpen = theia.window.visibleTextEditors.filter(editor => editor.document.fileName.startsWith('client.log'));
assert.ok(isClientLogFileOpen);
});

it('Test Java Open all log files', async () => {
it('Test Java Open server log file', async () => {
// Ensure all files are closed
closeAllOpenFiles();

// Then check if the serverLog command opens the client log
await vscode.commands.executeCommand(clientLogCmd);
const isClientLogFileOpen = vscode.window.visibleTextEditors.filter(editor => editor.document.fileName.startsWith('client.log'));
assert.ok(isClientLogFileOpen);
// Then check if the serverLog command opens the server log
await theia.commands.executeCommand(serverLogCmd);
const isServerLogFileOpen = theia.window.visibleTextEditors.filter(editor => editor.document.fileName === '.log');
assert.ok(isServerLogFileOpen);
});

it('Test Java Open all log files', async () => {
it('Test Java Open client log file', async () => {
// Ensure all files are closed
closeAllOpenFiles();

// Then check if the serverLog command opens both the client log and the server log
await vscode.commands.executeCommand(openAllLogs);
const isServerLogFileOpen = vscode.window.visibleTextEditors.filter(editor => editor.document.fileName === '.log');
assert.ok(isServerLogFileOpen);
const isClientLogFileOpen = vscode.window.visibleTextEditors.filter(editor => editor.document.fileName.startsWith('client.log'));
// Then check if the clientLog command opens the client log
await theia.commands.executeCommand(clientLogCmd);
const isClientLogFileOpen = theia.window.visibleTextEditors.filter(editor => editor.document.fileName.startsWith('client.log'));
assert.ok(isClientLogFileOpen);
});

Expand Down
13 changes: 5 additions & 8 deletions tests/helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*********************************************************************
* Copyright (c) 2019 Red Hat, Inc.
* Copyright (c) 2020 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -9,15 +9,12 @@
**********************************************************************/

import * as path from 'path';
import * as vscode from '@theia/plugin';
import * as theia from '@theia/plugin';

export const extensionID = 'redhat.java';

export function closeAllOpenFiles() {
vscode.window.visibleTextEditors.map(file => vscode.commands.executeCommand('workbench.action.closeActiveEditor', file.document.uri));
theia.window.visibleTextEditors.map(file => theia.commands.executeCommand('workbench.action.closeActiveEditor', file.document.uri));
}
export async function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
export const getSrcDocPath = (p: string) => path.resolve(__dirname, '../testWorkspace/src/main/java/org/my/sample', p);
export const getSrcDocUri = (p: string) => vscode.Uri.file(getSrcDocPath(p));
export const getSrcDocPath = (p: string) => path.resolve('/projects/Che-Java-Tests/testWorkspace/src/main/java/org/my/sample', p);
export const getSrcDocUri = (p: string) => theia.Uri.file(getSrcDocPath(p));
Loading