Skip to content
This repository was archived by the owner on May 18, 2025. It is now read-only.

Commit 7b3af20

Browse files
committed
Add instructions for testing
1 parent c8f9fed commit 7b3af20

File tree

1 file changed

+81
-17
lines changed

1 file changed

+81
-17
lines changed

src/content/docs/developers/contributing.mdx

Lines changed: 81 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,113 @@
22
title: "Contributing"
33
description: "Introduction to developing OpenMarch"
44
sidebar:
5-
order: -1
5+
order: -1
66
---
77

8-
import { LinkCard } from '@astrojs/starlight/components';
8+
import { LinkCard } from "@astrojs/starlight/components";
9+
import { Steps } from "@astrojs/starlight/components";
910

1011
Get in here and contribute to OpenMarch! Learn our stack and codebase here.
1112

1213
We'd reccommend to take a look at all of our [tasks](https://github.com/OpenMarch/OpenMarch/issues), and pick some you'd like to work on. The ones with `good first issue` and `help wanted` tags are good for getting started.
1314

1415
Feel free to ask questions in the Discord if you're having problems with anything.
1516

16-
<LinkCard
17-
title="Stack"
18-
href="/developers/stack/"
19-
/>
17+
<LinkCard title="Stack" href="/developers/stack/" />
2018
<LinkCard
2119
title="Discord"
2220
href="https://discord.com/invite/eTsQ98uZzq"
2321
description="Go to #developers for support!"
2422
/>
2523

26-
## Running the Dev Environment
24+
## Running the Dev Environment
25+
26+
<Steps>
2727

2828
1. Download & install [Node.js](https://nodejs.org/en)
2929
2. Download the code via git from the main branch (if you're contributing, [make a fork](https://github.com/OpenMarch/OpenMarch/fork) and clone your own repo): `git clone https://github.com/OpenMarch/OpenMarch.git`
30-
- You might need to download git for this. You can also use other methods like the GitHub CLI
30+
- You might need to download git for this. You can also use other methods like the GitHub CLI
3131
3. Install dependencies: `npm install` (may take a while)
32-
- You might get a bunch of scary npm errors after installing. If running the app doesn't work after, follow [these steps](https://github.com/Automattic/node-canvas?tab=readme-ov-file#compiling) to fix it.
32+
- You might get a bunch of scary npm errors after installing. If running the app doesn't work after, follow [these steps](https://github.com/Automattic/node-canvas?tab=readme-ov-file#compiling) to fix it.
3333
4. Run the dev environment: `npm run dev`
34+
- If you see a bunch of errors, you may need to run `npm run app:prepare` first. More on this in the [running tests](#running-tests) section
35+
36+
</Steps>
3437

3538
## Codebase Structure
3639

3740
Our simplified directory structure:
3841

3942
- `/electron` - The "main" process, the backend of the app, with database and system functionality
40-
- /database
41-
- /main
42-
- /preload - Preload script for IPC
43+
- /database
44+
- /main
45+
- /preload - Preload script for IPC
4346
- `/src` - the "renderer" process, this is our react frontend.
44-
- `/components` - In here you find all the components of OpenMarch, the sidebars, titlebar, dialogs, UI component primitives. All of them are in their subfolder.
45-
- `/context` - React Context for the app of some sort of state/value
46-
- `/global` - Classes, objects and functions for various items in the app, such as Page, Marcher, MarcherShape, etc.
47-
- `/stores` - Global stores for certain items and actions, such as the list of Pages and Marchers
48-
- `App.tsx` - the main app file
47+
- `/components` - In here you find all the components of OpenMarch, the sidebars, titlebar, dialogs, UI component primitives. All of them are in their subfolder.
48+
- `/context` - React Context for the app of some sort of state/value
49+
- `/global` - Classes, objects and functions for various items in the app, such as Page, Marcher, MarcherShape, etc.
50+
- `/stores` - Global stores for certain items and actions, such as the list of Pages and Marchers
51+
- `App.tsx` - the main app file
4952

5053
Most of the directories like `stores`, `context`, `database` also have a `__test__` directory. These are [Vitest](https://vitest.dev/) or [Playwright](https://playwright.dev/) tests, which test the functionalites of certain things. Tests are important, please write them!
54+
55+
## Running Tests
56+
57+
Since Electron has to rebuild `better-sqlite3` (the package used to interact with the database), we must follow a few steps when transitioning between running automated tests and running the app.
58+
59+
### Prepare for testing
60+
61+
These steps only apply for tests involving database interactions.
62+
You don't need to rebuild any packages if you're only testing frontend components.
63+
If you don't, though, the entire test suite will not pass.
64+
65+
> For frontend specific tests, ignore the steps below and just run `npm run test`.
66+
>
67+
> Using the `Vitest` extension in VSCode is also handy.
68+
69+
<Steps>
70+
71+
1. Close the app if it's running
72+
1. Rebuild the `better-sqlite3` package
73+
74+
```bash
75+
npm run test:prepare
76+
```
77+
78+
- This will rebuild `better-sqlite3` to run on the same version of Node.js that the rest of the packages are on
79+
80+
1. If the tests didn't start, run them again
81+
82+
```bash
83+
npm run test
84+
```
85+
86+
1. You can see other test scripts in the `package.json`
87+
88+
</Steps>
89+
90+
### Running the app after testing
91+
92+
Since we rebuilt `better-sqlite3` with `npm`, we must rebuild it so that it can run in our Electron main process.
93+
94+
> Also do this if you ever see this error. It indicates that `better-sqlite3` has not been rebuilt with the same version of Node.js as the Electron main process:
95+
>
96+
> ```
97+
> Failed to connect to database:
98+
> PLEASE RUN 'node_modules/.bin/electron-rebuild -f -w better-sqlite3' to resolve this
99+
> ```
100+
101+
<Steps>
102+
103+
1. Stop any tests if they are running.
104+
1. Rebuild `better-sqlite3` for Electron
105+
106+
```bash
107+
npm run app:prepare
108+
```
109+
110+
- This will rebuild `better-sqlite3` to run on the same version of Node.js that the Electron main process is on
111+
112+
1. The app should launch on its own, but if it doesn't you can run `npm run dev` to launch it.
113+
114+
</Steps>

0 commit comments

Comments
 (0)