@oracle/oraclejet-jest-preset 13.0.0 → 14.0.0
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 +14 -0
- package/package.json +33 -9
- package/src/babel.js +23 -22
- package/src/loaders/ojL10n-loader.js +12 -5
- package/src/mocks/ojlocaledata.js +4 -7
- package/src/mocks/ojthemeutils.js +15 -8
- package/src/mocks/ojtimezonedata.js +10 -0
- package/src/mocks/ojtranslation.js +11 -3
- package/src/preset.js +7 -4
- package/src/utils.js +17 -0
package/README.md
ADDED
package/package.json
CHANGED
|
@@ -1,24 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oracle/oraclejet-jest-preset",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "14.0.0",
|
|
4
4
|
"description": "JET preset for Jest testing",
|
|
5
5
|
"main": "jest-preset.js",
|
|
6
6
|
"author": "",
|
|
7
7
|
"license": "UPL-1.0",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"clean": "rimraf test_results",
|
|
10
|
+
"test": "jest -c test/jest.config.js",
|
|
11
|
+
"test:debug": "yarn run --inspect jest -i --testTimeout=999999"
|
|
12
|
+
},
|
|
8
13
|
"dependencies": {
|
|
9
|
-
"babel-
|
|
10
|
-
"babel-
|
|
14
|
+
"@babel/plugin-proposal-decorators": "^7.18.10",
|
|
15
|
+
"babel-jest": "^27.2.0",
|
|
16
|
+
"babel-plugin-transform-amd-to-commonjs": "^1.6.0",
|
|
11
17
|
"css": "^3.0.0",
|
|
12
|
-
"
|
|
18
|
+
"identity-obj-proxy": "~3.0.0",
|
|
19
|
+
"jest-preset-preact": "^4.0.5",
|
|
13
20
|
"jest-raw-loader": "^1.0.1",
|
|
14
|
-
"preact-render-to-string": "^5.1.
|
|
21
|
+
"preact-render-to-string": "^5.1.19"
|
|
15
22
|
},
|
|
16
23
|
"peerDependencies": {
|
|
17
|
-
"
|
|
18
|
-
"
|
|
24
|
+
"@oracle/oraclejet": ">=14.x",
|
|
25
|
+
"jest": "27.x"
|
|
19
26
|
},
|
|
20
27
|
"files": [
|
|
21
|
-
"
|
|
28
|
+
"jest-preset.js",
|
|
22
29
|
"src/**"
|
|
23
|
-
]
|
|
30
|
+
],
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@jest/globals": "27.5.1",
|
|
33
|
+
"@oracle/oraclejet": "link:../oraclejet/dist",
|
|
34
|
+
"@oracle/oraclejet-test-utils": "workspace:^",
|
|
35
|
+
"@testing-library/preact": "^2.0.1",
|
|
36
|
+
"@testing-library/user-event": "~13.5.0",
|
|
37
|
+
"@types/jest": "27.5.1",
|
|
38
|
+
"copyfiles": "^2.4.1",
|
|
39
|
+
"hammerjs": "2.0.8",
|
|
40
|
+
"jest": "27.5.1",
|
|
41
|
+
"jquery": "3.6.1",
|
|
42
|
+
"preact": "10.11.3",
|
|
43
|
+
"ramda": "~0.27.2",
|
|
44
|
+
"regenerator-runtime": "^0.13.9",
|
|
45
|
+
"resize-observer-polyfill": "^1.5.1",
|
|
46
|
+
"rimraf": "3.0.2"
|
|
47
|
+
}
|
|
24
48
|
}
|
package/src/babel.js
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
const { default: babelJest } = require('babel-jest');
|
|
2
2
|
|
|
3
3
|
module.exports = babelJest.createTransformer({
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
4
|
+
presets: [
|
|
5
|
+
[
|
|
6
|
+
'@babel/preset-typescript',
|
|
7
|
+
{
|
|
8
|
+
jsxPragma: 'h'
|
|
9
|
+
}
|
|
10
|
+
],
|
|
11
|
+
'@babel/preset-env'
|
|
12
|
+
],
|
|
13
|
+
plugins: [
|
|
14
|
+
'babel-plugin-transform-amd-to-commonjs',
|
|
15
|
+
[
|
|
16
|
+
'@babel/plugin-transform-react-jsx',
|
|
17
|
+
{
|
|
18
|
+
runtime: 'automatic',
|
|
19
|
+
importSource: 'preact'
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
['@babel/plugin-proposal-decorators', { legacy: true }],
|
|
23
|
+
'@babel/plugin-proposal-class-properties'
|
|
24
|
+
],
|
|
25
|
+
babelrc: false,
|
|
26
|
+
configFile: false
|
|
26
27
|
});
|
|
@@ -18,7 +18,7 @@ const context = vm.createContext({
|
|
|
18
18
|
define: function(rb) {
|
|
19
19
|
// define({ ... })
|
|
20
20
|
if (arguments.length === 1) {
|
|
21
|
-
return rb;
|
|
21
|
+
return typeof rb === 'function' ? rb() : rb;
|
|
22
22
|
}
|
|
23
23
|
// define(['require', 'exports'], function(require, exports))
|
|
24
24
|
const exp = {};
|
|
@@ -37,9 +37,16 @@ module.exports = {
|
|
|
37
37
|
// Since the script runs in our context, assign it to "this.rb" so that we
|
|
38
38
|
// can retrieve it
|
|
39
39
|
const script = new vm.Script(`this.rb = ${content}`);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
try {
|
|
41
|
+
// Run in try/catch to process only AMD files. All other file types (CJS)
|
|
42
|
+
// will throw exception
|
|
43
|
+
script.runInContext(context);
|
|
44
|
+
// app resource bundles are underneath 'root'
|
|
45
|
+
// otherwise return entire bundle
|
|
46
|
+
const bundle = context.rb.root || context.rb;
|
|
47
|
+
bundle._ojLocale_ = 'en';
|
|
48
|
+
return `module.exports = ${JSON.stringify(context.rb.root || context.rb)}`;
|
|
49
|
+
} catch (ex) {}
|
|
50
|
+
return content;
|
|
44
51
|
}
|
|
45
52
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
const LocaleData = require(
|
|
2
|
-
const rootBundle = require(
|
|
3
|
-
const enBundle = require(
|
|
1
|
+
const LocaleData = require('@oracle/oraclejet/dist/js/libs/oj/debug/ojlocaledata');
|
|
2
|
+
const rootBundle = require('ojL10n!ojtranslations/nls/localeElements');
|
|
3
|
+
const enBundle = require('ojL10n!ojtranslations/nls/en/localeElements');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
_ojLocale_: "en",
|
|
7
|
-
});
|
|
8
|
-
LocaleData.setBundle(enBundle.main.en);
|
|
5
|
+
LocaleData.setBundle({ ...enBundle.main.en, ...rootBundle });
|
|
9
6
|
module.exports = LocaleData;
|
|
@@ -3,11 +3,11 @@ const fs = require('fs');
|
|
|
3
3
|
const path = require('path');
|
|
4
4
|
|
|
5
5
|
let rules;
|
|
6
|
-
let cssVars
|
|
6
|
+
let cssVars;
|
|
7
7
|
const fontFamilyJsons = {};
|
|
8
8
|
function parseRules() {
|
|
9
9
|
if (!rules) {
|
|
10
|
-
const cssPath =
|
|
10
|
+
const cssPath = require.resolve('__oj-theme-css');
|
|
11
11
|
const contents = fs.readFileSync(cssPath).toString();
|
|
12
12
|
rules = css.parse(contents).stylesheet.rules.filter((rule) => rule.selectors);
|
|
13
13
|
}
|
|
@@ -26,7 +26,10 @@ function parseJSONFromFontFamily(className) {
|
|
|
26
26
|
);
|
|
27
27
|
const ff = rule.declarations.find((decl) => decl.property === 'font-family');
|
|
28
28
|
// Remove !important and start/ending quotes
|
|
29
|
-
const ffValue = ff.value
|
|
29
|
+
const ffValue = ff.value
|
|
30
|
+
.replace(/\s*!important;?/, '')
|
|
31
|
+
.replace(/^'/, '')
|
|
32
|
+
.replace(/'$/, '');
|
|
30
33
|
config = fontFamilyJsons[className] = JSON.parse(ffValue);
|
|
31
34
|
}
|
|
32
35
|
return config;
|
|
@@ -34,15 +37,19 @@ function parseJSONFromFontFamily(className) {
|
|
|
34
37
|
|
|
35
38
|
function getCachedCSSVarValues(names) {
|
|
36
39
|
parseRules();
|
|
37
|
-
if (!cssVars
|
|
40
|
+
if (!cssVars) {
|
|
38
41
|
// Find all :root declarations
|
|
39
|
-
rules.
|
|
42
|
+
cssVars = rules.reduce((accum, rule) => {
|
|
40
43
|
if (rule.selectors.includes(':root')) {
|
|
41
|
-
|
|
44
|
+
return {
|
|
45
|
+
...accum,
|
|
46
|
+
...rule.declarations.reduce((acc2, decl) => ({ ...acc2, [decl.property]: decl }), {})
|
|
47
|
+
};
|
|
42
48
|
}
|
|
43
|
-
|
|
49
|
+
return accum;
|
|
50
|
+
}, {});
|
|
44
51
|
}
|
|
45
|
-
const matches =
|
|
52
|
+
const matches = names.map((name) => cssVars[name]).filter(Boolean);
|
|
46
53
|
// Remove leading/trailing quotes
|
|
47
54
|
return matches.map((match) => match.value.replace(/^'/, '').replace(/'$/, ''));
|
|
48
55
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const TimezoneData = require('@oracle/oraclejet/dist/js/libs/oj/debug/ojtimezonedata');
|
|
2
|
+
const rootData = require('ojL10n!ojtranslations/nls/timezoneData');
|
|
3
|
+
const enUsData = require('ojL10n!ojtranslations/nls/en-US/timezoneData');
|
|
4
|
+
const { deepMerge } = require('../utils');
|
|
5
|
+
|
|
6
|
+
const data = {};
|
|
7
|
+
deepMerge(data, rootData, enUsData);
|
|
8
|
+
TimezoneData.__mergeIntoLocaleElements(data);
|
|
9
|
+
|
|
10
|
+
module.exports = TimezoneData;
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
const Translation = require(
|
|
2
|
-
const rootTranslations = require(
|
|
1
|
+
const Translation = require('@oracle/oraclejet/dist/js/libs/oj/debug/ojtranslation');
|
|
2
|
+
const rootTranslations = require('ojL10n!ojtranslations/nls/ojtranslations');
|
|
3
3
|
|
|
4
4
|
Translation.setBundle(rootTranslations);
|
|
5
|
-
module.exports =
|
|
5
|
+
module.exports = {
|
|
6
|
+
...Translation,
|
|
7
|
+
setBundle: (bundle) => {
|
|
8
|
+
// Merge into rootTranslations
|
|
9
|
+
if (bundle !== rootTranslations) {
|
|
10
|
+
Object.assign(rootTranslations, bundle.root || bundle);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
package/src/preset.js
CHANGED
|
@@ -2,6 +2,9 @@ const jestPreset = require('jest-preset-preact');
|
|
|
2
2
|
const path = require('path');
|
|
3
3
|
|
|
4
4
|
const mappedModules = {
|
|
5
|
+
// Alias to allow ojthemeutils to fetch CSS w/o being intercepted by
|
|
6
|
+
// identify-obj-proxy mapping below
|
|
7
|
+
'^__oj-theme-css$': '@oracle/oraclejet/dist/css/redwood/oj-redwood.css',
|
|
5
8
|
// Noop style files
|
|
6
9
|
'^.+\\.(css|sass|scss|less)$': 'identity-obj-proxy',
|
|
7
10
|
'^css!.*': 'identity-obj-proxy',
|
|
@@ -19,16 +22,16 @@ const mappedModules = {
|
|
|
19
22
|
],
|
|
20
23
|
'ojL10n!./(.*)': './$1',
|
|
21
24
|
'ojL10n!ojtranslations/nls/(.*)': '@oracle/oraclejet/dist/js/libs/oj/resources/nls/$1',
|
|
22
|
-
'jqueryui-amd/(.*)': '@oracle/oraclejet/dist/js/libs/jquery/jqueryui-amd-1.13.
|
|
23
|
-
'@oracle/oraclejet-preact/(.*)': '@oracle/oraclejet
|
|
25
|
+
'jqueryui-amd/(.*)': '@oracle/oraclejet/dist/js/libs/jquery/jqueryui-amd-1.13.2/$1',
|
|
26
|
+
'@oracle/oraclejet-preact/(.*)': '@oracle/oraclejet-preact/cjs/$1'
|
|
24
27
|
};
|
|
25
28
|
|
|
26
29
|
Object.assign(jestPreset, {
|
|
27
30
|
modulePaths: ['@oracle/oraclejet/dist/js/libs/oj/'],
|
|
28
31
|
transform: {
|
|
29
|
-
|
|
32
|
+
[`\\${path.sep}resources\\${path.sep}nls\\${path.sep}`]: require.resolve('./loaders/ojL10n-loader'),
|
|
30
33
|
// Use our own Babel configuration
|
|
31
|
-
'^.+\\.(mjs|js|jsx|ts|tsx)$':
|
|
34
|
+
'^.+\\.(mjs|js|jsx|ts|tsx)$': require.resolve('./babel.js'),
|
|
32
35
|
// Handle loader.ts which loads component.json and expects string instead of
|
|
33
36
|
// JSON object
|
|
34
37
|
'component\\.json$': require.resolve('./loaders/json-text-loader'),
|
package/src/utils.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function deepMerge(o1, ...rest) {
|
|
2
|
+
if (!rest.length) {
|
|
3
|
+
return;
|
|
4
|
+
}
|
|
5
|
+
const o2 = rest.shift();
|
|
6
|
+
Object.keys(o2).forEach(k2 => {
|
|
7
|
+
const v2 = o2[k2];
|
|
8
|
+
if (typeof v2 === 'object' && k2 in o1) {
|
|
9
|
+
deepMerge(o1[k2], v2);
|
|
10
|
+
} else {
|
|
11
|
+
o1[k2] = v2;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
deepMerge(o1, ...rest);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = { deepMerge };
|