You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can use the CLI to automatically add and update workflows to your code:
@@ -15,6 +13,9 @@ $ flarum-cli infra githubActions
15
13
16
14
:::
17
15
16
+
## Backend
17
+
18
+
18
19
All you need to do is create a `.github/workflows/backend.yml` file in your extension, it will reuse a predefined workflow by the core development team which can be found [here](https://github.com/flarum/framework/blob/main/.github/workflows/REUSABLE_backend.yml). You need to specify the configuration as follows:
19
20
20
21
```yaml
@@ -34,9 +35,7 @@ jobs:
34
35
backend_directory: .
35
36
```
36
37
37
-
## Backend
38
-
39
-
Flarum provides a pre-defined workflow for running certain jobs for the backend of your extension. These are the currently available jobs:
@@ -69,4 +68,52 @@ For more details on parameters, [checkout the full predefined reusable workflow
69
68
70
69
## Frontend
71
70
72
-
Soon..
71
+
All you need to do is create a `.github/workflows/frontend.yml` file in your extension, it will reuse a predefined workflow by the core development team which can be found [here](https://github.com/flarum/framework/blob/main/.github/workflows/REUSABLE_frontend.yml). You need to specify the configuration as follows:
| Backend Directory | `backend_directory` | The directory of the project where backend code is located. This should contain a `composer.json` file, and is generally the root directory of the repo. | string |
110
+
| Frontend Directory | `frontend_directory` | The directory of the project where frontend code is located. This should contain a `package.json` file. | string |
111
+
| Main Git Branch | `main_git_branch` | The main git branch to use for the workflow. | string |
112
+
| Node Version | `node_version` | The node version to use for the workflow. | string |
113
+
| JS Package Manager | `js_package_manager` | The package manager to use (ex. yarn) | string |
114
+
| Cache Dependency Path | `cache_dependency_path` | The path to the cache dependency file. | string |
115
+
:::tip
116
+
117
+
For more details on parameters, [checkout the full predefined reusable workflow file](https://github.com/flarum/framework/blob/main/.github/workflows/REUSABLE_frontend.yml).
Then, you will need to set up a file structure for tests:
455
+
456
+
```
457
+
js
458
+
├── dist
459
+
├── src
460
+
├── tests
461
+
│ ├── unit
462
+
│ │ └── functionTest.test.js
463
+
│ ├── integration
464
+
│ │ └── componentTest.test.js
465
+
├── package.json
466
+
├── tsconfig.json
467
+
├── tsconfig.test.json
468
+
├── jest.config.cjs
469
+
└── webpack.config.cjs
470
+
```
471
+
472
+
#### GitHub Testing Workflow
473
+
474
+
To run tests on every commit and pull request, check out the [GitHub Actions](github-actions.md) page.
475
+
476
+
### Using Unit Tests
477
+
478
+
Like any other JS project, you can use Jest to write unit tests for your frontend code. Checkout the [Jest docs](https://jestjs.io/docs/using-matchers) for more information on how to write tests.
479
+
480
+
Here's a simple example of a unit test fo core's `abbreviateNumber` function:
test('abbreviates large numbers with decimal places', () => {
495
+
expect(abbreviateNumber(100500)).toBe('100.5K');
496
+
expect(abbreviateNumber(13234)).toBe('13.2K');
497
+
});
498
+
```
499
+
500
+
### Using Integration Tests
501
+
502
+
Integration tests are used to test the components of your frontend code and the interaction between different components. For example, you might test that a page component renders the correct content based on certain parameters.
503
+
504
+
Here's a simple example of an integration test for core's `Alert` component:
These are the custom methods that are available for mithril component tests:
561
+
***`toHaveElement(selector)`** - Checks if the component has an element that matches the given selector.
562
+
***`toContainRaw(content)`** - Checks if the component HTML contains the given content.
563
+
564
+
To negate any of these methods, simply prefix them with `not.`. For example, `expect(alert).not.toHaveElement('button.Alert-dismiss');`. For more information, check out the [Jest docs](https://jestjs.io/docs/using-matchers). For example you may need to check how to [mock functions](https://jestjs.io/docs/mock-functions), or how to use `beforeEach` and `afterEach` to set up and tear down tests.
0 commit comments