@modern-js/plugin-testing 1.5.0 → 1.5.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.
package/.eslintrc.js CHANGED
@@ -1,7 +1,9 @@
1
1
  module.exports = {
2
+ root: true,
2
3
  extends: ['@modern-js'],
3
4
  parserOptions: {
4
- project: require.resolve('./tsconfig.json'),
5
+ tsconfigRootDir: __dirname,
6
+ project: ['./tsconfig.json'],
5
7
  },
6
- ignorePatterns: ['type.d.ts'],
8
+ ignorePatterns: ['types'],
7
9
  };
package/CHANGELOG.md CHANGED
@@ -1,5 +1,55 @@
1
1
  # @modern-js/plugin-testing
2
2
 
3
+ ## 1.5.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 3f209269: feat(testing): add `afterTest` hook for testing plugin
8
+ - Updated dependencies [4697d1db]
9
+ - Updated dependencies [0ee4bb4e]
10
+ - Updated dependencies [6fa74d5f]
11
+ - Updated dependencies [3f209269]
12
+ - @modern-js/webpack@1.6.0
13
+ - @modern-js/testing@1.5.0
14
+ - @modern-js/utils@1.7.0
15
+ - @modern-js/runtime-core@1.4.4
16
+ - @modern-js/testing-plugin-bff@1.4.1
17
+
18
+ ## 1.5.1
19
+
20
+ ### Patch Changes
21
+
22
+ - 6c1438d2: fix: missing peer deps warnings
23
+ - 77519490: refactor(webpack): remove `@modern-js/core`
24
+ - 50f351b2: fix:
25
+
26
+ 1. plugin-testing types
27
+ 2. `tools.jest` not working when combined with bff testing
28
+
29
+ - Updated dependencies [2d155c4c]
30
+ - Updated dependencies [a0475f1a]
31
+ - Updated dependencies [123e432d]
32
+ - Updated dependencies [6c1438d2]
33
+ - Updated dependencies [e5a9b26d]
34
+ - Updated dependencies [0b26b93b]
35
+ - Updated dependencies [123e432d]
36
+ - Updated dependencies [f9f66ef9]
37
+ - Updated dependencies [71526621]
38
+ - Updated dependencies [77519490]
39
+ - Updated dependencies [592edabc]
40
+ - Updated dependencies [3578716a]
41
+ - Updated dependencies [895fa0ff]
42
+ - Updated dependencies [3d1fac2a]
43
+ - Updated dependencies [3578913e]
44
+ - Updated dependencies [50f351b2]
45
+ - Updated dependencies [1c3beab3]
46
+ - @modern-js/utils@1.6.0
47
+ - @modern-js/webpack@1.5.7
48
+ - @modern-js/testing@1.4.4
49
+ - @modern-js/bff-utils@1.2.4
50
+ - @modern-js/testing-plugin-bff@1.4.1
51
+ - @modern-js/runtime-core@1.4.3
52
+
3
53
  ## 1.5.0
4
54
 
5
55
  ### Minor Changes
@@ -1,20 +1,16 @@
1
1
  import path from 'path';
2
2
  import { PLUGIN_SCHEMAS, createRuntimeExportsUtils, isApiOnly } from '@modern-js/utils';
3
- import { jestConfigHook, getModuleNameMapper, DEFAULT_RESOLVER_PATH } from '@modern-js/testing';
3
+ import { testingHooks, getModuleNameMapper, DEFAULT_RESOLVER_PATH } from '@modern-js/testing';
4
4
  import { getWebpackConfig, WebpackConfigTarget } from '@modern-js/webpack';
5
5
  import TestingBffPlugin from '@modern-js/testing-plugin-bff';
6
6
  import { MODERNJS_CONFIG_KEY } from "../constant";
7
7
  import test from "./test";
8
8
  export const mergeUserJestConfig = testUtils => {
9
- const resolveJestConfig = testUtils.testConfig.jest;
9
+ const resolveJestConfig = testUtils.testConfig.jest; // resolveJestConfig 如果是函数类型,在所有测试插件 jestConfig 都执行后,再执行生成最终配置
10
10
 
11
11
  if (resolveJestConfig && typeof resolveJestConfig !== 'function') {
12
12
  testUtils.mergeJestConfig(resolveJestConfig);
13
13
  }
14
-
15
- if (typeof resolveJestConfig === 'function') {
16
- resolveJestConfig(testUtils.jestConfig);
17
- }
18
14
  };
