-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #186 from Hargne/dev
Release 4.0.0
- Loading branch information
Showing
38 changed files
with
4,332 additions
and
3,486 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,32 @@ | ||
name: Run tests | ||
|
||
name: Build & Test | ||
on: | ||
push: | ||
branches: [ master, dev ] | ||
branches: [master, dev] | ||
pull_request: | ||
branches: [ master, dev ] | ||
|
||
branches: [master, dev] | ||
jobs: | ||
build: | ||
|
||
jest-tests: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [14.x, 16.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: yarn install | ||
- run: yarn test | ||
node-version: "22" | ||
- name: Install dependencies | ||
run: | | ||
yarn install | ||
- name: Run Jest tests locally | ||
run: | | ||
yarn test | ||
node14-tests: | ||
uses: ./.github/workflows/test-with-docker.yml | ||
with: | ||
node_version: "14" | ||
jest_versions: "19 20 21 22 23 24 25 26 27 28 29" | ||
node16-tests: | ||
uses: ./.github/workflows/test-with-docker.yml | ||
with: | ||
node_version: "16" | ||
jest_versions: "19" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Test With Docker | ||
on: | ||
workflow_call: | ||
inputs: | ||
node_version: | ||
required: true | ||
type: string | ||
jest_versions: | ||
required: true | ||
type: string | ||
|
||
jobs: | ||
test-flow: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
- name: Set up Docker | ||
uses: docker/setup-buildx-action@v2 | ||
- name: Build Docker Image (Node ${{ inputs.node_version }}) | ||
run: | | ||
docker build --build-arg NODE_VERSION=${{ inputs.node_version }} --build-arg JEST_VERSIONS="${{ inputs.jest_versions }}" -t node${{ inputs.node_version }}-image . | ||
- name: Run Docker Image (Test against Jest versions ${{ inputs.jest_versions }}) | ||
run: | | ||
docker run --name node${{ inputs.node_version }}-container node${{ inputs.node_version }}-image | ||
- name: Cleanup Docker Container & Image | ||
if: always() | ||
run: | | ||
docker rm -f node${{ inputs.node_version }}-container || true | ||
docker rmi -f node${{ inputs.node_version }}-image || true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,4 @@ npm-debug.log | |
node_modules/ | ||
test-report/ | ||
dist/ | ||
test-report.html | ||
testResultsProcessorResult.html | ||
report.html |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
ARG NODE_VERSION=14 | ||
ARG JEST_VERSIONS=19 | ||
|
||
FROM node:20.10.0 AS build | ||
|
||
# Pass arguments as environment variables so they persists when we switch Node version | ||
ENV JEST_VERSIONS=$JEST_VERSIONS | ||
|
||
# Build the Jest HTML Reporter package | ||
WORKDIR /app | ||
COPY . . | ||
RUN yarn install | ||
RUN yarn bundle | ||
|
||
# Switch to a different Node version | ||
FROM node:${NODE_VERSION}-slim AS final | ||
|
||
# Re-declare environment variables as we have switched node | ||
ARG JEST_VERSIONS | ||
ENV JEST_VERSIONS=$JEST_VERSIONS | ||
|
||
WORKDIR /app | ||
|
||
# Copy over the Jest HTML Reporter package we built in the previous step | ||
COPY --from=build /app/dist /app/jest-html-reporter/dist | ||
COPY --from=build /app/style /app/jest-html-reporter/style | ||
COPY --from=build /app/package.json /app/jest-html-reporter/package.json | ||
COPY --from=build /app/yarn.lock /app/jest-html-reporter/yarn.lock | ||
|
||
# Install jest-html-reporter dependencies using yarn | ||
WORKDIR /app/jest-html-reporter | ||
ENV NODE_ENV=production | ||
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 | ||
RUN npm install | ||
|
||
# Run the bash script containing the tests | ||
COPY /e2e/run_tests.sh /app/run_tests.sh | ||
RUN chmod +x /app/run_tests.sh | ||
|
||
CMD ["/bin/sh", "/app/run_tests.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/bin/sh | ||
|
||
JEST_VERSIONS=${JEST_VERSIONS:-"29"} # Default Jest versions | ||
|
||
# Echo the current Node version | ||
echo "Current Node version: $(node -v)" | ||
|
||
# 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 | ||
# 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!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const add = (a, b) => a + b; | ||
const subtract = (a, b) => a - b; | ||
|
||
module.exports = { add, subtract }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* This is only template tests used for testing the | ||
* implementation jest-html-reporter together with Jest | ||
*/ | ||
|
||
const { add, subtract } = require("./index"); | ||
|
||
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); | ||
}); | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "test-project", | ||
"version": "1.0.0", | ||
"description": "A simple project to test Jest HTML Reporter", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"test": "jest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// @ts-check | ||
|
||
import eslint from "@eslint/js"; | ||
import tseslint from "typescript-eslint"; | ||
|
||
export default tseslint.config( | ||
eslint.configs.recommended, | ||
tseslint.configs.strict, | ||
tseslint.configs.stylistic | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,23 @@ | ||
{ | ||
"roots": ["<rootDir>"], | ||
"roots": ["<rootDir>/src"], | ||
"preset": "ts-jest", | ||
"transform": { | ||
"^.+\\.tsx?$": [ | ||
"ts-jest", | ||
{ | ||
"babelConfig": true | ||
} | ||
] | ||
}, | ||
"collectCoverage": true, | ||
"collectCoverageFrom": [ | ||
"./src/**/*.{ts,tsx}", | ||
"!src/style.ts", | ||
"!**/test/*.{ts,tsx}", | ||
"!**/node_modules/**", | ||
"!**/coverage/**", | ||
"!**/vendor/**" | ||
"./src/**/*.ts", | ||
"!**/**/*.d.ts", | ||
"!**/**/*.types.ts", | ||
"!./src/__mock__/**/*.ts" | ||
], | ||
"coverageDirectory": "./coverage", | ||
"coverageReporters": ["json", "html", "text", "text-summary"], | ||
"coverageThreshold": { | ||
"global": { | ||
"branches": 50, | ||
"functions": 50, | ||
"lines": 50, | ||
"statements": 50 | ||
"branches": 75, | ||
"functions": 75, | ||
"lines": 75, | ||
"statements": 75 | ||
} | ||
}, | ||
"verbose": true, | ||
"reporters": [ | ||
"default", | ||
[ | ||
"./dist", | ||
{ | ||
"pageTitle": "Test Suite Reporter", | ||
"outputPath": "<rootDir>/testResultsProcessorResult.html", | ||
"includeFailureMsg": true, | ||
"includeConsoleLog": true, | ||
"useCssFile": true, | ||
"sort": "titleAsc", | ||
"append": false | ||
} | ||
] | ||
] | ||
"testEnvironment": "jsdom", | ||
"verbose": true | ||
} |
Oops, something went wrong.