Skip to content

Commit

Permalink
Merge pull request #191 from Hargne/feature/a11y
Browse files Browse the repository at this point in the history
Test Report a11y
  • Loading branch information
Hargne authored Feb 9, 2025
2 parents 84c0b7a + db4c75e commit bc6bd23
Show file tree
Hide file tree
Showing 13 changed files with 648 additions and 254 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ npm-debug.log
node_modules/
test-report/
dist/
test-report.html
testResultsProcessorResult.html
report.html
4 changes: 0 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ RUN npm install --ignore-engines
# Copy and run the test-project directory into the container and run the tests with the Jest HTML Reporter
WORKDIR /app
COPY /e2e/test-project /app

# As a test results processor
RUN echo "{\"testEnvironment\": \"node\", \"testResultsProcessor\": \"<rootDir>/jest-html-reporter\"}" > /app/jest.config.json
RUN echo "{\"pageTitle\": \"A Testresult Processor Title\", \"outputPath\": \"<rootDir>/testResultsProcessor.html\"}" > /app/jesthtmlreporter.config.json
RUN npm install

# Run the bash script containing the tests
Expand Down
95 changes: 81 additions & 14 deletions e2e/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,90 @@
#!/bin/sh

JEST_VERSIONS=${JEST_VERSIONS:-"29"} # Default Jest versions

# Echo the current Node version
echo "Current Node version: $(node -v)"

# Convert space-separated JEST_VERSIONS to an array
# Create a jest config with properties we should test against
FILENAME="test-report"
PAGE_TITLE="A Title For This Report"

for VERSION in $JEST_VERSIONS; do
echo "Installing Jest version: $VERSION"
npm install jest@$VERSION || exit 1

echo "Running tests with Jest version: $VERSION"
yarn test --config=jest.config.json || exit 1

# Check if the output contains the expected text
if grep -q "A Testresult Processor Title" ./testResultsProcessor.html; then
echo "✅ Tests passed for Jest version: $VERSION"
else
echo "❌ Tests failed for Jest version: $VERSION"
exit 1
fi
# Extract the major version number
MAJOR_VERSION=$(echo "$VERSION" | cut -d. -f1)

# For Jest versions above 20 we use the reporters option
if [ "$MAJOR_VERSION" -ge 20 ]; then
cat <<EOF > jest.config.json || { echo "❌ Failed to create jest.config.json"; exit 1; }
{
"testEnvironment": "node",
"reporters": [
"default",
["<rootDir>/jest-html-reporter", {
"append": false,
"boilerplate": null,
"collapseSuitesByDefault": true,
"customScriptPath": null,
"dateFormat": "yyyy-mm-dd (HH:MM:ss)",
"executionTimeWarningThreshold": 1,
"includeConsoleLog": true,
"includeFailureMsg": true,
"includeStackTrace": true,
"includeSuiteFailure": true,
"logo": "https://placehold.co/100x50/png?text=Test+Report&font=playfair-display",
"outputPath": "<rootDir>/${FILENAME}.html",
"pageTitle": "${PAGE_TITLE}",
"sort": "status",
"statusIgnoreFilter": null,
"styleOverridePath": "./style/defaultTheme.css",
"useCssFile": true
}]
]
}
EOF
else
cat <<EOF > jest.config.json || { echo "❌ Failed to create jest.config.json"; exit 1; }
{
"testEnvironment": "node",
"testResultsProcessor": "<rootDir>/jest-html-reporter"
}
EOF
cat <<EOF > jesthtmlreporter.config.json || { echo "❌ Failed to create jesthtmlreporter.config.json"; exit 1; }
{
"append": false,
"boilerplate": null,
"collapseSuitesByDefault": true,
"customScriptPath": null,
"dateFormat": "yyyy-mm-dd (HH:MM:ss)",
"executionTimeWarningThreshold": 1,
"includeConsoleLog": true,
"includeFailureMsg": true,
"includeStackTrace": true,
"includeSuiteFailure": true,
"logo": "https://placehold.co/100x50/png?text=Test+Report&font=playfair-display",
"outputPath": "<rootDir>/${FILENAME}.html",
"pageTitle": "${PAGE_TITLE}",
"sort": "status",
"statusIgnoreFilter": null,
"styleOverridePath": "./style/defaultTheme.css",
"useCssFile": true
}
EOF
fi

echo "Installing Jest version: $VERSION"
npm install jest@$VERSION || exit 1

echo "Running tests with Jest version: $VERSION"
npm run test -- --config=jest.config.json || exit 1

# Check if the output contains the expected text
if grep -q "$PAGE_TITLE" ./$FILENAME.html; then
echo "✅ Tests passed for Jest version: $VERSION"
else
echo "❌ Tests failed for Jest version: $VERSION"
exit 1
fi
done

echo "✅ All Jest versions passed!"
20 changes: 14 additions & 6 deletions e2e/test-project/index.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
/**
* This is only template tests used for testing the
* implementation jest-html-reporter together with Jest
*/

const { add, subtract } = require("./index");

test("adds 1 + 2 to equal 3", () => {
expect(add(1, 2)).toBe(3);
});
describe("test-project", () => {
test("adds 1 + 2 to equal 3", () => {
expect(add(1, 2)).toBe(3);
});

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

test("subtracts 5 - 3 to equal 2", () => {
expect(subtract(5, 3)).toBe(2);
});
1 change: 1 addition & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"statements": 75
}
},
"testEnvironment": "jsdom",
"verbose": true
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"@types/sinon": "9.0.11",
"eslint": "^9.19.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"rollup": "^4.34.1",
"sinon": "^9.0.1",
"ts-jest": "^29.0.0",
Expand Down
1 change: 1 addition & 0 deletions src/__mock__/mockAggregatedResultSingle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,4 @@ export const mockAggregatedResultSingle: AggregatedResult = {
},
],
};
export default mockAggregatedResultSingle;
1 change: 1 addition & 0 deletions src/__mock__/mockJestGlobalConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ export const mockJestGlobalConfig: Config.GlobalConfig = {
watchPlugins: undefined,
watchman: true,
};
export default mockJestGlobalConfig;
Loading

0 comments on commit bc6bd23

Please sign in to comment.