Skip to content

Experimental PR to test switching from .js to .ts #346

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

Closed
wants to merge 17 commits into from

Conversation

duluca
Copy link
Contributor

@duluca duluca commented Feb 26, 2018

Goal, remove Browserify as a dependency with a browser targeted tsconfig.json file.
To get there, must switch over to .ts.
Lot's of errors, because TypeScript isn't liking the existing imports and module.exports.

Errors received after switching

src/args-match.ts(7,21): error TS2339: Property 'allowMatchers' does not exist on type '{}'.
src/callback.ts(16,10): error TS2339: Property '__name' does not exist on type '(...matcherArgs: any[]) => any'.
src/callback.ts(17,10): error TS2339: Property '__matches' does not exist on type '(...matcherArgs: any[]) => any'.
src/config.ts(7,23): error TS2304: Cannot find name 'global'.
src/config.ts(27,7): error TS2554: Expected 3 arguments, but got 2.
src/config.ts(36,7): error TS2554: Expected 3 arguments, but got 2.
src/constructor.ts(7,7): error TS2554: Expected 2-3 arguments, but got 1.
src/constructor.ts(11,16): error TS2554: Expected 2 arguments, but got 1.
src/constructor.ts(16,45): error TS2554: Expected 2 arguments, but got 1.
src/function.ts(9,7): error TS2554: Expected 2-3 arguments, but got 1.
src/function/index.ts(7,12): error TS2554: Expected 3 arguments, but got 2.
src/function/index.ts(9,12): error TS2554: Expected 3 arguments, but got 2.
src/imitate/create-imitation.ts(14,14): error TS2554: Expected 2 arguments, but got 1.
src/imitate/overwrite-children/is-fakeable.ts(14,5): error TS2304: Cannot find name 'global'.
src/index.ts(15,1): error TS2304: Cannot find name 'module'.
src/log.ts(5,44): error TS2304: Cannot find name 'console'.
src/log.ts(5,68): error TS2304: Cannot find name 'console'.
src/log.ts(6,7): error TS2304: Cannot find name 'console'.
src/matchers/builtin/captor.ts(11,16): error TS2339: Property 'values' does not exist on type '{ capture: (...matcherArgs: any[]) => any; }'.
src/matchers/builtin/captor.ts(11,32): error TS2339: Property 'values' does not exist on type '{ capture: (...matcherArgs: any[]) => any; }'.
src/matchers/builtin/captor.ts(12,16): error TS2339: Property 'values' does not exist on type '{ capture: (...matcherArgs: any[]) => any; }'.
src/matchers/builtin/captor.ts(13,16): error TS2339: Property 'value' does not exist on type '{ capture: (...matcherArgs: any[]) => any; }'.
src/object.ts(18,12): error TS2554: Expected 2-3 arguments, but got 1.
src/object.ts(30,21): error TS2554: Expected 2 arguments, but got 1.
src/object.ts(39,24): error TS2554: Expected 2 arguments, but got 1.
src/object.ts(48,5): error TS2554: Expected 3 arguments, but got 2.
src/object.ts(61,3): error TS2554: Expected 3 arguments, but got 2.
src/object.ts(64,3): error TS2554: Expected 3 arguments, but got 2.
src/quibble.browser.ts(1,1): error TS2304: Cannot find name 'module'.
src/replace/index.ts(10,12): error TS2556: Expected 2 arguments, but got 0 or more.
src/replace/index.ts(10,29): error TS2461: Type 'IArguments' is not an array type.
src/replace/index.ts(12,12): error TS2556: Expected 3 arguments, but got 0 or more.
src/replace/index.ts(12,31): error TS2461: Type 'IArguments' is not an array type.
src/replace/jest-module.ts(4,18): error TS2304: Cannot find name 'require'.
src/replace/jest-module.ts(6,5): error TS2554: Expected 3 arguments, but got 2.
src/replace/module.ts(2,18): error TS2307: Cannot find module 'path'.
src/replace/module.ts(11,14): error TS2304: Cannot find name 'jest'.
src/replace/module.ts(11,40): error TS2556: Expected 2 arguments, but got 0 or more.
src/replace/module.ts(11,54): error TS2461: Type 'IArguments' is not an array type.
src/replace/module.ts(27,12): error TS2552: Cannot find name 'require'. Did you mean 'requireAt'?
src/replace/module.ts(30,12): error TS2552: Cannot find name 'require'. Did you mean 'requireAt'?
src/replace/module.ts(30,20): error TS2552: Cannot find name 'require'. Did you mean 'requireAt'?
src/replace/module.ts(31,17): error TS2304: Cannot find name 'process'.
src/replace/property.ts(24,5): error TS2554: Expected 3 arguments, but got 2.
src/replace/property.ts(41,5): error TS2554: Expected 3 arguments, but got 2.
src/store/stubbings.ts(105,12): error TS2554: Expected 3 arguments, but got 2.
src/value/call-log.ts(17,10): error TS2339: Property 'calls' does not exist on type 'CallLog'.
src/value/call-log.ts(18,10): error TS2339: Property 'callHistory' does not exist on type 'CallLog'.
src/value/call-log.ts(22,10): error TS2339: Property 'callHistory' does not exist on type 'CallLog'.
src/value/call-log.ts(23,14): error TS2339: Property 'calls' does not exist on type 'CallLog'.
src/value/call-log.ts(24,12): error TS2339: Property 'calls' does not exist on type 'CallLog'.
src/value/call-log.ts(26,12): error TS2339: Property 'calls' does not exist on type 'CallLog'.
src/value/call-log.ts(31,17): error TS2339: Property 'calls' does not exist on type 'CallLog'.
src/value/call-log.ts(35,27): error TS2339: Property 'callHistory' does not exist on type 'CallLog'.
src/value/call-log.ts(36,26): error TS2339: Property 'calls' does not exist on type 'CallLog'.
src/value/call-log.ts(37,12): error TS2339: Property 'calls' does not exist on type 'CallLog'.
src/value/call.ts(3,10): error TS2339: Property 'context' does not exist on type 'Call'.
src/value/call.ts(4,10): error TS2339: Property 'args' does not exist on type 'Call'.
src/value/double.ts(6,29): error TS2339: Property 'fake' does not exist on type 'Double'.
src/value/double.ts(11,10): error TS2339: Property 'name' does not exist on type 'Double'.
src/value/double.ts(12,10): error TS2339: Property 'real' does not exist on type 'Double'.
src/value/double.ts(13,10): error TS2339: Property 'children' does not exist on type 'Double'.
src/value/double.ts(15,12): error TS2339: Property 'parent' does not exist on type 'Double'.
src/value/double.ts(21,10): error TS2339: Property 'children' does not exist on type 'Double'.
src/value/double.ts(26,61): error TS2339: Property 'name' does not exist on type 'Double'.
src/value/double.ts(33,15): error TS2339: Property 'parent' does not exist on type 'Double'.
src/value/double.ts(34,17): error TS2339: Property 'parent' does not exist on type 'Double'.
src/value/double.ts(34,46): error TS2339: Property 'parent' does not exist on type 'Double'.
src/value/stubbing-register.ts(17,10): error TS2339: Property 'stubbings' does not exist on type 'StubbingRegister'.
src/value/stubbing-register.ts(21,14): error TS2339: Property 'stubbings' does not exist on type 'StubbingRegister'.
src/value/stubbing-register.ts(22,12): error TS2339: Property 'stubbings' does not exist on type 'StubbingRegister'.
src/value/stubbing-register.ts(24,12): error TS2339: Property 'stubbings' does not exist on type 'StubbingRegister'.
src/value/stubbing-register.ts(29,17): error TS2339: Property 'stubbings' does not exist on type 'StubbingRegister'.
src/value/stubbing.ts(5,10): error TS2339: Property 'type' does not exist on type 'Stubbing'.
src/value/stubbing.ts(6,10): error TS2339: Property 'args' does not exist on type 'Stubbing'.
src/value/stubbing.ts(7,10): error TS2339: Property 'outcomes' does not exist on type 'Stubbing'.
src/value/stubbing.ts(8,10): error TS2339: Property 'options' does not exist on type 'Stubbing'.
src/value/stubbing.ts(9,10): error TS2551: Property 'satisfyingCalls' does not exist on type 'Stubbing'. Did you mean 'addSatisfyingCall'?
src/value/stubbing.ts(13,14): error TS2339: Property 'options' does not exist on type 'Stubbing'.
src/value/stubbing.ts(14,17): error TS2551: Property 'satisfyingCalls' does not exist on type 'Stubbing'. Did you mean 'addSatisfyingCall'?
src/value/stubbing.ts(14,45): error TS2339: Property 'options' does not exist on type 'Stubbing'.
src/value/stubbing.ts(18,43): error TS2551: Property 'satisfyingCalls' does not exist on type 'Stubbing'. Did you mean 'addSatisfyingCall'?
src/value/stubbing.ts(19,29): error TS2339: Property 'outcomes' does not exist on type 'Stubbing'.
src/value/stubbing.ts(20,19): error TS2339: Property 'outcomes' does not exist on type 'Stubbing'.
src/value/stubbing.ts(22,26): error TS2339: Property 'outcomes' does not exist on type 'Stubbing'.
src/value/stubbing.ts(27,10): error TS2551: Property 'satisfyingCalls' does not exist on type 'Stubbing'. Did you mean 'addSatisfyingCall'?
src/verify.ts(23,5): error TS2554: Expected 3 arguments, but got 2.
src/verify/index.ts(8,10): error TS2459: Type 'void' has no property 'double' and no string index signature.
src/verify/index.ts(8,18): error TS2459: Type 'void' has no property 'call' and no string index signature.
src/when.ts(44,12): error TS2554: Expected 3 arguments, but got 2.
src/when.ts(66,5): error TS2554: Expected 3 arguments, but got 2.
src/when/ensure-rehearsal.ts(5,5): error TS2554: Expected 3 arguments, but got 2.

