@modern-js/utils 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @modern-js/utils
2
2
 
3
+ ## 1.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - ec4dbffb: feat: support as a pure api service
8
+ - bada2879: refactor plugin-garfish:
9
+ - change @modern-js/plugin-micro-frontend => @modern-js/plugin-garfish
10
+ - remove disableCustomerRouter logic
11
+ - adding unit test
12
+ - fix plugin-garfish type error
13
+
14
+ ### Patch Changes
15
+
16
+ - d099e5c5: fix error when modify modern.config.js
17
+ - 24f616ca: feat: support custom meta info
18
+ - bd819a8d: feat: add wait function
19
+
3
20
  ## 1.2.2
4
21
 
5
22
  ### Patch Changes
@@ -1,5 +1,5 @@
1
1
  export const clearConsole = () => {
2
- if (process.stdout.isTTY) {
2
+ if (process.stdout.isTTY && !process.env.DEBUG) {
3
3
  process.stdout.write('\x1B[H\x1B[2J');
4
4
  }
5
5
  };
@@ -18,4 +18,9 @@ export const requireExistModule = (filename, extensions = ['.ts', '.js']) => {
18
18
  }
19
19
 
20
20
  return compatRequire(exist);
21
+ };
22
+ export const cleanRequireCache = filelist => {
23
+ filelist.forEach(filepath => {
24
+ delete require.cache[filepath];
25
+ });
21
26
  };
@@ -1,16 +1,6 @@
1
- /**
2
- * alias to src directory
3
- */
4
- export const INTERNAL_SRC_ALIAS = '@_modern_js_src';
5
- /**
6
- * alias to node_modules/.modern-js
7
- */
8
-
9
- export const INTERNAL_DIR_ALAIS = '@_modern_js_internal';
10
1
  /**
11
2
  * hmr socket connect path
12
3
  */
13
-
14
4
  export const HMR_SOCK_PATH = '/_modern_js_hmr_ws';
15
5
  /**
16
6
  * route specification file
@@ -47,11 +37,6 @@ export const SERVER_RENDER_FUNCTION_NAME = 'serverRender';
47
37
  */
48
38
 
49
39
  export const LOADABLE_STATS_FILE = 'loadable-stats.json';
50
- /**
51
- * real entry generate by modern.js
52
- */
53
-
54
- export const HIDE_MODERN_JS_DIR = './node_modules/.modern-js';
55
40
  /**
56
41
  * internal specified folder
57
42
  */
@@ -133,8 +118,8 @@ export const INTERNAL_PLUGINS = {
133
118
  cli: '@modern-js/plugin-server/cli',
134
119
  server: '@modern-js/plugin-server/server'
135
120
  },
136
- '@modern-js/plugin-micro-frontend': {
137
- cli: '@modern-js/plugin-micro-frontend/cli'
121
+ '@modern-js/plugin-garfish': {
122
+ cli: '@modern-js/plugin-garfish/cli'
138
123
  },
139
124
  '@modern-js/plugin-jarvis': {
140
125
  cli: '@modern-js/plugin-jarvis/cli'
@@ -301,7 +286,7 @@ export const PLUGIN_SCHEMAS = {
301
286
  typeof: ['object', 'function']
302
287
  }
303
288
  }],
