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

Migrate type tests to TSTyche #2725

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions .eslintrc.js
Expand Up @@ -110,5 +110,14 @@ module.exports = {
'import/order': 'off',
},
},
{
files: [
'**/*.test-d.ts',
'**/*.test-d.tsx',
],
rules: {
'jest/valid-expect': 'off',
},
},
],
};
3 changes: 3 additions & 0 deletions .github/workflows/node-ci.yml
Expand Up @@ -58,6 +58,9 @@ jobs:
yarn lint
yarn ci:lint-docs

- name: Type tests
run: yarn test:types

- name: Unit tests
run: yarn test "^(?:(?!(address|react-server|web-worker)).)*$"
env:
Expand Down
4 changes: 2 additions & 2 deletions config/typescript/tsconfig.base.json
Expand Up @@ -14,13 +14,13 @@

// Strictness
// Strict mode enables these options.
// Disable them temporarily while we fix up problematic behaviour from
// Disable them temporarily while we fix up problematic behavior from
// the time before we wanted strict mode
"strictBindCallApply": false,
"strictFunctionTypes": false,
"noImplicitAny": false,
"useUnknownInCatchVariables": false,
// These values are are not controled by strict mode, though they are
// These values are not controlled by strict mode, though they are
// enabled in the 'strictest' config that we inherit from.
// These reach a level of pedanticness we aren't worried about
"noImplicitOverride": false,
Expand Down
10 changes: 0 additions & 10 deletions jest.config.js
Expand Up @@ -93,15 +93,6 @@ function project(packageName, overrideOptions = {}) {
};
}

function typesProject(packageName, overrideOptions = {}) {
return project(packageName, {
displayName: {name: packageName, color: 'blue'},
runner: 'jest-runner-tsd',
testRegex: ['.+\\.test-d\\.(ts|tsx)$'],
...overrideOptions,
});
}

module.exports = {
cacheDirectory: `${root}/.cache/jest`,
watchPlugins: [
Expand All @@ -115,7 +106,6 @@ module.exports = {
// Everything else is the `packages/*` folders
...packageMapping.flatMap(({name}) => [
project(name, configOverrides[name]),
typesProject(name, configOverrides[name]),
]),
],
};
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -11,6 +11,7 @@
"type-check": "tsc --build",
"ci:lint-docs": "yarn generate docs && ./scripts/check-docs.sh",
"test": "jest",
"test:types": "tstyche",
"release": "tsc --build && node ./scripts/build.mjs && changeset publish",
"clean": "rimraf './packages/*/build' './packages/*/!(rollup.config).{d.ts,js,esnext,mjs}' '.cache'",
"generate": "plop",
Expand Down Expand Up @@ -48,7 +49,6 @@
"@shopify/eslint-plugin": "^42.0.1",
"@tsconfig/node-lts": "^18.12.1",
"@tsconfig/strictest": "^2.0.0",
"@tsd/typescript": "^4.9.5",
"@types/babel__core": "^7.1.7",
"@types/jest": "^29.4.0",
"@types/react": "^18.0.0",
Expand All @@ -66,7 +66,6 @@
"jest": "^29.4.2",
"jest-environment-jsdom": "^29.4.2",
"jest-extended": "^3.2.3",
"jest-runner-tsd": "^4.0.0",
"jest-watch-typeahead": "^2.2.2",
"npm-run-all": "^4.1.5",
"plop": "^2.6.0",
Expand All @@ -81,6 +80,7 @@
"rimraf": "^2.6.2",
"rollup": "^2.60.1",
"rollup-plugin-node-externals": "^2.2.0",
"tstyche": "^1.0.0",
"typescript": "~5.0.2",
"yalc": "^1.0.0-pre.50"
},
Expand Down
13 changes: 11 additions & 2 deletions packages/admin-graphql-api-utilities/test-d/tsconfig.json
@@ -1,8 +1,17 @@
{
"extends": "../../../config/typescript/tsconfig.base.json",
"compilerOptions": {
"emitDeclarationOnly": false,
"strict": true,
"target": "ES2015",
"moduleResolution": "Node"
"strictBindCallApply": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"exactOptionalPropertyTypes": true,

"types": []
},
"include": ["**/*"],
"exclude": [],

"references": [{"path": ".."}]
}
51 changes: 30 additions & 21 deletions packages/admin-graphql-api-utilities/test-d/types.test-d.ts
@@ -1,29 +1,38 @@
import {
expectType,
expectAssignable,
expectNotAssignable,
expectNotType,
} from 'tsd-lite';
import {describe, it, expect} from 'tstyche';

import type {Gid, ShopifyGid} from '../src';
import {composeGid, composeGidFactory} from '../src';

/**
* Shopify GIDs
*/
describe('composeGid', () => {
it('composes Gid using key and number id', () => {
expect(composeGid('Customers', 123)).type.toEqual<
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff is noisy, but it was so tempting to use describe() and it().

ShopifyGid<'Customers'>
>();
expect(composeGid('Customers', 123)).type.toEqual<
Gid<'shopify', 'Customers'>
>();

expectType<ShopifyGid<'Customers'>>(composeGid('Customers', 123));
expectType<Gid<'shopify', 'Customers'>>(composeGid('Customers', 123));
expectAssignable<string>(composeGid('Customers', 123));
expectNotAssignable<ShopifyGid<'Orders'>>(composeGid('Customers', 123));
expect(composeGid('Customers', 123)).type.toMatch<string>();
expect(composeGid('Customers', 123)).type.not.toMatch<
ShopifyGid<'Orders'>
>();
});
});

/**
* Custom GIDs
*/
describe('composeGidFactory', () => {
it('composes custom Gid using key and number id', () => {
const composeCustomGid = composeGidFactory('custom-app');

const composeCustomGid = composeGidFactory('custom-app');
expect(composeCustomGid('Customers', 123)).type.not.toEqual<
ShopifyGid<'Customers'>
>();
expect(composeCustomGid('Customers', 123)).type.toEqual<
Gid<'custom-app', 'Customers'>
>();

expectNotType<ShopifyGid<'Customers'>>(composeCustomGid('Customers', 123));
expectType<Gid<'custom-app', 'Customers'>>(composeCustomGid('Customers', 123));
expectAssignable<string>(composeCustomGid('Customers', 123));
expectNotAssignable<Gid<'custom-app', 'Orders'>>(composeGid('Customers', 123));
expect(composeCustomGid('Customers', 123)).type.toMatch<string>();
expect(composeGid('Customers', 123)).type.not.toMatch<
Gid<'custom-app', 'Orders'>
>();
});
});
13 changes: 12 additions & 1 deletion packages/useful-types/test-d/tsconfig.json
@@ -1,6 +1,17 @@
{
"extends": "../../../config/typescript/tsconfig.base.json",
"compilerOptions": {
"strict": true
"emitDeclarationOnly": false,
"strict": true,
"strictBindCallApply": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"exactOptionalPropertyTypes": true,

"types": []
},
"include": ["**/*"],
"exclude": [],

"references": [{"path": ".."}]
}