@elliemae/pui-cli 6.0.0-beta.3 → 6.0.0-beta.33
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/lib/cli-commands/pack.js +4 -9
- package/lib/cli-commands/test.js +1 -12
- package/lib/cli-commands/tsc.js +103 -0
- package/lib/lint/eslint/common.js +5 -6
- package/lib/lint/lint-staged.config.js +8 -1
- package/lib/pui-config/index.js +18 -0
- package/lib/server/index.js +5 -9
- package/lib/server/middlewares/addDevMiddlewares.js +2 -2
- package/lib/server/middlewares/addProdMiddlewares.js +10 -3
- package/lib/testing/jest.config.js +26 -7
- package/lib/testing/mocks/matchMedia.js +2 -2
- package/lib/testing/mocks/pui-app-loader.js +1 -3
- package/lib/testing/mocks/pui-diagnostics.js +27 -35
- package/lib/testing/mocks/pui-user-monitoring.js +3 -5
- package/lib/testing/mocks/retry-axios.js +3 -5
- package/lib/testing/mocks/svg.js +5 -3
- package/lib/testing/resolver.js +47 -0
- package/lib/testing/setup-react-env.js +3 -0
- package/lib/testing/setup-tests.js +27 -4
- package/lib/transpile/.swcrc +11 -0
- package/lib/transpile/esbuild.js +62 -0
- package/lib/transpile/react-shim.js +2 -0
- package/lib/transpile/swcrc.config.js +13 -0
- package/lib/typescript/tsc-files/index.js +61 -0
- package/lib/typescript/tsc-files/utils.js +16 -0
- package/lib/webpack/helpers.js +37 -4
- package/lib/webpack/webpack.base.babel.js +43 -69
- package/lib/webpack/webpack.dev.babel.js +0 -2
- package/lib/webpack/webpack.lib.base.babel.js +30 -51
- package/lib/webpack/webpack.lib.dev.babel.js +0 -2
- package/lib/webpack/webpack.lib.prod.babel.js +8 -21
- package/lib/webpack/webpack.prod.babel.js +5 -11
- package/lib/webpack/webpack.storybook.js +20 -86
- package/package.json +103 -95
- package/lib/testing/setup-styled-components-tests.js +0 -1
package/lib/cli-commands/pack.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
/* eslint-disable max-lines */
|
|
1
2
|
const { exit } = require('yargs');
|
|
2
3
|
const path = require('path');
|
|
3
4
|
const { writeFile, readFile } = require('fs/promises');
|
|
4
5
|
const { exec, logInfo, logError, logSuccess } = require('./utils');
|
|
5
6
|
const { isTypeScriptEnabled } = require('../typescript/util');
|
|
7
|
+
const { esBuild } = require('../transpile/esbuild');
|
|
6
8
|
|
|
7
9
|
const { name } = require('../../package.json');
|
|
8
10
|
|
|
@@ -37,14 +39,9 @@ async function createPackageJson(file, commonJS, sideEffects) {
|
|
|
37
39
|
await writeFile(file, packageJSON);
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
async function nodeBuild({ srcPath, commonJS, emitModuleType
|
|
42
|
+
async function nodeBuild({ srcPath, commonJS, emitModuleType }) {
|
|
41
43
|
const outDir = `./dist/${commonJS ? 'cjs' : 'es'}`;
|
|
42
|
-
|
|
43
|
-
const babelEnv = commonJS ? ' ES_MODULES=false' : '';
|
|
44
|
-
await exec(
|
|
45
|
-
`cross-env NODE_ENV=production MODULE_EXTENSIONS=true ${targetEnv}${babelEnv} babel --extensions ".ts,.tsx,.js,.jsx" ${srcPath} --out-dir ${outDir} --copy-files --no-copy-ignored --ignore **/*.test.js --ignore **/*.test.ts --ignore **/*.spec.js --ignore **/*.spec.ts --ignore **/*.test.jsx --ignore **/*.test.tsx --ignore **/*.spec.jsx --ignore **/*.spec.tsx`,
|
|
46
|
-
{ shell: true, stdio: 'inherit' },
|
|
47
|
-
);
|
|
44
|
+
await esBuild({ srcPath, commonJS });
|
|
48
45
|
if (emitModuleType) {
|
|
49
46
|
const sideEffects = await getSideEffects();
|
|
50
47
|
await createPackageJson(
|
|
@@ -79,7 +76,6 @@ async function pack({ production, target, module, srcPath, emitModuleType }) {
|
|
|
79
76
|
srcPath,
|
|
80
77
|
commonJS: false,
|
|
81
78
|
emitModuleType,
|
|
82
|
-
target,
|
|
83
79
|
});
|
|
84
80
|
}
|
|
85
81
|
}
|
|
@@ -118,7 +114,6 @@ exports.builder = {
|
|
|
118
114
|
},
|
|
119
115
|
emitModuleType: {
|
|
120
116
|
type: 'boolean',
|
|
121
|
-
// eslint-disable-next-line max-lines
|
|
122
117
|
default: true,
|
|
123
118
|
description:
|
|
124
119
|
'creates type attribute in the package.json and sets its value to commonjs or module based on module cli argument. default: true',
|
package/lib/cli-commands/test.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const { exit } = require('yargs');
|
|
2
2
|
const { exec, logError, logSuccess } = require('./utils');
|
|
3
|
-
const { lintCSS, lintJS } = require('./lint');
|
|
4
3
|
|
|
5
4
|
const { CI = false } = process.env;
|
|
6
5
|
|
|
@@ -19,17 +18,7 @@ async function handler(argv) {
|
|
|
19
18
|
if (argv.r) commandOptions += ' --bail --findRelatedTests';
|
|
20
19
|
if (argv.s) commandOptions += ' --silent';
|
|
21
20
|
try {
|
|
22
|
-
if (
|
|
23
|
-
try {
|
|
24
|
-
await lintJS();
|
|
25
|
-
await lintCSS();
|
|
26
|
-
logSuccess('Linting completed');
|
|
27
|
-
} catch (err) {
|
|
28
|
-
logError('Linting failed');
|
|
29
|
-
exit(-1, err);
|
|
30
|
-
return -1;
|
|
31
|
-
}
|
|
32
|
-
} else {
|
|
21
|
+
if (CI) {
|
|
33
22
|
await exec('rimraf ./reports');
|
|
34
23
|
}
|
|
35
24
|
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
const { exit } = require('yargs');
|
|
2
|
+
const { dirname, join } = require('path');
|
|
3
|
+
const { spawnSync } = require('child_process');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const { logInfo, logError } = require('./utils');
|
|
6
|
+
|
|
7
|
+
const randomChars = () => Math.random().toString(36).slice(2);
|
|
8
|
+
|
|
9
|
+
const resolveFromModule = (moduleName, ...paths) => {
|
|
10
|
+
const modulePath = dirname(require.resolve(`${moduleName}/package.json`));
|
|
11
|
+
return join(modulePath, ...paths);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const resolveFromRoot = (...paths) => join(process.cwd(), ...paths);
|
|
15
|
+
|
|
16
|
+
const validateTypescript = async () => {
|
|
17
|
+
const args = process.argv.slice(2);
|
|
18
|
+
const argsProjectIndex = args.findIndex((arg) =>
|
|
19
|
+
['-p', '--project'].includes(arg),
|
|
20
|
+
);
|
|
21
|
+
const argsProjectValue =
|
|
22
|
+
argsProjectIndex !== -1 ? args[argsProjectIndex + 1] : undefined;
|
|
23
|
+
|
|
24
|
+
const files = args.filter((file) => /\.(ts|tsx)$/.test(file));
|
|
25
|
+
if (files.length === 0) {
|
|
26
|
+
process.exit(0);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const remainingArgsToForward = args
|
|
30
|
+
.slice()
|
|
31
|
+
.filter((arg) => !files.includes(arg));
|
|
32
|
+
|
|
33
|
+
if (argsProjectIndex !== -1) {
|
|
34
|
+
remainingArgsToForward.splice(argsProjectIndex, 2);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Load existing config
|
|
38
|
+
const tsconfigPath = argsProjectValue || resolveFromRoot('tsconfig.json');
|
|
39
|
+
const tsconfigContent = fs.readFileSync(tsconfigPath).toString();
|
|
40
|
+
// Use 'eval' to read the JSON as regular JavaScript syntax so that comments are allowed
|
|
41
|
+
// eslint-disable-next-line prefer-const
|
|
42
|
+
let tsconfig = {};
|
|
43
|
+
// eslint-disable-next-line no-eval
|
|
44
|
+
eval(`tsconfig = ${tsconfigContent}`);
|
|
45
|
+
|
|
46
|
+
// Write a temp config file
|
|
47
|
+
const tmpTsconfigPath = resolveFromRoot(`tsconfig.${randomChars()}.json`);
|
|
48
|
+
const tmpTsconfig = {
|
|
49
|
+
...tsconfig,
|
|
50
|
+
compilerOptions: {
|
|
51
|
+
...tsconfig.compilerOptions,
|
|
52
|
+
skipLibCheck: true,
|
|
53
|
+
},
|
|
54
|
+
files,
|
|
55
|
+
include: ['shared/typings'],
|
|
56
|
+
};
|
|
57
|
+
fs.writeFileSync(tmpTsconfigPath, JSON.stringify(tmpTsconfig, null, 2));
|
|
58
|
+
|
|
59
|
+
// Type-check our files
|
|
60
|
+
const { status } = spawnSync(
|
|
61
|
+
resolveFromModule(
|
|
62
|
+
'typescript',
|
|
63
|
+
`../.bin/tsc${process.platform === 'win32' ? '.cmd' : ''}`,
|
|
64
|
+
),
|
|
65
|
+
['-p', tmpTsconfigPath, ...remainingArgsToForward],
|
|
66
|
+
{ stdio: 'inherit' },
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
// Delete temp config file
|
|
70
|
+
fs.unlinkSync(tmpTsconfigPath);
|
|
71
|
+
|
|
72
|
+
process.exit(status);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
async function handler(argv) {
|
|
76
|
+
try {
|
|
77
|
+
await validateTypescript(argv.p);
|
|
78
|
+
logInfo('Typescript validation started');
|
|
79
|
+
} catch (err) {
|
|
80
|
+
logError('Typescript validation failed', err);
|
|
81
|
+
exit(-1, err);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
exports.command = 'tsc [options]';
|
|
86
|
+
|
|
87
|
+
exports.describe = 'validate typescript code';
|
|
88
|
+
|
|
89
|
+
exports.builder = {
|
|
90
|
+
project: {
|
|
91
|
+
alias: 'p',
|
|
92
|
+
type: 'boolean',
|
|
93
|
+
default: false,
|
|
94
|
+
},
|
|
95
|
+
docs: {
|
|
96
|
+
type: 'boolean',
|
|
97
|
+
default: false,
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
exports.handler = handler;
|
|
102
|
+
|
|
103
|
+
exports.validateTypescript = validateTypescript;
|
|
@@ -9,6 +9,7 @@ exports.baseExtends = [
|
|
|
9
9
|
'plugin:jsdoc/recommended',
|
|
10
10
|
'plugin:wdio/recommended',
|
|
11
11
|
'plugin:testing-library/dom',
|
|
12
|
+
'plugin:storybook/recommended',
|
|
12
13
|
];
|
|
13
14
|
|
|
14
15
|
const basePlugins = ['testing-library', 'jest', 'jsdoc', 'wdio'];
|
|
@@ -36,12 +37,10 @@ const baseRules = {
|
|
|
36
37
|
'import/prefer-default-export': 0,
|
|
37
38
|
'import/extensions': [
|
|
38
39
|
2,
|
|
39
|
-
'
|
|
40
|
+
'never',
|
|
40
41
|
{
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
ts: 'never',
|
|
44
|
-
tsx: 'never',
|
|
42
|
+
json: 'ignorePackages',
|
|
43
|
+
js: 'ignorePackages',
|
|
45
44
|
},
|
|
46
45
|
],
|
|
47
46
|
indent: [
|
|
@@ -104,7 +103,7 @@ const reactRules = {
|
|
|
104
103
|
'react/react-in-jsx-scope': 0,
|
|
105
104
|
'react/jsx-filename-extension': [
|
|
106
105
|
1,
|
|
107
|
-
{ extensions: ['.js', '.jsx', '.
|
|
106
|
+
{ extensions: ['.js', '.jsx', '.tsx', '.mdx'] },
|
|
108
107
|
],
|
|
109
108
|
'redux-saga/no-yield-in-race': 2,
|
|
110
109
|
'redux-saga/yield-effects': 2,
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
|
|
1
3
|
module.exports = {
|
|
2
|
-
'*.{ts,tsx}': [
|
|
4
|
+
'*.{ts,tsx}': [
|
|
5
|
+
`node ${path.resolve(
|
|
6
|
+
__dirname,
|
|
7
|
+
'../typescript/tsc-files/index.js',
|
|
8
|
+
)} --noEmit --emitDeclarationOnly false`,
|
|
9
|
+
],
|
|
3
10
|
'*.{js,ts,jsx,tsx}': [
|
|
4
11
|
'npm run lint:fix',
|
|
5
12
|
'npm run test:staged',
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const { merge } = require('lodash');
|
|
4
|
+
|
|
5
|
+
const baseConfig = {
|
|
6
|
+
esBuild: {
|
|
7
|
+
target: 'es2020',
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const getPUIConfig = () => {
|
|
12
|
+
const configPath = path.resolve(process.cwd(), './pui.config.js');
|
|
13
|
+
if (!fs.existsSync(configPath)) return baseConfig;
|
|
14
|
+
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
15
|
+
return merge(baseConfig, config);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
exports.getPUIConfig = getPUIConfig;
|
package/lib/server/index.js
CHANGED
|
@@ -13,8 +13,11 @@ const { loadRoutes } = require('./util');
|
|
|
13
13
|
const { getAssetPath } = require('../webpack/helpers');
|
|
14
14
|
|
|
15
15
|
const pino = expressPinoLogger({
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
transport: {
|
|
17
|
+
target: 'pino-pretty',
|
|
18
|
+
options: {
|
|
19
|
+
colorize: true,
|
|
20
|
+
},
|
|
18
21
|
},
|
|
19
22
|
});
|
|
20
23
|
pino.logger.level = 'warn';
|
|
@@ -57,13 +60,6 @@ const customHost = argv.host || process.env.HOST;
|
|
|
57
60
|
const host = customHost || null; // Let http.Server use its default IPv6/4 host
|
|
58
61
|
const prettyHost = customHost || 'localhost';
|
|
59
62
|
|
|
60
|
-
// use the gzipped bundle
|
|
61
|
-
app.get('*.js', (req, res, next) => {
|
|
62
|
-
req.url += '.gz';
|
|
63
|
-
res.set('Content-Encoding', 'gzip');
|
|
64
|
-
next();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
63
|
// Start your app.
|
|
68
64
|
app.listen(port, host, async (err) => {
|
|
69
65
|
if (err) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const webpack = require('webpack');
|
|
2
|
-
const
|
|
2
|
+
const expressStaticGzip = require('express-static-gzip');
|
|
3
3
|
const webpackDevMiddleware = require('webpack-dev-middleware');
|
|
4
4
|
const webpackHotMiddleware = require('webpack-hot-middleware');
|
|
5
5
|
const { sendFileWithCSPNonce } = require('../csp');
|
|
@@ -25,7 +25,7 @@ module.exports = function addDevMiddlewares(app, webpackConfig) {
|
|
|
25
25
|
heartbeat: 10 * 1000,
|
|
26
26
|
}),
|
|
27
27
|
);
|
|
28
|
-
app.use(
|
|
28
|
+
app.use(expressStaticGzip('cdn'));
|
|
29
29
|
|
|
30
30
|
const { outputFileSystem } = (middleware || {}).context || {};
|
|
31
31
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
|
-
const express = require('express');
|
|
3
2
|
const compression = require('compression');
|
|
3
|
+
const expressStaticGzip = require('express-static-gzip');
|
|
4
4
|
const { sendFileWithCSPNonce } = require('../csp');
|
|
5
5
|
|
|
6
6
|
module.exports = function addProdMiddlewares(app, options) {
|
|
@@ -17,8 +17,15 @@ module.exports = function addProdMiddlewares(app, options) {
|
|
|
17
17
|
sendFileWithCSPNonce({ outputPath, res });
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
-
app.use(
|
|
21
|
-
|
|
20
|
+
app.use(
|
|
21
|
+
publicPath,
|
|
22
|
+
expressStaticGzip(outputPath, {
|
|
23
|
+
index: false,
|
|
24
|
+
enableBrotli: true,
|
|
25
|
+
orderPreference: ['br'],
|
|
26
|
+
}),
|
|
27
|
+
);
|
|
28
|
+
app.use(expressStaticGzip('cdn'));
|
|
22
29
|
|
|
23
30
|
app.get('*', (req, res) => sendFileWithCSPNonce({ outputPath, res }));
|
|
24
31
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const { getAppConfig, getAssetPath } = require('../webpack/helpers');
|
|
3
|
+
const swcrcConfig = require('../transpile/swcrc.config.js');
|
|
3
4
|
|
|
4
5
|
const name = '@elliemae/pui-cli';
|
|
5
6
|
const rootDir = path.join('<rootDir>', 'node_modules', name);
|
|
@@ -42,8 +43,8 @@ const jestConfig = {
|
|
|
42
43
|
'!app/*/RbGenerated*/*.{js, ts, jsx, tsx}',
|
|
43
44
|
'!app/index.{js, ts, jsx, tsx}',
|
|
44
45
|
'!app/global-styles.{js, ts, jsx, tsx}',
|
|
45
|
-
'!app
|
|
46
|
-
'!lib
|
|
46
|
+
'!app/**/loadable.{js, ts, jsx, tsx}',
|
|
47
|
+
'!lib/**/loadable.{js, ts, jsx, tsx}',
|
|
47
48
|
],
|
|
48
49
|
coverageThreshold: {
|
|
49
50
|
// Todo: enable the coverage threshold later
|
|
@@ -66,17 +67,35 @@ const jestConfig = {
|
|
|
66
67
|
'@elliemae/pui-user-monitoring': `${getRootDir()}/lib/testing/mocks/pui-user-monitoring.js`,
|
|
67
68
|
'@elliemae/pui-app-loader': `${getRootDir()}/lib/testing/mocks/pui-app-loader.js`,
|
|
68
69
|
'@elliemae/pui-diagnostics': `${getRootDir()}/lib/testing/mocks/pui-diagnostics.js`,
|
|
70
|
+
'react-spring/web': '<rootDir>/node_modules/react-spring/web.cjs.js',
|
|
71
|
+
'react-spring/renderprops':
|
|
72
|
+
'<rootDir>/node_modules/react-spring/renderprops.cjs.js',
|
|
69
73
|
'styled-components':
|
|
70
74
|
'<rootDir>/node_modules/styled-components/dist/styled-components.cjs.js',
|
|
71
75
|
},
|
|
76
|
+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
|
|
72
77
|
setupFilesAfterEnv: [`${getRootDir()}/lib/testing/setup-tests.js`],
|
|
73
78
|
setupFiles: ['raf/polyfill', 'whatwg-fetch'],
|
|
74
|
-
testRegex: '(app|lib).*/tests/.*\\.test\\.
|
|
79
|
+
testRegex: '(app|lib).*/tests/.*\\.test\\.[jt]sx?$',
|
|
75
80
|
snapshotSerializers: [],
|
|
76
81
|
testResultsProcessor: 'jest-sonar-reporter',
|
|
82
|
+
resolver: path.resolve(__dirname, './resolver.js'),
|
|
83
|
+
transform: {
|
|
84
|
+
'^.+\\.[jt]sx?$': ['@swc/jest', swcrcConfig],
|
|
85
|
+
},
|
|
86
|
+
// transform: {
|
|
87
|
+
// '^.+\\.[jt]sx?$': [
|
|
88
|
+
// 'esbuild-jest',
|
|
89
|
+
// {
|
|
90
|
+
// target: 'es2020',
|
|
91
|
+
// loaders: {
|
|
92
|
+
// '.js': 'jsx',
|
|
93
|
+
// },
|
|
94
|
+
// },
|
|
95
|
+
// ],
|
|
96
|
+
// },
|
|
77
97
|
transformIgnorePatterns: [
|
|
78
|
-
'node_modules/(?!(
|
|
79
|
-
'node_modules/@elliemae/em-platform-document-viewer',
|
|
98
|
+
'node_modules/(?!(.*@elliemae/pui-cli|lodash-es|react-select|react-dates)/)',
|
|
80
99
|
],
|
|
81
100
|
globals: {
|
|
82
101
|
APP_CONFIG: getAppConfig(),
|
|
@@ -86,8 +105,8 @@ const jestConfig = {
|
|
|
86
105
|
testEnvironment: 'jsdom',
|
|
87
106
|
};
|
|
88
107
|
|
|
89
|
-
if (isReactModule)
|
|
108
|
+
if (isReactModule && jestConfig.setupFilesAfterEnv)
|
|
90
109
|
jestConfig.setupFilesAfterEnv.push(
|
|
91
|
-
`${getRootDir()}/lib/testing/setup-
|
|
110
|
+
`${getRootDir()}/lib/testing/setup-react-env.js`,
|
|
92
111
|
);
|
|
93
112
|
module.exports = jestConfig;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
*
|
|
3
3
|
*/
|
|
4
|
-
export default
|
|
4
|
+
export default () => {
|
|
5
5
|
Object.defineProperty(window, 'matchMedia', {
|
|
6
6
|
value: () => ({
|
|
7
7
|
matches: false,
|
|
@@ -15,4 +15,4 @@ export default function () {
|
|
|
15
15
|
getPropertyValue: () => {},
|
|
16
16
|
}),
|
|
17
17
|
});
|
|
18
|
-
}
|
|
18
|
+
};
|
|
@@ -1,36 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
error: 'error',
|
|
21
|
-
audit: 'audit',
|
|
22
|
-
fatal: 'fatal',
|
|
23
|
-
},
|
|
24
|
-
Console() {
|
|
25
|
-
return {
|
|
26
|
-
log() {},
|
|
27
|
-
};
|
|
28
|
-
},
|
|
29
|
-
http() {
|
|
30
|
-
return {
|
|
31
|
-
log() {},
|
|
32
|
-
};
|
|
33
|
-
},
|
|
34
|
-
webvitals() {},
|
|
35
|
-
logUnhandledErrors() {},
|
|
1
|
+
export const logger = () => ({
|
|
2
|
+
setLogLevel() {},
|
|
3
|
+
setOptions() {},
|
|
4
|
+
info() {},
|
|
5
|
+
warn() {},
|
|
6
|
+
error() {},
|
|
7
|
+
trace() {},
|
|
8
|
+
debug() {},
|
|
9
|
+
audit() {},
|
|
10
|
+
fatal() {},
|
|
11
|
+
});
|
|
12
|
+
export const LogLevel = {
|
|
13
|
+
info: 'info',
|
|
14
|
+
debug: 'debug',
|
|
15
|
+
trace: 'trace',
|
|
16
|
+
warn: 'warn',
|
|
17
|
+
error: 'error',
|
|
18
|
+
audit: 'audit',
|
|
19
|
+
fatal: 'fatal',
|
|
36
20
|
};
|
|
21
|
+
export const Console = () => ({
|
|
22
|
+
log: () => {},
|
|
23
|
+
});
|
|
24
|
+
export const http = () => ({
|
|
25
|
+
log() {},
|
|
26
|
+
});
|
|
27
|
+
export const webvitals = () => {};
|
|
28
|
+
export const logUnhandledErrors = () => {};
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
startVirtualPageMonitoringWithAutoEnd: () => {},
|
|
5
|
-
};
|
|
1
|
+
export const setCustomUserData = () => {};
|
|
2
|
+
export const setCustomVirtualPageName = () => {};
|
|
3
|
+
export const startVirtualPageMonitoringWithAutoEnd = () => {};
|
package/lib/testing/mocks/svg.js
CHANGED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const resolutions = [
|
|
2
|
+
{
|
|
3
|
+
matcher: /\.jsx?$/i,
|
|
4
|
+
extensions: ['.tsx', '.ts'],
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
matcher: /\.mjs$/i,
|
|
8
|
+
extensions: ['.mts'],
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
matcher: /\.cjs$/i,
|
|
12
|
+
extensions: ['.cts'],
|
|
13
|
+
},
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
const resolveConfig = {
|
|
17
|
+
conditionNames: ['import', 'node', 'default'],
|
|
18
|
+
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json', '.node'],
|
|
19
|
+
modules: ['node_modules', 'app', 'lib'],
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const importResolver = require('enhanced-resolve').create.sync(resolveConfig);
|
|
23
|
+
const requireResolver = require('enhanced-resolve').create.sync({
|
|
24
|
+
...resolveConfig,
|
|
25
|
+
conditionNames: ['require', 'node', 'default'],
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
module.exports = (request, options) => {
|
|
29
|
+
let resolver = requireResolver;
|
|
30
|
+
if (options.conditions?.includes('import')) {
|
|
31
|
+
resolver = importResolver;
|
|
32
|
+
}
|
|
33
|
+
const resolution = resolutions.find(({ matcher }) => matcher.test(request));
|
|
34
|
+
if (resolution) {
|
|
35
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
36
|
+
for (const extension of resolution.extensions) {
|
|
37
|
+
try {
|
|
38
|
+
return resolver(
|
|
39
|
+
options.basedir,
|
|
40
|
+
request.replace(resolution.matcher, extension),
|
|
41
|
+
);
|
|
42
|
+
// eslint-disable-next-line no-empty
|
|
43
|
+
} catch {}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return resolver(options.basedir, request);
|
|
47
|
+
};
|
|
@@ -3,12 +3,35 @@
|
|
|
3
3
|
import 'core-js/stable';
|
|
4
4
|
import 'regenerator-runtime/runtime';
|
|
5
5
|
import '@testing-library/jest-dom/extend-expect';
|
|
6
|
-
import
|
|
6
|
+
import jestAxe from 'jest-axe';
|
|
7
7
|
import ResizeObserver from 'resize-observer-polyfill';
|
|
8
|
-
import addMatchMedia from './mocks/matchMedia';
|
|
9
|
-
import { logger } from './mocks/pui-diagnostics';
|
|
8
|
+
import addMatchMedia from './mocks/matchMedia.js';
|
|
9
|
+
import { logger } from './mocks/pui-diagnostics.js';
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
// eslint-disable-next-line no-console
|
|
12
|
+
const originalError = console.error;
|
|
13
|
+
// eslint-disable-next-line no-console
|
|
14
|
+
console.error = (...args) => {
|
|
15
|
+
const ignoreList = [
|
|
16
|
+
`Warning: Can't perform a React state update on an unmounted component`,
|
|
17
|
+
`Warning: Function components cannot be given refs`,
|
|
18
|
+
`Warning: Failed %s type:`,
|
|
19
|
+
`Warning: Invalid DOM property`,
|
|
20
|
+
`Warning: Each child in a list should have a unique`,
|
|
21
|
+
'Warning: Received `%s` for a non-boolean attribute',
|
|
22
|
+
'Warning: <%s /> is using incorrect casing.',
|
|
23
|
+
'Warning: The tag <%s> is unrecognized in this browser',
|
|
24
|
+
];
|
|
25
|
+
if (
|
|
26
|
+
ignoreList.find(
|
|
27
|
+
(ignoreMsg) => !!args.find((arg) => arg.includes?.(ignoreMsg)),
|
|
28
|
+
)
|
|
29
|
+
)
|
|
30
|
+
return false;
|
|
31
|
+
return originalError(...args);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
if (expect) expect.extend(jestAxe.toHaveNoViolations);
|
|
12
35
|
jest.setTimeout(60000);
|
|
13
36
|
|
|
14
37
|
const addElementToBody = (element) => {
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const esbuild = require('esbuild');
|
|
2
|
+
const fg = require('fast-glob');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { getPUIConfig } = require('../pui-config');
|
|
6
|
+
|
|
7
|
+
const { esBuild } = getPUIConfig();
|
|
8
|
+
|
|
9
|
+
const commonConfig = {
|
|
10
|
+
bundle: false,
|
|
11
|
+
target: esBuild.target,
|
|
12
|
+
loader: { '.js': 'jsx' },
|
|
13
|
+
mainFields: ['module', 'browser', 'main'],
|
|
14
|
+
inject: [path.resolve(__dirname, './react-shim.js')],
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const distFolder = 'dist';
|
|
18
|
+
|
|
19
|
+
const copyFiles = async ({ srcdir, outdir }) => {
|
|
20
|
+
const files = await fg([
|
|
21
|
+
`${srcdir}/**/*.*`,
|
|
22
|
+
`!${srcdir}/**/*.{js,jsx,ts,tsx,cjs,mjs}`,
|
|
23
|
+
]);
|
|
24
|
+
files.forEach((srcFilePath) => {
|
|
25
|
+
const destFilePath = srcFilePath.replace(srcdir, outdir);
|
|
26
|
+
fs.copyFileSync(srcFilePath, destFilePath);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const build = async ({ srcPath, commonJS }) => {
|
|
31
|
+
const inputFiles = [
|
|
32
|
+
`${srcPath}/**/*.{js,jsx,ts,tsx}`,
|
|
33
|
+
`!${srcPath}/**/*.test.{js,jsx,ts,tsx}`,
|
|
34
|
+
`!${srcPath}/**/*.stories.{js,jsx,ts,tsx}`,
|
|
35
|
+
`!${srcPath}/**/*.endpoint.{js,jsx,ts,tsx}`,
|
|
36
|
+
];
|
|
37
|
+
if (commonJS) {
|
|
38
|
+
const outdir = `${distFolder}/cjs`;
|
|
39
|
+
const commonJSEntryPoints = await fg(inputFiles);
|
|
40
|
+
await esbuild.build({
|
|
41
|
+
entryPoints: commonJSEntryPoints,
|
|
42
|
+
...commonConfig,
|
|
43
|
+
outdir,
|
|
44
|
+
format: 'cjs',
|
|
45
|
+
});
|
|
46
|
+
await copyFiles({ srcdir: srcPath, outdir });
|
|
47
|
+
} else {
|
|
48
|
+
const outdir = `${distFolder}/es`;
|
|
49
|
+
const entryPoints = await fg(
|
|
50
|
+
inputFiles.concat([`!${srcPath}/**/cjs/**/*.{js,jsx,ts,tsx}`]),
|
|
51
|
+
);
|
|
52
|
+
await esbuild.build({
|
|
53
|
+
entryPoints,
|
|
54
|
+
...commonConfig,
|
|
55
|
+
outdir,
|
|
56
|
+
format: 'esm',
|
|
57
|
+
});
|
|
58
|
+
await copyFiles({ srcdir: srcPath, outdir });
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
exports.esBuild = build;
|