Skip to content

Commit b8b5ab2

Browse files
committed
Reformat remaining Markdown files
1 parent 0c8edb2 commit b8b5ab2

File tree

8 files changed

+52
-1
lines changed

8 files changed

+52
-1
lines changed

docs/src/modules/4-advanced/flow/flow.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
6. Any tabs that need to be loaded will then be loaded, ready for display by the frontend.
1212

1313
## In the Frontend
14+
1415
![image](./fig2.png)
1516
> Figure 2: The Flow of the Source Modules system in the frontend
1617

docs/src/modules/4-advanced/linting.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ order: 2
33
---
44

55
# Code Formatting and Linting
6+
67
Code linting is the process of conducting static analysis on code to detect potential runtime issues and enforce
78
stylistic conventions. Linting for the repository is provided by [ESLint](https://eslint.org).
89

@@ -11,31 +12,38 @@ stylistic conventions. Linting for the repository is provided by [ESLint](https:
1112
> removed from the Modules repository.
1213
1314
## Running ESLint
15+
1416
ESLint can be run on its own on your bundle/tab code by using either of the following commands:
17+
1518
```sh
1619
yarn lint
1720
yarn buildtools lint .
1821
```
1922

2023
If you wish to run ESLint during the build process, you can instead use:
24+
2125
```sh
2226
yarn build --lint
2327
yarn buildtools build <bundle|tab> . --lint
2428
```
2529

2630
## Disabling ESLint Rules
31+
2732
If, for whatever reason you need to disable a specific ESLint rule for your bundle/tab, you can use the `// eslint-disable` directive. Please provide a short explanation on why
2833
the rule needs to be disabled, following the example provided below:
34+
2935
```tsx
3036
import { Button } from '@blueprintjs/core';
3137
// eslint-disable @typescript-eslint/no-var-requires This import doesn't work if written using ESM
3238
const TextBox = require('Textbox').default
3339
```
3440

3541
## Ignoring Files
42+
3643
By default, ESLint has been configured to not lint files in specific directories or matching specific patterns. You can see the ignore patterns in `eslint.config.js` under the section labelled "Global Ignores". Please
3744
note that if any of your code files matche these ignore patterns, they will not be properly linted by ESLint.
3845

3946
## Integration with Git Hooks
47+
4048
Linting is run during the pre-push hook and also on pull-requests. Your code must not have any lint errors in order to be pushed to the
4149
branch and can have neither errors nor warnings to be merged.

docs/src/modules/4-advanced/manifest.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
title: Modules Manifest
33
---
44
# The Modules Manifest
5+
56
Every bundle has its own [manifest](../2-bundle/1-overview#manifestjson), but there is also a combined manifest, which actually consists of all the
67
separate bundles' manifests combined into one. This serves as a easy file for `js-slang` to check against when loading bundles and also to make
78
sure that the bundle being loaded actually exists.

docs/src/modules/4-advanced/testing.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The testing library used by this repository is [`vitest`](https://vitest.dev).
88
> [!IMPORTANT]
99
> Other Source Academy repositories use `jest` as their testing package. Although `vitest` has been designed as a drop in replacement for `jest`,
1010
> there are subtle differences between the two. For example, `vi.spyOn` doesn't replace the implementation within the module while `jest.spyOn` does (See [here](https://vitest.dev/guide/mocking.html#mocking-pitfalls)).
11-
>
11+
>
1212
> Refer to [this page](https://vitest.dev/guide/migration.html#jest) for more differences between `jest` and `vitest`.
1313
1414
## Adding Tests
@@ -17,6 +17,7 @@ By default, any Typescript (`.ts`) files located within a `__tests__` folder are
1717
detect any tests within that file, it will throw an error. This also includes any subdirectories under a `__tests__` folder.
1818

1919
Simply write your tests within a `__tests__` folder:
20+
2021
```ts
2122
// curve/src/__tests__/index.ts
2223
import { describe, expect, test } from 'vitest'; // You will need to import these functions, unlike in Jest
@@ -33,6 +34,7 @@ describe('This is a describe block', () => {
3334
> Javascript and Typescript declarations but will still conduct type checking for them.
3435
3536
Tests for tabs can also use the `.tsx` extension along with JSX syntax:
37+
3638
```tsx
3739
// Curve/__tests__/index.tsx
3840
import { expect, test } from 'vitest';
@@ -52,16 +54,19 @@ For more instructions on how to write tests you can refer to the [Vitest website
5254
5355
While writing tests, you might find that you might want to focus on a single test or single group of tests. For this, `vitest` provides on its `test`, `it` and `describe` functions
5456
a `.skip` and a `.only` property:
57+
5558
```ts
5659
describe('Test1 and Test3 will run!', () => {
5760
test('Test1', () => {});
5861
test.skip('Test2', () => {});
5962
test('Test3', () => {})
6063
});
6164
```
65+
6266
You don't have to comment out your tests; simply use `.skip` to indicate that a test block should not be executed.
6367

6468
If for some reason you want to skip your tests based on some condition, `vitest` provides the `skipIf` property:
69+
6570
```ts
6671
describe('Test1 and Test3 will run!', () => {
6772
test('Test1', () => {});
@@ -71,13 +76,15 @@ describe('Test1 and Test3 will run!', () => {
7176
```
7277

7378
`.only` is kind of the reverse of `.skip`. Tests that you use `.only` with will be the **only** tests that run in that file:
79+
7480
```ts
7581
describe('Only Test 2 will run!', () => {
7682
test('Test1', () => {});
7783
test.only('Test2', () => {});
7884
test('Test3', () => {})
7985
});
8086
```
87+
8188
The main runner that runs unit tests on the CI/CD pipeline does not allow for `.only`. You can simulate this behaviour by running your tests with the
8289
`--no-allow-only` flag. This behaviour is intended to prevent you from causing only part of your tests to run.
8390

@@ -86,12 +93,14 @@ The main runner that runs unit tests on the CI/CD pipeline does not allow for `.
8693
> to remove `.only` before pushing to the main repository.
8794
8895
Pushing with skipped tests however, is allowed. Do leave a comment explaining why the test is skipped:
96+
8997
```ts
9098
// Test is skipped because there is an outstanding bug
9199
test.skip('Test path resolution', () => {})
92100
```
93101

94102
### Stubbing Tests
103+
95104
If you want to indicate that tests should be written for certain functionality in the future, you can use `.todo`:
96105

97106
```ts
@@ -102,7 +111,9 @@ test.todo('Test path resolution')
102111
TODO tests still generate an entry in your test reports, but will be considered neither failed nor passed.
103112

104113
## Running Tests
114+
105115
To run tests for a given bundle or tab, simply run either of the following commands within the directory:
116+
106117
```sh
107118
yarn buildtools test .
108119
yarn test # If your package.json has this script specified
@@ -115,13 +126,16 @@ You can also use `--update` to update snapshots and `--coverage` to run the V8 c
115126
For bundles and tabs, the test environment should always be `jsdom`, since they are intended for the browser.
116127

117128
## Integration with Git Hooks
129+
118130
Any tests that you have written must be pass in order for you to push to the main repository, as well as for your pull requests to be merged.
119131

120132
> [!TIP]
121133
> You can push to the branch while bypassing the Git hook by running:
134+
>
122135
> ```sh
123136
> git push --no-verify
124137
> ```
138+
>
125139
> However, the tests will still be run and must pass before your pull request can be merged. So, we recommend not using this option
126140
> unless absolutely necessary.
127141
@@ -138,18 +152,21 @@ written in plain Javascript with a <nobr><code>// @ts-check</code></nobr> direct
138152
139153
> [!WARNING] Dependency Optimization Error
140154
> You may find that when your tests run on your local machine the following warning (or something similar) may appear:
155+
>
141156
> ```sh
142157
> [vite] (client) ✨ new dependencies optimized: react/jsx-dev-runtime
143158
> [vite] (client) ✨ optimized dependencies changed. reloading
144159
> [vitest] Vite unexpectedly reloaded a test. This may cause tests to fail, lead to flaky behaviour or duplicated test runs.
145160
> For a stable experience, please add mentioned dependencies to your config's `optimizeDeps.include` field manually.
146161
> ```
162+
>
147163
> If this warning appears when you run your tests on the machine, you may find that your tests may still pass on the local machine, but
148164
> fail on the CI pipeline.
149165
>
150166
> This is because you have a dependency that Vite can only detect at runtime and so has to run its internal transforms twice. This causes
151167
> Vitest to fail, since the original import would have failed. To fix this, you should create your own `vitest.config.js` and add those
152168
> dependencies to `optimizeDeps`:
169+
>
153170
> ```js
154171
> export default defineProject({
155172
> optimizeDeps: {
@@ -160,13 +177,15 @@ written in plain Javascript with a <nobr><code>// @ts-check</code></nobr> direct
160177
> }
161178
> })
162179
> ```
180+
>
163181
> For more information, refer to the [Vite](https://vite.dev/config/dep-optimization-options.html#optimizedeps-include) documentation.
164182
165183
Should you need to use a unique configuration, simply create your own `vitest.config.js` at the root of your bundle/tab.
166184
The configuration options in your `vitest.config.js` will be used **in addition** to the default options, so it is not necessary
167185
to redefine every single option in your configuration file.
168186
169187
You should use the `defineProject` helper instead of the `defineConfig` helper:
188+
170189
```js [vitest.config.js]
171190
// @ts-check
172191
import { defineProject } from 'vitest/config';
@@ -183,13 +202,15 @@ There is no need to use `mergeConfig` to merge your configuration with the root
183202
the merging is performed automatically.
184203
185204
## Browser Mode
205+
186206
Tabs have the ability to leverage `playwright` and `vitest`'s browser mode to ensure that the interactive features of the tab actually
187207
behave like they should.
188208
189209
The default testing configuration for tabs has browser mode disabled. This is so that if your tab doesn't need the features that Playwright provides,
190210
`vitest` won't need to spin up the Playwright instance.
191211
192212
### Setting up Browser Mode
213+
193214
Should you wish to enable browser mode, create a custom `vitest` configuration file for your tab with the `browswer.enabled` option set to `true`:
194215
195216
```js {9}
@@ -214,13 +235,15 @@ Now, the tests for your tab will be run in browser mode.
214235
> add more instances if necessary.
215236
216237
### Writing Interactive Tests
238+
217239
Writing interactive tests is not very different from writing regular tests. Most of the time, the usual test and assertion functions will suffice.
218240
219241
> [!INFO]
220242
> While writing your tests, you should use watch mode. This will allow `vitest` to open a browser and actually display what your tab looks like whilst
221243
> being rendered during the test.
222244
223245
Use the `render` function provided `vitest-browser-react` to render your tab/component to a screen. The returned component can then be interacted with:
246+
224247
```tsx
225248
import { render } from 'vitest-browser-react';
226249
@@ -233,13 +256,15 @@ test('Testing my component', () => {
233256
expect().somethingToHaveHappened();
234257
});
235258
```
259+
236260
`vitest` also provides [a different set](https://vitest.dev/guide/browser/assertion-api.html) of matchers that you can use specifically with browser elements.
237261
238262
> [!TIP]
239263
> `vitest-browser-react` also provides a `cleanup` function that can be used after each test. You don't _technically_ need to use it, but
240264
> you may find that if you have multiple tests in the same file that behaviour might be inconsistent.
241265
>
242266
> You can use it with `afterEach` from `vitest`:
267+
>
243268
> ```ts
244269
> import { afterEach } from 'vitest';
245270
> import { cleanup } from 'vitest-browser-react';
@@ -248,6 +273,7 @@ test('Testing my component', () => {
248273
> ```
249274
250275
### `expect.poll` and `expect.element`
276+
251277
Sometimes, visual elements take a while to finish or an element might take a while to load. If you just directly used an assertion, the assertion
252278
might fail because the element hasn't displayed yet:
253279
@@ -263,6 +289,7 @@ test('An animation', async () => {
263289
```
264290
265291
Instead, `vitest` provides a special set of matchers that can be used to "retry" the assertion until it passes or when it times out:
292+
266293
```tsx
267294
import { render } from 'vitest-browser-react';
268295
@@ -277,9 +304,11 @@ test('An animation', async () => {
277304
```
278305
279306
### Animations with `requestAnimationFrame`
307+
280308
If you're using `requestAnimationFrame` to trigger animations, you can also test the behaviour of these animated components.
281309
282310
Firstly, add the following setup and teardown function calls to your code:
311+
283312
```ts
284313
import { beforeEach, afterEach, vi } from 'vitest';
285314

docs/src/modules/4-advanced/typescript.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ Using the [`extends`](https://www.typescriptlang.org/tsconfig/#extends) property
44
different levels to share options across both bundles and tabs.
55

66
## Missing types for dependencies and overriding `tsconfig.json`
7+
78
Sometimes, your bundle might depend on packages that have published their types differently. For example, the `communication` bundle requires `mqtt`:
9+
810
```ts
911
import { connect, type MqttClient, type QoS } from 'mqtt/dist/mqtt';
1012
// Need to use "mqtt/dist/mqtt" as "mqtt" requires global, which SA's compiler does not define.
@@ -16,7 +18,9 @@ export const STATE_OFFLINE = 'Offline';
1618

1719
// ...other things
1820
```
21+
1922
The `mqtt` dependency however, is specified as such in `package.json`:
23+
2024
```json
2125
{
2226
"dependencies": {
@@ -25,6 +29,7 @@ The `mqtt` dependency however, is specified as such in `package.json`:
2529
}
2630
}
2731
```
32+
2833
The helpful comment below the import explains the discrepancy. Without further configuration, we find that Typescript is unable to find the types for the `mqtt/dist/mqtt` package:
2934
![](./mqtt-types.png)
3035

docs/src/repotools/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
The `@sourceacademy/modules-repotools` package itself has a bunch of utilities for working with the repository.
44

55
Below is a list of other tools:
6+
67
- [Development Server](./devserver/devserver)
78
- [Docs Server](./docserver/1-overview)
89
- [ESLint](./linting)

docs/src/repotools/linting.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ The ESLint config file for this repository is fairly complex. The different conf
44
You can refer to [this](https://eslint.org/docs/latest/use/configure/configuration-files) page for more information on how ESLint processes these configuration objects.
55

66
Generally, there are two types of linting rules:
7+
78
1. Repository only code (used for development of modules)
89
2. Module code (Code that is actually intended to be used in Source)
910

@@ -14,6 +15,7 @@ ESLint does provide a configuration inspector which can be started using <nobr>`
1415
and also other information like what rules are considered deprecated.
1516

1617
## Configuration Conventions
18+
1719
Our linting configurations often inherit from recommended configurations provided by plugins. However, not all of the rules that are configured by these configurations make sense
1820
for the repository at large. This requires that we manually override some of the settings provided by these configurations.
1921

@@ -36,6 +38,7 @@ are usually incomplete snippets of Typescript/Javascript, so a lot of the typica
3638
-->
3739

3840
## Linting JSON Files
41+
3942
For the most part, there are only stylistic rules that need to be applied to JSON files. This is why this repository doesn't use the official `@eslint/json` package for linting JSON files.
4043
Instead. the parser from `eslint-plugin-json` is used so that stylistic rules can be applied to the JSON files. This does mean that none of the rules from `@eslint/json` can be applied
4144
directly.

docs/src/repotools/vscode.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
# VSCode Integration
2+
23
This page is dedicated to explaining all the VSCode integrations available from this repository.
34

45
Since most developers here are assumed to be using Visual Studio Code, this repository automatically provides some extra tooling that integrates with VSCode, all found within the `.vscode` folder.
56

67
## JSON Schemas
8+
79
By default, VSCode doesn't apply any kind of validation to JSON files that don't have explicit schemas. Using the `settings.json` file, we can apply JSON schemas to specific JSON files.
810

911
For this repository, this has been configured for `tsconfig.*.json` files to extend both the original `tsconfig` schema, but also to include the Typedoc schema. Bundle manifest files
1012
should also automatically receive validation and IntelliSense autocompletion.
1113

1214
## ESLint Validation
15+
1316
By default, the VSCode ESLint extension doesn't also lint YAML files. This means that although ESLint will lint YAML files, the linting warnings and errors
1417
for YAML files will not appear in VSCode. Thus, we need to provide a specific configuration to tell the extension to lint YAML files.

0 commit comments

Comments
 (0)