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

Add module mocking functionality #1140

Open
jason0x43 opened this issue Apr 14, 2020 · 0 comments
Open

Add module mocking functionality #1140

jason0x43 opened this issue Apr 14, 2020 · 0 comments
Labels
effort-high This will take a while enhancement A new or improved feature priority-medium This should get done, but it's not a high priority

Comments

@jason0x43
Copy link
Member

Intern should provide an out-of-the-box solution for module mocking. The system should work with at least the Node loader and webpack, and it should provide type safety.

The mocking system currently used for Intern's self tests would probably work:

({ default: Node } = await mockImport(
  () => import('src/core/lib/executors/Node'),
  replace => {
    replace(() =>
      import('src/core/lib/common/ErrorFormatter')
    ).withDefault(MockErrorFormatter as any);
    replace(() => import('src/core/lib/common/console')).with(
      mockConsole
    );
  }
);

The snippet above dynamically imports a module, replacing certain of that modules imports with mock values. These imports are type safe, which is why the as any is required for the MockErrorFormatter mock, which doesn't completely mock ErrorFormatter.

The built in mocking system should be optional, and it shouldn't get in the way if the user wants to use something else.

@jason0x43 jason0x43 added enhancement A new or improved feature effort-high This will take a while priority-medium This should get done, but it's not a high priority labels Apr 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort-high This will take a while enhancement A new or improved feature priority-medium This should get done, but it's not a high priority
Projects
None yet
Development

No branches or pull requests

1 participant