Skip to content

Commit 5560fb4

Browse files
committed
FYP-44: updated the way we build and run tests
1 parent c95d930 commit 5560fb4

18 files changed

+249
-126
lines changed

.vscode/launch.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"--extensionDevelopmentPath=${workspaceFolder}"
4141
],
4242
"outFiles": [
43-
"${workspaceFolder}/out/**/*.js"
43+
"${workspaceFolder}/out/src/**/*.js"
4444
],
4545
"preLaunchTask": "${defaultBuildTask}"
4646
},
@@ -50,10 +50,10 @@
5050
"request": "launch",
5151
"args": [
5252
"--extensionDevelopmentPath=${workspaceFolder}",
53-
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
53+
"--extensionTestsPath=${workspaceFolder}/out/src/test/suite/index"
5454
],
5555
"outFiles": [
56-
"${workspaceFolder}/out/test/**/*.js"
56+
"${workspaceFolder}/out/src/test/**/*.js"
5757
],
5858
"preLaunchTask": "${defaultBuildTask}"
5959
}

azure-pipelines.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,10 @@ steps:
4141
- script: yarn --frozen-lockfile
4242
displayName: Install Dependencies
4343

44-
- script: yarn compile
45-
displayName: Build Extension
46-
4744
- script: yarn serve
4845
displayName: Build Language Server
4946

50-
- script: yarn run pretest
51-
displayName: Pre-test
52-
53-
- bash: node ./out/test/runTest.js
54-
displayName: Run Tests
47+
- script: yarn run test
48+
displayName: Build & Test
49+
env:
50+
DISPLAY: ':99.0'

