Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add stricter Query types #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "0.8.1",
"scripts": {
"test": "jest --config jestconfig.json --detectOpenHandles",
"type-tests": "tsd",
"test:watch": "jest --watch --config jestconfig.json --detectOpenHandles",
"perf": "rollup --config rollup.benchmarks.config.mjs && cp index.* perf.* lib && tsc && env NODE_ENV=test node --expose-gc --enable-source-maps --es-module-specifier-resolution=node lib/benchmarks/index.js",
"deopt": "rm *.log && node --trace-ic --enable-source-maps --es-module-specifier-resolution=node lib/tests/performance.test.js && mv *.log v8.pre.log && node striplog.cjs && deoptigate",
Expand All @@ -23,6 +24,13 @@
"engines": {
"node": ">=12"
},
"tsd": {
"directory": "test-d",
"compilerOptions": {
"target": "esnext",
"lib": ["esnext", "dom"]
}
},
"repository": "[email protected]:lastolivegames/becsy.git",
"author": "Piotr Kaminski <[email protected]>",
"license": "MIT",
Expand All @@ -42,6 +50,7 @@
"rollup-plugin-terser": "^7.0.2",
"ts-jest": "^27.0.5",
"tsc-watch": "^4.2.9",
"tsd": "^0.17.0",
"typescript": "^4.2.3"
}
}
4 changes: 4 additions & 0 deletions test-d/empty.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* This has to be a empty file
* @see https://github.com/MLH-Fellowship/jest-runner-tsd/blob/e25720040939fc79ab38d73c1495be90d5b92566/README.md#for-typescript-projects
*/
101 changes: 101 additions & 0 deletions test-d/query.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import {expectType} from 'tsd';
import {System} from '../src/system';

test('query has not flavours by default', () => {
class A {
a = 0;
}

interface ExpectedShape {
current: undefined;
added: undefined;
removed: undefined;
changed: undefined;
addedOrChanged: undefined;
changedOrRemoved: undefined;
addedChangedOrRemoved: undefined;
}

class UnusedTestSystem extends System {
private q = this.query(b => b.with(A));
execute() {
expectType<ExpectedShape>(this.q);
}
}
});

test('query has flavour added by .with', () => {
class A {
a = 0;
}

interface ExpectedShape {
current: readonly Entity[];
}

class UnusedTestSystem extends System {
private q = this.query(b => b.with(A));
execute() {
expectType<ExpectedShape>(this.q);
}
}
});

test('query has narrow flavour type added by .with', () => {
class A {
a = 0;
}

interface ExpectedShape {
current: readonly A[];
}

class UnusedTestSystem extends System {
private q = this.query(b => b.with(A));
execute() {
expectType<ExpectedShape>(this.q);
}
}
});

test('query has narrow flavour types added by multiple .with', () => {
class A {
a = 0;
}

class B {
b = 0;
}

interface ExpectedShape {
current: readonly A[] | readonly B[];
}

class UnusedTestSystem extends System {
private q = this.query(b => b.with(A).with(B));
execute() {
expectType<ExpectedShape>(this.q);
}
}
});

test('query has narrow flavour types added by single .with', () => {
class A {
a = 0;
}

class B {
b = 0;
}

interface ExpectedShape {
current: readonly A[] | readonly B[];
}

class UnusedTestSystem extends System {
private q = this.query(b => b.with(A, B));
execute() {
expectType<ExpectedShape>(this.q);
}
}
});
Loading