Skip to content

Commit

Permalink
Set up infrastructure for Jest (JavaScript) tests (#282)
Browse files Browse the repository at this point in the history
Prework for #208.

Abby and I decided that we want Jest tests for two purposes:

1. Checking that web components are in sync between the Pytorch and Furo
themes, e.g. we didn't forget to update one of the folders.
1. We could do this either by using Snapshot testing or by simply
checking that the file contents are equal.
2. We have some non-trivial logic in
#267 and want to write
automated unit tests.

This PR adds the basic infrastructure, like setting up CI to install
Node.js. That will make it easier to review follow-up PRs that add
actual tests.

> We could do this either by using snapshot testing

I think we'd benefit from adding snapshot testing for the top nav bar
rendering correctly. I want to do this in a follow up PR so we can
properly decide if we want to add snapshots or not; the decision to use
snapshots is separate from whether to use Jest generally.
  • Loading branch information
Eric-Arellano authored Apr 27, 2023
1 parent 6345fbf commit b5d76bd
Show file tree
Hide file tree
Showing 6 changed files with 3,217 additions and 3 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,24 @@ jobs:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Python 3.9
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 18
- name: Install Node.js dependencies
run: npm ci
- name: Run Node.js tests
run: npm test
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install ubuntu Deps
- name: Install Ubuntu deps
run: sudo apt-get install -y pandoc graphviz
- name: Install tox
run: |
python -m pip install -U tox
- name: Build Docs
- name: Build example docs
run: tox run -e py
- name: Compress Artifacts
run: |
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,6 @@ dmypy.json
# Pyre type checker
.pyre/
.DS_Store

# JavaScript
/node_modules
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ This subfolder contains some example `.rst` files that show how to implement spe
3. Run `pip install -e .`
4. Run `sphinx-build -b html example_docs/docs/ example_docs/docs/_build/html` to build the documentation. This will create the `example_docs/docs/_build` subfolder where you can see the html files generated based on the `.rst` files in the `docs` folder and the styles pulled from the `qiskit_sphinx_theme`.

------
## Run JavaScript tests

We write some tests in JavaScript (Node.js) to have automated checks of the theme, e.g. that certain components render properly.

To run these tests, you first need to install Node.js on your machine. If you expect to use JavaScript in other projects, we recommend using [NVM](https://github.com/nvm-sh/nvm). Otherwise, consider using [Homebrew](https://formulae.brew.sh/formula/node) or installing [Node.js directly](https://nodejs.org/en).

Then:

1. `npm install`
2. `npm test`

------
## Updating bundled web components

Expand Down
5 changes: 5 additions & 0 deletions __tests__/utils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { expect, test } = require("@jest/globals");

test("dummy test to check Jest infrastructure works. Remove after", () => {
expect(true).toBe(true);
});
Loading

0 comments on commit b5d76bd

Please sign in to comment.