package.json

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,21 @@
1414
"activationEvents": [
1515
"onLanguage:java"
1616
],
17-
"main": "./out/extension.js",
17+
"main": "./out/src/extension.js",
1818
"scripts": {
1919
"vscode:prepublish": "yarn run build && yarn run test",
2020
"compile": "tsc -p ./",
21-
"serve": "mvn clean install",
22-
"build": "yarn run lint && yarn run compile && mvn clean install",
21+
"build": "mvn clean install",
2322
"lint": "eslint --fix \"**/*.{js,ts,tsx}\"",
24-
"pretest": "rm -rf out/test/suite/test && cp -R src/test/suite/test out/test/suite/test",
25-
"test": "yarn run build && yarn run pretest && node ./out/test/runTest.js",
26-
"watch": "tsc -watch -p ./"
23+
"test": "sh test.sh",
24+
"watch": "tsc -watch -p ./ "
2725
},
2826
"devDependencies": {
2927
"@types/flat": "^5.0.1",
3028
"@types/glob": "^7.1.3",
3129
"@types/mocha": "^8.2.0",
3230
"@types/node": "^12.11.7",
31+
"@types/prettier": "^2.2.1",
3332
"@types/vscode": "^1.50.0",
3433
"@typescript-eslint/eslint-plugin": "^4.1.1",
3534
"@typescript-eslint/parser": "^4.1.1",
@@ -40,7 +39,7 @@
4039
"mocha": "^8.1.3",
4140
"string-hex": "^1.0.0",
4241
"typescript": "^4.0.2",
43-
"vscode-test": "^1.4.0"
42+
"vscode-test": "^1.5.1"
4443
},
4544
"dependencies": {
4645
"deepdash": "^5.3.2",
@@ -80,14 +79,14 @@
8079
".java",
8180
".class"
8281
],
83-
"configuration": "./language-configuration.json"
82+
"configuration": "./out/src/syntaxes/language-configuration.json"
8483
}
8584
],
8685
"grammars": [
8786
{
8887
"language": "java",
8988
"scopeName": "source.java",
90-
"path": "./syntaxes/java.tmLanguage.json"
89+
"path": "./out/src/syntaxes/java.tmLanguage.json"
9190
}
9291
],
9392
"configuration": {

src/commands/displaySyntaxTree.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ require('deepdash')(_);
1010
export function displaySyntaxTree() {
1111
const editor = getEditor();
1212
const code = editor.document.getText();
13-
if (typeof code !== 'string') {
14-
throw Error('Was unable to read code!');
15-
}
1613

1714
// Get the last part of the filename (after the last slash), e.g. Refactor.java
1815
const filename = editor.document.fileName.substring(
@@ -38,7 +35,7 @@ export function displaySyntaxTree() {
3835
throw Error(error.message);
3936
}
4037

41-
ast = _.filterDeep(ast, (value, key, parent) => {
38+
ast = _.filterDeep(ast, (value: any, key: any, parent: any) => {
4239
if (value !== null) {
4340
if (Array.isArray(value) && value.length === 0) {
4441
return false;

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function activate(context: vscode.ExtensionContext) {
2323

2424
let classPath = path.join(
2525
__dirname,
26-
'..',
26+
'../../',
2727
'launcher',
2828
'target',
2929
'launcher.jar',
File renamed without changes.

src/test/runTest.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,20 @@ async function main() {
66
try {
77
// The folder containing the Extension Manifest package.json
88
// Passed to `--extensionDevelopmentPath`
9-
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
9+
const extensionDevelopmentPath = path.resolve(__dirname, '../../../');
1010

11-
// The path to the extension test script
11+
// The path to the extension test runner script
1212
// Passed to --extensionTestsPath
1313
const extensionTestsPath = path.resolve(__dirname, './suite/index');
1414

1515
// Download VS Code, unzip it and run the integration test
16-
await runTests({ extensionDevelopmentPath, extensionTestsPath });
16+
await runTests({
17+
extensionDevelopmentPath,
18+
extensionTestsPath,
19+
launchArgs: ['--disable-extensions'],
20+
});
1721
} catch (err) {
22+
console.error(err);
1823
console.error('Failed to run tests');
1924
process.exit(1);
2025
}

src/test/suite/extension.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ suite('Extension Test Suite', () => {
1616
'DiogoTheCoder.make-java-great-again',
1717
)!;
1818

19-
textDocument = await activate(FILE_PATH);
19+
textDocument = await activate(ext, FILE_PATH);
2020
assert.strictEqual(textDocument.lineCount > 0, true);
2121
assert.strictEqual(ext.isActive, true);
2222

23-
const text = textDocument.getText();
24-
2523
await sleep(5000);
2624

2725
const diagnostics = vscode.languages.getDiagnostics(textDocument.uri);

src/test/suite/helper.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import * as vscode from 'vscode';
2-
import { TextDocument } from 'vscode';
2+
import { Extension, TextDocument } from 'vscode';
33
import path from 'path';
44

55
export let doc: vscode.TextDocument;
66
export let editor: vscode.TextEditor;
77

8-
export async function activate(filePath: string): Promise<TextDocument> {
9-
const ext = vscode.extensions.getExtension(
10-
'DiogoTheCoder.make-java-great-again',
11-
)!;
12-
13-
await ext.activate();
8+
export async function activate(
9+
extension: Extension<any>,
10+
filePath: string,
11+
): Promise<TextDocument> {
12+
await extension.activate();
1413
try {
1514
doc = await vscode.workspace.openTextDocument(filePath);
1615
editor = await vscode.window.showTextDocument(doc);
@@ -25,7 +24,7 @@ export async function activate(filePath: string): Promise<TextDocument> {
2524
export function getDocPath(relativePath: string) {
2625
// Resolve Windows nonsense
2726
relativePath = relativePath.replace('%3A', '');
28-
return path.join(__dirname, `test/src/${relativePath}`);
27+
return path.join(__dirname, `java/src/${relativePath}`);
2928
}
3029

3130
export async function sleep(ms: number) {

src/test/suite/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export function run(): Promise<void> {
66
// Create the mocha test
77
const mocha = new Mocha({
88
ui: 'tdd',
9+
color: true,
910
timeout: 60 * 60 * 1000,
1011
});
1112

File renamed without changes.
File renamed without changes.

src/typings/mulang.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare module 'mulang';

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function writeCode(code: string): void {
2626

2727
const formattedCode = prettier.format(code, {
2828
parser: 'java',
29-
tabWidth: editor.options.tabSize,
29+
tabWidth: Number.parseInt(editor.options.tabSize?.toString() ?? '4', 10),
3030
});
3131

3232
const updateCode = new vscode.TextEdit(wholeDocument, formattedCode);

test.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
# Clear out the old compiled TS files
4+
rm -rf out/
5+
6+
# Run tsc -p ./
7+
yarn run compile
8+
9+
# Copy over the syntaxes folder (JSON files) to the out
10+
cp -a src/syntaxes out/src/syntaxes
11+
12+
# Copy over the App.java used for testing
13+
mkdir -p "out/src/test/suite/java"
14+
cp -r src/test/suite/java/. out/src/test/suite/java
15+
16+
# And run the tests!
17+
node ./out/src/test/runTest.js

tsconfig.json

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,16 @@
44
"module": "commonjs",
55
"target": "es2019",
66
"outDir": "out",
7-
"lib": [
8-
"ES2019"
9-
],
7+
"lib": ["ES2019"],
108
"sourceMap": true,
11-
"rootDir": "src",
129
"strict": true,
1310
"composite": true,
1411
"esModuleInterop": true,
1512
"suppressImplicitAnyIndexErrors": true,
16-
"noImplicitAny": false,
1713
"skipLibCheck": true,
14+
"resolveJsonModule": true,
15+
"allowJs" : true,
1816
},
19-
"include": [
20-
"src"
21-
],
22-
"exclude": [
23-
"node_modules",
24-
"./node_modules",
25-
"./node_modules/*",
26-
"./node_modules/@types/node/index.d.ts",
27-
"**/out/**",
28-
".vscode-test"
29-
]
17+
"include": ["./src/**/*"],
18+
"exclude": ["node_modules", ".vscode-test", "out"]
3019
}

0 commit comments

Comments
 (0)