Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test github action - (DO NOT COMMIT) #1275

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
lib/**
node_modules/**
!node_modules/@salesforce/dev-config/tsconfig.json
14 changes: 8 additions & 6 deletions .eslintrc.json → .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{
"parser": "@typescript-eslint/parser",
"extends": [
module.exports = {
parser: "@typescript-eslint/parser",
extends: [
"eslint-config-salesforce-typescript",
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:sf-plugin/migration"
],
"parserOptions": {
parserOptions: {
"sourceType": "module",
"ecmaVersion": 2018,
"project": "./tsconfig.json"
"project": "./tsconfig.json",
"tsconfigRootDir": __dirname
},
"plugins": [
plugins: [
"@typescript-eslint"
]
}
26 changes: 26 additions & 0 deletions .github/workflows/gha-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: gha-test
on:
workflow_call:

pull_request:
types: [edited, opened, reopened, synchronize]

jobs:
do_the_thing:
runs-on: ubuntu-latest
name: Test the new actions
env:
NODE_OPTIONS: "--max_old_space_size=4096"
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 'lts/*' # Always use Node LTS for building dependencies.
- run: yarn
- run: yarn build
- uses: rmohan20/code-analyzer-action@main
with:
render-results: false
runtype: simple
engine: eslint-typescript
target: "./src/**/*.ts"
4 changes: 2 additions & 2 deletions .github/workflows/validate-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ jobs:
uses: ./github-actions/verify-pr-title
id: verify_pr_title
# Separately, we also need to run all of our tests.
run_tests:
uses: ./.github/workflows/run-tests.yml
# run_tests:
# uses: ./.github/workflows/run-tests.yml
34 changes: 33 additions & 1 deletion cli-messaging/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import java.awt.Desktop

plugins {
java
jacoco
}

version = "1.0"
Expand All @@ -16,16 +19,45 @@ dependencies {
}
implementation("com.google.code.gson:gson:2.10.1")
implementation("com.google.guava:guava:31.1-jre")

testImplementation("org.hamcrest:hamcrest:2.2")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.2")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.9.2")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.9.2")
}

tasks.getByName<Test>("test") {
tasks.test {
// Use JUnit 5
useJUnitPlatform()

testLogging {
events("passed", "skipped", "failed")
}
// Run tests in multiple threads
maxParallelForks = Runtime.getRuntime().availableProcessors()/2 + 1

// Report is always generated after test runs
finalizedBy(tasks.jacocoTestReport)
}

tasks.jacocoTestReport {
dependsOn(tasks.test)
}

tasks.register("showCoverageReport") {
group = "verification"
dependsOn(tasks.jacocoTestReport)
doLast {
Desktop.getDesktop().browse(File("$buildDir/reports/jacoco/test/html/index.html").toURI())
}
}

tasks.jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = BigDecimal("0.70") // TODO: We should aim to increase this
}
}
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@lwc/eslint-plugin-lwc": "^1.1.2",
"@oclif/core": "^3.3.2",
"@salesforce/core": "^5",
"@salesforce/dev-config": "^3",
"@salesforce/eslint-config-lwc": "^3.2.1",
"@salesforce/eslint-plugin-lightning": "^1.0.0",
"@salesforce/sf-plugins-core": "^5.0.4",
Expand Down Expand Up @@ -55,7 +56,6 @@
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@oclif/plugin-help": "^5",
"@salesforce/cli-plugins-testkit": "^5.0.4",
"@salesforce/dev-config": "^3",
"@salesforce/ts-sinon": "^1.1.2",
"@types/chai": "^4",
"@types/cross-spawn": "^6.0.2",
Expand Down Expand Up @@ -139,7 +139,7 @@
"lint-typescript": "eslint ./src --ext .ts --max-warnings 0",
"test": "./gradlew test jacocoTestCoverageVerification && nyc mocha --timeout 10000 --retries 5 \"./test/**/*.test.ts\"",
"test-quiet": "cross-env SFGE_LOGGING=false ./gradlew test jacocoTestCoverageVerification && nyc mocha --timeout 10000 --retries 5 \"./test/**/*.test.ts\"",
"test-cli-messaging": "./gradlew cli-messaging:test",
"test-cli-messaging": "./gradlew cli-messaging:test cli-messaging:jacocoTestCoverageVerification",
"test-pmd-cataloger": "./gradlew pmd-cataloger:test pmd-cataloger:jacocoTestCoverageVerification",
"test-sfge": "./gradlew sfge:test sfge:jacocoTestCoverageVerification",
"test-sfge-quiet": "cross-env SFGE_LOGGING=false ./gradlew sfge:test sfge:jacocoTestCoverageVerification",
Expand Down
45 changes: 34 additions & 11 deletions pmd-cataloger/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import java.awt.Desktop

plugins {
java
application
Expand Down Expand Up @@ -58,21 +60,23 @@ dependencies {
implementation ("com.googlecode.json-simple:json-simple:1.1.1") {
exclude("junit")
}
implementation("com.google.code.gson:gson:2.3")
implementation("com.google.guava:guava:28.0-jre")
testImplementation("org.mockito:mockito-core:1.+")
testImplementation("junit", "junit", "4.12")
testImplementation("org.hamcrest:hamcrest:2.1")
implementation("com.google.code.gson:gson:2.10.1")
implementation("com.google.guava:guava:31.1-jre")

testImplementation("org.mockito:mockito-core:5.2.0")
testImplementation("org.hamcrest:hamcrest:2.2")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.2")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.9.2")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.9.2")

// Used in unit tests
testImplementation(files("$buildDir/../../test/test-jars/apex/testjar-categories-and-rulesets-1.jar"))
}

