Object returned from GitVersion not consistent - gitversion

Is it normal that the object returned by the GitVersion alias is different if I specify 'OutputType' vs omitting this setting?
If I specify the output type, the properties of the returned object are all 'null' but when I omit the setting, the properties are set to expected values
For example:
Task("Version")
.Does(() =>
{
var versionInfo = GitVersion(new GitVersionSettings()
{
UpdateAssemblyInfo = true,
OutputType = GitVersionOutput.BuildServer
});
Information("MajorMinorPatch: {0}", versionInfo.MajorMinorPatch);
Information("FullSemVer: {0}", versionInfo.FullSemVer);
Information("InformationalVersion: {0}", versionInfo.InformationalVersion);
Information("LegacySemVer: {0}", versionInfo.LegacySemVer);
Information("Nuget v1 version: {0}", versionInfo.NuGetVersion);
Information("Nuget v2 version: {0}", versionInfo.NuGetVersionV2);
});
The output is:
MajorMinorPatch: [NULL]
FullSemVer: [NULL]
InformationalVersion: [NULL]
LegacySemVer: [NULL]
Nuget v1 version: [NULL]
Nuget v2 version: [NULL]
If I change my task like so:
Task("Version")
.Does(() =>
{
var versionInfo = GitVersion(new GitVersionSettings()
{
UpdateAssemblyInfo = false
});
Information("MajorMinorPatch: {0}", versionInfo.MajorMinorPatch);
Information("FullSemVer: {0}", versionInfo.FullSemVer);
Information("InformationalVersion: {0}", versionInfo.InformationalVersion);
Information("LegacySemVer: {0}", versionInfo.LegacySemVer);
Information("Nuget v1 version: {0}", versionInfo.NuGetVersion);
Information("Nuget v2 version: {0}", versionInfo.NuGetVersionV2);
});
The output is:
MajorMinorPatch: 0.1.0
FullSemVer: 0.1.0+1
InformationalVersion: 0.1.0+1.Branch.master.Sha.5b2
LegacySemVer: 0.1.0
Nuget v1 version: 0.1.0
Nuget v2 version: 0.1.0

This is "by-design".
https://github.com/cake-build/cake/blob/develop/src/Cake.Common/Tools/GitVersion/GitVersionRunner.cs#L71
GitVersion has a default output type of JSON, which means that the JSON output which contains all the asserted version numbers is available for inspection. At this point, Cake collects this JSON output, combines them into a GitVersion object, and returns that to the Cake script.
When you use OutputType = GitVersionOutput.BuildServer there is no JSON output. Instead, GitVersion works with the Build Server that it is running on, whether that is TeamCity, AppVeyor, or whatever, and makes the asserted version numbers available via another mechanism. i.e. either via setting environment variables, or using service messages to tell the build server about this. As a result, there is nothing really for Cake to consume to create the GitVersion object for returning.
The typical way around this would be to first run GitVersion with OutputType = GitVersionOutput.BuildServer and then immediately run it again, and use the returned variables. This is actually what we do within our own Cake script:
https://github.com/cake-build/cake/blob/develop/build/version.cake#L38
Running this a second time should actually be very quick, as GitVersion actually caches the result of the first run. There might actually be something that we can do in Cake to read this cached output, and use that as the output of the call. Would you be able to raise this as an issue here so we can track it?

Related

Karate - When i run a basic feature with get call, i get karate exception as INSTANCE on the line where get is called [duplicate]

