Skip to content

Commit

Permalink
Improve build tool to adapt the new tests architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
MangelMaxime committed Mar 13, 2024
1 parent 2755ce8 commit b17fee2
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 1,912 deletions.
12 changes: 6 additions & 6 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
"fable"
]
},
"fantomas": {
"version": "6.3.0-alpha-007",
"commands": [
"fantomas"
]
},
"husky": {
"version": "0.6.4",
"commands": [
Expand All @@ -25,6 +19,12 @@
"commands": [
"femto"
]
},
"fantomas": {
"version": "6.3.0-beta-001",
"commands": [
"fantomas"
]
}
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,5 @@ src/Glutinum.Web/CssModules.fs
*.fable-temp.csproj

.DS_Store

tests/specs/generated/
63 changes: 59 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,69 @@ type FSharpAttribute =

### Tests

Tests are generated based on the `tests/specs/` folder content.
This project use [Vitest](https://vitest.dev/) for running tests.

Each `.d.ts` correspond to a test and should have a matching `.fsx` file, the name of the test is the relative path to the `tests/specs/` folder without the `.d.ts` extension.
Vitest was chosen because it seems to have a lot of attention and is actively maintained. Plus, it seems well integrated with VSCode and Rider, allowing us to use the test explorer and even debug the tests using source maps.

For example, if you have a file `tests/specs/exports/variable.d.ts`, you should have a `tests/specs/exports/variable.fsx`.
If you prefer, it is possible to run the tests via the CLI.

The name of the test is `exports/variable`.
#### VSCode

Install [Vitest plugin](https://marketplace.visualstudio.com/items?itemName=vitest.explorer), then you will be able to run the tests from the test explorer.

#### Rider

You need to add a new configuration of type `Vitest`.

1. `Run > Edit Configurations...`
2. Add a new configuration of type `Vitest`
3. Then you can run the tests by selecting the configuration in the top right corner of the IDE.

#### Specs

> [!TIP]
> Run `./build.sh --help` to see the available options (look for `test specs` command).
Specs tests are using to test isolated TypeScript syntax and their conversion to F#.

They are generated based on the `tests/specs/references` folder.

Each `.d.ts` correspond to a test and have a matching `.fsx` file.

When running `./build.sh test specs`, it will generate a similar hierarchy in the `tests/specs/generated` folder.

Example:

```text
tests/specs/references
├── interfaces
│ ├── callSignature.d.ts
│ ├── callSignature.fsx
│ └── indexSignature
│ ├── numberParameter.d.ts
│ └── numberParameter.fsx
└── typeQuery
├── class.d.ts
├── class.fsx
├── defaultToObj.d.ts
└── defaultToObj.fsx
```

generates:

```text
tests/specs/generated
├── interfaces
│ ├── index.test.js
│ └── indexSignature
│ └── index.test.js
└── typeQuery
└── index.test.js
```

`index.test.js` contains all the tests for the `.d.ts` of the same folder.

> [!NOTE]
> If you are using VSCode, the `fsx` file will be nested under the `d.ts` file in your explorer.
The `.fsx` correspond to the expected result suffixed with the following:
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"@ts-morph/bootstrap": "^0.22.0",
"@vitejs/plugin-react": "^4.2.1",
"@vitest/ui": "^1.3.1",
"ava": "^6.1.2",
"bulma": "^0.9.4",
"dirname-filename-esm": "^1.1.1",
"fable-css-modules": "^1.7.0",
Expand Down
Loading

0 comments on commit b17fee2

Please sign in to comment.