Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…re-aria into refactor/305-restructure-vrops-components

Signed-off-by: Stefan Genov <[email protected]>
  • Loading branch information
Michaelpalacce committed Jan 16, 2025
2 parents 61f43b5 + 4ad97a6 commit 6df96d4
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 5 deletions.
13 changes: 13 additions & 0 deletions docs/versions/latest/Release.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,17 @@ This is just an internal restructuring effort, no functionality was changed.

## Upgrade procedure

### *Dynamic type definitions for the unit tests framework.*

The package name and version of the type definitions are being installed dynamically based on the configuration of the solution.
This ensures the type definitions available for type hinting / autocomplete in the IDE and for the transpilation are matching the actual code definitions of the unit test framework.

#### Previous Behavior

The type definitions installed were always the same package and version - the [BTVA built-in Jasmine definitions](https://github.com/vmware/build-tools-for-vmware-aria/tree/v3.1.1/vro-types/jasmine) (link is to v3.1.1, might be outdated at later point in time).

#### New Behavior

The configuration in the pom file affects both the framework being used and its type definitions being made available.

[//]: # (Explain in details if something needs to be done)
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.File;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;

/**
* Executes the external project's dependency list.
Expand All @@ -50,30 +51,48 @@ public abstract class AbstractInstallNodeDepsMojo extends AbstractIacMojo {
@Override
public final void execute() throws MojoExecutionException, MojoFailureException {
boolean allTgzLibsResolved = true;
int commandLength = 0;
File nodeModules = new File(project.getBasedir(), "node_modules");
if (skipInstallNodeDeps) {
if (nodeModules.exists()) {
getLog().info("Skipping the Dependency installation");
return;
} else {
getLog().info("Ignoring the flag skipInstallNodeDeps,"
+
"as node dependencies doesn't exist and are required for the successful build...");
+ "as node dependencies doesn't exist and are required for the successful build...");
}
}

if (!nodeModules.exists()) {
getLog().debug("node_modules doesn't exists. Creating it...");
nodeModules.mkdirs();
}


// TODO: Think of a way to put the logic for unit test framework in one place instead of two separate components.
// Checking if there's specific unit test framework specified. If there is - it will be added to the dependencies list.
// If not - the default Jasmine type definitions will be kept from the original dependencies list.

Properties projectProperties = project.getProperties();
String unitTestFrameworkPackage = projectProperties.getProperty("test.framework.package");
String unitTestFrameworkVersion = projectProperties.getProperty("test.framework.version");
String unitTestFrameworkTypes = projectProperties.getProperty("test.framework.types.version");
boolean useDefaultUnitTestFramework = unitTestFrameworkPackage == null
|| unitTestFrameworkPackage.equals(new String("jasmine")) && unitTestFrameworkVersion == null;

getLog().debug("unitTestFrameworkPackage => " + unitTestFrameworkPackage);
getLog().debug("unitTestFrameworkVersion => " + unitTestFrameworkVersion);
getLog().debug("unitTestFrameworkTypes => " + unitTestFrameworkTypes);

List<String> deps = new LinkedList<>();

for (Object o : project.getArtifacts()) {
Artifact a = (Artifact) o;
if ("tgz".equals(a.getType())) {

if (
!useDefaultUnitTestFramework
&& a.getArtifactId().equals(new String("jasmine"))
) {
continue;
}
deps.add(a.getFile().getAbsolutePath());
allTgzLibsResolved = allTgzLibsResolved && a.isResolved();
}
Expand Down Expand Up @@ -111,6 +130,54 @@ public final void execute() throws MojoExecutionException, MojoFailureException

String npmExec = SystemUtils.IS_OS_WINDOWS ? "npm.cmd" : "npm";

// Add a dependency for the unit test framework type
// definitions according to the project configuration.
if (!useDefaultUnitTestFramework) {
if (unitTestFrameworkVersion == null) {
getLog().info(
"No specific versions of the unit testing framework received, will be using the"
+ " latest available for both the framework dependency and its type definitions."
);
unitTestFrameworkTypes = "latest";
unitTestFrameworkVersion = "latest";
} else if (unitTestFrameworkTypes == null) {
if (unitTestFrameworkVersion.equals(new String("latest"))) {
unitTestFrameworkTypes = "latest";
} else {
int dotPosition = unitTestFrameworkVersion.lastIndexOf('.');
getLog().warn("dotPosition: " + dotPosition);
unitTestFrameworkTypes = unitTestFrameworkVersion.substring(0, dotPosition) + ".X";
}
getLog().warn(
"Received specific version for the unit testing framework, but not for its type definitions, "
+ "attempting to use [" + unitTestFrameworkTypes + "], generated from the framework version. "
+ "Please, be aware the type definitions are handled by the DefinitelyTyped project "
+ "(https://definitelytyped.org/). In case there are any issues with installing the generated types "
+ "version, please try specifying which version should be applied."
);
} else {
getLog().warn(
"Received specific versions for unit test framework and framework type definition,"
+ " will attempt to install those. Please, be aware these need to be a proper match"
+ " and are handled by the DefinitelyTyped project (https://definitelytyped.org/)."
);
}

unitTestFrameworkPackage = unitTestFrameworkPackage != null ? unitTestFrameworkPackage : "jasmine";
String unitTestFrameworkTypeDefsPackage = "@types/" + unitTestFrameworkPackage + "@" + unitTestFrameworkTypes;

getLog().info(
"Adding dependency to be installed for the unit tests framework "
+ "type definitions: " + unitTestFrameworkTypeDefsPackage
);

List<String> framework = new LinkedList<>();
framework.add(unitTestFrameworkTypeDefsPackage);
dependencies.add(framework);
}

// Idea: Should we separate dependencies as dev deps and regular ones?

for (List<String> dependency: dependencies) {
getLog().debug("Dependency size: " + dependency.size());
dependency.add(0, npmExec);
Expand Down
4 changes: 4 additions & 0 deletions typescript/vrotest/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ Supported properties:
- `test.framework.version` - the version of the framework npm package to use, should be one of the versions available for the specified framework npm package. If not provided will use:
- `^4.0.2` for `jasmine` for backward comaptibility.
- `latest` for `jest`.
- `test.framework.types.version` - optional value, will be used to install a specific version of the type definitions for the unit test framework. This is related to the [DefinitelyTyped project](https://definitelytyped.org/) and the versions need to be aligned with the available ones originating from it. If not value is provided:
- And the Jasmine framework is used with the default framework version, the solution will install the default type definitions as well - ensures backward compatibility.
- If the latest version of any framework is used the solution will install the latest available type definitions for it.
- If a specific version of any framework is used the solution will attempt to install the `major.minor.X` version of the type definitions. In case there is no such version, the user needs to specify which version should be used via the `test.framework.types.version` property.
- `test.framework.runner` - enables using a specific runner, currently only used for `jest`, optional, supported values: `swc`, if omitted will use the default runner.
- `test.framework.jasmine.reporters.version` - version of the Jasmine reporters package to use when using the `jasmine` option for the framework selection, optional, defaults to `^2.5.2` for backward compatibility if omitted.
- `test.ansicolors.version` - The `ansi-colors` npm package is used in the Jasmine reporters configured for the tests, optional, defaults to `^4.1.1` for backward compatibility if omitted.
Expand Down

0 comments on commit 6df96d4

Please sign in to comment.