Skip to content

Commit ae53eb7

Browse files
Merge pull request #247 from SarahIsWeird/main
Replace this in object methods
2 parents 5970667 + e996cae commit ae53eb7

File tree

12 files changed

+1063
-61
lines changed

12 files changed

+1063
-61
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ jobs:
99
- { name: Checkout, uses: actions/checkout@v4 }
1010
- { name: Setup Node.js environment, uses: actions/setup-node@v4, with: { node-version: ^18 || >=20 } }
1111
- { name: Setup pnpm, uses: pnpm/action-setup@v3, with: { version: ^9.0.1, run_install: true } }
12-
- run: export PATH=$PWD/node_modules/.bin:$PATH
12+
- run: echo $PWD/node_modules/.bin:$PATH > $GITHUB_PATH
1313
- run: scripts/package.sh
1414
- run: scripts/lint.sh
15+
- run: vitest run

CONTRIBUTING.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,28 @@ You can run the development version of HSM by running `node dist/bin/hsm.js`. Yo
3030

3131
### Install the Development Version of the NPM Package in Another Project
3232
In the other project (e.g. testing with Hackmud Scripting Environment) run `pnpm add ~/path/to/hackmud-script-manager/dist`.
33+
34+
## Tests
35+
Tests can be run by running `vitest run` (assuming you have followed above setup instructions).
36+
37+
There is currently not enforcement on writing unit tests but if you are going to, the test you write MUST be failing.
38+
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
39+
AFTER the commit the test is added in. This ensures that someone else can checkout the commit with the newly added test
40+
and verify that it is failing, checkout the commit where the fix is implemented, and verify that the test is now
41+
passing.
42+
43+
The files in the `game-scripts-test/` folder are the input for testing `processScript()`. They are read by the vitest
44+
block at the bottom of `src/processScript/index.ts` where they are transformed and evaluated. Support for testing
45+
subscripts and other preprocessor-related stuff is not yet implemented. If one of these tests is failing, you will see
46+
the path outputed like so:
47+
48+
```
49+
❯ src/processScript/index.ts (1 test | 1 failed) 6ms
50+
× game-scripts-tests/this_function_array.ts 6ms
51+
→ expected undefined to be [ [Function] ] // Object.is equality
52+
```
53+
54+
Notice `game-scripts-tests/this_function_array.ts`.
55+
56+
The naming convention uses underscores instead of dashes as if it was the name of a real hackmud script (which cannot
57+
contain dashes).
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export default ({ expect }: typeof import('vitest')) => {
2+
const test = {
3+
[0]: 'test[0]',
4+
foo: [
5+
function () {
6+
// @ts-ignore
7+
return this[0]
8+
}
9+
],
10+
bar() {
11+
return this
12+
}
13+
};
14+
15+
expect(test.foo[0]!()).toBe(test.foo[0])
16+
expect(test.bar()).toBe(test)
17+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default ({ expect }: typeof import('vitest')) => {
2+
const array = [
3+
function (this: any) {
4+
return this
5+
}
6+
]
7+
8+
expect(array[0]!()).toBe(array)
9+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@
8686
"@types/semver": "^7.5.8",
8787
"babel-plugin-here": "^1.0.2",
8888
"semver": "^7.6.3",
89-
"typescript": "^5.7.2"
89+
"typescript": "^5.7.2",
90+
"vitest": "^3.0.5"
9091
},
9192
"peerDependencies": {
9293
"typescript": "^5.4.5"

0 commit comments

Comments
 (0)