Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
- { name: Checkout, uses: actions/checkout@v4 }
- { name: Setup Node.js environment, uses: actions/setup-node@v4, with: { node-version: ^18 || >=20 } }
- { name: Setup pnpm, uses: pnpm/action-setup@v3, with: { version: ^9.0.1, run_install: true } }
- run: export PATH=$PWD/node_modules/.bin:$PATH
- run: echo $PWD/node_modules/.bin:$PATH > $GITHUB_PATH
- run: scripts/package.sh
- run: scripts/lint.sh
- run: vitest run
25 changes: 25 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,28 @@ You can run the development version of HSM by running `node dist/bin/hsm.js`. Yo

### Install the Development Version of the NPM Package in Another Project
In the other project (e.g. testing with Hackmud Scripting Environment) run `pnpm add ~/path/to/hackmud-script-manager/dist`.

## Tests
Tests can be run by running `vitest run` (assuming you have followed above setup instructions).

There is currently not enforcement on writing unit tests but if you are going to, the test you write MUST be failing.
You CANNOT add passing tests. If you are also writing a fix for a new test, ensure that the fix is in a seperate commit
AFTER the commit the test is added in. This ensures that someone else can checkout the commit with the newly added test
and verify that it is failing, checkout the commit where the fix is implemented, and verify that the test is now
passing.

The files in the `game-scripts-test/` folder are the input for testing `processScript()`. They are read by the vitest
block at the bottom of `src/processScript/index.ts` where they are transformed and evaluated. Support for testing
subscripts and other preprocessor-related stuff is not yet implemented. If one of these tests is failing, you will see
the path outputed like so:

```
❯ src/processScript/index.ts (1 test | 1 failed) 6ms
× game-scripts-tests/this_function_array.ts 6ms
→ expected undefined to be [ [Function] ] // Object.is equality
```

Notice `game-scripts-tests/this_function_array.ts`.

The naming convention uses underscores instead of dashes as if it was the name of a real hackmud script (which cannot
contain dashes).
17 changes: 17 additions & 0 deletions game-scripts-tests/this_array_in_object.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default ({ expect }: typeof import('vitest')) => {
const test = {
[0]: 'test[0]',
foo: [
function () {
// @ts-ignore
return this[0]
}
],
bar() {
return this
}
};

expect(test.foo[0]!()).toBe(test.foo[0])
expect(test.bar()).toBe(test)
}
9 changes: 9 additions & 0 deletions game-scripts-tests/this_function_array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default ({ expect }: typeof import('vitest')) => {
const array = [
function (this: any) {
return this
}
]

expect(array[0]!()).toBe(array)
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
"@types/semver": "^7.5.8",
"babel-plugin-here": "^1.0.2",
"semver": "^7.6.3",
"typescript": "^5.7.2"
"typescript": "^5.7.2",
"vitest": "^3.0.5"
},
"peerDependencies": {
"typescript": "^5.4.5"
Expand Down
Loading
Loading