Skip to content

Commit 9f0b858

Browse files
authored
Add JavaScript implementation (#42)
1 parent 4b5ddd5 commit 9f0b858

24 files changed

+5054
-55
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text eol=lf

.github/workflows/release-npm.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Release NPM
2+
3+
on:
4+
push:
5+
branches: [release/*]
6+
7+
jobs:
8+
publish-npm:
9+
name: Publish NPM module
10+
runs-on: ubuntu-latest
11+
environment: Release
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-node@v4
15+
with:
16+
node-version: '22'
17+
cache: 'npm'
18+
cache-dependency-path: javascript/package-lock.json
19+
- run: npm install-test
20+
working-directory: javascript
21+
- uses: cucumber/action-publish-npm@v1.1.1
22+
with:
23+
npm-token: ${{ secrets.NPM_TOKEN }}
24+
working-directory: javascript

.github/workflows/test-javascript.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: test-javascript
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- renovate/**
8+
pull_request:
9+
branches:
10+
- main
11+
workflow_call:
12+
13+
jobs:
14+
test-javascript:
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
os:
20+
- ubuntu-latest
21+
node-version: ["18.x", "20.x", "22.x"]
22+
include:
23+
- os: windows-latest
24+
node-version: "22.x"
25+
- os: macos-latest
26+
node-version: "22.x"
27+
28+
steps:
29+
- uses: actions/checkout@v4
30+
31+
- name: with Node.js ${{ matrix.node-version }} on ${{ matrix.os }}
32+
uses: actions/setup-node@v4
33+
with:
34+
node-version: ${{ matrix.node-version }}
35+
cache: "npm"
36+
cache-dependency-path: javascript/package-lock.json
37+
38+
- run: npm install-ci-test
39+
working-directory: javascript

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99

1010
### Added
11-
- Update dependency io.cucumber:messages up to v26 ((#38)[https://github.com/cucumber/query/pull/38])
11+
- JavaScript implementation ([#42](https://github.com/cucumber/junit-xml-formatter/pull/42))
12+
- Update dependency io.cucumber:messages up to v26 ([#38](https://github.com/cucumber/junit-xml-formatter/pull/38))
13+
14+
### Fixed
15+
- Attempts that have been superseded by retries are now omitted from the report ([#42](https://github.com/cucumber/junit-xml-formatter/pull/42))
1216

1317
## [0.5.0] - 2024-06-22
1418
### Added

java/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<dependency>
5757
<groupId>io.cucumber</groupId>
5858
<artifactId>query</artifactId>
59-
<version>[12.2.0,13.0.0)</version>
59+
<version>[13.0.2,14.0.0)</version>
6060
</dependency>
6161

6262
<dependency>

java/src/main/java/io/cucumber/junitxmlformatter/XmlReportData.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,19 @@ int getTestCaseCount() {
6060
return query.findAllTestCaseStarted().size();
6161
}
6262

63-
String getPickleName(TestCaseStarted testCaseStarted) {
64-
Pickle pickle = query.findPickleBy(testCaseStarted)
63+
private Pickle getPickle(TestCaseStarted testCaseStarted) {
64+
return query.findPickleBy(testCaseStarted)
6565
.orElseThrow(() -> new IllegalStateException("No pickle for " + testCaseStarted.getId()));
66+
}
6667

67-
return query.findNameOf(pickle, namingStrategy);
68+
String getPickleName(TestCaseStarted testCaseStarted) {
69+
return query.findNameOf(getPickle(testCaseStarted), namingStrategy);
6870
}
6971

7072
String getFeatureName(TestCaseStarted testCaseStarted) {
7173
return query.findFeatureBy(testCaseStarted)
7274
.map(Feature::getName)
73-
.orElseThrow(() -> new IllegalStateException("No feature for " + testCaseStarted));
75+
.orElseGet(() -> this.getPickle(testCaseStarted).getUri());
7476
}
7577

7678
List<Entry<String, String>> getStepsAndResult(TestCaseStarted testCaseStarted) {
@@ -119,7 +121,7 @@ List<TestCaseStarted> getAllTestCaseStarted() {
119121
private static final TestStepResult SCENARIO_WITH_NO_STEPS = new TestStepResult(ZERO_DURATION, null, PASSED, null);
120122

121123
TestStepResult getTestCaseStatus(TestCaseStarted testCaseStarted) {
122-
return query.findMostSevereTestStepResulBy(testCaseStarted)
124+
return query.findMostSevereTestStepResultBy(testCaseStarted)
123125
.orElse(SCENARIO_WITH_NO_STEPS);
124126
}
125127

java/src/main/java/io/cucumber/junitxmlformatter/XmlReportWriter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ private void writeSuiteAttributes(EscapingXmlStreamWriter writer) throws XMLStre
5656
Map<TestStepResultStatus, Long> counts = data.getTestCaseStatusCounts();
5757

5858
writer.writeAttribute("tests", String.valueOf(data.getTestCaseCount()));
59-
writer.writeAttribute("skipped", counts.getOrDefault(SKIPPED, 0L).toString());
59+
writer.writeAttribute("skipped", counts.get(SKIPPED).toString());
6060
writer.writeAttribute("failures", String.valueOf(countFailures(counts)));
6161
writer.writeAttribute("errors", "0");
6262
}
6363

6464
private static long countFailures(Map<TestStepResultStatus, Long> counts) {
65-
return createNotPassedNotSkippedSet().stream().mapToLong(s -> counts.getOrDefault(s, 0L)).sum();
65+
return createNotPassedNotSkippedSet().stream().mapToLong(counts::get).sum();
6666
}
6767

6868
private static EnumSet<TestStepResultStatus> createNotPassedNotSkippedSet() {

javascript/.eslintrc.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"node": true
5+
},
6+
"parser": "@typescript-eslint/parser",
7+
"parserOptions": {
8+
"project": "tsconfig.json",
9+
"sourceType": "module"
10+
},
11+
"plugins": [
12+
"import",
13+
"simple-import-sort",
14+
"n",
15+
"@typescript-eslint"
16+
],
17+
"extends": [
18+
"eslint:recommended",
19+
"plugin:import/typescript",
20+
"plugin:@typescript-eslint/eslint-recommended",
21+
"plugin:@typescript-eslint/recommended",
22+
"plugin:prettier/recommended"
23+
],
24+
"rules": {
25+
"import/no-cycle": "error",
26+
"n/no-extraneous-import": "error",
27+
"@typescript-eslint/ban-ts-ignore": "off",
28+
"@typescript-eslint/ban-ts-comment": "off",
29+
"@typescript-eslint/explicit-module-boundary-types": "off",
30+
"@typescript-eslint/explicit-function-return-type": "off",
31+
"@typescript-eslint/no-use-before-define": "off",
32+
"@typescript-eslint/interface-name-prefix": "off",
33+
"@typescript-eslint/member-delimiter-style": "off",
34+
"@typescript-eslint/no-explicit-any": "error",
35+
"@typescript-eslint/no-non-null-assertion": "error",
36+
"simple-import-sort/imports": "error",
37+
"simple-import-sort/exports": "error"
38+
}
39+
}

javascript/.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
dist/
2+
.idea/
3+
.nyc_output/
4+
coverage/
5+
node_modules/
6+
yarn.lock
7+
*.log
8+
.deps
9+
.tested*
10+
.linted
11+
.built*
12+
.compared
13+
.codegen
14+
acceptance/
15+
storybook-static
16+
*-go
17+
*.iml
18+
.vscode-test
19+
20+
# stryker temp files
21+
.stryker-tmp
22+
reports

javascript/.mocharc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"loader": "ts-node/esm",
3+
"extension": ["ts"],
4+
"recursive": true
5+
}

0 commit comments

Comments
 (0)