@searls
Copy link
Member

searls commented Feb 27, 2018

Hey Doguhan, since I've never used Typescript before I will probably make pretty slow work of a lot of these errors. Do you want to try to take a pass at these and raise any question marks here?

@duluca
Copy link
Contributor Author

duluca commented Mar 27, 2018

@kgroat if you're interested in helping out, this is the PR for transitioning in to .ts files

@searls
Copy link
Member

searls commented Mar 31, 2018

Hey friends, what's the status update of this branch?

@duluca
Copy link
Contributor Author

duluca commented Mar 31, 2018 via email

@searls
Copy link
Member

searls commented Apr 1, 2018

Working on getting this up to date and tests passing.

  • get tests running by passing allowJs: true to ts-node/register
  • rebase origin/master to get up to date
  • figure out the meaning fo the changes of src/index.ts

Right now the only failing test is the test/unit/index.test.js, because a few extra properties were tacked on, but they're undefined at runtime so I can't understand how they're meaningful. Of course I'd prefer not to export additional undefined stuff since this is the publicly consumed module.

Here's what src/index is currently:

{
  quibble: [test double for "quibble: quibble"],
  function: [test double for "../../src/function: .default"],
  func: [test double for "../../src/function: .default"],
  object: [test double for "../../src/object: .default"],
  constructor: [test double for "../../src/constructor: .default"],
  imitate: [test double for "../../src/imitate: .default"],
  when: [test double for "../../src/when: .default"],
  verify: [test double for "../../src/verify: .default"],
  matchers: {
    create: [test double for "../../src/matchers: .default.create"],
    captor: [test double for "../../src/matchers: .default.captor"],
    isA: [test double for "../../src/matchers: .default.isA"],
    anything: [test double for "../../src/matchers: .default.anything"],
    contains: [test double for "../../src/matchers: .default.contains"],
    argThat: [test double for "../../src/matchers: .default.argThat"],
    not: [test double for "../../src/matchers: .default.not"]
  },
  Captor: undefined,
  Created: undefined,
  replace: [test double for "../../src/replace: .default"],
  explain: [test double for "../../src/explain: .default"],
  reset: [test double for "../../src/reset: .default"],
  config: [test double for "../../src/config: .default"],
  ConfigObject: undefined,
  callback: callback,
  version: "3.7.0"
}