I'm trying use karate for e2e tests and have started with a minimal setup. I want to create some config items in karate-config.js for use in the tests but karate is reporting that file is not a js function and hence the test fails trying to get the config:
Warning: Nashorn engine is planned to be removed from a future JDK release
12:16:35.264 [Test worker] WARN com.intuit.karate - not a js function or feature file: read('classpath:karate-config.js') - [type: NULL, value: null]
---------------------------------------------------------
feature: classpath:karate/insurer.feature
scenarios: 1 | passed: 0 | failed: 1 | time: 0.0163
---------------------------------------------------------
HTML report: (paste into browser to view) | Karate version: 0.9.1
file:/Users/srowatt/dev/repos/api/price-service/build/surefire-reports/karate.insurer.html
---------------------------------------------------------
-unknown-:4 - javascript evaluation failed: priceBaseUrl, ReferenceError: "priceBaseUrl" is not defined in <eval> at line number 1
org.opentest4j.AssertionFailedError: -unknown-:4 - javascript evaluation failed: priceBaseUrl, ReferenceError: "priceBaseUrl" is not defined in <eval> at line number 1
This is my karate-config.js:
function fn() {
return {
priceBaseUrl: "http://localhost:8080"
};
}
This is my insurer.feature test:
Feature: which creates insurers
Background:
* url priceBaseUrl
* configure logPrettyRequest = true
* configure logPrettyResponse = true
Scenario: basic roundtrip
# create a new insurer
Given path 'insurers'
And request { name: 'Sammy Insurance', companyCode: '99' }
When method post
Then status 201
And match response == { resourceId: '#number', version: 0, createdBy: 'anonymousUser' }
* def insurerId = response.resourceId
# get insurer by resource id
Given path 'insurers', insurerId
When method get
Then status 200
And match response == { id: '#(id)', name: 'Sammy Insurance', companyCode: '99' }
This is the InsurerTest.java test runner:
package karate;
import com.intuit.karate.junit5.Karate;
class InsurerTest {
#Karate.Test
public Karate testInsurer() {
return new Karate().feature("classpath:karate/insurer.feature");
}
}
Please use below code in the karate-config.js
function() {
return priceBaseUrl='http://localhost:8080';
}
When I see this:
Warning: Nashorn engine is planned to be removed from a future JDK release
I suspect you are on Java 9 or 11 ? To be honest, we haven't fully tested Karate on those versions of Java yet. Would it be possible for you to confirm that Java 8 (maybe 9 / 10 also) is OK.
That said, we are interested in resolving this as soon as possible, so if you can submit a sample project where we can replicate this, please do so: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue
EDIT: Karate 1.0 will use GraalVM instead of Nashorn and will run on even JDK 16: https://software-that-matters.com/2021/01/27/7-new-features-in-karate-test-automation-version-1_0/

Gauge Tags from my gauge gradle task is not being passed to beforespec

I have an issue where tags from my gauge gradle task is not being passed to beforespec whereas the the tags are passed to spec files
Any idea what is the issue?
I'm in Gauge version: 0.9.1
Plugins
html-report (3.1.0)
java (0.6.2)
gradle gauge task :
task runTestsInQA(type: GaugeTask) {
doFirst {
println 'Running tests for the V1 in QA environment...'
gauge {
specsDir = 'specs'
tags = 'V1'
env = 'qa'
additionalFlags = '--verbose'
}
}
}
_
My beforespec code:
#beforespec(tags = "V1")
public void beforeSpec(ExecutionContext context)
{
System.out.println("Tags in scenario "+context.getAllTags());
}
Here, print statement is throwing null array [ ]
This gist contains an example project with gauge + java + gradle.
In your case, note that the BeforeSpec hook is a tagged execution hook, so it will get executed only when the respective tags are passed.
Also note that if you wish to get tags for a scenario, you are better off using the BeforeScenario hook, since you can then get all the tags (scenarios inherit spec tags).

How to make 'testPattern' mandatory while updating snapshots in Jest?

Snapshot testing comes handy for testing UI components. If your UI component changes, you are expected to update the snapshot as well to reflect the same. We can specify 'testNamePattern' to update snapshots for a specific test.
jest --updateSnapshot --testNamePattern abc.test.js
Is it possible to mandate 'testNamePattern' while updating snapshots? This will help avoid updating other failing snapshots by mistake. I understand that it is expected to be caught in code review phase. However, I want to ensure that snapshots are always updated for a specific pattern.
As of now, there isn't any CLI option for doing this per doc. I have added a small snippet to my testFrameworkScriptFile to ensure that testNamePattern is passed while updating snapshots.
import yargs from 'yargs';
const mandateTestNamePattern = () => {
const args = yargs.option('testNamePattern', {
type: 'string'
}).option('t', {
type: 'string'
}).argv;
if (args.updateSnapshot || args.u) {
if (args.testNamePattern || args.t) {
// valid case
} else {
throw new Error('TestNamePattern is mandatory while updating snapshots');
}
}
};
mandateTestNamePattern();

When overriding default configuration for Date Serialization, it becomes missing in the JSON example in metadata pages

I am attempting to override the default DateTime serialization with the following code:
JsConfig<DateTime>.SerializeFn = d =>
{
return d.ToString("o") + "Z";
};
JsConfig<DateTime>.RawSerializeFn = d =>
{
return d.ToString("o") + "Z";
};
(not sure the diff between SerializeFn and RawSerializeFn so i tried both to be sure...I also tried implementing the DeserializeFn in case they both needed to be overwritten, but saw some results)
Anyways... everytime I try this, any date members in our DTOs goes missing in the sample request/response JSON on the metadata pages. (date members still show in the Parameters section though).
I am using SS v4.0.40.0
PS: I later realized that my whole goal of appending "Z" to all DateTimes could be accomplished with this configuration:
JsConfig.DateHandler = DateHandler.ISO8601;
JsConfig.AssumeUtc = true;
JsConfig.AppendUtcOffset = false;
but I still wanted to file this bug - Thanks!
The DateTime serialization can't be changed in isolation, if you take over serializing to an unsupported custom format you'll also need to handle deserializing it with the appropriate RawDeserializeFn/DeserializeFn configuration.
You can also handle parsing unknown DateTime formats by registering a ParseError callback, i.e:
DateTimeSerializer.OnParseErrorFn = (dateTimeStr, ex) => //DateTime;
If you want to file an issue with any ServiceStack libraries, upgrade to the latest version of ServiceStack to ensure it's still an issue, if it is please submit it to github.com/ServiceStack/Issues with a sample code/failing test that reproduces the issue.

