Detalhes do pacote

ts-auto-mock

Typescript-TDD203.2kMIT3.7.4

Typescript transformer to unlock automatic mock creation for interfaces and classes

typescript, spy, mock, auto

readme (leia-me)

TS auto mock

Test npm version Downloads semantic-release Commitizen friendly GitHub Sponsor All Contributors Slack Need help? Join us on Slack

:warning: This repository is now no longer maintained for new features development :warning:

A few years ago we've created this project with the idea in mind that typescript transformers would be easier to configure.

Unfortunately the typescript team has no intention to improve the developer experience. You can see more information at this link.

We believe that stop developing new features is the best decision to inform who is currently using it and who find it for the first time.

We will keep fixing bugs and vulnerability.

Other reasons why this library might not be for you:

  • Typescript transformers works only when using the tsc typescript compiler. If you are using esbuild or swc you will not be able to use this library.
  • Test double are a double-edge sword. They have to be used carefully and at the right time. Increasing the number of test doubles could decrease the value of your tests. The amount of configuration required by this library might not justify the amount of test doubles that your application requires.

A TypeScript transformer that will allow you to create mocks for any types (interfaces, classes, etc.) without the need to create manual fakes/mocks.

API Documentation

Installation

Usage

Quick overview

import { createMock } from 'ts-auto-mock';

interface Person {
    id: string;

    getName(): string;

    details: {
        phone: number
    }
}

const mock = createMock<Person>();
mock.id // ""
mock.getName() // ""
mock.details // "{ phone: 0 }"

Changelog

Find the changelog here: Changelog.

Roadmap

You can find the roadmap of this project on the Wiki page: Roadmap.

Do you want to contribute?

Authors

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Artem Kornev

🐛 💻

Fabian

🐛 💻

Geoffrey 'C0ZEN' Testelin

🐛 💻 🤔 🔧

Giulio Caprino

💬 💻 📖 🤔 🚇 🚧 📆

Marc

🐛 💻

Martin Jesper Low Madsen

🐛 💻 🤔

Vittorio Guerriero

💬 💻 🤔 🚇 🚧 📆 🔧

This project follows the all-contributors specification. Contributions of any kind welcome!

Sponsor ✨

Thanks to these people


Kenta Mukai

License

This project is licensed under the MIT License

changelog (log de mudanças)

Semantic Versioning Changelog

3.7.4 (2024-08-24)

