Giter Site home page Giter Site logo

jest-runner-tsd's People

Contributors

dependabot[bot] avatar hasezoey avatar mrazauskas avatar renovate-bot avatar renovate[bot] avatar saurabhagarwala avatar simenb avatar smartclash avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

keeganwitt

jest-runner-tsd's Issues

Action Required: Fix Renovate Configuration

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)

How to specify path to tsconfig.json?

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?

Could not find test files. Create one and try again

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

File is not listed within the file list of project '.../__typetests__/tsconfig.json'

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'

Folder structure

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

Jest config

/** @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'],
    },
  ],
}

Debugging

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

  1. Renaming to a .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 folder
  2. I can import the type from the "built" package. - but that requires the package to be built before running the test, which is not ideal!

Would appreciate any tips, and thanks for putting this together.

Add README

The project requires a README so that it becomes easy for other people to use this runner

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • chore(deps): lock file maintenance

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

github-actions
.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
npm
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

  • Check this box to trigger a request for Renovate to run again on this repository

[Feature] Pass multiple error messages

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.

alternative idea: zero dependency `ts` parser / typechecker

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 tests is really useful? It is, of course! Few reasons:

  • scoped variables;
  • .skip, .only, .todo
  • no need of comments to organised tests;
  • notes for future readers;
  • etc

The solution I have at this moment:

  • familiar jestish API;
  • zero dependencies (only jest, its dependencies and typescript);
  • zero config (jest.config and tsconfig.json do the job); (edit: it will have config to allow testing upon different versions of TypeScript's compiler)

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 berry Error: create-jest-runner tried to access jest-runner (a peer dependency) but it isn't provided by its ancestors

❯ 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'))
    })
  })
})

System:

  • OS: macOS 11.6.8
  • CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz

Binaries:

  • Node: 16.14.2 - /private/var/folders/xk/s3n8ww014pzbx2sn30ctz7000000gq/T/xfs-cda192a6/node
  • Yarn: 3.2.2 - /private/var/folders/xk/s3n8ww014pzbx2sn30ctz7000000gq/T/xfs-cda192a6/yarn
  • npm: 8.5.0 - ~/.asdf/plugins/nodejs/shims/npm
❯ 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])

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.