How to Report Results to Sauce Labs using Geb/Spock?

I want to use the Sauce Labs Java REST API to send Pass/Fail status back to the Sauce Labs dashboard. I am using Geb+Spock, and my Gradle build creates a test results directory where results are output in XML. My problem is that the results XML file doesn't seem to be generated until after the Spock specification's cleanupSpec() exits. This causes my code to report the results of the previous test run, rather than the current one. Clearly not what I want!
Is there some way to get to the results from within cleanupSpec() without relying on the XML? Or a way to get the results to file earlier? Or some alternative that will be much better than either of those?
Some code:
In build.gradle, I specify the testResultsDir. This is where the XML file is written after the Spock specifications exit:
drivers.each { driver ->
task "${driver}Test"(type: Test) {
cleanTest
systemProperty "geb.env", driver
testResultsDir = file("$buildDir/test-results/${driver}")
systemProperty "proj.test.resultsDir", testResultsDir
}
}
Here is the setupSpec() and cleanupSpec() in my LoginSpec class:
class LoginSpec extends GebSpec {
#Shared def SauceREST client = new SauceREST("redactedName", "redactedKey")
#Shared def sauceJobID
#Shared def allSpecsPass = true
def setupSpec() {
sauceJobID = driver.getSessionId().toString()
}
def cleanupSpec() {
def String specResultsDir = System.getProperty("proj.test.resultsDir") ?: "./build/test-results"
def String specResultsFile = this.getClass().getName()
def String specResultsXML = "${specResultsDir}/TEST-${specResultsFile}.xml"
def testsuiteResults = new XmlSlurper().parse( new File( specResultsXML ))
// read error and failure counts from the XML
def errors = testsuiteResults.#errors.text()?.toInteger()
def failures = testsuiteResults.#failures.text()?.toInteger()
if ( (errors + failures) > 0 ) { allSpecsPass = false }
if ( allSpecsPass ) {
client.jobPassed(sauceJobID)
} else {
client.jobFailed(sauceJobID)
}
}
}
The rest of this class contains login specifications that do not interact with SauceLabs. When I read the XML, it turns out that it was written at the end of the previous LoginSpec run. I need a way to get to the values of the current run.
Thanks!
Test reports are generated after a Specification has finished execution and the generation is performed by the build system, so in your case by Gradle. Spock has no knowledge of that so you are unable to get that information from within the test.
You can on the other hand quite easily get that information from Gradle. Test task has two methods that might be of interest to you here: addTestListener() and afterSuite(). It seems that the cleaner solution here would be to use the first method, implement a test listener and put your logic in afterSuite() of the listener (and not the task configuration). You would probably need to put that listener implementation in buildSrc as it looks like you have a dependency on SauceREST and you would need to build and compile your listener class before being able to use it as an argument to addTestListener() in build.gradle of your project.
Following on from erdi's suggestion, I've created a Sauce Gradle helper library, which provides a Test Listener that parses the test XML output and invokes the Sauce REST API to set the pass/fail status.
The library can be included by adding the following to your build.gradle file:
import com.saucelabs.gradle.SauceListener
buildscript {
repositories {
mavenCentral()
maven {
url "https://repository-saucelabs.forge.cloudbees.com/release"
}
}
dependencies {
classpath group: 'com.saucelabs', name: 'saucerest', version: '1.0.2'
classpath group: 'com.saucelabs', name: 'sauce_java_common', version: '1.0.14'
classpath group: 'com.saucelabs.gradle', name: 'sauce-gradle-plugin', version: '0.0.1'
}
}
gradle.addListener(new SauceListener("YOUR_SAUCE_USERNAME", "YOUR_SAUCE_ACCESS_KEY"))
You will also need to output the Selenium session id for each test, so that the SauceListener can associate the Sauce Job with the pass/fail status. To do this, include the following output in the stdout:
SauceOnDemandSessionID=SELENIUM_SESSION_ID

Resources