Performance Improvements

  • dep: update dependencies to latest version (#1589) (17db060)

3.7.3 (2024-04-13)

Bug Fixes

  • negativeNumbers: convert negative literal numbers to unary expression with minus token (#1580) (5b9289d)

3.7.2 (2023-12-25)

Bug Fixes

  • typescript: add support to typescript 5.3 (8913b86)

3.7.1 (2023-06-19)

Bug Fixes

  • typescript: improve typings for partials (28ad22a)

3.7.0 (2023-05-11)

Features

  • typescript5: Add compatibility to typescript 5 (7378ad7)

BREAKING CHANGES

  • typescript5: Typescript 4 is not longer supported

3.6.4 (2022-12-08)

Bug Fixes

  • ci: update names on ci and fix workflow (a1a09d7)

3.6.3 (2022-12-08)

Bug Fixes

  • typescript: add support to typescript 4.9.3 (77bfaba)

3.6.2 (2022-05-06)

Bug Fixes

  • node: downgrade the engine strict version to 14 because is still supported by node js in maintenance (263e870)

3.6.1 (2022-05-04)

Bug Fixes

3.6.0 (2022-04-30)

Features

  • (dependencies: update typescript to version 4.6.4 (1a83487)
  • dependencies: update winston to version 3.7.2 (9286731)

3.5.1 (2022-04-26)

Performance Improvements

  • update typescrpt to 4.6.3 (365d851)

3.5.0 (2021-09-12)

Features

  • arrowfunctionliteraltypes: add some compatibility for arrow functions without type definitions (b2fb8de)

3.4.0 (2021-09-02)

Features

  • functionliteraltypes: add some compatibility for functions without type definitions! (#889) (a21e012)

3.3.6 (2021-08-28)

Bug Fixes

  • vulnerability: fix some vulnerabilities (53a13e5)

3.3.5 (2021-08-08)

Performance Improvements

  • typescript: upgrade to latest version of typescript (69e52e1)

3.3.4 (2021-08-08)

Bug Fixes

  • husky: remove husky from post install because it will be required for consumers of the packages (83498e2)

3.3.3 (2021-08-08)

Performance Improvements

  • dependencies: run husky installation only when installing not when publishing the package (#871) (9fea5d4)

3.3.2 (2021-08-08)

Performance Improvements

  • dependencies: upgrade performance dependencies (#870) (ab99348)

3.3.1 (2021-08-08)

Performance Improvements

  • dependencies: update ts-auto-mock dependencies to the latest version (46fbacf)

3.3.0 (2021-06-24)

Features

  • export alternative transformer function to allow providing customized typescript (#802) (9f1dce4)

3.2.3 (2021-06-17)

Bug Fixes

  • transformer: ignore namespace when resolving a declaration (#793) (c356caa)

3.2.2 (2021-05-22)

Bug Fixes

  • merge: ensure undefined is assigned when merging partial mock (#748) (31c5ff5)

3.2.1 (2021-05-20)

Bug Fixes

3.2.0 (2021-05-19)

Features

  • getAccessor: correctly mock get accessors for mocked classes (3530039)

3.1.3 (2021-04-21)

Performance Improvements

3.1.2 (2021-03-15)

Performance Improvements

3.1.1 (2021-02-18)

Bug Fixes

  • typeReference: log warning when type definition does not exists and cannot be located (#618) (5750def)

3.1.0 (2021-01-06)

Features

  • hydrate-mocks: add create-hydrated-mock functionality (aa2ebad)

3.0.0 (2020-12-25)

chore

BREAKING CHANGES

  • typescript: typescript >= 4.0.2 is required to use ts-auto-mock Update your typescript dependency to version >= 4.0.2

2.7.0 (2020-12-08)

Features

  • registerMock: allow use of mocked generics in register mock factory (512e150)

2.6.5 (2020-10-08)

Bug Fixes

  • createMockList: count the number of create mock list on runtime instead of relying on a numeric literal (eec45dd), closes #595

2.6.4 (2020-09-18)

Bug Fixes

  • transformer: apply null and warning when property type cannot be identified (7cc1ec0)
  • typescript: restore support for typescript 3 (825cc01)

2.6.3 (2020-09-17)

Bug Fixes

  • transformer: do not fail when accessing index of extended this for a computed property (02e7b12)

2.6.2 (2020-09-15)

Bug Fixes

  • definitelyTyped: do not fail on mocking module declarations (4660f58)

2.6.1 (2020-09-15)

Bug Fixes

  • transformer: fix interface call signature with undeclared return type (#533) (55da89f)

2.6.0 (2020-09-15)

Features

  • fileFilter: add config option to specify files with mocks (526d677)

2.5.3 (2020-09-15)

Bug Fixes

  • properties: create property when undefined/void, do not emit property only when optional (70d65ed)

2.5.2 (2020-09-13)

Bug Fixes

  • enum: fix enum constant computed properties (9c96a53)

2.5.1 (2020-09-12)

Bug Fixes

  • mockValues: assign, not merge, override value when is a mock to prevent maximum callstack size exceeded errors (7431d80)

2.5.0 (2020-09-11)

Bug Fixes

  • logs: ensure logs tests work on windows (a160a87)

Features

  • transformer: tuple type now gets mocked as an instance of specified tuple, add keyof warning, support readonly array/tuple Pmyl 23 minutes ago (af9df91)

2.4.0 (2020-09-09)

Features

2.3.5 (2020-08-29)

Bug Fixes

  • createMock: PartialDeep to ignore object prototype properties (37cb34d)

2.3.4 (2020-08-09)

Bug Fixes

  • partial: improve deep partial type to ensure compilation without errors when passing default values to create mock and create mock list (7463501)

2.3.3 (2020-07-11)

Bug Fixes

  • typeof-module: prevent unsupported declaration to be transformer when mocking typeof of a module that uses exports = (09aa3b3)

2.3.2 (2020-07-05)

Bug Fixes

  • upgrade gatsby-plugin-google-analytics from 2.3.1 to 2.3.3 (52c1b88)

2.3.1 (2020-07-05)

Bug Fixes

  • upgrade typescript from 3.9.3 to 3.9.5 (82bf1b8)

2.3.0 (2020-06-27)

Features

  • transformer: error when running tests with no transformer installation (16506e5)
  • transformer: extract repeated error in a constant, fixed error wording (dd73b57)

2.2.8 (2020-06-14)

Bug Fixes

  • module: switch to commonjs2 libraryTarget (#379) (9259f10)

2.2.7 (2020-06-10)

Bug Fixes

  • registerMock: allow to use mocks defined in variables (#330) (b14bd5c)

2.2.6 (2020-06-06)

Bug Fixes

  • release: create a release every time there are new changes on master (0013c9d)

2.2.5 (2020-05-31)

Bug Fixes

  • indexedAccessType: ensure compiler doesn't break for unsupported indexed access type (2ef31c7)

2.2.4 (2020-05-31)

Bug Fixes

  • release: ensure develop will be up to date after a release (613b5ed)

2.2.3 (2020-05-31)

Bug Fixes

  • token: ensure performance and definitely typed pull requests are created with the right token (869fa37)

2.2.1 (2020-05-31)

Bug Fixes

  • release: test release pipeline version (b8f78dd)

2.2.0 (2020-05-31)

Bug Fixes

  • release: adjust automated pr to create a valid commit msg (#354) (1600788)
  • release: change owner to uittorio attempting to fix npm authentication problem (9092ff6)
  • release: ensure correct folder will be published to npm (9664b3d)
  • release: ensure library its build before publishing (fb5535b)
  • release: fix syntax in release.yml (ef97ae5)
  • release: revert owner and add token registration (169cc76)
  • release: semantic release test (#351) (996b5a9)

Features

  • random: add enum random support (eeceea2)

2.1.22 (2020-05-25)

2.1.21 (2020-05-25)

Features

  • random: enable random feature for primitives types (9666efc)

2.0.0 (2020-05-13)

2.0.0 (2020-05-13)

Bug Fixes

  • transformer: Ensure mocked interfaces don't extend themselves infinitely if passed as generic argument (#312) (9911d94)
  • union: ensure union type with null or unknown will mock the first type (#322) (a2d58ad)

BREAKING CHANGES

  • union: union types that resolve in null or unknown will now not be converted to undefined.

before

type = string | null // undefined

after

type = string | null // '' (empty string)

1.6.2 (2020-05-11)

1.6.2 (2020-05-11)

1.6.1 (2020-05-10)

Features

1.6.0 (2020-04-11)

1.5.891 (2020-04-11)

1.5.891 (2020-04-11)

1.5.89 (2020-04-11)

1.5.88 (2020-04-11)

1.5.88 (2020-04-11)

1.5.87 (2020-04-11)

1.5.87 (2020-04-11)

1.5.86 (2020-04-11)

1.5.85 (2020-04-11)

1.5.85 (2020-04-11)

1.5.84 (2020-04-11)

1.5.84 (2020-04-11)

1.5.83 (2020-04-11)

1.5.83 (2020-04-11)

1.5.82 (2020-04-11)

1.5.82 (2020-04-11)

1.5.81 (2020-04-11)

1.5.63 (2020-04-11)

1.5.62 (2020-04-11)

1.5.61 (2020-04-11)

1.5.6 (2020-04-11)

1.5.5 (2020-04-11)

Bug Fixes

  • upgrade gatsby-plugin-google-analytics from 2.1.35 to 2.2.2 (#299) (b8335d5)
  • upgrade ttypescript from 1.5.8 to 1.5.10 (#298) (7e7bd59)

Features

  • extendsMappedType: make sure extending mapped types do not prevent to compile (#241) (627b9bc)
  • set: add Set support as a type (#233) (446c090)
  • typescript: add support for typescript 3.8 (#246) (2a18bed)

1.5.4 (2020-02-08)

Bug Fixes

  • transformer: export definitely typed for transformer so it will be easier to read the documentation while developing (#222) (37b4b7e)
  • typeof-alias-export: make sure alias exports will be transformed correctly (#214) (27ae136)
  • typequery: add support for typequery undefined (#227) (0b835b1)

Features

1.5.1 (2020-01-31)

1.5.0 (2020-01-31)

Bug Fixes

  • definitelyTyped: add node types in generated tsconfig (#186) (19caa94)
  • definitelyTyped: copy compiler option "paths" from processed type (#185) (6265fde)
  • definitelyTyped: use ts-ignore before createMock so that value type modules don't fail (acd2c6f)
  • genericNotProvided: make sure required generic will default to null when are not provided (#180) (ad76471)
  • mockProperty: make sure a falsy value can be assigned to a mock property (#208) (0b37699)
  • ui: use index as key of list of components to make sure the ui doesn't fail when a type gets processed multiple times (#178) (84a52a1)

Features

  • constructorType: Add constructor type descriptor (#115) (8f26218)
  • constructSignature: add construct signature (#116) (b0aa18a)
  • DefinitelyTyped: add process with ui to run createMock on every type of DefinitelyTyped repository (#136) (445f31e)
  • genericDefault: add support for default generics on declaration and extensions (#126) (a9df32a)
  • import: add import equals support and make sure transformer test run in a context so the cache system will work (f23039d)
  • importequal: add support for export equals and remove webpack env types that were conflicting with types node (#124) (990ecf1)
  • indexedAccess: add indexed access support for mocks (#119) (a3e9841)
  • intersectionsfunction: add support for function intersections and parenthesised type in intersections (#127) (5572631)
  • multipledeclaration-bigint: add support for multiple declarations functions for types and values and biging (#163) (00d9904)
  • registerMock: add registerMock functionality to register custom mocks per project (#125) (0feb05a)
  • typeQuery: add support for typeof of an imported module (#128) (a9e25a3)

Performance Improvements

1.4.1 (2019-11-30)

Bug Fixes

  • enum: add module declaration enum support (4642520)

1.4.0 (2019-11-26)

Features

  • config: add option to disable cache between files as a workaround until #101 is completed (92cd1d7)

1.3.1 (2019-11-21)

Bug Fixes

  • this: make sure literal type will not interfere with "this" reference (fd2270b), closes #88 #88

feature

  • genericReuse: add types with generic to mock factory (ddd94b0)

Features

  • interfaceCallSignature: add support for interface call signature (#82) (a00ff55)

BREAKING CHANGES

  • genericReuse: extensions (Provider) provideMethod will be deprecated in future releases in favour of provideMethodWithDeferredValue

Provider.provideMethod is deprecated changed: Before: Provider.instance.provideMethod((name: string, value: any) => { ... }); After: Provider.instance.provideMethodWithDeferredValue((name: string, value: () => any) => { ... });

Read the DOCS for more information

  • add global scope and move type reference cache in the scope

  • remove space

  • init scope

  • add first version - extend generic still doesnt work

  • remove unused method

  • add back the new generic tests

  • remove unused file, disable extensions, intersection and ts lib (WIP)

  • simplify generic function

  • merge generic tests and add reuse test

  • remove unused files

  • re enable working tests and add some info for this branch

  • add test and comment to find test to fix

  • add enumerable to object so it will have the correct output and add support to recursive call signatures

  • fix type generic case

  • restric interface to specific types so it will be easier to extend it

  • rename function

  • first working version generic extends

  • remove unused descriptor and add more test to support types

  • add more tests

  • make sure factory cache is not exposed, divide caches

  • refactor type parameter

  • add more test and refactor the mess in mock factory call

  • add more tests

  • add more tests

  • added back promises implementation and all test

  • remove comment we will write test scenario when available

  • add direct type test mock

  • remove unused import

  • remove comments

  • remove unused field

  • document playground command

  • Update README.md

  • remove unnecessary code, rename text and simplify for

  • remove unnecessary create mock in the test

  • remove unnecessary if

  • deprecate getMethod and add new method to make sure with don't introduce breaking changes

  • update deprecated comment

  • update

0.0.2 (2019-09-21)

0.0.1 (2019-09-21)

1.2.0 (2019-08-18)

Features

  • defaultValues: merge default values (#78) (e5a7424)

1.1.4 (2019-07-06)

Bug Fixes

  • core: use path.relative to check if two urls are the same (#69) (e79b29c)

Features

  • log: add test script that will output logs (d577cf8)

1.1.3 (2019-06-29)

Features

  • log: logging feature, remove npm i logs for ci (0cdfa27)

1.1.2 (2019-05-18)

1.1.1 (2019-04-27)

1.1.0 (2019-04-27)

Bug Fixes

  • modules: make sure transformer is exported in the right folder (832afc1)

1.0.0 (2019-04-27)

Code Refactoring

  • module division: modules divisions (54575a7)

Features

  • createMockList: add createMockList functionality, add typings to framework test (#34) (3030ba5)

BREAKING CHANGES

  • module division: extensions (On, method) are in a separate modules, mockFactory changed interface, name (Provider) and module

Importing On, method changed:

Before: import { On, method } from "ts-auto-mock";

After: import { On, method } from "ts-auto-mock/extension";

MockFactory changed name, module and interface:

Before: import { MockFactory } from "ts-auto-mock";

MockFactory.instance.registerFactory((name: string, value: any) => { ... });

After: import { Provider } from "ts-auto-mock/extension";

Provider.instance.provideMethod((name: string, value: any) => { ... });

0.0.27 (2019-04-07)

Bug Fixes

  • tslinttest: fix another unit test (5b84a55)

0.0.26 (2019-04-07)

0.0.25 (2019-04-07)

Features

  • changelog: add changelog (bd3a43d)
  • ci: add minimum ci to run test on branches (34d4ac7)