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

jest transformers for babel and ts #842

Merged
merged 10 commits into from Apr 19, 2020
Merged

jest transformers for babel and ts #842

merged 10 commits into from Apr 19, 2020

Conversation

3cp
Copy link
Member

@3cp 3cp commented Apr 13, 2020

Wrap original jest transformers to support au2 conventions.

  • @aurelia/babel-jest to wrap babel-jest
  • @aurelia/ts-jest to wrap ts-jest.

Update to clarify my approach: because jest apparently does not support chained transformers (this does not match webpack's achitect on the loader chain), I have to wrap existing babel-jest and ts-jest to apply our conventions.

@3cp
Copy link
Member Author

3cp commented Apr 13, 2020

Two obstacles so far:

  1. need to update typescript-eslint to support latest TypeScript syntax import type ....
⋊> ~/a/aurelia on jest ◦ npm ls @typescript-eslint/eslint-plugin
aurelia@ /Users/huocp/aurelia/aurelia
└── @typescript-eslint/eslint-plugin@2.16.0

typescript-eslint/typescript-eslint#1697

@BBosman could we upgrade typescript-eslint to latest version 2.27.0? If there is no other complications, I can try update it in this branch too.

2. export = is not supported by typescript when targeting ECMAScript modules. But jest expects the transformer (a npm module) has a Transformer(type) object directly on module.exports.

This is basically the same problem I faced before when I try to write a parcel v1 plugin (it expects a commonjs module too), but gave up and decided to wait (still waiting) for parcel v2 release.

Jest support is more important than parcel. @fkleuver should we have special build setup for this two (working on the babel-jest now, no ts-jest yet) jest packages to build only commonjs dist files? This setup might be useful for some other future modules (e.g. parcel) too.

Update I found out how to manually export needed parts.

@3cp
Copy link
Member Author

3cp commented Apr 13, 2020

@BBosman I tried to upgrade typescript-eslint 2.27.0 locally, but still see the error around import type. I guess I missed some other eslint packages.

@BBosman
Copy link
Contributor

BBosman commented Apr 13, 2020

Did you also update typescript itself? Because this repo is still at 2.7.x as far as I know.

@3cp
Copy link
Member Author

3cp commented Apr 13, 2020

@BBosman thx! I will try to upgrade ts from 3.7 to 3.8.

@3cp
Copy link
Member Author

3cp commented Apr 13, 2020

I will defer the typescript upgrade to @fkleuver as I got some syntax error in packages/runtime with TypeScript 3.8.3.

Guess ts introduced some breaking changes again...

lerna ERR! npm run build exited 1 in '@aurelia/runtime'
lerna ERR! npm run build stdout:

> @aurelia/runtime@0.6.0 build /Users/huocp/aurelia/aurelia/packages/runtime
> tsc -b

src/binding/connectable.ts(65,5): error TS2322: Type 'ISubscribable & { [id: number]: number; }' is not assignable to type 'number | (ISubscribable & { [id: string]: number; })'.
  Type 'ISubscribable & { [id: number]: number; }' is not assignable to type 'ISubscribable & { [id: string]: number; }'.
    Type 'ISubscribable & { [id: number]: number; }' is not assignable to type '{ [id: string]: number; }'.
      Index signature is missing in type 'ISubscribable & { [id: number]: number; }'.
src/templating/controller.ts(237,37): error TS2345: Argument of type 'Controller<T, C>' is not assignable to parameter of type 'Controller<INode, IViewModel<INode>>'.
  Types of property 'bindingContext' are incompatible.
    Type 'IIndexable<C & { create(controller: IController<INode, IViewModel<INode>>, definition: CustomElementDefinition<Constructable<{}>>, parentContainer: IContainer, parts: Record<...> | undefined, flags: LifecycleFlags): void | PartialResourceDefinition<...>; ... 11 more ...; caching(flags: LifecycleFlags): void; }, unkn...' is not assignable to type 'IIndexable<IViewModel<INode> & { create(controller: IController<INode, IViewModel<INode>>, definition: CustomElementDefinition<Constructable<{}>>, parentContainer: IContainer, parts: Record<...> | undefined, flags: LifecycleFlags): void | PartialResourceDefinition<...>; ... 11 more ...; caching(flags: LifecycleFlags...'.
      Type 'IIndexable<C & { create(controller: IController<INode, IViewModel<INode>>, definition: CustomElementDefinition<Constructable<{}>>, parentContainer: IContainer, parts: Record<...> | undefined, flags: LifecycleFlags): void | PartialResourceDefinition<...>; ... 11 more ...; caching(flags: LifecycleFlags): void; }, unkn...' is not assignable to type 'IIndexable<IViewModel<INode> & { create(controller: IController<INode, IViewModel<INode>>, definition: CustomElementDefinition<Constructable<{}>>, parentContainer: IContainer, parts: Record<...> | undefined, flags: LifecycleFlags): void | PartialResourceDefinition<...>; ... 11 more ...; caching(flags: LifecycleFlags...'.
        Type 'IIndexable<C & { create(controller: IController<INode, IViewModel<INode>>, definition: CustomElementDefinition<Constructable<{}>>, parentContainer: IContainer, parts: Record<...> | undefined, flags: LifecycleFlags): void | PartialResourceDefinition<...>; ... 11 more ...; caching(flags: LifecycleFlags): void; }, unkn...' is not assignable to type 'IIndexable<IViewModel<INode> & { create(controller: IController<INode, IViewModel<INode>>, definition: CustomElementDefinition<Constructable<{}>>, parentContainer: IContainer, parts: Record<...> | undefined, flags: LifecycleFlags): void | PartialResourceDefinition<...>; ... 11 more ...; caching(flags: LifecycleFlags...'.
          Type 'IIndexable<C & { create(controller: IController<INode, IViewModel<INode>>, definition: CustomElementDefinition<Constructable<{}>>, parentContainer: IContainer, parts: Record<...> | undefined, flags: LifecycleFlags): void | PartialResourceDefinition<...>; ... 11 more ...; caching(flags: LifecycleFlags): void; }, unkn...' is not assignable to type '{ [x: string]: unknown; [x: number]: unknown; }'.
            Index signature is missing in type '{ [K in Exclude<string, "create" | "beforeCompile" | "afterCompile" | "afterCompileChildren" | "beforeBind" | "afterBind" | "beforeUnbind" | "afterUnbind" | "beforeAttach" | "afterAttach" | "beforeDetach" | "afterDetach" | "caching" | keyof C> | Exclude<...> | Exclude<...>]: unknown; } & ICustomElementViewModel<...>...'.
src/templating/controller.ts(271,37): error TS2345: Argument of type 'Controller<T, C>' is not assignable to parameter of type 'Controller<INode, IViewModel<INode>>'.
  Types of property 'bindingContext' are incompatible.
    Type 'IIndexable<C & { create(controller: IController<INode, IViewModel<INode>>, definition: CustomElementDefinition<Constructable<{}>>, parentContainer: IContainer, parts: Record<...> | undefined, flags: LifecycleFlags): void | PartialResourceDefinition<...>; ... 11 more ...; caching(flags: LifecycleFlags): void; }, unkn...' is not assignable to type 'IIndexable<IViewModel<INode> & { create(controller: IController<INode, IViewModel<INode>>, definition: CustomElementDefinition<Constructable<{}>>, parentContainer: IContainer, parts: Record<...> | undefined, flags: LifecycleFlags): void | PartialResourceDefinition<...>; ... 11 more ...; caching(flags: LifecycleFlags...'.
      Type 'IIndexable<C & { create(controller: IController<INode, IViewModel<INode>>, definition: CustomElementDefinition<Constructable<{}>>, parentContainer: IContainer, parts: Record<...> | undefined, flags: LifecycleFlags): void | PartialResourceDefinition<...>; ... 11 more ...; caching(flags: LifecycleFlags): void; }, unkn...' is not assignable to type 'IIndexable<IViewModel<INode> & { create(controller: IController<INode, IViewModel<INode>>, definition: CustomElementDefinition<Constructable<{}>>, parentContainer: IContainer, parts: Record<...> | undefined, flags: LifecycleFlags): void | PartialResourceDefinition<...>; ... 11 more ...; caching(flags: LifecycleFlags...'.
        Type 'IIndexable<C & { create(controller: IController<INode, IViewModel<INode>>, definition: CustomElementDefinition<Constructable<{}>>, parentContainer: IContainer, parts: Record<...> | undefined, flags: LifecycleFlags): void | PartialResourceDefinition<...>; ... 11 more ...; caching(flags: LifecycleFlags): void; }, unkn...' is not assignable to type 'IIndexable<IViewModel<INode> & { create(controller: IController<INode, IViewModel<INode>>, definition: CustomElementDefinition<Constructable<{}>>, parentContainer: IContainer, parts: Record<...> | undefined, flags: LifecycleFlags): void | PartialResourceDefinition<...>; ... 11 more ...; caching(flags: LifecycleFlags...'.
          Type 'IIndexable<C & { create(controller: IController<INode, IViewModel<INode>>, definition: CustomElementDefinition<Constructable<{}>>, parentContainer: IContainer, parts: Record<...> | undefined, flags: LifecycleFlags): void | PartialResourceDefinition<...>; ... 11 more ...; caching(flags: LifecycleFlags): void; }, unkn...' is not assignable to type '{ [x: string]: unknown; [x: number]: unknown; }'.
            Index signature is missing in type '{ [K in Exclude<string, "create" | "beforeCompile" | "afterCompile" | "afterCompileChildren" | "beforeBind" | "afterBind" | "beforeUnbind" | "afterUnbind" | "beforeAttach" | "afterAttach" | "beforeDetach" | "afterDetach" | "caching" | keyof C> | Exclude<...> | Exclude<...>]: unknown; } & ICustomAttributeViewModel<.....'.
src/templating/controller.ts(275,12): error TS2352: Conversion of type 'Controller<T, C>' to type 'ICustomAttributeController<T, C>' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
  Types of property 'bindingContext' are incompatible.
    Type 'IIndexable<C & { create(controller: IController<INode, IViewModel<INode>>, definition: CustomElementDefinition<Constructable<{}>>, parentContainer: IContainer, parts: Record<...> | undefined, flags: LifecycleFlags): void | PartialResourceDefinition<...>; ... 11 more ...; caching(flags: LifecycleFlags): void; }, unkn...' is not comparable to type 'C & { [x: string]: unknown; [x: number]: unknown; }'.
      Type 'IIndexable<C & { create(controller: IController<INode, IViewModel<INode>>, definition: CustomElementDefinition<Constructable<{}>>, parentContainer: IContainer, parts: Record<...> | undefined, flags: LifecycleFlags): void | PartialResourceDefinition<...>; ... 11 more ...; caching(flags: LifecycleFlags): void; }, unkn...' is not comparable to type 'C & { [x: string]: unknown; [x: number]: unknown; }'.
        Type 'IIndexable<C & { create(controller: IController<INode, IViewModel<INode>>, definition: CustomElementDefinition<Constructable<{}>>, parentContainer: IContainer, parts: Record<...> | undefined, flags: LifecycleFlags): void | PartialResourceDefinition<...>; ... 11 more ...; caching(flags: LifecycleFlags): void; }, unkn...' is not comparable to type '{ [x: string]: unknown; [x: number]: unknown; }'.
          Index signature is missing in type '{ [K in Exclude<string, "create" | "beforeCompile" | "afterCompile" | "afterCompileChildren" | "beforeBind" | "afterBind" | "beforeUnbind" | "afterUnbind" | "beforeAttach" | "afterAttach" | "beforeDetach" | "afterDetach" | "caching" | keyof C> | Exclude<...> | Exclude<...>]: unknown; } & ICustomAttributeViewModel<.....'.

@3cp
Copy link
Member Author

3cp commented Apr 13, 2020

In the meantime, I will use TS 3.7 syntax (downside is moving some devDeps to deps which only introduce types).

@fkleuver no need special commonjs build for jest, I found out how to manually export needed parts.

@3cp
Copy link
Member Author

3cp commented Apr 13, 2020

Good, @aurelia/babel-jest works in my local environment.
Next step is to find out how to fill up the missing unit tests for this jest transformer...

@AureliaEffect
Copy link
Member

@codeclimate
Copy link

codeclimate bot commented Apr 13, 2020

Code Climate has analyzed commit 93ebe19 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 84.0% (0.0% change).

View more on Code Climate.

@AureliaEffect
Copy link
Member

@codecov
Copy link

codecov bot commented Apr 13, 2020

Codecov Report

Merging #842 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #842   +/-   ##
=======================================
  Coverage   83.76%   83.76%           
=======================================
  Files         194      194           
  Lines       17334    17334           
  Branches     3564     3564           
=======================================
  Hits        14519    14519           
  Misses       2815     2815           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 63f1c1e...93ebe19. Read the comment docs.

@AureliaEffect
Copy link
Member

@AureliaEffect
Copy link
Member

@3cp 3cp added this to the Au2 v0.7.0 milestone Apr 13, 2020
@3cp
Copy link
Member Author

3cp commented Apr 13, 2020

Both @aurelia/babel-jest and @aurelia/ts-jest worked as expected in local dev.

Pending implementing unit tests.

@AureliaEffect
Copy link
Member

@3cp 3cp marked this pull request as ready for review April 14, 2020 03:42
@3cp
Copy link
Member Author

3cp commented Apr 14, 2020

Added unit tests. Double checked with jest skeletons aurelia/new#17 again. All good.

@3cp
Copy link
Member Author

3cp commented Apr 14, 2020

Note the jest skeletons aurelia/new#17 use default jest jsdom env. Our au2 *-html core modules work well with default jest jsdom env, so the test setup file is same for jest (nodejs env) and jasmine (browser env).

@AureliaEffect
Copy link
Member

@AureliaEffect
Copy link
Member

@fkleuver fkleuver merged commit 2861ea8 into master Apr 19, 2020
@fkleuver fkleuver deleted the jest branch April 19, 2020 14:32
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.

None yet

4 participants