Skip to content

Commit bc6bd23

Browse files
authored
Merge pull request #191 from Hargne/feature/a11y
Test Report a11y
2 parents 84c0b7a + db4c75e commit bc6bd23

13 files changed

+648
-254
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ npm-debug.log
33
node_modules/
44
test-report/
55
dist/
6-
test-report.html
7-
testResultsProcessorResult.html
6+
report.html

Dockerfile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ RUN npm install --ignore-engines
3535
# Copy and run the test-project directory into the container and run the tests with the Jest HTML Reporter
3636
WORKDIR /app
3737
COPY /e2e/test-project /app
38-
39-
# As a test results processor
40-
RUN echo "{\"testEnvironment\": \"node\", \"testResultsProcessor\": \"<rootDir>/jest-html-reporter\"}" > /app/jest.config.json
41-
RUN echo "{\"pageTitle\": \"A Testresult Processor Title\", \"outputPath\": \"<rootDir>/testResultsProcessor.html\"}" > /app/jesthtmlreporter.config.json
4238
RUN npm install
4339

4440
# Run the bash script containing the tests

e2e/run_tests.sh

Lines changed: 81 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,90 @@
11
#!/bin/sh
22

3+
JEST_VERSIONS=${JEST_VERSIONS:-"29"} # Default Jest versions
4+
35
# Echo the current Node version
46
echo "Current Node version: $(node -v)"
57

6-
# Convert space-separated JEST_VERSIONS to an array
8+
# Create a jest config with properties we should test against
9+
FILENAME="test-report"
10+
PAGE_TITLE="A Title For This Report"
11+
712
for VERSION in $JEST_VERSIONS; do
8-
echo "Installing Jest version: $VERSION"
9-
npm install jest@$VERSION || exit 1
10-
11-
echo "Running tests with Jest version: $VERSION"
12-
yarn test --config=jest.config.json || exit 1
13-
14-
# Check if the output contains the expected text
15-
if grep -q "A Testresult Processor Title" ./testResultsProcessor.html; then
16-
echo "✅ Tests passed for Jest version: $VERSION"
17-
else
18-
echo "❌ Tests failed for Jest version: $VERSION"
19-
exit 1
20-
fi
13+
# Extract the major version number
14+
MAJOR_VERSION=$(echo "$VERSION" | cut -d. -f1)
15+
16+
# For Jest versions above 20 we use the reporters option
17+
if [ "$MAJOR_VERSION" -ge 20 ]; then
18+
cat <<EOF > jest.config.json || { echo "❌ Failed to create jest.config.json"; exit 1; }
19+
{
20+
"testEnvironment": "node",
21+
"reporters": [
22+
"default",
23+
["<rootDir>/jest-html-reporter", {
24+
"append": false,
25+
"boilerplate": null,
26+
"collapseSuitesByDefault": true,
27+
"customScriptPath": null,
28+
"dateFormat": "yyyy-mm-dd (HH:MM:ss)",
29+
"executionTimeWarningThreshold": 1,
30+
"includeConsoleLog": true,
31+
"includeFailureMsg": true,
32+
"includeStackTrace": true,
33+
"includeSuiteFailure": true,
34+
"logo": "https://placehold.co/100x50/png?text=Test+Report&font=playfair-display",
35+
"outputPath": "<rootDir>/${FILENAME}.html",
36+
"pageTitle": "${PAGE_TITLE}",
37+
"sort": "status",
38+
"statusIgnoreFilter": null,
39+
"styleOverridePath": "./style/defaultTheme.css",
40+
"useCssFile": true
41+
}]
42+
]
43+
}
44+
EOF
45+
else
46+
cat <<EOF > jest.config.json || { echo "❌ Failed to create jest.config.json"; exit 1; }
47+
{
48+
"testEnvironment": "node",
49+
"testResultsProcessor": "<rootDir>/jest-html-reporter"
50+
}
51+
EOF
52+
cat <<EOF > jesthtmlreporter.config.json || { echo "❌ Failed to create jesthtmlreporter.config.json"; exit 1; }
53+
{
54+
"append": false,
55+
"boilerplate": null,
56+
"collapseSuitesByDefault": true,
57+
"customScriptPath": null,
58+
"dateFormat": "yyyy-mm-dd (HH:MM:ss)",
59+
"executionTimeWarningThreshold": 1,
60+
"includeConsoleLog": true,
61+
"includeFailureMsg": true,
62+
"includeStackTrace": true,
63+
"includeSuiteFailure": true,
64+
"logo": "https://placehold.co/100x50/png?text=Test+Report&font=playfair-display",
65+
"outputPath": "<rootDir>/${FILENAME}.html",
66+
"pageTitle": "${PAGE_TITLE}",
67+
"sort": "status",
68+
"statusIgnoreFilter": null,
69+
"styleOverridePath": "./style/defaultTheme.css",
70+
"useCssFile": true
71+
}
72+
EOF
73+
fi
74+
75+
echo "Installing Jest version: $VERSION"
76+
npm install jest@$VERSION || exit 1
77+
78+
echo "Running tests with Jest version: $VERSION"
79+
npm run test -- --config=jest.config.json || exit 1
80+
81+
# Check if the output contains the expected text
82+
if grep -q "$PAGE_TITLE" ./$FILENAME.html; then
83+
echo "✅ Tests passed for Jest version: $VERSION"
84+
else
85+
echo "❌ Tests failed for Jest version: $VERSION"
86+
exit 1
87+
fi
2188
done
2289

2390
echo "✅ All Jest versions passed!"

e2e/test-project/index.test.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
/**
2+
* This is only template tests used for testing the
3+
* implementation jest-html-reporter together with Jest
4+
*/
5+
16
const { add, subtract } = require("./index");
27

3-
test("adds 1 + 2 to equal 3", () => {
4-
expect(add(1, 2)).toBe(3);
5-
});
8+
describe("test-project", () => {
9+
test("adds 1 + 2 to equal 3", () => {
10+
expect(add(1, 2)).toBe(3);
11+
});
12+
13+
test("subtracts 5 - 3 to equal 2", () => {
14+
expect(subtract(5, 3)).toBe(2);
15+
});
16+
})
617

7-
test("subtracts 5 - 3 to equal 2", () => {
8-
expect(subtract(5, 3)).toBe(2);
9-
});

jest.config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
"statements": 75
1919
}
2020
},
21+
"testEnvironment": "jsdom",
2122
"verbose": true
2223
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"@types/sinon": "9.0.11",
6565
"eslint": "^9.19.0",
6666
"jest": "^29.7.0",
67+
"jest-environment-jsdom": "^29.7.0",
6768
"rollup": "^4.34.1",
6869
"sinon": "^9.0.1",
6970
"ts-jest": "^29.0.0",

src/__mock__/mockAggregatedResultSingle.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,4 @@ export const mockAggregatedResultSingle: AggregatedResult = {
7272
},
7373
],
7474
};
75+
export default mockAggregatedResultSingle;

src/__mock__/mockJestGlobalConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,4 @@ export const mockJestGlobalConfig: Config.GlobalConfig = {
6262
watchPlugins: undefined,
6363
watchman: true,
6464
};
65+
export default mockJestGlobalConfig;

0 commit comments

Comments
 (0)