304
- '@modern-js/plugin-micro-frontend': [{
289
+ '@modern-js/plugin-garfish': [{
305
290
  target: 'runtime.masterApp',
306
291
  schema: {
307
292
  type: ['object']
@@ -29,4 +29,5 @@ export * from "./prettyInstructions";
29
29
  export * from "./alias";
30
30
  export * from "./import";
31
31
  export * from "./watch";
32
- export * from "./nodeEnv";
32
+ export * from "./nodeEnv";
33
+ export * from "./wait";
@@ -38,13 +38,14 @@ export const prettyInstructions = (appContext, config) => {
38
38
  const {
39
39
  entrypoints,
40
40
  serverRoutes,
41
- port
41
+ port,
42
+ existSrc
42
43
  } = appContext;
43
44
  const urls = getAddressUrls(config.dev.https && isDev() ? 'https' : 'http', port);
44
- const routes = serverRoutes.filter(route => route.entryName);
45
+ const routes = existSrc ? serverRoutes.filter(route => route.entryName) : serverRoutes;
45
46
  let message = 'App running at:\n\n';
46
47
 
47
- if (isSingleEntry(entrypoints)) {
48
+ if (isSingleEntry(entrypoints) || !existSrc) {
48
49
  message += urls.map(({
49
50
  type,
50
51
  url
@@ -0,0 +1,5 @@
1
+ const wait = (time = 0) => new Promise(resolve => {
2
+ setTimeout(resolve, time);
3
+ });
4
+
5
+ export { wait };
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.clearConsole = void 0;
7
7
 
8
8
  const clearConsole = () => {
9
- if (process.stdout.isTTY) {
9
+ if (process.stdout.isTTY && !process.env.DEBUG) {
10
10
  process.stdout.write('\x1B[H\x1B[2J');
11
11
  }
12
12
  };
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.requireExistModule = exports.compatRequire = void 0;
6
+ exports.requireExistModule = exports.compatRequire = exports.cleanRequireCache = void 0;
7
7
 
8
8
  var _findExists = require("./findExists");
9
9
 
@@ -30,4 +30,12 @@ const requireExistModule = (filename, extensions = ['.ts', '.js']) => {
30
30
  return compatRequire(exist);
31
31
  };
32
32
 
33
- exports.requireExistModule = requireExistModule;
33
+ exports.requireExistModule = requireExistModule;
34
+
35
+ const cleanRequireCache = filelist => {
36
+ filelist.forEach(filepath => {
37
+ delete require.cache[filepath];
38
+ });
39
+ };
40
+
41
+ exports.cleanRequireCache = cleanRequireCache;
@@ -3,23 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.SHARED_DIR = exports.SERVER_RENDER_FUNCTION_NAME = exports.SERVER_DIR = exports.SERVER_BUNDLE_DIRECTORY = exports.ROUTE_SPEC_FILE = exports.PLUGIN_SCHEMAS = exports.MAIN_ENTRY_NAME = exports.LOADABLE_STATS_FILE = exports.LAUNCH_EDITOR_ENDPOINT = exports.INTERNAL_SRC_ALIAS = exports.INTERNAL_PLUGINS = exports.INTERNAL_DIR_ALAIS = exports.HMR_SOCK_PATH = exports.HIDE_MODERN_JS_DIR = exports.ENTRY_NAME_PATTERN = exports.API_DIR = void 0;
6
+ exports.SHARED_DIR = exports.SERVER_RENDER_FUNCTION_NAME = exports.SERVER_DIR = exports.SERVER_BUNDLE_DIRECTORY = exports.ROUTE_SPEC_FILE = exports.PLUGIN_SCHEMAS = exports.MAIN_ENTRY_NAME = exports.LOADABLE_STATS_FILE = exports.LAUNCH_EDITOR_ENDPOINT = exports.INTERNAL_PLUGINS = exports.HMR_SOCK_PATH = exports.ENTRY_NAME_PATTERN = exports.API_DIR = void 0;
7
7
 
8
- /**
9
- * alias to src directory
10
- */
11
- const INTERNAL_SRC_ALIAS = '@_modern_js_src';
12
- /**
13
- * alias to node_modules/.modern-js
14
- */
15
-
16
- exports.INTERNAL_SRC_ALIAS = INTERNAL_SRC_ALIAS;
17
- const INTERNAL_DIR_ALAIS = '@_modern_js_internal';
18
8
  /**
19
9
  * hmr socket connect path
20
10
  */
21
-
22
- exports.INTERNAL_DIR_ALAIS = INTERNAL_DIR_ALAIS;
23
11
  const HMR_SOCK_PATH = '/_modern_js_hmr_ws';
24
12
  /**
25
13
  * route specification file
@@ -63,17 +51,11 @@ const SERVER_RENDER_FUNCTION_NAME = 'serverRender';
63
51
 
64
52
  exports.SERVER_RENDER_FUNCTION_NAME = SERVER_RENDER_FUNCTION_NAME;
65
53
  const LOADABLE_STATS_FILE = 'loadable-stats.json';
66
- /**
67
- * real entry generate by modern.js
68
- */
69
-
70
- exports.LOADABLE_STATS_FILE = LOADABLE_STATS_FILE;
71
- const HIDE_MODERN_JS_DIR = './node_modules/.modern-js';
72
54
  /**
73
55
  * internal specified folder
74
56
  */
75
57
 
76
- exports.HIDE_MODERN_JS_DIR = HIDE_MODERN_JS_DIR;
58
+ exports.LOADABLE_STATS_FILE = LOADABLE_STATS_FILE;
77
59
  const API_DIR = 'api';
78
60
  exports.API_DIR = API_DIR;
79
61
  const SERVER_DIR = 'server';
@@ -154,8 +136,8 @@ const INTERNAL_PLUGINS = {
154
136
  cli: '@modern-js/plugin-server/cli',
155
137
  server: '@modern-js/plugin-server/server'
156
138
  },
157
- '@modern-js/plugin-micro-frontend': {
158
- cli: '@modern-js/plugin-micro-frontend/cli'
139
+ '@modern-js/plugin-garfish': {
140
+ cli: '@modern-js/plugin-garfish/cli'
159
141
  },
160
142
  '@modern-js/plugin-jarvis': {
161
143
  cli: '@modern-js/plugin-jarvis/cli'
@@ -323,7 +305,7 @@ const PLUGIN_SCHEMAS = {
323
305
  typeof: ['object', 'function']
324
306
  }
325
307
  }],
326
- '@modern-js/plugin-micro-frontend': [{
308
+ '@modern-js/plugin-garfish': [{
327
309
  target: 'runtime.masterApp',
328
310
  schema: {
329
311
  type: ['object']
@@ -432,6 +432,20 @@ Object.keys(_nodeEnv).forEach(function (key) {
432
432
  });
433
433
  });
434
434
 
435
+ var _wait = require("./wait");
436
+
437
+ Object.keys(_wait).forEach(function (key) {
438
+ if (key === "default" || key === "__esModule") return;
439
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
440
+ if (key in exports && exports[key] === _wait[key]) return;
441
+ Object.defineProperty(exports, key, {
442
+ enumerable: true,
443
+ get: function () {
444
+ return _wait[key];
445
+ }
446
+ });
447
+ });
448
+
435
449
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
436
450
 
437
451
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -52,13 +52,14 @@ const prettyInstructions = (appContext, config) => {
52
52
  const {
53
53
  entrypoints,
54
54
  serverRoutes,
55
- port
55
+ port,
56
+ existSrc
56
57
  } = appContext;
57
58
  const urls = getAddressUrls(config.dev.https && (0, _is.isDev)() ? 'https' : 'http', port);
58
- const routes = serverRoutes.filter(route => route.entryName);
59
+ const routes = existSrc ? serverRoutes.filter(route => route.entryName) : serverRoutes;
59
60
  let message = 'App running at:\n\n';
60
61
 
61
- if (isSingleEntry(entrypoints)) {
62
+ if (isSingleEntry(entrypoints) || !existSrc) {
62
63
  message += urls.map(({
63
64
  type,
64
65
  url
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.wait = void 0;
7
+
8
+ const wait = (time = 0) => new Promise(resolve => {
9
+ setTimeout(resolve, time);
10
+ });
11
+
12
+ exports.wait = wait;
@@ -1,5 +1,5 @@
1
1
  export var clearConsole = function clearConsole() {
2
- if (process.stdout.isTTY) {
2
+ if (process.stdout.isTTY && !process.env.DEBUG) {
3
3
  process.stdout.write('\x1B[H\x1B[2J');
4
4
  }
5
5
  };
@@ -21,4 +21,9 @@ export var requireExistModule = function requireExistModule(filename) {
21
21
  }
22
22
 
23
23
  return compatRequire(exist);
24
+ };
25
+ export var cleanRequireCache = function cleanRequireCache(filelist) {
26
+ filelist.forEach(function (filepath) {
27
+ delete require.cache[filepath];
28
+ });
24
29
  };
@@ -1,18 +1,8 @@
1
1
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
2
 
3
- /**
4
- * alias to src directory
5
- */
6
- export var INTERNAL_SRC_ALIAS = '@_modern_js_src';
7
- /**
8
- * alias to node_modules/.modern-js
9
- */
10
-
11
- export var INTERNAL_DIR_ALAIS = '@_modern_js_internal';
12
3
  /**
13
4
  * hmr socket connect path
14
5
  */
15
-
16
6
  export var HMR_SOCK_PATH = '/_modern_js_hmr_ws';
17
7
  /**
18
8
  * route specification file
@@ -49,11 +39,6 @@ export var SERVER_RENDER_FUNCTION_NAME = 'serverRender';
49
39
  */
50
40
 
51
41
  export var LOADABLE_STATS_FILE = 'loadable-stats.json';
52
- /**
53
- * real entry generate by modern.js
54
- */
55
-
56
- export var HIDE_MODERN_JS_DIR = './node_modules/.modern-js';
57
42
  /**
58
43
  * internal specified folder
59
44
  */
@@ -135,8 +120,8 @@ export var INTERNAL_PLUGINS = {
135
120
  cli: '@modern-js/plugin-server/cli',
136
121
  server: '@modern-js/plugin-server/server'
137
122
  },
138
- '@modern-js/plugin-micro-frontend': {
139
- cli: '@modern-js/plugin-micro-frontend/cli'
123
+ '@modern-js/plugin-garfish': {
124
+ cli: '@modern-js/plugin-garfish/cli'
140
125
  },
141
126
  '@modern-js/plugin-jarvis': {
142
127
  cli: '@modern-js/plugin-jarvis/cli'
@@ -301,7 +286,7 @@ export var PLUGIN_SCHEMAS = {
301
286
  "typeof": ['object', 'function']
302
287
  }
303
288
  }],
304
- '@modern-js/plugin-micro-frontend': [{
289
+ '@modern-js/plugin-garfish': [{
305
290
  target: 'runtime.masterApp',
306
291
  schema: {
307
292
  type: ['object']
@@ -29,4 +29,5 @@ export * from "./prettyInstructions";
29
29
  export * from "./alias";
30
30
  export * from "./import";
31
31
  export * from "./watch";
32
- export * from "./nodeEnv";
32
+ export * from "./nodeEnv";
33
+ export * from "./wait";
@@ -56,14 +56,15 @@ export var prettyInstructions = function prettyInstructions(appContext, config)
56
56
  var _ref = appContext,
57
57
  entrypoints = _ref.entrypoints,
58
58
  serverRoutes = _ref.serverRoutes,
59
- port = _ref.port;
59
+ port = _ref.port,
60
+ existSrc = _ref.existSrc;
60
61
  var urls = getAddressUrls(config.dev.https && isDev() ? 'https' : 'http', port);
61
- var routes = serverRoutes.filter(function (route) {
62
+ var routes = existSrc ? serverRoutes.filter(function (route) {
62
63
  return route.entryName;
63
- });
64
+ }) : serverRoutes;
64
65
  var message = 'App running at:\n\n';
65
66
 
66
- if (isSingleEntry(entrypoints)) {
67
+ if (isSingleEntry(entrypoints) || !existSrc) {
67
68
  message += urls.map(function (_ref2) {
68
69
  var type = _ref2.type,
69
70
  url = _ref2.url;
@@ -0,0 +1,8 @@
1
+ var wait = function wait() {
2
+ var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
3
+ return new Promise(function (resolve) {
4
+ setTimeout(resolve, time);
5
+ });
6
+ };
7
+
8
+ export { wait };
@@ -4,4 +4,5 @@
4
4
  * @returns module export object.
5
5
  */
6
6
  export declare const compatRequire: (filePath: string) => any;
7
- export declare const requireExistModule: (filename: string, extensions?: string[]) => any;
7
+ export declare const requireExistModule: (filename: string, extensions?: string[]) => any;
8
+ export declare const cleanRequireCache: (filelist: string[]) => void;
@@ -1,16 +1,6 @@
1
- /**
2
- * alias to src directory
3
- */
4
- export declare const INTERNAL_SRC_ALIAS = "@_modern_js_src";
5
- /**
6
- * alias to node_modules/.modern-js
7
- */
8
-
9
- export declare const INTERNAL_DIR_ALAIS = "@_modern_js_internal";
10
1
  /**
11
2
  * hmr socket connect path
12
3
  */
13
-
14
4
  export declare const HMR_SOCK_PATH = "/_modern_js_hmr_ws";
15
5
  /**
16
6
  * route specification file
@@ -47,11 +37,6 @@ export declare const SERVER_RENDER_FUNCTION_NAME = "serverRender";
47
37
  */
48
38
 
49
39
  export declare const LOADABLE_STATS_FILE = "loadable-stats.json";
50
- /**
51
- * real entry generate by modern.js
52
- */
53
-
54
- export declare const HIDE_MODERN_JS_DIR = "./node_modules/.modern-js";
55
40
  /**
56
41
  * internal specified folder
57
42
  */
@@ -188,7 +173,7 @@ export declare const PLUGIN_SCHEMAS: {
188
173
  typeof: string[];
189
174
  };
190
175
  }[];
191
- '@modern-js/plugin-micro-frontend': {
176
+ '@modern-js/plugin-garfish': {
192
177
  target: string;
193
178
  schema: {
194
179
  type: string[];
@@ -28,4 +28,5 @@ export * from './prettyInstructions';
28
28
  export * from './alias';
29
29
  export * from './import';
30
30
  export * from './watch';
31
- export * from './nodeEnv';
31
+ export * from './nodeEnv';
32
+ export * from './wait';
@@ -0,0 +1,2 @@
1
+ declare const wait: (time?: number) => Promise<unknown>;
2
+ export { wait };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.2.2",
14
+ "version": "1.3.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -0,0 +1,19 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`prettyInstructions The src directory does not exist 1`] = `
4
+ "App running at:
5
+
6
+ > Network: http://127.0.0.1:8080/api
7
+ > Network: http://11.11.111.11:8080/api
8
+ > Network: http://10.100.100.100:8080/api
9
+ "
10
+ `;
11
+
12
+ exports[`prettyInstructions basic usage 1`] = `
13
+ "App running at:
14
+
15
+ > Network: http://127.0.0.1:8080/
16
+ > Network: http://11.11.111.11:8080/
17
+ > Network: http://10.100.100.100:8080/
18
+ "
19
+ `;
@@ -1,5 +1,5 @@
1
1
  import path from 'path';
2
- import { compatRequire } from '../src/compatRequire';
2
+ import { compatRequire, cleanRequireCache } from '../src/compatRequire';
3
3
 
4
4
  describe('compat require', () => {
5
5
  const fixturePath = path.resolve(__dirname, './fixtures/compat-require');
@@ -19,4 +19,14 @@ describe('compat require', () => {
19
19
  test(`should return null`, () => {
20
20
  expect(compatRequire(path.join(fixturePath, 'empty.js'))).toEqual(null);
21
21
  });
22
+
23
+ test('should clearn cache after fn', () => {
24
+ const foo = module.require('./fixtures/compat-require/foo');
25
+ const requirePath = require.resolve('./fixtures/compat-require/foo.js');
26
+ expect(foo.name).toBe('foo');
27
+ expect(require.cache[requirePath]).toBeDefined();
28
+ cleanRequireCache([requirePath]);
29
+ jest.resetModules();
30
+ expect(require.cache[requirePath]).toBeUndefined();
31
+ });
22
32
  });
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ name: 'foo',
3
+ };
@@ -0,0 +1,139 @@
1
+ import { prettyInstructions } from '../src/prettyInstructions';
2
+
3
+ const mockNetworkInterfaces = {
4
+ lo0: [
5
+ {
6
+ address: '127.0.0.1',
7
+ netmask: '255.0.0.0',
8
+ family: 'IPv4',
9
+ mac: '00:00:00:00:00:00',
10
+ internal: true,
11
+ cidr: '127.0.0.1/8',
12
+ },
13
+ ],
14
+ en5: [
15
+ {
16
+ address: 'fe80::aede:48ff:fe00:1122',
17
+ netmask: 'ffff:ffff:ffff:ffff::',
18
+ family: 'IPv6',
19
+ mac: 'ac:de:48:00:11:22',
20
+ internal: false,
21
+ cidr: 'fe80::aede:48ff:fe00:1122/64',
22
+ scopeid: 4,
23
+ },
24
+ ],
25
+ en0: [
26
+ {
27
+ address: '11.11.111.11',
28
+ netmask: '255.255.252.0',
29
+ family: 'IPv4',
30
+ mac: '90:9c:4a:cf:11:d2',
31
+ internal: false,
32
+ cidr: '10.85.117.60/22',
33
+ },
34
+ ],
35
+ utun2: [
36
+ {
37
+ address: '10.100.100.100',
38
+ netmask: '255.255.224.0',
39
+ family: 'IPv4',
40
+ mac: '00:00:00:00:00:00',
41
+ internal: false,
42
+ cidr: '10.255.182.172/19',
43
+ },
44
+ ],
45
+ };
46
+
47
+ jest.mock('os', () => {
48
+ const originalModule = jest.requireActual('os');
49
+ return {
50
+ __esModule: true,
51
+ ...originalModule,
52
+ default: {
53
+ networkInterfaces() {
54
+ return mockNetworkInterfaces;
55
+ },
56
+ },
57
+ };
58
+ });
59
+
60
+ jest.mock('chalk', () => ({
61
+ __esModule: true,
62
+ default: {
63
+ bold: jest.fn(str => str),
64
+ green: jest.fn(str => str),
65
+ red: jest.fn(str => str),
66
+ yellow: jest.fn(str => str),
67
+ cyanBright: jest.fn(str => str),
68
+ },
69
+ }));
70
+
71
+ describe('prettyInstructions', () => {
72
+ test('basic usage', () => {
73
+ const mockAppContext = {
74
+ entrypoints: [
75
+ {
76
+ entryName: 'main',
77
+ entry: '/example/node_modules/.modern-js/main/index.js',
78
+ isAutoMount: true,
79
+ customBootstrap: false,
80
+ },
81
+ ],
82
+ serverRoutes: [
83
+ {
84
+ urlPath: '/',
85
+ entryName: 'main',
86
+ entryPath: 'html/main/index.html',
87
+ isSPA: true,
88
+ isSSR: false,
89
+ enableModernMode: false,
90
+ },
91
+ {
92
+ urlPath: '/api',
93
+ isApi: true,
94
+ entryPath: '',
95
+ isSPA: false,
96
+ isSSR: false,
97
+ },
98
+ ],
99
+ port: 8080,
100
+ existSrc: true,
101
+ };
102
+ const mockConfig = {
103
+ dev: {
104
+ https: true,
105
+ },
106
+ };
107
+
108
+ const message = prettyInstructions(mockAppContext, mockConfig);
109
+
110
+ expect(message).toMatchSnapshot();
111
+ });
112
+
113
+ test('The src directory does not exist', () => {
114
+ const mockAppContext = {
115
+ entrypoints: [],
116
+ serverRoutes: [
117
+ {
118
+ urlPath: '/api',
119
+ isApi: true,
120
+ entryPath: '',
121
+ isSPA: false,
122
+ isSSR: false,
123
+ },
124
+ ],
125
+ port: 8080,
126
+ existSrc: false,
127
+ };
128
+
129
+ const mockConfig = {
130
+ dev: {
131
+ https: true,
132
+ },
133
+ };
134
+
135
+ const message = prettyInstructions(mockAppContext, mockConfig);
136
+
137
+ expect(message).toMatchSnapshot();
138
+ });
139
+ });
package/tests/wait.ts ADDED
@@ -0,0 +1,38 @@
1
+ import { wait } from '../src/wait';
2
+
3
+ jest.useRealTimers();
4
+
5
+ describe('wait', () => {
6
+ test('basic usage', async () => {
7
+ const fn1 = jest.fn();
8
+ const fn2 = jest.fn();
9
+ const fn3 = async () => {
10
+ fn1();
11
+ await wait();
12
+ fn2();
13
+ };
14
+
15
+ fn3();
16
+ expect(fn1).toBeCalled();
17
+ expect(fn2).not.toBeCalled();
18
+ await wait();
19
+ expect(fn2).toBeCalled();
20
+ });
21
+
22
+ test('delay', async () => {
23
+ const fn1 = jest.fn();
24
+ const fn2 = jest.fn();
25
+ const time = 100;
26
+ const fn3 = async () => {
27
+ fn1();
28
+ await wait(time);
29
+ fn2();
30
+ };
31
+
32
+ fn3();
33
+ expect(fn1).toBeCalled();
34
+ expect(fn2).not.toBeCalled();
35
+ await wait(time);
36
+ expect(fn2).toBeCalled();
37
+ });
38
+ });