diff --git a/babel.config.json b/babel.config.json new file mode 100644 index 000000000..86ef21087 --- /dev/null +++ b/babel.config.json @@ -0,0 +1,3 @@ +{ + "presets": ["@babel/preset-env", "@babel/preset-react"] +} diff --git a/modules/ppcp-blocks/resources/js/test/checkout-handler.test.js b/modules/ppcp-blocks/resources/js/test/checkout-handler.test.js new file mode 100644 index 000000000..933149bd0 --- /dev/null +++ b/modules/ppcp-blocks/resources/js/test/checkout-handler.test.js @@ -0,0 +1,6 @@ +import { render} from '@testing-library/react'; +import {CheckoutHandler} from "../Components/checkout-handler"; + +test('checkout handler', () => { + render( {}}/>) +}); diff --git a/package.json b/package.json index b66c7f165..3e8eaef2c 100644 --- a/package.json +++ b/package.json @@ -80,7 +80,7 @@ "pw-install": "yarn playwright install --with-deps", "pw-tests": "yarn playwright test", "pw-tests-headed": "yarn playwright test --headed", - "test:unit": "wp-scripts test-unit-js", + "test:unit": "wp-scripts test-unit-js --config ./tests/js/jest.config.json", "prebuild": "rm -rf ./vendor && find . -name 'node_modules' -type d -maxdepth 3 -exec rm -rf {} +", "build": "composer install --no-dev && yarn install && yarn run archive", "prearchive": "rm -rf $npm_package_name.zip", @@ -99,11 +99,13 @@ "uuid": "^9.0.1" }, "devDependencies": { + "@babel/plugin-proposal-class-properties": "^7.18.6", "@testing-library/dom": "^10.1.0", "@testing-library/jest-dom": "^6.4.6", "@testing-library/react": "^16.0.0", "@wordpress/element": "^6.1.0", "@wordpress/scripts": "^28.0.0", + "babel-plugin-explicit-exports-references": "^1.0.2", "jquery": "^3.7.1", "react-dom": "^18.3.1" } diff --git a/tests/js/jest.config.json b/tests/js/jest.config.json new file mode 100644 index 000000000..2529b5696 --- /dev/null +++ b/tests/js/jest.config.json @@ -0,0 +1,17 @@ +{ + "preset": "@wordpress/jest-preset-default", + "rootDir": "../../", + "moduleDirectories": [ "node_modules" ], + "moduleNameMapper": { + "^react$": "/node_modules/react", + "^react-dom$": "/node_modules/react-dom" + }, + "testPathIgnorePatterns": [ + "/tests/", + "/node_modules/", + "/vendor/" + ], + "transform": { + "^.+\\.(js|ts|tsx)$": "/tests/js/jestPreprocess.js" + } +} diff --git a/tests/js/jestPreprocess.js b/tests/js/jestPreprocess.js new file mode 100644 index 000000000..cbd6024ed --- /dev/null +++ b/tests/js/jestPreprocess.js @@ -0,0 +1,10 @@ +const babelOptions = { + presets: [ '@babel/preset-typescript', '@wordpress/babel-preset-default' ], + plugins: [ + 'explicit-exports-references', + '@babel/plugin-proposal-class-properties', + ], +}; + +module.exports = + require( 'babel-jest' ).default.createTransformer( babelOptions ); diff --git a/yarn.lock b/yarn.lock index 152d59ab5..bf2a42ada 100644 --- a/yarn.lock +++ b/yarn.lock @@ -28,7 +28,7 @@ resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.24.7.tgz#d23bbea508c3883ba8251fb4164982c36ea577ed" integrity sha512-qJzAIcv03PyaWqxRgO4mSU3lihncDT296vnyuE2O8uA4w3UHWI4S3hgeZd1L8W1Bft40w9JxJ2b412iDUFFRhw== -"@babel/core@^7.11.6", "@babel/core@^7.12.3", "@babel/core@^7.16.0", "@babel/core@^7.21.3", "@babel/core@^7.23.9": +"@babel/core@^7.11.6", "@babel/core@^7.12.3", "@babel/core@^7.13.15", "@babel/core@^7.16.0", "@babel/core@^7.21.3", "@babel/core@^7.23.9": version "7.24.7" resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.24.7.tgz#b676450141e0b52a3d43bc91da86aa608f950ac4" integrity sha512-nykK+LEK86ahTkX/3TgauT0ikKoNCfKHEaZYTUVupJdTLzGNvrblu4u6fa7DhZONAltdf8e662t/abY8idrd/g== @@ -94,7 +94,7 @@ lru-cache "^5.1.1" semver "^6.3.1" -"@babel/helper-create-class-features-plugin@^7.24.7": +"@babel/helper-create-class-features-plugin@^7.18.6", "@babel/helper-create-class-features-plugin@^7.24.7": version "7.24.7" resolved "https://registry.yarnpkg.com/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.24.7.tgz#2eaed36b3a1c11c53bdf80d53838b293c52f5b3b" integrity sha512-kTkaDl7c9vO80zeX1rJxnuRpEsD5tA81yh11X1gQo+PhSti3JS+7qeZo9U4RHobKRiFPKaGK3svUAeb8D0Q7eg== @@ -311,6 +311,14 @@ "@babel/helper-environment-visitor" "^7.24.7" "@babel/helper-plugin-utils" "^7.24.7" +"@babel/plugin-proposal-class-properties@^7.18.6": + version "7.18.6" + resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-class-properties/-/plugin-proposal-class-properties-7.18.6.tgz#b110f59741895f7ec21a6fff696ec46265c446a3" + integrity sha512-cumfXOF0+nzZrrN8Rf0t7M+tF6sZc7vhQwYQck9q1/5w2OExlD+b4v4RpMJFaV1Z7WcDRgO6FqvxqxGlwo+RHQ== + dependencies: + "@babel/helper-create-class-features-plugin" "^7.18.6" + "@babel/helper-plugin-utils" "^7.18.6" + "@babel/plugin-proposal-private-property-in-object@7.21.0-placeholder-for-preset-env.2": version "7.21.0-placeholder-for-preset-env.2" resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.0-placeholder-for-preset-env.2.tgz#7844f9289546efa9febac2de4cfe358a050bd703" @@ -1044,7 +1052,7 @@ dependencies: regenerator-runtime "^0.14.0" -"@babel/template@^7.24.7", "@babel/template@^7.3.3": +"@babel/template@^7.12.13", "@babel/template@^7.24.7", "@babel/template@^7.3.3": version "7.24.7" resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.24.7.tgz#02efcee317d0609d2c07117cb70ef8fb17ab7315" integrity sha512-jYqfPrU9JTF0PmPy1tLYHW4Mp4KlgxJD9l2nP9fD6yT/ICi554DmrWBAEYpIelzjHf1msDP3PxJIRt/nFNfBig== @@ -1069,7 +1077,7 @@ debug "^4.3.1" globals "^11.1.0" -"@babel/types@^7.0.0", "@babel/types@^7.20.7", "@babel/types@^7.21.3", "@babel/types@^7.24.7", "@babel/types@^7.3.3", "@babel/types@^7.4.4": +"@babel/types@^7.0.0", "@babel/types@^7.13.14", "@babel/types@^7.20.7", "@babel/types@^7.21.3", "@babel/types@^7.24.7", "@babel/types@^7.3.3", "@babel/types@^7.4.4": version "7.24.7" resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.24.7.tgz#6027fe12bc1aa724cd32ab113fb7f1988f1f66f2" integrity sha512-XEFXSlxiG5td2EJRe8vOmRbaXVgfcBlszKujvVmWIK/UpywWljQCfzAv3RQCGujWQ1RD4YYWEAqDXfuJiy8f5Q== @@ -3061,6 +3069,16 @@ babel-loader@^8.2.3: make-dir "^3.1.0" schema-utils "^2.6.5" +babel-plugin-explicit-exports-references@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/babel-plugin-explicit-exports-references/-/babel-plugin-explicit-exports-references-1.0.2.tgz#47102fcb5c97f5d54dcc03a99685d90c2ab564cf" + integrity sha512-z+weAyF11Mr1azXIR5pfhAeXeK8ZvacXSKgPLGdwBoR7efyqnUxYvlGUny7eHZxAO/Q1C2O1+xO9lwgGPDaBlw== + dependencies: + "@babel/core" "^7.13.15" + "@babel/template" "^7.12.13" + "@babel/types" "^7.13.14" + debug "^4.3.1" + babel-plugin-istanbul@^6.1.1: version "6.1.1" resolved "https://registry.yarnpkg.com/babel-plugin-istanbul/-/babel-plugin-istanbul-6.1.1.tgz#fa88ec59232fd9b4e36dbbc540a8ec9a9b47da73"