Skip to content
This repository has been archived by the owner on Sep 24, 2019. It is now read-only.

Commit

Permalink
Programatically set OmniSharpPlugin path at dev time.
Browse files Browse the repository at this point in the history
- Integrated the path setting with functional tests and F5 experience.
  • Loading branch information
NTaylorMullen committed Apr 12, 2019
1 parent 157e4e8 commit c31fba0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 5 deletions.
19 changes: 15 additions & 4 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "never"
"reveal": "silent"
},
"dependsOn": [
"CompileClient"
"CompileClient",
"SetupTestApps"
]
},
{
Expand All @@ -26,7 +27,7 @@
"path": "src/Microsoft.AspNetCore.Razor.VSCode/",
"problemMatcher": "$tsc-watch",
"presentation": {
"reveal": "never"
"reveal": "silent"
},
"dependsOn": [
"CompileClient"
Expand All @@ -39,7 +40,17 @@
"path": "client/",
"problemMatcher": "$tsc-watch",
"presentation": {
"reveal": "never"
"reveal": "silent"
}
},
{
"label": "SetupTestApps",
"type": "npm",
"script": "setupTestApps",
"path": "client/",
"problemMatcher": "$tsc-watch",
"presentation": {
"reveal": "silent"
}
}
]
Expand Down
46 changes: 46 additions & 0 deletions build/setupTestAppSettings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// The goal of this file is to enable us to programmatically set the Razor OmniSharp plugin path. Typically when project system changes
// happen we need to wait until OmniSharp consumes those changes to properly test them. This file enables us to locate the plugin and
// then setup the test apps to use the new plugin path.

var fs = require('fs');
var path = require('path');

function findInDir(directoryPath, needle) {
if (!fs.existsSync(directoryPath)){
return;
}

var files = fs.readdirSync(directoryPath);
for (var i = 0; i < files.length; i++){
var filename = path.join(directoryPath, files[i]);

if (fs.lstatSync(filename).isDirectory()){
var result = findInDir(filename, needle);
if (result) {
return result;
}
} else if (filename.indexOf(needle) >= 0) {
return filename;
};
};
}

console.log('Reading existing .vscode/settings.json for test apps...');
var vscodeSettingsPath = '../test/testapps/.vscode/settings.json';
var bytes = fs.readFileSync(vscodeSettingsPath);
var json = JSON.parse(bytes);

console.log('Locating OmniSharp plugin dll...')
var relativePath = findInDir('../src/Microsoft.AspNetCore.Razor.OmniSharpPlugin/bin', 'Microsoft.AspNetCore.Razor.OmniSharpPlugin.dll');

if (!relativePath) {
console.warn('Warning: Could not locate OmniSharp plugin path. Falling back to installed plugin.');
} else {
var absolutePath = path.resolve(relativePath);
console.log(`Found Razor plugin dll path as '${absolutePath}'.`);
json["razor.plugin.path"] = absolutePath;
}

console.log('Saving testapps vscode settings.');
var stringifiedJson = JSON.stringify(json, /* replacer */ null, /* spaces */ 4);
fs.writeFileSync(vscodeSettingsPath, stringifiedJson);
3 changes: 2 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
}
},
"scripts": {
"setupTestApps": "node ../build/setupTestAppSettings.js",
"vscode:prepublish": "npm run compile",
"clean": "rimraf out",
"compile": "npm run clean && npm run lint && tsc -p ./",
Expand All @@ -131,7 +132,7 @@
"unittest": "npm run compile && npm run test:unitcore",
"test:unitcore": "mocha --recursive out/unittest",
"test:unitcore:watch": "mocha -r ts-node/register --recursive unittest/**/*.ts --watch --watch-extensions ts",
"test:functional": "cross-env CODE_TESTS_WORKSPACE=../test/testapps node ./node_modules/vscode/bin/test"
"test:functional": "npm run setupTestApps && cross-env CODE_TESTS_WORKSPACE=../test/testapps node ./node_modules/vscode/bin/test"
},
"devDependencies": {
"@types/mocha": "2.2.42",
Expand Down

0 comments on commit c31fba0

Please sign in to comment.