@modern-js/core 1.1.5-beta.1 → 1.3.1

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.
@@ -0,0 +1,74 @@
1
+ import path from 'path';
2
+ import { cli } from '../src';
3
+ import { resolveConfig, loadUserConfig } from '../src/config';
4
+ import { loadEnv } from '../src/loadEnv';
5
+
6
+ jest.mock('../src/config', () => ({
7
+ __esModule: true,
8
+ ...jest.requireActual('../src/config'),
9
+ loadUserConfig: jest.fn(),
10
+ resolveConfig: jest.fn(),
11
+ }));
12
+
13
+ jest.mock('../src/loadEnv', () => ({
14
+ __esModule: true,
15
+ ...jest.requireActual('../src/loadEnv'),
16
+ loadEnv: jest.fn(),
17
+ }));
18
+
19
+ describe('@modern-js/core test', () => {
20
+ let mockResolveConfig: any = {};
21
+ let mockLoadedConfig: any = {};
22
+ const cwdSpy = jest.spyOn(process, 'cwd');
23
+ const cwd = path.join(__dirname, './fixtures/index-test');
24
+
25
+ const resetMock = () => {
26
+ jest.resetAllMocks();
27
+ cwdSpy.mockReturnValue(cwd);
28
+ (resolveConfig as jest.Mock).mockReturnValue(
29
+ Promise.resolve(mockResolveConfig),
30
+ );
31
+ (loadUserConfig as jest.Mock).mockImplementation(() =>
32
+ Promise.resolve(mockLoadedConfig),
33
+ );
34
+ };
35
+
36
+ const resetValues = () => {
37
+ mockLoadedConfig = {
38
+ config: {},
39
+ filePath: false,
40
+ dependencies: [],
41
+ pkgConfig: {},
42
+ jsConfig: {},
43
+ };
44
+ mockResolveConfig = {
45
+ server: {
46
+ port: 8080,
47
+ },
48
+ output: {
49
+ path: './my/test/path',
50
+ },
51
+ };
52
+ };
53
+
54
+ beforeEach(() => {
55
+ resetValues();
56
+ resetMock();
57
+ });
58
+
59
+ it('test cli create', () => {
60
+ expect(cli).toBeTruthy();
61
+ });
62
+
63
+ it('test cli init dev', async () => {
64
+ cwdSpy.mockReturnValue(path.join(cwd, 'nested-folder'));
65
+ const options = {
66
+ beforeUsePlugins: jest.fn(),
67
+ };
68
+ options.beforeUsePlugins.mockImplementation((plugins, _) => plugins);
69
+ await cli.init(['dev'], options);
70
+ expect(loadEnv).toHaveBeenCalledWith(cwd);
71
+ expect(options.beforeUsePlugins).toHaveBeenCalledWith([], {});
72
+ // TODO: add more test cases
73
+ });
74
+ });
@@ -1,6 +1,6 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
- import { loadEnv } from '@/loadEnv';
3
+ import { loadEnv } from '../src/loadEnv';
4
4
 
5
5
  const fixture = path.resolve(__dirname, './fixtures/load-env');
6
6
 
@@ -1,7 +1,21 @@
1
1
  import path from 'path';
2
- import { loadPlugins } from '@/loadPlugins';
2
+ import { loadPlugins, getAppPlugins } from '../src/loadPlugins';
3
3
 
4
4
  describe('load plugins', () => {
5
+ test('getAppPlugins', () => {
6
+ const appDirectory = path.resolve(
7
+ __dirname,
8
+ './fixtures/load-plugin/user-plugins',
9
+ );
10
+ const plugins = getAppPlugins(appDirectory, ['foo' as any], {
11
+ x: {
12
+ cli: 'x',
13
+ forced: true,
14
+ } as any,
15
+ });
16
+ expect(plugins).toEqual([{ cli: 'x', forced: true }, 'foo']);
17
+ });
18
+
5
19
  test('should load user plugin successfully', () => {
6
20
  const fixture = path.resolve(
7
21
  __dirname,
@@ -31,6 +45,27 @@ describe('load plugins', () => {
31
45
  ]);
32
46
  });
33
47
 
48
+ test('should load user string plugin successfully', () => {
49
+ const fixture = path.resolve(
50
+ __dirname,
51
+ './fixtures/load-plugin/user-plugins',
52
+ );
53
+
54
+ const plugins = loadPlugins(fixture, [
55
+ path.join(fixture, './test-plugin-a.js') as any,
56
+ ]);
57
+
58
+ expect(plugins).toEqual([
59
+ {
60
+ cli: {
61
+ name: 'a',
62
+ pluginPath: path.join(fixture, './test-plugin-a.js'),
63
+ },
64
+ cliPath: path.join(fixture, './test-plugin-a.js'),
65
+ },
66
+ ]);
67
+ });
68
+
34
69
  test(`should throw error when plugin not found `, () => {
35
70
  const fixture = path.resolve(__dirname, './fixtures/load-plugin/not-found');
36
71
 
@@ -1,4 +1,4 @@
1
- import { mergeConfig } from '@/config/mergeConfig';
1
+ import { mergeConfig } from '../src/config/mergeConfig';
2
2
 
3
3
  describe('load plugins', () => {
4
4
  test('should replace property deeply', () => {
@@ -1,5 +1,5 @@
1
- import { repeatKeyWarning } from '@/utils/repeatKeyWarning';
2
- import { UserConfig } from '@/config';
1
+ import { repeatKeyWarning } from '../src/utils/repeatKeyWarning';
2
+ import { UserConfig } from '../src/config';
3
3
 
4
4
  jest.spyOn(process, 'exit').mockImplementation();
5
5
 
@@ -1,4 +1,4 @@
1
- import { patchSchema, traverseSchema } from '@/config/schema';
1
+ import { patchSchema, traverseSchema } from '../src/config/schema';
2
2
 
3
3
  describe('patch schemas', () => {
4
4
  test('should add schema succcessfully', () => {
@@ -6,8 +6,6 @@
6
6
  "baseUrl": "./",
7
7
  "isolatedModules": true,
8
8
  "esModuleInterop": true,
9
- "paths": {
10
- "@/*": ["../src/*"]
11
- }
9
+ "paths": {}
12
10
  }
13
11
  }
@@ -0,0 +1,8 @@
1
+ import { program, Command } from '../src/utils/commander';
2
+
3
+ describe('utils', () => {
4
+ it('default', () => {
5
+ expect(program).toBeDefined();
6
+ expect(Command).toBeDefined();
7
+ });
8
+ });
package/tsconfig.json CHANGED
@@ -6,9 +6,7 @@
6
6
  "baseUrl": "./",
7
7
  "isolatedModules": true,
8
8
  "esModuleInterop": true,
9
- "paths": {
10
- "@/*": ["./src/*"]
11
- }
9
+ "paths": {}
12
10
  },
13
11
  "include": ["src"]
14
12
  }