Skip to content
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

Add JavaScript implementation #42

Merged
merged 30 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
830c285
add project structure and acceptance test
davidjgoss Nov 1, 2024
d4a31b2
implement suite-level attributes
davidjgoss Nov 2, 2024
4c6757c
test case attrs with basic names
davidjgoss Nov 2, 2024
7981c70
restructure code
davidjgoss Nov 2, 2024
4c33d8b
output steps
davidjgoss Nov 2, 2024
c5f69c2
emit failure element
davidjgoss Nov 2, 2024
efae310
instrument lineage and use feature name
davidjgoss Nov 2, 2024
5eb8930
use lineage for test case names
davidjgoss Nov 2, 2024
bd2633a
implement the rest of failure element
davidjgoss Nov 3, 2024
5d2cfdc
remove query packages, add peer dep
davidjgoss Nov 3, 2024
8d01a0f
split some functions out
davidjgoss Nov 3, 2024
83e5aeb
allow customising suiteName
davidjgoss Nov 3, 2024
431b2bb
add README.md
davidjgoss Nov 3, 2024
d36676b
store all TestCaseStarted, filter at query time
davidjgoss Nov 4, 2024
d392a57
some naming changes and tidying
davidjgoss Nov 14, 2024
4545b5c
Merge branch 'main' into feat/javascript
davidjgoss Nov 14, 2024
e40fdc6
update js with new query
davidjgoss Nov 14, 2024
f2f7936
update java dependency and fix method name
davidjgoss Nov 14, 2024
5d5f858
use lineage from query in js
davidjgoss Nov 14, 2024
1c162eb
bump query version in java and fix retry fixture
davidjgoss Nov 14, 2024
dfaec0e
add empty fixture, fix js impl
davidjgoss Nov 14, 2024
7ebb8d7
add pickle uri fallback for classname
davidjgoss Nov 14, 2024
cde97ce
add github actions
davidjgoss Nov 14, 2024
30984fa
update npm scripts
davidjgoss Nov 14, 2024
3b5dd01
normalise line endings
davidjgoss Nov 14, 2024
ce9ccb7
update CHANGELOG.md
davidjgoss Nov 14, 2024
6d889be
Replace getOrDefault calls
mpkorstanje Nov 15, 2024
157f9d3
fix(deps): update dependency io.cucumber:query to v13.0.2
mpkorstanje Nov 15, 2024
f994219
update CHANGELOG.md
davidjgoss Nov 15, 2024
9e212f2
set js version to match java
davidjgoss Nov 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
24 changes: 24 additions & 0 deletions .github/workflows/release-npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Release NPM

on:
push:
branches: [release/*]

jobs:
publish-npm:
name: Publish NPM module
runs-on: ubuntu-latest
environment: Release
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
cache-dependency-path: javascript/package-lock.json
- run: npm install-test
working-directory: javascript
- uses: cucumber/action-publish-npm@v1.1.1
with:
npm-token: ${{ secrets.NPM_TOKEN }}
working-directory: javascript
39 changes: 39 additions & 0 deletions .github/workflows/test-javascript.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: test-javascript

on:
push:
branches:
- main
- renovate/**
pull_request:
branches:
- main
workflow_call:

jobs:
test-javascript:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
node-version: ["18.x", "20.x", "22.x"]
include:
- os: windows-latest
node-version: "22.x"
- os: macos-latest
node-version: "22.x"

steps:
- uses: actions/checkout@v4

- name: with Node.js ${{ matrix.node-version }} on ${{ matrix.os }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
cache-dependency-path: javascript/package-lock.json

- run: npm install-ci-test
working-directory: javascript
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
- Update dependency io.cucumber:messages up to v26 ((#38)[https://github.com/cucumber/query/pull/38])
- JavaScript implementation ([#42](https://github.com/cucumber/junit-xml-formatter/pull/42))
- Update dependency io.cucumber:messages up to v26 ([#38](https://github.com/cucumber/junit-xml-formatter/pull/38))

### Fixed
- Attempts that have been superseded by retries are now omitted from the report ([#42](https://github.com/cucumber/junit-xml-formatter/pull/42))

## [0.5.0] - 2024-06-22
### Added
Expand Down
2 changes: 1 addition & 1 deletion java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>query</artifactId>
<version>[12.2.0,13.0.0)</version>
<version>[13.0.2,14.0.0)</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,19 @@ int getTestCaseCount() {
return query.findAllTestCaseStarted().size();
}

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

return query.findNameOf(pickle, namingStrategy);
String getPickleName(TestCaseStarted testCaseStarted) {
return query.findNameOf(getPickle(testCaseStarted), namingStrategy);
}

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

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

TestStepResult getTestCaseStatus(TestCaseStarted testCaseStarted) {
return query.findMostSevereTestStepResulBy(testCaseStarted)
return query.findMostSevereTestStepResultBy(testCaseStarted)
.orElse(SCENARIO_WITH_NO_STEPS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ private void writeSuiteAttributes(EscapingXmlStreamWriter writer) throws XMLStre
Map<TestStepResultStatus, Long> counts = data.getTestCaseStatusCounts();

writer.writeAttribute("tests", String.valueOf(data.getTestCaseCount()));
writer.writeAttribute("skipped", counts.getOrDefault(SKIPPED, 0L).toString());
writer.writeAttribute("skipped", counts.get(SKIPPED).toString());
writer.writeAttribute("failures", String.valueOf(countFailures(counts)));
writer.writeAttribute("errors", "0");
}

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

private static EnumSet<TestStepResultStatus> createNotPassedNotSkippedSet() {
Expand Down
39 changes: 39 additions & 0 deletions javascript/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"env": {
"browser": true,
"node": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"plugins": [
"import",
"simple-import-sort",
"n",
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:import/typescript",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"rules": {
"import/no-cycle": "error",
"n/no-extraneous-import": "error",
"@typescript-eslint/ban-ts-ignore": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/member-delimiter-style": "off",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-non-null-assertion": "error",
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error"
}
}
22 changes: 22 additions & 0 deletions javascript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
dist/
.idea/
.nyc_output/
coverage/
node_modules/
yarn.lock
*.log
.deps
.tested*
.linted
.built*
.compared
.codegen
acceptance/
storybook-static
*-go
*.iml
.vscode-test

# stryker temp files
.stryker-tmp
reports
5 changes: 5 additions & 0 deletions javascript/.mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"loader": "ts-node/esm",
"extension": ["ts"],
"recursive": true
}
6 changes: 6 additions & 0 deletions javascript/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"semi": false,
"singleQuote": true,
"printWidth": 100
}
5 changes: 5 additions & 0 deletions javascript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
⚠️ This is an internal package; you don't need to install it in order to use the junit formatter in `@cucumber/cucumber` as it's built in there.

# junit-xml-formatter

> Takes a stream of Cucumber messages and outputs a JUnit XML report
Loading