2

As far as I can see, the salesforce/sfdx-lwc-jest LWC JavaScript test framework does not support the simple TAP (Test Anything Protocol) output format that CI (Continuous Integration) servers such as Jenkins can easily consume and merge into their overall summary of test results.

(I've posted a request for this format here https://github.com/salesforce/sfdx-lwc-jest/issues/128.)

By the way, the formats are close e.g. TAP:

1..2
ok 1 - Input file opened
not ok 2 - First line of the input valid

and sfdx-lwc-jest output:

PASS force-app/main/default/lwc/progress/__tests__/progress.base.test.js
FAIL force-app/main/default/lwc/baseStep/__tests__/baseStep.test.js

Or is there some hidden way to configure that output format before I start writing a sed script?

1 Answer 1

1

The answer is yes.

Got a super quick answer here:

https://github.com/salesforce/sfdx-lwc-jest/issues/128

to use:

https://github.com/MailOnline/jest-tap-reporter

I couldn't get it to work just configuring in package.json but this did work:

"scripts": {
    "test:unit": "sfdx-lwc-jest -- --reporters='jest-tap-reporter'"
},

On reflection I'm going to use the JUnit format via https://www.npmjs.com/package/jest-junit. So in `package.json':

"scripts": {
    "test:unit": "sfdx-lwc-jest -- --reporters=default --reporters=jest-junit"
}

and then to run (inside https://claimvantage.github.io/sfdx-jenkins-shared-library/ but basically wrapped shell commands):

afterTestStage: {  org ->

    echo "${org.name} running LWC tests"

    // Install LWC test runner and JUnit reporter; config is in package.json and perhaps dependency should be too
    shWithStatus "npm install @salesforce/sfdx-lwc-jest --save-dev"
    shWithStatus "npm install jest-junit --save-dev"

    // Test result folder
    sh "mkdir -p ${env.WORKSPACE}/tests/${env.BUILD_NUMBER}/${org.name}"

    // Run tests - deliberately no status check so build doesn't fail immediately; klunky reporter option passing via environment variables
    sh returnStatus: true, script: "JEST_JUNIT_OUTPUT_DIR='${env.WORKSPACE}/tests/${env.BUILD_NUMBER}/${org.name}' JEST_JUNIT_OUTPUT_NAME='test-result-lwc-junit.xml' npm run test:unit"

    // Prefix class name with target org to separate the test results
    sh returnStatus: true, script: "sed -i -- 's/classname=\"/classname=\"${org.name}./g' ${env.WORKSPACE}/tests/${env.BUILD_NUMBER}/${org.name}/test-result-lwc-junit.xml/"
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.