Skip to content

Commit 48b2b5c

Browse files
Add a test framework to test the JS part of the course (#2471)
This is a first draft for a test framework for testing the JS part of the book that is discussed in #2462 It is using [webdriverIO](https://webdriver.io/) and the webdriverIO [Expect API](https://webdriver.io/docs/api/expect-webdriverio/) in combination with [Mocha](https://mochajs.org/). WebdriverIO is taking care of accessing the webpage with a real browser and can access the state of the page so behavior can be asserted. Currently only a small test for the speaker-notes implementation demos the functionality. The [Static Server Service](https://webdriver.io/docs/static-server-service/) is used to serve the book in a way that the test runner can access it. A CI integration can look like https://webdriver.io/docs/githubactions/ and is implemented with a headless setup. In CI it uses the language variable to set environment variable that configures where the built book should be mounted from --------- Co-authored-by: Martin Geisler <[email protected]>
1 parent d868584 commit 48b2b5c

File tree

10 files changed

+7206
-0
lines changed

10 files changed

+7206
-0
lines changed

.github/workflows/build.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,19 @@ jobs:
181181
MDBOOK_BOOK__LANGUAGE: ${{ matrix.language }}
182182
run: mdbook test
183183

184+
- name: Setup Node
185+
uses: actions/setup-node@v4
186+
with:
187+
node-version: 18
188+
- name: Install test framework
189+
run: npm install
190+
working-directory: ./tests
191+
- name: Test Javascript
192+
run: npm test
193+
env:
194+
TEST_BOOK_DIR: ../book/comprehensive-rust-${{ matrix.language }}/html
195+
working-directory: ./tests
196+
184197
po-diff:
185198
name: Translation diff
186199
runs-on: ubuntu-latest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ count.dat
1919
# Nodejs Files (dprint)
2020
node_modules/
2121
package.json
22+
!tests/package.json
2223
pnpm-lock.yaml
2324

2425
# Crowdin Config (Contains API Keys)

tests/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Testing Comprehensive Rust
2+
3+
The course material contains JS code that can break and needs to be checked for
4+
functionality. Examples are `theme/speaker-notes.js` or `theme/book.js`.
5+
6+
Comprehensive Rust is using [webdriverIO](https://webdriver.io/) and the
7+
[webdriverIO Expect API](https://webdriver.io/docs/api/expect-webdriverio/) in
8+
combination with [Mocha] (https://mochajs.org/). WebdriverIO is taking care of
9+
accessing the webpage with a real browser and can access the state of the page
10+
so behavior can be asserted.
11+
12+
The [Static Server Service](https://webdriver.io/docs/static-server-service/) is
13+
used mainly in the [CI](../github/workflows/build.yml) to serve the book on port
14+
`localhost:8080` such that the test runner can access it. This mode is used when
15+
`npm start` or `npm test` is executed.
16+
17+
For local testing and quick iterations it is possible to use `mdbook serve`
18+
which creates a small HTTP server on port 3000 by default. There is a special
19+
config that is invoked with `npm run test-mdbook` that uses
20+
`http://localhost:3000`

0 commit comments

Comments
 (0)