-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Migrate Jest JUnit reporter to TS #79919
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
96b0329
Converts Jest JUnit reporter to TS
e958847
Merge branch 'master' of github.com:elastic/kibana into pr/79919
spalger d2414ce
coalesce new package versions with existing installs
spalger 07ada94
Updates yarn.lock
2974e9a
Merge branch 'master' into jest-reporter
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
export * from './junit_reporter'; | ||
|
||
export * from './report_path'; |
37 changes: 37 additions & 0 deletions
37
packages/kbn-test/src/jest/integration_tests/__fixtures__/jest.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
const { resolve } = require('path'); | ||
const { REPO_ROOT } = require('@kbn/utils'); | ||
|
||
module.exports = { | ||
reporters: [ | ||
'default', | ||
[ | ||
`${REPO_ROOT}/packages/kbn-test/target/jest/junit_reporter`, | ||
{ | ||
reportName: 'JUnit Reporter Integration Test', | ||
rootDirectory: resolve( | ||
REPO_ROOT, | ||
'packages/kbn-test/src/jest/integration_tests/__fixtures__' | ||
), | ||
}, | ||
], | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,20 +22,31 @@ import { writeFileSync, mkdirSync } from 'fs'; | |
|
||
import xmlBuilder from 'xmlbuilder'; | ||
|
||
import { escapeCdata, makeJunitReportPath } from '@kbn/test'; | ||
import type { Config } from '@jest/types'; | ||
import { AggregatedResult, Test, BaseReporter } from '@jest/reporters'; | ||
|
||
const ROOT_DIR = dirname(require.resolve('../../../package.json')); | ||
import { escapeCdata } from '../mocha/xml'; | ||
import { makeJunitReportPath } from './report_path'; | ||
|
||
interface ReporterOptions { | ||
reportName?: string; | ||
rootDirectory?: string; | ||
} | ||
|
||
/** | ||
* Jest reporter that produces JUnit report when running on CI | ||
* @class JestJUnitReporter | ||
*/ | ||
export default class JestJUnitReporter { | ||
constructor(globalConfig, options = {}) { | ||
const { reportName = 'Jest Tests', rootDirectory = ROOT_DIR } = options; | ||
|
||
this._reportName = reportName; | ||
this._rootDirectory = resolve(rootDirectory); | ||
// eslint-disable-next-line import/no-default-export | ||
export default class JestJUnitReporter extends BaseReporter { | ||
private _reportName: string; | ||
private _rootDirectory: string; | ||
|
||
constructor(globalConfig: Config.GlobalConfig, { rootDirectory, reportName }: ReporterOptions) { | ||
super(); | ||
this._reportName = reportName || 'Jest Tests'; | ||
this._rootDirectory = rootDirectory ? resolve(rootDirectory) : resolve(__dirname, '../..'); | ||
} | ||
|
||
/** | ||
|
@@ -44,7 +55,7 @@ export default class JestJUnitReporter { | |
* @param {JestResults} results see https://facebook.github.io/jest/docs/en/configuration.html#testresultsprocessor-string | ||
* @return {undefined} | ||
*/ | ||
onRunComplete(contexts, results) { | ||
onRunComplete(contexts: Set<Test['context']>, results: AggregatedResult): void { | ||
if (!process.env.CI || process.env.DISABLE_JUNIT_REPORTER || !results.testResults.length) { | ||
return; | ||
} | ||
|
@@ -55,18 +66,19 @@ export default class JestJUnitReporter { | |
'testsuites', | ||
{ encoding: 'utf-8' }, | ||
{}, | ||
{ skipNullAttributes: true } | ||
{ keepNullAttributes: false } | ||
); | ||
|
||
const msToIso = (ms) => (ms ? new Date(ms).toISOString().slice(0, -5) : undefined); | ||
const msToSec = (ms) => (ms ? (ms / 1000).toFixed(3) : undefined); | ||
const msToIso = (ms: number | null | undefined) => | ||
ms ? new Date(ms).toISOString().slice(0, -5) : undefined; | ||
const msToSec = (ms: number | null | undefined) => (ms ? (ms / 1000).toFixed(3) : undefined); | ||
|
||
root.att({ | ||
name: 'jest', | ||
timestamp: msToIso(results.startTime), | ||
time: msToSec(Date.now() - results.startTime), | ||
tests: results.numTotalTests, | ||
failures: results.numFailingTests, | ||
failures: results.numFailedTests, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was incorrect property. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😱 |
||
skipped: results.numPendingTests, | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was incorrect option.