no23reason / jest-trx-results-processor Goto Github PK
View Code? Open in Web Editor NEWJest results processor for exporting into TRX files for Visual Studio
License: MIT License
Jest results processor for exporting into TRX files for Visual Studio
License: MIT License
codeBase should provide the actual fill path of test suite file. Currently, codeBase and Name are providing same string.
codeBase should provide name of actual file name of test suite containing the test case.
this can be provided using below code:
// Build variables for suite name
const filepath = path.relative('./', testRunResult.testFilePath);
const filename = path.basename(filepath);
Configuration
I am using your package tor publish my test results to Azure Devops. The way I am using it is the following:
package.json
, under jest
-configuration"testResultsProcessor": "<rootDir>/jestTrxProcessor.js"
jestTrxProcessor.js
-file looks like the following:var builder = require('jest-trx-results-processor');
var processor = builder({
outputFile: 'jestTestResults.trx'
});
module.exports = processor;
Problem
I want to skip processing the trx when running locally. Now it is being run on every test. I instead want it to run only when Azure Devops
runs the tests. How is the best way to do this? When reading the readme it states that this is not the prefered way to run your package and will be removed. Does the newer configuration method support running only on CI? Or is that a configuration to set in jest itself?
Hi
I have created a new pull request will all the changes suggested by you:
https://github.com/deepakkamboj/jest-trx-results-processor/pull/5
Please commit this PR in your repository:
https://github.com/no23reason/jest-trx-results-processor
Please create a new NPM package from the above pull request.
Jest no longer supports testResultsProcessor
(see jest-community/jest-junit#56). Looks like the new configuration syntax should look something like this:
{
"jest": {
"reporters": ["default", "jest-trx-results-processor"]
}
}
or
{
"jest": {
"reporters": [
"default",
["jest-trx-results-processor", { "outputFile": "./myFile.trx" }]
]
}
}
I've tried this in Jest 23.6 but it did not produce any outcome, as if jest-trx-results-processor
was not used at all. What can be missing?
In the duration
attribute of UnitTestResultduration
element, there is only the total milliseconds, not formatted duration.
It is working well for me.
My results are coming through as package "(root)". Could there be a way, perhaps in the builder({}) object, where I can specify a package name? I might want to put "(Javascript tests)" or something similar there. Alternatively, you could just hard code "Jest tests", perhaps.
I am using a jest runner that will execute a suite of tests multiple times in parallel. I'd like to be able to have the results-processor output a different trx file for each of these executions, possibly based off an environment variable.
Would it be possible to allow it's output filename to be overwritten as such?
export JEST_TRX_FILE="$BROWSER"-results.trx
When run locally it works fine. The .trx file is created where I expect it to.
The same tests run in docker causes the error
Missing attribute value for attribute runUser of element TestRun
The following error is throw if you have a test file where are the tests are filtered out with the -t
flag:
RangeError: Invalid time value
at Date.toISOString (<anonymous>)
at ...\test\node_modules\jest-trx-results-processor\dist\trx-generator.js:121:103
at Array.forEach (<anonymous>)
at ...\test\node_modules\jest-trx-results-processor\dist\trx-generator.js:95:37
at Array.forEach (<anonymous>)
at Object.exports.generateTrx (...\test\node_modules\jest-trx-results-processor\dist\trx-generator.js:92:31)
at ...\test\node_modules\jest-trx-results-processor\dist\index.js:11:35
at processResults (...\test\node_modules\jest-cli\build\run_jest.js:62:55)
at ...\test\node_modules\jest-cli\build\run_jest.js:155:12
at Generator.next (<anonymous>)
Jest version: ^21.2.1, jest-trx-results-processor: ^0.0.5
Steps to reproduce: create one spec file with one test
test("first", function () {
expect(2).toEqual(2);
});
Run the test with a non matching filter e.g. jest -t "second"
During our test runs some of tests might produce some artifacts, like screenshots, logs, etc. Since VSTest supports attachments, I wonder if it would be possible to add this feature to this reporter?
I receive a require not defined
TypeError: require(...) is not a function
at processResults (C:\Users\jesse.lay\Desktop\new app\versaweb_2019_edition\node_modules\jest-cli\build\runJest.js:126:55)
at C:\Users\jesse.lay\Desktop\new app\versaweb_2019_edition\node_modules\jest-cli\build\runJest.js:211:12
at Generator.next ()
at step (C:\Users\jesse.lay\Desktop\new app\versaweb_2019_edition\node_modules\jest-cli\build\runJest.js:1:260)
at C:\Users\jesse.lay\Desktop\new app\versaweb_2019_edition\node_modules\jest-cli\build\runJest.js:1:420
at
at process._tickCallback (internal/process/next_tick.js:188:7)
"scripts": {
"start": "node scripts/start.js",
"build": "node scripts/build.js",
"test": "node scripts/test.js --env=jsdom --json",
"test:ci": "jest --coverage"
},
"jest": {
"testResultsProcessor": "./scripts/jestTrxProcessor",
"collectCoverageFrom": [
"src//*.{js,jsx,mjs}"
],
"setupFiles": [
"/config/polyfills.js"
],
"testMatch": [
"/src//tests//*.{js,jsx,mjs}",
"/src//?(.)(spec|test).{js,jsx,mjs}"
],
"testEnvironment": "node",
"testURL": "http://localhost",
"transform": {
"^.+\.(js|jsx|mjs)$": "/node_modules/babel-jest",
"^.+\.css$": "/config/jest/cssTransform.js",
"^(?!.\.(js|jsx|mjs|css|json)$)": "/config/jest/fileTransform.js"
},
"transformIgnorePatterns": [
"[/\\]node_modules[/\\].+\.(js|jsx|mjs)$"
],
"moduleNameMapper": {
"^react-native$": "react-native-web"
},
"moduleFileExtensions": [
"web.js",
"js",
"json",
"web.jsx",
"jsx",
"node",
"mjs"
]
config
reporters: [
'default',
[
'jest-trx-results-processor',
{
outputFile: 'test_results/resulting.trx', // defaults to "test-results.trx"
// "defaultUserName": "user name to use if automatic detection fails" // defaults to "anonymous"
},
],
],
result
Error: ENOENT: no such file or directory, open 'test_results/resulting.trx'
at Object.openSync (fs.js:439:3)
at Object.writeFileSync (fs.js:1190:35)
at TrxReporter.onRunComplete (.../node_modules/jest-trx-results-processor/dist/index.js:15:18)
at .../node_modules/jest/node_modules/jest-cli/build/ReporterDispatcher.js:89:27
at Generator.next (<anonymous>)
at step (.../node_modules/jest/node_modules/jest-cli/build/ReporterDispatcher.js:13:30)
at .../node_modules/jest/node_modules/jest-cli/build/ReporterDispatcher.js:24:15
at process._tickCallback (internal/process/next_tick.js:68:7)
If I create the folder manually before running it works fine.
Although the test suite passes and the trx file is created successfully, npm gives the following error and makes the pipeline fail:
Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: 7.523s, estimated 8s Ran all test suites. DONE TRX file output to 'test-results.trx' TypeError: Cannot set property 'onRunComplete' of undefined at TrxReporter (C:\Repo\SystemTestsSolution\node_modules\jest-trx-results-processor\dist\index.js:26:28) at Object.<anonymous> (C:\Repo\SystemTestsSolution\jestTrxProcessor.js:3:17) at Module._compile (internal/modules/cjs/loader.js:956:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10) at Module.load (internal/modules/cjs/loader.js:812:32) at Function.Module._load (internal/modules/cjs/loader.js:724:14)
It's currently guessed at by claiming that each test of n
takes 1/n
th of the time of the full suite:
export const getSuitePerTestDuration = (testSuiteResult: TestResult): number =>
// take the total duration of suite and divide it by the number of tests
// (Jest does not provide per test performance info)
Math.floor(
(testSuiteResult.perfStats.end - testSuiteResult.perfStats.start) /
(testSuiteResult.numPassingTests +
testSuiteResult.numFailingTests +
testSuiteResult.numPendingTests +
testSuiteResult.numTodoTests),
);
But it seems the comment is wrong these days, as Jest has an AssertionResult.duration?: number
field:
export type AssertionResult = {
ancestorTitles: Array<string>;
duration?: Milliseconds | null | undefined;
failureMessages: Array<string>;
fullName: string;
invocations?: number;
location: Callsite | null | undefined;
numPassingAsserts: number;
status: Status;
title: string;
};
Trying to run jest
from command line having reporter set to jest-trx-results-processor
jest --reporters=jest-trx-results-processor
ends up with error
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined at validateString (internal/validators.js:113:11) at Object.resolve (path.js:139:9) at TrxReporter.onRunComplete (C:\Git\client\node_modules\jest-trx-results-processor\dist\index.js:20:67)
Currently, this results processor outputs a "Skipped" outcome for any tests which are marked to be skipped. However, this does not match what karma-trx-reporter outputs or what Visual Studio's api lists (see outcome property of Add test results to a test run section). Both list the outcome should be NotExecuted for skipped tests.
Can we switch the outcome of skipped tests to be NotExecuted instead of Skipped to align with the above? I can submit a PR for this if it sounds good.
.att(
"startTime",
new Date(
testSuiteResult.perfStats.start + runningDuration,
).toISOString(),
)
.att(
"endTime",
new Date(
testSuiteResult.perfStats.start + runningDuration,
).toISOString(),
)
Should not add runningDuration for startTime
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.