Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp committed Dec 31, 2024
1 parent 1f52fed commit 78bdd5d
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 9 deletions.
32 changes: 24 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
],
"devDependencies": {
"@changesets/cli": "^2.26.0",
"node-qunit-puppeteer": "^2.2.0",
"bundlesize": "^1.0.0-beta.2",
"local-web-server": "^4.2.1",
"node-qunit-puppeteer": "^2.2.0",
"wireit": "^0.9.3"
},
"wireit": {
Expand All @@ -31,5 +31,8 @@
}
}
}
},
"dependencies": {
"expect-type": "^1.1.0"
}
}
12 changes: 12 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"bundlesize": "wireit",
"server": "wireit",
"test": "wireit",
"test:types": "wireit",
"test:browser": "wireit",
"build:cjs": "wireit",
"build": "wireit"
},
Expand Down Expand Up @@ -74,6 +76,16 @@
}
},
"test": {
"dependencies": [
"test:types",
"test:browser"
]
},
"test:types": {
"command": "tsc -p test/types/tsconfig.json",
"files": []
},
"test:browser": {
"command": "node-qunit-puppeteer http://localhost:1965/test/test.html 10000",
"dependencies": [
"server"
Expand Down
24 changes: 24 additions & 0 deletions packages/core/test/types/send.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { expectTypeOf } from 'expect-type';
import { test } from 'node:test';
import {
type Service,
createMachine,
transition,
state,
} from 'robot3';

test('send(event) is typed', () => {
const machine = createMachine({
one: state(transition('go-two', 'two')),
two: state(transition('go-one', 'one')),
three: state()
});

type Params = Parameters<Service<typeof machine>['send']>;
type EventParam = Params[0];
type StringParams = Extract<EventParam, string>;
expectTypeOf<StringParams>().toEqualTypeOf<'go-one' | 'go-two'>();

type ObjectParams = Extract<EventParam, { type: string; }>;
expectTypeOf<ObjectParams['type']>().toEqualTypeOf<'go-one' | 'go-two'>();
});
33 changes: 33 additions & 0 deletions packages/core/test/types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"include": ["../..", "."],
"exclude": ["../../node_modules"],
"compilerOptions": {
/* Base Options: */
"esModuleInterop": true,
"skipLibCheck": false,
"target": "es2022",
"allowJs": false,
"moduleDetection": "force",
"isolatedModules": true,
"moduleResolution": "nodenext",

/* Strictness */
"strict": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,

/* AND if you're building for a library: */
"declaration": true,

/* AND if you're building for a library in a monorepo: */
"composite": true,
"declarationMap": true,

/* If NOT transpiling with TypeScript: */
"module": "nodenext",
"noEmit": true,

/* If your code runs in the DOM: */
"lib": ["es2022", "dom", "dom.iterable"]
}
}

0 comments on commit 78bdd5d

Please sign in to comment.