configure<JavaPluginConvention> {
sourceCompatibility = JavaVersion.VERSION_1_8
}
java.sourceCompatibility = JavaVersion.VERSION_1_8

application {
mainClassName = "sfdc.sfdx.scanner.pmd.Main"
mainClass.set("sfdc.sfdx.scanner.pmd.Main");
}

// Running the cli locally needs the dist exploded, so just do that
Expand All @@ -87,18 +91,37 @@ tasks.named("assemble") {
}

tasks.test {
finalizedBy(tasks.jacocoTestReport) // Report is always generated after test runs.
// Use JUnit 5
useJUnitPlatform()

testLogging {
events("passed", "skipped", "failed")
}

// Run tests in multiple threads
maxParallelForks = Runtime.getRuntime().availableProcessors()/2 + 1

// Report is always generated after test runs
finalizedBy(tasks.jacocoTestReport)
}

tasks.jacocoTestReport {
dependsOn(tasks.test)
}

tasks.register("showCoverageReport") {
group = "verification"
dependsOn(tasks.jacocoTestReport)
doLast {
Desktop.getDesktop().browse(File("$buildDir/reports/jacoco/test/html/index.html").toURI())
}
}

tasks.jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = "0.80".toBigDecimal()
minimum = BigDecimal("0.80")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
package sfdc.sfdx.scanner.pmd;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertThat;
import static sfdc.sfdx.scanner.TestConstants.*;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static sfdc.sfdx.scanner.TestConstants.APEX;
import static sfdc.sfdx.scanner.TestConstants.JAVA;
import static sfdc.sfdx.scanner.TestConstants.SOMECAT_XML_FILE;

import java.util.Arrays;
import java.util.Map;
import java.util.Set;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import com.salesforce.messaging.EventKey;
import com.salesforce.messaging.MessagePassableException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* Unit test for {@link LanguageXmlFileMapping}
*/
public class LanguageXmlFileMappingTest {
@Rule
public ExpectedException thrown = ExpectedException.none();

private LanguageXmlFileMapping languageXmlFileMapping;

@Before
@BeforeEach
public void setup() {
languageXmlFileMapping = new LanguageXmlFileMapping();
}
Expand Down Expand Up @@ -122,10 +121,9 @@ private void testCollision(String collidingPath) {

languageXmlFileMapping.addPathsForLanguage(Arrays.asList(xmlContainer1), APEX);

thrown.expect(new MessagePassableExceptionMatcher(EventKey.ERROR_EXTERNAL_DUPLICATE_XML_PATH,
new String[] { collidingPath, jar2, jar1 }));

languageXmlFileMapping.addPathsForLanguage(Arrays.asList(xmlContainer2), APEX);
MessagePassableException ex = assertThrows(MessagePassableException.class, () -> languageXmlFileMapping.addPathsForLanguage(Arrays.asList(xmlContainer2), APEX));
assertThat(ex.getEventKey(), is(EventKey.ERROR_EXTERNAL_DUPLICATE_XML_PATH));
assertThat(ex.getArgs(), is(new String[] { collidingPath, jar2, jar1 }));
}

private void setupCategoriesAndRulesets() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package sfdc.sfdx.scanner.pmd;

import static org.junit.Assert.*;

import org.junit.Test;
import com.salesforce.messaging.MessagePassableException;
import com.salesforce.messaging.EventKey;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.util.List;
import java.util.Map;

import com.salesforce.messaging.EventKey;
import com.salesforce.messaging.MessagePassableException;
import org.junit.jupiter.api.Test;

public class MainArgsHandlingTest {

final Main main = new Main();
Expand All @@ -24,13 +26,13 @@ public void verifyHappyCase() {
final Map<String, List<String>> stringListMap = main.parseArguments(args);

// Validate
assertEquals("Unexpected number of items in parsed map", 1, stringListMap.size());
assertTrue("Language not found in parsed map", stringListMap.containsKey(language));
assertEquals(1, stringListMap.size(), "Unexpected number of items in parsed map");
assertTrue(stringListMap.containsKey(language), "Language not found in parsed map");

final List<String> parsedPaths = stringListMap.get(language);
assertEquals("Unexpected number of paths in parsed map", paths.length, parsedPaths.size());
assertEquals(paths.length, parsedPaths.size(), "Unexpected number of paths in parsed map");
for (String path : paths) {
assertTrue("Path not found in parsed map: " + path, parsedPaths.contains(path));
assertTrue(parsedPaths.contains(path), "Path not found in parsed map: " + path);
}
}

Expand Down Expand Up @@ -73,8 +75,8 @@ private void testParseArgForErrorHandling(String[] args, String expectedArgForMe
main.parseArguments(args);
fail(failureMessage);
} catch (MessagePassableException e) {
assertEquals("Unexpected eventKey on exception", EventKey.ERROR_INTERNAL_MAIN_INVALID_ARGUMENT, e.getEventKey());
assertEquals("Unexpected arg list on exception", expectedArgForMessage, e.getArgs()[0]);
assertEquals(EventKey.ERROR_INTERNAL_MAIN_INVALID_ARGUMENT, e.getEventKey(), "Unexpected eventKey on exception");
assertEquals(expectedArgForMessage, e.getArgs()[0], "Unexpected arg list on exception");
}
}
}
Loading
Loading