Skip to content

Commit fdd512f

Browse files
authored
Merge pull request #186 from Hargne/dev
Release 4.0.0
2 parents 161a27f + a66c8f3 commit fdd512f

38 files changed

+4332
-3486
lines changed

.babelrc

Lines changed: 0 additions & 13 deletions
This file was deleted.

.github/workflows/main.yml

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
1-
name: Run tests
2-
1+
name: Build & Test
32
on:
43
push:
5-
branches: [ master, dev ]
4+
branches: [master, dev]
65
pull_request:
7-
branches: [ master, dev ]
8-
6+
branches: [master, dev]
97
jobs:
10-
build:
11-
8+
jest-tests:
129
runs-on: ubuntu-latest
13-
14-
strategy:
15-
matrix:
16-
node-version: [14.x, 16.x]
17-
1810
steps:
19-
- uses: actions/checkout@v3
20-
- name: Use Node.js ${{ matrix.node-version }}
21-
uses: actions/setup-node@v3
11+
- name: Checkout code
12+
uses: actions/checkout@v2
13+
- name: Set up Node.js
14+
uses: actions/setup-node@v2
2215
with:
23-
node-version: ${{ matrix.node-version }}
24-
- run: yarn install
25-
- run: yarn test
16+
node-version: "22"
17+
- name: Install dependencies
18+
run: |
19+
yarn install
20+
- name: Run Jest tests locally
21+
run: |
22+
yarn test
23+
node14-tests:
24+
uses: ./.github/workflows/test-with-docker.yml
25+
with:
26+
node_version: "14"
27+
jest_versions: "19 20 21 22 23 24 25 26 27 28 29"
28+
node16-tests:
29+
uses: ./.github/workflows/test-with-docker.yml
30+
with:
31+
node_version: "16"
32+
jest_versions: "19"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Test With Docker
2+
on:
3+
workflow_call:
4+
inputs:
5+
node_version:
6+
required: true
7+
type: string
8+
jest_versions:
9+
required: true
10+
type: string
11+
12+
jobs:
13+
test-flow:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v2
18+
- name: Set up Docker
19+
uses: docker/setup-buildx-action@v2
20+
- name: Build Docker Image (Node ${{ inputs.node_version }})
21+
run: |
22+
docker build --build-arg NODE_VERSION=${{ inputs.node_version }} --build-arg JEST_VERSIONS="${{ inputs.jest_versions }}" -t node${{ inputs.node_version }}-image .
23+
- name: Run Docker Image (Test against Jest versions ${{ inputs.jest_versions }})
24+
run: |
25+
docker run --name node${{ inputs.node_version }}-container node${{ inputs.node_version }}-image
26+
- name: Cleanup Docker Container & Image
27+
if: always()
28+
run: |
29+
docker rm -f node${{ inputs.node_version }}-container || true
30+
docker rmi -f node${{ inputs.node_version }}-image || true

.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

.npmrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

.travis.yml

Lines changed: 0 additions & 4 deletions
This file was deleted.

Dockerfile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
ARG NODE_VERSION=14
2+
ARG JEST_VERSIONS=19
3+
4+
FROM node:20.10.0 AS build
5+
6+
# Pass arguments as environment variables so they persists when we switch Node version
7+
ENV JEST_VERSIONS=$JEST_VERSIONS
8+
9+
# Build the Jest HTML Reporter package
10+
WORKDIR /app
11+
COPY . .
12+
RUN yarn install
13+
RUN yarn bundle
14+
15+
# Switch to a different Node version
16+
FROM node:${NODE_VERSION}-slim AS final
17+
18+
# Re-declare environment variables as we have switched node
19+
ARG JEST_VERSIONS
20+
ENV JEST_VERSIONS=$JEST_VERSIONS
21+
22+
WORKDIR /app
23+
24+
# Copy over the Jest HTML Reporter package we built in the previous step
25+
COPY --from=build /app/dist /app/jest-html-reporter/dist
26+
COPY --from=build /app/style /app/jest-html-reporter/style
27+
COPY --from=build /app/package.json /app/jest-html-reporter/package.json
28+
COPY --from=build /app/yarn.lock /app/jest-html-reporter/yarn.lock
29+
30+
# Install jest-html-reporter dependencies using yarn
31+
WORKDIR /app/jest-html-reporter
32+
ENV NODE_ENV=production
33+
RUN npm install --ignore-engines
34+
35+
# Copy and run the test-project directory into the container and run the tests with the Jest HTML Reporter
36+
WORKDIR /app
37+
COPY /e2e/test-project /app
38+
RUN npm install
39+
40+
# Run the bash script containing the tests
41+
COPY /e2e/run_tests.sh /app/run_tests.sh
42+
RUN chmod +x /app/run_tests.sh
43+
44+
CMD ["/bin/sh", "/app/run_tests.sh"]

README.md

Lines changed: 31 additions & 44 deletions
Large diffs are not rendered by default.

e2e/run_tests.sh

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/sh
2+
3+
JEST_VERSIONS=${JEST_VERSIONS:-"29"} # Default Jest versions
4+
5+
# Echo the current Node version
6+
echo "Current Node version: $(node -v)"
7+
8+
# Create a jest config with properties we should test against
9+
FILENAME="test-report"
10+
PAGE_TITLE="A Title For This Report"
11+
12+
for VERSION in $JEST_VERSIONS; do
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
88+
done
89+
90+
echo "✅ All Jest versions passed!"

e2e/test-project/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const add = (a, b) => a + b;
2+
const subtract = (a, b) => a - b;
3+
4+
module.exports = { add, subtract };

0 commit comments

Comments
 (0)