jest-community / jest-runner-tsd Goto Github PK
View Code? Open in Web Editor NEWJest runner to test TypeScript typings
License: MIT License
Jest runner to test TypeScript typings
License: MIT License
There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.
Error type: Cannot find preset's package (github>whitesource/merge-confidence:beta)
jest-runner-tsd is finding the wrong tsconfig.json (the one in a package subdirectory), instead of the correct one we use for tests (tsconfig.test.json at the root of the repo).
How can I tell jest-runner-tsd to use this custom tsconfig file?
Depends on MLH-Fellowship/tsd#12. Get numTests
, numFailedTests
and numPassedTests
and then pass it through our pass()
or fail()
method.
When trying to run tests, I get the following error:
FAIL src/__type_tests__/pick-deep.test-d.ts
● Test suite failed to run
Could not find test files. Create one and try again
It seems like there isn't anything being found from mlh-tsd
in findCustomTestFiles
. If, after globby
, I output:
console.log({testFilesPattern, testFiles, cwd})
I get this:
{
testFilesPattern: [
'C:\\Users\\crutchcorn\\git\\UnicornUtter\\ts-util-helpers\\src\\__type_tests__\\pick-deep.test-d.ts'
],
testFiles: [],
cwd: 'C:\\Users\\crutchcorn\\git\\UnicornUtter\\ts-util-helpers'
}
My jest file is this:
module.exports = {
runner: 'jest-runner-tsd',
testMatch: ['**/*.test-d.ts'],
};
And my test is indeed in the pick-deep.test-d.ts path
I'm running Windows 11 if that helps
I seem to have an odd configuration issue with the tsd runner. I have a file where I define the types I'm using in my tsd test, but I receive this error when running tsd tests. There are no TS errors while running tsc
, only while running the jest-runner-tsd.
It's just a type import:
import type { RouteParams, ParamType } from '../routeParamsTypes'
File '/Users/dac09/Code/redwood/packages/router/src/routeParamsTypes.ts' is not listed within the file list of project '/Users/dac09/Code/redwood/packages/router/src/__typetests__/tsconfig.json'
The relevant parts of the tree looks like this:
.
├── ambient.d.ts
├── jest.config.js
├── jest.setup.js
├── package.json
├── src
│ ├── __tests__
│ │ ├──
│ ├── __typetests__
│ │ ├── routeParamsTypes.test.ts
│ │ └── tsconfig.json
│ ├── routeParamsTypes.ts
└── tsconfig.json
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
projects: [
{
displayName: 'code',
setupFilesAfterEnv: ['./jest.setup.js'],
testEnvironment: 'jest-environment-jsdom',
testMatch: ['**/*.test.+(ts|tsx|js)', '!**/__typetests__/*.ts'],
},
{
displayName: {
color: 'blue',
name: 'types',
},
runner: 'jest-runner-tsd',
testMatch: ['**/__typetests__/*.test.ts'],
},
],
}
Just to be sure, I've defined a tsconfig.json in the __typetests__
folder too that just extends the original.
{
"extends": "../../tsconfig.json"
}
The output of yarn tsc -p src/__typetests__ --showConfig
lists routeParamsTypes.ts correctly.
Other Workarounds I've tried
.d.ts
file seems to work, but.... then I'll need to modify my build step to manually copy over the .d.ts file into the dist folderWould appreciate any tips, and thanks for putting this together.
The project requires a README so that it becomes easy for other people to use this runner
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates are awaiting their schedule. Click on a checkbox to get an update now.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
@typescript-eslint/eslint-plugin
, @typescript-eslint/parser
)These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.
.github/workflows/nodejs.yml
actions/checkout v4
actions/setup-node v4
actions/checkout v4
actions/setup-node v4
actions/checkout v4
actions/setup-node v4
actions/checkout v4
actions/setup-node v4
actions/checkout v4
actions/setup-node v4
package.json
@babel/code-frame ^7.15.8
chalk ^4.1.2
create-jest-runner ^0.12.0
tsd-lite ^0.8.0
@babel/core ^7.15.8
@babel/preset-env ^7.15.8
@babel/preset-typescript ^7.15.0
@jest/test-result ^29.1.0
@tsconfig/node16 ^16.1.0
@tsd/typescript ~5.4.0
@types/babel__code-frame ^7.0.3
@typescript-eslint/eslint-plugin ^6.0.0
@typescript-eslint/parser ^6.0.0
babel-jest ^29.1.0
eslint ^8.0.0
eslint-config-prettier ^9.0.0
eslint-plugin-prettier ^5.0.0
execa ^5.1.1
jest ^29.1.0
prettier ^3.0.0
typescript ~5.4.0
@tsd/typescript 4.x || 5.x
node >=16
yarn 3.8.1
There is no way currently to pass multiple errors encountered when a runner created from create-jest-runner
is executed.
Update: The test results support multiple error messages, but the abstracted fail
function doesn't supports passing multiple test results. So the fail
function needs to be updated to pass all test errors.
In order to make it easier to maintain, we should add tests to this repo. Something like the integration tests we have for the ESLint runner would be nice: https://github.com/jest-community/jest-runner-eslint/tree/bbf3a8164b494f329a7e9ca71ab2c44e7ae7fc3a/integrationTests
From #25
@SimenB Just to leave a note. I was thinking / working on a ts
parser, which reads a file like this one:
test('is deprecated', () => {
expect(user.id).type.not.toBeDeprecated();
expect(user.accountName).type.toBeDeprecated('Use `id` property instead.'); // should fail
});
test('type equality', () => {
expect({ a: 'b' }).type.toEqual<{ a: string }>();
expect({ a: 'b' }).type.toEqual<{ a: number | string }>(); // should fail
});
test('type match', () => {
expect('ten').type.toMatch<string | number>();
expect({ a: 'b' }).type.not.toMatch<Record<string, number>>();
});
test('type error', () => {
expect(one('fail')).type.toThrow('Expected 0 arguments, but got 1.');
expect(one('fail')).type.not.toThrow(); // should fail
});
And returns:
{
testPath: 'path/to/some.test.ts',
testResult: [
{
failureReport: {
expected: 'Use `id` property instead.',
matcherName: 'toBeDeprecated',
isNot: false,
type: 'assertion',
received: '',
},
fileName: 'path/to/some.test.ts',
// fileText - full file source
result: 'fail',
testTitle: 'is deprecated',
},
{
failureReport: {
expected: '{ a: string | number; }',
matcherName: 'toEqual',
isNot: false,
type: 'assertion',
received: '{ a: string; }',
},
fileName: 'path/to/some.test.ts',
// fileText - full file source
result: 'fail',
testTitle: 'type equality',
},
{
result: 'pass',
testTitle: 'type match',
},
{
failureReport: {
expected: '',
matcherName: 'toThrow',
isNot: true,
type: 'assertion',
received: '',
},
fileName: 'path/to/some.test.ts',
// fileText - full file source
result: 'fail',
testTitle: 'type error',
},
],
};
Not yet finished, but it works! Reporter and runner are the missing parts.
While working on this, I was thinking if having test
s is really useful? It is, of course! Few reasons:
.skip
, .only
, .todo
The solution I have at this moment:
jest
, its dependencies and typescript
);jest.config
and tsconfig.json
do the job);Working on it. Will be posting updates here. This is not tsd
based solution anymore, but I think it is related to jest-runner-tsd
.
❯ yarn jest
Error: create-jest-runner tried to access jest-runner (a peer dependency) but it isn't provided by its ancestors; this makes the require call ambiguous and unsound.
Required package: jest-runner
Required by: create-jest-runner@virtual:f3a1aa84056e0c9bae1641138e71f4a6777a2cdf049b6d742bae451fc08717f5ce327e91580a4167fe0dec92b44f1ee97b8bd064f0aeb1afd7237b152c12efab#npm:0.11.1 (via /Users/nqy642/IdeaProjects/E1-Library/.yarn/__virtual__/create-jest-runner-virtual-108a2314ea/0/cache/create-jest-runner-npm-0.11.1-8026afed73-6fc69d9fe3.zip/node_modules/create-jest-runner/build/)
Ancestor breaking the chain: jest-runner-tsd@virtual:d97b79db4fda8f479e265452a16c3344f5cce9cf2b369c79cb7dd5d8f9a8b5dca20c35b42ad804c2caebb36e7ad1004e4131c47d5d929fa5fbba7a20044f5ecf#npm:3.1.0
Require stack:
- /Users/nqy642/IdeaProjects/E1-Library/.yarn/__virtual__/create-jest-runner-virtual-108a2314ea/0/cache/create-jest-runner-npm-0.11.1-8026afed73-6fc69d9fe3.zip/node_modules/create-jest-runner/build/createJestRunner.js
- /Users/nqy642/IdeaProjects/E1-Library/.yarn/__virtual__/create-jest-runner-virtual-108a2314ea/0/cache/create-jest-runner-npm-0.11.1-8026afed73-6fc69d9fe3.zip/node_modules/create-jest-runner/build/index.js
- /Users/nqy642/IdeaProjects/E1-Library/.yarn/__virtual__/jest-runner-tsd-virtual-f3a1aa8405/0/cache/jest-runner-tsd-npm-3.1.0-d9ef8343c8-c080b642ca.zip/node_modules/jest-runner-tsd/src/index.js
- /Users/nqy642/IdeaProjects/E1-Library/.yarn/cache/jest-util-npm-28.1.3-9ae2283a08-fd6459742c.zip/node_modules/jest-util/build/requireOrImportModule.js
- /Users/nqy642/IdeaProjects/E1-Library/.yarn/cache/jest-util-npm-28.1.3-9ae2283a08-fd6459742c.zip/node_modules/jest-util/build/index.js
- /Users/nqy642/IdeaProjects/E1-Library/.yarn/__virtual__/jest-config-virtual-fb81c2f38c/0/cache/jest-config-npm-28.1.3-47d1c91477-ddabffd3a3.zip/node_modules/jest-config/build/getCacheDirectory.js
- /Users/nqy642/IdeaProjects/E1-Library/.yarn/__virtual__/jest-config-virtual-fb81c2f38c/0/cache/jest-config-npm-28.1.3-47d1c91477-ddabffd3a3.zip/node_modules/jest-config/build/Defaults.js
- /Users/nqy642/IdeaProjects/E1-Library/.yarn/__virtual__/jest-config-virtual-fb81c2f38c/0/cache/jest-config-npm-28.1.3-47d1c91477-ddabffd3a3.zip/node_modules/jest-config/build/normalize.js
- /Users/nqy642/IdeaProjects/E1-Library/.yarn/__virtual__/jest-config-virtual-fb81c2f38c/0/cache/jest-config-npm-28.1.3-47d1c91477-ddabffd3a3.zip/node_modules/jest-config/build/index.js
- /Users/nqy642/IdeaProjects/E1-Library/.yarn/__virtual__/jest-cli-virtual-5919ff1e13/0/cache/jest-cli-npm-28.1.3-aab5c7389d-fb424576bf.zip/node_modules/jest-cli/build/init/index.js
- /Users/nqy642/IdeaProjects/E1-Library/.yarn/__virtual__/jest-cli-virtual-5919ff1e13/0/cache/jest-cli-npm-28.1.3-aab5c7389d-fb424576bf.zip/node_modules/jest-cli/build/cli/index.js
- /Users/nqy642/IdeaProjects/E1-Library/.yarn/__virtual__/jest-cli-virtual-5919ff1e13/0/cache/jest-cli-npm-28.1.3-aab5c7389d-fb424576bf.zip/node_modules/jest-cli/build/index.js
- /Users/nqy642/IdeaProjects/E1-Library/.yarn/__virtual__/jest-cli-virtual-5919ff1e13/0/cache/jest-cli-npm-28.1.3-aab5c7389d-fb424576bf.zip/node_modules/jest-cli/bin/jest.js
- /Users/nqy642/IdeaProjects/E1-Library/.yarn/__virtual__/jest-virtual-65092f3388/0/cache/jest-npm-28.1.3-207c50e059-b9dcb542eb.zip/node_modules/jest/bin/jest.js
at Function.require$$0.Module._resolveFilename (/Users/nqy642/IdeaProjects/E1-Library/.pnp.cjs:17439:13)
at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/Users/nqy642/IdeaProjects/E1-Library/.yarn/cache/@cspotcode-source-map-support-npm-0.8.1-964f2de99d-5718f26708.zip/node_modules/@cspotcode/source-map-support/source-map-support.js:811:30)
at Function.require$$0.Module._load (/Users/nqy642/IdeaProjects/E1-Library/.pnp.cjs:17293:42)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/nqy642/IdeaProjects/E1-Library/.yarn/__virtual__/create-jest-runner-virtual-108a2314ea/0/cache/create-jest-runner-npm-0.11.1-8026afed73-6fc69d9fe3.zip/node_modules/create-jest-runner/build/createJestRunner.js:8:19)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
at require$$0.Module._extensions..js (/Users/nqy642/IdeaProjects/E1-Library/.pnp.cjs:17483:33)
at require.extensions.<computed> (/Users/nqy642/IdeaProjects/E1-Library/.yarn/__virtual__/ts-node-virtual-57b3eea5c8/0/cache/ts-node-npm-10.9.1-6c268be7f4-090adff130.zip/node_modules/ts-node/src/index.ts:1608:43)
I suspect this is an issue with support for yarn and how it's doing its require/and or lack of a dependency on jest? or something?
import { InitialOptionsTsJest } from 'ts-jest'
import { defaults as tsjPreset } from 'ts-jest/presets'
const config: InitialOptionsTsJest = {
testEnvironment: 'node',
preset: 'ts-jest',
testPathIgnorePatterns: ['/(\\.test|node_modules|dist)'],
projects: [
{
displayName: 'unit',
testMatch: ['<rootDir>/**/test/unit/**/*.test.ts'],
runner: 'jest-runner',
transform: { ...tsjPreset.transform },
},
{
displayName: 'types',
runner: 'jest-runner-tsd',
testMatch: ['<rootDir>/**/test/types/**/*.test.ts'],
},
],
// setupFilesAfterEnv: ['jest-extended/all'],
}
export default config
import { createErrorCodes } from '@cof/e1-types'
import { describe, test } from '@jest/globals'
import Joi from 'joi'
import { expectType } from 'tsd-lite'
import { validateRequired } from '../../src/validate'
describe('validate', () => {
const errorCodes = createErrorCodes({
limit: [100023],
npe: [200099, ''],
} as const)
describe('validateRequired', () => {
test('string', () => {
const arg = 'v'
expectType<string>(validateRequired(arg, Joi.any(), 'npe'))
})
})
})
❯ yarn why jest-runner-tsd && yarn why @tsd/typescript && yarn why tsd-lite
└─ @cof/e1-lib@workspace:.
└─ jest-runner-tsd@npm:3.1.0 [d97b7] (via npm:^3.1.0 [d97b7])
├─ @cof/e1-lib@workspace:.
│ └─ @tsd/typescript@npm:4.7.4 (via npm:^4.7.4)
│
├─ @cof/e1-types@workspace:packages/types
│ └─ @tsd/typescript@npm:4.7.4 (via npm:^4.7.4)
│
└─ @cof/e1-util@workspace:packages/util
└─ @tsd/typescript@npm:4.7.4 (via npm:^4.7.4)
├─ @cof/e1-types@workspace:packages/types
│ └─ tsd-lite@npm:0.5.6 [f3a1a] (via npm:^0.5.4 [f3a1a])
│
├─ @cof/e1-util@workspace:packages/util
│ └─ tsd-lite@npm:0.5.6 [f3a1a] (via npm:^0.5.4 [f3a1a])
│
├─ jest-runner-tsd@npm:3.1.0
│ └─ tsd-lite@npm:0.5.6 (via npm:^0.5.4)
│
└─ jest-runner-tsd@npm:3.1.0 [d97b7]
└─ tsd-lite@npm:0.5.6 [f3a1a] (via npm:^0.5.4 [f3a1a])
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.