@umijs/test 3.5.18 → 4.0.0-rc.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/README.md +2 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +37 -0
- package/package.json +31 -32
- package/setupFiles/shim.js +2 -0
- package/bin/umi-test.js +0 -21
- package/helpers/setupFiles/jasmine.js +0 -1
- package/helpers/setupFiles/shim.js +0 -6
- package/helpers/transformers/css.js +0 -9
- package/helpers/transformers/file.js +0 -25
- package/helpers/transformers/javascript.js +0 -7
- package/lib/createDefaultConfig/createDefaultConfig.d.ts +0 -21
- package/lib/createDefaultConfig/createDefaultConfig.js +0 -106
- package/lib/index.d.ts +0 -3
- package/lib/index.js +0 -171
- package/lib/types.d.ts +0 -15
- package/lib/types.js +0 -17
- package/lib/utils/index.d.ts +0 -1
- package/lib/utils/index.js +0 -25
- package/lib/utils/mockConsole.d.ts +0 -16
- package/lib/utils/mockConsole.js +0 -101
package/README.md
CHANGED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Config } from '@jest/types';
|
|
2
|
+
export declare type JSTransformer = 'esbuild' | 'swc' | 'ts-jest';
|
|
3
|
+
export type { Config };
|
|
4
|
+
export declare function createConfig(opts?: {
|
|
5
|
+
jsTransformer?: JSTransformer;
|
|
6
|
+
target?: 'node' | 'browser';
|
|
7
|
+
}): Config.InitialOptions;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createConfig = void 0;
|
|
4
|
+
function getJSTransformer(jsTransformer) {
|
|
5
|
+
switch (jsTransformer) {
|
|
6
|
+
case 'esbuild':
|
|
7
|
+
return require.resolve('esbuild-jest');
|
|
8
|
+
case 'swc':
|
|
9
|
+
return require.resolve('@swc-node/jest');
|
|
10
|
+
case 'ts-jest':
|
|
11
|
+
return require.resolve('ts-jest');
|
|
12
|
+
default:
|
|
13
|
+
throw new Error(`Unknown jsTransformer: ${jsTransformer}`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function createConfig(opts) {
|
|
17
|
+
const config = {
|
|
18
|
+
testMatch: ['**/*.test.(t|j)s(x)?'],
|
|
19
|
+
transform: {
|
|
20
|
+
'^.+\\.tsx?$': getJSTransformer((opts === null || opts === void 0 ? void 0 : opts.jsTransformer) || 'esbuild'),
|
|
21
|
+
},
|
|
22
|
+
moduleNameMapper: {
|
|
23
|
+
'^.+\\.(css|less|sass|scss|stylus)$': require.resolve('identity-obj-proxy'),
|
|
24
|
+
},
|
|
25
|
+
testTimeout: 30000,
|
|
26
|
+
modulePathIgnorePatterns: [
|
|
27
|
+
'<rootDir>/packages/.+/compiled',
|
|
28
|
+
'<rootDir>/packages/.+/fixtures',
|
|
29
|
+
],
|
|
30
|
+
setupFiles: [require.resolve('../setupFiles/shim')],
|
|
31
|
+
};
|
|
32
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.target) === 'browser') {
|
|
33
|
+
config.testEnvironment = 'jsdom';
|
|
34
|
+
}
|
|
35
|
+
return config;
|
|
36
|
+
}
|
|
37
|
+
exports.createConfig = createConfig;
|
package/package.json
CHANGED
|
@@ -1,45 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/test",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-rc.3",
|
|
4
4
|
"description": "@umijs/test",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"files": [
|
|
8
|
-
"lib",
|
|
9
|
-
"helpers",
|
|
10
|
-
"bin"
|
|
11
|
-
],
|
|
5
|
+
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/test#readme",
|
|
6
|
+
"bugs": "https://github.com/umijs/umi-next/issues",
|
|
12
7
|
"repository": {
|
|
13
8
|
"type": "git",
|
|
14
|
-
"url": "https://github.com/umijs/umi"
|
|
9
|
+
"url": "https://github.com/umijs/umi-next"
|
|
15
10
|
},
|
|
16
|
-
"keywords": [
|
|
17
|
-
"umi"
|
|
18
|
-
],
|
|
19
|
-
"authors": [
|
|
20
|
-
"chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
|
|
21
|
-
],
|
|
22
11
|
"license": "MIT",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
12
|
+
"main": "dist/index.js",
|
|
13
|
+
"types": "dist/index.d.ts",
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"setupFiles"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "pnpm tsc",
|
|
20
|
+
"build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
|
|
21
|
+
"dev": "pnpm build -- --watch"
|
|
27
22
|
},
|
|
28
23
|
"dependencies": {
|
|
29
|
-
"@
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"babel-core": "7.0.0-bridge.0",
|
|
33
|
-
"babel-jest": "^26.6.3",
|
|
34
|
-
"core-js": "3.8.2",
|
|
24
|
+
"@jest/types": "27.5.1",
|
|
25
|
+
"esbuild": "0.14.23",
|
|
26
|
+
"esbuild-jest": "0.5.0",
|
|
35
27
|
"identity-obj-proxy": "3.0.0",
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
|
|
28
|
+
"isomorphic-unfetch": "3.1.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"jest": "27.5.1"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
41
35
|
},
|
|
42
|
-
"
|
|
43
|
-
"
|
|
36
|
+
"authors": [
|
|
37
|
+
"chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
|
|
38
|
+
],
|
|
39
|
+
"compiledConfig": {
|
|
40
|
+
"deps": [
|
|
41
|
+
"identity-obj-proxy"
|
|
42
|
+
]
|
|
44
43
|
}
|
|
45
44
|
}
|
package/bin/umi-test.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const { yParser, chalk, createDebug } = require('@umijs/utils');
|
|
3
|
-
const debug = createDebug('umi:test');
|
|
4
|
-
|
|
5
|
-
const args = yParser(process.argv.slice(2), {
|
|
6
|
-
alias: {
|
|
7
|
-
watch: ['w'],
|
|
8
|
-
version: ['v'],
|
|
9
|
-
},
|
|
10
|
-
boolean: ['coverage', 'watch', 'version', 'debug', 'e2e'],
|
|
11
|
-
default: {
|
|
12
|
-
e2e: true,
|
|
13
|
-
},
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
require('../lib')
|
|
17
|
-
.default(args)
|
|
18
|
-
.catch((e) => {
|
|
19
|
-
console.error(chalk.red(e));
|
|
20
|
-
process.exit(1);
|
|
21
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
jasmine.DEFAULT_TIMEOUT_INTERVAL = 200000; // eslint-disable-line
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
process(src, filename) {
|
|
5
|
-
const assetFilename = JSON.stringify(path.basename(filename));
|
|
6
|
-
|
|
7
|
-
if (filename.match(/\.svg$/)) {
|
|
8
|
-
return `module.exports = {
|
|
9
|
-
__esModule: true,
|
|
10
|
-
default: ${assetFilename},
|
|
11
|
-
ReactComponent: ({ svgRef, ...props }) => ({
|
|
12
|
-
$$typeof: Symbol.for('react.element'),
|
|
13
|
-
type: 'svg',
|
|
14
|
-
ref: svgRef || null,
|
|
15
|
-
key: null,
|
|
16
|
-
props: Object.assign({}, props, {
|
|
17
|
-
children: ${assetFilename}
|
|
18
|
-
})
|
|
19
|
-
}),
|
|
20
|
-
};`;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return `module.exports = ${assetFilename};`;
|
|
24
|
-
},
|
|
25
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { IUmiTestArgs } from '../types';
|
|
2
|
-
export default function (cwd: string, args: IUmiTestArgs): {
|
|
3
|
-
maxWorkers?: number | undefined;
|
|
4
|
-
collectCoverageFrom: (string | false | undefined)[];
|
|
5
|
-
moduleFileExtensions: string[];
|
|
6
|
-
moduleNameMapper: {
|
|
7
|
-
'\\.(css|less|sass|scss|stylus)$': string;
|
|
8
|
-
};
|
|
9
|
-
setupFiles: string[];
|
|
10
|
-
setupFilesAfterEnv: string[];
|
|
11
|
-
testEnvironment: string;
|
|
12
|
-
testMatch: string[];
|
|
13
|
-
testPathIgnorePatterns: string[];
|
|
14
|
-
transform: {
|
|
15
|
-
'^.+\\.(js|jsx|ts|tsx)$': string;
|
|
16
|
-
'^.+\\.(css|less|sass|scss|stylus)$': string;
|
|
17
|
-
'^(?!.*\\.(js|jsx|ts|tsx|css|less|sass|scss|stylus|json)$)': string;
|
|
18
|
-
};
|
|
19
|
-
verbose: boolean;
|
|
20
|
-
transformIgnorePatterns: never[];
|
|
21
|
-
};
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = _default;
|
|
7
|
-
|
|
8
|
-
function _react() {
|
|
9
|
-
const data = _interopRequireDefault(require("react"));
|
|
10
|
-
|
|
11
|
-
_react = function _react() {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _utils() {
|
|
19
|
-
const data = require("@umijs/utils");
|
|
20
|
-
|
|
21
|
-
_utils = function _utils() {
|
|
22
|
-
return data;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
return data;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function _assert() {
|
|
29
|
-
const data = _interopRequireDefault(require("assert"));
|
|
30
|
-
|
|
31
|
-
_assert = function _assert() {
|
|
32
|
-
return data;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
return data;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function _fs() {
|
|
39
|
-
const data = require("fs");
|
|
40
|
-
|
|
41
|
-
_fs = function _fs() {
|
|
42
|
-
return data;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
return data;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function _path() {
|
|
49
|
-
const data = require("path");
|
|
50
|
-
|
|
51
|
-
_path = function _path() {
|
|
52
|
-
return data;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
return data;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
59
|
-
|
|
60
|
-
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; }
|
|
61
|
-
|
|
62
|
-
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; }
|
|
63
|
-
|
|
64
|
-
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; }
|
|
65
|
-
|
|
66
|
-
function _default(cwd, args) {
|
|
67
|
-
const testMatchTypes = ['spec', 'test'];
|
|
68
|
-
|
|
69
|
-
if (args.e2e) {
|
|
70
|
-
testMatchTypes.push('e2e');
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const isLerna = (0, _utils().isLernaPackage)(cwd);
|
|
74
|
-
const hasPackage = isLerna && args.package;
|
|
75
|
-
const testMatchPrefix = hasPackage ? `**/packages/${args.package}/` : '';
|
|
76
|
-
const hasSrc = (0, _fs().existsSync)((0, _path().join)(cwd, 'src'));
|
|
77
|
-
|
|
78
|
-
if (hasPackage) {
|
|
79
|
-
(0, _assert().default)((0, _fs().existsSync)((0, _path().join)(cwd, 'packages', args.package)), `You specified --package, but packages/${args.package} does not exists.`);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return _objectSpread({
|
|
83
|
-
collectCoverageFrom: ['index.{js,jsx,ts,tsx}', hasSrc && 'src/**/*.{js,jsx,ts,tsx}', isLerna && !args.package && 'packages/*/src/**/*.{js,jsx,ts,tsx}', isLerna && args.package && `packages/${args.package}/src/**/*.{js,jsx,ts,tsx}`, '!**/typings/**', '!**/types/**', '!**/fixtures/**', '!**/examples/**', '!**/*.d.ts'].filter(Boolean),
|
|
84
|
-
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'json'],
|
|
85
|
-
moduleNameMapper: {
|
|
86
|
-
'\\.(css|less|sass|scss|stylus)$': require.resolve('identity-obj-proxy')
|
|
87
|
-
},
|
|
88
|
-
setupFiles: [require.resolve('../../helpers/setupFiles/shim')],
|
|
89
|
-
setupFilesAfterEnv: [require.resolve('../../helpers/setupFiles/jasmine')],
|
|
90
|
-
testEnvironment: require.resolve('jest-environment-jsdom-fourteen'),
|
|
91
|
-
testMatch: [`${testMatchPrefix}**/?*.(${testMatchTypes.join('|')}).(j|t)s?(x)`],
|
|
92
|
-
testPathIgnorePatterns: ['/node_modules/', '/fixtures/'],
|
|
93
|
-
transform: {
|
|
94
|
-
'^.+\\.(js|jsx|ts|tsx)$': require.resolve('../../helpers/transformers/javascript'),
|
|
95
|
-
'^.+\\.(css|less|sass|scss|stylus)$': require.resolve('../../helpers/transformers/css'),
|
|
96
|
-
'^(?!.*\\.(js|jsx|ts|tsx|css|less|sass|scss|stylus|json)$)': require.resolve('../../helpers/transformers/file')
|
|
97
|
-
},
|
|
98
|
-
verbose: true,
|
|
99
|
-
transformIgnorePatterns: [// 加 [^/]*? 是为了兼容 tnpm 的目录结构
|
|
100
|
-
// 比如:_umi-test@1.5.5@umi-test
|
|
101
|
-
// `node_modules/(?!([^/]*?umi|[^/]*?umi-test)/)`,
|
|
102
|
-
]
|
|
103
|
-
}, process.env.MAX_WORKERS ? {
|
|
104
|
-
maxWorkers: Number(process.env.MAX_WORKERS)
|
|
105
|
-
} : {});
|
|
106
|
-
}
|
package/lib/index.d.ts
DELETED
package/lib/index.js
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _exportNames = {};
|
|
7
|
-
exports.default = _default;
|
|
8
|
-
|
|
9
|
-
function _react() {
|
|
10
|
-
const data = _interopRequireDefault(require("react"));
|
|
11
|
-
|
|
12
|
-
_react = function _react() {
|
|
13
|
-
return data;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
return data;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function _utils() {
|
|
20
|
-
const data = require("@umijs/utils");
|
|
21
|
-
|
|
22
|
-
_utils = function _utils() {
|
|
23
|
-
return data;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
return data;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function _assert() {
|
|
30
|
-
const data = _interopRequireDefault(require("assert"));
|
|
31
|
-
|
|
32
|
-
_assert = function _assert() {
|
|
33
|
-
return data;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
return data;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function _fs() {
|
|
40
|
-
const data = require("fs");
|
|
41
|
-
|
|
42
|
-
_fs = function _fs() {
|
|
43
|
-
return data;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
return data;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function _jest() {
|
|
50
|
-
const data = require("jest");
|
|
51
|
-
|
|
52
|
-
_jest = function _jest() {
|
|
53
|
-
return data;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
return data;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function _args() {
|
|
60
|
-
const data = require("jest-cli/build/cli/args");
|
|
61
|
-
|
|
62
|
-
_args = function _args() {
|
|
63
|
-
return data;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
return data;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function _path() {
|
|
70
|
-
const data = require("path");
|
|
71
|
-
|
|
72
|
-
_path = function _path() {
|
|
73
|
-
return data;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
return data;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
var _createDefaultConfig = _interopRequireDefault(require("./createDefaultConfig/createDefaultConfig"));
|
|
80
|
-
|
|
81
|
-
var _utils2 = require("./utils");
|
|
82
|
-
|
|
83
|
-
Object.keys(_utils2).forEach(function (key) {
|
|
84
|
-
if (key === "default" || key === "__esModule") return;
|
|
85
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
86
|
-
if (key in exports && exports[key] === _utils2[key]) return;
|
|
87
|
-
Object.defineProperty(exports, key, {
|
|
88
|
-
enumerable: true,
|
|
89
|
-
get: function get() {
|
|
90
|
-
return _utils2[key];
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
96
|
-
|
|
97
|
-
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; }
|
|
98
|
-
|
|
99
|
-
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; }
|
|
100
|
-
|
|
101
|
-
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; }
|
|
102
|
-
|
|
103
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
104
|
-
|
|
105
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
106
|
-
|
|
107
|
-
const debug = (0, _utils().createDebug)('umi:test');
|
|
108
|
-
|
|
109
|
-
function _default(_x) {
|
|
110
|
-
return _ref.apply(this, arguments);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function _ref() {
|
|
114
|
-
_ref = _asyncToGenerator(function* (args) {
|
|
115
|
-
process.env.NODE_ENV = 'test';
|
|
116
|
-
|
|
117
|
-
if (args.debug) {
|
|
118
|
-
_utils().createDebug.enable('umi:test');
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
debug(`args: ${JSON.stringify(args)}`); // Print related versions
|
|
122
|
-
|
|
123
|
-
if (args.version) {
|
|
124
|
-
console.log(`umi-test@${require('../package.json').version}`);
|
|
125
|
-
console.log(`jest@${require('jest/package.json').version}`);
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const cwd = args.cwd || process.cwd(); // Read config from cwd/jest.config.js
|
|
130
|
-
|
|
131
|
-
const userJestConfigFile = (0, _path().join)(cwd, 'jest.config.js');
|
|
132
|
-
|
|
133
|
-
const userJestConfig = (0, _fs().existsSync)(userJestConfigFile) && require(userJestConfigFile);
|
|
134
|
-
|
|
135
|
-
debug(`config from jest.config.js: ${JSON.stringify(userJestConfig)}`); // Read jest config from package.json
|
|
136
|
-
|
|
137
|
-
const packageJSONPath = (0, _path().join)(cwd, 'package.json');
|
|
138
|
-
|
|
139
|
-
const packageJestConfig = (0, _fs().existsSync)(packageJSONPath) && require(packageJSONPath).jest;
|
|
140
|
-
|
|
141
|
-
debug(`jest config from package.json: ${JSON.stringify(packageJestConfig)}`); // Merge configs
|
|
142
|
-
// user config and args config could have value function for modification
|
|
143
|
-
|
|
144
|
-
const config = (0, _utils().mergeConfig)((0, _createDefaultConfig.default)(cwd, args), packageJestConfig, userJestConfig);
|
|
145
|
-
debug(`final config: ${JSON.stringify(config)}`); // Generate jest options
|
|
146
|
-
|
|
147
|
-
const argsConfig = Object.keys(_args().options).reduce((prev, name) => {
|
|
148
|
-
if (args[name]) prev[name] = args[name]; // Convert alias args into real one
|
|
149
|
-
|
|
150
|
-
const alias = _args().options[name].alias;
|
|
151
|
-
|
|
152
|
-
if (alias && args[alias]) prev[name] = args[alias];
|
|
153
|
-
return prev;
|
|
154
|
-
}, {});
|
|
155
|
-
debug(`config from args: ${JSON.stringify(argsConfig)}`); // Run jest
|
|
156
|
-
|
|
157
|
-
const result = yield (0, _jest().runCLI)(_objectSpread({
|
|
158
|
-
// @ts-ignore
|
|
159
|
-
_: args._ || [],
|
|
160
|
-
// @ts-ignore
|
|
161
|
-
$0: args.$0 || '',
|
|
162
|
-
// 必须是单独的 config 配置,值为 string,否则不生效
|
|
163
|
-
// @ts-ignore
|
|
164
|
-
config: JSON.stringify(config)
|
|
165
|
-
}, argsConfig), [cwd]);
|
|
166
|
-
debug(result); // Throw error when run failed
|
|
167
|
-
|
|
168
|
-
(0, _assert().default)(result.results.success, `Test with jest failed`);
|
|
169
|
-
});
|
|
170
|
-
return _ref.apply(this, arguments);
|
|
171
|
-
}
|
package/lib/types.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { ArgsType } from '@umijs/utils';
|
|
2
|
-
import { runCLI } from 'jest';
|
|
3
|
-
import { options as CliOptions } from 'jest-cli/build/cli/args';
|
|
4
|
-
export interface IUmiTestArgs extends Partial<ArgsType<typeof runCLI>['0']> {
|
|
5
|
-
version?: boolean;
|
|
6
|
-
cwd?: string;
|
|
7
|
-
debug?: boolean;
|
|
8
|
-
e2e?: boolean;
|
|
9
|
-
package?: string;
|
|
10
|
-
}
|
|
11
|
-
export declare type PickedJestCliOptions = {
|
|
12
|
-
[T in keyof typeof CliOptions]?: T extends keyof IUmiTestArgs[T] ? T : typeof CliOptions[T] extends {
|
|
13
|
-
alias: infer U;
|
|
14
|
-
} ? IUmiTestArgs[T] : never;
|
|
15
|
-
};
|
package/lib/types.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
function _react() {
|
|
8
|
-
const data = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
|
-
_react = function _react() {
|
|
11
|
-
return data;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
return data;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
package/lib/utils/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as mockConsole } from './mockConsole';
|
package/lib/utils/index.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "mockConsole", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function get() {
|
|
9
|
-
return _mockConsole.default;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
function _react() {
|
|
14
|
-
const data = _interopRequireDefault(require("react"));
|
|
15
|
-
|
|
16
|
-
_react = function _react() {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
return data;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
var _mockConsole = _interopRequireDefault(require("./mockConsole"));
|
|
24
|
-
|
|
25
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
declare type ConsoleFunctionName = {
|
|
2
|
-
[T in keyof Console]: Console[T] extends (...args: any[]) => any ? T : never;
|
|
3
|
-
}[keyof Console];
|
|
4
|
-
export declare type MessageStore = any[][] | ((...args: any[]) => void);
|
|
5
|
-
export declare type MessageStoreWithType = [ConsoleFunctionName, ...any[]][] | ((name: ConsoleFunctionName, ...args: any[]) => void);
|
|
6
|
-
interface ResetMockConsole<T> {
|
|
7
|
-
(): void;
|
|
8
|
-
messages: T;
|
|
9
|
-
}
|
|
10
|
-
interface MockConsoleFunction<T> {
|
|
11
|
-
(messageStore?: T): ResetMockConsole<T>;
|
|
12
|
-
}
|
|
13
|
-
interface MockConsole extends Record<ConsoleFunctionName, MockConsoleFunction<MessageStore>>, MockConsoleFunction<MessageStoreWithType> {
|
|
14
|
-
}
|
|
15
|
-
declare const _default: MockConsole;
|
|
16
|
-
export default _default;
|
package/lib/utils/mockConsole.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
function _react() {
|
|
9
|
-
const data = _interopRequireDefault(require("react"));
|
|
10
|
-
|
|
11
|
-
_react = function _react() {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
21
|
-
|
|
22
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
23
|
-
|
|
24
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
25
|
-
|
|
26
|
-
const consoleFunctionName = Object.keys(console).filter(key => typeof console[key] === 'function');
|
|
27
|
-
/**
|
|
28
|
-
* @example
|
|
29
|
-
* function sample() {
|
|
30
|
-
* console.log('a');
|
|
31
|
-
* console.warn('b');
|
|
32
|
-
* return 0;
|
|
33
|
-
* }
|
|
34
|
-
*
|
|
35
|
-
* test('test sample', () => {
|
|
36
|
-
* const reset = mockConsole();
|
|
37
|
-
* expect(sample()).toBe(0);
|
|
38
|
-
* reset();
|
|
39
|
-
* expect(reset.messages).toEqual([
|
|
40
|
-
* ['log', 'a'],
|
|
41
|
-
* ['warn', 'b'],
|
|
42
|
-
* ]);
|
|
43
|
-
* });
|
|
44
|
-
*
|
|
45
|
-
* test('test sample', () => {
|
|
46
|
-
* const reset = mockConsole.log();
|
|
47
|
-
* expect(sample()).toBe(0);
|
|
48
|
-
* reset();
|
|
49
|
-
* expect(reset.messages).toEqual([['a']]);
|
|
50
|
-
* });
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
function mockConsole(messageStore = []) {
|
|
54
|
-
const self = mockConsole;
|
|
55
|
-
const messages = Array.isArray(messageStore) ? messageStore : [];
|
|
56
|
-
const callback = Array.isArray(messageStore) ? null : messageStore;
|
|
57
|
-
const resets = consoleFunctionName.map(name => {
|
|
58
|
-
return self[name]((...args) => {
|
|
59
|
-
messages.push([name, ...args]);
|
|
60
|
-
if (callback) callback(name, ...args);
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
const reset = () => resets.forEach(fn => fn());
|
|
65
|
-
|
|
66
|
-
reset.messages = messages;
|
|
67
|
-
return reset;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
var _iterator = _createForOfIteratorHelper(consoleFunctionName),
|
|
71
|
-
_step;
|
|
72
|
-
|
|
73
|
-
try {
|
|
74
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
75
|
-
const name = _step.value;
|
|
76
|
-
mockConsole[name] = getMockConsoleFunction(name);
|
|
77
|
-
}
|
|
78
|
-
} catch (err) {
|
|
79
|
-
_iterator.e(err);
|
|
80
|
-
} finally {
|
|
81
|
-
_iterator.f();
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
var _default = mockConsole;
|
|
85
|
-
exports.default = _default;
|
|
86
|
-
|
|
87
|
-
function getMockConsoleFunction(name) {
|
|
88
|
-
return function mockConsoleFunction(messageStore = []) {
|
|
89
|
-
const messages = Array.isArray(messageStore) ? messageStore : [];
|
|
90
|
-
const callback = Array.isArray(messageStore) ? null : messageStore;
|
|
91
|
-
const consoleSpy = jest.spyOn(console, name).mockImplementation((...args) => {
|
|
92
|
-
messages.push(args);
|
|
93
|
-
if (callback) callback(...args);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
const reset = () => consoleSpy.mockRestore();
|
|
97
|
-
|
|
98
|
-
reset.messages = messages;
|
|
99
|
-
return reset;
|
|
100
|
-
};
|
|
101
|
-
}
|