Skip to content

Commit

Permalink
Merge pull request #23 from oleksis/playwright-jekyll
Browse files Browse the repository at this point in the history
Playwright and Jekyll
  • Loading branch information
kjaymiller authored Oct 6, 2023
2 parents ff966bf + 8f34986 commit 863928a
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 37 deletions.
9 changes: 6 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers-contrib/features/pre-commit:2": {}
"ghcr.io/devcontainers-contrib/features/pre-commit:2": {},
"ghcr.io/devcontainers/features/docker-in-docker": {},
"ghcr.io/devcontainers-contrib/features/act:1": {}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
Expand All @@ -16,10 +18,11 @@
4000,
// Live reload server
35729
]
],

// Uncomment the next line to run commands after the container is created.
// "postCreateCommand": "jekyll --version"
// git config --global --add safe.directory /workspaces/blackpythondevs.github.io
"postCreateCommand": "python3 -m pip install black pytest-playwright && python3 -m playwright install --with-deps"

// Configure tool-specific properties.
// "customizations": {},
Expand Down
18 changes: 10 additions & 8 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
* text=auto

* .md text
* .html text
* .css text
* .js text
* .yml text
* .xml text
* .md text eol=lf
* .html text eol=lf
* .css text eol=lf
* .js text eol=lf
* .yml text eol=lf
* .xml text eol=lf

* .bat eol=crlf
* .bat text eol=crlf

* .sh eol=lf
* .sh text eol=lf

* .png binary
* .jpg binary
* .gif binary

_site/* -text -diff -merge
18 changes: 12 additions & 6 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
name: Playwright Tests
# https://devblogs.microsoft.com/python/announcing-playwright-for-python-reliable-end-to-end-testing-for-the-web/
# https://github.com/marketplace/actions/run-playwright-tests

on:
push:
branches:
- gh-pages
workflow_dispatch:

jobs:
test:
Expand All @@ -17,10 +20,13 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install playwright pytest pytest-playwright
pip install -r requirements-dev.txt
python -m playwright install --with-deps
- name: Sleep for 30 seconds
run: sleep 45s
shell: bash
- name: Run tests
run: python -m pytest
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Jekyll detached and pytest
run: |
bundle exec jekyll serve --detach
python -m pytest
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ _site
venv
.venv
.jekyll-metadata
*/__pycache__
**/__pycache__
.pytest_cache
bin/
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ repos:
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.2.2
9 changes: 9 additions & 0 deletions _articles/es/community.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
layout: index
lang: es
title: Comunidad
---

# Comunidad

Esta es la página de ejemplo Comunidad
9 changes: 9 additions & 0 deletions _articles/es/conferences.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
layout: index
lang: es
title: Conferencias
---

# Conferencias

Esta es la página de ejemplo Conferencias
9 changes: 9 additions & 0 deletions _articles/es/events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
layout: index
lang: es
title: Eventos
---

# Eventos

Esta es la página de ejemplo Eventos
2 changes: 2 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ exclude:
- vendor
- venv
- .venv
- requirements*.txt
- pytest.ini
# timezone: America/Toronto

permalink: "/:path/"
Expand Down
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
python_files = *.py
addopts = -v
3 changes: 3 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
black
pre-commit
pytest-playwright
33 changes: 14 additions & 19 deletions tests/test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

import pytest
from playwright.sync_api import Page, expect


live_server_url = "https://blackpythondevs.github.io"
live_server_url = "http://127.0.0.1:4000"

routes = [
("about.html"),
Expand All @@ -12,18 +10,9 @@
("events.html"),
]

@pytest.mark.parametrize("url", routes)
def test_destination_options(
page: Page,
url: str,
):
"""Test that the destinations page loads with seeded data"""
# Create a destination
page.goto(f"{live_server_url}/{url}")
page.on("response", lambda response: expect(response.status).to_equal(200))

@pytest.mark.parametrize("url", routes)
def test_destination_(
def test_destination(
page: Page,
url: str,
) -> None:
Expand All @@ -32,17 +21,23 @@ def test_destination_(
page.goto(f"{live_server_url}/{url}")
page.on("response", lambda response: expect(response.status).to_equal(200))


@pytest.mark.parametrize(
"title, url",(
("Acerca de", '/es/about/'),
"title, url",
(
("Acerca de", "/es/about/"),
("Inicio", "/es/"),
("Eventos", "/es/events/"),
("Comunidad", "/es/community/"),
("Conferencias", "/es/conferences/"),
)
),
)
def test_headers_in_language(page: Page, title:str, url:str) -> None:
page.goto("https://blackpythondevs.github.io/")
def test_headers_in_language(page: Page, title: str, url: str) -> None:
page.goto(live_server_url)
lang = page.evaluate("document.documentElement.lang")
assert lang == "en"
page.get_by_label("Language").select_option("es")
page.get_by_role("link", name=title).click()
expect(page).to_have_url(f"https://blackpythondevs.github.io{url}")
expect(page).to_have_url(f"{live_server_url}{url}")
lang = page.evaluate("document.documentElement.lang")
assert lang == "es"

0 comments on commit 863928a

Please sign in to comment.