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

Monoid and Semigroup for project settings #5

Closed
waynevanson opened this issue Nov 10, 2021 · 3 comments
Closed

Monoid and Semigroup for project settings #5

waynevanson opened this issue Nov 10, 2021 · 3 comments

Comments

@waynevanson
Copy link

Is your feature request related to a problem? Please describe.
Extend beyond matchers with jest related monoids and semigroups!

Describe the solution you'd like

Add Monoid and Semigroup instances for @jest/types#Config#*

Describe alternatives you've considered
This lib has some traction, so I think this repo is the best place to put something like this.

Additional context

I use a substantial amounts of JS in my jest config. I like being able to use fp-ts to help create configuration. It's currently more painful than it should be. I used config#projects in the more complex repos.

Appendix

Semigroup for Config.InitialProjectConfig:

function partial<T extends Record<string, unknown>>(struct: {
  [P in keyof Required<T>]: S.Semigroup<Required<T>[P]>;
}): S.Semigroup<Partial<T>> {
  return {
    concat: (x, y) =>
      pipe(
        Object.keys(struct) as ReadonlyArray<keyof T>,
        A.reduce({} as Partial<T>, (b, key) =>
          pipe(
            [x[key], y[key]],
            A.map(O.fromNullable),
            S.concatAll(O.getMonoid(struct[key]))(O.none),
            O.map((value) => ({ ...b, [key]: value })),
            O.getOrElseW(() => b)
          )
        )
      ),
  };
}

type Ommiited =
  | "globals"
  | "haste"
  | "moduleNameMapper"
  | "testEnvironmentOptions"
  | "testRegex"
  | "timers"
  | "transform";

const ss: S.Semigroup<Omit<Config.InitialOptions, Ommiited>> = partial<
  Required<Omit<Config.InitialProjectOptions, Ommiited>>
>({
  automock: Boolean.MonoidAny,
  cache: Boolean.MonoidAny,
  cacheDirectory: S.first(),
  clearMocks: Boolean.MonoidAny,
  coveragePathIgnorePatterns: MA.getSemigroup(),
  cwd: S.first(),
  dependencyExtractor: S.first(),
  detectLeaks: Boolean.MonoidAny,
  detectOpenHandles: Boolean.MonoidAny,
  displayName: S.first(),
  errorOnDeprecated: Boolean.MonoidAny,
  extensionsToTreatAsEsm: MA.getSemigroup(),
  extraGlobals: MA.getSemigroup(),
  filter: S.first(),
  forceCoverageMatch: MA.getSemigroup(),
  globalSetup: S.first(),
  globalTeardown: S.first(),
  injectGlobals: Boolean.MonoidAny,
  moduleDirectories: MA.getSemigroup(),
  moduleFileExtensions: MA.getSemigroup(),
  moduleLoader: S.first(),
  modulePathIgnorePatterns: MA.getSemigroup(),
  modulePaths: MA.getSemigroup(),
  name: S.first(),
  prettierPath: S.first(),
  resetMocks: Boolean.MonoidAny,
  resetModules: Boolean.MonoidAny,
  resolver: S.first(),
  restoreMocks: Boolean.MonoidAny,
  rootDir: S.first(),
  roots: MA.getSemigroup(),
  runner: S.first(),
  setupFiles: MA.getSemigroup(),
  setupFilesAfterEnv: MA.getSemigroup(),
  skipFilter: Boolean.MonoidAny,
  skipNodeResolution: Boolean.MonoidAny,
  slowTestThreshold: S.first(),
  snapshotFormat: S.struct({}),
  snapshotResolver: S.first(),
  snapshotSerializers: MA.getSemigroup(),
  testEnvironment: S.last(),
  testLocationInResults: Boolean.MonoidAny,
  testMatch: MA.getSemigroup(),
  testPathIgnorePatterns: MA.getSemigroup(),
  testRunner: S.last(),
  testURL: S.last(),
  transformIgnorePatterns: S.last(),
  unmockedModulePathPatterns: MA.getSemigroup(),
  watchPathIgnorePatterns: MA.getSemigroup(),
});
@leilapearson
Copy link
Contributor

Thanks for the request.

I'm not sure that this package is the best place for these. I really see jest-fp-ts as being a simple set of matchers, and also I suspect that it's not that common for people to need what you are proposing. You certainly seem to be both an fp-ts and jest power user!

Perhaps create a separate package for this?

Will leave your request open for a bit in case you or others want to comment further.

@waynevanson
Copy link
Author

Thank you for compliment!

I would assume it's one of the better places to put this considering the name of the package couldn't be more generically scoped to fpts and jest.

But then again it's published under your own npm organisation, so you might be right; there may be a better home for it.

Feel free to close it when you feel like it 👍

@leilapearson
Copy link
Contributor

Closing this feature request as it is outside of the intended package scope.

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

No branches or pull requests

2 participants