Skip to content

Commit 78bdd5d

Browse files
committed
Add tests
1 parent 1f52fed commit 78bdd5d

File tree

5 files changed

+97
-9
lines changed

5 files changed

+97
-9
lines changed

Diff for: package-lock.json

+24-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
],
1818
"devDependencies": {
1919
"@changesets/cli": "^2.26.0",
20-
"node-qunit-puppeteer": "^2.2.0",
2120
"bundlesize": "^1.0.0-beta.2",
2221
"local-web-server": "^4.2.1",
22+
"node-qunit-puppeteer": "^2.2.0",
2323
"wireit": "^0.9.3"
2424
},
2525
"wireit": {
@@ -31,5 +31,8 @@
3131
}
3232
}
3333
}
34+
},
35+
"dependencies": {
36+
"expect-type": "^1.1.0"
3437
}
3538
}

Diff for: packages/core/package.json

+12
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
"bundlesize": "wireit",
3030
"server": "wireit",
3131
"test": "wireit",
32+
"test:types": "wireit",
33+
"test:browser": "wireit",
3234
"build:cjs": "wireit",
3335
"build": "wireit"
3436
},
@@ -74,6 +76,16 @@
7476
}
7577
},
7678
"test": {
79+
"dependencies": [
80+
"test:types",
81+
"test:browser"
82+
]
83+
},
84+
"test:types": {
85+
"command": "tsc -p test/types/tsconfig.json",
86+
"files": []
87+
},
88+
"test:browser": {
7789
"command": "node-qunit-puppeteer http://localhost:1965/test/test.html 10000",
7890
"dependencies": [
7991
"server"

Diff for: packages/core/test/types/send.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { expectTypeOf } from 'expect-type';
2+
import { test } from 'node:test';
3+
import {
4+
type Service,
5+
createMachine,
6+
transition,
7+
state,
8+
} from 'robot3';
9+
10+
test('send(event) is typed', () => {
11+
const machine = createMachine({
12+
one: state(transition('go-two', 'two')),
13+
two: state(transition('go-one', 'one')),
14+
three: state()
15+
});
16+
17+
type Params = Parameters<Service<typeof machine>['send']>;
18+
type EventParam = Params[0];
19+
type StringParams = Extract<EventParam, string>;
20+
expectTypeOf<StringParams>().toEqualTypeOf<'go-one' | 'go-two'>();
21+
22+
type ObjectParams = Extract<EventParam, { type: string; }>;
23+
expectTypeOf<ObjectParams['type']>().toEqualTypeOf<'go-one' | 'go-two'>();
24+
});

Diff for: packages/core/test/types/tsconfig.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"include": ["../..", "."],
3+
"exclude": ["../../node_modules"],
4+
"compilerOptions": {
5+
/* Base Options: */
6+
"esModuleInterop": true,
7+
"skipLibCheck": false,
8+
"target": "es2022",
9+
"allowJs": false,
10+
"moduleDetection": "force",
11+
"isolatedModules": true,
12+
"moduleResolution": "nodenext",
13+
14+
/* Strictness */
15+
"strict": true,
16+
"noUncheckedIndexedAccess": true,
17+
"noImplicitOverride": true,
18+
19+
/* AND if you're building for a library: */
20+
"declaration": true,
21+
22+
/* AND if you're building for a library in a monorepo: */
23+
"composite": true,
24+
"declarationMap": true,
25+
26+
/* If NOT transpiling with TypeScript: */
27+
"module": "nodenext",
28+
"noEmit": true,
29+
30+
/* If your code runs in the DOM: */
31+
"lib": ["es2022", "dom", "dom.iterable"]
32+
}
33+
}

0 commit comments

Comments
 (0)