Skip to content

Commit

Permalink
fix: improve validations (#173)
Browse files Browse the repository at this point in the history
- Issues in mta.yaml are now marked as errors
- Path validation is removed (since the path can be created during the
  build)
- Yaml syntax highlighting for mtaext files

Fix:
- mta executable is downloaded if not available for the purpose of
  validations (it's still required for generators)

Tests:
- Remove unnecessary test (it failed in environments where mbt is installed)
- Add new test
- Fix coverage on windows (coverage does not work on Windows when 
  mocha runs in parallel: mochajs/mocha#4372)
  • Loading branch information
tal-sapan committed Jan 19, 2021
1 parent 9b77e30 commit 64e2b7a
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -81,4 +81,4 @@ dist
out
*.vsix


unpacked_bin
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -22,8 +22,8 @@ Make sure the following tools are installed in your environment:
- [Cloud MTA Build Tool](https://github.com/SAP/cloud-mta-build-tool) to build MTA project.
- [Cloud Foundry CLI](https://github.com/cloudfoundry/cli) to work with Cloud Foundry.
- [MultiApps CF CLI Plugin](https://github.com/cloudfoundry-incubator/multiapps-cli-plugin) to deploy MTA archive to Cloud Fountry.
- [MTA tool](https://github.com/SAP/cloud-mta) for exploring and validating the multitarget application descriptor.
- [Yeoman-ui extension](https://github.com/SAP/yeoman-ui) to work with wizard.
- [MTA tool](https://github.com/SAP/cloud-mta) to add MTA modules.
- [Yeoman-ui extension](https://github.com/SAP/yeoman-ui) to add MTA modules.

### Download and Installation

Expand Down
50 changes: 43 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions package.json
Expand Up @@ -22,7 +22,8 @@
"*"
],
"extensionDependencies": [
"sapos.yeoman-ui"
"sapos.yeoman-ui",
"vscode.yaml"
],
"main": "./dist/extension.js",
"contributes": {
Expand All @@ -33,6 +34,14 @@
"label": "Validate MTA development descriptor and extension files"
}
],
"languages": [
{
"id": "yaml",
"extensions": [
".mtaext"
]
}
],
"jsonValidation": [
{
"fileMatch": [
Expand Down Expand Up @@ -127,8 +136,8 @@
"format:validate": "prettier --check --ignore-path .gitignore \"**/*.@(ts|js|json|md|yml)\"",
"lint": "eslint . --ext .ts --fix --max-warnings=0",
"build": "vsce package",
"test": "nyc mocha -p tsconfig.json",
"coverage:check": "nyc mocha -p tsconfig.json",
"test": "nyc mocha",
"coverage:check": "nyc mocha",
"vscode:prepublish": "webpack --mode production",
"webpack": "webpack --mode development",
"webpack:watch": "webpack --mode development --watch"
Expand All @@ -139,7 +148,7 @@
"fs-extra": "9.0.1",
"@vscode-logging/logger": "1.2.2",
"@sap/swa-for-sapbas-vsx": "1.1.11",
"@sap/mta-lib": "1.6.5"
"@sap/mta-lib": "1.6.6"
},
"devDependencies": {
"@commitlint/cli": "11.0.0",
Expand All @@ -158,6 +167,7 @@
"chai": "4.2.0",
"conventional-changelog-cli": "2.1.1",
"conventional-recommended-bump": "6.1.0",
"copy-webpack-plugin": "7.0.0",
"cz-conventional-changelog": "3.3.0",
"eslint": "7.17.0",
"eslint-config-prettier": "7.1.0",
Expand Down
6 changes: 0 additions & 6 deletions tests/commands/mtaBuildCommand.spec.ts
Expand Up @@ -217,10 +217,4 @@ describe("MTA build command unit tests", () => {
windowMock.expects("showErrorMessage").withExactArgs(messages.INSTALL_MBT);
await mtaBuildCommand.mtaBuildCommand(selected as Uri, swa);
});

it("mtaBuildCommand - tracking throws error", async () => {
sandbox.stub(SWATracker.prototype, "track").throws(new Error("error"));
tasksMock.expects("executeTask").never();
await mtaBuildCommand.mtaBuildCommand(selected as Uri, swa);
});
});
18 changes: 18 additions & 0 deletions tests/utils/utils.spec.ts
Expand Up @@ -6,6 +6,7 @@ import * as sinon from "sinon";
import { Utils } from "../../src/utils/utils";
import { SelectionItem } from "../../src/utils/selectionItem";
import { IChildLogger } from "@vscode-logging/logger";
import * as fsExtra from "fs-extra";

describe("Utils unit tests", () => {
const path1 = "some/path/to/file1";
Expand Down Expand Up @@ -94,6 +95,23 @@ describe("Utils unit tests", () => {
expect(response).to.equal(undefined);
});

it("getConfigFileField - fetch field from existing config file", async () => {
utilsMock
.expects("getConfigFilePath")
.once()
.returns("path/to/existing/file");
// Converting SinonStub because it takes the wrong overload
((sinon.stub(fsExtra, "readFile") as unknown) as sinon.SinonStub<
[string, string],
Promise<string>
>)
.withArgs("path/to/existing/file", "utf8")
.resolves(`{"field1":"field1_value"}`);

const response = await Utils.getConfigFileField("field1", loggerImpl);
expect(response).to.equal("field1_value");
});

it("getFilePaths - get paths of a non windows platform", () => {
const filePaths = [{ path: path1 } as Uri, { path: path2 } as Uri];
sandbox.stub(Utils, "isWindows").returns(false);
Expand Down
22 changes: 22 additions & 0 deletions webpack.config.js
@@ -1,6 +1,8 @@
"use strict";

const path = require("path");
const fs = require("fs");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const distPath = path.resolve(__dirname, "dist");

/**@type {import('webpack').Configuration}*/
Expand Down Expand Up @@ -36,5 +38,25 @@ const config = {
},
],
},
// Enable cloud-mta usage via auto-download, see https://github.com/SAP/cloud-mta#packaging-with-webpack
node: {
__dirname: false,
},
plugins: [
// Enable cloud-mta usage via auto-download, see https://github.com/SAP/cloud-mta#packaging-with-webpack
new CopyWebpackPlugin({
patterns: [
{
from: path.join(require.resolve("mta-local"), "..", "bin"),
to: path.resolve(distPath, "bin"),
},
],
}),
function (compiler) {
compiler.hooks.done.tap("ExecuteChmodOnBinMta", () => {
fs.chmodSync(path.resolve(distPath, "bin", "mta"), "755");
});
},
],
};
module.exports = config;

0 comments on commit 64e2b7a

Please sign in to comment.