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

chore: Type check test files #9101

Merged
merged 14 commits into from
Nov 15, 2023
Merged
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
* fix: de-dupe coalescing when includes or adapterOptions is present but still use findRecord #8704
* fix: make implicit relationship teardown following delete of related record safe #8705
* fix: catch errors during didCommit in DEBUG #8708

## 5.1.1 (2023-07-07)

#### :bug: Bug Fix
Expand Down Expand Up @@ -3053,7 +3053,7 @@ The full API reference of `DS.Snapshot` can be found [here](https://api.emberjs.
- fetch() -> fetchById() in docs
- Run findHasMany inside an ED runloop
- Cleanup debug adapter test: Watching Records
- Fixed didDelete event/callback not fired in uncommited state
- Fixed didDelete event/callback not fired in uncommitted state
- Add main entry point for package.json.
- register the store as a service
- Warn when expected coalesced records are not found in the response
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"scripts": {
"takeoff": "FORCE_COLOR=2 pnpm install --reporter=append-only",
"prepare": "pnpm build",
"build": "turbo _build --log-order=stream --filter=./packages/*",
"build": "turbo _build --log-order=stream --filter=./packages/* --concurrency=1; pnpm run sync:tests",
"sync:tests": "pnpm run --filter=./tests/* -r --workspace-concurrency=1 --if-present _syncPnpm",
"build:docs": "mkdir -p packages/-ember-data/dist && cd ./docs-generator && node ./compile-docs.js",
"lint": "bun run turbo --log-order=stream lint --concurrency=1",
"lint:prettier": "prettier --check --cache --cache-location=.prettier-cache --log-level=warn .",
Expand Down
3 changes: 2 additions & 1 deletion packages/active-record/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"README.md",
"LICENSE.md",
"ember-data-logo-dark.svg",
"ember-data-logo-light.svg"
"ember-data-logo-light.svg",
"unstable-preview-types"
],
"exports": {
"./*": {
Expand Down
25 changes: 24 additions & 1 deletion packages/unpublished-test-infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,36 @@
},
"license": "MIT",
"author": "",
"files": [
"addon-test-support",
"src",
"index.js",
"dist",
"tsconfig.json"
],
"typesVersions": {
"*": {
"test-support": [
"dist/addon-test-support/index.d.ts"
],
"test-support/*": [
"dist/addon-test-support/*",
"dist/addon-test-support/*/index.d.ts"
],
"*": [
"dist/addon/*",
"dist/addon/*/index.d.ts"
]
}
},
"directories": {
"doc": "doc",
"test": "tests"
},
"scripts": {
"check:types": "tsc --noEmit",
"test:infra": "ember test",
"build:types": "tsc --build --emitDeclarationOnly",
"_build": "bun run build:types",
"_syncPnpm": "bun run sync-dependencies-meta-injected"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/unpublished-test-infra/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"allowJs": true,
"noEmit": true,
"noEmit": false,
"noImplicitOverride": true,

// Enable faster builds
Expand Down
36 changes: 36 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/builders/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
16 changes: 10 additions & 6 deletions tests/builders/app/services/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import { buildSchema, modelFor } from '@ember-data/model/hooks';
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 { ModelSchema } from '@ember-data/store/-types/q/ds-model';
import type { Cache } from '@warp-drive/core-types/cache';

export default class Store extends DataStore {
constructor(args: unknown) {
Expand All @@ -21,19 +22,22 @@ export default class Store extends DataStore {
this.registerSchema(buildSchema(this));
}

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

instantiateRecord(identifier: StableRecordIdentifier, createRecordArgs: { [key: string]: unknown }): unknown {
override instantiateRecord(
identifier: StableRecordIdentifier,
createRecordArgs: { [key: string]: unknown }
): unknown {
return instantiateRecord.call(this, identifier, createRecordArgs);
}

teardownRecord(record: Model): void {
override teardownRecord(record: Model): void {
return teardownRecord.call(this, record);
}

modelFor(type: string) {
return modelFor.call(this, type);
override modelFor(type: string): ModelSchema {
return modelFor.call(this, type)!;
}
}
2 changes: 2 additions & 0 deletions tests/builders/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",
"build:production": "pnpm build:tests -e production",
"check:types": "tsc --noEmit",
"test": "bun ./diagnostic.js",
"test:production": "bun ./diagnostic.js",
"_syncPnpm": "bun run sync-dependencies-meta-injected"
Expand Down Expand Up @@ -114,6 +115,7 @@
"ember-source-channel-url": "^3.0.0",
"loader.js": "^4.7.0",
"silent-error": "^1.1.1",
"typescript": "^5.2.2",
"webpack": "^5.89.0"
},
"ember": {
Expand Down
45 changes: 25 additions & 20 deletions tests/builders/tests/integration/create-record-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ import JSONAPICache from '@ember-data/json-api';
import { createRecord } from '@ember-data/json-api/request';
import Model, { attr, instantiateRecord, teardownRecord } from '@ember-data/model';
import { buildSchema, modelFor } from '@ember-data/model/hooks';
import type { StructuredDataDocument } from '@ember-data/request';
import type { RequestContext, StructuredDataDocument } from '@ember-data/request';
import RequestManager from '@ember-data/request';
import type { Future, Handler, RequestContext } from '@ember-data/request/-private/types';
import { setBuildURLConfig } from '@ember-data/request-utils';
import type { Future, Handler } from '@ember-data/request/-private/types';
import DataStore, { CacheHandler, recordIdentifierFor } from '@ember-data/store';
import type { Cache } from '@ember-data/store/-types/cache/cache';
import { SingleResourceDataDocument } from '@ember-data/store/-types/cache/document';
import type { CacheCapabilitiesManager } from '@ember-data/store/-types/q/cache-store-wrapper';
import { SingleResourceDocument } from '@warp-drive/core-types/spec/raw';
import { ModelSchema } from '@ember-data/store/-types/q/ds-model';
import { JsonApiError } from '@ember-data/store/-types/q/record-data-json-api';
import { TestContext } from '@ember/test-helpers';
import type { Cache } from '@warp-drive/core-types/cache';
import type { SingleResourceDataDocument } from '@warp-drive/core-types/spec/document';
import type { SingleResourceDocument } from '@warp-drive/core-types/spec/raw';

class TestStore extends DataStore {
constructor(args: unknown) {
Expand All @@ -27,20 +29,23 @@ class TestStore extends DataStore {
this.registerSchema(buildSchema(this));
}

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

instantiateRecord(identifier: StableRecordIdentifier, createRecordArgs: { [key: string]: unknown }): unknown {
override instantiateRecord(
identifier: StableRecordIdentifier,
createRecordArgs: { [key: string]: unknown }
): unknown {
return instantiateRecord.call(this, identifier, createRecordArgs);
}

teardownRecord(record: Model): void {
override teardownRecord(record: Model): void {
return teardownRecord.call(this, record);
}

modelFor(type: string) {
return modelFor.call(this, type);
override modelFor(type: string): ModelSchema {
return modelFor.call(this, type)!;
}
}

Expand All @@ -59,23 +64,23 @@ module('Integration - createRecord', function (hooks) {
setBuildURLConfig({ host: '', namespace: '' });
});

test('Saving a new record with a createRecord op works as expected', async function (assert) {
test('Saving a new record with a createRecord op works as expected', async function (this: TestContext, assert) {
const { owner } = this;

// intercept cache APIs to ensure they are called as expected
class TestCache extends JSONAPICache {
willCommit(identifier: StableRecordIdentifier): void {
override willCommit(identifier: StableRecordIdentifier): void {
assert.step(`willCommit ${identifier.lid}`);
return super.willCommit(identifier);
}
didCommit(
override didCommit(
committedIdentifier: StableRecordIdentifier,
result: StructuredDataDocument<SingleResourceDocument>
): SingleResourceDataDocument<StableExistingRecordIdentifier> {
assert.step(`didCommit ${committedIdentifier.lid}`);
return super.didCommit(committedIdentifier, result);
}
commitWasRejected(identifier: StableRecordIdentifier, errors?: JsonApiError[]): void {
override commitWasRejected(identifier: StableRecordIdentifier, errors?: JsonApiError[]): void {
assert.step(`commitWasRejected ${identifier.lid}`);
return super.commitWasRejected(identifier, errors);
}
Expand All @@ -101,7 +106,7 @@ module('Integration - createRecord', function (hooks) {
const manager = this.requestManager;
manager.use([TestHandler]);
}
createCache(capabilities: CacheCapabilitiesManager): Cache {
override createCache(capabilities: CacheCapabilitiesManager): Cache {
return new TestCache(capabilities);
}
}
Expand Down Expand Up @@ -139,23 +144,23 @@ module('Integration - createRecord', function (hooks) {
assert.verifySteps([`willCommit ${identifier.lid}`, 'handle createRecord request', `didCommit ${identifier.lid}`]);
});

test('Rejecting during Save of a new record with a createRecord op works as expected', async function (assert) {
test('Rejecting during Save of a new record with a createRecord op works as expected', async function (this: TestContext, assert) {
const { owner } = this;

// intercept cache APIs to ensure they are called as expected
class TestCache extends JSONAPICache {
willCommit(identifier: StableRecordIdentifier): void {
override willCommit(identifier: StableRecordIdentifier): void {
assert.step(`willCommit ${identifier.lid}`);
return super.willCommit(identifier);
}
didCommit(
override didCommit(
committedIdentifier: StableRecordIdentifier,
result: StructuredDataDocument<SingleResourceDocument>
): SingleResourceDataDocument<StableExistingRecordIdentifier> {
assert.step(`didCommit ${committedIdentifier.lid}`);
return super.didCommit(committedIdentifier, result);
}
commitWasRejected(identifier: StableRecordIdentifier, errors?: JsonApiError[]): void {
override commitWasRejected(identifier: StableRecordIdentifier, errors?: JsonApiError[]): void {
assert.step(`commitWasRejected ${identifier.lid}`);
return super.commitWasRejected(identifier, errors);
}
Expand All @@ -181,7 +186,7 @@ module('Integration - createRecord', function (hooks) {
const manager = this.requestManager;
manager.use([TestHandler]);
}
createCache(capabilities: CacheCapabilitiesManager): Cache {
override createCache(capabilities: CacheCapabilitiesManager): Cache {
return new TestCache(capabilities);
}
}
Expand Down
Loading