dvabuzyarov / moq.ts

Moq for Typescript
Apache License 2.0
122 stars 10 forks source link

Import Moq.ts issue #943

Closed hantsy closed 1 year ago

hantsy commented 1 year ago

In my typescript sample project, I used moq.ts as a mocking example in tests, but in the latest updates, an exception was thrown when running the testing codes in Github actions.

The test example is here.

 Details:

    /home/runner/work/code-challenges/code-challenges/transaction-analyzer/node-typescript/node_modules/moq.ts/fesm2020/moq.ts.mjs:3955
    export { APPLY_RETURN_VALUE, ApplyReflectorTrap, ApplyTrap, ArgumentsEqualityComparer, AsyncExpressionDetector, AsyncExpressionReflector, AsyncReflectingProxyInjectorFactory, AutoMockFactory, AutoMockInjectorConfig, AutoMockNameFormatter, AutoMockOptionsBuilder, AutoMockProvider, AutoMockedStorage, CONSTRUCT_RETURN_VALUE, CallCounter, CallbackPresetFactory, CallbackPresetPlayer, CallbacksPreset, CommonTypeProvider, ComplexExpressionErrorFormatter, ComplexExpressionGuard, ComplexExpressionValidator, CompositeExpressionReflector, ConstantEqualityComparer, ConstantFormatter, ConstructReflectorTrap, ConstructTrap, DateMatcher, DefaultInjectorConfig, EXPRESSIONS, EXPRESSION_REFLECTOR, EqualConstantMatcher, EqualMatcher, EqualMatchingInjectorConfig, Expression, ExpressionEqualityComparer, ExpressionFormatter, ExpressionGuardExceptionFactory, ExpressionHasMethodExplorer, ExpressionHasPropertyExplorer, ExpressionValidator, ExpressionsFormatter, FunctionExpression, FunctionExpressionValidator, FunctionFormatter, FunctionMatcher, GET_RETURN_VALUE, GetPropertyEqualityComparer, GetPropertyExpression, GetPropertyExpressionValidator, GetPropertyFormatter, GetPrototypeOfTrap, GetReflectorTrap, GetTrap, HasMethodExplorer, HasPropertyExplorer, HasReflectorTrap, HasTrap, Host, INJECTOR, INJECTOR_IMPL, InOperatorEqualityComparer, InOperatorExpression, InOperatorExpressionValidator, InOperatorFormatter, InOperatorInteractionExplorer, InjectFlags, InjectionToken, Injector, InstanceMethodEqualityComparer, InstanceMethodExpressionValidator, InteractionFormatter, InteractionPlayer, It, ItEqualityComparer, IterableTester, IteratorMatcher, MOCK, MOCK_CONSTRUCTOR, MOCK_OPTIONS, MapMatcher, MembersMethodExplorer, MembersPropertyExplorer, MethodEqualityComparer, MethodExpression, MethodFormatter, MethodOnlyReflectingProxyFactory, MethodReflectingProxyFactory, MethodReflectorTrap, MimicsPreset, MimicsPresetFactory, MimicsPresetPlayer, MimicsRejectedAsyncPresetFactory, MimicsResolvedAsyncPresetFactory, Mock, MockCore, MockOptionsBuilder, MoqAPI, NG_TEMP_TOKEN_PATH, NO_NEW_LINE, NamePrefixProvider, NewOperatorEqualityComparer, NewOperatorExpression, NewOperatorExpressionValidator, NewOperatorFormatter, NullInjector, OBJECT_MATCHERS, ObjectHasMethodExplorer, ObjectHasPropertyExplorer, ObjectMapProvider, ObjectMatcher, Optional, POJOMatcher, PlayTimes, PlayableAlways, PlayableExactly, PlayableNever, PlayableOnce, PlayablePresetProvider, PlayableSequence, PresetBuilder, PresetBuilderFactory, PresetHasInOperatorExplorer, PresetHasMethodExplorer, PresetHasPropertyExplorer, PresetPlayablesUpdater, PresetPlayer, Presets, PrimitiveMatcher, PropertiesValueStorage, PropertyDescriptorProvider, PropertyIsReadOnlyTester, PropertyKeyFormatter, PrototypeStorage, ProxyFactory, REFLECT_APPLY, REFLECT_HAS, ROOT_MOCK, Range, ReflectingProxyFactory, ReflectingProxyInjectorFactory, RejectedPromiseFactory, ResolvedPromiseFactory, ReturnsAsyncPresetFactory, ReturnsPreset, ReturnsPresetFactory, RootMockProvider, SOURCE, Self, SequenceId, SetPropertyEqualityComparer, SetPropertyExpression, SetPropertyExpressionValidator, SetPropertyFormatter, SetPrototypeOfTrap, SetReflectorTrap, SetTrap, SetupFactory, SkipSelf, SpyFunctionProvider, StaticInjector, StringErrorStyler, SyncExpressionReflector, THROW_IF_NOT_FOUND, ThrowsAsyncPresetFactory, ThrowsPreset, ThrowsPresetFactory, Times, TrackedExpressionsFormatter, Tracker, Type, TypesMatcher, USE_VALUE, VerificationTester, Verifier, VerifyError, VerifyFormatter, catchInjectorError, dump, formatError, forwardRef, getClosureSafeProperty, injectorFactory, isForwardRef, mockOptionsProviders, resolveForwardRef, stringify };
    ^^^^^^

    SyntaxError: Unexpected token 'export'

      2 | import Big from 'big.js';
      3 | import { mock } from 'jest-mock-extended';
    > 4 | import { IMock, Mock, Times } from "moq.ts";
        | ^
dvabuzyarov commented 1 year ago

I will take a look.

dvabuzyarov commented 1 year ago

It looks like your project is using commonjs. https://jestjs.io/docs/ecmascript-modules

starting version 10 moq.ts is ESM. Prior versions are build as commonjs.

hantsy commented 1 year ago

I am using Typescript, it should support ESM by default.

dvabuzyarov commented 1 year ago

I am not using jest, so can't say for sure. But according official jest documentation jest ships with experimental support for ECMAScript Modules (ESM)..

Could you dig into settings and be sure that it should work? Or maybe can you create a demo project with another ESM project that you can use with jest. It will help me to sort it out.

hantsy commented 1 year ago

OK, I am trying to update the example project to support ESM.

dvabuzyarov commented 1 year ago

@hantsy With v10.0.6 I have added back commons support. Your example works fine with the it.