19
15
  export default (() => {
20
16
  const BffPlugin = TestingBffPlugin();
@@ -22,18 +18,14 @@ export default (() => {
22
18
  name: '@modern-js/plugin-testing',
23
19
  usePlugins: [BffPlugin],
24
20
  post: [BffPlugin.name],
25
- registerHook: {
26
- jestConfig: jestConfigHook
27
- },
21
+ registerHook: testingHooks,
28
22
  setup: api => {
29
23
  let testingExportsUtils;
30
- const appContext = api.useAppContext();
31
- const userConfig = api.useResolvedConfigContext();
32
24
  return {
33
25
  commands: ({
34
26
  program
35
27
  }) => {
36
- program.command('test').allowUnknownOption().usage('[options]').action(async () => {
28
+ program.command('test').allowUnknownOption().usage('<regexForTestFiles> --[options]').action(async () => {
37
29
  await test(api);
38
30
  });
39
31
  },
@@ -43,6 +35,7 @@ export default (() => {
43
35
  },
44
36
 
45
37
  config() {
38
+ const appContext = api.useAppContext();
46
39
  testingExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, 'testing');
47
40
  return {
48
41
  source: {
@@ -59,13 +52,15 @@ export default (() => {
59
52
  },
60
53
 
61
54
  jestConfig: async (utils, next) => {
62
- const apiOnly = await isApiOnly(appContext.srcDirectory);
55
+ const appContext = api.useAppContext();
56
+ const userConfig = api.useResolvedConfigContext();
57
+ const apiOnly = await isApiOnly(appContext.appDirectory);
63
58
 
64
59
  if (apiOnly) {
65
60
  return next(utils);
66
61
  }
67
62
 
68
- const webpackConfig = getWebpackConfig(WebpackConfigTarget.CLIENT);
63
+ const webpackConfig = getWebpackConfig(WebpackConfigTarget.CLIENT, appContext, userConfig);
69
64
  const {
70
65
  resolve: {
71
66
  alias = {}
@@ -77,9 +72,7 @@ export default (() => {
77
72
  },
78
73
  moduleNameMapper: getModuleNameMapper(alias),
79
74
  testEnvironment: 'jsdom',
80
- resolver: DEFAULT_RESOLVER_PATH
81
- });
82
- utils.setJestConfig({
75
+ resolver: DEFAULT_RESOLVER_PATH,
83
76
  rootDir: appContext.appDirectory || process.cwd(),
84
77
  // todo: diffrent test root for diffrent solutions
85
78
  // testMatch: [`<rootDir>/(src|tests|electron)/**/*.test.[jt]s?(x)`],
@@ -22,15 +22,11 @@ var _test = _interopRequireDefault(require("./test"));
22
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
23
 
24
24
  const mergeUserJestConfig = testUtils => {
25
- const resolveJestConfig = testUtils.testConfig.jest;
25
+ const resolveJestConfig = testUtils.testConfig.jest; // resolveJestConfig 如果是函数类型,在所有测试插件 jestConfig 都执行后,再执行生成最终配置
26
26
 
27
27
  if (resolveJestConfig && typeof resolveJestConfig !== 'function') {
28
28
  testUtils.mergeJestConfig(resolveJestConfig);
29
29
  }
30
-
31
- if (typeof resolveJestConfig === 'function') {
32
- resolveJestConfig(testUtils.jestConfig);
33
- }
34
30
  };
35
31
 
36
32
  exports.mergeUserJestConfig = mergeUserJestConfig;
@@ -41,18 +37,14 @@ var _default = () => {
41
37
  name: '@modern-js/plugin-testing',
42
38
  usePlugins: [BffPlugin],
43
39
  post: [BffPlugin.name],
44
- registerHook: {
45
- jestConfig: _testing.jestConfigHook
46
- },
40
+ registerHook: _testing.testingHooks,
47
41
  setup: api => {
48
42
  let testingExportsUtils;
49
- const appContext = api.useAppContext();
50
- const userConfig = api.useResolvedConfigContext();
51
43
  return {
52
44
  commands: ({
53
45
  program
54
46
  }) => {
55
- program.command('test').allowUnknownOption().usage('[options]').action(async () => {
47
+ program.command('test').allowUnknownOption().usage('<regexForTestFiles> --[options]').action(async () => {
56
48
  await (0, _test.default)(api);
57
49
  });
58
50
  },
@@ -62,6 +54,7 @@ var _default = () => {
62
54
  },
63
55
 
64
56
  config() {
57
+ const appContext = api.useAppContext();
65
58
  testingExportsUtils = (0, _utils.createRuntimeExportsUtils)(appContext.internalDirectory, 'testing');
66
59
  return {
67
60
  source: {
@@ -79,13 +72,15 @@ var _default = () => {
79
72
  },
80
73
 
81
74
  jestConfig: async (utils, next) => {
82
- const apiOnly = await (0, _utils.isApiOnly)(appContext.srcDirectory);
75
+ const appContext = api.useAppContext();
76
+ const userConfig = api.useResolvedConfigContext();
77
+ const apiOnly = await (0, _utils.isApiOnly)(appContext.appDirectory);
83
78
 
84
79
  if (apiOnly) {
85
80
  return next(utils);
86
81
  }
87
82
 
88
- const webpackConfig = (0, _webpack.getWebpackConfig)(_webpack.WebpackConfigTarget.CLIENT);
83
+ const webpackConfig = (0, _webpack.getWebpackConfig)(_webpack.WebpackConfigTarget.CLIENT, appContext, userConfig);
89
84
  const {
90
85
  resolve: {
91
86
  alias = {}
@@ -97,9 +92,7 @@ var _default = () => {
97
92
  },
98
93
  moduleNameMapper: (0, _testing.getModuleNameMapper)(alias),
99
94
  testEnvironment: 'jsdom',
100
- resolver: _testing.DEFAULT_RESOLVER_PATH
101
- });
102
- utils.setJestConfig({
95
+ resolver: _testing.DEFAULT_RESOLVER_PATH,
103
96
  rootDir: appContext.appDirectory || process.cwd(),
104
97
  // todo: diffrent test root for diffrent solutions
105
98
  // testMatch: [`<rootDir>/(src|tests|electron)/**/*.test.[jt]s?(x)`],
@@ -8,21 +8,17 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
8
8
 
9
9
  import path from 'path';
10
10
  import { PLUGIN_SCHEMAS, createRuntimeExportsUtils, isApiOnly } from '@modern-js/utils';
11
- import { jestConfigHook, getModuleNameMapper, DEFAULT_RESOLVER_PATH } from '@modern-js/testing';
11
+ import { testingHooks, getModuleNameMapper, DEFAULT_RESOLVER_PATH } from '@modern-js/testing';
12
12
  import { getWebpackConfig, WebpackConfigTarget } from '@modern-js/webpack';
13
13
  import TestingBffPlugin from '@modern-js/testing-plugin-bff';
14
14
  import { MODERNJS_CONFIG_KEY } from "../constant";
15
15
  import test from "./test";
16
16
  export var mergeUserJestConfig = function mergeUserJestConfig(testUtils) {
17
- var resolveJestConfig = testUtils.testConfig.jest;
17
+ var resolveJestConfig = testUtils.testConfig.jest; // resolveJestConfig 如果是函数类型,在所有测试插件 jestConfig 都执行后,再执行生成最终配置
18
18
 
19
19
  if (resolveJestConfig && typeof resolveJestConfig !== 'function') {
20
20
  testUtils.mergeJestConfig(resolveJestConfig);
21
21
  }
22
-
23
- if (typeof resolveJestConfig === 'function') {
24
- resolveJestConfig(testUtils.jestConfig);
25
- }
26
22
  };
27
23
  export default (function () {
28
24
  var BffPlugin = TestingBffPlugin();
@@ -30,17 +26,13 @@ export default (function () {
30
26
  name: '@modern-js/plugin-testing',
31
27
  usePlugins: [BffPlugin],
32
28
  post: [BffPlugin.name],
33
- registerHook: {
34
- jestConfig: jestConfigHook
35
- },
29
+ registerHook: testingHooks,
36
30
  setup: function setup(api) {
37
31
  var testingExportsUtils;
38
- var appContext = api.useAppContext();
39
- var userConfig = api.useResolvedConfigContext();
40
32
  return {
41
33
  commands: function commands(_ref) {
42
34
  var program = _ref.program;
43
- program.command('test').allowUnknownOption().usage('[options]').action( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
35
+ program.command('test').allowUnknownOption().usage('<regexForTestFiles> --[options]').action( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
44
36
  return _regeneratorRuntime.wrap(function _callee$(_context) {
45
37
  while (1) {
46
38
  switch (_context.prev = _context.next) {
@@ -60,6 +52,7 @@ export default (function () {
60
52
  return PLUGIN_SCHEMAS['@modern-js/plugin-testing'];
61
53
  },
62
54
  config: function config() {
55
+ var appContext = api.useAppContext();
63
56
  testingExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, 'testing');
64
57
  return {
65
58
  source: {
@@ -75,35 +68,35 @@ export default (function () {
75
68
  },
76
69
  jestConfig: function () {
77
70
  var _jestConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(utils, next) {
78
- var apiOnly, webpackConfig, _webpackConfig$resolv, alias;
71
+ var appContext, userConfig, apiOnly, webpackConfig, _webpackConfig$resolv, alias;
79
72
 
80
73
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
81
74
  while (1) {
82
75
  switch (_context2.prev = _context2.next) {
83
76
  case 0:
84
- _context2.next = 2;
85
- return isApiOnly(appContext.srcDirectory);
77
+ appContext = api.useAppContext();
78
+ userConfig = api.useResolvedConfigContext();
79
+ _context2.next = 4;
80
+ return isApiOnly(appContext.appDirectory);
86
81
 
87
- case 2:
82
+ case 4:
88
83
  apiOnly = _context2.sent;
89
84
 
90
85
  if (!apiOnly) {
91
- _context2.next = 5;
86
+ _context2.next = 7;
92
87
  break;
93
88
  }
94
89
 
95
90
  return _context2.abrupt("return", next(utils));
96
91
 
97
- case 5:
98
- webpackConfig = getWebpackConfig(WebpackConfigTarget.CLIENT);
92
+ case 7:
93
+ webpackConfig = getWebpackConfig(WebpackConfigTarget.CLIENT, appContext, userConfig);
99
94
  _webpackConfig$resolv = webpackConfig.resolve.alias, alias = _webpackConfig$resolv === void 0 ? {} : _webpackConfig$resolv;
100
95
  utils.mergeJestConfig({
101
96
  globals: _defineProperty({}, MODERNJS_CONFIG_KEY, userConfig),
102
97
  moduleNameMapper: getModuleNameMapper(alias),
103
98
  testEnvironment: 'jsdom',
104
- resolver: DEFAULT_RESOLVER_PATH
105
- });
106
- utils.setJestConfig({
99
+ resolver: DEFAULT_RESOLVER_PATH,
107
100
  rootDir: appContext.appDirectory || process.cwd(),
108
101
  // todo: diffrent test root for diffrent solutions
109
102
  // testMatch: [`<rootDir>/(src|tests|electron)/**/*.test.[jt]s?(x)`],
@@ -113,7 +106,7 @@ export default (function () {
113
106
  mergeUserJestConfig(utils);
114
107
  return _context2.abrupt("return", next(utils));
115
108
 
116
- case 11:
109
+ case 12:
117
110
  case "end":
118
111
  return _context2.stop();
119
112
  }
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.5.0",
14
+ "version": "1.5.3",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -19,19 +19,18 @@
19
19
  "jsnext:modern": "./dist/js/modern/index.js",
20
20
  "exports": {
21
21
  "./types": {
22
- "jsnext:source": "./type.d.ts",
23
- "default": "./type.d.ts"
22
+ "jsnext:source": "./types/index.d.ts",
23
+ "default": "./types/index.d.ts"
24
24
  },
25
25
  "./type": {
26
- "jsnext:source": "./type.d.ts",
27
- "default": "./type.d.ts"
26
+ "jsnext:source": "./types/index.d.ts",
27
+ "default": "./types/index.d.ts"
28
28
  },
29
29
  ".": {
30
30
  "node": {
31
31
  "jsnext:source": "./src/runtime-testing/index.ts",
32
32
  "import": "./dist/js/modern/runtime-testing/index.js",
33
- "require": "./dist/js/node/runtime-testing/index.js",
34
- "types": "./types/index.d.ts"
33
+ "require": "./dist/js/node/runtime-testing/index.js"
35
34
  },
36
35
  "default": "./dist/js/treeshaking/runtime-testing/index.js"
37
36
  },
@@ -39,8 +38,7 @@
39
38
  "jsnext:source": "./src/runtime-testing/index.ts",
40
39
  "node": {
41
40
  "import": "./dist/js/modern/runtime-testing/index.js",
42
- "require": "./dist/js/node/runtime-testing/index.js",
43
- "types": "./types/index.d.ts"
41
+ "require": "./dist/js/node/runtime-testing/index.js"
44
42
  },
45
43
  "default": "./dist/js/treeshaking/runtime-testing/index.js"
46
44
  },
@@ -48,8 +46,7 @@
48
46
  "jsnext:source": "./src/runtime-testing/base.ts",
49
47
  "node": {
50
48
  "import": "./dist/js/modern/runtime-testing/base.js",
51
- "require": "./dist/js/node/runtime-testing/base.js",
52
- "types": "./types/base.d.ts"
49
+ "require": "./dist/js/node/runtime-testing/base.js"
53
50
  },
54
51
  "default": "./dist/js/treeshaking/runtime-testing/base.js"
55
52
  },
@@ -70,10 +67,10 @@
70
67
  "./dist/types/runtime-testing/index.d.ts"
71
68
  ],
72
69
  "type": [
73
- "./type.d.ts"
70
+ "./types/index.d.ts"
74
71
  ],
75
72
  "types": [
76
- "./type.d.ts"
73
+ "./types/index.d.ts"
77
74
  ],
78
75
  "runtime-base": [
79
76
  "./dist/types/runtime-testing/base.d.ts"
@@ -81,40 +78,36 @@
81
78
  }
82
79
  },
83
80
  "dependencies": {
81
+ "@babel/core": "7.16.7",
84
82
  "@babel/preset-env": "^7.15.6",
85
83
  "@babel/runtime": "^7",
84
+ "@modern-js-reduck/plugin-auto-actions": "^1.0.2",
85
+ "@modern-js-reduck/plugin-effects": "^1.0.2",
86
+ "@modern-js-reduck/plugin-immutable": "^1.0.1",
87
+ "@modern-js-reduck/store": "^1.0.3",
86
88
  "@modern-js/babel-compiler": "^1.2.3",
87
- "@modern-js/testing": "^1.4.3",
88
- "@modern-js/utils": "^1.5.0",
89
- "@modern-js/webpack": "^1.5.6",
89
+ "@modern-js/bff-utils": "^1.2.4",
90
+ "@modern-js/runtime-core": "^1.4.4",
91
+ "@modern-js/testing": "^1.5.0",
92
+ "@modern-js/testing-plugin-bff": "^1.4.1",
93
+ "@modern-js/utils": "^1.7.0",
94
+ "@modern-js/webpack": "^1.6.0",
90
95
  "@testing-library/jest-dom": "^5.14.1",
91
96
  "@testing-library/react": "^12.0.0",
92
- "@modern-js/testing-plugin-bff": "^1.4.0"
93
- },
94
- "peerDependencies": {
95
- "@modern-js-reduck/plugin-auto-actions": "^1.0.0",
96
- "@modern-js-reduck/plugin-effects": "^1.0.0",
97
- "@modern-js-reduck/plugin-immutable": "^1.0.0",
98
- "@modern-js-reduck/store": "^1.0.0",
99
- "@modern-js/runtime-core": "^1.4.2"
97
+ "@types/testing-library__jest-dom": "^5.14.3"
100
98
  },
101
99
  "devDependencies": {
102
- "@modern-js-reduck/plugin-auto-actions": "^1.0.0",
103
- "@modern-js-reduck/plugin-effects": "^1.0.0",
104
- "@modern-js-reduck/plugin-immutable": "^1.0.0",
105
- "@modern-js-reduck/store": "^1.0.0",
100
+ "@modern-js/core": "1.10.0",
106
101
  "@scripts/build": "0.0.0",
107
- "@modern-js/core": "1.8.0",
108
- "@modern-js/runtime-core": "1.4.2",
102
+ "@scripts/jest-config": "0.0.0",
109
103
  "@types/jest": "^26",
110
104
  "@types/node": "^14",
111
105
  "@types/react": "^17",
112
106
  "@types/react-dom": "^17",
107
+ "jest": "^27",
113
108
  "react": "^17",
114
109
  "react-dom": "^17",
115
- "typescript": "^4",
116
- "jest": "^27",
117
- "@scripts/jest-config": "0.0.0"
110
+ "typescript": "^4"
118
111
  },
119
112
  "sideEffects": false,
120
113
  "modernConfig": {},
@@ -1,8 +1,8 @@
1
1
  import "@testing-library/react"
2
2
  import "@testing-library/jest-dom"
3
- import "./dist/types/runtime-testing"
3
+ import "../dist/types/runtime-testing"
4
4
 
5
5
  declare module '@modern-js/runtime/testing' {
6
6
  export * from '@testing-library/react';
7
- export { renderApp, createStore, testBff } from './dist/types/runtime-testing';
7
+ export { renderApp, createStore, testBff } from '../dist/types/runtime-testing';
8
8
  }