searls added 2 commits April 1, 2018 10:58
1. import & export quibble (I can't figure out how to one-liner this)

2. Remove the three names that are exported as undefined because I 
can't figure out what to do with them. Hopefully someone in testdouble#346 can
educate me!
@searls
Copy link
Member

searls commented Apr 1, 2018

Okay, all done for now. Forced the src/index.ts test passing and now we're onto a myriad of npm run style:ts standard style errors

@duluca
Copy link
Contributor Author

duluca commented Apr 3, 2018

@searls this command is giving me a headache standard --fix --parser typescript-eslint-parser --plugin typescript \"**/*.ts\". It seems like a string of tools that are not meant to be used with each other, failing to recognize basic TypeScript code. In my Angular codebase, I use tslint in combination with prettier. I've added tslint in with a Standard.js config, and the error messages look like actual linting fails.

@searls
Copy link
Member

searls commented Apr 3, 2018

@duluca it looks like this is probably the way to go with standard (I agree this configuration is not good). Here's a github comment with 7 or 8 repos configured to use it: bradzacher/eslint-plugin-typescript#110 (comment)

@searls
Copy link
Member

searls commented Jul 14, 2022

Closing as stale (though I'd still be interested in moving testdouble.js to typescript, enough has changed in the tooling that we'd probably want to start fresh)

@searls searls closed this Jul 14, 2022
@duluca
Copy link
Contributor Author

duluca commented Jul 14, 2022 via email

@searls
Copy link
Member

searls commented Jul 14, 2022

Bring it on, @duluca! Incidentally, I tried porting Mocktail to Sorbet but it looks like Sorbet's type system is not capable of generic return types being coded as instances that match a class/module argument type (e.g. Mocktail.of(Basket) can't be typed to ensure the return value is an instance of Basket)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants