@modern-js/module-tools 1.4.2 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/js/modern/cli/build.js +2 -2
  3. package/dist/js/modern/cli/dev.js +2 -2
  4. package/dist/js/modern/commands/build.js +4 -5
  5. package/dist/js/modern/commands/dev.js +6 -7
  6. package/dist/js/modern/features/build/build-platform.js +3 -3
  7. package/dist/js/modern/features/build/build-watch.js +5 -6
  8. package/dist/js/modern/features/build/build.js +5 -6
  9. package/dist/js/modern/features/build/index.js +5 -5
  10. package/dist/js/modern/features/build/utils.js +9 -10
  11. package/dist/js/modern/features/dev/index.js +9 -7
  12. package/dist/js/modern/index.js +37 -37
  13. package/dist/js/node/cli/build.js +2 -2
  14. package/dist/js/node/cli/dev.js +2 -2
  15. package/dist/js/node/commands/build.js +4 -6
  16. package/dist/js/node/commands/dev.js +6 -8
  17. package/dist/js/node/features/build/build-platform.js +3 -4
  18. package/dist/js/node/features/build/build-watch.js +5 -7
  19. package/dist/js/node/features/build/build.js +5 -7
  20. package/dist/js/node/features/build/index.js +5 -5
  21. package/dist/js/node/features/build/utils.js +9 -11
  22. package/dist/js/node/features/dev/index.js +9 -8
  23. package/dist/js/node/index.js +50 -42
  24. package/dist/types/cli/build.d.ts +2 -1
  25. package/dist/types/cli/dev.d.ts +2 -1
  26. package/dist/types/commands/build.d.ts +2 -1
  27. package/dist/types/commands/dev.d.ts +2 -1
  28. package/dist/types/features/build/build-platform.d.ts +2 -1
  29. package/dist/types/features/build/build-watch.d.ts +2 -2
  30. package/dist/types/features/build/build.d.ts +2 -2
  31. package/dist/types/features/build/index.d.ts +2 -2
  32. package/dist/types/features/build/utils.d.ts +4 -3
  33. package/dist/types/features/dev/index.d.ts +4 -3
  34. package/dist/types/index.d.ts +3 -19
  35. package/package.json +8 -8
  36. package/tests/dev-cli.test.ts +42 -8
  37. package/tests/dev-command.test.ts +36 -10
  38. package/tests/dev-feature.test.ts +45 -13
@@ -1,14 +1,16 @@
1
+ import { manager } from '@modern-js/core';
1
2
  import { runSubCmd } from '../src/features/dev';
2
3
 
3
4
  const mockModuleToolsMenu = jest.fn();
4
5
  const mockDevMeta = jest.fn();
5
6
  const exit = jest.spyOn(process, 'exit').mockImplementation();
6
- jest.mock('@modern-js/core', () => ({
7
- __esModule: true,
8
- mountHook: jest.fn(() => ({
7
+ const mockAPI = {
8
+ useAppContext: jest.fn((): any => ({})),
9
+ useResolvedConfigContext: jest.fn(),
10
+ useHookRunners: (): any => ({
9
11
  moduleToolsMenu: mockModuleToolsMenu,
10
- })),
11
- }));
12
+ }),
13
+ };
12
14
 
13
15
  describe('dev feature with subCmd', () => {
14
16
  beforeEach(() => {
@@ -18,29 +20,59 @@ describe('dev feature with subCmd', () => {
18
20
  mockModuleToolsMenu.mockReturnValue([
19
21
  { value: 'storybook', runTask: mockDevMeta },
20
22
  ]);
21
- await runSubCmd('storybook', { isTsProject: true, appDirectory: '' });
22
- expect(mockDevMeta.mock.calls.length).toBe(1);
23
+ const cloned = manager.clone(mockAPI);
24
+ cloned.usePlugin({
25
+ async setup(api) {
26
+ await runSubCmd(api, 'storybook', {
27
+ isTsProject: true,
28
+ appDirectory: '',
29
+ });
30
+ expect(mockDevMeta.mock.calls.length).toBe(1);
31
+ },
32
+ });
33
+ await cloned.init();
23
34
  });
24
35
 
25
36
  it('should run task with "storybook" params when storybook plugin not exist', async () => {
26
37
  mockModuleToolsMenu.mockReturnValue([]);
27
- await runSubCmd('storybook', { isTsProject: true, appDirectory: '' });
28
- expect(exit).toHaveBeenCalled();
38
+ const cloned = manager.clone(mockAPI);
39
+ cloned.usePlugin({
40
+ async setup(api) {
41
+ await runSubCmd(api, 'storybook', {
42
+ isTsProject: true,
43
+ appDirectory: '',
44
+ });
45
+ expect(exit).toHaveBeenCalled();
46
+ },
47
+ });
48
+ await cloned.init();
29
49
  });
30
50
 
31
51
  it('should run task with alias name "story" params when storybook plugin exist', async () => {
32
52
  mockModuleToolsMenu.mockReturnValue([
33
53
  { value: 'storybook', aliasValues: ['story'], runTask: mockDevMeta },
34
54
  ]);
35
- await runSubCmd('story', { isTsProject: true, appDirectory: '' });
36
- expect(mockDevMeta.mock.calls.length).toBe(1);
55
+ const cloned = manager.clone(mockAPI);
56
+ cloned.usePlugin({
57
+ async setup(api) {
58
+ await runSubCmd(api, 'story', { isTsProject: true, appDirectory: '' });
59
+ expect(mockDevMeta.mock.calls.length).toBe(1);
60
+ },
61
+ });
62
+ await cloned.init();
37
63
  });
38
64
 
39
65
  it('should run task with alias name "story1" params when storybook plugin exist', async () => {
40
66
  mockModuleToolsMenu.mockReturnValue([
41
67
  { value: 'storybook', aliasValues: ['story'], runTask: mockDevMeta },
42
68
  ]);
43
- await runSubCmd('story1', { isTsProject: true, appDirectory: '' });
44
- expect(mockDevMeta.mock.calls.length).toBe(0);
69
+ const cloned = manager.clone(mockAPI);
70
+ cloned.usePlugin({
71
+ async setup(api) {
72
+ await runSubCmd(api, 'story1', { isTsProject: true, appDirectory: '' });
73
+ expect(mockDevMeta.mock.calls.length).toBe(0);
74
+ },
75
+ });
76
+ await cloned.init();
45
77
  });
46
78
  });