Skip to content

Commit

Permalink
Merge pull request #230 from stakater/add-tests
Browse files Browse the repository at this point in the history
rasheedamir authored Jan 10, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 03cd4cd + 370f338 commit 9bb0bbf
Showing 5 changed files with 3,294 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
@@ -30,3 +30,31 @@ jobs:
CONTAINER_REGISTRY_PASSWORD: ${{ secrets.GHCR_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.STAKATER_DELIVERY_SLACK_WEBHOOK }}
DOCKER_SECRETS: GIT_AUTH_TOKEN=${{ secrets.PUBLISH_TOKEN }}
test:
runs-on: ubuntu-latest
needs: [
build_container,
deploy_doc
]
env:
CURRENT_BRANCH: ${{ needs.deploy_doc.outputs.CURRENT_BRANCH }}
IMAGE_PATH: ${{ needs.build_container.outputs.IMAGE_PATH }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Login to Docker Registry
uses: docker/login-action@v3
with:
registry: ghcr.io/stakater
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Run Docker container for the docs
run: |
docker run -d --name mto-docs -p 8080:8080 ${{ env.IMAGE_PATH }} || exit 1
- name: Build testcafe tests
working-directory: ./testcafe
run: |
docker build -t testcafe-tests --build-arg CURRENT_BRANCH=${{ env.CURRENT_BRANCH }} .
- name: Run Docker container to run tests
run: |
docker run --rm --network="host" --name myapp-testcafe-container testcafe-tests:latest
19 changes: 19 additions & 0 deletions testcafe/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:22-alpine
WORKDIR testcafe

ARG CURRENT_BRANCH

ENV CURRENT_BRANCH=$CURRENT_BRANCH
ENV XDG_DOWNLOAD_DIR=/opt/JDownloader/Downloads

COPY src src
COPY package.json package.json

RUN echo "Install build deps.." \
&& apk --update --no-cache add \
chromium \
tzdata

RUN yarn

CMD ["yarn", "start"]
12 changes: 12 additions & 0 deletions testcafe/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "mto-docs-testcafe-tests",
"version": "1.0.0",
"dependencies": {
"testcafe": "^3.3.0",
"dotenv": "^16.3.1"
},
"scripts": {
"local": "testcafe chrome src/**.ts",
"start": "testcafe chromium:headless src/**.ts"
}
}
65 changes: 65 additions & 0 deletions testcafe/src/run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { fixture, Selector } from "testcafe";

const consentControlsDiv = Selector('.md-consent__controls');
const acceptButton = consentControlsDiv.find('button').withText('Accept');
const searchInput = Selector('input.md-search__input').withAttribute('placeholder', 'Search');
const searchResultItem = Selector('li.md-search-result__item');
const searchLabel = Selector('label.md-header__button.md-icon').withAttribute('for', '__search');
const currentBranch = <string>process.env.CURRENT_BRANCH;

fixture("Verify site")
.page`${'http://127.0.0.1:8080/'.concat(currentBranch, '/#')}`
.skipJsErrors();

test('Verify index file exists', async t => {
await t
.navigateTo(`${'http://127.0.0.1:8080/'.concat(currentBranch, '/index.html')}`);
})

test('Search for existence of incorrectly rendered fenced code blocks', async (t) => {
await t.maximizeWindow();

const acceptButtonExists = await acceptButton.exists;

if (acceptButtonExists) {
await t.click(acceptButton);
}

const searchLabelExists = await searchLabel.exists;
const searchLabelVisible = await searchLabel.visible;

if (searchLabelExists && searchLabelVisible) {
await t.click(searchLabel);
}

await t.expect(searchInput.visible).ok();
await t.click(searchInput);
await t.typeText(searchInput, "```")

const searchResultItemExists = await searchResultItem.exists;
await t.expect(searchResultItemExists).notOk('Fenced code blocks exist in the search result and are therefore incorrectly rendered, failing the test');
})

test('Search for existence of incorrectly rendered admonitions', async (t) => {
await t.maximizeWindow();

const acceptButtonExists = await acceptButton.exists;

if (acceptButtonExists) {
await t.click(acceptButton);
}

const searchLabelExists = await searchLabel.exists;
const searchLabelVisible = await searchLabel.visible;

if (searchLabelExists && searchLabelVisible) {
await t.click(searchLabel);
}

await t.expect(searchInput.visible).ok();
await t.click(searchInput);
await t.typeText(searchInput, "!!!")

const searchResultItemExists = await searchResultItem.exists;
await t.expect(searchResultItemExists).notOk('Admonitions exist in the search result and are therefore incorrectly rendered, failing the test');
})
3,170 changes: 3,170 additions & 0 deletions testcafe/yarn.lock

Large diffs are not rendered by default.

0 comments on commit 9bb0bbf

Please sign in to comment.