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

Add type-checking to tests/warp-drive__schema-record #9085

Merged
merged 6 commits into from
Nov 2, 2023
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ concurrency:

jobs:
lint:
timeout-minutes: 5
timeout-minutes: 6
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
Expand Down
2 changes: 1 addition & 1 deletion config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"node": ">= 20.9.0"
},
"volta": {
"extends": "../../package.json"
"extends": "../package.json"
},
"packageManager": "[email protected]"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"lint:prettier": "prettier --check --cache --cache-location=.prettier-cache --log-level=warn .",
"lint:prettier:fix": "prettier --write --cache --cache-location=.prettier-cache --log-level=warn .",
"preinstall": "npx only-allow pnpm",
"check:types": "pnpm run -r --workspace-concurrency=-1 --if-present check:types",
"check:types": "bun run turbo --log-order=stream check:types",
"test": "pnpm turbo test --concurrency=1",
"test:production": "pnpm turbo test:production --concurrency=1",
"test:try-one": "pnpm --filter main-test-app run test:try-one",
Expand Down
9 changes: 8 additions & 1 deletion packages/schema-record/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@
"README.md",
"LICENSE.md",
"NCC-1701-a.svg",
"NCC-1701-a-blue.svg"
"NCC-1701-a-blue.svg",
"unstable-preview-types"
],
"exports": {
"./*": {
"types": "./unstable-preview-types/*.d.ts",
"default": "./addon/*.js"
}
},
"dependenciesMeta": {
"@ember-data/private-build-infra": {
"injected": true
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion tests/warp-drive__schema-record/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Resolver from './resolver';
class App extends Application {
modulePrefix = config.modulePrefix;
podModulePrefix = config.podModulePrefix;
Resolver = Resolver;
override Resolver = Resolver;
}

loadInitializers(App, config.modulePrefix);
Expand Down
8 changes: 4 additions & 4 deletions tests/warp-drive__schema-record/app/services/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import JSONAPICache from '@ember-data/json-api';
import RequestManager from '@ember-data/request';
import Fetch from '@ember-data/request/fetch';
import DataStore, { CacheHandler } from '@ember-data/store';
import type { Cache } from '@ember-data/store/-types/cache/cache';
import type { CacheCapabilitiesManager } from '@ember-data/store/-types/q/cache-store-wrapper';
import type { Cache } from '@warp-drive/core-types/cache';

export default class Store extends DataStore {
constructor(args: unknown) {
Expand All @@ -18,15 +18,15 @@ export default class Store extends DataStore {
manager.useCache(CacheHandler);
}

createCache(capabilities: CacheCapabilitiesManager): Cache {
override createCache(capabilities: CacheCapabilitiesManager): Cache {
return new JSONAPICache(capabilities);
}

instantiateRecord(identifier: StableRecordIdentifier, createArgs?: Record<string, unknown>): SchemaRecord {
override instantiateRecord(identifier: StableRecordIdentifier, createArgs?: Record<string, unknown>): SchemaRecord {
return instantiateRecord(this, identifier, createArgs);
}

teardownRecord(record: SchemaRecord): void {
override teardownRecord(record: SchemaRecord): void {
return teardownRecord(record);
}
}
3 changes: 3 additions & 0 deletions tests/warp-drive__schema-record/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"scripts": {
"build:tests": "IS_TESTING=true EMBER_CLI_TEST_COMMAND=true ember build --output-path=dist-test --suppress-sizes",
"check:types": "tsc --noEmit",
"start": "ember test --port=0 --serve --no-launch",
"test": "ember test --test-port=0 --path=dist-test",
"_syncPnpm": "bun run sync-dependencies-meta-injected"
Expand Down Expand Up @@ -75,6 +76,7 @@
"@ember/test-helpers": "^3.2.0",
"@glimmer/component": "^1.1.2",
"@glimmer/tracking": "^1.1.2",
"@types/qunit": "^2.19.7",
"@warp-drive/core-types": "workspace:5.5.0-alpha.11",
"@warp-drive/schema-record": "workspace:5.5.0-alpha.11",
"ember-auto-import": "^2.6.3",
Expand All @@ -97,6 +99,7 @@
"qunit-console-grouper": "^0.3.0",
"qunit-dom": "^3.0.0",
"silent-error": "^1.1.1",
"typescript": "^5.2.2",
"webpack": "^5.89.0"
},
"ember": {
Expand Down
11 changes: 7 additions & 4 deletions tests/warp-drive__schema-record/tests/-utils/reactive-context.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { render, TestContext } from '@ember/test-helpers';
import Component from '@glimmer/component';

import type { RecordInstance } from '@ember-data/store/-types/q/record-instance';
import type { FieldSchema } from '@warp-drive/schema-record/schema';

import { hbs } from 'ember-cli-htmlbars';

import type { ResourceRelationship } from '@ember-data/store/-types/cache/relationship';
import type { ResourceRelationship } from '@warp-drive/core-types/cache/relationship';

export async function reactiveContext<T extends object>(this: TestContext, record: T, fields: FieldSchema[]) {
export async function reactiveContext<T extends RecordInstance>(this: TestContext, record: T, fields: FieldSchema[]) {
const _fields: string[] = ['idCount', 'id', '$typeCount', '$type'];
fields.forEach((field) => {
_fields.push(field.name + 'Count');
Expand Down Expand Up @@ -38,12 +39,14 @@ export async function reactiveContext<T extends object>(this: TestContext, recor
Object.defineProperty(ReactiveComponent.prototype, 'id', {
get() {
counters['id']++;
// @ts-expect-error RecordInstance isn't typed yet
return record['id'] as unknown;
},
});
Object.defineProperty(ReactiveComponent.prototype, '$type', {
get() {
counters['$type']++;
// @ts-expect-error RecordInstance isn't typed yet
return record['$type'] as unknown;
},
});
Expand All @@ -60,9 +63,9 @@ export async function reactiveContext<T extends object>(this: TestContext, recor
counters[field.name]++;

if (field.kind === 'attribute' || field.kind === 'derived') {
return record[field.name] as unknown;
return record[field.name as keyof T] as unknown;
} else if (field.kind === 'resource') {
return (record[field.name] as ResourceRelationship).data?.id;
return (record[field.name as keyof T] as ResourceRelationship).data?.id;
}
},
});
Expand Down
3 changes: 2 additions & 1 deletion tests/warp-drive__schema-record/tests/reads/resource-test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TestContext } from '@ember/test-helpers';
import { SchemaRecord } from '@warp-drive/schema-record/record';
import { SchemaService } from '@warp-drive/schema-record/schema';
import { module, test } from 'qunit';
Expand All @@ -17,7 +18,7 @@ interface User {
module('Reads | resource', function (hooks) {
setupTest(hooks);

test('we can use simple fields with no `type`', function (assert) {
test('we can use simple fields with no `type`', function (this: TestContext, assert) {
const store = this.owner.lookup('service:store') as Store;
const schema = new SchemaService();
store.registerSchema(schema);
Expand Down
28 changes: 28 additions & 0 deletions tests/warp-drive__schema-record/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"include": ["app/**/*", "config/**/*", "tests/**/*"],
"baseUrl": ".",
"compilerOptions": {
"lib": ["DOM", "ESNext"],
"module": "esnext",
"target": "esnext",
"moduleResolution": "bundler",
"moduleDetection": "force",
"strict": true,
"downlevelIteration": true,
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"allowJs": true,

"noImplicitOverride": true,

"incremental": true,

"noEmit": true,
"declaration": false,

"types": ["ember-source/types"],
"paths": {}
},
"references": []
}
4 changes: 4 additions & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
],
"dependsOn": ["_syncPnpm"]
},
"check:types": {
"cache": false,
"dependsOn": ["_syncPnpm", "^_build"]
},
"build:tests": {
"inputs": [
// + V2-Addon convention
Expand Down