@modern-js/plugin-testing 1.0.0-rc.2
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.
- package/LICENSE +21 -0
- package/README.md +32 -0
- package/dist/js/modern/cli/index.js +43 -0
- package/dist/js/modern/cli/plugins/modern.js +44 -0
- package/dist/js/modern/cli/resolver.js +15 -0
- package/dist/js/modern/cli/test.js +43 -0
- package/dist/js/modern/constant.js +1 -0
- package/dist/js/modern/index.js +2 -0
- package/dist/js/modern/runtime-testing/app.js +51 -0
- package/dist/js/modern/runtime-testing/customRender.js +17 -0
- package/dist/js/modern/runtime-testing/index.js +2 -0
- package/dist/js/modern/runtime-testing/resolvePlugins.js +23 -0
- package/dist/js/node/cli/index.js +59 -0
- package/dist/js/node/cli/plugins/modern.js +59 -0
- package/dist/js/node/cli/resolver.js +20 -0
- package/dist/js/node/cli/test.js +60 -0
- package/dist/js/node/constant.js +8 -0
- package/dist/js/node/index.js +20 -0
- package/dist/js/node/runtime-testing/app.js +64 -0
- package/dist/js/node/runtime-testing/customRender.js +29 -0
- package/dist/js/node/runtime-testing/index.js +32 -0
- package/dist/js/node/runtime-testing/resolvePlugins.js +31 -0
- package/dist/js/treeshaking/cli/index.js +54 -0
- package/dist/js/treeshaking/cli/plugins/modern.js +47 -0
- package/dist/js/treeshaking/cli/resolver.js +17 -0
- package/dist/js/treeshaking/cli/test.js +78 -0
- package/dist/js/treeshaking/constant.js +1 -0
- package/dist/js/treeshaking/index.js +2 -0
- package/dist/js/treeshaking/runtime-testing/app.js +64 -0
- package/dist/js/treeshaking/runtime-testing/customRender.js +21 -0
- package/dist/js/treeshaking/runtime-testing/index.js +2 -0
- package/dist/js/treeshaking/runtime-testing/resolvePlugins.js +23 -0
- package/dist/types/cli/index.d.ts +3 -0
- package/dist/types/cli/plugins/modern.d.ts +3 -0
- package/dist/types/cli/resolver.d.ts +1 -0
- package/dist/types/cli/test.d.ts +8 -0
- package/dist/types/constant.d.ts +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/runtime-testing/app.d.ts +17 -0
- package/dist/types/runtime-testing/customRender.d.ts +5 -0
- package/dist/types/runtime-testing/index.d.ts +2 -0
- package/dist/types/runtime-testing/resolvePlugins.d.ts +2 -0
- package/modern.config.js +2 -0
- package/package.json +44 -0
- package/src/.eslintrc.json +3 -0
- package/src/cli/index.ts +48 -0
- package/src/cli/plugins/modern.ts +50 -0
- package/src/cli/resolver.ts +16 -0
- package/src/cli/test.ts +66 -0
- package/src/constant.ts +1 -0
- package/src/index.ts +3 -0
- package/src/runtime-testing/app.ts +48 -0
- package/src/runtime-testing/customRender.ts +11 -0
- package/src/runtime-testing/index.ts +3 -0
- package/src/runtime-testing/resolvePlugins.ts +23 -0
- package/tsconfig.json +12 -0
- package/type.d.ts +4 -0
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021 Modern.js
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
<p align="center">
|
3
|
+
<a href="https://modernjs.dev" target="blank"><img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs.png" width="300" alt="Modern.js Logo" /></a>
|
4
|
+
</p>
|
5
|
+
|
6
|
+
<p align="center">现代 Web 工程体系</p>
|
7
|
+
|
8
|
+
## 背景
|
9
|
+
- [迈入现代 Web 开发](https://zhuanlan.zhihu.com/p/386607009)
|
10
|
+
- [现代 Web 开发者问卷调查报告](https://zhuanlan.zhihu.com/p/403206195)
|
11
|
+
|
12
|
+
## 计划
|
13
|
+
|
14
|
+
Modern.js 的 1.0.0.rc 版已经发到 npm,目前在做测试改进,README 文档之后统一提供(现阶段加入测试和开发,可以发 [issue](https://github.com/modern-js-dev/modern.js/issues) 留微信联系),完整的文档站计划在10月14日上线
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import path from 'path';
|
2
|
+
import { createPlugin, useAppContext } from '@modern-js/core';
|
3
|
+
import { createRuntimeExportsUtils, PLUGIN_SCHEMAS } from '@modern-js/utils';
|
4
|
+
import test from "./test";
|
5
|
+
export default createPlugin(() => {
|
6
|
+
let testingExportsUtils;
|
7
|
+
return {
|
8
|
+
commands: ({
|
9
|
+
program
|
10
|
+
}) => {
|
11
|
+
program.command('test').allowUnknownOption().usage('[options]').action(async () => {
|
12
|
+
await test();
|
13
|
+
});
|
14
|
+
},
|
15
|
+
|
16
|
+
validateSchema() {
|
17
|
+
return PLUGIN_SCHEMAS['@modern-js/plugin-testing'];
|
18
|
+
},
|
19
|
+
|
20
|
+
config() {
|
21
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
22
|
+
const {
|
23
|
+
value: appContext
|
24
|
+
} = useAppContext();
|
25
|
+
testingExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, 'testing');
|
26
|
+
return {
|
27
|
+
source: {
|
28
|
+
alias: {
|
29
|
+
'@modern-js/runtime/testing': testingExportsUtils.getPath()
|
30
|
+
}
|
31
|
+
}
|
32
|
+
};
|
33
|
+
},
|
34
|
+
|
35
|
+
addRuntimeExports() {
|
36
|
+
const testingPath = path.resolve(__dirname, '../');
|
37
|
+
testingExportsUtils.addExport(`export * from '${testingPath}'`);
|
38
|
+
}
|
39
|
+
|
40
|
+
};
|
41
|
+
}, {
|
42
|
+
name: '@modern-js/plugin-testing'
|
43
|
+
});
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import path from 'path';
|
2
|
+
import { createPlugin } from '@modern-js/testing';
|
3
|
+
import { modernjs_config_key } from "../../constant";
|
4
|
+
|
5
|
+
const getModuleNameMapper = config => {
|
6
|
+
const {
|
7
|
+
resolve: {
|
8
|
+
alias = {}
|
9
|
+
}
|
10
|
+
} = config;
|
11
|
+
return Object.keys(alias).reduce((memo, cur) => {
|
12
|
+
const aliasValue = Array.isArray(alias[cur]) ? alias[cur] : [alias[cur]];
|
13
|
+
const isFile = aliasValue.some(s => s.endsWith('.js'));
|
14
|
+
|
15
|
+
if (isFile) {
|
16
|
+
memo[cur] = aliasValue[0];
|
17
|
+
}
|
18
|
+
|
19
|
+
const key = `^${cur}/(.*)$`;
|
20
|
+
const value = path.normalize(`${aliasValue}/$1`);
|
21
|
+
memo[key] = value;
|
22
|
+
return memo;
|
23
|
+
}, {});
|
24
|
+
};
|
25
|
+
|
26
|
+
export default ((webpackConfig, userConfig, pwd) => createPlugin(() => ({
|
27
|
+
jestConfig: (utils, next) => {
|
28
|
+
utils.mergeJestConfig({
|
29
|
+
globals: {
|
30
|
+
[modernjs_config_key]: userConfig
|
31
|
+
},
|
32
|
+
moduleNameMapper: getModuleNameMapper(webpackConfig),
|
33
|
+
testEnvironment: 'jsdom',
|
34
|
+
resolver: require.resolve("../resolver")
|
35
|
+
});
|
36
|
+
utils.setJestConfig({
|
37
|
+
// todo: diffrent test root for diffrent solutions
|
38
|
+
testMatch: [`${pwd || process.cwd()}/(src|tests|api)/**/*.test.[jt]s?(x)`]
|
39
|
+
});
|
40
|
+
return next(utils);
|
41
|
+
}
|
42
|
+
}), {
|
43
|
+
name: '@modern-js/testing-plugin-modern'
|
44
|
+
}));
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import enhanceResolve from 'enhanced-resolve';
|
2
|
+
const resolver = enhanceResolve.create.sync({
|
3
|
+
conditionNames: ['require', 'node', 'default'],
|
4
|
+
extensions: ['.js', '.json', '.node', '.ts', '.tsx']
|
5
|
+
});
|
6
|
+
|
7
|
+
const shouldResolveByEnhance = url => /^@[^/]+\/[^/]+\/.*/.test(url);
|
8
|
+
|
9
|
+
module.exports = function (request, options) {
|
10
|
+
if (shouldResolveByEnhance(request)) {
|
11
|
+
return resolver(options.basedir, request);
|
12
|
+
}
|
13
|
+
|
14
|
+
return options.defaultResolver(request, options);
|
15
|
+
};
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import path from 'path';
|
2
|
+
import { compiler } from '@modern-js/babel-compiler';
|
3
|
+
import { useAppContext, useResolvedConfigContext } from '@modern-js/core';
|
4
|
+
import { runTest } from '@modern-js/testing';
|
5
|
+
import { getWebpackConfig, WebpackConfigTarget } from '@modern-js/webpack'; // import testingBffPlugin from '@modern-js/testing-plugin-bff';
|
6
|
+
|
7
|
+
import modernTestPlugin from "./plugins/modern";
|
8
|
+
|
9
|
+
const test = async () => {
|
10
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
11
|
+
const {
|
12
|
+
value: userConfig
|
13
|
+
} = useResolvedConfigContext(); // eslint-disable-next-line react-hooks/rules-of-hooks
|
14
|
+
|
15
|
+
const {
|
16
|
+
value: config
|
17
|
+
} = useAppContext(); // todo: consider lib-tools ...
|
18
|
+
|
19
|
+
const webpackConfigs = getWebpackConfig(WebpackConfigTarget.CLIENT);
|
20
|
+
userConfig.testing = userConfig.testing || {};
|
21
|
+
userConfig.testing.jest = userConfig.testing.jest || userConfig.tools.jest;
|
22
|
+
userConfig.testing.plugins = [...(userConfig.testing.plugins || []), modernTestPlugin(webpackConfigs, userConfig, config.appDirectory) // testingBffPlugin({
|
23
|
+
// pwd: config.appDirectory,
|
24
|
+
// userConfig: userConfig,
|
25
|
+
// plugins: config.plugins.map(p => p.server).filter(Boolean),
|
26
|
+
// routes: (config as any).serverRoutes
|
27
|
+
// }),
|
28
|
+
];
|
29
|
+
const runtimeExportsPath = path.join(config.internalDirectory, '.runtime-exports');
|
30
|
+
await compiler({
|
31
|
+
sourceDir: runtimeExportsPath,
|
32
|
+
rootDir: runtimeExportsPath,
|
33
|
+
distDir: runtimeExportsPath,
|
34
|
+
quiet: true
|
35
|
+
}, {
|
36
|
+
presets: [[require.resolve('@babel/preset-env'), {
|
37
|
+
modules: 'cjs'
|
38
|
+
}]]
|
39
|
+
});
|
40
|
+
await runTest(userConfig.testing);
|
41
|
+
};
|
42
|
+
|
43
|
+
export default test;
|
@@ -0,0 +1 @@
|
|
1
|
+
export const modernjs_config_key = '__modernjs_config__';
|
@@ -0,0 +1,51 @@
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
2
|
+
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
4
|
+
|
5
|
+
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; }
|
6
|
+
|
7
|
+
import { createApp } from '@modern-js/runtime-core';
|
8
|
+
import resolvePlugins from "./resolvePlugins";
|
9
|
+
import { modernjs_config_key } from "../constant";
|
10
|
+
|
11
|
+
class ModernRuntime {
|
12
|
+
constructor(options) {
|
13
|
+
this.options = void 0;
|
14
|
+
this.options = options;
|
15
|
+
}
|
16
|
+
|
17
|
+
init(options) {
|
18
|
+
this.options = options;
|
19
|
+
}
|
20
|
+
|
21
|
+
createApp(props) {
|
22
|
+
var _this$options;
|
23
|
+
|
24
|
+
const {
|
25
|
+
entry,
|
26
|
+
children
|
27
|
+
} = props || {};
|
28
|
+
let runtimeFeatures = (_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.runtime;
|
29
|
+
|
30
|
+
if (entry) {
|
31
|
+
var _this$options$runtime;
|
32
|
+
|
33
|
+
runtimeFeatures = _objectSpread(_objectSpread({}, runtimeFeatures || {}), (_this$options$runtime = this.options.runtimeByEntries) === null || _this$options$runtime === void 0 ? void 0 : _this$options$runtime[entry]);
|
34
|
+
}
|
35
|
+
|
36
|
+
const Component = () => {
|
37
|
+
if (!children) {
|
38
|
+
return null;
|
39
|
+
}
|
40
|
+
|
41
|
+
return children;
|
42
|
+
};
|
43
|
+
|
44
|
+
return createApp({
|
45
|
+
plugins: resolvePlugins(runtimeFeatures || {})
|
46
|
+
})(Component);
|
47
|
+
}
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
export default new ModernRuntime(global[modernjs_config_key] || {});
|
@@ -0,0 +1,17 @@
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
2
|
+
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
4
|
+
|
5
|
+
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; }
|
6
|
+
|
7
|
+
import React from 'react';
|
8
|
+
import { render } from '@testing-library/react';
|
9
|
+
import app from "./app";
|
10
|
+
|
11
|
+
const WrapModernProviders = props => /*#__PURE__*/React.createElement(app.createApp(props));
|
12
|
+
|
13
|
+
const customRender = (ui, options) => render(ui, _objectSpread({
|
14
|
+
wrapper: WrapModernProviders
|
15
|
+
}, options));
|
16
|
+
|
17
|
+
export default customRender;
|
@@ -0,0 +1,23 @@
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
2
|
+
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
4
|
+
|
5
|
+
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; }
|
6
|
+
|
7
|
+
const allowedFeatures = ['router', 'state'];
|
8
|
+
export default function resolvePlugins(features) {
|
9
|
+
const plugins = [];
|
10
|
+
|
11
|
+
if (!features) {
|
12
|
+
return plugins;
|
13
|
+
}
|
14
|
+
|
15
|
+
Object.keys(features).forEach(feature => {
|
16
|
+
if (allowedFeatures.includes(feature)) {
|
17
|
+
const curPluginRes = require(`@modern-js/runtime/plugins`)[feature](_objectSpread({}, features[feature]));
|
18
|
+
|
19
|
+
plugins.push(curPluginRes);
|
20
|
+
}
|
21
|
+
});
|
22
|
+
return plugins;
|
23
|
+
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
9
|
+
|
10
|
+
var _core = require("@modern-js/core");
|
11
|
+
|
12
|
+
var _utils = require("@modern-js/utils");
|
13
|
+
|
14
|
+
var _test = _interopRequireDefault(require("./test"));
|
15
|
+
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
|
+
|
18
|
+
var _default = (0, _core.createPlugin)(() => {
|
19
|
+
let testingExportsUtils;
|
20
|
+
return {
|
21
|
+
commands: ({
|
22
|
+
program
|
23
|
+
}) => {
|
24
|
+
program.command('test').allowUnknownOption().usage('[options]').action(async () => {
|
25
|
+
await (0, _test.default)();
|
26
|
+
});
|
27
|
+
},
|
28
|
+
|
29
|
+
validateSchema() {
|
30
|
+
return _utils.PLUGIN_SCHEMAS['@modern-js/plugin-testing'];
|
31
|
+
},
|
32
|
+
|
33
|
+
config() {
|
34
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
35
|
+
const {
|
36
|
+
value: appContext
|
37
|
+
} = (0, _core.useAppContext)();
|
38
|
+
testingExportsUtils = (0, _utils.createRuntimeExportsUtils)(appContext.internalDirectory, 'testing');
|
39
|
+
return {
|
40
|
+
source: {
|
41
|
+
alias: {
|
42
|
+
'@modern-js/runtime/testing': testingExportsUtils.getPath()
|
43
|
+
}
|
44
|
+
}
|
45
|
+
};
|
46
|
+
},
|
47
|
+
|
48
|
+
addRuntimeExports() {
|
49
|
+
const testingPath = _path.default.resolve(__dirname, '../');
|
50
|
+
|
51
|
+
testingExportsUtils.addExport(`export * from '${testingPath}'`);
|
52
|
+
}
|
53
|
+
|
54
|
+
};
|
55
|
+
}, {
|
56
|
+
name: '@modern-js/plugin-testing'
|
57
|
+
});
|
58
|
+
|
59
|
+
exports.default = _default;
|
@@ -0,0 +1,59 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
9
|
+
|
10
|
+
var _testing = require("@modern-js/testing");
|
11
|
+
|
12
|
+
var _constant = require("../../constant");
|
13
|
+
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
|
+
|
16
|
+
const getModuleNameMapper = config => {
|
17
|
+
const {
|
18
|
+
resolve: {
|
19
|
+
alias = {}
|
20
|
+
}
|
21
|
+
} = config;
|
22
|
+
return Object.keys(alias).reduce((memo, cur) => {
|
23
|
+
const aliasValue = Array.isArray(alias[cur]) ? alias[cur] : [alias[cur]];
|
24
|
+
const isFile = aliasValue.some(s => s.endsWith('.js'));
|
25
|
+
|
26
|
+
if (isFile) {
|
27
|
+
memo[cur] = aliasValue[0];
|
28
|
+
}
|
29
|
+
|
30
|
+
const key = `^${cur}/(.*)$`;
|
31
|
+
|
32
|
+
const value = _path.default.normalize(`${aliasValue}/$1`);
|
33
|
+
|
34
|
+
memo[key] = value;
|
35
|
+
return memo;
|
36
|
+
}, {});
|
37
|
+
};
|
38
|
+
|
39
|
+
var _default = (webpackConfig, userConfig, pwd) => (0, _testing.createPlugin)(() => ({
|
40
|
+
jestConfig: (utils, next) => {
|
41
|
+
utils.mergeJestConfig({
|
42
|
+
globals: {
|
43
|
+
[_constant.modernjs_config_key]: userConfig
|
44
|
+
},
|
45
|
+
moduleNameMapper: getModuleNameMapper(webpackConfig),
|
46
|
+
testEnvironment: 'jsdom',
|
47
|
+
resolver: require.resolve("../resolver")
|
48
|
+
});
|
49
|
+
utils.setJestConfig({
|
50
|
+
// todo: diffrent test root for diffrent solutions
|
51
|
+
testMatch: [`${pwd || process.cwd()}/(src|tests|api)/**/*.test.[jt]s?(x)`]
|
52
|
+
});
|
53
|
+
return next(utils);
|
54
|
+
}
|
55
|
+
}), {
|
56
|
+
name: '@modern-js/testing-plugin-modern'
|
57
|
+
});
|
58
|
+
|
59
|
+
exports.default = _default;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _enhancedResolve = _interopRequireDefault(require("enhanced-resolve"));
|
4
|
+
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
6
|
+
|
7
|
+
const resolver = _enhancedResolve.default.create.sync({
|
8
|
+
conditionNames: ['require', 'node', 'default'],
|
9
|
+
extensions: ['.js', '.json', '.node', '.ts', '.tsx']
|
10
|
+
});
|
11
|
+
|
12
|
+
const shouldResolveByEnhance = url => /^@[^/]+\/[^/]+\/.*/.test(url);
|
13
|
+
|
14
|
+
module.exports = function (request, options) {
|
15
|
+
if (shouldResolveByEnhance(request)) {
|
16
|
+
return resolver(options.basedir, request);
|
17
|
+
}
|
18
|
+
|
19
|
+
return options.defaultResolver(request, options);
|
20
|
+
};
|
@@ -0,0 +1,60 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
9
|
+
|
10
|
+
var _babelCompiler = require("@modern-js/babel-compiler");
|
11
|
+
|
12
|
+
var _core = require("@modern-js/core");
|
13
|
+
|
14
|
+
var _testing = require("@modern-js/testing");
|
15
|
+
|
16
|
+
var _webpack = require("@modern-js/webpack");
|
17
|
+
|
18
|
+
var _modern = _interopRequireDefault(require("./plugins/modern"));
|
19
|
+
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
21
|
+
|
22
|
+
// import testingBffPlugin from '@modern-js/testing-plugin-bff';
|
23
|
+
const test = async () => {
|
24
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
25
|
+
const {
|
26
|
+
value: userConfig
|
27
|
+
} = (0, _core.useResolvedConfigContext)(); // eslint-disable-next-line react-hooks/rules-of-hooks
|
28
|
+
|
29
|
+
const {
|
30
|
+
value: config
|
31
|
+
} = (0, _core.useAppContext)(); // todo: consider lib-tools ...
|
32
|
+
|
33
|
+
const webpackConfigs = (0, _webpack.getWebpackConfig)(_webpack.WebpackConfigTarget.CLIENT);
|
34
|
+
userConfig.testing = userConfig.testing || {};
|
35
|
+
userConfig.testing.jest = userConfig.testing.jest || userConfig.tools.jest;
|
36
|
+
userConfig.testing.plugins = [...(userConfig.testing.plugins || []), (0, _modern.default)(webpackConfigs, userConfig, config.appDirectory) // testingBffPlugin({
|
37
|
+
// pwd: config.appDirectory,
|
38
|
+
// userConfig: userConfig,
|
39
|
+
// plugins: config.plugins.map(p => p.server).filter(Boolean),
|
40
|
+
// routes: (config as any).serverRoutes
|
41
|
+
// }),
|
42
|
+
];
|
43
|
+
|
44
|
+
const runtimeExportsPath = _path.default.join(config.internalDirectory, '.runtime-exports');
|
45
|
+
|
46
|
+
await (0, _babelCompiler.compiler)({
|
47
|
+
sourceDir: runtimeExportsPath,
|
48
|
+
rootDir: runtimeExportsPath,
|
49
|
+
distDir: runtimeExportsPath,
|
50
|
+
quiet: true
|
51
|
+
}, {
|
52
|
+
presets: [[require.resolve('@babel/preset-env'), {
|
53
|
+
modules: 'cjs'
|
54
|
+
}]]
|
55
|
+
});
|
56
|
+
await (0, _testing.runTest)(userConfig.testing);
|
57
|
+
};
|
58
|
+
|
59
|
+
var _default = test;
|
60
|
+
exports.default = _default;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
|
7
|
+
require("@testing-library/jest-dom/extend-expect");
|
8
|
+
|
9
|
+
var _runtimeTesting = require("./runtime-testing");
|
10
|
+
|
11
|
+
Object.keys(_runtimeTesting).forEach(function (key) {
|
12
|
+
if (key === "default" || key === "__esModule") return;
|
13
|
+
if (key in exports && exports[key] === _runtimeTesting[key]) return;
|
14
|
+
Object.defineProperty(exports, key, {
|
15
|
+
enumerable: true,
|
16
|
+
get: function () {
|
17
|
+
return _runtimeTesting[key];
|
18
|
+
}
|
19
|
+
});
|
20
|
+
});
|
@@ -0,0 +1,64 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _runtimeCore = require("@modern-js/runtime-core");
|
9
|
+
|
10
|
+
var _resolvePlugins = _interopRequireDefault(require("./resolvePlugins"));
|
11
|
+
|
12
|
+
var _constant = require("../constant");
|
13
|
+
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
|
+
|
16
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
17
|
+
|
18
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
19
|
+
|
20
|
+
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; }
|
21
|
+
|
22
|
+
class ModernRuntime {
|
23
|
+
constructor(options) {
|
24
|
+
this.options = void 0;
|
25
|
+
this.options = options;
|
26
|
+
}
|
27
|
+
|
28
|
+
init(options) {
|
29
|
+
this.options = options;
|
30
|
+
}
|
31
|
+
|
32
|
+
createApp(props) {
|
33
|
+
var _this$options;
|
34
|
+
|
35
|
+
const {
|
36
|
+
entry,
|
37
|
+
children
|
38
|
+
} = props || {};
|
39
|
+
let runtimeFeatures = (_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.runtime;
|
40
|
+
|
41
|
+
if (entry) {
|
42
|
+
var _this$options$runtime;
|
43
|
+
|
44
|
+
runtimeFeatures = _objectSpread(_objectSpread({}, runtimeFeatures || {}), (_this$options$runtime = this.options.runtimeByEntries) === null || _this$options$runtime === void 0 ? void 0 : _this$options$runtime[entry]);
|
45
|
+
}
|
46
|
+
|
47
|
+
const Component = () => {
|
48
|
+
if (!children) {
|
49
|
+
return null;
|
50
|
+
}
|
51
|
+
|
52
|
+
return children;
|
53
|
+
};
|
54
|
+
|
55
|
+
return (0, _runtimeCore.createApp)({
|
56
|
+
plugins: (0, _resolvePlugins.default)(runtimeFeatures || {})
|
57
|
+
})(Component);
|
58
|
+
}
|
59
|
+
|
60
|
+
}
|
61
|
+
|
62
|
+
var _default = new ModernRuntime(global[_constant.modernjs_config_key] || {});
|
63
|
+
|
64
|
+
exports.default = _default;
|
@@ -0,0 +1,29 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
9
|
+
|
10
|
+
var _react2 = require("@testing-library/react");
|
11
|
+
|
12
|
+
var _app = _interopRequireDefault(require("./app"));
|
13
|
+
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
|
+
|
16
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
17
|
+
|
18
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
19
|
+
|
20
|
+
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; }
|
21
|
+
|
22
|
+
const WrapModernProviders = props => /*#__PURE__*/_react.default.createElement(_app.default.createApp(props));
|
23
|
+
|
24
|
+
const customRender = (ui, options) => (0, _react2.render)(ui, _objectSpread({
|
25
|
+
wrapper: WrapModernProviders
|
26
|
+
}, options));
|
27
|
+
|
28
|
+
var _default = customRender;
|
29
|
+
exports.default = _default;
|
@@ -0,0 +1,32 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
var _exportNames = {
|
7
|
+
renderApp: true
|
8
|
+
};
|
9
|
+
Object.defineProperty(exports, "renderApp", {
|
10
|
+
enumerable: true,
|
11
|
+
get: function () {
|
12
|
+
return _customRender.default;
|
13
|
+
}
|
14
|
+
});
|
15
|
+
|
16
|
+
var _customRender = _interopRequireDefault(require("./customRender"));
|
17
|
+
|
18
|
+
var _react = require("@testing-library/react");
|
19
|
+
|
20
|
+
Object.keys(_react).forEach(function (key) {
|
21
|
+
if (key === "default" || key === "__esModule") return;
|
22
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
23
|
+
if (key in exports && exports[key] === _react[key]) return;
|
24
|
+
Object.defineProperty(exports, key, {
|
25
|
+
enumerable: true,
|
26
|
+
get: function () {
|
27
|
+
return _react[key];
|
28
|
+
}
|
29
|
+
});
|
30
|
+
});
|
31
|
+
|
32
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|