From 745951289f9bb92fecd25a831b87ed50709d035f Mon Sep 17 00:00:00 2001 From: ahnpnl <27772165+ahnpnl@users.noreply.github.com> Date: Wed, 11 Dec 2024 12:04:09 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20kulshekh?= =?UTF-8?q?ar/ts-jest@053102f024fe40ad122edb9c119e61113b074489=20?= =?UTF-8?q?=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 404.html | 4 ++-- assets/js/{00e7239c.83cf3479.js => 00e7239c.0c995c08.js} | 2 +- assets/js/{0259e2f2.c84f259b.js => 0259e2f2.b2bfac7c.js} | 2 +- assets/js/{03be7dae.50acd6db.js => 03be7dae.00559958.js} | 2 +- assets/js/{057d33b8.62e2233c.js => 057d33b8.93d2c767.js} | 2 +- assets/js/{06fbaa8e.57ac1f62.js => 06fbaa8e.61528603.js} | 2 +- assets/js/{07a7640f.abff013a.js => 07a7640f.c2323d27.js} | 2 +- assets/js/{0833143f.2817f5a6.js => 0833143f.52063431.js} | 2 +- assets/js/{093c23a0.1daed7f6.js => 093c23a0.4144588c.js} | 2 +- assets/js/{0a51ecf3.bfe4da1e.js => 0a51ecf3.be2dc629.js} | 2 +- assets/js/{0b2fcab7.524bcc94.js => 0b2fcab7.a6171f76.js} | 2 +- assets/js/{0d0f47fc.66e804d6.js => 0d0f47fc.1ac99fc2.js} | 2 +- assets/js/{10aeaaf3.fea17a78.js => 10aeaaf3.85aa8f82.js} | 2 +- assets/js/{1165ba55.6aa22ae8.js => 1165ba55.79b100ec.js} | 2 +- assets/js/{12292045.14a6c846.js => 12292045.5d460baa.js} | 2 +- assets/js/{15c7296a.f02b1818.js => 15c7296a.b10729cc.js} | 2 +- assets/js/{16ada0e2.5d9aea68.js => 16ada0e2.e08794d1.js} | 2 +- assets/js/{16bac89a.14497471.js => 16bac89a.7f86c6eb.js} | 2 +- assets/js/{1854c3e7.d414a6fb.js => 1854c3e7.40243a56.js} | 2 +- assets/js/{1917a510.aceaa1a7.js => 1917a510.5ab3afc8.js} | 2 +- assets/js/{19f0fee7.f9d853a2.js => 19f0fee7.8a32259e.js} | 2 +- assets/js/{1ca5b1f2.7b876712.js => 1ca5b1f2.44bf028b.js} | 2 +- assets/js/{2145bebc.378525df.js => 2145bebc.68b79213.js} | 2 +- assets/js/{22e01789.d0575031.js => 22e01789.40ec38ee.js} | 2 +- assets/js/{22f8c605.97329a1f.js => 22f8c605.cd0013a5.js} | 2 +- assets/js/{2331e073.321c45e4.js => 2331e073.67cd78ff.js} | 2 +- assets/js/{2338618e.50f7fb38.js => 2338618e.edd2aa5f.js} | 2 +- assets/js/{24991caa.6876bd74.js => 24991caa.97adaac5.js} | 2 +- assets/js/{265d7427.2fb79e7b.js => 265d7427.45a293f1.js} | 2 +- assets/js/{270520cb.66d198dc.js => 270520cb.387ac587.js} | 2 +- assets/js/{295b567d.a71774d7.js => 295b567d.47624169.js} | 2 +- assets/js/{2a3bd03a.8879b397.js => 2a3bd03a.3487bf7c.js} | 2 +- assets/js/{2b68f68f.c5eeb725.js => 2b68f68f.411a7201.js} | 2 +- assets/js/{2b77ff19.ff8f122b.js => 2b77ff19.7d69ff37.js} | 2 +- assets/js/{2b94ed59.d675dd5a.js => 2b94ed59.5d2ddf62.js} | 2 +- assets/js/{2bccb399.51fe225e.js => 2bccb399.5edbe13a.js} | 2 +- assets/js/{2c53b5e4.3589b250.js => 2c53b5e4.e23fa1b0.js} | 2 +- assets/js/{2d143bed.70765e71.js => 2d143bed.a8f1abb0.js} | 2 +- assets/js/{2e89f3c4.6f967198.js => 2e89f3c4.01abed72.js} | 2 +- assets/js/{304054d0.b6c2bc75.js => 304054d0.338556f9.js} | 2 +- assets/js/{334e0bf3.b5f04685.js => 334e0bf3.a900e034.js} | 2 +- assets/js/{3432663a.4f4acd85.js => 3432663a.9cff8df9.js} | 2 +- assets/js/{35779d9e.1967fc1e.js => 35779d9e.e35fa0f5.js} | 2 +- assets/js/{35ce71d5.c5787073.js => 35ce71d5.1ceeb43b.js} | 2 +- assets/js/{3787ba46.79103c8d.js => 3787ba46.3187f2ee.js} | 2 +- assets/js/{3bfdd655.815c18b5.js => 3bfdd655.50e26fcc.js} | 2 +- assets/js/{3e930f87.764f2b98.js => 3e930f87.eaf4b848.js} | 2 +- assets/js/{4040fa6b.96207318.js => 4040fa6b.9ea385db.js} | 2 +- assets/js/{44207808.3a269b4f.js => 44207808.8f0ac8c9.js} | 2 +- assets/js/{44d840ac.741a6c7e.js => 44d840ac.9f1c89dc.js} | 2 +- assets/js/{4aabdf82.d312f6b1.js => 4aabdf82.2a45d1cb.js} | 2 +- assets/js/{4c23203f.72c02dac.js => 4c23203f.ae730044.js} | 2 +- assets/js/{4c757249.9bb387a9.js => 4c757249.c1884e45.js} | 2 +- assets/js/{4d54d076.0dbbf9af.js => 4d54d076.d01053ce.js} | 2 +- assets/js/{4dd3fb5c.fb642566.js => 4dd3fb5c.da93f493.js} | 2 +- assets/js/{4e0c07c5.4112f062.js => 4e0c07c5.57eedcdd.js} | 2 +- assets/js/{5316ff60.5138fd7c.js => 5316ff60.09d0f6fe.js} | 2 +- assets/js/{544d8072.6eddd2c9.js => 544d8072.4881b7d6.js} | 2 +- assets/js/{54ceb25f.daee3545.js => 54ceb25f.17d4f1b4.js} | 2 +- assets/js/{54f44165.7c5a3f91.js => 54f44165.d90b0204.js} | 2 +- assets/js/{5bf3837a.62777e91.js => 5bf3837a.e9c81638.js} | 2 +- assets/js/{61b42bb5.754d1be0.js => 61b42bb5.539f1df0.js} | 2 +- assets/js/{629085c0.5f85dd08.js => 629085c0.97393345.js} | 2 +- assets/js/{6625be2a.b983ec8c.js => 6625be2a.de300dce.js} | 2 +- assets/js/{673550c0.c16d574d.js => 673550c0.5a99e13d.js} | 2 +- assets/js/{6789ef91.1bfe1b39.js => 6789ef91.31fd45fd.js} | 2 +- assets/js/{684ec830.9fd6bfb9.js => 684ec830.fbea694e.js} | 2 +- assets/js/{6bc4332d.639b5dee.js => 6bc4332d.c40d1ab1.js} | 2 +- assets/js/{6cdc57e1.57b80edb.js => 6cdc57e1.27f28efa.js} | 2 +- assets/js/{6f04af8d.af15916e.js => 6f04af8d.77c90ed6.js} | 2 +- assets/js/{6f4d8994.117a0347.js => 6f4d8994.59d7b33c.js} | 2 +- assets/js/{6f82a5f4.4fafb087.js => 6f82a5f4.1082f97a.js} | 2 +- assets/js/{7335c74d.c31a2be6.js => 7335c74d.d595bd82.js} | 2 +- assets/js/{73f5a02c.77733def.js => 73f5a02c.33e8cb11.js} | 2 +- assets/js/{75ab14ad.eedd6538.js => 75ab14ad.c68fd977.js} | 2 +- assets/js/{78f0a226.fcab7721.js => 78f0a226.3bd0ffa6.js} | 2 +- assets/js/{7aac82f3.f98a61f2.js => 7aac82f3.11f9b301.js} | 2 +- assets/js/{7b562fc7.d3988519.js => 7b562fc7.b7aa5465.js} | 2 +- assets/js/{7d1a64ae.a6037b4f.js => 7d1a64ae.4f6fa23f.js} | 2 +- assets/js/{7dafce35.8f740fa3.js => 7dafce35.6c17d5d2.js} | 2 +- assets/js/{7ec61308.9c63e66e.js => 7ec61308.e2b86301.js} | 2 +- assets/js/{801c4327.10205da7.js => 801c4327.c006a379.js} | 2 +- assets/js/{850a2979.647ee6bf.js => 850a2979.ad40f081.js} | 2 +- assets/js/{86b5844b.d350fa07.js => 86b5844b.f61f80de.js} | 2 +- assets/js/{8b2f9623.cd44d226.js => 8b2f9623.f045538d.js} | 2 +- assets/js/{8b622911.ec34731d.js => 8b622911.633e729a.js} | 2 +- assets/js/{8cf61ec4.18a24356.js => 8cf61ec4.a78c37c1.js} | 2 +- assets/js/{8d536cde.a8645fee.js => 8d536cde.26af3277.js} | 2 +- assets/js/{8e5d45d9.93e6e394.js => 8e5d45d9.849fbe21.js} | 2 +- assets/js/{8e81f9bb.a7990d5d.js => 8e81f9bb.d4682633.js} | 2 +- assets/js/{902acc05.763dfe6c.js => 902acc05.f0269b39.js} | 2 +- assets/js/{90645308.39c8de4b.js => 90645308.49eba68d.js} | 2 +- assets/js/{9226f379.a45c386e.js => 9226f379.5f1c5b18.js} | 2 +- assets/js/{96f7df01.8bfb600d.js => 96f7df01.48c01edb.js} | 2 +- assets/js/{9762b2e9.a60a5583.js => 9762b2e9.c07ce416.js} | 2 +- assets/js/{981dc414.57664b9f.js => 981dc414.d0180d50.js} | 2 +- assets/js/{9920b385.f93e0231.js => 9920b385.c2b915d3.js} | 2 +- assets/js/{9d036230.992329cf.js => 9d036230.f9704aa5.js} | 2 +- assets/js/{9ed06f50.296535f3.js => 9ed06f50.04a0976b.js} | 2 +- assets/js/{a09c2993.e6b9df8d.js => a09c2993.bdfd098b.js} | 2 +- assets/js/{a132b5de.645f7642.js => a132b5de.53d8d570.js} | 2 +- assets/js/{a21658d9.27d7fd56.js => a21658d9.f60aa266.js} | 2 +- assets/js/{a5ea8355.63e9e00c.js => a5ea8355.2199c8e1.js} | 2 +- assets/js/{a6267c3c.9fe1c460.js => a6267c3c.bf4e5e2b.js} | 2 +- assets/js/{a7423e3b.47f3318d.js => a7423e3b.635b1547.js} | 2 +- assets/js/{a7bc29db.005cdfe9.js => a7bc29db.e33e8aff.js} | 2 +- assets/js/{a8c654d7.ed76a70f.js => a8c654d7.6ecb388a.js} | 2 +- assets/js/{a8e3f14e.c57728a2.js => a8e3f14e.667ab091.js} | 2 +- assets/js/{aaf1bd4c.a76bf8b2.js => aaf1bd4c.33ec191c.js} | 2 +- assets/js/{ae1ffb77.e2a0d769.js => ae1ffb77.bb67cfb5.js} | 2 +- assets/js/{aeb5491d.11795c71.js => aeb5491d.2140da85.js} | 2 +- assets/js/{aeb823d8.e763955c.js => aeb823d8.f4474cf0.js} | 2 +- assets/js/{afb030c9.0176420a.js => afb030c9.cd6a94fc.js} | 2 +- assets/js/{b317f538.6b770618.js => b317f538.35c80c6c.js} | 2 +- assets/js/{b519512b.be96fda8.js => b519512b.18577b7e.js} | 2 +- assets/js/{b72fc7f8.205d41b7.js => b72fc7f8.69e0097e.js} | 2 +- assets/js/{b809b403.4d8874bb.js => b809b403.a5ae287c.js} | 2 +- assets/js/{b96776d9.c20e4410.js => b96776d9.c3b55621.js} | 2 +- assets/js/{bdf18d96.ef8ea76d.js => bdf18d96.26b56a84.js} | 2 +- assets/js/{bdfec613.fae4d7a9.js => bdfec613.dee9370f.js} | 2 +- assets/js/{bf341476.28157d87.js => bf341476.06c38444.js} | 2 +- assets/js/{c010a830.565e8076.js => c010a830.7a17d40e.js} | 2 +- assets/js/{c1932cab.7674b66d.js => c1932cab.28f8c650.js} | 2 +- assets/js/{c1a7450f.47d4c4ee.js => c1a7450f.bc600371.js} | 2 +- assets/js/{c6326909.213084ed.js => c6326909.a8d572e1.js} | 2 +- assets/js/{c8c88a41.06eff6cf.js => c8c88a41.444eb5d2.js} | 2 +- assets/js/{c8eced56.2b96d068.js => c8eced56.d8927fa4.js} | 2 +- assets/js/{ceaad8ca.26b23793.js => ceaad8ca.7a2881e9.js} | 2 +- assets/js/{cf5c42a2.595bac99.js => cf5c42a2.aaa08e62.js} | 2 +- assets/js/{cffdf1e5.cf2f418e.js => cffdf1e5.1d9ce4e5.js} | 2 +- assets/js/{d0e697d4.c6440020.js => d0e697d4.8469c21f.js} | 2 +- assets/js/{d296dded.f75bff98.js => d296dded.e85b0aff.js} | 2 +- assets/js/{d3b43630.fcc5105a.js => d3b43630.eccf12e3.js} | 2 +- assets/js/{d4836a8e.b1763707.js => d4836a8e.49a40161.js} | 2 +- assets/js/{d4a6dd78.ebdffa88.js => d4a6dd78.99b839a8.js} | 2 +- assets/js/{d6f9473b.1f6aa8d3.js => d6f9473b.4ea96a3d.js} | 2 +- assets/js/{d8357ecf.29f91670.js => d8357ecf.f1f3fca7.js} | 2 +- assets/js/{d9f7da4b.16f670ec.js => d9f7da4b.d4b6ce02.js} | 2 +- assets/js/{da431c38.1b5c02ee.js => da431c38.df55fcc1.js} | 2 +- assets/js/{dabdf990.2836a489.js => dabdf990.47a863fa.js} | 2 +- assets/js/{db49ae54.98f92ebe.js => db49ae54.6c64bd98.js} | 2 +- assets/js/{db795cf2.039b2323.js => db795cf2.3fa12001.js} | 2 +- assets/js/{dcbdd84f.b89413b1.js => dcbdd84f.cd175312.js} | 2 +- assets/js/{e3a856ae.e046cbac.js => e3a856ae.f4179db3.js} | 2 +- assets/js/{e5e34c6b.34d2aa10.js => e5e34c6b.83cffe15.js} | 2 +- assets/js/{e8085380.1ce58536.js => e8085380.3c65ab32.js} | 2 +- assets/js/{e87a3571.9597891d.js => e87a3571.0c980777.js} | 2 +- assets/js/{e8b13364.c13e2b25.js => e8b13364.71f5c781.js} | 2 +- assets/js/{eabdbf07.22b244a5.js => eabdbf07.5410c020.js} | 2 +- assets/js/{ec6c7123.93ae7b87.js => ec6c7123.8810b94a.js} | 2 +- assets/js/{f01607c0.a408f628.js => f01607c0.cdf147cf.js} | 2 +- assets/js/{f0683fd0.2befdc34.js => f0683fd0.043633fc.js} | 2 +- assets/js/{f154e663.b0212b7d.js => f154e663.fff8a972.js} | 2 +- assets/js/{f298e69b.70fafe25.js => f298e69b.4ecb8a66.js} | 2 +- assets/js/{f371827f.04a303bd.js => f371827f.8009cbda.js} | 2 +- assets/js/{f4dd4a52.bbf579b7.js => f4dd4a52.b13354ac.js} | 2 +- assets/js/{f6605416.f4cc3ff6.js => f6605416.777896e5.js} | 2 +- assets/js/{f6aab920.88ecf1a3.js => f6aab920.23d6e4b0.js} | 2 +- assets/js/{f6f550ec.c49076a5.js => f6f550ec.6ebd70e3.js} | 2 +- assets/js/{f7416098.6d7831a2.js => f7416098.99e20882.js} | 2 +- assets/js/{f7862b07.8de16ae5.js => f7862b07.88c0d675.js} | 2 +- assets/js/{f7b7430f.c4d24c44.js => f7b7430f.0b7a9f59.js} | 2 +- assets/js/{f7cb2af4.4584226e.js => f7cb2af4.99a450db.js} | 2 +- assets/js/{f8fb2427.a69eb55c.js => f8fb2427.6a6c567e.js} | 2 +- assets/js/{fa061f97.c83784db.js => fa061f97.1355d829.js} | 2 +- assets/js/{fb1b7a48.74274200.js => fb1b7a48.b5e4f6ba.js} | 2 +- assets/js/{fc43d853.45796344.js => fc43d853.cb9c3261.js} | 2 +- assets/js/{fc80686b.b18b0112.js => fc80686b.d9f583eb.js} | 2 +- assets/js/{fdcb7476.feb6962b.js => fdcb7476.0782afd3.js} | 2 +- assets/js/{fe39109b.92f315a0.js => fe39109b.2dd4360a.js} | 2 +- assets/js/{fe3b9d2d.b2989998.js => fe3b9d2d.91ae64e8.js} | 2 +- assets/js/{main.80f7cbc5.js => main.1a623312.js} | 4 ++-- ...80f7cbc5.js.LICENSE.txt => main.1a623312.js.LICENSE.txt} | 0 .../{runtime~main.5791154f.js => runtime~main.4a94813a.js} | 2 +- docs/26.5/babel7-or-ts/index.html | 6 +++--- docs/26.5/contributing/index.html | 6 +++--- docs/26.5/debugging/index.html | 6 +++--- docs/26.5/getting-started/installation/index.html | 6 +++--- .../26.5/getting-started/options/astTransformers/index.html | 6 +++--- docs/26.5/getting-started/options/babelConfig/index.html | 6 +++--- docs/26.5/getting-started/options/compiler/index.html | 6 +++--- docs/26.5/getting-started/options/diagnostics/index.html | 6 +++--- docs/26.5/getting-started/options/index.html | 6 +++--- .../26.5/getting-started/options/isolatedModules/index.html | 6 +++--- .../options/stringifyContentPathRegex/index.html | 6 +++--- docs/26.5/getting-started/options/tsconfig/index.html | 6 +++--- docs/26.5/getting-started/paths-mapping/index.html | 6 +++--- docs/26.5/getting-started/presets/index.html | 6 +++--- docs/26.5/getting-started/version-checking/index.html | 6 +++--- docs/26.5/guides/esm-support/index.html | 6 +++--- docs/26.5/guides/mock-es6-class/index.html | 6 +++--- docs/26.5/guides/react-native/index.html | 6 +++--- docs/26.5/guides/test-helpers/index.html | 6 +++--- docs/26.5/guides/troubleshooting/index.html | 6 +++--- docs/26.5/guides/using-with-monorepo/index.html | 6 +++--- docs/26.5/index.html | 6 +++--- docs/26.5/migration/index.html | 6 +++--- docs/26.5/processing/index.html | 6 +++--- docs/27.0/babel7-or-ts/index.html | 6 +++--- docs/27.0/contributing/index.html | 6 +++--- docs/27.0/debugging/index.html | 6 +++--- docs/27.0/getting-started/installation/index.html | 6 +++--- .../27.0/getting-started/options/astTransformers/index.html | 6 +++--- docs/27.0/getting-started/options/babelConfig/index.html | 6 +++--- docs/27.0/getting-started/options/compiler/index.html | 6 +++--- docs/27.0/getting-started/options/diagnostics/index.html | 6 +++--- docs/27.0/getting-started/options/index.html | 6 +++--- .../27.0/getting-started/options/isolatedModules/index.html | 6 +++--- .../options/stringifyContentPathRegex/index.html | 6 +++--- docs/27.0/getting-started/options/tsconfig/index.html | 6 +++--- docs/27.0/getting-started/options/useESM/index.html | 6 +++--- docs/27.0/getting-started/paths-mapping/index.html | 6 +++--- docs/27.0/getting-started/presets/index.html | 6 +++--- docs/27.0/getting-started/version-checking/index.html | 6 +++--- docs/27.0/guides/esm-support/index.html | 6 +++--- docs/27.0/guides/mock-es6-class/index.html | 6 +++--- docs/27.0/guides/react-native/index.html | 6 +++--- docs/27.0/guides/test-helpers/index.html | 6 +++--- docs/27.0/guides/troubleshooting/index.html | 6 +++--- docs/27.0/guides/using-with-monorepo/index.html | 6 +++--- docs/27.0/index.html | 6 +++--- docs/27.0/migration/index.html | 6 +++--- docs/27.0/processing/index.html | 6 +++--- docs/27.1/babel7-or-ts/index.html | 6 +++--- docs/27.1/contributing/index.html | 6 +++--- docs/27.1/debugging/index.html | 6 +++--- docs/27.1/getting-started/installation/index.html | 6 +++--- .../27.1/getting-started/options/astTransformers/index.html | 6 +++--- docs/27.1/getting-started/options/babelConfig/index.html | 6 +++--- docs/27.1/getting-started/options/compiler/index.html | 6 +++--- docs/27.1/getting-started/options/diagnostics/index.html | 6 +++--- docs/27.1/getting-started/options/index.html | 6 +++--- .../27.1/getting-started/options/isolatedModules/index.html | 6 +++--- .../options/stringifyContentPathRegex/index.html | 6 +++--- docs/27.1/getting-started/options/tsconfig/index.html | 6 +++--- docs/27.1/getting-started/options/useESM/index.html | 6 +++--- docs/27.1/getting-started/paths-mapping/index.html | 6 +++--- docs/27.1/getting-started/presets/index.html | 6 +++--- docs/27.1/getting-started/version-checking/index.html | 6 +++--- docs/27.1/guides/esm-support/index.html | 6 +++--- docs/27.1/guides/mock-es6-class/index.html | 6 +++--- docs/27.1/guides/react-native/index.html | 6 +++--- docs/27.1/guides/test-helpers/index.html | 6 +++--- docs/27.1/guides/troubleshooting/index.html | 6 +++--- docs/27.1/guides/using-with-monorepo/index.html | 6 +++--- docs/27.1/index.html | 6 +++--- docs/27.1/migration/index.html | 6 +++--- docs/27.1/processing/index.html | 6 +++--- docs/28.0/babel7-or-ts/index.html | 6 +++--- docs/28.0/contributing/index.html | 6 +++--- docs/28.0/debugging/index.html | 6 +++--- docs/28.0/getting-started/installation/index.html | 6 +++--- .../28.0/getting-started/options/astTransformers/index.html | 6 +++--- docs/28.0/getting-started/options/babelConfig/index.html | 6 +++--- docs/28.0/getting-started/options/compiler/index.html | 6 +++--- docs/28.0/getting-started/options/diagnostics/index.html | 6 +++--- docs/28.0/getting-started/options/index.html | 6 +++--- .../28.0/getting-started/options/isolatedModules/index.html | 6 +++--- .../options/stringifyContentPathRegex/index.html | 6 +++--- docs/28.0/getting-started/options/tsconfig/index.html | 6 +++--- docs/28.0/getting-started/options/useESM/index.html | 6 +++--- docs/28.0/getting-started/paths-mapping/index.html | 6 +++--- docs/28.0/getting-started/presets/index.html | 6 +++--- docs/28.0/getting-started/version-checking/index.html | 6 +++--- docs/28.0/guides/esm-support/index.html | 6 +++--- docs/28.0/guides/mock-es6-class/index.html | 6 +++--- docs/28.0/guides/react-native/index.html | 6 +++--- docs/28.0/guides/troubleshooting/index.html | 6 +++--- docs/28.0/guides/using-with-monorepo/index.html | 6 +++--- docs/28.0/index.html | 6 +++--- docs/28.0/migration/index.html | 6 +++--- docs/28.0/processing/index.html | 6 +++--- docs/29.0/babel7-or-ts/index.html | 6 +++--- docs/29.0/contributing/index.html | 6 +++--- docs/29.0/debugging/index.html | 6 +++--- docs/29.0/getting-started/installation/index.html | 6 +++--- .../29.0/getting-started/options/astTransformers/index.html | 6 +++--- docs/29.0/getting-started/options/babelConfig/index.html | 6 +++--- docs/29.0/getting-started/options/compiler/index.html | 6 +++--- docs/29.0/getting-started/options/diagnostics/index.html | 6 +++--- docs/29.0/getting-started/options/index.html | 6 +++--- .../29.0/getting-started/options/isolatedModules/index.html | 6 +++--- .../options/stringifyContentPathRegex/index.html | 6 +++--- docs/29.0/getting-started/options/tsconfig/index.html | 6 +++--- docs/29.0/getting-started/options/useESM/index.html | 6 +++--- docs/29.0/getting-started/paths-mapping/index.html | 6 +++--- docs/29.0/getting-started/presets/index.html | 6 +++--- docs/29.0/getting-started/version-checking/index.html | 6 +++--- docs/29.0/guides/esm-support/index.html | 6 +++--- docs/29.0/guides/mock-es6-class/index.html | 6 +++--- docs/29.0/guides/react-native/index.html | 6 +++--- docs/29.0/guides/troubleshooting/index.html | 6 +++--- docs/29.0/guides/using-with-monorepo/index.html | 6 +++--- docs/29.0/index.html | 6 +++--- docs/29.0/migration/index.html | 6 +++--- docs/29.0/processing/index.html | 6 +++--- docs/babel7-or-ts/index.html | 6 +++--- docs/contributing/index.html | 6 +++--- docs/debugging/index.html | 6 +++--- docs/getting-started/installation/index.html | 6 +++--- docs/getting-started/options/astTransformers/index.html | 6 +++--- docs/getting-started/options/babelConfig/index.html | 6 +++--- docs/getting-started/options/compiler/index.html | 6 +++--- docs/getting-started/options/diagnostics/index.html | 6 +++--- docs/getting-started/options/index.html | 6 +++--- docs/getting-started/options/isolatedModules/index.html | 6 +++--- .../options/stringifyContentPathRegex/index.html | 6 +++--- docs/getting-started/options/tsconfig/index.html | 6 +++--- docs/getting-started/options/useESM/index.html | 6 +++--- docs/getting-started/paths-mapping/index.html | 6 +++--- docs/getting-started/presets/index.html | 6 +++--- docs/getting-started/version-checking/index.html | 6 +++--- docs/guides/esm-support/index.html | 6 +++--- docs/guides/mock-es6-class/index.html | 6 +++--- docs/guides/react-native/index.html | 6 +++--- docs/guides/troubleshooting/index.html | 6 +++--- docs/guides/using-with-monorepo/index.html | 6 +++--- docs/index.html | 6 +++--- docs/migration/index.html | 6 +++--- docs/next/babel7-or-ts/index.html | 6 +++--- docs/next/contributing/index.html | 6 +++--- docs/next/debugging/index.html | 6 +++--- docs/next/getting-started/installation/index.html | 6 +++--- .../next/getting-started/options/astTransformers/index.html | 6 +++--- docs/next/getting-started/options/babelConfig/index.html | 6 +++--- docs/next/getting-started/options/compiler/index.html | 6 +++--- docs/next/getting-started/options/diagnostics/index.html | 6 +++--- docs/next/getting-started/options/index.html | 6 +++--- .../next/getting-started/options/isolatedModules/index.html | 6 +++--- .../options/stringifyContentPathRegex/index.html | 6 +++--- docs/next/getting-started/options/tsconfig/index.html | 6 +++--- docs/next/getting-started/options/useESM/index.html | 6 +++--- docs/next/getting-started/paths-mapping/index.html | 6 +++--- docs/next/getting-started/presets/index.html | 6 +++--- docs/next/getting-started/version-checking/index.html | 6 +++--- docs/next/guides/esm-support/index.html | 6 +++--- docs/next/guides/mock-es6-class/index.html | 6 +++--- docs/next/guides/react-native/index.html | 6 +++--- docs/next/guides/troubleshooting/index.html | 6 +++--- docs/next/guides/using-with-monorepo/index.html | 6 +++--- docs/next/index.html | 6 +++--- docs/next/migration/index.html | 6 +++--- docs/next/processing/index.html | 6 +++--- docs/processing/index.html | 6 +++--- index.html | 4 ++-- sw.js | 2 +- versions/index.html | 4 ++-- 347 files changed, 690 insertions(+), 690 deletions(-) rename assets/js/{00e7239c.83cf3479.js => 00e7239c.0c995c08.js} (99%) rename assets/js/{0259e2f2.c84f259b.js => 0259e2f2.b2bfac7c.js} (98%) rename assets/js/{03be7dae.50acd6db.js => 03be7dae.00559958.js} (99%) rename assets/js/{057d33b8.62e2233c.js => 057d33b8.93d2c767.js} (98%) rename assets/js/{06fbaa8e.57ac1f62.js => 06fbaa8e.61528603.js} (97%) rename assets/js/{07a7640f.abff013a.js => 07a7640f.c2323d27.js} (98%) rename assets/js/{0833143f.2817f5a6.js => 0833143f.52063431.js} (97%) rename assets/js/{093c23a0.1daed7f6.js => 093c23a0.4144588c.js} (99%) rename assets/js/{0a51ecf3.bfe4da1e.js => 0a51ecf3.be2dc629.js} (99%) rename assets/js/{0b2fcab7.524bcc94.js => 0b2fcab7.a6171f76.js} (98%) rename assets/js/{0d0f47fc.66e804d6.js => 0d0f47fc.1ac99fc2.js} (99%) rename assets/js/{10aeaaf3.fea17a78.js => 10aeaaf3.85aa8f82.js} (96%) rename assets/js/{1165ba55.6aa22ae8.js => 1165ba55.79b100ec.js} (98%) rename assets/js/{12292045.14a6c846.js => 12292045.5d460baa.js} (97%) rename assets/js/{15c7296a.f02b1818.js => 15c7296a.b10729cc.js} (99%) rename assets/js/{16ada0e2.5d9aea68.js => 16ada0e2.e08794d1.js} (97%) rename assets/js/{16bac89a.14497471.js => 16bac89a.7f86c6eb.js} (98%) rename assets/js/{1854c3e7.d414a6fb.js => 1854c3e7.40243a56.js} (98%) rename assets/js/{1917a510.aceaa1a7.js => 1917a510.5ab3afc8.js} (99%) rename assets/js/{19f0fee7.f9d853a2.js => 19f0fee7.8a32259e.js} (99%) rename assets/js/{1ca5b1f2.7b876712.js => 1ca5b1f2.44bf028b.js} (97%) rename assets/js/{2145bebc.378525df.js => 2145bebc.68b79213.js} (98%) rename assets/js/{22e01789.d0575031.js => 22e01789.40ec38ee.js} (98%) rename assets/js/{22f8c605.97329a1f.js => 22f8c605.cd0013a5.js} (97%) rename assets/js/{2331e073.321c45e4.js => 2331e073.67cd78ff.js} (98%) rename assets/js/{2338618e.50f7fb38.js => 2338618e.edd2aa5f.js} (99%) rename assets/js/{24991caa.6876bd74.js => 24991caa.97adaac5.js} (98%) rename assets/js/{265d7427.2fb79e7b.js => 265d7427.45a293f1.js} (98%) rename assets/js/{270520cb.66d198dc.js => 270520cb.387ac587.js} (99%) rename assets/js/{295b567d.a71774d7.js => 295b567d.47624169.js} (99%) rename assets/js/{2a3bd03a.8879b397.js => 2a3bd03a.3487bf7c.js} (98%) rename assets/js/{2b68f68f.c5eeb725.js => 2b68f68f.411a7201.js} (98%) rename assets/js/{2b77ff19.ff8f122b.js => 2b77ff19.7d69ff37.js} (99%) rename assets/js/{2b94ed59.d675dd5a.js => 2b94ed59.5d2ddf62.js} (97%) rename assets/js/{2bccb399.51fe225e.js => 2bccb399.5edbe13a.js} (99%) rename assets/js/{2c53b5e4.3589b250.js => 2c53b5e4.e23fa1b0.js} (98%) rename assets/js/{2d143bed.70765e71.js => 2d143bed.a8f1abb0.js} (98%) rename assets/js/{2e89f3c4.6f967198.js => 2e89f3c4.01abed72.js} (98%) rename assets/js/{304054d0.b6c2bc75.js => 304054d0.338556f9.js} (99%) rename assets/js/{334e0bf3.b5f04685.js => 334e0bf3.a900e034.js} (97%) rename assets/js/{3432663a.4f4acd85.js => 3432663a.9cff8df9.js} (98%) rename assets/js/{35779d9e.1967fc1e.js => 35779d9e.e35fa0f5.js} (99%) rename assets/js/{35ce71d5.c5787073.js => 35ce71d5.1ceeb43b.js} (97%) rename assets/js/{3787ba46.79103c8d.js => 3787ba46.3187f2ee.js} (98%) rename assets/js/{3bfdd655.815c18b5.js => 3bfdd655.50e26fcc.js} (99%) rename assets/js/{3e930f87.764f2b98.js => 3e930f87.eaf4b848.js} (99%) rename assets/js/{4040fa6b.96207318.js => 4040fa6b.9ea385db.js} (97%) rename assets/js/{44207808.3a269b4f.js => 44207808.8f0ac8c9.js} (99%) rename assets/js/{44d840ac.741a6c7e.js => 44d840ac.9f1c89dc.js} (99%) rename assets/js/{4aabdf82.d312f6b1.js => 4aabdf82.2a45d1cb.js} (98%) rename assets/js/{4c23203f.72c02dac.js => 4c23203f.ae730044.js} (98%) rename assets/js/{4c757249.9bb387a9.js => 4c757249.c1884e45.js} (98%) rename assets/js/{4d54d076.0dbbf9af.js => 4d54d076.d01053ce.js} (98%) rename assets/js/{4dd3fb5c.fb642566.js => 4dd3fb5c.da93f493.js} (99%) rename assets/js/{4e0c07c5.4112f062.js => 4e0c07c5.57eedcdd.js} (98%) rename assets/js/{5316ff60.5138fd7c.js => 5316ff60.09d0f6fe.js} (99%) rename assets/js/{544d8072.6eddd2c9.js => 544d8072.4881b7d6.js} (98%) rename assets/js/{54ceb25f.daee3545.js => 54ceb25f.17d4f1b4.js} (98%) rename assets/js/{54f44165.7c5a3f91.js => 54f44165.d90b0204.js} (99%) rename assets/js/{5bf3837a.62777e91.js => 5bf3837a.e9c81638.js} (98%) rename assets/js/{61b42bb5.754d1be0.js => 61b42bb5.539f1df0.js} (98%) rename assets/js/{629085c0.5f85dd08.js => 629085c0.97393345.js} (99%) rename assets/js/{6625be2a.b983ec8c.js => 6625be2a.de300dce.js} (99%) rename assets/js/{673550c0.c16d574d.js => 673550c0.5a99e13d.js} (99%) rename assets/js/{6789ef91.1bfe1b39.js => 6789ef91.31fd45fd.js} (99%) rename assets/js/{684ec830.9fd6bfb9.js => 684ec830.fbea694e.js} (99%) rename assets/js/{6bc4332d.639b5dee.js => 6bc4332d.c40d1ab1.js} (98%) rename assets/js/{6cdc57e1.57b80edb.js => 6cdc57e1.27f28efa.js} (98%) rename assets/js/{6f04af8d.af15916e.js => 6f04af8d.77c90ed6.js} (99%) rename assets/js/{6f4d8994.117a0347.js => 6f4d8994.59d7b33c.js} (97%) rename assets/js/{6f82a5f4.4fafb087.js => 6f82a5f4.1082f97a.js} (98%) rename assets/js/{7335c74d.c31a2be6.js => 7335c74d.d595bd82.js} (99%) rename assets/js/{73f5a02c.77733def.js => 73f5a02c.33e8cb11.js} (99%) rename assets/js/{75ab14ad.eedd6538.js => 75ab14ad.c68fd977.js} (98%) rename assets/js/{78f0a226.fcab7721.js => 78f0a226.3bd0ffa6.js} (99%) rename assets/js/{7aac82f3.f98a61f2.js => 7aac82f3.11f9b301.js} (99%) rename assets/js/{7b562fc7.d3988519.js => 7b562fc7.b7aa5465.js} (98%) rename assets/js/{7d1a64ae.a6037b4f.js => 7d1a64ae.4f6fa23f.js} (98%) rename assets/js/{7dafce35.8f740fa3.js => 7dafce35.6c17d5d2.js} (99%) rename assets/js/{7ec61308.9c63e66e.js => 7ec61308.e2b86301.js} (99%) rename assets/js/{801c4327.10205da7.js => 801c4327.c006a379.js} (99%) rename assets/js/{850a2979.647ee6bf.js => 850a2979.ad40f081.js} (99%) rename assets/js/{86b5844b.d350fa07.js => 86b5844b.f61f80de.js} (99%) rename assets/js/{8b2f9623.cd44d226.js => 8b2f9623.f045538d.js} (98%) rename assets/js/{8b622911.ec34731d.js => 8b622911.633e729a.js} (98%) rename assets/js/{8cf61ec4.18a24356.js => 8cf61ec4.a78c37c1.js} (98%) rename assets/js/{8d536cde.a8645fee.js => 8d536cde.26af3277.js} (98%) rename assets/js/{8e5d45d9.93e6e394.js => 8e5d45d9.849fbe21.js} (97%) rename assets/js/{8e81f9bb.a7990d5d.js => 8e81f9bb.d4682633.js} (99%) rename assets/js/{902acc05.763dfe6c.js => 902acc05.f0269b39.js} (98%) rename assets/js/{90645308.39c8de4b.js => 90645308.49eba68d.js} (99%) rename assets/js/{9226f379.a45c386e.js => 9226f379.5f1c5b18.js} (99%) rename assets/js/{96f7df01.8bfb600d.js => 96f7df01.48c01edb.js} (98%) rename assets/js/{9762b2e9.a60a5583.js => 9762b2e9.c07ce416.js} (98%) rename assets/js/{981dc414.57664b9f.js => 981dc414.d0180d50.js} (99%) rename assets/js/{9920b385.f93e0231.js => 9920b385.c2b915d3.js} (99%) rename assets/js/{9d036230.992329cf.js => 9d036230.f9704aa5.js} (98%) rename assets/js/{9ed06f50.296535f3.js => 9ed06f50.04a0976b.js} (98%) rename assets/js/{a09c2993.e6b9df8d.js => a09c2993.bdfd098b.js} (97%) rename assets/js/{a132b5de.645f7642.js => a132b5de.53d8d570.js} (99%) rename assets/js/{a21658d9.27d7fd56.js => a21658d9.f60aa266.js} (98%) rename assets/js/{a5ea8355.63e9e00c.js => a5ea8355.2199c8e1.js} (98%) rename assets/js/{a6267c3c.9fe1c460.js => a6267c3c.bf4e5e2b.js} (97%) rename assets/js/{a7423e3b.47f3318d.js => a7423e3b.635b1547.js} (98%) rename assets/js/{a7bc29db.005cdfe9.js => a7bc29db.e33e8aff.js} (99%) rename assets/js/{a8c654d7.ed76a70f.js => a8c654d7.6ecb388a.js} (97%) rename assets/js/{a8e3f14e.c57728a2.js => a8e3f14e.667ab091.js} (99%) rename assets/js/{aaf1bd4c.a76bf8b2.js => aaf1bd4c.33ec191c.js} (98%) rename assets/js/{ae1ffb77.e2a0d769.js => ae1ffb77.bb67cfb5.js} (97%) rename assets/js/{aeb5491d.11795c71.js => aeb5491d.2140da85.js} (98%) rename assets/js/{aeb823d8.e763955c.js => aeb823d8.f4474cf0.js} (99%) rename assets/js/{afb030c9.0176420a.js => afb030c9.cd6a94fc.js} (98%) rename assets/js/{b317f538.6b770618.js => b317f538.35c80c6c.js} (97%) rename assets/js/{b519512b.be96fda8.js => b519512b.18577b7e.js} (98%) rename assets/js/{b72fc7f8.205d41b7.js => b72fc7f8.69e0097e.js} (99%) rename assets/js/{b809b403.4d8874bb.js => b809b403.a5ae287c.js} (97%) rename assets/js/{b96776d9.c20e4410.js => b96776d9.c3b55621.js} (99%) rename assets/js/{bdf18d96.ef8ea76d.js => bdf18d96.26b56a84.js} (98%) rename assets/js/{bdfec613.fae4d7a9.js => bdfec613.dee9370f.js} (99%) rename assets/js/{bf341476.28157d87.js => bf341476.06c38444.js} (97%) rename assets/js/{c010a830.565e8076.js => c010a830.7a17d40e.js} (97%) rename assets/js/{c1932cab.7674b66d.js => c1932cab.28f8c650.js} (99%) rename assets/js/{c1a7450f.47d4c4ee.js => c1a7450f.bc600371.js} (99%) rename assets/js/{c6326909.213084ed.js => c6326909.a8d572e1.js} (97%) rename assets/js/{c8c88a41.06eff6cf.js => c8c88a41.444eb5d2.js} (98%) rename assets/js/{c8eced56.2b96d068.js => c8eced56.d8927fa4.js} (97%) rename assets/js/{ceaad8ca.26b23793.js => ceaad8ca.7a2881e9.js} (99%) rename assets/js/{cf5c42a2.595bac99.js => cf5c42a2.aaa08e62.js} (98%) rename assets/js/{cffdf1e5.cf2f418e.js => cffdf1e5.1d9ce4e5.js} (99%) rename assets/js/{d0e697d4.c6440020.js => d0e697d4.8469c21f.js} (97%) rename assets/js/{d296dded.f75bff98.js => d296dded.e85b0aff.js} (97%) rename assets/js/{d3b43630.fcc5105a.js => d3b43630.eccf12e3.js} (98%) rename assets/js/{d4836a8e.b1763707.js => d4836a8e.49a40161.js} (98%) rename assets/js/{d4a6dd78.ebdffa88.js => d4a6dd78.99b839a8.js} (99%) rename assets/js/{d6f9473b.1f6aa8d3.js => d6f9473b.4ea96a3d.js} (99%) rename assets/js/{d8357ecf.29f91670.js => d8357ecf.f1f3fca7.js} (97%) rename assets/js/{d9f7da4b.16f670ec.js => d9f7da4b.d4b6ce02.js} (97%) rename assets/js/{da431c38.1b5c02ee.js => da431c38.df55fcc1.js} (99%) rename assets/js/{dabdf990.2836a489.js => dabdf990.47a863fa.js} (97%) rename assets/js/{db49ae54.98f92ebe.js => db49ae54.6c64bd98.js} (98%) rename assets/js/{db795cf2.039b2323.js => db795cf2.3fa12001.js} (97%) rename assets/js/{dcbdd84f.b89413b1.js => dcbdd84f.cd175312.js} (97%) rename assets/js/{e3a856ae.e046cbac.js => e3a856ae.f4179db3.js} (98%) rename assets/js/{e5e34c6b.34d2aa10.js => e5e34c6b.83cffe15.js} (97%) rename assets/js/{e8085380.1ce58536.js => e8085380.3c65ab32.js} (99%) rename assets/js/{e87a3571.9597891d.js => e87a3571.0c980777.js} (98%) rename assets/js/{e8b13364.c13e2b25.js => e8b13364.71f5c781.js} (99%) rename assets/js/{eabdbf07.22b244a5.js => eabdbf07.5410c020.js} (98%) rename assets/js/{ec6c7123.93ae7b87.js => ec6c7123.8810b94a.js} (98%) rename assets/js/{f01607c0.a408f628.js => f01607c0.cdf147cf.js} (98%) rename assets/js/{f0683fd0.2befdc34.js => f0683fd0.043633fc.js} (97%) rename assets/js/{f154e663.b0212b7d.js => f154e663.fff8a972.js} (99%) rename assets/js/{f298e69b.70fafe25.js => f298e69b.4ecb8a66.js} (99%) rename assets/js/{f371827f.04a303bd.js => f371827f.8009cbda.js} (99%) rename assets/js/{f4dd4a52.bbf579b7.js => f4dd4a52.b13354ac.js} (99%) rename assets/js/{f6605416.f4cc3ff6.js => f6605416.777896e5.js} (99%) rename assets/js/{f6aab920.88ecf1a3.js => f6aab920.23d6e4b0.js} (98%) rename assets/js/{f6f550ec.c49076a5.js => f6f550ec.6ebd70e3.js} (99%) rename assets/js/{f7416098.6d7831a2.js => f7416098.99e20882.js} (98%) rename assets/js/{f7862b07.8de16ae5.js => f7862b07.88c0d675.js} (98%) rename assets/js/{f7b7430f.c4d24c44.js => f7b7430f.0b7a9f59.js} (98%) rename assets/js/{f7cb2af4.4584226e.js => f7cb2af4.99a450db.js} (99%) rename assets/js/{f8fb2427.a69eb55c.js => f8fb2427.6a6c567e.js} (99%) rename assets/js/{fa061f97.c83784db.js => fa061f97.1355d829.js} (99%) rename assets/js/{fb1b7a48.74274200.js => fb1b7a48.b5e4f6ba.js} (98%) rename assets/js/{fc43d853.45796344.js => fc43d853.cb9c3261.js} (98%) rename assets/js/{fc80686b.b18b0112.js => fc80686b.d9f583eb.js} (99%) rename assets/js/{fdcb7476.feb6962b.js => fdcb7476.0782afd3.js} (99%) rename assets/js/{fe39109b.92f315a0.js => fe39109b.2dd4360a.js} (99%) rename assets/js/{fe3b9d2d.b2989998.js => fe3b9d2d.91ae64e8.js} (97%) rename assets/js/{main.80f7cbc5.js => main.1a623312.js} (94%) rename assets/js/{main.80f7cbc5.js.LICENSE.txt => main.1a623312.js.LICENSE.txt} (100%) rename assets/js/{runtime~main.5791154f.js => runtime~main.4a94813a.js} (54%) diff --git a/404.html b/404.html index 4b31ec1315..2bb0c8305f 100644 --- a/404.html +++ b/404.html @@ -12,8 +12,8 @@ - - + +
Skip to main content

Page Not Found

We could not find what you were looking for.

Please contact the owner of the site that linked you to the original URL and let them know their link is broken.

diff --git a/assets/js/00e7239c.83cf3479.js b/assets/js/00e7239c.0c995c08.js similarity index 99% rename from assets/js/00e7239c.83cf3479.js rename to assets/js/00e7239c.0c995c08.js index 2c01907751..29c3f9a037 100644 --- a/assets/js/00e7239c.83cf3479.js +++ b/assets/js/00e7239c.0c995c08.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8970],{1611:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>l,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/astTransformers","title":"AST transformers option","description":"ts-jest by default does hoisting for a few jest methods via a TypeScript AST transformer. One can also create custom","source":"@site/docs/getting-started/options/astTransformers.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/astTransformers","permalink":"/ts-jest/docs/next/getting-started/options/astTransformers","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/astTransformers.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"AST transformers option"}}');var r=s(4848),a=s(8453),o=s(9489),i=s(7227);const l={title:"AST transformers option"},c=void 0,u={},d=[{value:"Examples",id:"examples",level:3},{value:"Basic Transformers",id:"basic-transformers",level:4},{value:"Configuring transformers with options",id:"configuring-transformers-with-options",level:4},{value:"Writing custom TypeScript AST transformers",id:"writing-custom-typescript-ast-transformers",level:3}];function m(e){const t={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"ts-jest"})," by default does hoisting for a few ",(0,r.jsx)(t.code,{children:"jest"})," methods via a TypeScript AST transformer. One can also create custom\nTypeScript AST transformers and provide them to ",(0,r.jsx)(t.code,{children:"ts-jest"})," to include into compilation process."]}),"\n",(0,r.jsxs)(t.p,{children:["The option is ",(0,r.jsx)(t.code,{children:"astTransformers"})," and it allows ones to specify which 3 types of TypeScript AST transformers to use with ",(0,r.jsx)(t.code,{children:"ts-jest"}),":"]}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"before"})," means your transformers get run before TS ones, which means your transformers will get raw TS syntax\ninstead of transpiled syntax (e.g ",(0,r.jsx)(t.code,{children:"import"})," instead of ",(0,r.jsx)(t.code,{children:"require"})," or ",(0,r.jsx)(t.code,{children:"define"})," )."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"after"})," means your transformers get run after TS ones, which gets transpiled syntax."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"afterDeclarations"})," means your transformers get run during ",(0,r.jsx)(t.code,{children:"d.ts"})," generation phase, allowing you to transform output type declarations."]}),"\n"]}),"\n",(0,r.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,r.jsx)(t.h4,{id:"basic-transformers",children:"Basic Transformers"}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n astTransformers: {\n before: ['my-custom-transformer'],\n },\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n astTransformers: {\n before: ['my-custom-transformer'],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(i.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "astTransformers": {\n "before": ["my-custom-transformer"]\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsx)(t.h4,{id:"configuring-transformers-with-options",children:"Configuring transformers with options"}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n astTransformers: {\n before: [\n {\n path: 'my-custom-transformer-that-needs-extra-opts',\n options: {}, // extra options to pass to transformers here\n },\n ],\n },\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n astTransformers: {\n before: [\n {\n path: 'my-custom-transformer-that-needs-extra-opts',\n options: {}, // extra options to pass to transformers here\n },\n ],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(i.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "astTransformers": {\n "before": [\n {\n "path": "my-custom-transformer-that-needs-extra-opts",\n "options": {} // extra options to pass to transformers here\n }\n ]\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsx)(t.h3,{id:"writing-custom-typescript-ast-transformers",children:"Writing custom TypeScript AST transformers"}),"\n",(0,r.jsxs)(t.p,{children:["To write a custom TypeScript AST transformers, one can take a look at ",(0,r.jsx)(t.a,{href:"https://github.com/kulshekhar/ts-jest/tree/main/src/transformers",children:"the one"})," that ",(0,r.jsx)(t.code,{children:"ts-jest"})," is using."]})]})}function p(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(m,{...e})}):m(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>o});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var a=s(4848);function o(e){let{children:t,hidden:s,className:o}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,o),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>T});var n=s(6540),r=s(4164),a=s(4245),o=s(6347),i=s(6494),l=s(2814),c=s(5167),u=s(9900);function d(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function m(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:r}}=e;return{value:t,label:s,attributes:n,default:r}}))}(s);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function p(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:s}=e;const r=(0,o.W6)(),a=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,l.aZ)(a),(0,n.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function h(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,a=m(e),[o,l]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:a}))),[c,d]=f({queryString:s,groupId:r}),[h,j]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,u.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&a.set(e)}),[s,a])]}({groupId:r}),x=(()=>{const e=c??h;return p({value:e,tabValues:a})?e:null})();(0,i.A)((()=>{x&&l(x)}),[x]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!p({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),j(e)}),[d,j,a]),tabValues:a}}var j=s(1062);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=s(4848);function b(e){let{className:t,block:s,selectedValue:n,selectValue:o,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,a.a_)(),u=e=>{const t=e.currentTarget,s=l.indexOf(t),r=i[s].value;r!==n&&(c(t),o(r))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const s=l.indexOf(e.currentTarget)+1;t=l[s]??l[0];break}case"ArrowLeft":{const s=l.indexOf(e.currentTarget)-1;t=l[s]??l[l.length-1];break}}t?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":s},t),children:i.map((e=>{let{value:t,label:s,attributes:a}=e;return(0,g.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>l.push(e),onKeyDown:d,onClick:u,...a,className:(0,r.A)("tabs__item",x.tabItem,a?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:a}=e;const o=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=h(e);return(0,g.jsxs)("div",{className:(0,r.A)("tabs-container",x.tabList),children:[(0,g.jsx)(b,{...t,...e}),(0,g.jsx)(v,{...t,...e})]})}function T(e){const t=(0,j.A)();return(0,g.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>o,x:()=>i});var n=s(6540);const r={},a=n.createContext(r);function o(e){const t=n.useContext(a);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),n.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8970],{1611:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>l,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/astTransformers","title":"AST transformers option","description":"ts-jest by default does hoisting for a few jest methods via a TypeScript AST transformer. One can also create custom","source":"@site/docs/getting-started/options/astTransformers.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/astTransformers","permalink":"/ts-jest/docs/next/getting-started/options/astTransformers","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/astTransformers.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"AST transformers option"}}');var r=s(4848),a=s(8453),o=s(9489),i=s(7227);const l={title:"AST transformers option"},c=void 0,u={},d=[{value:"Examples",id:"examples",level:3},{value:"Basic Transformers",id:"basic-transformers",level:4},{value:"Configuring transformers with options",id:"configuring-transformers-with-options",level:4},{value:"Writing custom TypeScript AST transformers",id:"writing-custom-typescript-ast-transformers",level:3}];function m(e){const t={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"ts-jest"})," by default does hoisting for a few ",(0,r.jsx)(t.code,{children:"jest"})," methods via a TypeScript AST transformer. One can also create custom\nTypeScript AST transformers and provide them to ",(0,r.jsx)(t.code,{children:"ts-jest"})," to include into compilation process."]}),"\n",(0,r.jsxs)(t.p,{children:["The option is ",(0,r.jsx)(t.code,{children:"astTransformers"})," and it allows ones to specify which 3 types of TypeScript AST transformers to use with ",(0,r.jsx)(t.code,{children:"ts-jest"}),":"]}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"before"})," means your transformers get run before TS ones, which means your transformers will get raw TS syntax\ninstead of transpiled syntax (e.g ",(0,r.jsx)(t.code,{children:"import"})," instead of ",(0,r.jsx)(t.code,{children:"require"})," or ",(0,r.jsx)(t.code,{children:"define"})," )."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"after"})," means your transformers get run after TS ones, which gets transpiled syntax."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"afterDeclarations"})," means your transformers get run during ",(0,r.jsx)(t.code,{children:"d.ts"})," generation phase, allowing you to transform output type declarations."]}),"\n"]}),"\n",(0,r.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,r.jsx)(t.h4,{id:"basic-transformers",children:"Basic Transformers"}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n astTransformers: {\n before: ['my-custom-transformer'],\n },\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n astTransformers: {\n before: ['my-custom-transformer'],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(i.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "astTransformers": {\n "before": ["my-custom-transformer"]\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsx)(t.h4,{id:"configuring-transformers-with-options",children:"Configuring transformers with options"}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n astTransformers: {\n before: [\n {\n path: 'my-custom-transformer-that-needs-extra-opts',\n options: {}, // extra options to pass to transformers here\n },\n ],\n },\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n astTransformers: {\n before: [\n {\n path: 'my-custom-transformer-that-needs-extra-opts',\n options: {}, // extra options to pass to transformers here\n },\n ],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(i.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "astTransformers": {\n "before": [\n {\n "path": "my-custom-transformer-that-needs-extra-opts",\n "options": {} // extra options to pass to transformers here\n }\n ]\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsx)(t.h3,{id:"writing-custom-typescript-ast-transformers",children:"Writing custom TypeScript AST transformers"}),"\n",(0,r.jsxs)(t.p,{children:["To write a custom TypeScript AST transformers, one can take a look at ",(0,r.jsx)(t.a,{href:"https://github.com/kulshekhar/ts-jest/tree/main/src/transformers",children:"the one"})," that ",(0,r.jsx)(t.code,{children:"ts-jest"})," is using."]})]})}function p(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(m,{...e})}):m(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>o});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var a=s(4848);function o(e){let{children:t,hidden:s,className:o}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,o),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>T});var n=s(6540),r=s(4164),a=s(4245),o=s(6347),i=s(6494),l=s(2814),c=s(5167),u=s(9900);function d(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function m(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:r}}=e;return{value:t,label:s,attributes:n,default:r}}))}(s);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function p(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:s}=e;const r=(0,o.W6)(),a=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,l.aZ)(a),(0,n.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function h(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,a=m(e),[o,l]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:a}))),[c,d]=f({queryString:s,groupId:r}),[h,j]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,u.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&a.set(e)}),[s,a])]}({groupId:r}),x=(()=>{const e=c??h;return p({value:e,tabValues:a})?e:null})();(0,i.A)((()=>{x&&l(x)}),[x]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!p({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),j(e)}),[d,j,a]),tabValues:a}}var j=s(1062);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=s(4848);function b(e){let{className:t,block:s,selectedValue:n,selectValue:o,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,a.a_)(),u=e=>{const t=e.currentTarget,s=l.indexOf(t),r=i[s].value;r!==n&&(c(t),o(r))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const s=l.indexOf(e.currentTarget)+1;t=l[s]??l[0];break}case"ArrowLeft":{const s=l.indexOf(e.currentTarget)-1;t=l[s]??l[l.length-1];break}}t?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":s},t),children:i.map((e=>{let{value:t,label:s,attributes:a}=e;return(0,g.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>l.push(e),onKeyDown:d,onClick:u,...a,className:(0,r.A)("tabs__item",x.tabItem,a?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:a}=e;const o=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=h(e);return(0,g.jsxs)("div",{className:(0,r.A)("tabs-container",x.tabList),children:[(0,g.jsx)(b,{...t,...e}),(0,g.jsx)(v,{...t,...e})]})}function T(e){const t=(0,j.A)();return(0,g.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>o,x:()=>i});var n=s(6540);const r={},a=n.createContext(r);function o(e){const t=n.useContext(a);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),n.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/0259e2f2.c84f259b.js b/assets/js/0259e2f2.b2bfac7c.js similarity index 98% rename from assets/js/0259e2f2.c84f259b.js rename to assets/js/0259e2f2.b2bfac7c.js index e3ebe6dee8..eabb378bf7 100644 --- a/assets/js/0259e2f2.c84f259b.js +++ b/assets/js/0259e2f2.b2bfac7c.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[378],{30:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>i,default:()=>m,frontMatter:()=>a,metadata:()=>t,toc:()=>d});const t=JSON.parse('{"id":"getting-started/options/astTransformers","title":"AST transformers option","description":"ts-jest by default does hoisting for a few jest methods via a TypeScript AST transformer. One can also create custom","source":"@site/versioned_docs/version-28.0/getting-started/options/astTransformers.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/astTransformers","permalink":"/ts-jest/docs/28.0/getting-started/options/astTransformers","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/options/astTransformers.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"AST transformers option"}}');var r=n(4848),o=n(8453);const a={title:"AST transformers option"},i=void 0,c={},d=[{value:"Examples",id:"examples",level:3},{value:"Basic Transformers",id:"basic-transformers",level:4},{value:"Configuring transformers with options",id:"configuring-transformers-with-options",level:4},{value:"Writing custom TypeScript AST transformers",id:"writing-custom-typescript-ast-transformers",level:3}];function l(e){const s={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.code,{children:"ts-jest"})," by default does hoisting for a few ",(0,r.jsx)(s.code,{children:"jest"})," methods via a TypeScript AST transformer. One can also create custom\nTypeScript AST transformers and provide them to ",(0,r.jsx)(s.code,{children:"ts-jest"})," to include into compilation process."]}),"\n",(0,r.jsxs)(s.p,{children:["The option is ",(0,r.jsx)(s.code,{children:"astTransformers"})," and it allows ones to specify which 3 types of TypeScript AST transformers to use with ",(0,r.jsx)(s.code,{children:"ts-jest"}),":"]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"before"})," means your transformers get run before TS ones, which means your transformers will get raw TS syntax\ninstead of transpiled syntax (e.g ",(0,r.jsx)(s.code,{children:"import"})," instead of ",(0,r.jsx)(s.code,{children:"require"})," or ",(0,r.jsx)(s.code,{children:"define"})," )."]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"after"})," means your transformers get run after TS ones, which gets transpiled syntax."]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"afterDeclarations"})," means your transformers get run during ",(0,r.jsx)(s.code,{children:"d.ts"})," generation phase, allowing you to transform output type declarations."]}),"\n"]}),"\n",(0,r.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,r.jsx)(s.h4,{id:"basic-transformers",children:"Basic Transformers"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n astTransformers: {\n before: ['my-custom-transformer'],\n },\n },\n },\n}\n"})}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "astTransformers": {\n "before": ["my-custom-transformer"]\n }\n }\n }\n }\n}\n'})}),"\n",(0,r.jsx)(s.h4,{id:"configuring-transformers-with-options",children:"Configuring transformers with options"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n astTransformers: {\n before: [\n {\n path: 'my-custom-transformer-that-needs-extra-opts',\n options: {}, // extra options to pass to transformers here\n },\n ],\n },\n },\n },\n}\n"})}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "astTransformers": {\n "before": [\n {\n "path": "my-custom-transformer-that-needs-extra-opts",\n "options": {} // extra options to pass to transformers here\n }\n ]\n }\n }\n }\n }\n}\n'})}),"\n",(0,r.jsx)(s.h3,{id:"writing-custom-typescript-ast-transformers",children:"Writing custom TypeScript AST transformers"}),"\n",(0,r.jsxs)(s.p,{children:["To write a custom TypeScript AST transformers, one can take a look at ",(0,r.jsx)(s.a,{href:"https://github.com/kulshekhar/ts-jest/tree/main/src/transformers",children:"the one"})," that ",(0,r.jsx)(s.code,{children:"ts-jest"})," is using."]})]})}function m(e={}){const{wrapper:s}={...(0,o.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(l,{...e})}):l(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>a,x:()=>i});var t=n(6540);const r={},o=t.createContext(r);function a(e){const s=t.useContext(o);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function i(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),t.createElement(o.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[378],{30:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>i,default:()=>m,frontMatter:()=>a,metadata:()=>t,toc:()=>d});const t=JSON.parse('{"id":"getting-started/options/astTransformers","title":"AST transformers option","description":"ts-jest by default does hoisting for a few jest methods via a TypeScript AST transformer. One can also create custom","source":"@site/versioned_docs/version-28.0/getting-started/options/astTransformers.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/astTransformers","permalink":"/ts-jest/docs/28.0/getting-started/options/astTransformers","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/options/astTransformers.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"AST transformers option"}}');var r=n(4848),o=n(8453);const a={title:"AST transformers option"},i=void 0,c={},d=[{value:"Examples",id:"examples",level:3},{value:"Basic Transformers",id:"basic-transformers",level:4},{value:"Configuring transformers with options",id:"configuring-transformers-with-options",level:4},{value:"Writing custom TypeScript AST transformers",id:"writing-custom-typescript-ast-transformers",level:3}];function l(e){const s={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.code,{children:"ts-jest"})," by default does hoisting for a few ",(0,r.jsx)(s.code,{children:"jest"})," methods via a TypeScript AST transformer. One can also create custom\nTypeScript AST transformers and provide them to ",(0,r.jsx)(s.code,{children:"ts-jest"})," to include into compilation process."]}),"\n",(0,r.jsxs)(s.p,{children:["The option is ",(0,r.jsx)(s.code,{children:"astTransformers"})," and it allows ones to specify which 3 types of TypeScript AST transformers to use with ",(0,r.jsx)(s.code,{children:"ts-jest"}),":"]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"before"})," means your transformers get run before TS ones, which means your transformers will get raw TS syntax\ninstead of transpiled syntax (e.g ",(0,r.jsx)(s.code,{children:"import"})," instead of ",(0,r.jsx)(s.code,{children:"require"})," or ",(0,r.jsx)(s.code,{children:"define"})," )."]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"after"})," means your transformers get run after TS ones, which gets transpiled syntax."]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"afterDeclarations"})," means your transformers get run during ",(0,r.jsx)(s.code,{children:"d.ts"})," generation phase, allowing you to transform output type declarations."]}),"\n"]}),"\n",(0,r.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,r.jsx)(s.h4,{id:"basic-transformers",children:"Basic Transformers"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n astTransformers: {\n before: ['my-custom-transformer'],\n },\n },\n },\n}\n"})}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "astTransformers": {\n "before": ["my-custom-transformer"]\n }\n }\n }\n }\n}\n'})}),"\n",(0,r.jsx)(s.h4,{id:"configuring-transformers-with-options",children:"Configuring transformers with options"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n astTransformers: {\n before: [\n {\n path: 'my-custom-transformer-that-needs-extra-opts',\n options: {}, // extra options to pass to transformers here\n },\n ],\n },\n },\n },\n}\n"})}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "astTransformers": {\n "before": [\n {\n "path": "my-custom-transformer-that-needs-extra-opts",\n "options": {} // extra options to pass to transformers here\n }\n ]\n }\n }\n }\n }\n}\n'})}),"\n",(0,r.jsx)(s.h3,{id:"writing-custom-typescript-ast-transformers",children:"Writing custom TypeScript AST transformers"}),"\n",(0,r.jsxs)(s.p,{children:["To write a custom TypeScript AST transformers, one can take a look at ",(0,r.jsx)(s.a,{href:"https://github.com/kulshekhar/ts-jest/tree/main/src/transformers",children:"the one"})," that ",(0,r.jsx)(s.code,{children:"ts-jest"})," is using."]})]})}function m(e={}){const{wrapper:s}={...(0,o.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(l,{...e})}):l(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>a,x:()=>i});var t=n(6540);const r={},o=t.createContext(r);function a(e){const s=t.useContext(o);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function i(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),t.createElement(o.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/03be7dae.50acd6db.js b/assets/js/03be7dae.00559958.js similarity index 99% rename from assets/js/03be7dae.50acd6db.js rename to assets/js/03be7dae.00559958.js index 9bc889eb8b..05d442e706 100644 --- a/assets/js/03be7dae.50acd6db.js +++ b/assets/js/03be7dae.00559958.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4768],{2699:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>d,contentTitle:()=>l,default:()=>u,frontMatter:()=>r,metadata:()=>t,toc:()=>a});const t=JSON.parse('{"id":"guides/troubleshooting","title":"Troubleshooting","description":"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them.","source":"@site/docs/guides/troubleshooting.md","sourceDirName":"guides","slug":"/guides/troubleshooting","permalink":"/ts-jest/docs/next/guides/troubleshooting","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/guides/troubleshooting.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"troubleshooting","title":"Troubleshooting"},"sidebar":"docs","previous":{"title":"Using with React Native","permalink":"/ts-jest/docs/next/guides/react-native"},"next":{"title":"Using with monorepo","permalink":"/ts-jest/docs/next/guides/using-with-monorepo"}}');var o=n(4848),i=n(8453);const r={id:"troubleshooting",title:"Troubleshooting"},l=void 0,d={},a=[{value:"Running ts-jest on CI tools",id:"running-ts-jest-on-ci-tools",level:2},{value:"PROBLEM",id:"problem",level:3},{value:"SOLUTION",id:"solution",level:3},{value:"Transform (node)-module explicitly",id:"transform-node-module-explicitly",level:2},{value:"PROBLEM",id:"problem-1",level:3},{value:"SOLUTION",id:"solution-1",level:3},{value:"Tests gets stuck when importing a dependency",id:"tests-gets-stuck-when-importing-a-dependency",level:2},{value:"PROBLEM",id:"problem-2",level:3},{value:"SOLUTION",id:"solution-2",level:3}];function c(e){const s={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(s.p,{children:"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them."}),"\n",(0,o.jsxs)(s.p,{children:["Please also check Jest ",(0,o.jsx)(s.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," if your issue is related to jest."]}),"\n",(0,o.jsx)(s.h2,{id:"running-ts-jest-on-ci-tools",children:"Running ts-jest on CI tools"}),"\n",(0,o.jsx)(s.h3,{id:"problem",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:'Cannot find module "" from ""'}),"\n",(0,o.jsx)(s.h3,{id:"solution",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check if ",(0,o.jsx)(s.code,{children:"rootDir"})," is referenced correctly. If not add this on your existing jest configuration."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n roots: [""]\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module directories are included on your jest configuration. If not add this on your existing jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleDirectories: ["node_modules",""],\n modulePaths: [""],\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module name is properly mapped and can be referenced by jest. If not, you can define moduleNameMapper for your jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleNameMapper: {\n "": "/",\n },\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check github folder names if its identical to you local folder names. Sometimes github never updates your folder names even if you rename it locally. If this happens rename your folders via github or use this command ",(0,o.jsx)(s.code,{children:"git mv "})," and commit changes."]}),"\n"]}),"\n",(0,o.jsx)(s.h2,{id:"transform-node-module-explicitly",children:"Transform (node)-module explicitly"}),"\n",(0,o.jsx)(s.h3,{id:"problem-1",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"SyntaxError: Cannot use import statement outside a module"}),"\n",(0,o.jsx)(s.h3,{id:"solution-1",children:"SOLUTION"}),"\n",(0,o.jsx)(s.p,{children:"One of the node modules hasn't the correct syntax for Jests execution step. It needs to\nbe transformed first."}),"\n",(0,o.jsx)(s.p,{children:"There is a good chance that the error message shows which module is affected:"}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-shell",children:' SyntaxError: Cannot use import statement outside a module\n > 22 | import Component from "../../node_modules/some-module/lib";\n | ^\n'})}),"\n",(0,o.jsxs)(s.p,{children:["In this case ",(0,o.jsx)(s.strong,{children:"some-module"})," is the problem and needs to be transformed.\nBy adding the following line to the configuration file it will tell Jest which modules\nshouldnt be ignored during the transformation step:"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n transformIgnorePatterns: ["node_modules/(?!(some-module|another-module))"]\n};\n'})}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.strong,{children:"some-module"})," and ",(0,o.jsx)(s.strong,{children:"another-module"})," will be transformed."]}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/63389757/jest-unit-test-syntaxerror-cannot-use-import-statement-outside-a-module",children:"here"})," and ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/52035066/how-to-write-jest-transformignorepatterns",children:"here"}),"."]}),"\n",(0,o.jsx)(s.h2,{id:"tests-gets-stuck-when-importing-a-dependency",children:"Tests gets stuck when importing a dependency"}),"\n",(0,o.jsx)(s.h3,{id:"problem-2",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"Without cache, jest takes an extremely long time to process files and appears to be stuck."}),"\n",(0,o.jsx)(s.h3,{id:"solution-2",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.code,{children:"ts-jest"})," internally uses TypeScript compiler API to transform ts/js file into js file. The recommendation is to only transform what is needed."]}),"\n",(0,o.jsxs)(s.p,{children:["A possible cause for that issue is that you may have enabled ",(0,o.jsx)(s.code,{children:"ts-jest"})," to process javascript files in addition to TypeScript files. This leads to the result that more files are loaded which can, in some cases, blow up the machine."]}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your tsconfig file, check if ",(0,o.jsx)(s.code,{children:"compilerOptions.allowJs"})," is unset or set to false."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'{\n "compilerOptions": {\n "allowJs": false,\n }\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your jest configuration, check if the transform property includes only ",(0,o.jsx)(s.code,{children:".ts"})," files for ts-jest. If not, change the regular expression to exclude js files. You can also add the attribute ",(0,o.jsx)(s.code,{children:"isolatedModules: true"})," for ts-jest to disable type checking for tests."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-diff",children:"module.exports = {\n ...\n 'transform': {\n- '^.+\\\\.(t|j)s$': ['ts-jest', {}],\n+ '^.+\\\\.ts$': ['ts-jest', { isolatedModules: true }],\n },\n};\n"})}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://github.com/kulshekhar/ts-jest/issues/4294",children:"here"})]})]})}function u(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,o.jsx)(s,{...e,children:(0,o.jsx)(c,{...e})}):c(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>r,x:()=>l});var t=n(6540);const o={},i=t.createContext(o);function r(e){const s=t.useContext(i);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function l(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),t.createElement(i.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4768],{2699:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>d,contentTitle:()=>l,default:()=>u,frontMatter:()=>r,metadata:()=>t,toc:()=>a});const t=JSON.parse('{"id":"guides/troubleshooting","title":"Troubleshooting","description":"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them.","source":"@site/docs/guides/troubleshooting.md","sourceDirName":"guides","slug":"/guides/troubleshooting","permalink":"/ts-jest/docs/next/guides/troubleshooting","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/guides/troubleshooting.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"troubleshooting","title":"Troubleshooting"},"sidebar":"docs","previous":{"title":"Using with React Native","permalink":"/ts-jest/docs/next/guides/react-native"},"next":{"title":"Using with monorepo","permalink":"/ts-jest/docs/next/guides/using-with-monorepo"}}');var o=n(4848),i=n(8453);const r={id:"troubleshooting",title:"Troubleshooting"},l=void 0,d={},a=[{value:"Running ts-jest on CI tools",id:"running-ts-jest-on-ci-tools",level:2},{value:"PROBLEM",id:"problem",level:3},{value:"SOLUTION",id:"solution",level:3},{value:"Transform (node)-module explicitly",id:"transform-node-module-explicitly",level:2},{value:"PROBLEM",id:"problem-1",level:3},{value:"SOLUTION",id:"solution-1",level:3},{value:"Tests gets stuck when importing a dependency",id:"tests-gets-stuck-when-importing-a-dependency",level:2},{value:"PROBLEM",id:"problem-2",level:3},{value:"SOLUTION",id:"solution-2",level:3}];function c(e){const s={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(s.p,{children:"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them."}),"\n",(0,o.jsxs)(s.p,{children:["Please also check Jest ",(0,o.jsx)(s.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," if your issue is related to jest."]}),"\n",(0,o.jsx)(s.h2,{id:"running-ts-jest-on-ci-tools",children:"Running ts-jest on CI tools"}),"\n",(0,o.jsx)(s.h3,{id:"problem",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:'Cannot find module "" from ""'}),"\n",(0,o.jsx)(s.h3,{id:"solution",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check if ",(0,o.jsx)(s.code,{children:"rootDir"})," is referenced correctly. If not add this on your existing jest configuration."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n roots: [""]\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module directories are included on your jest configuration. If not add this on your existing jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleDirectories: ["node_modules",""],\n modulePaths: [""],\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module name is properly mapped and can be referenced by jest. If not, you can define moduleNameMapper for your jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleNameMapper: {\n "": "/",\n },\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check github folder names if its identical to you local folder names. Sometimes github never updates your folder names even if you rename it locally. If this happens rename your folders via github or use this command ",(0,o.jsx)(s.code,{children:"git mv "})," and commit changes."]}),"\n"]}),"\n",(0,o.jsx)(s.h2,{id:"transform-node-module-explicitly",children:"Transform (node)-module explicitly"}),"\n",(0,o.jsx)(s.h3,{id:"problem-1",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"SyntaxError: Cannot use import statement outside a module"}),"\n",(0,o.jsx)(s.h3,{id:"solution-1",children:"SOLUTION"}),"\n",(0,o.jsx)(s.p,{children:"One of the node modules hasn't the correct syntax for Jests execution step. It needs to\nbe transformed first."}),"\n",(0,o.jsx)(s.p,{children:"There is a good chance that the error message shows which module is affected:"}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-shell",children:' SyntaxError: Cannot use import statement outside a module\n > 22 | import Component from "../../node_modules/some-module/lib";\n | ^\n'})}),"\n",(0,o.jsxs)(s.p,{children:["In this case ",(0,o.jsx)(s.strong,{children:"some-module"})," is the problem and needs to be transformed.\nBy adding the following line to the configuration file it will tell Jest which modules\nshouldnt be ignored during the transformation step:"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n transformIgnorePatterns: ["node_modules/(?!(some-module|another-module))"]\n};\n'})}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.strong,{children:"some-module"})," and ",(0,o.jsx)(s.strong,{children:"another-module"})," will be transformed."]}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/63389757/jest-unit-test-syntaxerror-cannot-use-import-statement-outside-a-module",children:"here"})," and ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/52035066/how-to-write-jest-transformignorepatterns",children:"here"}),"."]}),"\n",(0,o.jsx)(s.h2,{id:"tests-gets-stuck-when-importing-a-dependency",children:"Tests gets stuck when importing a dependency"}),"\n",(0,o.jsx)(s.h3,{id:"problem-2",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"Without cache, jest takes an extremely long time to process files and appears to be stuck."}),"\n",(0,o.jsx)(s.h3,{id:"solution-2",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.code,{children:"ts-jest"})," internally uses TypeScript compiler API to transform ts/js file into js file. The recommendation is to only transform what is needed."]}),"\n",(0,o.jsxs)(s.p,{children:["A possible cause for that issue is that you may have enabled ",(0,o.jsx)(s.code,{children:"ts-jest"})," to process javascript files in addition to TypeScript files. This leads to the result that more files are loaded which can, in some cases, blow up the machine."]}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your tsconfig file, check if ",(0,o.jsx)(s.code,{children:"compilerOptions.allowJs"})," is unset or set to false."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'{\n "compilerOptions": {\n "allowJs": false,\n }\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your jest configuration, check if the transform property includes only ",(0,o.jsx)(s.code,{children:".ts"})," files for ts-jest. If not, change the regular expression to exclude js files. You can also add the attribute ",(0,o.jsx)(s.code,{children:"isolatedModules: true"})," for ts-jest to disable type checking for tests."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-diff",children:"module.exports = {\n ...\n 'transform': {\n- '^.+\\\\.(t|j)s$': ['ts-jest', {}],\n+ '^.+\\\\.ts$': ['ts-jest', { isolatedModules: true }],\n },\n};\n"})}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://github.com/kulshekhar/ts-jest/issues/4294",children:"here"})]})]})}function u(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,o.jsx)(s,{...e,children:(0,o.jsx)(c,{...e})}):c(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>r,x:()=>l});var t=n(6540);const o={},i=t.createContext(o);function r(e){const s=t.useContext(i);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function l(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),t.createElement(i.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/057d33b8.62e2233c.js b/assets/js/057d33b8.93d2c767.js similarity index 98% rename from assets/js/057d33b8.62e2233c.js rename to assets/js/057d33b8.93d2c767.js index 47ad298761..77e498f3f2 100644 --- a/assets/js/057d33b8.62e2233c.js +++ b/assets/js/057d33b8.93d2c767.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8683],{7282:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>a,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>t,toc:()=>l});const t=JSON.parse('{"id":"guides/mock-es6-class","title":"Mock ES6 class","description":"TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.","source":"@site/versioned_docs/version-28.0/guides/mock-es6-class.md","sourceDirName":"guides","slug":"/guides/mock-es6-class","permalink":"/ts-jest/docs/28.0/guides/mock-es6-class","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/guides/mock-es6-class.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"mock-es6-class","title":"Mock ES6 class"},"sidebar":"version-28.0-docs","previous":{"title":"ESM Support","permalink":"/ts-jest/docs/28.0/guides/esm-support"},"next":{"title":"Using with React Native","permalink":"/ts-jest/docs/28.0/guides/react-native"}}');var o=n(4848),r=n(8453);const i={id:"mock-es6-class",title:"Mock ES6 class"},c=void 0,a={},l=[];function d(e){const s={code:"code",p:"p",pre:"pre",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(s.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,o.jsx)(s.code,{children:"const soundPlayer = require('./sound-player')"}),". Therefore creating an instance of the class that was exported as\na default will look like this: ",(0,o.jsx)(s.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"jest.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\n })\n})\n"})}),"\n",(0,o.jsx)(s.p,{children:"You will get the error"}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,o.jsxs)(s.p,{children:["because ",(0,o.jsx)(s.code,{children:"soundPlayer.default"})," does not point to a function. Your mock has to return an object which has a property default\nthat points to a function."]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"jest.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\n }\n }),\n }\n})\n"})}),"\n",(0,o.jsxs)(s.p,{children:["For named imports, like ",(0,o.jsx)(s.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,o.jsx)(s.code,{children:"default"})," with imported module name, ",(0,o.jsx)(s.code,{children:"OAuth2"})," in this example:"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"jest.mock('./oauth', () => {\n return {\n OAuth2: ... // mock here\n }\n})\n"})})]})}function u(e={}){const{wrapper:s}={...(0,r.R)(),...e.components};return s?(0,o.jsx)(s,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>i,x:()=>c});var t=n(6540);const o={},r=t.createContext(o);function i(e){const s=t.useContext(r);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function c(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),t.createElement(r.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8683],{7282:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>a,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>t,toc:()=>l});const t=JSON.parse('{"id":"guides/mock-es6-class","title":"Mock ES6 class","description":"TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.","source":"@site/versioned_docs/version-28.0/guides/mock-es6-class.md","sourceDirName":"guides","slug":"/guides/mock-es6-class","permalink":"/ts-jest/docs/28.0/guides/mock-es6-class","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/guides/mock-es6-class.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"mock-es6-class","title":"Mock ES6 class"},"sidebar":"version-28.0-docs","previous":{"title":"ESM Support","permalink":"/ts-jest/docs/28.0/guides/esm-support"},"next":{"title":"Using with React Native","permalink":"/ts-jest/docs/28.0/guides/react-native"}}');var o=n(4848),r=n(8453);const i={id:"mock-es6-class",title:"Mock ES6 class"},c=void 0,a={},l=[];function d(e){const s={code:"code",p:"p",pre:"pre",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(s.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,o.jsx)(s.code,{children:"const soundPlayer = require('./sound-player')"}),". Therefore creating an instance of the class that was exported as\na default will look like this: ",(0,o.jsx)(s.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"jest.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\n })\n})\n"})}),"\n",(0,o.jsx)(s.p,{children:"You will get the error"}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,o.jsxs)(s.p,{children:["because ",(0,o.jsx)(s.code,{children:"soundPlayer.default"})," does not point to a function. Your mock has to return an object which has a property default\nthat points to a function."]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"jest.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\n }\n }),\n }\n})\n"})}),"\n",(0,o.jsxs)(s.p,{children:["For named imports, like ",(0,o.jsx)(s.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,o.jsx)(s.code,{children:"default"})," with imported module name, ",(0,o.jsx)(s.code,{children:"OAuth2"})," in this example:"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"jest.mock('./oauth', () => {\n return {\n OAuth2: ... // mock here\n }\n})\n"})})]})}function u(e={}){const{wrapper:s}={...(0,r.R)(),...e.components};return s?(0,o.jsx)(s,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>i,x:()=>c});var t=n(6540);const o={},r=t.createContext(o);function i(e){const s=t.useContext(r);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function c(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),t.createElement(r.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/06fbaa8e.57ac1f62.js b/assets/js/06fbaa8e.61528603.js similarity index 97% rename from assets/js/06fbaa8e.57ac1f62.js rename to assets/js/06fbaa8e.61528603.js index d3fe1ae0cb..054d04d69f 100644 --- a/assets/js/06fbaa8e.57ac1f62.js +++ b/assets/js/06fbaa8e.61528603.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[942],{7568:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>c,default:()=>u,frontMatter:()=>r,metadata:()=>s,toc:()=>g});const s=JSON.parse('{"id":"debugging","title":"Debugging ts-jest","description":"You can activate the debug logger by setting the environment variable TSJESTLOG before running tests.","source":"@site/versioned_docs/version-27.0/debugging.md","sourceDirName":".","slug":"/debugging","permalink":"/ts-jest/docs/27.0/debugging","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/debugging.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"debugging","title":"Debugging ts-jest"},"sidebar":"version-27.0-docs","previous":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/27.0/migration"}}');var o=n(4848),i=n(8453);const r={id:"debugging",title:"Debugging ts-jest"},c=void 0,d={},g=[];function l(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["You can activate the debug logger by setting the environment variable ",(0,o.jsx)(t.code,{children:"TS_JEST_LOG"})," before running tests.\nThe output of the logger will be in ",(0,o.jsx)(t.strong,{children:"ts-jest.log"})," in current working directory."]}),"\n",(0,o.jsxs)(t.p,{children:["The debug logger contains some useful information about how internal ",(0,o.jsx)(t.code,{children:"ts-jest"})," works, including which files are processed,\nwhich Jest config or TypeScript config is used etc."]}),"\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{children:"export TS_JEST_LOG=ts-jest.log\n"})}),"\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.strong,{children:"Windows"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{children:"set TS_JEST_LOG=ts-jest.log\n"})})]})}function u(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>c});var s=n(6540);const o={},i=s.createContext(o);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[942],{7568:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>c,default:()=>u,frontMatter:()=>r,metadata:()=>s,toc:()=>g});const s=JSON.parse('{"id":"debugging","title":"Debugging ts-jest","description":"You can activate the debug logger by setting the environment variable TSJESTLOG before running tests.","source":"@site/versioned_docs/version-27.0/debugging.md","sourceDirName":".","slug":"/debugging","permalink":"/ts-jest/docs/27.0/debugging","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/debugging.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"debugging","title":"Debugging ts-jest"},"sidebar":"version-27.0-docs","previous":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/27.0/migration"}}');var o=n(4848),i=n(8453);const r={id:"debugging",title:"Debugging ts-jest"},c=void 0,d={},g=[];function l(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["You can activate the debug logger by setting the environment variable ",(0,o.jsx)(t.code,{children:"TS_JEST_LOG"})," before running tests.\nThe output of the logger will be in ",(0,o.jsx)(t.strong,{children:"ts-jest.log"})," in current working directory."]}),"\n",(0,o.jsxs)(t.p,{children:["The debug logger contains some useful information about how internal ",(0,o.jsx)(t.code,{children:"ts-jest"})," works, including which files are processed,\nwhich Jest config or TypeScript config is used etc."]}),"\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{children:"export TS_JEST_LOG=ts-jest.log\n"})}),"\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.strong,{children:"Windows"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{children:"set TS_JEST_LOG=ts-jest.log\n"})})]})}function u(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>c});var s=n(6540);const o={},i=s.createContext(o);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/07a7640f.abff013a.js b/assets/js/07a7640f.c2323d27.js similarity index 98% rename from assets/js/07a7640f.abff013a.js rename to assets/js/07a7640f.c2323d27.js index b861f1207d..dcf5e5f080 100644 --- a/assets/js/07a7640f.abff013a.js +++ b/assets/js/07a7640f.c2323d27.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7796],{5340:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>d,contentTitle:()=>l,default:()=>u,frontMatter:()=>r,metadata:()=>t,toc:()=>a});const t=JSON.parse('{"id":"guides/troubleshooting","title":"Troubleshooting","description":"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them.","source":"@site/versioned_docs/version-27.0/guides/troubleshooting.md","sourceDirName":"guides","slug":"/guides/troubleshooting","permalink":"/ts-jest/docs/27.0/guides/troubleshooting","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/guides/troubleshooting.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"troubleshooting","title":"Troubleshooting"},"sidebar":"version-27.0-docs","previous":{"title":"Test helpers","permalink":"/ts-jest/docs/27.0/guides/test-helpers"},"next":{"title":"Using with monorepo","permalink":"/ts-jest/docs/27.0/guides/using-with-monorepo"}}');var o=n(4848),i=n(8453);const r={id:"troubleshooting",title:"Troubleshooting"},l=void 0,d={},a=[{value:"Running ts-jest on CI tools",id:"running-ts-jest-on-ci-tools",level:2},{value:"PROBLEM",id:"problem",level:3},{value:"SOLUTION",id:"solution",level:3},{value:"Transform (node)-module explicitly",id:"transform-node-module-explicitly",level:2},{value:"PROBLEM",id:"problem-1",level:3},{value:"SOLUTION",id:"solution-1",level:3},{value:"Tests gets stuck when importing a dependency",id:"tests-gets-stuck-when-importing-a-dependency",level:2},{value:"PROBLEM",id:"problem-2",level:3},{value:"SOLUTION",id:"solution-2",level:3}];function c(e){const s={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(s.p,{children:"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them."}),"\n",(0,o.jsxs)(s.p,{children:["Please also check Jest ",(0,o.jsx)(s.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," if your issue is related to jest."]}),"\n",(0,o.jsx)(s.h2,{id:"running-ts-jest-on-ci-tools",children:"Running ts-jest on CI tools"}),"\n",(0,o.jsx)(s.h3,{id:"problem",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:'Cannot find module "" from ""'}),"\n",(0,o.jsx)(s.h3,{id:"solution",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check if ",(0,o.jsx)(s.code,{children:"rootDir"})," is referenced correctly. If not add this on your existing jest configuration."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n roots: [""]\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module directories are included on your jest configuration. If not add this on your existing jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleDirectories: ["node_modules",""],\n modulePaths: [""],\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module name is properly mapped and can be referenced by jest. If not, you can define moduleNameMapper for your jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleNameMapper: {\n "": "/",\n },\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check github folder names if its identical to you local folder names. Sometimes github never updates your folder names even if you rename it locally. If this happens rename your folders via github or use this command ",(0,o.jsx)(s.code,{children:"git mv "})," and commit changes."]}),"\n"]}),"\n",(0,o.jsx)(s.h2,{id:"transform-node-module-explicitly",children:"Transform (node)-module explicitly"}),"\n",(0,o.jsx)(s.h3,{id:"problem-1",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"SyntaxError: Cannot use import statement outside a module"}),"\n",(0,o.jsx)(s.h3,{id:"solution-1",children:"SOLUTION"}),"\n",(0,o.jsx)(s.p,{children:"One of the node modules hasn't the correct syntax for Jests execution step. It needs to\nbe transformed first."}),"\n",(0,o.jsx)(s.p,{children:"There is a good chance that the error message shows which module is affected:"}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-shell",children:' SyntaxError: Cannot use import statement outside a module\n > 22 | import Component from "../../node_modules/some-module/lib";\n | ^\n'})}),"\n",(0,o.jsxs)(s.p,{children:["In this case ",(0,o.jsx)(s.strong,{children:"some-module"})," is the problem and needs to be transformed.\nBy adding the following line to the configuration file it will tell Jest which modules\nshouldnt be ignored during the transformation step:"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n transformIgnorePatterns: ["node_modules/(?!(some-module|another-module))"]\n};\n'})}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.strong,{children:"some-module"})," and ",(0,o.jsx)(s.strong,{children:"another-module"})," will be transformed."]}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/63389757/jest-unit-test-syntaxerror-cannot-use-import-statement-outside-a-module",children:"here"})," and ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/52035066/how-to-write-jest-transformignorepatterns",children:"here"}),"."]}),"\n",(0,o.jsx)(s.h2,{id:"tests-gets-stuck-when-importing-a-dependency",children:"Tests gets stuck when importing a dependency"}),"\n",(0,o.jsx)(s.h3,{id:"problem-2",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"Without cache, jest takes an extremely long time to process files and appears to be stuck."}),"\n",(0,o.jsx)(s.h3,{id:"solution-2",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.code,{children:"ts-jest"})," internally uses TypeScript compiler API to transform ts/js file into js file. The recommendation is to only transform what is needed."]}),"\n",(0,o.jsxs)(s.p,{children:["A possible cause for that issue is that you may have enabled ",(0,o.jsx)(s.code,{children:"ts-jest"})," to process javascript files in addition to TypeScript files. This leads to the result that more files are loaded which can, in some cases, blow up the machine."]}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your tsconfig file, check if ",(0,o.jsx)(s.code,{children:"compilerOptions.allowJs"})," is unset or set to false."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'{\n "compilerOptions": {\n "allowJs": false,\n }\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your jest configuration, check if the transform property includes only ",(0,o.jsx)(s.code,{children:".ts"})," files for ts-jest. If not, change the regular expression to exclude js files. You can also add the attribute ",(0,o.jsx)(s.code,{children:"isolatedModules: true"})," for ts-jest to disable type checking for tests."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-diff",children:"module.exports = {\n ...\n 'transform': {\n- '^.+\\\\.(t|j)s$': ['ts-jest', {}],\n+ '^.+\\\\.ts$': ['ts-jest', { isolatedModules: true }],\n },\n};\n"})}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://github.com/kulshekhar/ts-jest/issues/4294",children:"here"})]})]})}function u(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,o.jsx)(s,{...e,children:(0,o.jsx)(c,{...e})}):c(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>r,x:()=>l});var t=n(6540);const o={},i=t.createContext(o);function r(e){const s=t.useContext(i);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function l(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),t.createElement(i.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7796],{5340:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>d,contentTitle:()=>l,default:()=>u,frontMatter:()=>r,metadata:()=>t,toc:()=>a});const t=JSON.parse('{"id":"guides/troubleshooting","title":"Troubleshooting","description":"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them.","source":"@site/versioned_docs/version-27.0/guides/troubleshooting.md","sourceDirName":"guides","slug":"/guides/troubleshooting","permalink":"/ts-jest/docs/27.0/guides/troubleshooting","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/guides/troubleshooting.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"troubleshooting","title":"Troubleshooting"},"sidebar":"version-27.0-docs","previous":{"title":"Test helpers","permalink":"/ts-jest/docs/27.0/guides/test-helpers"},"next":{"title":"Using with monorepo","permalink":"/ts-jest/docs/27.0/guides/using-with-monorepo"}}');var o=n(4848),i=n(8453);const r={id:"troubleshooting",title:"Troubleshooting"},l=void 0,d={},a=[{value:"Running ts-jest on CI tools",id:"running-ts-jest-on-ci-tools",level:2},{value:"PROBLEM",id:"problem",level:3},{value:"SOLUTION",id:"solution",level:3},{value:"Transform (node)-module explicitly",id:"transform-node-module-explicitly",level:2},{value:"PROBLEM",id:"problem-1",level:3},{value:"SOLUTION",id:"solution-1",level:3},{value:"Tests gets stuck when importing a dependency",id:"tests-gets-stuck-when-importing-a-dependency",level:2},{value:"PROBLEM",id:"problem-2",level:3},{value:"SOLUTION",id:"solution-2",level:3}];function c(e){const s={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(s.p,{children:"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them."}),"\n",(0,o.jsxs)(s.p,{children:["Please also check Jest ",(0,o.jsx)(s.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," if your issue is related to jest."]}),"\n",(0,o.jsx)(s.h2,{id:"running-ts-jest-on-ci-tools",children:"Running ts-jest on CI tools"}),"\n",(0,o.jsx)(s.h3,{id:"problem",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:'Cannot find module "" from ""'}),"\n",(0,o.jsx)(s.h3,{id:"solution",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check if ",(0,o.jsx)(s.code,{children:"rootDir"})," is referenced correctly. If not add this on your existing jest configuration."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n roots: [""]\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module directories are included on your jest configuration. If not add this on your existing jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleDirectories: ["node_modules",""],\n modulePaths: [""],\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module name is properly mapped and can be referenced by jest. If not, you can define moduleNameMapper for your jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleNameMapper: {\n "": "/",\n },\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check github folder names if its identical to you local folder names. Sometimes github never updates your folder names even if you rename it locally. If this happens rename your folders via github or use this command ",(0,o.jsx)(s.code,{children:"git mv "})," and commit changes."]}),"\n"]}),"\n",(0,o.jsx)(s.h2,{id:"transform-node-module-explicitly",children:"Transform (node)-module explicitly"}),"\n",(0,o.jsx)(s.h3,{id:"problem-1",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"SyntaxError: Cannot use import statement outside a module"}),"\n",(0,o.jsx)(s.h3,{id:"solution-1",children:"SOLUTION"}),"\n",(0,o.jsx)(s.p,{children:"One of the node modules hasn't the correct syntax for Jests execution step. It needs to\nbe transformed first."}),"\n",(0,o.jsx)(s.p,{children:"There is a good chance that the error message shows which module is affected:"}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-shell",children:' SyntaxError: Cannot use import statement outside a module\n > 22 | import Component from "../../node_modules/some-module/lib";\n | ^\n'})}),"\n",(0,o.jsxs)(s.p,{children:["In this case ",(0,o.jsx)(s.strong,{children:"some-module"})," is the problem and needs to be transformed.\nBy adding the following line to the configuration file it will tell Jest which modules\nshouldnt be ignored during the transformation step:"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n transformIgnorePatterns: ["node_modules/(?!(some-module|another-module))"]\n};\n'})}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.strong,{children:"some-module"})," and ",(0,o.jsx)(s.strong,{children:"another-module"})," will be transformed."]}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/63389757/jest-unit-test-syntaxerror-cannot-use-import-statement-outside-a-module",children:"here"})," and ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/52035066/how-to-write-jest-transformignorepatterns",children:"here"}),"."]}),"\n",(0,o.jsx)(s.h2,{id:"tests-gets-stuck-when-importing-a-dependency",children:"Tests gets stuck when importing a dependency"}),"\n",(0,o.jsx)(s.h3,{id:"problem-2",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"Without cache, jest takes an extremely long time to process files and appears to be stuck."}),"\n",(0,o.jsx)(s.h3,{id:"solution-2",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.code,{children:"ts-jest"})," internally uses TypeScript compiler API to transform ts/js file into js file. The recommendation is to only transform what is needed."]}),"\n",(0,o.jsxs)(s.p,{children:["A possible cause for that issue is that you may have enabled ",(0,o.jsx)(s.code,{children:"ts-jest"})," to process javascript files in addition to TypeScript files. This leads to the result that more files are loaded which can, in some cases, blow up the machine."]}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your tsconfig file, check if ",(0,o.jsx)(s.code,{children:"compilerOptions.allowJs"})," is unset or set to false."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'{\n "compilerOptions": {\n "allowJs": false,\n }\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your jest configuration, check if the transform property includes only ",(0,o.jsx)(s.code,{children:".ts"})," files for ts-jest. If not, change the regular expression to exclude js files. You can also add the attribute ",(0,o.jsx)(s.code,{children:"isolatedModules: true"})," for ts-jest to disable type checking for tests."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-diff",children:"module.exports = {\n ...\n 'transform': {\n- '^.+\\\\.(t|j)s$': ['ts-jest', {}],\n+ '^.+\\\\.ts$': ['ts-jest', { isolatedModules: true }],\n },\n};\n"})}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://github.com/kulshekhar/ts-jest/issues/4294",children:"here"})]})]})}function u(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,o.jsx)(s,{...e,children:(0,o.jsx)(c,{...e})}):c(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>r,x:()=>l});var t=n(6540);const o={},i=t.createContext(o);function r(e){const s=t.useContext(i);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function l(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),t.createElement(i.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/0833143f.2817f5a6.js b/assets/js/0833143f.52063431.js similarity index 97% rename from assets/js/0833143f.2817f5a6.js rename to assets/js/0833143f.52063431.js index 11c22e7184..eb7aa86a2b 100644 --- a/assets/js/0833143f.2817f5a6.js +++ b/assets/js/0833143f.52063431.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2625],{6464:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>r,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"guides/using-with-monorepo","title":"Using with monorepo","description":"To use ts-jest in a project with monorepo structure, you\'ll need to use Jest projects configuration.","source":"@site/versioned_docs/version-27.0/guides/using-with-monorepo.md","sourceDirName":"guides","slug":"/guides/using-with-monorepo","permalink":"/ts-jest/docs/27.0/guides/using-with-monorepo","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/guides/using-with-monorepo.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"using-with-monorepo","title":"Using with monorepo"},"sidebar":"version-27.0-docs","previous":{"title":"Troubleshooting","permalink":"/ts-jest/docs/27.0/guides/troubleshooting"},"next":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/27.0/babel7-or-ts"}}');var n=o(4848),i=o(8453);const r={id:"using-with-monorepo",title:"Using with monorepo"},c=void 0,u={},d=[];function a(e){const t={a:"a",code:"code",p:"p",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["To use ",(0,n.jsx)(t.code,{children:"ts-jest"})," in a project with monorepo structure, you'll need to use ",(0,n.jsx)(t.a,{href:"https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig",children:"Jest projects configuration"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["When using Jest ",(0,n.jsx)(t.code,{children:"projects"})," configuration, Jest will run ",(0,n.jsx)(t.code,{children:"ts-jest"})," against each project which is defined in the configuration."]})]})}function p(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(a,{...e})}):a(e)}},8453:(e,t,o)=>{o.d(t,{R:()=>r,x:()=>c});var s=o(6540);const n={},i=s.createContext(n);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2625],{6464:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>r,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"guides/using-with-monorepo","title":"Using with monorepo","description":"To use ts-jest in a project with monorepo structure, you\'ll need to use Jest projects configuration.","source":"@site/versioned_docs/version-27.0/guides/using-with-monorepo.md","sourceDirName":"guides","slug":"/guides/using-with-monorepo","permalink":"/ts-jest/docs/27.0/guides/using-with-monorepo","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/guides/using-with-monorepo.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"using-with-monorepo","title":"Using with monorepo"},"sidebar":"version-27.0-docs","previous":{"title":"Troubleshooting","permalink":"/ts-jest/docs/27.0/guides/troubleshooting"},"next":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/27.0/babel7-or-ts"}}');var n=o(4848),i=o(8453);const r={id:"using-with-monorepo",title:"Using with monorepo"},c=void 0,u={},d=[];function a(e){const t={a:"a",code:"code",p:"p",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["To use ",(0,n.jsx)(t.code,{children:"ts-jest"})," in a project with monorepo structure, you'll need to use ",(0,n.jsx)(t.a,{href:"https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig",children:"Jest projects configuration"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["When using Jest ",(0,n.jsx)(t.code,{children:"projects"})," configuration, Jest will run ",(0,n.jsx)(t.code,{children:"ts-jest"})," against each project which is defined in the configuration."]})]})}function p(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(a,{...e})}):a(e)}},8453:(e,t,o)=>{o.d(t,{R:()=>r,x:()=>c});var s=o(6540);const n={},i=s.createContext(n);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/093c23a0.1daed7f6.js b/assets/js/093c23a0.4144588c.js similarity index 99% rename from assets/js/093c23a0.1daed7f6.js rename to assets/js/093c23a0.4144588c.js index 8cb9ec7943..70bf307315 100644 --- a/assets/js/093c23a0.1daed7f6.js +++ b/assets/js/093c23a0.4144588c.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5258],{5003:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>j,frontMatter:()=>c,metadata:()=>n,toc:()=>h});const n=JSON.parse('{"id":"getting-started/options","title":"Options","description":"Introduction","source":"@site/versioned_docs/version-29.0/getting-started/options.md","sourceDirName":"getting-started","slug":"/getting-started/options","permalink":"/ts-jest/docs/29.0/getting-started/options","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/options.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"options","title":"Options"},"sidebar":"version-29.0-docs","previous":{"title":"Presets","permalink":"/ts-jest/docs/29.0/getting-started/presets"},"next":{"title":"Paths mapping","permalink":"/ts-jest/docs/29.0/getting-started/paths-mapping"}}');var r=s(4848),o=s(8453),i=s(9489),l=s(7227);const c={id:"options",title:"Options"},a=void 0,d={},h=[{value:"Introduction",id:"introduction",level:3},{value:"Options",id:"options",level:3}];function u(e){const t={a:"a",admonition:"admonition",code:"code",em:"em",h3:"h3",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.h3,{id:"introduction",children:"Introduction"}),"\n",(0,r.jsx)(t.admonition,{type:"caution",children:(0,r.jsxs)(t.p,{children:["If you are using custom ",(0,r.jsx)(t.code,{children:"transform"})," config, please remove ",(0,r.jsx)(t.code,{children:"preset"})," from your Jest config to avoid issues that Jest doesn't transform files correctly."]})}),"\n",(0,r.jsxs)(t.p,{children:["All ",(0,r.jsx)(t.code,{children:"ts-jest"})," specific options can be defined in Jest ",(0,r.jsx)(t.code,{children:"transform"})," config object in the ",(0,r.jsx)(t.code,{children:"package.json"})," file of your project,\nor through a ",(0,r.jsx)(t.code,{children:"jest.config.js"}),", or ",(0,r.jsx)(t.code,{children:"jest.config.ts"})," file."]}),"\n",(0,r.jsxs)(i.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n // ts-jest configuration goes here\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n // ts-jest configuration goes here\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n // ts-jest configuration goes here\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsx)(t.admonition,{type:"important",children:(0,r.jsxs)(t.p,{children:["When using TypeScript Jest config file, Jest will use ",(0,r.jsx)(t.code,{children:"ts-node"})," to compile the config file. ",(0,r.jsx)(t.code,{children:"ts-jest"})," doesn't take part in\nthat process."]})}),"\n",(0,r.jsx)(t.h3,{id:"options",children:"Options"}),"\n",(0,r.jsx)(t.p,{children:"All options have default values which should fit most of the projects. Click on the option's name to see details and example(s)."}),"\n",(0,r.jsxs)(t.table,{children:[(0,r.jsx)(t.thead,{children:(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.th,{children:"Option"}),(0,r.jsx)(t.th,{children:"Description"}),(0,r.jsx)(t.th,{children:"Type"}),(0,r.jsx)(t.th,{children:"Default"})]})}),(0,r.jsxs)(t.tbody,{children:[(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/compiler",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"compiler"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"string"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:'"typescript"'})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/tsconfig",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"tsconfig"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"string"}),"|",(0,r.jsx)(t.code,{children:"object"}),"|",(0,r.jsx)(t.code,{children:"boolean"})]}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"auto"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/isolatedModules",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"isolatedModules"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"boolean"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"disabled"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/astTransformers",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"astTransformers"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"object"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"auto"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/diagnostics",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"diagnostics"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"boolean"}),"|",(0,r.jsx)(t.code,{children:"object"})]}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"enabled"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/babelConfig",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"babelConfig"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"boolean"}),"|",(0,r.jsx)(t.code,{children:"string"}),"|",(0,r.jsx)(t.code,{children:"object"})]}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"disabled"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/stringifyContentPathRegex",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"stringifyContentPathRegex"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"string"}),"|",(0,r.jsx)(t.code,{children:"RegExp"})]}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"disabled"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/useESM",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"useESM"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/useESM",children:"Enable ESM support"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"boolean"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"auto"})})]})]})]})]})}function j(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(u,{...e})}):u(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>i});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var o=s(4848);function i(e){let{children:t,hidden:s,className:i}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,i),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>w});var n=s(6540),r=s(4164),o=s(4245),i=s(6347),l=s(6494),c=s(2814),a=s(5167),d=s(9900);function h(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function u(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return h(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:r}}=e;return{value:t,label:s,attributes:n,default:r}}))}(s);return function(e){const t=(0,a.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function j(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function x(e){let{queryString:t=!1,groupId:s}=e;const r=(0,i.W6)(),o=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,c.aZ)(o),(0,n.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(r.location.search);t.set(o,e),r.replace({...r.location,search:t.toString()})}),[o,r])]}function p(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,o=u(e),[i,c]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!j({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:o}))),[a,h]=x({queryString:s,groupId:r}),[p,f]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,o]=(0,d.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&o.set(e)}),[s,o])]}({groupId:r}),m=(()=>{const e=a??p;return j({value:e,tabValues:o})?e:null})();(0,l.A)((()=>{m&&c(m)}),[m]);return{selectedValue:i,selectValue:(0,n.useCallback)((e=>{if(!j({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);c(e),h(e),f(e)}),[h,f,o]),tabValues:o}}var f=s(1062);const m={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=s(4848);function b(e){let{className:t,block:s,selectedValue:n,selectValue:i,tabValues:l}=e;const c=[],{blockElementScrollPositionUntilNextRender:a}=(0,o.a_)(),d=e=>{const t=e.currentTarget,s=c.indexOf(t),r=l[s].value;r!==n&&(a(t),i(r))},h=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const s=c.indexOf(e.currentTarget)+1;t=c[s]??c[0];break}case"ArrowLeft":{const s=c.indexOf(e.currentTarget)-1;t=c[s]??c[c.length-1];break}}t?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":s},t),children:l.map((e=>{let{value:t,label:s,attributes:o}=e;return(0,g.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>c.push(e),onKeyDown:h,onClick:d,...o,className:(0,r.A)("tabs__item",m.tabItem,o?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:o}=e;const i=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=i.find((e=>e.props.value===o));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:i.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==o})))})}function y(e){const t=p(e);return(0,g.jsxs)("div",{className:(0,r.A)("tabs-container",m.tabList),children:[(0,g.jsx)(b,{...t,...e}),(0,g.jsx)(v,{...t,...e})]})}function w(e){const t=(0,f.A)();return(0,g.jsx)(y,{...e,children:h(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>i,x:()=>l});var n=s(6540);const r={},o=n.createContext(r);function i(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5258],{5003:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>j,frontMatter:()=>c,metadata:()=>n,toc:()=>h});const n=JSON.parse('{"id":"getting-started/options","title":"Options","description":"Introduction","source":"@site/versioned_docs/version-29.0/getting-started/options.md","sourceDirName":"getting-started","slug":"/getting-started/options","permalink":"/ts-jest/docs/29.0/getting-started/options","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/options.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"options","title":"Options"},"sidebar":"version-29.0-docs","previous":{"title":"Presets","permalink":"/ts-jest/docs/29.0/getting-started/presets"},"next":{"title":"Paths mapping","permalink":"/ts-jest/docs/29.0/getting-started/paths-mapping"}}');var r=s(4848),o=s(8453),i=s(9489),l=s(7227);const c={id:"options",title:"Options"},a=void 0,d={},h=[{value:"Introduction",id:"introduction",level:3},{value:"Options",id:"options",level:3}];function u(e){const t={a:"a",admonition:"admonition",code:"code",em:"em",h3:"h3",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.h3,{id:"introduction",children:"Introduction"}),"\n",(0,r.jsx)(t.admonition,{type:"caution",children:(0,r.jsxs)(t.p,{children:["If you are using custom ",(0,r.jsx)(t.code,{children:"transform"})," config, please remove ",(0,r.jsx)(t.code,{children:"preset"})," from your Jest config to avoid issues that Jest doesn't transform files correctly."]})}),"\n",(0,r.jsxs)(t.p,{children:["All ",(0,r.jsx)(t.code,{children:"ts-jest"})," specific options can be defined in Jest ",(0,r.jsx)(t.code,{children:"transform"})," config object in the ",(0,r.jsx)(t.code,{children:"package.json"})," file of your project,\nor through a ",(0,r.jsx)(t.code,{children:"jest.config.js"}),", or ",(0,r.jsx)(t.code,{children:"jest.config.ts"})," file."]}),"\n",(0,r.jsxs)(i.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n // ts-jest configuration goes here\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n // ts-jest configuration goes here\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n // ts-jest configuration goes here\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsx)(t.admonition,{type:"important",children:(0,r.jsxs)(t.p,{children:["When using TypeScript Jest config file, Jest will use ",(0,r.jsx)(t.code,{children:"ts-node"})," to compile the config file. ",(0,r.jsx)(t.code,{children:"ts-jest"})," doesn't take part in\nthat process."]})}),"\n",(0,r.jsx)(t.h3,{id:"options",children:"Options"}),"\n",(0,r.jsx)(t.p,{children:"All options have default values which should fit most of the projects. Click on the option's name to see details and example(s)."}),"\n",(0,r.jsxs)(t.table,{children:[(0,r.jsx)(t.thead,{children:(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.th,{children:"Option"}),(0,r.jsx)(t.th,{children:"Description"}),(0,r.jsx)(t.th,{children:"Type"}),(0,r.jsx)(t.th,{children:"Default"})]})}),(0,r.jsxs)(t.tbody,{children:[(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/compiler",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"compiler"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"string"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:'"typescript"'})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/tsconfig",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"tsconfig"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"string"}),"|",(0,r.jsx)(t.code,{children:"object"}),"|",(0,r.jsx)(t.code,{children:"boolean"})]}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"auto"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/isolatedModules",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"isolatedModules"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"boolean"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"disabled"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/astTransformers",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"astTransformers"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"object"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"auto"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/diagnostics",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"diagnostics"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"boolean"}),"|",(0,r.jsx)(t.code,{children:"object"})]}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"enabled"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/babelConfig",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"babelConfig"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"boolean"}),"|",(0,r.jsx)(t.code,{children:"string"}),"|",(0,r.jsx)(t.code,{children:"object"})]}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"disabled"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/stringifyContentPathRegex",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"stringifyContentPathRegex"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"string"}),"|",(0,r.jsx)(t.code,{children:"RegExp"})]}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"disabled"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/useESM",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"useESM"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/useESM",children:"Enable ESM support"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"boolean"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"auto"})})]})]})]})]})}function j(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(u,{...e})}):u(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>i});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var o=s(4848);function i(e){let{children:t,hidden:s,className:i}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,i),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>w});var n=s(6540),r=s(4164),o=s(4245),i=s(6347),l=s(6494),c=s(2814),a=s(5167),d=s(9900);function h(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function u(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return h(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:r}}=e;return{value:t,label:s,attributes:n,default:r}}))}(s);return function(e){const t=(0,a.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function j(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function x(e){let{queryString:t=!1,groupId:s}=e;const r=(0,i.W6)(),o=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,c.aZ)(o),(0,n.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(r.location.search);t.set(o,e),r.replace({...r.location,search:t.toString()})}),[o,r])]}function p(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,o=u(e),[i,c]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!j({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:o}))),[a,h]=x({queryString:s,groupId:r}),[p,f]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,o]=(0,d.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&o.set(e)}),[s,o])]}({groupId:r}),m=(()=>{const e=a??p;return j({value:e,tabValues:o})?e:null})();(0,l.A)((()=>{m&&c(m)}),[m]);return{selectedValue:i,selectValue:(0,n.useCallback)((e=>{if(!j({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);c(e),h(e),f(e)}),[h,f,o]),tabValues:o}}var f=s(1062);const m={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=s(4848);function b(e){let{className:t,block:s,selectedValue:n,selectValue:i,tabValues:l}=e;const c=[],{blockElementScrollPositionUntilNextRender:a}=(0,o.a_)(),d=e=>{const t=e.currentTarget,s=c.indexOf(t),r=l[s].value;r!==n&&(a(t),i(r))},h=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const s=c.indexOf(e.currentTarget)+1;t=c[s]??c[0];break}case"ArrowLeft":{const s=c.indexOf(e.currentTarget)-1;t=c[s]??c[c.length-1];break}}t?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":s},t),children:l.map((e=>{let{value:t,label:s,attributes:o}=e;return(0,g.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>c.push(e),onKeyDown:h,onClick:d,...o,className:(0,r.A)("tabs__item",m.tabItem,o?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:o}=e;const i=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=i.find((e=>e.props.value===o));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:i.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==o})))})}function y(e){const t=p(e);return(0,g.jsxs)("div",{className:(0,r.A)("tabs-container",m.tabList),children:[(0,g.jsx)(b,{...t,...e}),(0,g.jsx)(v,{...t,...e})]})}function w(e){const t=(0,f.A)();return(0,g.jsx)(y,{...e,children:h(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>i,x:()=>l});var n=s(6540);const r={},o=n.createContext(r);function i(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/0a51ecf3.bfe4da1e.js b/assets/js/0a51ecf3.be2dc629.js similarity index 99% rename from assets/js/0a51ecf3.bfe4da1e.js rename to assets/js/0a51ecf3.be2dc629.js index fe61b4ae3c..b991590be7 100644 --- a/assets/js/0a51ecf3.bfe4da1e.js +++ b/assets/js/0a51ecf3.be2dc629.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4441],{9638:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>f,frontMatter:()=>l,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"guides/react-native","title":"Using with React Native","description":"To use ts-jest with React Native + TypeScript and Babel 7, you\'ll first need to follow this tutorial.","source":"@site/versioned_docs/version-29.0/guides/react-native.md","sourceDirName":"guides","slug":"/guides/react-native","permalink":"/ts-jest/docs/29.0/guides/react-native","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/guides/react-native.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"react-native","title":"Using with React Native"},"sidebar":"version-29.0-docs","previous":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/29.0/guides/mock-es6-class"},"next":{"title":"Troubleshooting","permalink":"/ts-jest/docs/29.0/guides/troubleshooting"}}');var r=n(4848),a=n(8453),o=n(9489),i=n(7227);const l={id:"react-native",title:"Using with React Native"},c=void 0,u={},d=[{value:"Babel config",id:"babel-config",level:3},{value:"TypeScript Configuration",id:"typescript-configuration",level:3},{value:"Jest config",id:"jest-config",level:3}];function p(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["To use ",(0,r.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,r.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,r.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,r.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,r.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,r.jsx)(t.code,{children:".babelrc"})," to ",(0,r.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n\nexport default jestConfig\n"})})})]}),"\n",(0,r.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,r.jsxs)(t.p,{children:["Create a new ",(0,r.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-json",children:'// tsconfig.spec.json\n{\n "extends": "./tsconfig.json",\n "compilerOptions": {\n "jsx": "react"\n }\n}\n'})}),"\n",(0,r.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,r.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,r.jsx)(t.code,{children:"jest"})," key of ",(0,r.jsx)(t.code,{children:"package.json"})," to ",(0,r.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n preset: 'react-native',\n transform: {\n '^.+\\\\.jsx$': 'babel-jest',\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: 'tsconfig.spec.json',\n },\n ],\n },\n moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport { defaults as tsjPreset } from 'ts-jest/presets'\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n preset: 'react-native',\n transform: {\n '^.+\\\\.jsx$': 'babel-jest',\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: 'tsconfig.spec.json',\n },\n ],\n },\n moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],\n}\n\nexport default jestConfig\n"})})})]})]})}function f(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var s=n(4164);const r={tabItem:"tabItem_Ymn6"};var a=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,s.A)(r.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),r=n(4164),a=n(4245),o=n(6347),i=n(6494),l=n(2814),c=n(5167),u=n(9900);function d(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:r}}=e;return{value:t,label:n,attributes:s,default:r}}))}(n);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function f(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:n}=e;const r=(0,o.W6)(),a=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(a),(0,s.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function m(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,a=p(e),[o,l]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!f({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:a}))),[c,d]=h({queryString:n,groupId:r}),[m,g]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,u.Dv)(n);return[r,(0,s.useCallback)((e=>{n&&a.set(e)}),[n,a])]}({groupId:r}),j=(()=>{const e=c??m;return f({value:e,tabValues:a})?e:null})();(0,i.A)((()=>{j&&l(j)}),[j]);return{selectedValue:o,selectValue:(0,s.useCallback)((e=>{if(!f({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),g(e)}),[d,g,a]),tabValues:a}}var g=n(1062);const j={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=n(4848);function v(e){let{className:t,block:n,selectedValue:s,selectValue:o,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,a.a_)(),u=e=>{const t=e.currentTarget,n=l.indexOf(t),r=i[n].value;r!==s&&(c(t),o(r))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:a}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>l.push(e),onKeyDown:d,onClick:u,...a,className:(0,r.A)("tabs__item",j.tabItem,a?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:a}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,s.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=m(e);return(0,b.jsxs)("div",{className:(0,r.A)("tabs-container",j.tabList),children:[(0,b.jsx)(v,{...t,...e}),(0,b.jsx)(x,{...t,...e})]})}function w(e){const t=(0,g.A)();return(0,b.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>i});var s=n(6540);const r={},a=s.createContext(r);function o(e){const t=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),s.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4441],{9638:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>f,frontMatter:()=>l,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"guides/react-native","title":"Using with React Native","description":"To use ts-jest with React Native + TypeScript and Babel 7, you\'ll first need to follow this tutorial.","source":"@site/versioned_docs/version-29.0/guides/react-native.md","sourceDirName":"guides","slug":"/guides/react-native","permalink":"/ts-jest/docs/29.0/guides/react-native","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/guides/react-native.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"react-native","title":"Using with React Native"},"sidebar":"version-29.0-docs","previous":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/29.0/guides/mock-es6-class"},"next":{"title":"Troubleshooting","permalink":"/ts-jest/docs/29.0/guides/troubleshooting"}}');var r=n(4848),a=n(8453),o=n(9489),i=n(7227);const l={id:"react-native",title:"Using with React Native"},c=void 0,u={},d=[{value:"Babel config",id:"babel-config",level:3},{value:"TypeScript Configuration",id:"typescript-configuration",level:3},{value:"Jest config",id:"jest-config",level:3}];function p(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["To use ",(0,r.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,r.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,r.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,r.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,r.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,r.jsx)(t.code,{children:".babelrc"})," to ",(0,r.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n\nexport default jestConfig\n"})})})]}),"\n",(0,r.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,r.jsxs)(t.p,{children:["Create a new ",(0,r.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-json",children:'// tsconfig.spec.json\n{\n "extends": "./tsconfig.json",\n "compilerOptions": {\n "jsx": "react"\n }\n}\n'})}),"\n",(0,r.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,r.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,r.jsx)(t.code,{children:"jest"})," key of ",(0,r.jsx)(t.code,{children:"package.json"})," to ",(0,r.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n preset: 'react-native',\n transform: {\n '^.+\\\\.jsx$': 'babel-jest',\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: 'tsconfig.spec.json',\n },\n ],\n },\n moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport { defaults as tsjPreset } from 'ts-jest/presets'\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n preset: 'react-native',\n transform: {\n '^.+\\\\.jsx$': 'babel-jest',\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: 'tsconfig.spec.json',\n },\n ],\n },\n moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],\n}\n\nexport default jestConfig\n"})})})]})]})}function f(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var s=n(4164);const r={tabItem:"tabItem_Ymn6"};var a=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,s.A)(r.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),r=n(4164),a=n(4245),o=n(6347),i=n(6494),l=n(2814),c=n(5167),u=n(9900);function d(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:r}}=e;return{value:t,label:n,attributes:s,default:r}}))}(n);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function f(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:n}=e;const r=(0,o.W6)(),a=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(a),(0,s.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function m(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,a=p(e),[o,l]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!f({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:a}))),[c,d]=h({queryString:n,groupId:r}),[m,g]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,u.Dv)(n);return[r,(0,s.useCallback)((e=>{n&&a.set(e)}),[n,a])]}({groupId:r}),j=(()=>{const e=c??m;return f({value:e,tabValues:a})?e:null})();(0,i.A)((()=>{j&&l(j)}),[j]);return{selectedValue:o,selectValue:(0,s.useCallback)((e=>{if(!f({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),g(e)}),[d,g,a]),tabValues:a}}var g=n(1062);const j={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=n(4848);function v(e){let{className:t,block:n,selectedValue:s,selectValue:o,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,a.a_)(),u=e=>{const t=e.currentTarget,n=l.indexOf(t),r=i[n].value;r!==s&&(c(t),o(r))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:a}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>l.push(e),onKeyDown:d,onClick:u,...a,className:(0,r.A)("tabs__item",j.tabItem,a?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:a}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,s.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=m(e);return(0,b.jsxs)("div",{className:(0,r.A)("tabs-container",j.tabList),children:[(0,b.jsx)(v,{...t,...e}),(0,b.jsx)(x,{...t,...e})]})}function w(e){const t=(0,g.A)();return(0,b.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>i});var s=n(6540);const r={},a=s.createContext(r);function o(e){const t=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),s.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/0b2fcab7.524bcc94.js b/assets/js/0b2fcab7.a6171f76.js similarity index 98% rename from assets/js/0b2fcab7.524bcc94.js rename to assets/js/0b2fcab7.a6171f76.js index 219be4a038..cbd286ff95 100644 --- a/assets/js/0b2fcab7.524bcc94.js +++ b/assets/js/0b2fcab7.a6171f76.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3004],{2639:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>a,contentTitle:()=>c,default:()=>g,frontMatter:()=>r,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"migration","title":"Migration from <=23.10","description":"You can use the config:migrate tool of ts-jest CLI if you\'re coming from an older version to help you migrate your Jest configuration.","source":"@site/versioned_docs/version-27.0/migration.md","sourceDirName":".","slug":"/migration","permalink":"/ts-jest/docs/27.0/migration","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/migration.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"migration","title":"Migration from <=23.10"},"sidebar":"version-27.0-docs","previous":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/27.0/babel7-or-ts"},"next":{"title":"Debugging ts-jest","permalink":"/ts-jest/docs/27.0/debugging"}}');var o=t(4848),i=t(8453);const r={id:"migration",title:"Migration from <=23.10"},c=void 0,a={},d=[{value:"NPM",id:"npm",level:3},{value:"Yarn",id:"yarn",level:3},{value:"NPM",id:"npm-1",level:3},{value:"Yarn",id:"yarn-1",level:3}];function l(e){const n={code:"code",em:"em",h3:"h3",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:["You can use the ",(0,o.jsx)(n.code,{children:"config:migrate"})," tool of ",(0,o.jsx)(n.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsxs)(n.em,{children:["If you're using ",(0,o.jsx)(n.code,{children:"jest.config.js"}),":"]})}),"\n",(0,o.jsx)(n.h3,{id:"npm",children:"NPM"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate jest.config.js\n"})}),"\n",(0,o.jsx)(n.h3,{id:"yarn",children:"Yarn"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate jest.config.js\n"})}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsxs)(n.em,{children:["If you're using ",(0,o.jsx)(n.code,{children:"jest"})," config property of ",(0,o.jsx)(n.code,{children:"package.json"}),":"]})}),"\n",(0,o.jsx)(n.h3,{id:"npm-1",children:"NPM"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate package.json\n"})}),"\n",(0,o.jsx)(n.h3,{id:"yarn-1",children:"Yarn"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate package.json\n"})})]})}function g(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>r,x:()=>c});var s=t(6540);const o={},i=s.createContext(o);function r(e){const n=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function c(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3004],{2639:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>a,contentTitle:()=>c,default:()=>g,frontMatter:()=>r,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"migration","title":"Migration from <=23.10","description":"You can use the config:migrate tool of ts-jest CLI if you\'re coming from an older version to help you migrate your Jest configuration.","source":"@site/versioned_docs/version-27.0/migration.md","sourceDirName":".","slug":"/migration","permalink":"/ts-jest/docs/27.0/migration","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/migration.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"migration","title":"Migration from <=23.10"},"sidebar":"version-27.0-docs","previous":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/27.0/babel7-or-ts"},"next":{"title":"Debugging ts-jest","permalink":"/ts-jest/docs/27.0/debugging"}}');var o=t(4848),i=t(8453);const r={id:"migration",title:"Migration from <=23.10"},c=void 0,a={},d=[{value:"NPM",id:"npm",level:3},{value:"Yarn",id:"yarn",level:3},{value:"NPM",id:"npm-1",level:3},{value:"Yarn",id:"yarn-1",level:3}];function l(e){const n={code:"code",em:"em",h3:"h3",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:["You can use the ",(0,o.jsx)(n.code,{children:"config:migrate"})," tool of ",(0,o.jsx)(n.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsxs)(n.em,{children:["If you're using ",(0,o.jsx)(n.code,{children:"jest.config.js"}),":"]})}),"\n",(0,o.jsx)(n.h3,{id:"npm",children:"NPM"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate jest.config.js\n"})}),"\n",(0,o.jsx)(n.h3,{id:"yarn",children:"Yarn"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate jest.config.js\n"})}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsxs)(n.em,{children:["If you're using ",(0,o.jsx)(n.code,{children:"jest"})," config property of ",(0,o.jsx)(n.code,{children:"package.json"}),":"]})}),"\n",(0,o.jsx)(n.h3,{id:"npm-1",children:"NPM"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate package.json\n"})}),"\n",(0,o.jsx)(n.h3,{id:"yarn-1",children:"Yarn"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate package.json\n"})})]})}function g(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>r,x:()=>c});var s=t(6540);const o={},i=s.createContext(o);function r(e){const n=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function c(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/0d0f47fc.66e804d6.js b/assets/js/0d0f47fc.1ac99fc2.js similarity index 99% rename from assets/js/0d0f47fc.66e804d6.js rename to assets/js/0d0f47fc.1ac99fc2.js index cb006c4263..f24e7c3773 100644 --- a/assets/js/0d0f47fc.66e804d6.js +++ b/assets/js/0d0f47fc.1ac99fc2.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4263],{6868:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>a,contentTitle:()=>d,default:()=>u,frontMatter:()=>l,metadata:()=>r,toc:()=>j});const r=JSON.parse('{"id":"getting-started/presets","title":"Presets","description":"The presets","source":"@site/versioned_docs/version-29.0/getting-started/presets.md","sourceDirName":"getting-started","slug":"/getting-started/presets","permalink":"/ts-jest/docs/29.0/getting-started/presets","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/presets.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"presets","title":"Presets"},"sidebar":"version-29.0-docs","previous":{"title":"Installation","permalink":"/ts-jest/docs/29.0/getting-started/installation"},"next":{"title":"Options","permalink":"/ts-jest/docs/29.0/getting-started/options"}}');var n=t(4848),i=t(8453),c=t(9489),o=t(7227);const l={id:"presets",title:"Presets"},d=void 0,a={},j=[{value:"The presets",id:"the-presets",level:3},{value:"Basic usage",id:"basic-usage",level:3},{value:"Advanced",id:"advanced",level:3}];function h(e){const s={admonition:"admonition",code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(s.h3,{id:"the-presets",children:"The presets"}),"\n",(0,n.jsx)(s.admonition,{type:"important",children:(0,n.jsxs)(s.p,{children:["Starting from ",(0,n.jsx)(s.strong,{children:"v28.0.0"}),", ",(0,n.jsx)(s.code,{children:"ts-jest"})," will gradually opt in adoption of ",(0,n.jsx)(s.code,{children:"esbuild"}),"/",(0,n.jsx)(s.code,{children:"swc"})," more to improve the performance. To make the transition smoothly, we introduce ",(0,n.jsx)(s.code,{children:"legacy"})," presets as a fallback when the new codes don't work yet."]})}),"\n",(0,n.jsx)(s.admonition,{type:"caution",children:(0,n.jsxs)(s.p,{children:["If you are using custom ",(0,n.jsx)(s.code,{children:"transform"})," config, please remove ",(0,n.jsx)(s.code,{children:"preset"})," from your Jest config to avoid issues that Jest doesn't transform files correctly."]})}),"\n",(0,n.jsxs)(s.p,{children:[(0,n.jsx)(s.code,{children:"ts-jest"})," comes with several presets, covering most of the project's base configuration:"]}),"\n",(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{children:"Preset name"}),(0,n.jsx)(s.th,{children:"Description"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsxs)(s.td,{children:[(0,n.jsx)(s.code,{children:"ts-jest/presets/default"}),(0,n.jsx)("br",{}),"or ",(0,n.jsx)(s.code,{children:"ts-jest"})]}),(0,n.jsxs)(s.td,{children:["TypeScript files (",(0,n.jsx)(s.code,{children:".ts"}),", ",(0,n.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"ts-jest"})," to ",(0,n.jsx)(s.strong,{children:"CommonJS"})," syntax, leaving JavaScript files (",(0,n.jsx)(s.code,{children:".js"}),", ",(0,n.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsxs)(s.td,{children:[(0,n.jsx)(s.code,{children:"ts-jest/presets/default-legacy"}),(0,n.jsx)("br",{}),"or ",(0,n.jsx)(s.code,{children:"ts-jest/legacy"})," (",(0,n.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,n.jsxs)(s.td,{children:["TypeScript files (",(0,n.jsx)(s.code,{children:".ts"}),", ",(0,n.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"ts-jest"})," to ",(0,n.jsx)(s.strong,{children:"CommonJS"})," syntax, leaving JavaScript files (",(0,n.jsx)(s.code,{children:".js"}),", ",(0,n.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsxs)(s.td,{children:[(0,n.jsx)(s.code,{children:"ts-jest/presets/default-esm"}),(0,n.jsx)("br",{})]}),(0,n.jsxs)(s.td,{children:["TypeScript files (",(0,n.jsx)(s.code,{children:".ts"}),", ",(0,n.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"ts-jest"})," to ",(0,n.jsx)(s.strong,{children:"ESM"})," syntax, leaving JavaScript files (",(0,n.jsx)(s.code,{children:".js"}),", ",(0,n.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsxs)(s.td,{children:[(0,n.jsx)(s.code,{children:"ts-jest/presets/default-esm-legacy"}),(0,n.jsx)("br",{})," (",(0,n.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,n.jsxs)(s.td,{children:["TypeScript files (",(0,n.jsx)(s.code,{children:".ts"}),", ",(0,n.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"ts-jest"})," to ",(0,n.jsx)(s.strong,{children:"ESM"})," syntax, leaving JavaScript files (",(0,n.jsx)(s.code,{children:".js"}),", ",(0,n.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"ts-jest/presets/js-with-ts"})}),(0,n.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,n.jsx)(s.code,{children:".ts"}),", ",(0,n.jsx)(s.code,{children:".tsx"}),", ",(0,n.jsx)(s.code,{children:".js"}),", ",(0,n.jsx)(s.code,{children:".jsx"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"ts-jest"})," to ",(0,n.jsx)(s.strong,{children:"CommonJS"})," syntax.",(0,n.jsx)("br",{}),"You'll need to set ",(0,n.jsx)(s.code,{children:"allowJs"})," to ",(0,n.jsx)(s.code,{children:"true"})," in your ",(0,n.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsxs)(s.td,{children:[(0,n.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-legacy"})," (",(0,n.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,n.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,n.jsx)(s.code,{children:".ts"}),", ",(0,n.jsx)(s.code,{children:".tsx"}),", ",(0,n.jsx)(s.code,{children:".js"}),", ",(0,n.jsx)(s.code,{children:".jsx"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"ts-jest"})," to ",(0,n.jsx)(s.strong,{children:"CommonJS"})," syntax.",(0,n.jsx)("br",{}),"You'll need to set ",(0,n.jsx)(s.code,{children:"allowJs"})," to ",(0,n.jsx)(s.code,{children:"true"})," in your ",(0,n.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-esm"})}),(0,n.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,n.jsx)(s.code,{children:".ts"}),", ",(0,n.jsx)(s.code,{children:".tsx"}),", ",(0,n.jsx)(s.code,{children:".js"}),", ",(0,n.jsx)(s.code,{children:".jsx"}),", ",(0,n.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"ts-jest"})," to ",(0,n.jsx)(s.strong,{children:"ESM"})," syntax.",(0,n.jsx)("br",{}),"You'll need to set ",(0,n.jsx)(s.code,{children:"allowJs"})," to ",(0,n.jsx)(s.code,{children:"true"})," in your ",(0,n.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsxs)(s.td,{children:[(0,n.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-esm-legacy"})," (",(0,n.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,n.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,n.jsx)(s.code,{children:".ts"}),", ",(0,n.jsx)(s.code,{children:".tsx"}),", ",(0,n.jsx)(s.code,{children:".js"}),", ",(0,n.jsx)(s.code,{children:".jsx"}),", ",(0,n.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"ts-jest"})," to ",(0,n.jsx)(s.strong,{children:"ESM"})," syntax.",(0,n.jsx)("br",{}),"You'll need to set ",(0,n.jsx)(s.code,{children:"allowJs"})," to ",(0,n.jsx)(s.code,{children:"true"})," in your ",(0,n.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"ts-jest/presets/js-with-babel"})}),(0,n.jsxs)(s.td,{children:["TypeScript files (",(0,n.jsx)(s.code,{children:".ts"}),", ",(0,n.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"ts-jest"})," to ",(0,n.jsx)(s.strong,{children:"CommonJS"})," syntax, and JavaScript files (",(0,n.jsx)(s.code,{children:".js"}),", ",(0,n.jsx)(s.code,{children:"jsx"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsxs)(s.td,{children:[(0,n.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-legacy"})," (",(0,n.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,n.jsxs)(s.td,{children:["TypeScript files (",(0,n.jsx)(s.code,{children:".ts"}),", ",(0,n.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"ts-jest"})," to ",(0,n.jsx)(s.strong,{children:"CommonJS"})," syntax, and JavaScript files (",(0,n.jsx)(s.code,{children:".js"}),", ",(0,n.jsx)(s.code,{children:"jsx"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-esm"})}),(0,n.jsxs)(s.td,{children:["TypeScript files (",(0,n.jsx)(s.code,{children:".ts"}),", ",(0,n.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"ts-jest"})," to ",(0,n.jsx)(s.strong,{children:"ESM"})," syntax, and JavaScript files (",(0,n.jsx)(s.code,{children:".js"}),", ",(0,n.jsx)(s.code,{children:"jsx"}),", ",(0,n.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsxs)(s.td,{children:[(0,n.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-esm-legacy"})," (",(0,n.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,n.jsxs)(s.td,{children:["TypeScript files (",(0,n.jsx)(s.code,{children:".ts"}),", ",(0,n.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"ts-jest"})," to ",(0,n.jsx)(s.strong,{children:"ESM"})," syntax, and JavaScript files (",(0,n.jsx)(s.code,{children:".js"}),", ",(0,n.jsx)(s.code,{children:"jsx"}),", ",(0,n.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"babel-jest"}),"."]})]})]})]}),"\n",(0,n.jsx)(s.h3,{id:"basic-usage",children:"Basic usage"}),"\n",(0,n.jsxs)(s.p,{children:["In most cases, simply setting the ",(0,n.jsx)(s.code,{children:"preset"})," key to the desired preset name in your Jest config should be enough to start\nusing TypeScript with Jest (assuming you added ",(0,n.jsx)(s.code,{children:"ts-jest"})," to your ",(0,n.jsx)(s.code,{children:"devDependencies"})," of course):"]}),"\n",(0,n.jsxs)(c.A,{groupId:"code-examples",children:[(0,n.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(s.pre,{children:(0,n.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n // Replace `ts-jest` with the preset you want to use\n // from the above list\n preset: 'ts-jest',\n}\n"})})}),(0,n.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(s.pre,{children:(0,n.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n // Replace `ts-jest` with the preset you want to use\n // from the above list\n preset: 'ts-jest',\n}\n\nexport default jestConfig\n"})})}),(0,n.jsx)(o.A,{value:"JSON",children:(0,n.jsx)(s.pre,{children:(0,n.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n\n{\n // [...]\n "jest": {\n // Replace `ts-jest` with the preset you want to use\n // from the above list\n "preset": "ts-jest"\n }\n}\n'})})})]}),"\n",(0,n.jsxs)(s.p,{children:[(0,n.jsx)(s.strong,{children:"Note:"})," presets use ",(0,n.jsx)(s.code,{children:"testMatch"}),", like Jest does in its defaults. If you want to use ",(0,n.jsx)(s.code,{children:"testRegex"})," instead in your configuration, you MUST set ",(0,n.jsx)(s.code,{children:"testMatch"})," to ",(0,n.jsx)(s.code,{children:"null"})," or Jest will bail."]}),"\n",(0,n.jsx)(s.h3,{id:"advanced",children:"Advanced"}),"\n",(0,n.jsxs)(s.p,{children:["Any preset can also be used with other options.\nIf you're already using another preset, you might want only some specific settings from the chosen ",(0,n.jsx)(s.code,{children:"ts-jest"})," preset.\nIn this case you'll need to use the JavaScript version of Jest config (comment/uncomment according to your use case):"]}),"\n",(0,n.jsxs)(c.A,{groupId:"code-examples",children:[(0,n.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(s.pre,{children:(0,n.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n// const { defaultsESM: tsjPreset } = require('ts-jest/presets')\n// const { jsWithTs: tsjPreset } = require('ts-jest/presets')\n// const { jsWithTsESM: tsjPreset } = require('ts-jest/presets')\n// const { jsWithBabel: tsjPreset } = require('ts-jest/presets')\n// const { jsWithBabelESM: tsjPreset } = require('ts-jest/presets')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n ...tsjPreset.transform,\n // [...]\n },\n}\n"})})}),(0,n.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(s.pre,{children:(0,n.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nimport { defaults as tsjPreset } from 'ts-jest/presets'\n// import { defaultsESM as tsjPreset } from 'ts-jest/presets';\n// import { jsWithTs as tsjPreset } from 'ts-jest/presets';\n// import { jsWithTsESM as tsjPreset } from 'ts-jest/presets';\n// import { jsWithBabel as tsjPreset } from 'ts-jest/presets';\n// import { jsWithBabelESM as tsjPreset } from 'ts-jest/presets';\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n ...tsjPreset.transform,\n // [...]\n },\n}\n\nexport default jestConfig\n"})})})]})]})}function u(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.jsx)(h,{...e})}):h(e)}},7227:(e,s,t)=>{t.d(s,{A:()=>c});t(6540);var r=t(4164);const n={tabItem:"tabItem_Ymn6"};var i=t(4848);function c(e){let{children:s,hidden:t,className:c}=e;return(0,i.jsx)("div",{role:"tabpanel",className:(0,r.A)(n.tabItem,c),hidden:t,children:s})}},9489:(e,s,t)=>{t.d(s,{A:()=>w});var r=t(6540),n=t(4164),i=t(4245),c=t(6347),o=t(6494),l=t(2814),d=t(5167),a=t(9900);function j(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:s}=e;return!!s&&"object"==typeof s&&"value"in s}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:s,children:t}=e;return(0,r.useMemo)((()=>{const e=s??function(e){return j(e).map((e=>{let{props:{value:s,label:t,attributes:r,default:n}}=e;return{value:s,label:t,attributes:r,default:n}}))}(t);return function(e){const s=(0,d.XI)(e,((e,s)=>e.value===s.value));if(s.length>0)throw new Error(`Docusaurus error: Duplicate values "${s.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[s,t])}function u(e){let{value:s,tabValues:t}=e;return t.some((e=>e.value===s))}function x(e){let{queryString:s=!1,groupId:t}=e;const n=(0,c.W6)(),i=function(e){let{queryString:s=!1,groupId:t}=e;if("string"==typeof s)return s;if(!1===s)return null;if(!0===s&&!t)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return t??null}({queryString:s,groupId:t});return[(0,l.aZ)(i),(0,r.useCallback)((e=>{if(!i)return;const s=new URLSearchParams(n.location.search);s.set(i,e),n.replace({...n.location,search:s.toString()})}),[i,n])]}function p(e){const{defaultValue:s,queryString:t=!1,groupId:n}=e,i=h(e),[c,l]=(0,r.useState)((()=>function(e){let{defaultValue:s,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(s){if(!u({value:s,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${s}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return s}const r=t.find((e=>e.default))??t[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:s,tabValues:i}))),[d,j]=x({queryString:t,groupId:n}),[p,f]=function(e){let{groupId:s}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(s),[n,i]=(0,a.Dv)(t);return[n,(0,r.useCallback)((e=>{t&&i.set(e)}),[t,i])]}({groupId:n}),m=(()=>{const e=d??p;return u({value:e,tabValues:i})?e:null})();(0,o.A)((()=>{m&&l(m)}),[m]);return{selectedValue:c,selectValue:(0,r.useCallback)((e=>{if(!u({value:e,tabValues:i}))throw new Error(`Can't select invalid tab value=${e}`);l(e),j(e),f(e)}),[j,f,i]),tabValues:i}}var f=t(1062);const m={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=t(4848);function g(e){let{className:s,block:t,selectedValue:r,selectValue:c,tabValues:o}=e;const l=[],{blockElementScrollPositionUntilNextRender:d}=(0,i.a_)(),a=e=>{const s=e.currentTarget,t=l.indexOf(s),n=o[t].value;n!==r&&(d(s),c(n))},j=e=>{let s=null;switch(e.key){case"Enter":a(e);break;case"ArrowRight":{const t=l.indexOf(e.currentTarget)+1;s=l[t]??l[0];break}case"ArrowLeft":{const t=l.indexOf(e.currentTarget)-1;s=l[t]??l[l.length-1];break}}s?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,n.A)("tabs",{"tabs--block":t},s),children:o.map((e=>{let{value:s,label:t,attributes:i}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:r===s?0:-1,"aria-selected":r===s,ref:e=>l.push(e),onKeyDown:j,onClick:a,...i,className:(0,n.A)("tabs__item",m.tabItem,i?.className,{"tabs__item--active":r===s}),children:t??s},s)}))})}function y(e){let{lazy:s,children:t,selectedValue:i}=e;const c=(Array.isArray(t)?t:[t]).filter(Boolean);if(s){const e=c.find((e=>e.props.value===i));return e?(0,r.cloneElement)(e,{className:(0,n.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:c.map(((e,s)=>(0,r.cloneElement)(e,{key:s,hidden:e.props.value!==i})))})}function v(e){const s=p(e);return(0,b.jsxs)("div",{className:(0,n.A)("tabs-container",m.tabList),children:[(0,b.jsx)(g,{...s,...e}),(0,b.jsx)(y,{...s,...e})]})}function w(e){const s=(0,f.A)();return(0,b.jsx)(v,{...e,children:j(e.children)},String(s))}},8453:(e,s,t)=>{t.d(s,{R:()=>c,x:()=>o});var r=t(6540);const n={},i=r.createContext(n);function c(e){const s=r.useContext(i);return r.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function o(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:c(e.components),r.createElement(i.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4263],{6868:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>a,contentTitle:()=>d,default:()=>u,frontMatter:()=>l,metadata:()=>r,toc:()=>j});const r=JSON.parse('{"id":"getting-started/presets","title":"Presets","description":"The presets","source":"@site/versioned_docs/version-29.0/getting-started/presets.md","sourceDirName":"getting-started","slug":"/getting-started/presets","permalink":"/ts-jest/docs/29.0/getting-started/presets","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/presets.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"presets","title":"Presets"},"sidebar":"version-29.0-docs","previous":{"title":"Installation","permalink":"/ts-jest/docs/29.0/getting-started/installation"},"next":{"title":"Options","permalink":"/ts-jest/docs/29.0/getting-started/options"}}');var n=t(4848),i=t(8453),c=t(9489),o=t(7227);const l={id:"presets",title:"Presets"},d=void 0,a={},j=[{value:"The presets",id:"the-presets",level:3},{value:"Basic usage",id:"basic-usage",level:3},{value:"Advanced",id:"advanced",level:3}];function h(e){const s={admonition:"admonition",code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(s.h3,{id:"the-presets",children:"The presets"}),"\n",(0,n.jsx)(s.admonition,{type:"important",children:(0,n.jsxs)(s.p,{children:["Starting from ",(0,n.jsx)(s.strong,{children:"v28.0.0"}),", ",(0,n.jsx)(s.code,{children:"ts-jest"})," will gradually opt in adoption of ",(0,n.jsx)(s.code,{children:"esbuild"}),"/",(0,n.jsx)(s.code,{children:"swc"})," more to improve the performance. To make the transition smoothly, we introduce ",(0,n.jsx)(s.code,{children:"legacy"})," presets as a fallback when the new codes don't work yet."]})}),"\n",(0,n.jsx)(s.admonition,{type:"caution",children:(0,n.jsxs)(s.p,{children:["If you are using custom ",(0,n.jsx)(s.code,{children:"transform"})," config, please remove ",(0,n.jsx)(s.code,{children:"preset"})," from your Jest config to avoid issues that Jest doesn't transform files correctly."]})}),"\n",(0,n.jsxs)(s.p,{children:[(0,n.jsx)(s.code,{children:"ts-jest"})," comes with several presets, covering most of the project's base configuration:"]}),"\n",(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{children:"Preset name"}),(0,n.jsx)(s.th,{children:"Description"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsxs)(s.td,{children:[(0,n.jsx)(s.code,{children:"ts-jest/presets/default"}),(0,n.jsx)("br",{}),"or ",(0,n.jsx)(s.code,{children:"ts-jest"})]}),(0,n.jsxs)(s.td,{children:["TypeScript files (",(0,n.jsx)(s.code,{children:".ts"}),", ",(0,n.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"ts-jest"})," to ",(0,n.jsx)(s.strong,{children:"CommonJS"})," syntax, leaving JavaScript files (",(0,n.jsx)(s.code,{children:".js"}),", ",(0,n.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsxs)(s.td,{children:[(0,n.jsx)(s.code,{children:"ts-jest/presets/default-legacy"}),(0,n.jsx)("br",{}),"or ",(0,n.jsx)(s.code,{children:"ts-jest/legacy"})," (",(0,n.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,n.jsxs)(s.td,{children:["TypeScript files (",(0,n.jsx)(s.code,{children:".ts"}),", ",(0,n.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"ts-jest"})," to ",(0,n.jsx)(s.strong,{children:"CommonJS"})," syntax, leaving JavaScript files (",(0,n.jsx)(s.code,{children:".js"}),", ",(0,n.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsxs)(s.td,{children:[(0,n.jsx)(s.code,{children:"ts-jest/presets/default-esm"}),(0,n.jsx)("br",{})]}),(0,n.jsxs)(s.td,{children:["TypeScript files (",(0,n.jsx)(s.code,{children:".ts"}),", ",(0,n.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"ts-jest"})," to ",(0,n.jsx)(s.strong,{children:"ESM"})," syntax, leaving JavaScript files (",(0,n.jsx)(s.code,{children:".js"}),", ",(0,n.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsxs)(s.td,{children:[(0,n.jsx)(s.code,{children:"ts-jest/presets/default-esm-legacy"}),(0,n.jsx)("br",{})," (",(0,n.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,n.jsxs)(s.td,{children:["TypeScript files (",(0,n.jsx)(s.code,{children:".ts"}),", ",(0,n.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"ts-jest"})," to ",(0,n.jsx)(s.strong,{children:"ESM"})," syntax, leaving JavaScript files (",(0,n.jsx)(s.code,{children:".js"}),", ",(0,n.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"ts-jest/presets/js-with-ts"})}),(0,n.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,n.jsx)(s.code,{children:".ts"}),", ",(0,n.jsx)(s.code,{children:".tsx"}),", ",(0,n.jsx)(s.code,{children:".js"}),", ",(0,n.jsx)(s.code,{children:".jsx"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"ts-jest"})," to ",(0,n.jsx)(s.strong,{children:"CommonJS"})," syntax.",(0,n.jsx)("br",{}),"You'll need to set ",(0,n.jsx)(s.code,{children:"allowJs"})," to ",(0,n.jsx)(s.code,{children:"true"})," in your ",(0,n.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsxs)(s.td,{children:[(0,n.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-legacy"})," (",(0,n.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,n.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,n.jsx)(s.code,{children:".ts"}),", ",(0,n.jsx)(s.code,{children:".tsx"}),", ",(0,n.jsx)(s.code,{children:".js"}),", ",(0,n.jsx)(s.code,{children:".jsx"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"ts-jest"})," to ",(0,n.jsx)(s.strong,{children:"CommonJS"})," syntax.",(0,n.jsx)("br",{}),"You'll need to set ",(0,n.jsx)(s.code,{children:"allowJs"})," to ",(0,n.jsx)(s.code,{children:"true"})," in your ",(0,n.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-esm"})}),(0,n.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,n.jsx)(s.code,{children:".ts"}),", ",(0,n.jsx)(s.code,{children:".tsx"}),", ",(0,n.jsx)(s.code,{children:".js"}),", ",(0,n.jsx)(s.code,{children:".jsx"}),", ",(0,n.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"ts-jest"})," to ",(0,n.jsx)(s.strong,{children:"ESM"})," syntax.",(0,n.jsx)("br",{}),"You'll need to set ",(0,n.jsx)(s.code,{children:"allowJs"})," to ",(0,n.jsx)(s.code,{children:"true"})," in your ",(0,n.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsxs)(s.td,{children:[(0,n.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-esm-legacy"})," (",(0,n.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,n.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,n.jsx)(s.code,{children:".ts"}),", ",(0,n.jsx)(s.code,{children:".tsx"}),", ",(0,n.jsx)(s.code,{children:".js"}),", ",(0,n.jsx)(s.code,{children:".jsx"}),", ",(0,n.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"ts-jest"})," to ",(0,n.jsx)(s.strong,{children:"ESM"})," syntax.",(0,n.jsx)("br",{}),"You'll need to set ",(0,n.jsx)(s.code,{children:"allowJs"})," to ",(0,n.jsx)(s.code,{children:"true"})," in your ",(0,n.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"ts-jest/presets/js-with-babel"})}),(0,n.jsxs)(s.td,{children:["TypeScript files (",(0,n.jsx)(s.code,{children:".ts"}),", ",(0,n.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"ts-jest"})," to ",(0,n.jsx)(s.strong,{children:"CommonJS"})," syntax, and JavaScript files (",(0,n.jsx)(s.code,{children:".js"}),", ",(0,n.jsx)(s.code,{children:"jsx"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsxs)(s.td,{children:[(0,n.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-legacy"})," (",(0,n.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,n.jsxs)(s.td,{children:["TypeScript files (",(0,n.jsx)(s.code,{children:".ts"}),", ",(0,n.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"ts-jest"})," to ",(0,n.jsx)(s.strong,{children:"CommonJS"})," syntax, and JavaScript files (",(0,n.jsx)(s.code,{children:".js"}),", ",(0,n.jsx)(s.code,{children:"jsx"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-esm"})}),(0,n.jsxs)(s.td,{children:["TypeScript files (",(0,n.jsx)(s.code,{children:".ts"}),", ",(0,n.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"ts-jest"})," to ",(0,n.jsx)(s.strong,{children:"ESM"})," syntax, and JavaScript files (",(0,n.jsx)(s.code,{children:".js"}),", ",(0,n.jsx)(s.code,{children:"jsx"}),", ",(0,n.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsxs)(s.td,{children:[(0,n.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-esm-legacy"})," (",(0,n.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,n.jsxs)(s.td,{children:["TypeScript files (",(0,n.jsx)(s.code,{children:".ts"}),", ",(0,n.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"ts-jest"})," to ",(0,n.jsx)(s.strong,{children:"ESM"})," syntax, and JavaScript files (",(0,n.jsx)(s.code,{children:".js"}),", ",(0,n.jsx)(s.code,{children:"jsx"}),", ",(0,n.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,n.jsx)(s.code,{children:"babel-jest"}),"."]})]})]})]}),"\n",(0,n.jsx)(s.h3,{id:"basic-usage",children:"Basic usage"}),"\n",(0,n.jsxs)(s.p,{children:["In most cases, simply setting the ",(0,n.jsx)(s.code,{children:"preset"})," key to the desired preset name in your Jest config should be enough to start\nusing TypeScript with Jest (assuming you added ",(0,n.jsx)(s.code,{children:"ts-jest"})," to your ",(0,n.jsx)(s.code,{children:"devDependencies"})," of course):"]}),"\n",(0,n.jsxs)(c.A,{groupId:"code-examples",children:[(0,n.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(s.pre,{children:(0,n.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n // Replace `ts-jest` with the preset you want to use\n // from the above list\n preset: 'ts-jest',\n}\n"})})}),(0,n.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(s.pre,{children:(0,n.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n // Replace `ts-jest` with the preset you want to use\n // from the above list\n preset: 'ts-jest',\n}\n\nexport default jestConfig\n"})})}),(0,n.jsx)(o.A,{value:"JSON",children:(0,n.jsx)(s.pre,{children:(0,n.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n\n{\n // [...]\n "jest": {\n // Replace `ts-jest` with the preset you want to use\n // from the above list\n "preset": "ts-jest"\n }\n}\n'})})})]}),"\n",(0,n.jsxs)(s.p,{children:[(0,n.jsx)(s.strong,{children:"Note:"})," presets use ",(0,n.jsx)(s.code,{children:"testMatch"}),", like Jest does in its defaults. If you want to use ",(0,n.jsx)(s.code,{children:"testRegex"})," instead in your configuration, you MUST set ",(0,n.jsx)(s.code,{children:"testMatch"})," to ",(0,n.jsx)(s.code,{children:"null"})," or Jest will bail."]}),"\n",(0,n.jsx)(s.h3,{id:"advanced",children:"Advanced"}),"\n",(0,n.jsxs)(s.p,{children:["Any preset can also be used with other options.\nIf you're already using another preset, you might want only some specific settings from the chosen ",(0,n.jsx)(s.code,{children:"ts-jest"})," preset.\nIn this case you'll need to use the JavaScript version of Jest config (comment/uncomment according to your use case):"]}),"\n",(0,n.jsxs)(c.A,{groupId:"code-examples",children:[(0,n.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(s.pre,{children:(0,n.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n// const { defaultsESM: tsjPreset } = require('ts-jest/presets')\n// const { jsWithTs: tsjPreset } = require('ts-jest/presets')\n// const { jsWithTsESM: tsjPreset } = require('ts-jest/presets')\n// const { jsWithBabel: tsjPreset } = require('ts-jest/presets')\n// const { jsWithBabelESM: tsjPreset } = require('ts-jest/presets')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n ...tsjPreset.transform,\n // [...]\n },\n}\n"})})}),(0,n.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(s.pre,{children:(0,n.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nimport { defaults as tsjPreset } from 'ts-jest/presets'\n// import { defaultsESM as tsjPreset } from 'ts-jest/presets';\n// import { jsWithTs as tsjPreset } from 'ts-jest/presets';\n// import { jsWithTsESM as tsjPreset } from 'ts-jest/presets';\n// import { jsWithBabel as tsjPreset } from 'ts-jest/presets';\n// import { jsWithBabelESM as tsjPreset } from 'ts-jest/presets';\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n ...tsjPreset.transform,\n // [...]\n },\n}\n\nexport default jestConfig\n"})})})]})]})}function u(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.jsx)(h,{...e})}):h(e)}},7227:(e,s,t)=>{t.d(s,{A:()=>c});t(6540);var r=t(4164);const n={tabItem:"tabItem_Ymn6"};var i=t(4848);function c(e){let{children:s,hidden:t,className:c}=e;return(0,i.jsx)("div",{role:"tabpanel",className:(0,r.A)(n.tabItem,c),hidden:t,children:s})}},9489:(e,s,t)=>{t.d(s,{A:()=>w});var r=t(6540),n=t(4164),i=t(4245),c=t(6347),o=t(6494),l=t(2814),d=t(5167),a=t(9900);function j(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:s}=e;return!!s&&"object"==typeof s&&"value"in s}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:s,children:t}=e;return(0,r.useMemo)((()=>{const e=s??function(e){return j(e).map((e=>{let{props:{value:s,label:t,attributes:r,default:n}}=e;return{value:s,label:t,attributes:r,default:n}}))}(t);return function(e){const s=(0,d.XI)(e,((e,s)=>e.value===s.value));if(s.length>0)throw new Error(`Docusaurus error: Duplicate values "${s.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[s,t])}function u(e){let{value:s,tabValues:t}=e;return t.some((e=>e.value===s))}function x(e){let{queryString:s=!1,groupId:t}=e;const n=(0,c.W6)(),i=function(e){let{queryString:s=!1,groupId:t}=e;if("string"==typeof s)return s;if(!1===s)return null;if(!0===s&&!t)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return t??null}({queryString:s,groupId:t});return[(0,l.aZ)(i),(0,r.useCallback)((e=>{if(!i)return;const s=new URLSearchParams(n.location.search);s.set(i,e),n.replace({...n.location,search:s.toString()})}),[i,n])]}function p(e){const{defaultValue:s,queryString:t=!1,groupId:n}=e,i=h(e),[c,l]=(0,r.useState)((()=>function(e){let{defaultValue:s,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(s){if(!u({value:s,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${s}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return s}const r=t.find((e=>e.default))??t[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:s,tabValues:i}))),[d,j]=x({queryString:t,groupId:n}),[p,f]=function(e){let{groupId:s}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(s),[n,i]=(0,a.Dv)(t);return[n,(0,r.useCallback)((e=>{t&&i.set(e)}),[t,i])]}({groupId:n}),m=(()=>{const e=d??p;return u({value:e,tabValues:i})?e:null})();(0,o.A)((()=>{m&&l(m)}),[m]);return{selectedValue:c,selectValue:(0,r.useCallback)((e=>{if(!u({value:e,tabValues:i}))throw new Error(`Can't select invalid tab value=${e}`);l(e),j(e),f(e)}),[j,f,i]),tabValues:i}}var f=t(1062);const m={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=t(4848);function g(e){let{className:s,block:t,selectedValue:r,selectValue:c,tabValues:o}=e;const l=[],{blockElementScrollPositionUntilNextRender:d}=(0,i.a_)(),a=e=>{const s=e.currentTarget,t=l.indexOf(s),n=o[t].value;n!==r&&(d(s),c(n))},j=e=>{let s=null;switch(e.key){case"Enter":a(e);break;case"ArrowRight":{const t=l.indexOf(e.currentTarget)+1;s=l[t]??l[0];break}case"ArrowLeft":{const t=l.indexOf(e.currentTarget)-1;s=l[t]??l[l.length-1];break}}s?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,n.A)("tabs",{"tabs--block":t},s),children:o.map((e=>{let{value:s,label:t,attributes:i}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:r===s?0:-1,"aria-selected":r===s,ref:e=>l.push(e),onKeyDown:j,onClick:a,...i,className:(0,n.A)("tabs__item",m.tabItem,i?.className,{"tabs__item--active":r===s}),children:t??s},s)}))})}function y(e){let{lazy:s,children:t,selectedValue:i}=e;const c=(Array.isArray(t)?t:[t]).filter(Boolean);if(s){const e=c.find((e=>e.props.value===i));return e?(0,r.cloneElement)(e,{className:(0,n.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:c.map(((e,s)=>(0,r.cloneElement)(e,{key:s,hidden:e.props.value!==i})))})}function v(e){const s=p(e);return(0,b.jsxs)("div",{className:(0,n.A)("tabs-container",m.tabList),children:[(0,b.jsx)(g,{...s,...e}),(0,b.jsx)(y,{...s,...e})]})}function w(e){const s=(0,f.A)();return(0,b.jsx)(v,{...e,children:j(e.children)},String(s))}},8453:(e,s,t)=>{t.d(s,{R:()=>c,x:()=>o});var r=t(6540);const n={},i=r.createContext(n);function c(e){const s=r.useContext(i);return r.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function o(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:c(e.components),r.createElement(i.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/10aeaaf3.fea17a78.js b/assets/js/10aeaaf3.85aa8f82.js similarity index 96% rename from assets/js/10aeaaf3.fea17a78.js rename to assets/js/10aeaaf3.85aa8f82.js index 6bd639449d..1bc3c418ba 100644 --- a/assets/js/10aeaaf3.fea17a78.js +++ b/assets/js/10aeaaf3.85aa8f82.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2957],{4006:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>p,contentTitle:()=>c,default:()=>u,frontMatter:()=>r,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"guides/esm-support","title":"ESM Support","description":"ESM support is only available in v27++","source":"@site/versioned_docs/version-26.5/guides/esm-support.md","sourceDirName":"guides","slug":"/guides/esm-support","permalink":"/ts-jest/docs/26.5/guides/esm-support","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/guides/esm-support.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"esm-support","title":"ESM Support"},"sidebar":"version-26.5-docs","previous":{"title":"Version checking","permalink":"/ts-jest/docs/26.5/getting-started/version-checking"},"next":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/26.5/guides/mock-es6-class"}}');var o=s(4848),i=s(8453);const r={id:"esm-support",title:"ESM Support"},c=void 0,p={},d=[];function a(t){const e={admonition:"admonition",p:"p",strong:"strong",...(0,i.R)(),...t.components};return(0,o.jsx)(e.admonition,{type:"important",children:(0,o.jsxs)(e.p,{children:["ESM support is only available in ",(0,o.jsx)(e.strong,{children:"v27++"})]})})}function u(t={}){const{wrapper:e}={...(0,i.R)(),...t.components};return e?(0,o.jsx)(e,{...t,children:(0,o.jsx)(a,{...t})}):a(t)}},8453:(t,e,s)=>{s.d(e,{R:()=>r,x:()=>c});var n=s(6540);const o={},i=n.createContext(o);function r(t){const e=n.useContext(i);return n.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function c(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:r(t.components),n.createElement(i.Provider,{value:e},t.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2957],{4006:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>p,contentTitle:()=>c,default:()=>u,frontMatter:()=>r,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"guides/esm-support","title":"ESM Support","description":"ESM support is only available in v27++","source":"@site/versioned_docs/version-26.5/guides/esm-support.md","sourceDirName":"guides","slug":"/guides/esm-support","permalink":"/ts-jest/docs/26.5/guides/esm-support","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/guides/esm-support.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"esm-support","title":"ESM Support"},"sidebar":"version-26.5-docs","previous":{"title":"Version checking","permalink":"/ts-jest/docs/26.5/getting-started/version-checking"},"next":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/26.5/guides/mock-es6-class"}}');var o=s(4848),i=s(8453);const r={id:"esm-support",title:"ESM Support"},c=void 0,p={},d=[];function a(t){const e={admonition:"admonition",p:"p",strong:"strong",...(0,i.R)(),...t.components};return(0,o.jsx)(e.admonition,{type:"important",children:(0,o.jsxs)(e.p,{children:["ESM support is only available in ",(0,o.jsx)(e.strong,{children:"v27++"})]})})}function u(t={}){const{wrapper:e}={...(0,i.R)(),...t.components};return e?(0,o.jsx)(e,{...t,children:(0,o.jsx)(a,{...t})}):a(t)}},8453:(t,e,s)=>{s.d(e,{R:()=>r,x:()=>c});var n=s(6540);const o={},i=n.createContext(o);function r(t){const e=n.useContext(i);return n.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function c(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:r(t.components),n.createElement(i.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/1165ba55.6aa22ae8.js b/assets/js/1165ba55.79b100ec.js similarity index 98% rename from assets/js/1165ba55.6aa22ae8.js rename to assets/js/1165ba55.79b100ec.js index 913c005d8b..b64ccde27b 100644 --- a/assets/js/1165ba55.6aa22ae8.js +++ b/assets/js/1165ba55.79b100ec.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8431],{687:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>l,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/installation","title":"Installation","description":"Dependencies","source":"@site/versioned_docs/version-26.5/getting-started/installation.md","sourceDirName":"getting-started","slug":"/getting-started/installation","permalink":"/ts-jest/docs/26.5/getting-started/installation","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/getting-started/installation.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"installation","title":"Installation"},"sidebar":"version-26.5-docs","previous":{"title":"Contributing","permalink":"/ts-jest/docs/26.5/contributing"},"next":{"title":"Presets","permalink":"/ts-jest/docs/26.5/getting-started/presets"}}');var i=n(4848),o=n(8453);const l={id:"installation",title:"Installation"},r=void 0,c={},d=[{value:"Dependencies",id:"dependencies",level:3},{value:"NPM",id:"npm",level:4},{value:"Yarn",id:"yarn",level:4},{value:"Jest config file",id:"jest-config-file",level:3},{value:"Creating",id:"creating",level:4},{value:"NPM",id:"npm-1",level:4},{value:"Yarn",id:"yarn-1",level:4},{value:"Customizing",id:"customizing",level:4}];function a(e){const t={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,i.jsxs)(t.p,{children:["You can install ",(0,i.jsx)(t.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,i.jsx)(t.h4,{id:"npm",children:"NPM"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(t.h4,{id:"yarn",children:"Yarn"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(t.admonition,{type:"tip",children:(0,i.jsxs)(t.p,{children:["Tip: If you get an error with the following ",(0,i.jsx)(t.code,{children:"npm"})," commands such as ",(0,i.jsx)(t.code,{children:"npx: command not found"}),", you can replace ",(0,i.jsx)(t.code,{children:"npx XXX"})," with ",(0,i.jsx)(t.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,i.jsx)(t.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,i.jsx)(t.h4,{id:"creating",children:"Creating"}),"\n",(0,i.jsxs)(t.p,{children:["By default Jest can run without any config files, but it will not compile ",(0,i.jsx)(t.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,i.jsx)(t.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,i.jsx)(t.code,{children:"ts-jest"})," preset."]}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,i.jsx)(t.h4,{id:"npm-1",children:"NPM"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"npx ts-jest config:init\n"})}),"\n",(0,i.jsx)(t.h4,{id:"yarn-1",children:"Yarn"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"yarn ts-jest config:init\n"})}),"\n",(0,i.jsxs)(t.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,i.jsx)(t.code,{children:".ts"})," files correctly."]}),"\n",(0,i.jsxs)(t.p,{children:["You can also use the ",(0,i.jsx)(t.code,{children:"jest --init"})," command (prefixed with either ",(0,i.jsx)(t.code,{children:"npx"})," or ",(0,i.jsx)(t.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,i.jsx)(t.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,i.jsx)(t.code,{children:'preset: "ts-jest"'})," to the ",(0,i.jsx)(t.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,i.jsx)(t.h4,{id:"customizing",children:"Customizing"}),"\n",(0,i.jsxs)(t.p,{children:["For customizing jest, please follow their ",(0,i.jsx)(t.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"ts-jest"})," specific options can be found ",(0,i.jsx)(t.a,{href:"/ts-jest/docs/26.5/getting-started/options",children:"here"}),"."]})]})}function h(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(a,{...e})}):a(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>l,x:()=>r});var s=n(6540);const i={},o=s.createContext(i);function l(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:l(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8431],{687:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>l,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/installation","title":"Installation","description":"Dependencies","source":"@site/versioned_docs/version-26.5/getting-started/installation.md","sourceDirName":"getting-started","slug":"/getting-started/installation","permalink":"/ts-jest/docs/26.5/getting-started/installation","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/getting-started/installation.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"installation","title":"Installation"},"sidebar":"version-26.5-docs","previous":{"title":"Contributing","permalink":"/ts-jest/docs/26.5/contributing"},"next":{"title":"Presets","permalink":"/ts-jest/docs/26.5/getting-started/presets"}}');var i=n(4848),o=n(8453);const l={id:"installation",title:"Installation"},r=void 0,c={},d=[{value:"Dependencies",id:"dependencies",level:3},{value:"NPM",id:"npm",level:4},{value:"Yarn",id:"yarn",level:4},{value:"Jest config file",id:"jest-config-file",level:3},{value:"Creating",id:"creating",level:4},{value:"NPM",id:"npm-1",level:4},{value:"Yarn",id:"yarn-1",level:4},{value:"Customizing",id:"customizing",level:4}];function a(e){const t={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,i.jsxs)(t.p,{children:["You can install ",(0,i.jsx)(t.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,i.jsx)(t.h4,{id:"npm",children:"NPM"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(t.h4,{id:"yarn",children:"Yarn"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(t.admonition,{type:"tip",children:(0,i.jsxs)(t.p,{children:["Tip: If you get an error with the following ",(0,i.jsx)(t.code,{children:"npm"})," commands such as ",(0,i.jsx)(t.code,{children:"npx: command not found"}),", you can replace ",(0,i.jsx)(t.code,{children:"npx XXX"})," with ",(0,i.jsx)(t.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,i.jsx)(t.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,i.jsx)(t.h4,{id:"creating",children:"Creating"}),"\n",(0,i.jsxs)(t.p,{children:["By default Jest can run without any config files, but it will not compile ",(0,i.jsx)(t.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,i.jsx)(t.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,i.jsx)(t.code,{children:"ts-jest"})," preset."]}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,i.jsx)(t.h4,{id:"npm-1",children:"NPM"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"npx ts-jest config:init\n"})}),"\n",(0,i.jsx)(t.h4,{id:"yarn-1",children:"Yarn"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"yarn ts-jest config:init\n"})}),"\n",(0,i.jsxs)(t.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,i.jsx)(t.code,{children:".ts"})," files correctly."]}),"\n",(0,i.jsxs)(t.p,{children:["You can also use the ",(0,i.jsx)(t.code,{children:"jest --init"})," command (prefixed with either ",(0,i.jsx)(t.code,{children:"npx"})," or ",(0,i.jsx)(t.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,i.jsx)(t.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,i.jsx)(t.code,{children:'preset: "ts-jest"'})," to the ",(0,i.jsx)(t.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,i.jsx)(t.h4,{id:"customizing",children:"Customizing"}),"\n",(0,i.jsxs)(t.p,{children:["For customizing jest, please follow their ",(0,i.jsx)(t.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"ts-jest"})," specific options can be found ",(0,i.jsx)(t.a,{href:"/ts-jest/docs/26.5/getting-started/options",children:"here"}),"."]})]})}function h(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(a,{...e})}):a(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>l,x:()=>r});var s=n(6540);const i={},o=s.createContext(i);function l(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:l(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/12292045.14a6c846.js b/assets/js/12292045.5d460baa.js similarity index 97% rename from assets/js/12292045.14a6c846.js rename to assets/js/12292045.5d460baa.js index 963ec34d80..e8c81e8971 100644 --- a/assets/js/12292045.14a6c846.js +++ b/assets/js/12292045.5d460baa.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[610],{5141:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>n,toc:()=>a});const n=JSON.parse('{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","source":"@site/versioned_docs/version-29.2/introduction.md","sourceDirName":".","slug":"/","permalink":"/ts-jest/docs/","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/introduction.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","slug":"/"},"sidebar":"version-29.1-docs","next":{"title":"Processing flow","permalink":"/ts-jest/docs/processing"}}');var o=s(4848),r=s(8453);const i={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},c=void 0,d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,r.R)(),...t.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(e.p,{children:[(0,o.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,o.jsx)(e.a,{href:"https://jestjs.io/docs/next/code-transformation#writing-custom-transformers",children:"transformer"})," with source map support that lets you use Jest to test projects written in TypeScript."]}),"\n",(0,o.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,o.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,o.jsx)(e.code,{children:"preset-typescript"})," ",(0,o.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,o.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,o.jsx)(e.admonition,{type:"important",children:(0,o.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,o.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,o.jsx)(e.code,{children:'npm i -D ts-jest@"<23.10.0"'})," to go back to the previous version"]})})]})}function u(t={}){const{wrapper:e}={...(0,r.R)(),...t.components};return e?(0,o.jsx)(e,{...t,children:(0,o.jsx)(p,{...t})}):p(t)}},8453:(t,e,s)=>{s.d(e,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(t){const e=n.useContext(r);return n.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function c(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:i(t.components),n.createElement(r.Provider,{value:e},t.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[610],{5141:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>n,toc:()=>a});const n=JSON.parse('{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","source":"@site/versioned_docs/version-29.2/introduction.md","sourceDirName":".","slug":"/","permalink":"/ts-jest/docs/","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/introduction.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","slug":"/"},"sidebar":"version-29.1-docs","next":{"title":"Processing flow","permalink":"/ts-jest/docs/processing"}}');var o=s(4848),r=s(8453);const i={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},c=void 0,d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,r.R)(),...t.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(e.p,{children:[(0,o.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,o.jsx)(e.a,{href:"https://jestjs.io/docs/next/code-transformation#writing-custom-transformers",children:"transformer"})," with source map support that lets you use Jest to test projects written in TypeScript."]}),"\n",(0,o.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,o.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,o.jsx)(e.code,{children:"preset-typescript"})," ",(0,o.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,o.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,o.jsx)(e.admonition,{type:"important",children:(0,o.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,o.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,o.jsx)(e.code,{children:'npm i -D ts-jest@"<23.10.0"'})," to go back to the previous version"]})})]})}function u(t={}){const{wrapper:e}={...(0,r.R)(),...t.components};return e?(0,o.jsx)(e,{...t,children:(0,o.jsx)(p,{...t})}):p(t)}},8453:(t,e,s)=>{s.d(e,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(t){const e=n.useContext(r);return n.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function c(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:i(t.components),n.createElement(r.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/15c7296a.f02b1818.js b/assets/js/15c7296a.b10729cc.js similarity index 99% rename from assets/js/15c7296a.f02b1818.js rename to assets/js/15c7296a.b10729cc.js index 2714fde88a..6599e57a52 100644 --- a/assets/js/15c7296a.f02b1818.js +++ b/assets/js/15c7296a.b10729cc.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[551],{6396:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>m,frontMatter:()=>u,metadata:()=>r,toc:()=>d});const r=JSON.parse('{"id":"guides/mock-es6-class","title":"Mock ES6 class","description":"TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.","source":"@site/versioned_docs/version-29.2/guides/mock-es6-class.md","sourceDirName":"guides","slug":"/guides/mock-es6-class","permalink":"/ts-jest/docs/guides/mock-es6-class","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/guides/mock-es6-class.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"mock-es6-class","title":"Mock ES6 class"},"sidebar":"version-29.1-docs","previous":{"title":"ESM Support","permalink":"/ts-jest/docs/guides/esm-support"},"next":{"title":"Using with React Native","permalink":"/ts-jest/docs/guides/react-native"}}');var s=n(4848),a=n(8453),l=n(9489),o=n(7227);const u={id:"mock-es6-class",title:"Mock ES6 class"},i=void 0,c={},d=[];function p(e){const t={code:"code",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,s.jsx)(t.code,{children:"const soundPlayer = require('./sound-player')"}),". Therefore creating an instance of the class that was exported as\na default will look like this: ",(0,s.jsx)(t.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\n",(0,s.jsxs)(l.A,{groupId:"code-examples",children:[(0,s.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",metastring:"tab",children:"jest.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\n })\n})\n"})})}),(0,s.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"jest.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\n })\n})\n"})})})]}),"\n",(0,s.jsx)(t.p,{children:"You will get the error"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,s.jsxs)(t.p,{children:["because ",(0,s.jsx)(t.code,{children:"soundPlayer.default"})," does not point to a function. Your mock has to return an object which has a property default\nthat points to a function."]}),"\n",(0,s.jsxs)(l.A,{groupId:"code-examples",children:[(0,s.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",metastring:"tab",children:"jest.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\n }\n }),\n }\n})\n"})})}),(0,s.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"jest.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\n }\n }),\n }\n})\n"})})})]}),"\n",(0,s.jsxs)(t.p,{children:["For named imports, like ",(0,s.jsx)(t.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,s.jsx)(t.code,{children:"default"})," with imported module name, ",(0,s.jsx)(t.code,{children:"OAuth2"})," in this example:"]}),"\n",(0,s.jsxs)(l.A,{groupId:"code-examples",children:[(0,s.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",metastring:"tab",children:"jest.mock('./oauth', () => {\n return {\n OAuth2: ... // mock here\n }\n})\n"})})}),(0,s.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"jest.mock('./oauth', () => {\n return {\n OAuth2: ... // mock here\n }\n})\n"})})})]})]})}function m(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(p,{...e})}):p(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>l});n(6540);var r=n(4164);const s={tabItem:"tabItem_Ymn6"};var a=n(4848);function l(e){let{children:t,hidden:n,className:l}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,r.A)(s.tabItem,l),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>k});var r=n(6540),s=n(4164),a=n(4245),l=n(6347),o=n(6494),u=n(2814),i=n(5167),c=n(9900);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:s}}=e;return{value:t,label:n,attributes:r,default:s}}))}(n);return function(e){const t=(0,i.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:n}=e;const s=(0,l.W6)(),a=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,u.aZ)(a),(0,r.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(s.location.search);t.set(a,e),s.replace({...s.location,search:t.toString()})}),[a,s])]}function f(e){const{defaultValue:t,queryString:n=!1,groupId:s}=e,a=p(e),[l,u]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:a}))),[i,d]=h({queryString:n,groupId:s}),[f,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[s,a]=(0,c.Dv)(n);return[s,(0,r.useCallback)((e=>{n&&a.set(e)}),[n,a])]}({groupId:s}),g=(()=>{const e=i??f;return m({value:e,tabValues:a})?e:null})();(0,o.A)((()=>{g&&u(g)}),[g]);return{selectedValue:l,selectValue:(0,r.useCallback)((e=>{if(!m({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);u(e),d(e),b(e)}),[d,b,a]),tabValues:a}}var b=n(1062);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var j=n(4848);function v(e){let{className:t,block:n,selectedValue:r,selectValue:l,tabValues:o}=e;const u=[],{blockElementScrollPositionUntilNextRender:i}=(0,a.a_)(),c=e=>{const t=e.currentTarget,n=u.indexOf(t),s=o[n].value;s!==r&&(i(t),l(s))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=u.indexOf(e.currentTarget)+1;t=u[n]??u[0];break}case"ArrowLeft":{const n=u.indexOf(e.currentTarget)-1;t=u[n]??u[u.length-1];break}}t?.focus()};return(0,j.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.A)("tabs",{"tabs--block":n},t),children:o.map((e=>{let{value:t,label:n,attributes:a}=e;return(0,j.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>u.push(e),onKeyDown:d,onClick:c,...a,className:(0,s.A)("tabs__item",g.tabItem,a?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:a}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:(0,s.A)("margin-top--md",e.props.className)}):null}return(0,j.jsx)("div",{className:"margin-top--md",children:l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=f(e);return(0,j.jsxs)("div",{className:(0,s.A)("tabs-container",g.tabList),children:[(0,j.jsx)(v,{...t,...e}),(0,j.jsx)(x,{...t,...e})]})}function k(e){const t=(0,b.A)();return(0,j.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>l,x:()=>o});var r=n(6540);const s={},a=r.createContext(s);function l(e){const t=r.useContext(a);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:l(e.components),r.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[551],{6396:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>m,frontMatter:()=>u,metadata:()=>r,toc:()=>d});const r=JSON.parse('{"id":"guides/mock-es6-class","title":"Mock ES6 class","description":"TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.","source":"@site/versioned_docs/version-29.2/guides/mock-es6-class.md","sourceDirName":"guides","slug":"/guides/mock-es6-class","permalink":"/ts-jest/docs/guides/mock-es6-class","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/guides/mock-es6-class.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"mock-es6-class","title":"Mock ES6 class"},"sidebar":"version-29.1-docs","previous":{"title":"ESM Support","permalink":"/ts-jest/docs/guides/esm-support"},"next":{"title":"Using with React Native","permalink":"/ts-jest/docs/guides/react-native"}}');var s=n(4848),a=n(8453),l=n(9489),o=n(7227);const u={id:"mock-es6-class",title:"Mock ES6 class"},i=void 0,c={},d=[];function p(e){const t={code:"code",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,s.jsx)(t.code,{children:"const soundPlayer = require('./sound-player')"}),". Therefore creating an instance of the class that was exported as\na default will look like this: ",(0,s.jsx)(t.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\n",(0,s.jsxs)(l.A,{groupId:"code-examples",children:[(0,s.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",metastring:"tab",children:"jest.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\n })\n})\n"})})}),(0,s.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"jest.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\n })\n})\n"})})})]}),"\n",(0,s.jsx)(t.p,{children:"You will get the error"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,s.jsxs)(t.p,{children:["because ",(0,s.jsx)(t.code,{children:"soundPlayer.default"})," does not point to a function. Your mock has to return an object which has a property default\nthat points to a function."]}),"\n",(0,s.jsxs)(l.A,{groupId:"code-examples",children:[(0,s.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",metastring:"tab",children:"jest.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\n }\n }),\n }\n})\n"})})}),(0,s.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"jest.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\n }\n }),\n }\n})\n"})})})]}),"\n",(0,s.jsxs)(t.p,{children:["For named imports, like ",(0,s.jsx)(t.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,s.jsx)(t.code,{children:"default"})," with imported module name, ",(0,s.jsx)(t.code,{children:"OAuth2"})," in this example:"]}),"\n",(0,s.jsxs)(l.A,{groupId:"code-examples",children:[(0,s.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",metastring:"tab",children:"jest.mock('./oauth', () => {\n return {\n OAuth2: ... // mock here\n }\n})\n"})})}),(0,s.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"jest.mock('./oauth', () => {\n return {\n OAuth2: ... // mock here\n }\n})\n"})})})]})]})}function m(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(p,{...e})}):p(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>l});n(6540);var r=n(4164);const s={tabItem:"tabItem_Ymn6"};var a=n(4848);function l(e){let{children:t,hidden:n,className:l}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,r.A)(s.tabItem,l),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>k});var r=n(6540),s=n(4164),a=n(4245),l=n(6347),o=n(6494),u=n(2814),i=n(5167),c=n(9900);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:s}}=e;return{value:t,label:n,attributes:r,default:s}}))}(n);return function(e){const t=(0,i.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:n}=e;const s=(0,l.W6)(),a=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,u.aZ)(a),(0,r.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(s.location.search);t.set(a,e),s.replace({...s.location,search:t.toString()})}),[a,s])]}function f(e){const{defaultValue:t,queryString:n=!1,groupId:s}=e,a=p(e),[l,u]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:a}))),[i,d]=h({queryString:n,groupId:s}),[f,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[s,a]=(0,c.Dv)(n);return[s,(0,r.useCallback)((e=>{n&&a.set(e)}),[n,a])]}({groupId:s}),g=(()=>{const e=i??f;return m({value:e,tabValues:a})?e:null})();(0,o.A)((()=>{g&&u(g)}),[g]);return{selectedValue:l,selectValue:(0,r.useCallback)((e=>{if(!m({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);u(e),d(e),b(e)}),[d,b,a]),tabValues:a}}var b=n(1062);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var j=n(4848);function v(e){let{className:t,block:n,selectedValue:r,selectValue:l,tabValues:o}=e;const u=[],{blockElementScrollPositionUntilNextRender:i}=(0,a.a_)(),c=e=>{const t=e.currentTarget,n=u.indexOf(t),s=o[n].value;s!==r&&(i(t),l(s))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=u.indexOf(e.currentTarget)+1;t=u[n]??u[0];break}case"ArrowLeft":{const n=u.indexOf(e.currentTarget)-1;t=u[n]??u[u.length-1];break}}t?.focus()};return(0,j.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.A)("tabs",{"tabs--block":n},t),children:o.map((e=>{let{value:t,label:n,attributes:a}=e;return(0,j.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>u.push(e),onKeyDown:d,onClick:c,...a,className:(0,s.A)("tabs__item",g.tabItem,a?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:a}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:(0,s.A)("margin-top--md",e.props.className)}):null}return(0,j.jsx)("div",{className:"margin-top--md",children:l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=f(e);return(0,j.jsxs)("div",{className:(0,s.A)("tabs-container",g.tabList),children:[(0,j.jsx)(v,{...t,...e}),(0,j.jsx)(x,{...t,...e})]})}function k(e){const t=(0,b.A)();return(0,j.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>l,x:()=>o});var r=n(6540);const s={},a=r.createContext(s);function l(e){const t=r.useContext(a);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:l(e.components),r.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/16ada0e2.5d9aea68.js b/assets/js/16ada0e2.e08794d1.js similarity index 97% rename from assets/js/16ada0e2.5d9aea68.js rename to assets/js/16ada0e2.e08794d1.js index 0d0744623c..30b15a9651 100644 --- a/assets/js/16ada0e2.5d9aea68.js +++ b/assets/js/16ada0e2.e08794d1.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5623],{283:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>r,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"guides/using-with-monorepo","title":"Using with monorepo","description":"To use ts-jest in a project with monorepo structure, you\'ll need to use Jest projects configuration.","source":"@site/versioned_docs/version-28.0/guides/using-with-monorepo.md","sourceDirName":"guides","slug":"/guides/using-with-monorepo","permalink":"/ts-jest/docs/28.0/guides/using-with-monorepo","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/guides/using-with-monorepo.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"using-with-monorepo","title":"Using with monorepo"},"sidebar":"version-28.0-docs","previous":{"title":"Troubleshooting","permalink":"/ts-jest/docs/28.0/guides/troubleshooting"},"next":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/28.0/babel7-or-ts"}}');var n=o(4848),i=o(8453);const r={id:"using-with-monorepo",title:"Using with monorepo"},c=void 0,u={},d=[];function a(e){const t={a:"a",code:"code",p:"p",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["To use ",(0,n.jsx)(t.code,{children:"ts-jest"})," in a project with monorepo structure, you'll need to use ",(0,n.jsx)(t.a,{href:"https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig",children:"Jest projects configuration"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["When using Jest ",(0,n.jsx)(t.code,{children:"projects"})," configuration, Jest will run ",(0,n.jsx)(t.code,{children:"ts-jest"})," against each project which is defined in the configuration."]})]})}function p(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(a,{...e})}):a(e)}},8453:(e,t,o)=>{o.d(t,{R:()=>r,x:()=>c});var s=o(6540);const n={},i=s.createContext(n);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5623],{283:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>r,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"guides/using-with-monorepo","title":"Using with monorepo","description":"To use ts-jest in a project with monorepo structure, you\'ll need to use Jest projects configuration.","source":"@site/versioned_docs/version-28.0/guides/using-with-monorepo.md","sourceDirName":"guides","slug":"/guides/using-with-monorepo","permalink":"/ts-jest/docs/28.0/guides/using-with-monorepo","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/guides/using-with-monorepo.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"using-with-monorepo","title":"Using with monorepo"},"sidebar":"version-28.0-docs","previous":{"title":"Troubleshooting","permalink":"/ts-jest/docs/28.0/guides/troubleshooting"},"next":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/28.0/babel7-or-ts"}}');var n=o(4848),i=o(8453);const r={id:"using-with-monorepo",title:"Using with monorepo"},c=void 0,u={},d=[];function a(e){const t={a:"a",code:"code",p:"p",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["To use ",(0,n.jsx)(t.code,{children:"ts-jest"})," in a project with monorepo structure, you'll need to use ",(0,n.jsx)(t.a,{href:"https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig",children:"Jest projects configuration"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["When using Jest ",(0,n.jsx)(t.code,{children:"projects"})," configuration, Jest will run ",(0,n.jsx)(t.code,{children:"ts-jest"})," against each project which is defined in the configuration."]})]})}function p(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(a,{...e})}):a(e)}},8453:(e,t,o)=>{o.d(t,{R:()=>r,x:()=>c});var s=o(6540);const n={},i=s.createContext(n);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/16bac89a.14497471.js b/assets/js/16bac89a.7f86c6eb.js similarity index 98% rename from assets/js/16bac89a.14497471.js rename to assets/js/16bac89a.7f86c6eb.js index e0bc62b76c..ea69d2fd2f 100644 --- a/assets/js/16bac89a.14497471.js +++ b/assets/js/16bac89a.7f86c6eb.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5046],{6186:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>r,metadata:()=>s,toc:()=>l});const s=JSON.parse('{"id":"babel7-or-ts","title":"Babel7 or TypeScript","description":"In Sept. 2018 Babel7 got released with an interesting preset: @babel/preset-typescript.","source":"@site/versioned_docs/version-27.1/babel7-or-ts.md","sourceDirName":".","slug":"/babel7-or-ts","permalink":"/ts-jest/docs/27.1/babel7-or-ts","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/babel7-or-ts.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"babel7-or-ts","title":"Babel7 or TypeScript"},"sidebar":"version-27.1-docs","previous":{"title":"Using with monorepo","permalink":"/ts-jest/docs/27.1/guides/using-with-monorepo"},"next":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/27.1/migration"}}');var i=n(4848),o=n(8453);const r={id:"babel7-or-ts",title:"Babel7 or TypeScript"},c=void 0,a={},l=[{value:"Limitations",id:"limitations",level:2},{value:"No type-checking",id:"no-type-checking",level:4},{value:"No namespace",id:"no-namespace",level:4},{value:"No const enum",id:"no-const-enum",level:4},{value:"No declaration merging (enum, namespace, ...)",id:"no-declaration-merging-enum-namespace-",level:4},{value:"No legacy import/export",id:"no-legacy-importexport",level:4},{value:"No caret type-casting with JSX enabled",id:"no-caret-type-casting-with-jsx-enabled",level:4}];function d(e){const t={a:"a",code:"code",h2:"h2",h4:"h4",hr:"hr",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,i.jsxs)(t.p,{children:["The goal is to make it easy for users using Babel to try TypeScript without moving out from Babel, just by adding a preset in their Babel config (here is the ",(0,i.jsx)(t.a,{href:"https://blogs.msdn.microsoft.com/typescript/2018/08/27/typescript-and-babel-7/",children:"MSDN blog post"})," about TypeScript and Babel 7)."]}),"\n",(0,i.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,i.jsxs)(t.p,{children:["While ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"})," is a great preset, you must know the limitation of it. Here is what is possible with TypeScript (and ",(0,i.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,i.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,i.jsxs)(t.p,{children:["This is the big ",(0,i.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,i.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,i.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,i.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,i.jsx)(t.p,{children:'With Babel, files are transpiled as isolated modules, there is no notion of "project". With TypeScript, files are part of a project and are compiled in that scope.'}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,i.jsx)(t.code,{children:"namespace"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"namespace app {\n export const VERSION = '1.0.0'\n export class App {\n /* ... */\n }\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,i.jsx)(t.code,{children:"const enum"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,i.jsx)(t.code,{children:"enum"}),", ",(0,i.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,i.jsxs)(t.p,{children:["You won't be able to do ",(0,i.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,i.jsx)(t.code,{children:"import"}),"/",(0,i.jsx)(t.code,{children:"export"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>c});var s=n(6540);const i={},o=s.createContext(i);function r(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5046],{6186:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>r,metadata:()=>s,toc:()=>l});const s=JSON.parse('{"id":"babel7-or-ts","title":"Babel7 or TypeScript","description":"In Sept. 2018 Babel7 got released with an interesting preset: @babel/preset-typescript.","source":"@site/versioned_docs/version-27.1/babel7-or-ts.md","sourceDirName":".","slug":"/babel7-or-ts","permalink":"/ts-jest/docs/27.1/babel7-or-ts","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/babel7-or-ts.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"babel7-or-ts","title":"Babel7 or TypeScript"},"sidebar":"version-27.1-docs","previous":{"title":"Using with monorepo","permalink":"/ts-jest/docs/27.1/guides/using-with-monorepo"},"next":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/27.1/migration"}}');var i=n(4848),o=n(8453);const r={id:"babel7-or-ts",title:"Babel7 or TypeScript"},c=void 0,a={},l=[{value:"Limitations",id:"limitations",level:2},{value:"No type-checking",id:"no-type-checking",level:4},{value:"No namespace",id:"no-namespace",level:4},{value:"No const enum",id:"no-const-enum",level:4},{value:"No declaration merging (enum, namespace, ...)",id:"no-declaration-merging-enum-namespace-",level:4},{value:"No legacy import/export",id:"no-legacy-importexport",level:4},{value:"No caret type-casting with JSX enabled",id:"no-caret-type-casting-with-jsx-enabled",level:4}];function d(e){const t={a:"a",code:"code",h2:"h2",h4:"h4",hr:"hr",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,i.jsxs)(t.p,{children:["The goal is to make it easy for users using Babel to try TypeScript without moving out from Babel, just by adding a preset in their Babel config (here is the ",(0,i.jsx)(t.a,{href:"https://blogs.msdn.microsoft.com/typescript/2018/08/27/typescript-and-babel-7/",children:"MSDN blog post"})," about TypeScript and Babel 7)."]}),"\n",(0,i.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,i.jsxs)(t.p,{children:["While ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"})," is a great preset, you must know the limitation of it. Here is what is possible with TypeScript (and ",(0,i.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,i.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,i.jsxs)(t.p,{children:["This is the big ",(0,i.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,i.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,i.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,i.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,i.jsx)(t.p,{children:'With Babel, files are transpiled as isolated modules, there is no notion of "project". With TypeScript, files are part of a project and are compiled in that scope.'}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,i.jsx)(t.code,{children:"namespace"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"namespace app {\n export const VERSION = '1.0.0'\n export class App {\n /* ... */\n }\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,i.jsx)(t.code,{children:"const enum"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,i.jsx)(t.code,{children:"enum"}),", ",(0,i.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,i.jsxs)(t.p,{children:["You won't be able to do ",(0,i.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,i.jsx)(t.code,{children:"import"}),"/",(0,i.jsx)(t.code,{children:"export"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>c});var s=n(6540);const i={},o=s.createContext(i);function r(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/1854c3e7.d414a6fb.js b/assets/js/1854c3e7.40243a56.js similarity index 98% rename from assets/js/1854c3e7.d414a6fb.js rename to assets/js/1854c3e7.40243a56.js index fe55169ccf..c955686134 100644 --- a/assets/js/1854c3e7.d414a6fb.js +++ b/assets/js/1854c3e7.40243a56.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1797],{8357:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>r,metadata:()=>s,toc:()=>l});const s=JSON.parse('{"id":"babel7-or-ts","title":"Babel7 or TypeScript","description":"In Sept. 2018 Babel7 got released with an interesting preset: @babel/preset-typescript.","source":"@site/versioned_docs/version-26.5/babel7-or-ts.md","sourceDirName":".","slug":"/babel7-or-ts","permalink":"/ts-jest/docs/26.5/babel7-or-ts","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/babel7-or-ts.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"babel7-or-ts","title":"Babel7 or TypeScript"},"sidebar":"version-26.5-docs","previous":{"title":"Using with monorepo","permalink":"/ts-jest/docs/26.5/guides/using-with-monorepo"},"next":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/26.5/migration"}}');var i=n(4848),o=n(8453);const r={id:"babel7-or-ts",title:"Babel7 or TypeScript"},c=void 0,a={},l=[{value:"Limitations",id:"limitations",level:2},{value:"No type-checking",id:"no-type-checking",level:4},{value:"No namespace",id:"no-namespace",level:4},{value:"No const enum",id:"no-const-enum",level:4},{value:"No declaration merging (enum, namespace, ...)",id:"no-declaration-merging-enum-namespace-",level:4},{value:"No legacy import/export",id:"no-legacy-importexport",level:4},{value:"No caret type-casting with JSX enabled",id:"no-caret-type-casting-with-jsx-enabled",level:4}];function d(e){const t={a:"a",code:"code",h2:"h2",h4:"h4",hr:"hr",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,i.jsxs)(t.p,{children:["The goal is to make it easy for users using Babel to try TypeScript without moving out from Babel, just by adding a preset in their Babel config (here is the ",(0,i.jsx)(t.a,{href:"https://blogs.msdn.microsoft.com/typescript/2018/08/27/typescript-and-babel-7/",children:"MSDN blog post"})," about TypeScript and Babel 7)."]}),"\n",(0,i.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,i.jsxs)(t.p,{children:["While ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"})," is a great preset, you must know the limitation of it. Here is what is possible with TypeScript (and ",(0,i.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,i.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,i.jsxs)(t.p,{children:["This is the big ",(0,i.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,i.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,i.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,i.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,i.jsx)(t.p,{children:'With Babel, files are transpiled as isolated modules, there is no notion of "project". With TypeScript, files are part of a project and are compiled in that scope.'}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,i.jsx)(t.code,{children:"namespace"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"namespace app {\n export const VERSION = '1.0.0'\n export class App {\n /* ... */\n }\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,i.jsx)(t.code,{children:"const enum"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,i.jsx)(t.code,{children:"enum"}),", ",(0,i.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,i.jsxs)(t.p,{children:["You won't be able to do ",(0,i.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,i.jsx)(t.code,{children:"import"}),"/",(0,i.jsx)(t.code,{children:"export"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>c});var s=n(6540);const i={},o=s.createContext(i);function r(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1797],{8357:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>r,metadata:()=>s,toc:()=>l});const s=JSON.parse('{"id":"babel7-or-ts","title":"Babel7 or TypeScript","description":"In Sept. 2018 Babel7 got released with an interesting preset: @babel/preset-typescript.","source":"@site/versioned_docs/version-26.5/babel7-or-ts.md","sourceDirName":".","slug":"/babel7-or-ts","permalink":"/ts-jest/docs/26.5/babel7-or-ts","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/babel7-or-ts.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"babel7-or-ts","title":"Babel7 or TypeScript"},"sidebar":"version-26.5-docs","previous":{"title":"Using with monorepo","permalink":"/ts-jest/docs/26.5/guides/using-with-monorepo"},"next":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/26.5/migration"}}');var i=n(4848),o=n(8453);const r={id:"babel7-or-ts",title:"Babel7 or TypeScript"},c=void 0,a={},l=[{value:"Limitations",id:"limitations",level:2},{value:"No type-checking",id:"no-type-checking",level:4},{value:"No namespace",id:"no-namespace",level:4},{value:"No const enum",id:"no-const-enum",level:4},{value:"No declaration merging (enum, namespace, ...)",id:"no-declaration-merging-enum-namespace-",level:4},{value:"No legacy import/export",id:"no-legacy-importexport",level:4},{value:"No caret type-casting with JSX enabled",id:"no-caret-type-casting-with-jsx-enabled",level:4}];function d(e){const t={a:"a",code:"code",h2:"h2",h4:"h4",hr:"hr",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,i.jsxs)(t.p,{children:["The goal is to make it easy for users using Babel to try TypeScript without moving out from Babel, just by adding a preset in their Babel config (here is the ",(0,i.jsx)(t.a,{href:"https://blogs.msdn.microsoft.com/typescript/2018/08/27/typescript-and-babel-7/",children:"MSDN blog post"})," about TypeScript and Babel 7)."]}),"\n",(0,i.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,i.jsxs)(t.p,{children:["While ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"})," is a great preset, you must know the limitation of it. Here is what is possible with TypeScript (and ",(0,i.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,i.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,i.jsxs)(t.p,{children:["This is the big ",(0,i.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,i.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,i.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,i.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,i.jsx)(t.p,{children:'With Babel, files are transpiled as isolated modules, there is no notion of "project". With TypeScript, files are part of a project and are compiled in that scope.'}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,i.jsx)(t.code,{children:"namespace"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"namespace app {\n export const VERSION = '1.0.0'\n export class App {\n /* ... */\n }\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,i.jsx)(t.code,{children:"const enum"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,i.jsx)(t.code,{children:"enum"}),", ",(0,i.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,i.jsxs)(t.p,{children:["You won't be able to do ",(0,i.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,i.jsx)(t.code,{children:"import"}),"/",(0,i.jsx)(t.code,{children:"export"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>c});var s=n(6540);const i={},o=s.createContext(i);function r(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/1917a510.aceaa1a7.js b/assets/js/1917a510.5ab3afc8.js similarity index 99% rename from assets/js/1917a510.aceaa1a7.js rename to assets/js/1917a510.5ab3afc8.js index 4a2784205d..b53a6d46f7 100644 --- a/assets/js/1917a510.aceaa1a7.js +++ b/assets/js/1917a510.5ab3afc8.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4076],{3644:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>p,frontMatter:()=>l,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/options/stringifyContentPathRegex","title":"Stringify content option","description":"The stringifyContentPathRegex option has been kept for backward compatibility of HTML_TRANSFORM","source":"@site/versioned_docs/version-29.2/getting-started/options/stringifyContentPathRegex.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/stringifyContentPathRegex","permalink":"/ts-jest/docs/getting-started/options/stringifyContentPathRegex","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/options/stringifyContentPathRegex.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Stringify content option"}}');var r=n(4848),o=n(8453),a=n(9489),i=n(7227);const l={title:"Stringify content option"},u=void 0,c={},d=[{value:"Example",id:"example",level:3}];function h(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["The ",(0,r.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,r.jsx)(t.code,{children:"__HTML_TRANSFORM__"}),"\nIt's a regular expression pattern used to match the path of file to be transformed.\nIf it matches, the file will be exported as a module exporting its content."]}),"\n",(0,r.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,r.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,r.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,r.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,r.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,r.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,r.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,r.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,r.jsx)(t.code,{children:"transform"})," option pointing to ",(0,r.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,r.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,r.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,r.jsxs)(t.p,{children:["In the ",(0,r.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,r.jsx)(t.code,{children:"package.json"})," version of the config, but extending from the preset will ensure more compatibility without any changes when updating."]}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n moduleFileExtensions: [...tsjPreset.moduleFileExtensions, 'html'],\n transform: {\n ...tsjPreset.transform,\n '\\\\.html$': [\n 'ts-jest',\n {\n stringifyContentPathRegex: /\\.html$/,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\nimport tsJestPresets from 'ts-jest/presets'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n moduleFileExtensions: [...tsJestPresets.defaults.moduleFileExtensions, 'html'],\n transform: {\n ...tsJestPresets.defaults.transform,\n '\\\\.html$': [\n 'ts-jest',\n {\n stringifyContentPathRegex: /\\.html$/,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleFileExtensions": ["js", "ts", "html"],\n "transform": {\n "\\\\.(html|ts|js)$": [\n "ts-jest",\n {\n "stringifyContentPathRegex": "\\\\.html$"\n }\n ]\n }\n }\n}\n'})})})]})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>a});n(6540);var s=n(4164);const r={tabItem:"tabItem_Ymn6"};var o=n(4848);function a(e){let{children:t,hidden:n,className:a}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,s.A)(r.tabItem,a),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),r=n(4164),o=n(4245),a=n(6347),i=n(6494),l=n(2814),u=n(5167),c=n(9900);function d(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:r}}=e;return{value:t,label:n,attributes:s,default:r}}))}(n);return function(e){const t=(0,u.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const r=(0,a.W6)(),o=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(o),(0,s.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(r.location.search);t.set(o,e),r.replace({...r.location,search:t.toString()})}),[o,r])]}function m(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,o=h(e),[a,l]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:o}))),[u,d]=f({queryString:n,groupId:r}),[m,g]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,o]=(0,c.Dv)(n);return[r,(0,s.useCallback)((e=>{n&&o.set(e)}),[n,o])]}({groupId:r}),b=(()=>{const e=u??m;return p({value:e,tabValues:o})?e:null})();(0,i.A)((()=>{b&&l(b)}),[b]);return{selectedValue:a,selectValue:(0,s.useCallback)((e=>{if(!p({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),g(e)}),[d,g,o]),tabValues:o}}var g=n(1062);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=n(4848);function j(e){let{className:t,block:n,selectedValue:s,selectValue:a,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:u}=(0,o.a_)(),c=e=>{const t=e.currentTarget,n=l.indexOf(t),r=i[n].value;r!==s&&(u(t),a(r))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:o}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>l.push(e),onKeyDown:d,onClick:c,...o,className:(0,r.A)("tabs__item",b.tabItem,o?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:o}=e;const a=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=a.find((e=>e.props.value===o));return e?(0,s.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:a.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==o})))})}function y(e){const t=m(e);return(0,x.jsxs)("div",{className:(0,r.A)("tabs-container",b.tabList),children:[(0,x.jsx)(j,{...t,...e}),(0,x.jsx)(v,{...t,...e})]})}function w(e){const t=(0,g.A)();return(0,x.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>a,x:()=>i});var s=n(6540);const r={},o=s.createContext(r);function a(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4076],{3644:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>p,frontMatter:()=>l,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/options/stringifyContentPathRegex","title":"Stringify content option","description":"The stringifyContentPathRegex option has been kept for backward compatibility of HTML_TRANSFORM","source":"@site/versioned_docs/version-29.2/getting-started/options/stringifyContentPathRegex.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/stringifyContentPathRegex","permalink":"/ts-jest/docs/getting-started/options/stringifyContentPathRegex","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/options/stringifyContentPathRegex.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Stringify content option"}}');var r=n(4848),o=n(8453),a=n(9489),i=n(7227);const l={title:"Stringify content option"},u=void 0,c={},d=[{value:"Example",id:"example",level:3}];function h(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["The ",(0,r.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,r.jsx)(t.code,{children:"__HTML_TRANSFORM__"}),"\nIt's a regular expression pattern used to match the path of file to be transformed.\nIf it matches, the file will be exported as a module exporting its content."]}),"\n",(0,r.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,r.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,r.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,r.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,r.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,r.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,r.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,r.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,r.jsx)(t.code,{children:"transform"})," option pointing to ",(0,r.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,r.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,r.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,r.jsxs)(t.p,{children:["In the ",(0,r.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,r.jsx)(t.code,{children:"package.json"})," version of the config, but extending from the preset will ensure more compatibility without any changes when updating."]}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n moduleFileExtensions: [...tsjPreset.moduleFileExtensions, 'html'],\n transform: {\n ...tsjPreset.transform,\n '\\\\.html$': [\n 'ts-jest',\n {\n stringifyContentPathRegex: /\\.html$/,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\nimport tsJestPresets from 'ts-jest/presets'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n moduleFileExtensions: [...tsJestPresets.defaults.moduleFileExtensions, 'html'],\n transform: {\n ...tsJestPresets.defaults.transform,\n '\\\\.html$': [\n 'ts-jest',\n {\n stringifyContentPathRegex: /\\.html$/,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleFileExtensions": ["js", "ts", "html"],\n "transform": {\n "\\\\.(html|ts|js)$": [\n "ts-jest",\n {\n "stringifyContentPathRegex": "\\\\.html$"\n }\n ]\n }\n }\n}\n'})})})]})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>a});n(6540);var s=n(4164);const r={tabItem:"tabItem_Ymn6"};var o=n(4848);function a(e){let{children:t,hidden:n,className:a}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,s.A)(r.tabItem,a),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),r=n(4164),o=n(4245),a=n(6347),i=n(6494),l=n(2814),u=n(5167),c=n(9900);function d(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:r}}=e;return{value:t,label:n,attributes:s,default:r}}))}(n);return function(e){const t=(0,u.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const r=(0,a.W6)(),o=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(o),(0,s.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(r.location.search);t.set(o,e),r.replace({...r.location,search:t.toString()})}),[o,r])]}function m(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,o=h(e),[a,l]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:o}))),[u,d]=f({queryString:n,groupId:r}),[m,g]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,o]=(0,c.Dv)(n);return[r,(0,s.useCallback)((e=>{n&&o.set(e)}),[n,o])]}({groupId:r}),b=(()=>{const e=u??m;return p({value:e,tabValues:o})?e:null})();(0,i.A)((()=>{b&&l(b)}),[b]);return{selectedValue:a,selectValue:(0,s.useCallback)((e=>{if(!p({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),g(e)}),[d,g,o]),tabValues:o}}var g=n(1062);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=n(4848);function j(e){let{className:t,block:n,selectedValue:s,selectValue:a,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:u}=(0,o.a_)(),c=e=>{const t=e.currentTarget,n=l.indexOf(t),r=i[n].value;r!==s&&(u(t),a(r))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:o}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>l.push(e),onKeyDown:d,onClick:c,...o,className:(0,r.A)("tabs__item",b.tabItem,o?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:o}=e;const a=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=a.find((e=>e.props.value===o));return e?(0,s.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:a.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==o})))})}function y(e){const t=m(e);return(0,x.jsxs)("div",{className:(0,r.A)("tabs-container",b.tabList),children:[(0,x.jsx)(j,{...t,...e}),(0,x.jsx)(v,{...t,...e})]})}function w(e){const t=(0,g.A)();return(0,x.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>a,x:()=>i});var s=n(6540);const r={},o=s.createContext(r);function a(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/19f0fee7.f9d853a2.js b/assets/js/19f0fee7.8a32259e.js similarity index 99% rename from assets/js/19f0fee7.f9d853a2.js rename to assets/js/19f0fee7.8a32259e.js index 027bf2c67d..c5a9605136 100644 --- a/assets/js/19f0fee7.f9d853a2.js +++ b/assets/js/19f0fee7.8a32259e.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8888],{5283:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>l,metadata:()=>i,toc:()=>d});const i=JSON.parse('{"id":"getting-started/options/diagnostics","title":"Diagnostics option","description":"The diagnostics option configures error reporting.","source":"@site/versioned_docs/version-27.1/getting-started/options/diagnostics.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/diagnostics","permalink":"/ts-jest/docs/27.1/getting-started/options/diagnostics","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/options/diagnostics.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Diagnostics option"}}');var o=s(4848),t=s(8453);const l={title:"Diagnostics option"},r=void 0,c={},d=[{value:"Disabling/enabling",id:"disablingenabling",level:3},{value:"Advanced configuration",id:"advanced-configuration",level:3},{value:"Examples",id:"examples",level:3},{value:"Disabling diagnostics",id:"disabling-diagnostics",level:4},{value:"Advanced options",id:"advanced-options",level:4},{value:"Enabling diagnostics for test files only",id:"enabling-diagnostics-for-test-files-only",level:5},{value:"Do not fail on first error",id:"do-not-fail-on-first-error",level:5},{value:"Ignoring some error codes",id:"ignoring-some-error-codes",level:5}];function a(e){const n={a:"a",code:"code",em:"em",h3:"h3",h4:"h4",h5:"h5",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,t.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:["The ",(0,o.jsx)(n.code,{children:"diagnostics"})," option configures error reporting.\nIt can both be enabled/disabled entirely or limited to a specific type of errors and/or files."]}),"\n",(0,o.jsxs)(n.p,{children:["If a diagnostic is not filtered out, ",(0,o.jsx)(n.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,o.jsx)(n.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,o.jsxs)(n.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,o.jsx)(n.code,{children:"diagnostics"})," option to ",(0,o.jsx)(n.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,o.jsx)(n.code,{children:"diagnostics"})," to ",(0,o.jsx)(n.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,o.jsx)(n.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,o.jsxs)(n.p,{children:["The ",(0,o.jsx)(n.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"warnOnly"})}),": If specified and ",(0,o.jsx)(n.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,o.jsx)(n.em,{children:"disabled"}),")."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,o.jsx)(n.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". By default here are the ones ignored:","\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"6059"}),": ",(0,o.jsx)(n.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"18002"}),": ",(0,o.jsx)(n.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"18003"}),": ",(0,o.jsx)(n.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,o.jsx)(n.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,o.jsx)(n.code,{children:"tsconfig"})," option ",(0,o.jsx)(n.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,o.jsx)(n.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,o.jsx)(n.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,o.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsx)(n.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: false,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": false\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,o.jsx)(n.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,o.jsxs)(n.p,{children:["Assuming all your test files ends with ",(0,o.jsx)(n.code,{children:".spec.ts"})," or ",(0,o.jsx)(n.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: {\n exclude: ['!**/*.(spec|test).ts'],\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": {\n "exclude": ["!**/*.(spec|test).ts"]\n }\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,o.jsxs)(n.p,{children:["While some diagnostics are stop-blockers for the compilation, most of them are not. If you want the compilation (and so your tests) to continue when encountering those, set the ",(0,o.jsx)(n.code,{children:"warnOnly"})," to ",(0,o.jsx)(n.code,{children:"true"}),":"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: {\n warnOnly: true,\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": {\n "warnOnly": true\n }\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,o.jsxs)(n.p,{children:["All TypeScript error codes can be found ",(0,o.jsx)(n.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,o.jsx)(n.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,o.jsxs)(n.ol,{children:["\n",(0,o.jsxs)(n.li,{children:["A single ",(0,o.jsx)(n.code,{children:"number"})," (example: ",(0,o.jsx)(n.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,o.jsxs)(n.li,{children:["A ",(0,o.jsx)(n.code,{children:"string"})," with a code (example ",(0,o.jsx)(n.code,{children:'"1009"'}),", ",(0,o.jsx)(n.code,{children:'"TS1009"'})," or ",(0,o.jsx)(n.code,{children:'"TS1009"'}),")"]}),"\n",(0,o.jsxs)(n.li,{children:["A ",(0,o.jsx)(n.code,{children:"string"})," with a list of the above (example: ",(0,o.jsx)(n.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,o.jsxs)(n.li,{children:["An ",(0,o.jsx)(n.code,{children:"array"})," of one or more from ",(0,o.jsx)(n.code,{children:"1"})," or ",(0,o.jsx)(n.code,{children:"3"})," (example: ",(0,o.jsx)(n.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: {\n ignoreCodes: [2571, 6031, 18003],\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": {\n "ignoreCodes": [2571, 6031, 18003]\n }\n }\n }\n }\n}\n'})})]})}function h(e={}){const{wrapper:n}={...(0,t.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(a,{...e})}):a(e)}},8453:(e,n,s)=>{s.d(n,{R:()=>l,x:()=>r});var i=s(6540);const o={},t=i.createContext(o);function l(e){const n=i.useContext(t);return i.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function r(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:l(e.components),i.createElement(t.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8888],{5283:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>l,metadata:()=>i,toc:()=>d});const i=JSON.parse('{"id":"getting-started/options/diagnostics","title":"Diagnostics option","description":"The diagnostics option configures error reporting.","source":"@site/versioned_docs/version-27.1/getting-started/options/diagnostics.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/diagnostics","permalink":"/ts-jest/docs/27.1/getting-started/options/diagnostics","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/options/diagnostics.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Diagnostics option"}}');var o=s(4848),t=s(8453);const l={title:"Diagnostics option"},r=void 0,c={},d=[{value:"Disabling/enabling",id:"disablingenabling",level:3},{value:"Advanced configuration",id:"advanced-configuration",level:3},{value:"Examples",id:"examples",level:3},{value:"Disabling diagnostics",id:"disabling-diagnostics",level:4},{value:"Advanced options",id:"advanced-options",level:4},{value:"Enabling diagnostics for test files only",id:"enabling-diagnostics-for-test-files-only",level:5},{value:"Do not fail on first error",id:"do-not-fail-on-first-error",level:5},{value:"Ignoring some error codes",id:"ignoring-some-error-codes",level:5}];function a(e){const n={a:"a",code:"code",em:"em",h3:"h3",h4:"h4",h5:"h5",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,t.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:["The ",(0,o.jsx)(n.code,{children:"diagnostics"})," option configures error reporting.\nIt can both be enabled/disabled entirely or limited to a specific type of errors and/or files."]}),"\n",(0,o.jsxs)(n.p,{children:["If a diagnostic is not filtered out, ",(0,o.jsx)(n.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,o.jsx)(n.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,o.jsxs)(n.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,o.jsx)(n.code,{children:"diagnostics"})," option to ",(0,o.jsx)(n.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,o.jsx)(n.code,{children:"diagnostics"})," to ",(0,o.jsx)(n.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,o.jsx)(n.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,o.jsxs)(n.p,{children:["The ",(0,o.jsx)(n.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"warnOnly"})}),": If specified and ",(0,o.jsx)(n.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,o.jsx)(n.em,{children:"disabled"}),")."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,o.jsx)(n.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". By default here are the ones ignored:","\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"6059"}),": ",(0,o.jsx)(n.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"18002"}),": ",(0,o.jsx)(n.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"18003"}),": ",(0,o.jsx)(n.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,o.jsx)(n.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,o.jsx)(n.code,{children:"tsconfig"})," option ",(0,o.jsx)(n.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,o.jsx)(n.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,o.jsx)(n.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,o.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsx)(n.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: false,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": false\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,o.jsx)(n.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,o.jsxs)(n.p,{children:["Assuming all your test files ends with ",(0,o.jsx)(n.code,{children:".spec.ts"})," or ",(0,o.jsx)(n.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: {\n exclude: ['!**/*.(spec|test).ts'],\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": {\n "exclude": ["!**/*.(spec|test).ts"]\n }\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,o.jsxs)(n.p,{children:["While some diagnostics are stop-blockers for the compilation, most of them are not. If you want the compilation (and so your tests) to continue when encountering those, set the ",(0,o.jsx)(n.code,{children:"warnOnly"})," to ",(0,o.jsx)(n.code,{children:"true"}),":"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: {\n warnOnly: true,\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": {\n "warnOnly": true\n }\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,o.jsxs)(n.p,{children:["All TypeScript error codes can be found ",(0,o.jsx)(n.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,o.jsx)(n.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,o.jsxs)(n.ol,{children:["\n",(0,o.jsxs)(n.li,{children:["A single ",(0,o.jsx)(n.code,{children:"number"})," (example: ",(0,o.jsx)(n.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,o.jsxs)(n.li,{children:["A ",(0,o.jsx)(n.code,{children:"string"})," with a code (example ",(0,o.jsx)(n.code,{children:'"1009"'}),", ",(0,o.jsx)(n.code,{children:'"TS1009"'})," or ",(0,o.jsx)(n.code,{children:'"TS1009"'}),")"]}),"\n",(0,o.jsxs)(n.li,{children:["A ",(0,o.jsx)(n.code,{children:"string"})," with a list of the above (example: ",(0,o.jsx)(n.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,o.jsxs)(n.li,{children:["An ",(0,o.jsx)(n.code,{children:"array"})," of one or more from ",(0,o.jsx)(n.code,{children:"1"})," or ",(0,o.jsx)(n.code,{children:"3"})," (example: ",(0,o.jsx)(n.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: {\n ignoreCodes: [2571, 6031, 18003],\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": {\n "ignoreCodes": [2571, 6031, 18003]\n }\n }\n }\n }\n}\n'})})]})}function h(e={}){const{wrapper:n}={...(0,t.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(a,{...e})}):a(e)}},8453:(e,n,s)=>{s.d(n,{R:()=>l,x:()=>r});var i=s(6540);const o={},t=i.createContext(o);function l(e){const n=i.useContext(t);return i.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function r(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:l(e.components),i.createElement(t.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/1ca5b1f2.7b876712.js b/assets/js/1ca5b1f2.44bf028b.js similarity index 97% rename from assets/js/1ca5b1f2.7b876712.js rename to assets/js/1ca5b1f2.44bf028b.js index 1803ce265c..465300c370 100644 --- a/assets/js/1ca5b1f2.7b876712.js +++ b/assets/js/1ca5b1f2.44bf028b.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1682],{1063:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/version-checking","title":"Version checking","description":"By default, ts-jest supports a range of versions for jest/typescript. One uses incompatible versions will receive a warning","source":"@site/versioned_docs/version-29.2/getting-started/version-checking.md","sourceDirName":"getting-started","slug":"/getting-started/version-checking","permalink":"/ts-jest/docs/getting-started/version-checking","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/version-checking.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"version-checking","title":"Version checking"},"sidebar":"version-29.1-docs","previous":{"title":"Paths mapping","permalink":"/ts-jest/docs/getting-started/paths-mapping"},"next":{"title":"ESM Support","permalink":"/ts-jest/docs/guides/esm-support"}}');var i=n(4848),r=n(8453);const o={id:"version-checking",title:"Version checking"},c=void 0,a={},d=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["By default, ",(0,i.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,i.jsx)(t.code,{children:"jest"}),"/",(0,i.jsx)(t.code,{children:"typescript"}),". One uses incompatible versions will receive a warning\nmessage while running tests. This warning message can be opt-out by setting environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"export TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Windows"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,i.jsxs)(t.p,{children:["As long as the environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"})," stays, the warning message will no longer show.\nThis can lead to unexpected errors due to the usage of incompatible versions' dependencies. Use this environment variable with precautions."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>c});var s=n(6540);const i={},r=s.createContext(i);function o(e){const t=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1682],{1063:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/version-checking","title":"Version checking","description":"By default, ts-jest supports a range of versions for jest/typescript. One uses incompatible versions will receive a warning","source":"@site/versioned_docs/version-29.2/getting-started/version-checking.md","sourceDirName":"getting-started","slug":"/getting-started/version-checking","permalink":"/ts-jest/docs/getting-started/version-checking","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/version-checking.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"version-checking","title":"Version checking"},"sidebar":"version-29.1-docs","previous":{"title":"Paths mapping","permalink":"/ts-jest/docs/getting-started/paths-mapping"},"next":{"title":"ESM Support","permalink":"/ts-jest/docs/guides/esm-support"}}');var i=n(4848),r=n(8453);const o={id:"version-checking",title:"Version checking"},c=void 0,a={},d=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["By default, ",(0,i.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,i.jsx)(t.code,{children:"jest"}),"/",(0,i.jsx)(t.code,{children:"typescript"}),". One uses incompatible versions will receive a warning\nmessage while running tests. This warning message can be opt-out by setting environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"export TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Windows"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,i.jsxs)(t.p,{children:["As long as the environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"})," stays, the warning message will no longer show.\nThis can lead to unexpected errors due to the usage of incompatible versions' dependencies. Use this environment variable with precautions."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>c});var s=n(6540);const i={},r=s.createContext(i);function o(e){const t=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/2145bebc.378525df.js b/assets/js/2145bebc.68b79213.js similarity index 98% rename from assets/js/2145bebc.378525df.js rename to assets/js/2145bebc.68b79213.js index ad07bfd261..b6a023b64a 100644 --- a/assets/js/2145bebc.378525df.js +++ b/assets/js/2145bebc.68b79213.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8703],{2522:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>l,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/installation","title":"Installation","description":"Dependencies","source":"@site/versioned_docs/version-27.1/getting-started/installation.md","sourceDirName":"getting-started","slug":"/getting-started/installation","permalink":"/ts-jest/docs/27.1/getting-started/installation","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/installation.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"installation","title":"Installation"},"sidebar":"version-27.1-docs","previous":{"title":"Contributing","permalink":"/ts-jest/docs/27.1/contributing"},"next":{"title":"Presets","permalink":"/ts-jest/docs/27.1/getting-started/presets"}}');var i=n(4848),o=n(8453);const l={id:"installation",title:"Installation"},r=void 0,c={},d=[{value:"Dependencies",id:"dependencies",level:3},{value:"NPM",id:"npm",level:4},{value:"Yarn",id:"yarn",level:4},{value:"Jest config file",id:"jest-config-file",level:3},{value:"Creating",id:"creating",level:4},{value:"NPM",id:"npm-1",level:4},{value:"Yarn",id:"yarn-1",level:4},{value:"Customizing",id:"customizing",level:4}];function a(e){const t={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,i.jsxs)(t.p,{children:["You can install ",(0,i.jsx)(t.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,i.jsx)(t.h4,{id:"npm",children:"NPM"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(t.h4,{id:"yarn",children:"Yarn"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(t.admonition,{type:"tip",children:(0,i.jsxs)(t.p,{children:["Tip: If you get an error with the following ",(0,i.jsx)(t.code,{children:"npm"})," commands such as ",(0,i.jsx)(t.code,{children:"npx: command not found"}),", you can replace ",(0,i.jsx)(t.code,{children:"npx XXX"})," with ",(0,i.jsx)(t.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,i.jsx)(t.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,i.jsx)(t.h4,{id:"creating",children:"Creating"}),"\n",(0,i.jsxs)(t.p,{children:["By default, Jest can run without any config files, but it will not compile ",(0,i.jsx)(t.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,i.jsx)(t.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,i.jsx)(t.code,{children:"ts-jest"})," preset."]}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,i.jsx)(t.h4,{id:"npm-1",children:"NPM"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"npx ts-jest config:init\n"})}),"\n",(0,i.jsx)(t.h4,{id:"yarn-1",children:"Yarn"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"yarn ts-jest config:init\n"})}),"\n",(0,i.jsxs)(t.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,i.jsx)(t.code,{children:".ts"})," files correctly."]}),"\n",(0,i.jsxs)(t.p,{children:["You can also use the ",(0,i.jsx)(t.code,{children:"jest --init"})," command (prefixed with either ",(0,i.jsx)(t.code,{children:"npx"})," or ",(0,i.jsx)(t.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,i.jsx)(t.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,i.jsx)(t.code,{children:'preset: "ts-jest"'})," to the ",(0,i.jsx)(t.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,i.jsx)(t.h4,{id:"customizing",children:"Customizing"}),"\n",(0,i.jsxs)(t.p,{children:["For customizing jest, please follow their ",(0,i.jsx)(t.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"ts-jest"})," specific options can be found ",(0,i.jsx)(t.a,{href:"/ts-jest/docs/27.1/getting-started/options",children:"here"}),"."]})]})}function h(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(a,{...e})}):a(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>l,x:()=>r});var s=n(6540);const i={},o=s.createContext(i);function l(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:l(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8703],{2522:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>l,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/installation","title":"Installation","description":"Dependencies","source":"@site/versioned_docs/version-27.1/getting-started/installation.md","sourceDirName":"getting-started","slug":"/getting-started/installation","permalink":"/ts-jest/docs/27.1/getting-started/installation","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/installation.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"installation","title":"Installation"},"sidebar":"version-27.1-docs","previous":{"title":"Contributing","permalink":"/ts-jest/docs/27.1/contributing"},"next":{"title":"Presets","permalink":"/ts-jest/docs/27.1/getting-started/presets"}}');var i=n(4848),o=n(8453);const l={id:"installation",title:"Installation"},r=void 0,c={},d=[{value:"Dependencies",id:"dependencies",level:3},{value:"NPM",id:"npm",level:4},{value:"Yarn",id:"yarn",level:4},{value:"Jest config file",id:"jest-config-file",level:3},{value:"Creating",id:"creating",level:4},{value:"NPM",id:"npm-1",level:4},{value:"Yarn",id:"yarn-1",level:4},{value:"Customizing",id:"customizing",level:4}];function a(e){const t={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,i.jsxs)(t.p,{children:["You can install ",(0,i.jsx)(t.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,i.jsx)(t.h4,{id:"npm",children:"NPM"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(t.h4,{id:"yarn",children:"Yarn"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(t.admonition,{type:"tip",children:(0,i.jsxs)(t.p,{children:["Tip: If you get an error with the following ",(0,i.jsx)(t.code,{children:"npm"})," commands such as ",(0,i.jsx)(t.code,{children:"npx: command not found"}),", you can replace ",(0,i.jsx)(t.code,{children:"npx XXX"})," with ",(0,i.jsx)(t.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,i.jsx)(t.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,i.jsx)(t.h4,{id:"creating",children:"Creating"}),"\n",(0,i.jsxs)(t.p,{children:["By default, Jest can run without any config files, but it will not compile ",(0,i.jsx)(t.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,i.jsx)(t.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,i.jsx)(t.code,{children:"ts-jest"})," preset."]}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,i.jsx)(t.h4,{id:"npm-1",children:"NPM"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"npx ts-jest config:init\n"})}),"\n",(0,i.jsx)(t.h4,{id:"yarn-1",children:"Yarn"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"yarn ts-jest config:init\n"})}),"\n",(0,i.jsxs)(t.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,i.jsx)(t.code,{children:".ts"})," files correctly."]}),"\n",(0,i.jsxs)(t.p,{children:["You can also use the ",(0,i.jsx)(t.code,{children:"jest --init"})," command (prefixed with either ",(0,i.jsx)(t.code,{children:"npx"})," or ",(0,i.jsx)(t.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,i.jsx)(t.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,i.jsx)(t.code,{children:'preset: "ts-jest"'})," to the ",(0,i.jsx)(t.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,i.jsx)(t.h4,{id:"customizing",children:"Customizing"}),"\n",(0,i.jsxs)(t.p,{children:["For customizing jest, please follow their ",(0,i.jsx)(t.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"ts-jest"})," specific options can be found ",(0,i.jsx)(t.a,{href:"/ts-jest/docs/27.1/getting-started/options",children:"here"}),"."]})]})}function h(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(a,{...e})}):a(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>l,x:()=>r});var s=n(6540);const i={},o=s.createContext(i);function l(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:l(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/22e01789.d0575031.js b/assets/js/22e01789.40ec38ee.js similarity index 98% rename from assets/js/22e01789.d0575031.js rename to assets/js/22e01789.40ec38ee.js index afa7dc29e8..42962b7fec 100644 --- a/assets/js/22e01789.d0575031.js +++ b/assets/js/22e01789.40ec38ee.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2365],{9790:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>r,contentTitle:()=>l,default:()=>p,frontMatter:()=>c,metadata:()=>o,toc:()=>a});const o=JSON.parse('{"id":"getting-started/options/tsconfig","title":"TypeScript Config option","description":"The tsconfig option allows you to define which tsconfig JSON file to use. An inline compiler options object can also be specified instead of a file path.","source":"@site/versioned_docs/version-28.0/getting-started/options/tsconfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/tsconfig","permalink":"/ts-jest/docs/28.0/getting-started/options/tsconfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/options/tsconfig.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"TypeScript Config option"}}');var s=t(4848),i=t(8453);const c={title:"TypeScript Config option"},l=void 0,r={},a=[{value:"Examples",id:"examples",level:3},{value:"Path to a tsconfig file",id:"path-to-a-tsconfig-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4},{value:"Disable auto-lookup",id:"disable-auto-lookup",level:4}];function d(e){const n={a:"a",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"tsconfig"})," option allows you to define which ",(0,s.jsx)(n.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,s.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," object can also be specified instead of a file path."]}),"\n",(0,s.jsxs)(n.p,{children:["By default ",(0,s.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,s.jsx)(n.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,s.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,s.jsx)(n.code,{children:"ES2015"})," is used as ",(0,s.jsx)(n.code,{children:"target"})," instead of ",(0,s.jsx)(n.code,{children:"ES5"}),"."]}),"\n",(0,s.jsxs)(n.p,{children:["If you need to use defaults and force ",(0,s.jsx)(n.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,s.jsx)(n.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,s.jsx)(n.code,{children:"false"}),"."]}),"\n",(0,s.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,s.jsxs)(n.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,s.jsx)(n.code,{children:"tsconfig"})," file"]}),"\n",(0,s.jsxs)(n.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,s.jsx)(n.code,{children:""})," in the path to start from the project root dir."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n tsconfig: 'tsconfig.test.json',\n },\n },\n}\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "tsconfig": "tsconfig.test.json"\n }\n }\n }\n}\n'})}),"\n",(0,s.jsx)(n.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,s.jsxs)(n.p,{children:["Refer to the TypeScript ",(0,s.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," for reference.\nIt's basically the same object you'd put in your ",(0,s.jsx)(n.code,{children:"tsconfig.json"}),"'s ",(0,s.jsx)(n.code,{children:"compilerOptions"}),"."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n tsconfig: {\n importHelpers: true,\n },\n },\n },\n}\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "tsconfig": {\n "importHelpers": true\n }\n }\n }\n }\n}\n'})}),"\n",(0,s.jsx)(n.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,s.jsxs)(n.p,{children:["By default ",(0,s.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,s.jsx)(n.code,{children:"tsconfig.json"})," in your project. But you may not want to use it at all and keep TypeScript default options. You can achieve this by setting ",(0,s.jsx)(n.code,{children:"tsconfig"})," to ",(0,s.jsx)(n.code,{children:"false"}),"."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n tsconfig: false,\n },\n },\n}\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "tsconfig": false\n }\n }\n }\n}\n'})})]})}function p(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>c,x:()=>l});var o=t(6540);const s={},i=o.createContext(s);function c(e){const n=o.useContext(i);return o.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:c(e.components),o.createElement(i.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2365],{9790:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>r,contentTitle:()=>l,default:()=>p,frontMatter:()=>c,metadata:()=>o,toc:()=>a});const o=JSON.parse('{"id":"getting-started/options/tsconfig","title":"TypeScript Config option","description":"The tsconfig option allows you to define which tsconfig JSON file to use. An inline compiler options object can also be specified instead of a file path.","source":"@site/versioned_docs/version-28.0/getting-started/options/tsconfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/tsconfig","permalink":"/ts-jest/docs/28.0/getting-started/options/tsconfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/options/tsconfig.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"TypeScript Config option"}}');var s=t(4848),i=t(8453);const c={title:"TypeScript Config option"},l=void 0,r={},a=[{value:"Examples",id:"examples",level:3},{value:"Path to a tsconfig file",id:"path-to-a-tsconfig-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4},{value:"Disable auto-lookup",id:"disable-auto-lookup",level:4}];function d(e){const n={a:"a",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"tsconfig"})," option allows you to define which ",(0,s.jsx)(n.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,s.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," object can also be specified instead of a file path."]}),"\n",(0,s.jsxs)(n.p,{children:["By default ",(0,s.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,s.jsx)(n.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,s.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,s.jsx)(n.code,{children:"ES2015"})," is used as ",(0,s.jsx)(n.code,{children:"target"})," instead of ",(0,s.jsx)(n.code,{children:"ES5"}),"."]}),"\n",(0,s.jsxs)(n.p,{children:["If you need to use defaults and force ",(0,s.jsx)(n.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,s.jsx)(n.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,s.jsx)(n.code,{children:"false"}),"."]}),"\n",(0,s.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,s.jsxs)(n.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,s.jsx)(n.code,{children:"tsconfig"})," file"]}),"\n",(0,s.jsxs)(n.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,s.jsx)(n.code,{children:""})," in the path to start from the project root dir."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n tsconfig: 'tsconfig.test.json',\n },\n },\n}\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "tsconfig": "tsconfig.test.json"\n }\n }\n }\n}\n'})}),"\n",(0,s.jsx)(n.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,s.jsxs)(n.p,{children:["Refer to the TypeScript ",(0,s.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," for reference.\nIt's basically the same object you'd put in your ",(0,s.jsx)(n.code,{children:"tsconfig.json"}),"'s ",(0,s.jsx)(n.code,{children:"compilerOptions"}),"."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n tsconfig: {\n importHelpers: true,\n },\n },\n },\n}\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "tsconfig": {\n "importHelpers": true\n }\n }\n }\n }\n}\n'})}),"\n",(0,s.jsx)(n.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,s.jsxs)(n.p,{children:["By default ",(0,s.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,s.jsx)(n.code,{children:"tsconfig.json"})," in your project. But you may not want to use it at all and keep TypeScript default options. You can achieve this by setting ",(0,s.jsx)(n.code,{children:"tsconfig"})," to ",(0,s.jsx)(n.code,{children:"false"}),"."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n tsconfig: false,\n },\n },\n}\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "tsconfig": false\n }\n }\n }\n}\n'})})]})}function p(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>c,x:()=>l});var o=t(6540);const s={},i=o.createContext(s);function c(e){const n=o.useContext(i);return o.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:c(e.components),o.createElement(i.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/22f8c605.97329a1f.js b/assets/js/22f8c605.cd0013a5.js similarity index 97% rename from assets/js/22f8c605.97329a1f.js rename to assets/js/22f8c605.cd0013a5.js index 493cb01843..d06ac20d38 100644 --- a/assets/js/22f8c605.97329a1f.js +++ b/assets/js/22f8c605.cd0013a5.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6475],{4624:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>n,toc:()=>a});const n=JSON.parse('{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","source":"@site/versioned_docs/version-27.1/introduction.md","sourceDirName":".","slug":"/","permalink":"/ts-jest/docs/27.1/","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/introduction.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","slug":"/"},"sidebar":"version-27.1-docs","next":{"title":"Processing flow","permalink":"/ts-jest/docs/27.1/processing"}}');var o=s(4848),r=s(8453);const i={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},c=void 0,d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,r.R)(),...t.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(e.p,{children:[(0,o.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,o.jsx)(e.a,{href:"https://jestjs.io/docs/next/code-transformation#writing-custom-transformers",children:"transformer"})," with source map support that lets you use Jest to test projects written in TypeScript."]}),"\n",(0,o.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,o.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,o.jsx)(e.code,{children:"preset-typescript"})," ",(0,o.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,o.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,o.jsx)(e.admonition,{type:"important",children:(0,o.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,o.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,o.jsx)(e.code,{children:'npm i -D ts-jest@"<23.10.0"'})," to go back to the previous version"]})})]})}function u(t={}){const{wrapper:e}={...(0,r.R)(),...t.components};return e?(0,o.jsx)(e,{...t,children:(0,o.jsx)(p,{...t})}):p(t)}},8453:(t,e,s)=>{s.d(e,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(t){const e=n.useContext(r);return n.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function c(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:i(t.components),n.createElement(r.Provider,{value:e},t.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6475],{4624:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>n,toc:()=>a});const n=JSON.parse('{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","source":"@site/versioned_docs/version-27.1/introduction.md","sourceDirName":".","slug":"/","permalink":"/ts-jest/docs/27.1/","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/introduction.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","slug":"/"},"sidebar":"version-27.1-docs","next":{"title":"Processing flow","permalink":"/ts-jest/docs/27.1/processing"}}');var o=s(4848),r=s(8453);const i={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},c=void 0,d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,r.R)(),...t.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(e.p,{children:[(0,o.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,o.jsx)(e.a,{href:"https://jestjs.io/docs/next/code-transformation#writing-custom-transformers",children:"transformer"})," with source map support that lets you use Jest to test projects written in TypeScript."]}),"\n",(0,o.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,o.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,o.jsx)(e.code,{children:"preset-typescript"})," ",(0,o.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,o.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,o.jsx)(e.admonition,{type:"important",children:(0,o.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,o.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,o.jsx)(e.code,{children:'npm i -D ts-jest@"<23.10.0"'})," to go back to the previous version"]})})]})}function u(t={}){const{wrapper:e}={...(0,r.R)(),...t.components};return e?(0,o.jsx)(e,{...t,children:(0,o.jsx)(p,{...t})}):p(t)}},8453:(t,e,s)=>{s.d(e,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(t){const e=n.useContext(r);return n.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function c(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:i(t.components),n.createElement(r.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/2331e073.321c45e4.js b/assets/js/2331e073.67cd78ff.js similarity index 98% rename from assets/js/2331e073.321c45e4.js rename to assets/js/2331e073.67cd78ff.js index 501c957e66..03cc61b787 100644 --- a/assets/js/2331e073.321c45e4.js +++ b/assets/js/2331e073.67cd78ff.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1455],{6716:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>d,contentTitle:()=>c,default:()=>h,frontMatter:()=>r,metadata:()=>n,toc:()=>l});const n=JSON.parse('{"id":"guides/test-helpers","title":"Test helpers","description":"This function is now deprecated and will be removed in 28.0.0. The function has been integrated into jest-mock package","source":"@site/versioned_docs/version-27.1/guides/test-helpers.md","sourceDirName":"guides","slug":"/guides/test-helpers","permalink":"/ts-jest/docs/27.1/guides/test-helpers","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/guides/test-helpers.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"test-helpers","title":"Test helpers"},"sidebar":"version-27.1-docs","previous":{"title":"Using with React Native","permalink":"/ts-jest/docs/27.1/guides/react-native"},"next":{"title":"Troubleshooting","permalink":"/ts-jest/docs/27.1/guides/troubleshooting"}}');var o=s(4848),i=s(8453);const r={id:"test-helpers",title:"Test helpers"},c=void 0,d={},l=[{value:"mocked<T>(item: T, deep = false)",id:"mockedtitem-t-deep--false",level:2},{value:"Example",id:"example",level:3}];function a(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.admonition,{type:"warning",children:(0,o.jsxs)(t.p,{children:["This function is now deprecated and will be removed in ",(0,o.jsx)(t.strong,{children:"28.0.0"}),". The function has been integrated into ",(0,o.jsx)(t.code,{children:"jest-mock"})," package\nas a part of Jest ",(0,o.jsx)(t.strong,{children:"27.4.0"}),", see ",(0,o.jsx)(t.a,{href:"https://github.com/facebook/jest/pull/12089",children:"https://github.com/facebook/jest/pull/12089"}),". Please use the one from ",(0,o.jsx)(t.code,{children:"jest-mock"})," instead."]})}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.code,{children:"ts-jest"})," provides some test utilities to be used in your test, related to TypeScript."]}),"\n",(0,o.jsx)(t.h2,{id:"mockedtitem-t-deep--false",children:(0,o.jsx)(t.code,{children:"mocked(item: T, deep = false)"})}),"\n",(0,o.jsxs)(t.p,{children:["The ",(0,o.jsx)(t.code,{children:"mocked"})," test helper provides typings on your mocked modules and even their deep methods, based on the typing of its source. It makes use of the latest TypeScript feature, so you even have argument types completion in the IDE (as opposed to ",(0,o.jsx)(t.code,{children:"jest.MockInstance"}),")."]}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.strong,{children:"Note:"})," while it needs to be a function so that input type is changed, the helper itself does nothing else than returning the given input value."]}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-ts",children:"// foo.ts\nexport const foo = {\n a: {\n b: {\n c: {\n hello: (name: string) => `Hello, ${name}`,\n },\n },\n },\n name: () => 'foo',\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-ts",children:"// foo.spec.ts\nimport { mocked } from 'ts-jest/utils'\nimport { foo } from './foo'\njest.mock('./foo')\n\n// here the whole foo var is mocked deeply\nconst mockedFoo = mocked(foo, true)\n\ntest('deep', () => {\n // there will be no TS error here, and you'll have completion in modern IDEs\n mockedFoo.a.b.c.hello('me')\n // same here\n expect(mockedFoo.a.b.c.hello.mock.calls).toHaveLength(1)\n})\n\ntest('direct', () => {\n foo.name()\n // here only foo.name is mocked (or its methods if it's an object)\n expect(mocked(foo.name).mock.calls).toHaveLength(1)\n})\n"})})]})}function h(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(a,{...e})}):a(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>r,x:()=>c});var n=s(6540);const o={},i=n.createContext(o);function r(e){const t=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1455],{6716:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>d,contentTitle:()=>c,default:()=>h,frontMatter:()=>r,metadata:()=>n,toc:()=>l});const n=JSON.parse('{"id":"guides/test-helpers","title":"Test helpers","description":"This function is now deprecated and will be removed in 28.0.0. The function has been integrated into jest-mock package","source":"@site/versioned_docs/version-27.1/guides/test-helpers.md","sourceDirName":"guides","slug":"/guides/test-helpers","permalink":"/ts-jest/docs/27.1/guides/test-helpers","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/guides/test-helpers.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"test-helpers","title":"Test helpers"},"sidebar":"version-27.1-docs","previous":{"title":"Using with React Native","permalink":"/ts-jest/docs/27.1/guides/react-native"},"next":{"title":"Troubleshooting","permalink":"/ts-jest/docs/27.1/guides/troubleshooting"}}');var o=s(4848),i=s(8453);const r={id:"test-helpers",title:"Test helpers"},c=void 0,d={},l=[{value:"mocked<T>(item: T, deep = false)",id:"mockedtitem-t-deep--false",level:2},{value:"Example",id:"example",level:3}];function a(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.admonition,{type:"warning",children:(0,o.jsxs)(t.p,{children:["This function is now deprecated and will be removed in ",(0,o.jsx)(t.strong,{children:"28.0.0"}),". The function has been integrated into ",(0,o.jsx)(t.code,{children:"jest-mock"})," package\nas a part of Jest ",(0,o.jsx)(t.strong,{children:"27.4.0"}),", see ",(0,o.jsx)(t.a,{href:"https://github.com/facebook/jest/pull/12089",children:"https://github.com/facebook/jest/pull/12089"}),". Please use the one from ",(0,o.jsx)(t.code,{children:"jest-mock"})," instead."]})}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.code,{children:"ts-jest"})," provides some test utilities to be used in your test, related to TypeScript."]}),"\n",(0,o.jsx)(t.h2,{id:"mockedtitem-t-deep--false",children:(0,o.jsx)(t.code,{children:"mocked(item: T, deep = false)"})}),"\n",(0,o.jsxs)(t.p,{children:["The ",(0,o.jsx)(t.code,{children:"mocked"})," test helper provides typings on your mocked modules and even their deep methods, based on the typing of its source. It makes use of the latest TypeScript feature, so you even have argument types completion in the IDE (as opposed to ",(0,o.jsx)(t.code,{children:"jest.MockInstance"}),")."]}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.strong,{children:"Note:"})," while it needs to be a function so that input type is changed, the helper itself does nothing else than returning the given input value."]}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-ts",children:"// foo.ts\nexport const foo = {\n a: {\n b: {\n c: {\n hello: (name: string) => `Hello, ${name}`,\n },\n },\n },\n name: () => 'foo',\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-ts",children:"// foo.spec.ts\nimport { mocked } from 'ts-jest/utils'\nimport { foo } from './foo'\njest.mock('./foo')\n\n// here the whole foo var is mocked deeply\nconst mockedFoo = mocked(foo, true)\n\ntest('deep', () => {\n // there will be no TS error here, and you'll have completion in modern IDEs\n mockedFoo.a.b.c.hello('me')\n // same here\n expect(mockedFoo.a.b.c.hello.mock.calls).toHaveLength(1)\n})\n\ntest('direct', () => {\n foo.name()\n // here only foo.name is mocked (or its methods if it's an object)\n expect(mocked(foo.name).mock.calls).toHaveLength(1)\n})\n"})})]})}function h(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(a,{...e})}):a(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>r,x:()=>c});var n=s(6540);const o={},i=n.createContext(o);function r(e){const t=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/2338618e.50f7fb38.js b/assets/js/2338618e.edd2aa5f.js similarity index 99% rename from assets/js/2338618e.50f7fb38.js rename to assets/js/2338618e.edd2aa5f.js index 00b92cfdf9..a6526828bd 100644 --- a/assets/js/2338618e.50f7fb38.js +++ b/assets/js/2338618e.edd2aa5f.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8529],{1349:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>p,frontMatter:()=>l,metadata:()=>r,toc:()=>d});const r=JSON.parse('{"id":"migration","title":"Migration from <=23.10","description":"You can use the config:migrate tool of ts-jest CLI if you\'re coming from an older version to help you migrate your Jest configuration.","source":"@site/versioned_docs/version-29.0/migration.md","sourceDirName":".","slug":"/migration","permalink":"/ts-jest/docs/29.0/migration","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/migration.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"migration","title":"Migration from <=23.10"},"sidebar":"version-29.0-docs","previous":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/29.0/babel7-or-ts"},"next":{"title":"Debugging ts-jest","permalink":"/ts-jest/docs/29.0/debugging"}}');var a=n(4848),s=n(8453),o=n(9489),i=n(7227);const l={id:"migration",title:"Migration from <=23.10"},u=void 0,c={},d=[];function m(e){const t={code:"code",em:"em",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(t.p,{children:["You can use the ",(0,a.jsx)(t.code,{children:"config:migrate"})," tool of ",(0,a.jsx)(t.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,a.jsx)(t.p,{children:(0,a.jsxs)(t.em,{children:["If you're using ",(0,a.jsx)(t.code,{children:"jest.config.js"}),":"]})}),"\n",(0,a.jsxs)(o.A,{groupId:"code-examples",children:[(0,a.jsx)(i.A,{value:"npm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-npm",metastring:"tab",children:"npx ts-jest config:migrate jest.config.js\n"})})}),(0,a.jsx)(i.A,{value:"Yarn",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-Yarn",metastring:"tab",children:"yarn ts-jest config:migrate jest.config.js\n"})})})]}),"\n",(0,a.jsx)(t.p,{children:(0,a.jsxs)(t.em,{children:["If you're using ",(0,a.jsx)(t.code,{children:"jest"})," config property of ",(0,a.jsx)(t.code,{children:"package.json"}),":"]})}),"\n",(0,a.jsxs)(o.A,{groupId:"code-examples",children:[(0,a.jsx)(i.A,{value:"npm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-npm",metastring:"tab",children:"npx ts-jest config:migrate package.json\n"})})}),(0,a.jsx)(i.A,{value:"Yarn",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-Yarn",metastring:"tab",children:"yarn ts-jest config:migrate package.json\n"})})})]})]})}function p(e={}){const{wrapper:t}={...(0,s.R)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(m,{...e})}):m(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var r=n(4164);const a={tabItem:"tabItem_Ymn6"};var s=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.A)(a.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>I});var r=n(6540),a=n(4164),s=n(4245),o=n(6347),i=n(6494),l=n(2814),u=n(5167),c=n(9900);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function m(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(n);return function(e){const t=(0,u.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const a=(0,o.W6)(),s=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(s),(0,r.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function g(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,s=m(e),[o,l]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:s}))),[u,d]=f({queryString:n,groupId:a}),[g,h]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,c.Dv)(n);return[a,(0,r.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),b=(()=>{const e=u??g;return p({value:e,tabValues:s})?e:null})();(0,i.A)((()=>{b&&l(b)}),[b]);return{selectedValue:o,selectValue:(0,r.useCallback)((e=>{if(!p({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),h(e)}),[d,h,s]),tabValues:s}}var h=n(1062);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var j=n(4848);function v(e){let{className:t,block:n,selectedValue:r,selectValue:o,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:u}=(0,s.a_)(),c=e=>{const t=e.currentTarget,n=l.indexOf(t),a=i[n].value;a!==r&&(u(t),o(a))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,j.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.A)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,j.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>l.push(e),onKeyDown:d,onClick:c,...s,className:(0,a.A)("tabs__item",b.tabItem,s?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:s}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===s));return e?(0,r.cloneElement)(e,{className:(0,a.A)("margin-top--md",e.props.className)}):null}return(0,j.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==s})))})}function y(e){const t=g(e);return(0,j.jsxs)("div",{className:(0,a.A)("tabs-container",b.tabList),children:[(0,j.jsx)(v,{...t,...e}),(0,j.jsx)(x,{...t,...e})]})}function I(e){const t=(0,h.A)();return(0,j.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>i});var r=n(6540);const a={},s=r.createContext(a);function o(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8529],{1349:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>p,frontMatter:()=>l,metadata:()=>r,toc:()=>d});const r=JSON.parse('{"id":"migration","title":"Migration from <=23.10","description":"You can use the config:migrate tool of ts-jest CLI if you\'re coming from an older version to help you migrate your Jest configuration.","source":"@site/versioned_docs/version-29.0/migration.md","sourceDirName":".","slug":"/migration","permalink":"/ts-jest/docs/29.0/migration","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/migration.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"migration","title":"Migration from <=23.10"},"sidebar":"version-29.0-docs","previous":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/29.0/babel7-or-ts"},"next":{"title":"Debugging ts-jest","permalink":"/ts-jest/docs/29.0/debugging"}}');var a=n(4848),s=n(8453),o=n(9489),i=n(7227);const l={id:"migration",title:"Migration from <=23.10"},u=void 0,c={},d=[];function m(e){const t={code:"code",em:"em",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(t.p,{children:["You can use the ",(0,a.jsx)(t.code,{children:"config:migrate"})," tool of ",(0,a.jsx)(t.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,a.jsx)(t.p,{children:(0,a.jsxs)(t.em,{children:["If you're using ",(0,a.jsx)(t.code,{children:"jest.config.js"}),":"]})}),"\n",(0,a.jsxs)(o.A,{groupId:"code-examples",children:[(0,a.jsx)(i.A,{value:"npm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-npm",metastring:"tab",children:"npx ts-jest config:migrate jest.config.js\n"})})}),(0,a.jsx)(i.A,{value:"Yarn",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-Yarn",metastring:"tab",children:"yarn ts-jest config:migrate jest.config.js\n"})})})]}),"\n",(0,a.jsx)(t.p,{children:(0,a.jsxs)(t.em,{children:["If you're using ",(0,a.jsx)(t.code,{children:"jest"})," config property of ",(0,a.jsx)(t.code,{children:"package.json"}),":"]})}),"\n",(0,a.jsxs)(o.A,{groupId:"code-examples",children:[(0,a.jsx)(i.A,{value:"npm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-npm",metastring:"tab",children:"npx ts-jest config:migrate package.json\n"})})}),(0,a.jsx)(i.A,{value:"Yarn",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-Yarn",metastring:"tab",children:"yarn ts-jest config:migrate package.json\n"})})})]})]})}function p(e={}){const{wrapper:t}={...(0,s.R)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(m,{...e})}):m(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var r=n(4164);const a={tabItem:"tabItem_Ymn6"};var s=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.A)(a.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>I});var r=n(6540),a=n(4164),s=n(4245),o=n(6347),i=n(6494),l=n(2814),u=n(5167),c=n(9900);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function m(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(n);return function(e){const t=(0,u.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const a=(0,o.W6)(),s=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(s),(0,r.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function g(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,s=m(e),[o,l]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:s}))),[u,d]=f({queryString:n,groupId:a}),[g,h]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,c.Dv)(n);return[a,(0,r.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),b=(()=>{const e=u??g;return p({value:e,tabValues:s})?e:null})();(0,i.A)((()=>{b&&l(b)}),[b]);return{selectedValue:o,selectValue:(0,r.useCallback)((e=>{if(!p({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),h(e)}),[d,h,s]),tabValues:s}}var h=n(1062);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var j=n(4848);function v(e){let{className:t,block:n,selectedValue:r,selectValue:o,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:u}=(0,s.a_)(),c=e=>{const t=e.currentTarget,n=l.indexOf(t),a=i[n].value;a!==r&&(u(t),o(a))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,j.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.A)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,j.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>l.push(e),onKeyDown:d,onClick:c,...s,className:(0,a.A)("tabs__item",b.tabItem,s?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:s}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===s));return e?(0,r.cloneElement)(e,{className:(0,a.A)("margin-top--md",e.props.className)}):null}return(0,j.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==s})))})}function y(e){const t=g(e);return(0,j.jsxs)("div",{className:(0,a.A)("tabs-container",b.tabList),children:[(0,j.jsx)(v,{...t,...e}),(0,j.jsx)(x,{...t,...e})]})}function I(e){const t=(0,h.A)();return(0,j.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>i});var r=n(6540);const a={},s=r.createContext(a);function o(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/24991caa.6876bd74.js b/assets/js/24991caa.97adaac5.js similarity index 98% rename from assets/js/24991caa.6876bd74.js rename to assets/js/24991caa.97adaac5.js index 9ba0fe40e7..4dcc26f890 100644 --- a/assets/js/24991caa.6876bd74.js +++ b/assets/js/24991caa.97adaac5.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8317],{6348:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>c,default:()=>a,frontMatter:()=>i,metadata:()=>n,toc:()=>u});const n=JSON.parse('{"id":"processing","title":"Processing flow","description":"These are internal technical documents. If you\'re not a contributor to ts-jest, but simply trying to use the library you\'ll find nothing of value here","source":"@site/versioned_docs/version-29.0/processing.md","sourceDirName":".","slug":"/processing","permalink":"/ts-jest/docs/29.0/processing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/processing.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"processing","title":"Processing flow"},"sidebar":"version-29.0-docs","previous":{"title":"Introduction","permalink":"/ts-jest/docs/29.0/"},"next":{"title":"Contributing","permalink":"/ts-jest/docs/29.0/contributing"}}');var o=s(4848),r=s(8453);const i={id:"processing",title:"Processing flow"},c=void 0,l={},u=[{value:"Jest process",id:"jest-process",level:2},{value:"ts-jest process",id:"ts-jest-process",level:2}];function d(e){const t={code:"code",em:"em",h2:"h2",img:"img",p:"p",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.p,{children:(0,o.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,o.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,o.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,o.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,o.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLJRRjim37tNLn3Omn9WwGUaG8Uz3YWmOFq1nQ9YjJ8PY7Iz0lduGHV7YHjWyvDruI7FuH7FfyGTYd0w6r6Rr9YzoayKVMWd6-4nTRXzD2Pus4ZFOtGWcW8TW__ulWNjaM3pWR8r-rTXMWuVpUu9nfEpYgR2F1g3KH0sn5k3v8Ali3v493iW83c1AMWF3-v1vHPz2YU46OXO4L8uzcg8WH0TA4F7mob4D0vzeA212JAsv6IGGwuBCESlBtqGZNXkSGasdUrwTDjpgIi8HwleO60tHfHRkWlIlaje5S6IWm9WL21QEe9WUW-vtiPsztHXK3CGd31944NI6hlIj0e80muDsYSUFWNTAFllqlUDSD7QQB8aUVbSxZPn8terHJsOGenmm5bUPwp0Ei6Ln000IpLGljkCTUyYJbqkMQ5zWtr360M1VQv-3hYSLzaTs0E_Nwdlp88momP1CfA3gKUw72UqBj2ncQJkhNZKlbKAeoWFyEFtIraNsJod0PDK3ci6FQQIU2e_FGVHd8rzEt_DBstWxYrVSapu3Qp0X362dSiP1TEk-3bRV4vfixVdAmURYJ51n-J3qNnciNkwz6xnN-7amv-s0uCzDHwVJ7UxVSzyHQRprJov-_YN9zycIMxkmHumhlnPzkuFeaNapiOeDNoNfJINz8iP_tS4zLR0UiNqgs90p_osVZGsDsPzwTwOMseCrRdv8YJKCP4OuG6rpqu8-hMyB5EiQGK8fzQEwv5LozmlXhlg8fBx2m00"})]})}function a(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8317],{6348:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>c,default:()=>a,frontMatter:()=>i,metadata:()=>n,toc:()=>u});const n=JSON.parse('{"id":"processing","title":"Processing flow","description":"These are internal technical documents. If you\'re not a contributor to ts-jest, but simply trying to use the library you\'ll find nothing of value here","source":"@site/versioned_docs/version-29.0/processing.md","sourceDirName":".","slug":"/processing","permalink":"/ts-jest/docs/29.0/processing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/processing.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"processing","title":"Processing flow"},"sidebar":"version-29.0-docs","previous":{"title":"Introduction","permalink":"/ts-jest/docs/29.0/"},"next":{"title":"Contributing","permalink":"/ts-jest/docs/29.0/contributing"}}');var o=s(4848),r=s(8453);const i={id:"processing",title:"Processing flow"},c=void 0,l={},u=[{value:"Jest process",id:"jest-process",level:2},{value:"ts-jest process",id:"ts-jest-process",level:2}];function d(e){const t={code:"code",em:"em",h2:"h2",img:"img",p:"p",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.p,{children:(0,o.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,o.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,o.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,o.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,o.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLJRRjim37tNLn3Omn9WwGUaG8Uz3YWmOFq1nQ9YjJ8PY7Iz0lduGHV7YHjWyvDruI7FuH7FfyGTYd0w6r6Rr9YzoayKVMWd6-4nTRXzD2Pus4ZFOtGWcW8TW__ulWNjaM3pWR8r-rTXMWuVpUu9nfEpYgR2F1g3KH0sn5k3v8Ali3v493iW83c1AMWF3-v1vHPz2YU46OXO4L8uzcg8WH0TA4F7mob4D0vzeA212JAsv6IGGwuBCESlBtqGZNXkSGasdUrwTDjpgIi8HwleO60tHfHRkWlIlaje5S6IWm9WL21QEe9WUW-vtiPsztHXK3CGd31944NI6hlIj0e80muDsYSUFWNTAFllqlUDSD7QQB8aUVbSxZPn8terHJsOGenmm5bUPwp0Ei6Ln000IpLGljkCTUyYJbqkMQ5zWtr360M1VQv-3hYSLzaTs0E_Nwdlp88momP1CfA3gKUw72UqBj2ncQJkhNZKlbKAeoWFyEFtIraNsJod0PDK3ci6FQQIU2e_FGVHd8rzEt_DBstWxYrVSapu3Qp0X362dSiP1TEk-3bRV4vfixVdAmURYJ51n-J3qNnciNkwz6xnN-7amv-s0uCzDHwVJ7UxVSzyHQRprJov-_YN9zycIMxkmHumhlnPzkuFeaNapiOeDNoNfJINz8iP_tS4zLR0UiNqgs90p_osVZGsDsPzwTwOMseCrRdv8YJKCP4OuG6rpqu8-hMyB5EiQGK8fzQEwv5LozmlXhlg8fBx2m00"})]})}function a(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/265d7427.2fb79e7b.js b/assets/js/265d7427.45a293f1.js similarity index 98% rename from assets/js/265d7427.2fb79e7b.js rename to assets/js/265d7427.45a293f1.js index a4d2e5e173..d67ef67173 100644 --- a/assets/js/265d7427.2fb79e7b.js +++ b/assets/js/265d7427.45a293f1.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7556],{1317:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>h,frontMatter:()=>r,metadata:()=>s,toc:()=>l});const s=JSON.parse('{"id":"getting-started/options/stringifyContentPathRegex","title":"Stringify content option","description":"The stringifyContentPathRegex option has been kept for backward compatibility of HTML_TRANSFORM","source":"@site/versioned_docs/version-27.0/getting-started/options/stringifyContentPathRegex.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/stringifyContentPathRegex","permalink":"/ts-jest/docs/27.0/getting-started/options/stringifyContentPathRegex","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/options/stringifyContentPathRegex.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Stringify content option"}}');var o=n(4848),i=n(8453);const r={title:"Stringify content option"},a=void 0,c={},l=[{value:"Example",id:"example",level:3}];function d(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["The ",(0,o.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,o.jsx)(t.code,{children:"__HTML_TRANSFORM__"}),"\nIt's a regular expression pattern used to match the path of file to be transformed.\nIf it matches, the file will be exported as a module exporting its content."]}),"\n",(0,o.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,o.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,o.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,o.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,o.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,o.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,o.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,o.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,o.jsx)(t.code,{children:"transform"})," option pointing to ",(0,o.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,o.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsxs)(t.p,{children:["In the ",(0,o.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,o.jsx)(t.code,{children:"package.json"})," version of the config, but extending from the preset will ensure more compatibility without any changes when updating."]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\n// Here `defaults` can be replaced with any other preset\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n\nmodule.exports = {\n // [...]\n moduleFileExtensions: [...tsjPreset.moduleFileExtensions, 'html'],\n transform: {\n ...tsjPreset.transform,\n '\\\\.html$': 'ts-jest',\n },\n globals: {\n 'ts-jest': {\n stringifyContentPathRegex: /\\.html$/,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleFileExtensions": ["js", "ts", "html"],\n "transform": {\n "\\\\.(html|ts|js)$": "ts-jest"\n },\n "globals": {\n "ts-jest": {\n "stringifyContentPathRegex": "\\\\.html$"\n }\n }\n }\n}\n'})})]})}function h(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>a});var s=n(6540);const o={},i=s.createContext(o);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7556],{1317:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>h,frontMatter:()=>r,metadata:()=>s,toc:()=>l});const s=JSON.parse('{"id":"getting-started/options/stringifyContentPathRegex","title":"Stringify content option","description":"The stringifyContentPathRegex option has been kept for backward compatibility of HTML_TRANSFORM","source":"@site/versioned_docs/version-27.0/getting-started/options/stringifyContentPathRegex.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/stringifyContentPathRegex","permalink":"/ts-jest/docs/27.0/getting-started/options/stringifyContentPathRegex","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/options/stringifyContentPathRegex.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Stringify content option"}}');var o=n(4848),i=n(8453);const r={title:"Stringify content option"},a=void 0,c={},l=[{value:"Example",id:"example",level:3}];function d(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["The ",(0,o.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,o.jsx)(t.code,{children:"__HTML_TRANSFORM__"}),"\nIt's a regular expression pattern used to match the path of file to be transformed.\nIf it matches, the file will be exported as a module exporting its content."]}),"\n",(0,o.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,o.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,o.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,o.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,o.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,o.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,o.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,o.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,o.jsx)(t.code,{children:"transform"})," option pointing to ",(0,o.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,o.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsxs)(t.p,{children:["In the ",(0,o.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,o.jsx)(t.code,{children:"package.json"})," version of the config, but extending from the preset will ensure more compatibility without any changes when updating."]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\n// Here `defaults` can be replaced with any other preset\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n\nmodule.exports = {\n // [...]\n moduleFileExtensions: [...tsjPreset.moduleFileExtensions, 'html'],\n transform: {\n ...tsjPreset.transform,\n '\\\\.html$': 'ts-jest',\n },\n globals: {\n 'ts-jest': {\n stringifyContentPathRegex: /\\.html$/,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleFileExtensions": ["js", "ts", "html"],\n "transform": {\n "\\\\.(html|ts|js)$": "ts-jest"\n },\n "globals": {\n "ts-jest": {\n "stringifyContentPathRegex": "\\\\.html$"\n }\n }\n }\n}\n'})})]})}function h(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>a});var s=n(6540);const o={},i=s.createContext(o);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/270520cb.66d198dc.js b/assets/js/270520cb.387ac587.js similarity index 99% rename from assets/js/270520cb.66d198dc.js rename to assets/js/270520cb.387ac587.js index 6a6db9505e..c982dd4b12 100644 --- a/assets/js/270520cb.66d198dc.js +++ b/assets/js/270520cb.387ac587.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3110],{4:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>u,contentTitle:()=>c,default:()=>j,frontMatter:()=>l,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/tsconfig","title":"TypeScript Config option","description":"The tsconfig option allows you to define which tsconfig JSON file to use. An inline compiler options object can also be specified instead of a file path.","source":"@site/versioned_docs/version-29.0/getting-started/options/tsconfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/tsconfig","permalink":"/ts-jest/docs/29.0/getting-started/options/tsconfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/options/tsconfig.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"TypeScript Config option"}}');var o=s(4848),r=s(8453),i=s(9489),a=s(7227);const l={title:"TypeScript Config option"},c=void 0,u={},d=[{value:"Examples",id:"examples",level:3},{value:"Path to a tsconfig file",id:"path-to-a-tsconfig-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4},{value:"Disable auto-lookup",id:"disable-auto-lookup",level:4}];function p(t){const e={a:"a",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,r.R)(),...t.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(e.p,{children:["The ",(0,o.jsx)(e.code,{children:"tsconfig"})," option allows you to define which ",(0,o.jsx)(e.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,o.jsx)(e.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," object can also be specified instead of a file path."]}),"\n",(0,o.jsxs)(e.p,{children:["By default ",(0,o.jsx)(e.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(e.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,o.jsx)(e.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,o.jsx)(e.code,{children:"ES2015"})," is used as ",(0,o.jsx)(e.code,{children:"target"})," instead of ",(0,o.jsx)(e.code,{children:"ES5"}),"."]}),"\n",(0,o.jsxs)(e.p,{children:["If you need to use defaults and force ",(0,o.jsx)(e.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,o.jsx)(e.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,o.jsx)(e.code,{children:"false"}),"."]}),"\n",(0,o.jsx)(e.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsxs)(e.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,o.jsx)(e.code,{children:"tsconfig"})," file"]}),"\n",(0,o.jsxs)(e.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,o.jsx)(e.code,{children:""})," in the path to start from the project root dir."]}),"\n",(0,o.jsxs)(i.A,{groupId:"code-examples",children:[(0,o.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: 'tsconfig.test.json',\n },\n ],\n },\n}\n"})})}),(0,o.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: 'tsconfig.test.json',\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,o.jsx)(a.A,{value:"JSON",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "tsconfig": "tsconfig.test.json"\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,o.jsx)(e.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,o.jsxs)(e.p,{children:["Refer to the TypeScript ",(0,o.jsx)(e.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," for reference.\nIt's basically the same object you'd put in your ",(0,o.jsx)(e.code,{children:"tsconfig.json"}),"'s ",(0,o.jsx)(e.code,{children:"compilerOptions"}),"."]}),"\n",(0,o.jsxs)(i.A,{groupId:"code-examples",children:[(0,o.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: {\n importHelpers: true,\n },\n },\n ],\n },\n}\n"})})}),(0,o.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: {\n importHelpers: true,\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,o.jsx)(a.A,{value:"JSON",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "tsconfig": {\n "importHelpers": true\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,o.jsx)(e.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,o.jsxs)(e.p,{children:["By default ",(0,o.jsx)(e.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(e.code,{children:"tsconfig.json"})," in your project. But you may not want to use it at all and keep TypeScript default options. You can achieve this by setting ",(0,o.jsx)(e.code,{children:"tsconfig"})," to ",(0,o.jsx)(e.code,{children:"false"}),"."]}),"\n",(0,o.jsxs)(i.A,{groupId:"code-examples",children:[(0,o.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: false,\n },\n ],\n },\n}\n"})})}),(0,o.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: false,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,o.jsx)(a.A,{value:"JSON",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "tsconfig": {\n "tsconfig": false\n }\n }\n ]\n }\n }\n}\n'})})})]})]})}function j(t={}){const{wrapper:e}={...(0,r.R)(),...t.components};return e?(0,o.jsx)(e,{...t,children:(0,o.jsx)(p,{...t})}):p(t)}},7227:(t,e,s)=>{s.d(e,{A:()=>i});s(6540);var n=s(4164);const o={tabItem:"tabItem_Ymn6"};var r=s(4848);function i(t){let{children:e,hidden:s,className:i}=t;return(0,r.jsx)("div",{role:"tabpanel",className:(0,n.A)(o.tabItem,i),hidden:s,children:e})}},9489:(t,e,s)=>{s.d(e,{A:()=>w});var n=s(6540),o=s(4164),r=s(4245),i=s(6347),a=s(6494),l=s(2814),c=s(5167),u=s(9900);function d(t){return n.Children.toArray(t).filter((t=>"\n"!==t)).map((t=>{if(!t||(0,n.isValidElement)(t)&&function(t){const{props:e}=t;return!!e&&"object"==typeof e&&"value"in e}(t))return t;throw new Error(`Docusaurus error: Bad child <${"string"==typeof t.type?t.type:t.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(t){const{values:e,children:s}=t;return(0,n.useMemo)((()=>{const t=e??function(t){return d(t).map((t=>{let{props:{value:e,label:s,attributes:n,default:o}}=t;return{value:e,label:s,attributes:n,default:o}}))}(s);return function(t){const e=(0,c.XI)(t,((t,e)=>t.value===e.value));if(e.length>0)throw new Error(`Docusaurus error: Duplicate values "${e.map((t=>t.value)).join(", ")}" found in . Every value needs to be unique.`)}(t),t}),[e,s])}function j(t){let{value:e,tabValues:s}=t;return s.some((t=>t.value===e))}function h(t){let{queryString:e=!1,groupId:s}=t;const o=(0,i.W6)(),r=function(t){let{queryString:e=!1,groupId:s}=t;if("string"==typeof e)return e;if(!1===e)return null;if(!0===e&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:e,groupId:s});return[(0,l.aZ)(r),(0,n.useCallback)((t=>{if(!r)return;const e=new URLSearchParams(o.location.search);e.set(r,t),o.replace({...o.location,search:e.toString()})}),[r,o])]}function f(t){const{defaultValue:e,queryString:s=!1,groupId:o}=t,r=p(t),[i,l]=(0,n.useState)((()=>function(t){let{defaultValue:e,tabValues:s}=t;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(e){if(!j({value:e,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${e}" but none of its children has the corresponding value. Available values are: ${s.map((t=>t.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return e}const n=s.find((t=>t.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:e,tabValues:r}))),[c,d]=h({queryString:s,groupId:o}),[f,m]=function(t){let{groupId:e}=t;const s=function(t){return t?`docusaurus.tab.${t}`:null}(e),[o,r]=(0,u.Dv)(s);return[o,(0,n.useCallback)((t=>{s&&r.set(t)}),[s,r])]}({groupId:o}),x=(()=>{const t=c??f;return j({value:t,tabValues:r})?t:null})();(0,a.A)((()=>{x&&l(x)}),[x]);return{selectedValue:i,selectValue:(0,n.useCallback)((t=>{if(!j({value:t,tabValues:r}))throw new Error(`Can't select invalid tab value=${t}`);l(t),d(t),m(t)}),[d,m,r]),tabValues:r}}var m=s(1062);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=s(4848);function b(t){let{className:e,block:s,selectedValue:n,selectValue:i,tabValues:a}=t;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),u=t=>{const e=t.currentTarget,s=l.indexOf(e),o=a[s].value;o!==n&&(c(e),i(o))},d=t=>{let e=null;switch(t.key){case"Enter":u(t);break;case"ArrowRight":{const s=l.indexOf(t.currentTarget)+1;e=l[s]??l[0];break}case"ArrowLeft":{const s=l.indexOf(t.currentTarget)-1;e=l[s]??l[l.length-1];break}}e?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.A)("tabs",{"tabs--block":s},e),children:a.map((t=>{let{value:e,label:s,attributes:r}=t;return(0,g.jsx)("li",{role:"tab",tabIndex:n===e?0:-1,"aria-selected":n===e,ref:t=>l.push(t),onKeyDown:d,onClick:u,...r,className:(0,o.A)("tabs__item",x.tabItem,r?.className,{"tabs__item--active":n===e}),children:s??e},e)}))})}function v(t){let{lazy:e,children:s,selectedValue:r}=t;const i=(Array.isArray(s)?s:[s]).filter(Boolean);if(e){const t=i.find((t=>t.props.value===r));return t?(0,n.cloneElement)(t,{className:(0,o.A)("margin-top--md",t.props.className)}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:i.map(((t,e)=>(0,n.cloneElement)(t,{key:e,hidden:t.props.value!==r})))})}function y(t){const e=f(t);return(0,g.jsxs)("div",{className:(0,o.A)("tabs-container",x.tabList),children:[(0,g.jsx)(b,{...e,...t}),(0,g.jsx)(v,{...e,...t})]})}function w(t){const e=(0,m.A)();return(0,g.jsx)(y,{...t,children:d(t.children)},String(e))}},8453:(t,e,s)=>{s.d(e,{R:()=>i,x:()=>a});var n=s(6540);const o={},r=n.createContext(o);function i(t){const e=n.useContext(r);return n.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function a(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:i(t.components),n.createElement(r.Provider,{value:e},t.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3110],{4:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>u,contentTitle:()=>c,default:()=>j,frontMatter:()=>l,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/tsconfig","title":"TypeScript Config option","description":"The tsconfig option allows you to define which tsconfig JSON file to use. An inline compiler options object can also be specified instead of a file path.","source":"@site/versioned_docs/version-29.0/getting-started/options/tsconfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/tsconfig","permalink":"/ts-jest/docs/29.0/getting-started/options/tsconfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/options/tsconfig.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"TypeScript Config option"}}');var o=s(4848),r=s(8453),i=s(9489),a=s(7227);const l={title:"TypeScript Config option"},c=void 0,u={},d=[{value:"Examples",id:"examples",level:3},{value:"Path to a tsconfig file",id:"path-to-a-tsconfig-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4},{value:"Disable auto-lookup",id:"disable-auto-lookup",level:4}];function p(t){const e={a:"a",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,r.R)(),...t.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(e.p,{children:["The ",(0,o.jsx)(e.code,{children:"tsconfig"})," option allows you to define which ",(0,o.jsx)(e.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,o.jsx)(e.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," object can also be specified instead of a file path."]}),"\n",(0,o.jsxs)(e.p,{children:["By default ",(0,o.jsx)(e.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(e.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,o.jsx)(e.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,o.jsx)(e.code,{children:"ES2015"})," is used as ",(0,o.jsx)(e.code,{children:"target"})," instead of ",(0,o.jsx)(e.code,{children:"ES5"}),"."]}),"\n",(0,o.jsxs)(e.p,{children:["If you need to use defaults and force ",(0,o.jsx)(e.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,o.jsx)(e.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,o.jsx)(e.code,{children:"false"}),"."]}),"\n",(0,o.jsx)(e.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsxs)(e.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,o.jsx)(e.code,{children:"tsconfig"})," file"]}),"\n",(0,o.jsxs)(e.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,o.jsx)(e.code,{children:""})," in the path to start from the project root dir."]}),"\n",(0,o.jsxs)(i.A,{groupId:"code-examples",children:[(0,o.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: 'tsconfig.test.json',\n },\n ],\n },\n}\n"})})}),(0,o.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: 'tsconfig.test.json',\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,o.jsx)(a.A,{value:"JSON",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "tsconfig": "tsconfig.test.json"\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,o.jsx)(e.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,o.jsxs)(e.p,{children:["Refer to the TypeScript ",(0,o.jsx)(e.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," for reference.\nIt's basically the same object you'd put in your ",(0,o.jsx)(e.code,{children:"tsconfig.json"}),"'s ",(0,o.jsx)(e.code,{children:"compilerOptions"}),"."]}),"\n",(0,o.jsxs)(i.A,{groupId:"code-examples",children:[(0,o.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: {\n importHelpers: true,\n },\n },\n ],\n },\n}\n"})})}),(0,o.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: {\n importHelpers: true,\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,o.jsx)(a.A,{value:"JSON",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "tsconfig": {\n "importHelpers": true\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,o.jsx)(e.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,o.jsxs)(e.p,{children:["By default ",(0,o.jsx)(e.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(e.code,{children:"tsconfig.json"})," in your project. But you may not want to use it at all and keep TypeScript default options. You can achieve this by setting ",(0,o.jsx)(e.code,{children:"tsconfig"})," to ",(0,o.jsx)(e.code,{children:"false"}),"."]}),"\n",(0,o.jsxs)(i.A,{groupId:"code-examples",children:[(0,o.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: false,\n },\n ],\n },\n}\n"})})}),(0,o.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: false,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,o.jsx)(a.A,{value:"JSON",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "tsconfig": {\n "tsconfig": false\n }\n }\n ]\n }\n }\n}\n'})})})]})]})}function j(t={}){const{wrapper:e}={...(0,r.R)(),...t.components};return e?(0,o.jsx)(e,{...t,children:(0,o.jsx)(p,{...t})}):p(t)}},7227:(t,e,s)=>{s.d(e,{A:()=>i});s(6540);var n=s(4164);const o={tabItem:"tabItem_Ymn6"};var r=s(4848);function i(t){let{children:e,hidden:s,className:i}=t;return(0,r.jsx)("div",{role:"tabpanel",className:(0,n.A)(o.tabItem,i),hidden:s,children:e})}},9489:(t,e,s)=>{s.d(e,{A:()=>w});var n=s(6540),o=s(4164),r=s(4245),i=s(6347),a=s(6494),l=s(2814),c=s(5167),u=s(9900);function d(t){return n.Children.toArray(t).filter((t=>"\n"!==t)).map((t=>{if(!t||(0,n.isValidElement)(t)&&function(t){const{props:e}=t;return!!e&&"object"==typeof e&&"value"in e}(t))return t;throw new Error(`Docusaurus error: Bad child <${"string"==typeof t.type?t.type:t.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(t){const{values:e,children:s}=t;return(0,n.useMemo)((()=>{const t=e??function(t){return d(t).map((t=>{let{props:{value:e,label:s,attributes:n,default:o}}=t;return{value:e,label:s,attributes:n,default:o}}))}(s);return function(t){const e=(0,c.XI)(t,((t,e)=>t.value===e.value));if(e.length>0)throw new Error(`Docusaurus error: Duplicate values "${e.map((t=>t.value)).join(", ")}" found in . Every value needs to be unique.`)}(t),t}),[e,s])}function j(t){let{value:e,tabValues:s}=t;return s.some((t=>t.value===e))}function h(t){let{queryString:e=!1,groupId:s}=t;const o=(0,i.W6)(),r=function(t){let{queryString:e=!1,groupId:s}=t;if("string"==typeof e)return e;if(!1===e)return null;if(!0===e&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:e,groupId:s});return[(0,l.aZ)(r),(0,n.useCallback)((t=>{if(!r)return;const e=new URLSearchParams(o.location.search);e.set(r,t),o.replace({...o.location,search:e.toString()})}),[r,o])]}function f(t){const{defaultValue:e,queryString:s=!1,groupId:o}=t,r=p(t),[i,l]=(0,n.useState)((()=>function(t){let{defaultValue:e,tabValues:s}=t;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(e){if(!j({value:e,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${e}" but none of its children has the corresponding value. Available values are: ${s.map((t=>t.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return e}const n=s.find((t=>t.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:e,tabValues:r}))),[c,d]=h({queryString:s,groupId:o}),[f,m]=function(t){let{groupId:e}=t;const s=function(t){return t?`docusaurus.tab.${t}`:null}(e),[o,r]=(0,u.Dv)(s);return[o,(0,n.useCallback)((t=>{s&&r.set(t)}),[s,r])]}({groupId:o}),x=(()=>{const t=c??f;return j({value:t,tabValues:r})?t:null})();(0,a.A)((()=>{x&&l(x)}),[x]);return{selectedValue:i,selectValue:(0,n.useCallback)((t=>{if(!j({value:t,tabValues:r}))throw new Error(`Can't select invalid tab value=${t}`);l(t),d(t),m(t)}),[d,m,r]),tabValues:r}}var m=s(1062);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=s(4848);function b(t){let{className:e,block:s,selectedValue:n,selectValue:i,tabValues:a}=t;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),u=t=>{const e=t.currentTarget,s=l.indexOf(e),o=a[s].value;o!==n&&(c(e),i(o))},d=t=>{let e=null;switch(t.key){case"Enter":u(t);break;case"ArrowRight":{const s=l.indexOf(t.currentTarget)+1;e=l[s]??l[0];break}case"ArrowLeft":{const s=l.indexOf(t.currentTarget)-1;e=l[s]??l[l.length-1];break}}e?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.A)("tabs",{"tabs--block":s},e),children:a.map((t=>{let{value:e,label:s,attributes:r}=t;return(0,g.jsx)("li",{role:"tab",tabIndex:n===e?0:-1,"aria-selected":n===e,ref:t=>l.push(t),onKeyDown:d,onClick:u,...r,className:(0,o.A)("tabs__item",x.tabItem,r?.className,{"tabs__item--active":n===e}),children:s??e},e)}))})}function v(t){let{lazy:e,children:s,selectedValue:r}=t;const i=(Array.isArray(s)?s:[s]).filter(Boolean);if(e){const t=i.find((t=>t.props.value===r));return t?(0,n.cloneElement)(t,{className:(0,o.A)("margin-top--md",t.props.className)}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:i.map(((t,e)=>(0,n.cloneElement)(t,{key:e,hidden:t.props.value!==r})))})}function y(t){const e=f(t);return(0,g.jsxs)("div",{className:(0,o.A)("tabs-container",x.tabList),children:[(0,g.jsx)(b,{...e,...t}),(0,g.jsx)(v,{...e,...t})]})}function w(t){const e=(0,m.A)();return(0,g.jsx)(y,{...t,children:d(t.children)},String(e))}},8453:(t,e,s)=>{s.d(e,{R:()=>i,x:()=>a});var n=s(6540);const o={},r=n.createContext(o);function i(t){const e=n.useContext(r);return n.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function a(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:i(t.components),n.createElement(r.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/295b567d.a71774d7.js b/assets/js/295b567d.47624169.js similarity index 99% rename from assets/js/295b567d.a71774d7.js rename to assets/js/295b567d.47624169.js index d75f4d6a32..c124558bd9 100644 --- a/assets/js/295b567d.a71774d7.js +++ b/assets/js/295b567d.47624169.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3549],{462:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>p,frontMatter:()=>l,metadata:()=>r,toc:()=>d});const r=JSON.parse('{"id":"migration","title":"Migration from <=23.10","description":"You can use the config:migrate tool of ts-jest CLI if you\'re coming from an older version to help you migrate your Jest configuration.","source":"@site/docs/migration.md","sourceDirName":".","slug":"/migration","permalink":"/ts-jest/docs/next/migration","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/migration.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"migration","title":"Migration from <=23.10"},"sidebar":"docs","previous":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/next/babel7-or-ts"},"next":{"title":"Debugging ts-jest","permalink":"/ts-jest/docs/next/debugging"}}');var a=n(4848),s=n(8453),o=n(9489),i=n(7227);const l={id:"migration",title:"Migration from <=23.10"},u=void 0,c={},d=[];function m(e){const t={code:"code",em:"em",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(t.p,{children:["You can use the ",(0,a.jsx)(t.code,{children:"config:migrate"})," tool of ",(0,a.jsx)(t.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,a.jsx)(t.p,{children:(0,a.jsxs)(t.em,{children:["If you're using ",(0,a.jsx)(t.code,{children:"jest.config.js"}),":"]})}),"\n",(0,a.jsxs)(o.A,{groupId:"code-examples",children:[(0,a.jsx)(i.A,{value:"npm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-npm",metastring:"tab",children:"npx ts-jest config:migrate jest.config.js\n"})})}),(0,a.jsx)(i.A,{value:"Yarn",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-Yarn",metastring:"tab",children:"yarn ts-jest config:migrate jest.config.js\n"})})})]}),"\n",(0,a.jsx)(t.p,{children:(0,a.jsxs)(t.em,{children:["If you're using ",(0,a.jsx)(t.code,{children:"jest"})," config property of ",(0,a.jsx)(t.code,{children:"package.json"}),":"]})}),"\n",(0,a.jsxs)(o.A,{groupId:"code-examples",children:[(0,a.jsx)(i.A,{value:"npm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-npm",metastring:"tab",children:"npx ts-jest config:migrate package.json\n"})})}),(0,a.jsx)(i.A,{value:"Yarn",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-Yarn",metastring:"tab",children:"yarn ts-jest config:migrate package.json\n"})})})]})]})}function p(e={}){const{wrapper:t}={...(0,s.R)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(m,{...e})}):m(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var r=n(4164);const a={tabItem:"tabItem_Ymn6"};var s=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.A)(a.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>I});var r=n(6540),a=n(4164),s=n(4245),o=n(6347),i=n(6494),l=n(2814),u=n(5167),c=n(9900);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function m(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(n);return function(e){const t=(0,u.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const a=(0,o.W6)(),s=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(s),(0,r.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function g(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,s=m(e),[o,l]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:s}))),[u,d]=f({queryString:n,groupId:a}),[g,h]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,c.Dv)(n);return[a,(0,r.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),b=(()=>{const e=u??g;return p({value:e,tabValues:s})?e:null})();(0,i.A)((()=>{b&&l(b)}),[b]);return{selectedValue:o,selectValue:(0,r.useCallback)((e=>{if(!p({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),h(e)}),[d,h,s]),tabValues:s}}var h=n(1062);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var j=n(4848);function v(e){let{className:t,block:n,selectedValue:r,selectValue:o,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:u}=(0,s.a_)(),c=e=>{const t=e.currentTarget,n=l.indexOf(t),a=i[n].value;a!==r&&(u(t),o(a))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,j.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.A)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,j.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>l.push(e),onKeyDown:d,onClick:c,...s,className:(0,a.A)("tabs__item",b.tabItem,s?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:s}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===s));return e?(0,r.cloneElement)(e,{className:(0,a.A)("margin-top--md",e.props.className)}):null}return(0,j.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==s})))})}function y(e){const t=g(e);return(0,j.jsxs)("div",{className:(0,a.A)("tabs-container",b.tabList),children:[(0,j.jsx)(v,{...t,...e}),(0,j.jsx)(x,{...t,...e})]})}function I(e){const t=(0,h.A)();return(0,j.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>i});var r=n(6540);const a={},s=r.createContext(a);function o(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3549],{462:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>p,frontMatter:()=>l,metadata:()=>r,toc:()=>d});const r=JSON.parse('{"id":"migration","title":"Migration from <=23.10","description":"You can use the config:migrate tool of ts-jest CLI if you\'re coming from an older version to help you migrate your Jest configuration.","source":"@site/docs/migration.md","sourceDirName":".","slug":"/migration","permalink":"/ts-jest/docs/next/migration","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/migration.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"migration","title":"Migration from <=23.10"},"sidebar":"docs","previous":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/next/babel7-or-ts"},"next":{"title":"Debugging ts-jest","permalink":"/ts-jest/docs/next/debugging"}}');var a=n(4848),s=n(8453),o=n(9489),i=n(7227);const l={id:"migration",title:"Migration from <=23.10"},u=void 0,c={},d=[];function m(e){const t={code:"code",em:"em",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(t.p,{children:["You can use the ",(0,a.jsx)(t.code,{children:"config:migrate"})," tool of ",(0,a.jsx)(t.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,a.jsx)(t.p,{children:(0,a.jsxs)(t.em,{children:["If you're using ",(0,a.jsx)(t.code,{children:"jest.config.js"}),":"]})}),"\n",(0,a.jsxs)(o.A,{groupId:"code-examples",children:[(0,a.jsx)(i.A,{value:"npm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-npm",metastring:"tab",children:"npx ts-jest config:migrate jest.config.js\n"})})}),(0,a.jsx)(i.A,{value:"Yarn",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-Yarn",metastring:"tab",children:"yarn ts-jest config:migrate jest.config.js\n"})})})]}),"\n",(0,a.jsx)(t.p,{children:(0,a.jsxs)(t.em,{children:["If you're using ",(0,a.jsx)(t.code,{children:"jest"})," config property of ",(0,a.jsx)(t.code,{children:"package.json"}),":"]})}),"\n",(0,a.jsxs)(o.A,{groupId:"code-examples",children:[(0,a.jsx)(i.A,{value:"npm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-npm",metastring:"tab",children:"npx ts-jest config:migrate package.json\n"})})}),(0,a.jsx)(i.A,{value:"Yarn",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-Yarn",metastring:"tab",children:"yarn ts-jest config:migrate package.json\n"})})})]})]})}function p(e={}){const{wrapper:t}={...(0,s.R)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(m,{...e})}):m(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var r=n(4164);const a={tabItem:"tabItem_Ymn6"};var s=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.A)(a.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>I});var r=n(6540),a=n(4164),s=n(4245),o=n(6347),i=n(6494),l=n(2814),u=n(5167),c=n(9900);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function m(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(n);return function(e){const t=(0,u.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const a=(0,o.W6)(),s=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(s),(0,r.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function g(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,s=m(e),[o,l]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:s}))),[u,d]=f({queryString:n,groupId:a}),[g,h]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,c.Dv)(n);return[a,(0,r.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),b=(()=>{const e=u??g;return p({value:e,tabValues:s})?e:null})();(0,i.A)((()=>{b&&l(b)}),[b]);return{selectedValue:o,selectValue:(0,r.useCallback)((e=>{if(!p({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),h(e)}),[d,h,s]),tabValues:s}}var h=n(1062);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var j=n(4848);function v(e){let{className:t,block:n,selectedValue:r,selectValue:o,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:u}=(0,s.a_)(),c=e=>{const t=e.currentTarget,n=l.indexOf(t),a=i[n].value;a!==r&&(u(t),o(a))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,j.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.A)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,j.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>l.push(e),onKeyDown:d,onClick:c,...s,className:(0,a.A)("tabs__item",b.tabItem,s?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:s}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===s));return e?(0,r.cloneElement)(e,{className:(0,a.A)("margin-top--md",e.props.className)}):null}return(0,j.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==s})))})}function y(e){const t=g(e);return(0,j.jsxs)("div",{className:(0,a.A)("tabs-container",b.tabList),children:[(0,j.jsx)(v,{...t,...e}),(0,j.jsx)(x,{...t,...e})]})}function I(e){const t=(0,h.A)();return(0,j.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>i});var r=n(6540);const a={},s=r.createContext(a);function o(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/2a3bd03a.8879b397.js b/assets/js/2a3bd03a.3487bf7c.js similarity index 98% rename from assets/js/2a3bd03a.8879b397.js rename to assets/js/2a3bd03a.3487bf7c.js index 5c89b61b79..acc1a652d0 100644 --- a/assets/js/2a3bd03a.8879b397.js +++ b/assets/js/2a3bd03a.3487bf7c.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6399],{4493:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>d,contentTitle:()=>l,default:()=>u,frontMatter:()=>r,metadata:()=>t,toc:()=>a});const t=JSON.parse('{"id":"guides/troubleshooting","title":"Troubleshooting","description":"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them.","source":"@site/versioned_docs/version-27.1/guides/troubleshooting.md","sourceDirName":"guides","slug":"/guides/troubleshooting","permalink":"/ts-jest/docs/27.1/guides/troubleshooting","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/guides/troubleshooting.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"troubleshooting","title":"Troubleshooting"},"sidebar":"version-27.1-docs","previous":{"title":"Test helpers","permalink":"/ts-jest/docs/27.1/guides/test-helpers"},"next":{"title":"Using with monorepo","permalink":"/ts-jest/docs/27.1/guides/using-with-monorepo"}}');var o=n(4848),i=n(8453);const r={id:"troubleshooting",title:"Troubleshooting"},l=void 0,d={},a=[{value:"Running ts-jest on CI tools",id:"running-ts-jest-on-ci-tools",level:2},{value:"PROBLEM",id:"problem",level:3},{value:"SOLUTION",id:"solution",level:3},{value:"Transform (node)-module explicitly",id:"transform-node-module-explicitly",level:2},{value:"PROBLEM",id:"problem-1",level:3},{value:"SOLUTION",id:"solution-1",level:3},{value:"Tests gets stuck when importing a dependency",id:"tests-gets-stuck-when-importing-a-dependency",level:2},{value:"PROBLEM",id:"problem-2",level:3},{value:"SOLUTION",id:"solution-2",level:3}];function c(e){const s={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(s.p,{children:"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them."}),"\n",(0,o.jsxs)(s.p,{children:["Please also check Jest ",(0,o.jsx)(s.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," if your issue is related to jest."]}),"\n",(0,o.jsx)(s.h2,{id:"running-ts-jest-on-ci-tools",children:"Running ts-jest on CI tools"}),"\n",(0,o.jsx)(s.h3,{id:"problem",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:'Cannot find module "" from ""'}),"\n",(0,o.jsx)(s.h3,{id:"solution",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check if ",(0,o.jsx)(s.code,{children:"rootDir"})," is referenced correctly. If not add this on your existing jest configuration."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n roots: [""]\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module directories are included on your jest configuration. If not add this on your existing jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleDirectories: ["node_modules",""],\n modulePaths: [""],\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module name is properly mapped and can be referenced by jest. If not, you can define moduleNameMapper for your jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleNameMapper: {\n "": "/",\n },\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check github folder names if its identical to you local folder names. Sometimes github never updates your folder names even if you rename it locally. If this happens rename your folders via github or use this command ",(0,o.jsx)(s.code,{children:"git mv "})," and commit changes."]}),"\n"]}),"\n",(0,o.jsx)(s.h2,{id:"transform-node-module-explicitly",children:"Transform (node)-module explicitly"}),"\n",(0,o.jsx)(s.h3,{id:"problem-1",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"SyntaxError: Cannot use import statement outside a module"}),"\n",(0,o.jsx)(s.h3,{id:"solution-1",children:"SOLUTION"}),"\n",(0,o.jsx)(s.p,{children:"One of the node modules hasn't the correct syntax for Jests execution step. It needs to\nbe transformed first."}),"\n",(0,o.jsx)(s.p,{children:"There is a good chance that the error message shows which module is affected:"}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-shell",children:' SyntaxError: Cannot use import statement outside a module\n > 22 | import Component from "../../node_modules/some-module/lib";\n | ^\n'})}),"\n",(0,o.jsxs)(s.p,{children:["In this case ",(0,o.jsx)(s.strong,{children:"some-module"})," is the problem and needs to be transformed.\nBy adding the following line to the configuration file it will tell Jest which modules\nshouldnt be ignored during the transformation step:"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n transformIgnorePatterns: ["node_modules/(?!(some-module|another-module))"]\n};\n'})}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.strong,{children:"some-module"})," and ",(0,o.jsx)(s.strong,{children:"another-module"})," will be transformed."]}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/63389757/jest-unit-test-syntaxerror-cannot-use-import-statement-outside-a-module",children:"here"})," and ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/52035066/how-to-write-jest-transformignorepatterns",children:"here"}),"."]}),"\n",(0,o.jsx)(s.h2,{id:"tests-gets-stuck-when-importing-a-dependency",children:"Tests gets stuck when importing a dependency"}),"\n",(0,o.jsx)(s.h3,{id:"problem-2",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"Without cache, jest takes an extremely long time to process files and appears to be stuck."}),"\n",(0,o.jsx)(s.h3,{id:"solution-2",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.code,{children:"ts-jest"})," internally uses TypeScript compiler API to transform ts/js file into js file. The recommendation is to only transform what is needed."]}),"\n",(0,o.jsxs)(s.p,{children:["A possible cause for that issue is that you may have enabled ",(0,o.jsx)(s.code,{children:"ts-jest"})," to process javascript files in addition to TypeScript files. This leads to the result that more files are loaded which can, in some cases, blow up the machine."]}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your tsconfig file, check if ",(0,o.jsx)(s.code,{children:"compilerOptions.allowJs"})," is unset or set to false."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'{\n "compilerOptions": {\n "allowJs": false,\n }\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your jest configuration, check if the transform property includes only ",(0,o.jsx)(s.code,{children:".ts"})," files for ts-jest. If not, change the regular expression to exclude js files. You can also add the attribute ",(0,o.jsx)(s.code,{children:"isolatedModules: true"})," for ts-jest to disable type checking for tests."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-diff",children:"module.exports = {\n ...\n 'transform': {\n- '^.+\\\\.(t|j)s$': ['ts-jest', {}],\n+ '^.+\\\\.ts$': ['ts-jest', { isolatedModules: true }],\n },\n};\n"})}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://github.com/kulshekhar/ts-jest/issues/4294",children:"here"})]})]})}function u(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,o.jsx)(s,{...e,children:(0,o.jsx)(c,{...e})}):c(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>r,x:()=>l});var t=n(6540);const o={},i=t.createContext(o);function r(e){const s=t.useContext(i);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function l(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),t.createElement(i.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6399],{4493:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>d,contentTitle:()=>l,default:()=>u,frontMatter:()=>r,metadata:()=>t,toc:()=>a});const t=JSON.parse('{"id":"guides/troubleshooting","title":"Troubleshooting","description":"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them.","source":"@site/versioned_docs/version-27.1/guides/troubleshooting.md","sourceDirName":"guides","slug":"/guides/troubleshooting","permalink":"/ts-jest/docs/27.1/guides/troubleshooting","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/guides/troubleshooting.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"troubleshooting","title":"Troubleshooting"},"sidebar":"version-27.1-docs","previous":{"title":"Test helpers","permalink":"/ts-jest/docs/27.1/guides/test-helpers"},"next":{"title":"Using with monorepo","permalink":"/ts-jest/docs/27.1/guides/using-with-monorepo"}}');var o=n(4848),i=n(8453);const r={id:"troubleshooting",title:"Troubleshooting"},l=void 0,d={},a=[{value:"Running ts-jest on CI tools",id:"running-ts-jest-on-ci-tools",level:2},{value:"PROBLEM",id:"problem",level:3},{value:"SOLUTION",id:"solution",level:3},{value:"Transform (node)-module explicitly",id:"transform-node-module-explicitly",level:2},{value:"PROBLEM",id:"problem-1",level:3},{value:"SOLUTION",id:"solution-1",level:3},{value:"Tests gets stuck when importing a dependency",id:"tests-gets-stuck-when-importing-a-dependency",level:2},{value:"PROBLEM",id:"problem-2",level:3},{value:"SOLUTION",id:"solution-2",level:3}];function c(e){const s={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(s.p,{children:"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them."}),"\n",(0,o.jsxs)(s.p,{children:["Please also check Jest ",(0,o.jsx)(s.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," if your issue is related to jest."]}),"\n",(0,o.jsx)(s.h2,{id:"running-ts-jest-on-ci-tools",children:"Running ts-jest on CI tools"}),"\n",(0,o.jsx)(s.h3,{id:"problem",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:'Cannot find module "" from ""'}),"\n",(0,o.jsx)(s.h3,{id:"solution",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check if ",(0,o.jsx)(s.code,{children:"rootDir"})," is referenced correctly. If not add this on your existing jest configuration."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n roots: [""]\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module directories are included on your jest configuration. If not add this on your existing jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleDirectories: ["node_modules",""],\n modulePaths: [""],\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module name is properly mapped and can be referenced by jest. If not, you can define moduleNameMapper for your jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleNameMapper: {\n "": "/",\n },\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check github folder names if its identical to you local folder names. Sometimes github never updates your folder names even if you rename it locally. If this happens rename your folders via github or use this command ",(0,o.jsx)(s.code,{children:"git mv "})," and commit changes."]}),"\n"]}),"\n",(0,o.jsx)(s.h2,{id:"transform-node-module-explicitly",children:"Transform (node)-module explicitly"}),"\n",(0,o.jsx)(s.h3,{id:"problem-1",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"SyntaxError: Cannot use import statement outside a module"}),"\n",(0,o.jsx)(s.h3,{id:"solution-1",children:"SOLUTION"}),"\n",(0,o.jsx)(s.p,{children:"One of the node modules hasn't the correct syntax for Jests execution step. It needs to\nbe transformed first."}),"\n",(0,o.jsx)(s.p,{children:"There is a good chance that the error message shows which module is affected:"}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-shell",children:' SyntaxError: Cannot use import statement outside a module\n > 22 | import Component from "../../node_modules/some-module/lib";\n | ^\n'})}),"\n",(0,o.jsxs)(s.p,{children:["In this case ",(0,o.jsx)(s.strong,{children:"some-module"})," is the problem and needs to be transformed.\nBy adding the following line to the configuration file it will tell Jest which modules\nshouldnt be ignored during the transformation step:"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n transformIgnorePatterns: ["node_modules/(?!(some-module|another-module))"]\n};\n'})}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.strong,{children:"some-module"})," and ",(0,o.jsx)(s.strong,{children:"another-module"})," will be transformed."]}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/63389757/jest-unit-test-syntaxerror-cannot-use-import-statement-outside-a-module",children:"here"})," and ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/52035066/how-to-write-jest-transformignorepatterns",children:"here"}),"."]}),"\n",(0,o.jsx)(s.h2,{id:"tests-gets-stuck-when-importing-a-dependency",children:"Tests gets stuck when importing a dependency"}),"\n",(0,o.jsx)(s.h3,{id:"problem-2",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"Without cache, jest takes an extremely long time to process files and appears to be stuck."}),"\n",(0,o.jsx)(s.h3,{id:"solution-2",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.code,{children:"ts-jest"})," internally uses TypeScript compiler API to transform ts/js file into js file. The recommendation is to only transform what is needed."]}),"\n",(0,o.jsxs)(s.p,{children:["A possible cause for that issue is that you may have enabled ",(0,o.jsx)(s.code,{children:"ts-jest"})," to process javascript files in addition to TypeScript files. This leads to the result that more files are loaded which can, in some cases, blow up the machine."]}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your tsconfig file, check if ",(0,o.jsx)(s.code,{children:"compilerOptions.allowJs"})," is unset or set to false."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'{\n "compilerOptions": {\n "allowJs": false,\n }\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your jest configuration, check if the transform property includes only ",(0,o.jsx)(s.code,{children:".ts"})," files for ts-jest. If not, change the regular expression to exclude js files. You can also add the attribute ",(0,o.jsx)(s.code,{children:"isolatedModules: true"})," for ts-jest to disable type checking for tests."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-diff",children:"module.exports = {\n ...\n 'transform': {\n- '^.+\\\\.(t|j)s$': ['ts-jest', {}],\n+ '^.+\\\\.ts$': ['ts-jest', { isolatedModules: true }],\n },\n};\n"})}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://github.com/kulshekhar/ts-jest/issues/4294",children:"here"})]})]})}function u(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,o.jsx)(s,{...e,children:(0,o.jsx)(c,{...e})}):c(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>r,x:()=>l});var t=n(6540);const o={},i=t.createContext(o);function r(e){const s=t.useContext(i);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function l(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),t.createElement(i.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/2b68f68f.c5eeb725.js b/assets/js/2b68f68f.411a7201.js similarity index 98% rename from assets/js/2b68f68f.c5eeb725.js rename to assets/js/2b68f68f.411a7201.js index 6dbcce86e4..d91ecbbe16 100644 --- a/assets/js/2b68f68f.c5eeb725.js +++ b/assets/js/2b68f68f.411a7201.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4519],{5885:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>l,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/installation","title":"Installation","description":"Dependencies","source":"@site/versioned_docs/version-27.0/getting-started/installation.md","sourceDirName":"getting-started","slug":"/getting-started/installation","permalink":"/ts-jest/docs/27.0/getting-started/installation","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/installation.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"installation","title":"Installation"},"sidebar":"version-27.0-docs","previous":{"title":"Contributing","permalink":"/ts-jest/docs/27.0/contributing"},"next":{"title":"Presets","permalink":"/ts-jest/docs/27.0/getting-started/presets"}}');var i=n(4848),o=n(8453);const l={id:"installation",title:"Installation"},r=void 0,c={},d=[{value:"Dependencies",id:"dependencies",level:3},{value:"NPM",id:"npm",level:4},{value:"Yarn",id:"yarn",level:4},{value:"Jest config file",id:"jest-config-file",level:3},{value:"Creating",id:"creating",level:4},{value:"NPM",id:"npm-1",level:4},{value:"Yarn",id:"yarn-1",level:4},{value:"Customizing",id:"customizing",level:4}];function a(e){const t={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,i.jsxs)(t.p,{children:["You can install ",(0,i.jsx)(t.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,i.jsx)(t.h4,{id:"npm",children:"NPM"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(t.h4,{id:"yarn",children:"Yarn"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(t.admonition,{type:"tip",children:(0,i.jsxs)(t.p,{children:["Tip: If you get an error with the following ",(0,i.jsx)(t.code,{children:"npm"})," commands such as ",(0,i.jsx)(t.code,{children:"npx: command not found"}),", you can replace ",(0,i.jsx)(t.code,{children:"npx XXX"})," with ",(0,i.jsx)(t.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,i.jsx)(t.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,i.jsx)(t.h4,{id:"creating",children:"Creating"}),"\n",(0,i.jsxs)(t.p,{children:["By default, Jest can run without any config files, but it will not compile ",(0,i.jsx)(t.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,i.jsx)(t.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,i.jsx)(t.code,{children:"ts-jest"})," preset."]}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,i.jsx)(t.h4,{id:"npm-1",children:"NPM"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"npx ts-jest config:init\n"})}),"\n",(0,i.jsx)(t.h4,{id:"yarn-1",children:"Yarn"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"yarn ts-jest config:init\n"})}),"\n",(0,i.jsxs)(t.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,i.jsx)(t.code,{children:".ts"})," files correctly."]}),"\n",(0,i.jsxs)(t.p,{children:["You can also use the ",(0,i.jsx)(t.code,{children:"jest --init"})," command (prefixed with either ",(0,i.jsx)(t.code,{children:"npx"})," or ",(0,i.jsx)(t.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,i.jsx)(t.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,i.jsx)(t.code,{children:'preset: "ts-jest"'})," to the ",(0,i.jsx)(t.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,i.jsx)(t.h4,{id:"customizing",children:"Customizing"}),"\n",(0,i.jsxs)(t.p,{children:["For customizing jest, please follow their ",(0,i.jsx)(t.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"ts-jest"})," specific options can be found ",(0,i.jsx)(t.a,{href:"/ts-jest/docs/27.0/getting-started/options",children:"here"}),"."]})]})}function h(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(a,{...e})}):a(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>l,x:()=>r});var s=n(6540);const i={},o=s.createContext(i);function l(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:l(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4519],{5885:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>l,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/installation","title":"Installation","description":"Dependencies","source":"@site/versioned_docs/version-27.0/getting-started/installation.md","sourceDirName":"getting-started","slug":"/getting-started/installation","permalink":"/ts-jest/docs/27.0/getting-started/installation","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/installation.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"installation","title":"Installation"},"sidebar":"version-27.0-docs","previous":{"title":"Contributing","permalink":"/ts-jest/docs/27.0/contributing"},"next":{"title":"Presets","permalink":"/ts-jest/docs/27.0/getting-started/presets"}}');var i=n(4848),o=n(8453);const l={id:"installation",title:"Installation"},r=void 0,c={},d=[{value:"Dependencies",id:"dependencies",level:3},{value:"NPM",id:"npm",level:4},{value:"Yarn",id:"yarn",level:4},{value:"Jest config file",id:"jest-config-file",level:3},{value:"Creating",id:"creating",level:4},{value:"NPM",id:"npm-1",level:4},{value:"Yarn",id:"yarn-1",level:4},{value:"Customizing",id:"customizing",level:4}];function a(e){const t={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,i.jsxs)(t.p,{children:["You can install ",(0,i.jsx)(t.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,i.jsx)(t.h4,{id:"npm",children:"NPM"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(t.h4,{id:"yarn",children:"Yarn"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(t.admonition,{type:"tip",children:(0,i.jsxs)(t.p,{children:["Tip: If you get an error with the following ",(0,i.jsx)(t.code,{children:"npm"})," commands such as ",(0,i.jsx)(t.code,{children:"npx: command not found"}),", you can replace ",(0,i.jsx)(t.code,{children:"npx XXX"})," with ",(0,i.jsx)(t.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,i.jsx)(t.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,i.jsx)(t.h4,{id:"creating",children:"Creating"}),"\n",(0,i.jsxs)(t.p,{children:["By default, Jest can run without any config files, but it will not compile ",(0,i.jsx)(t.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,i.jsx)(t.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,i.jsx)(t.code,{children:"ts-jest"})," preset."]}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,i.jsx)(t.h4,{id:"npm-1",children:"NPM"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"npx ts-jest config:init\n"})}),"\n",(0,i.jsx)(t.h4,{id:"yarn-1",children:"Yarn"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"yarn ts-jest config:init\n"})}),"\n",(0,i.jsxs)(t.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,i.jsx)(t.code,{children:".ts"})," files correctly."]}),"\n",(0,i.jsxs)(t.p,{children:["You can also use the ",(0,i.jsx)(t.code,{children:"jest --init"})," command (prefixed with either ",(0,i.jsx)(t.code,{children:"npx"})," or ",(0,i.jsx)(t.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,i.jsx)(t.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,i.jsx)(t.code,{children:'preset: "ts-jest"'})," to the ",(0,i.jsx)(t.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,i.jsx)(t.h4,{id:"customizing",children:"Customizing"}),"\n",(0,i.jsxs)(t.p,{children:["For customizing jest, please follow their ",(0,i.jsx)(t.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"ts-jest"})," specific options can be found ",(0,i.jsx)(t.a,{href:"/ts-jest/docs/27.0/getting-started/options",children:"here"}),"."]})]})}function h(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(a,{...e})}):a(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>l,x:()=>r});var s=n(6540);const i={},o=s.createContext(i);function l(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:l(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/2b77ff19.ff8f122b.js b/assets/js/2b77ff19.7d69ff37.js similarity index 99% rename from assets/js/2b77ff19.ff8f122b.js rename to assets/js/2b77ff19.7d69ff37.js index 099c048bcb..e2f3b3a715 100644 --- a/assets/js/2b77ff19.ff8f122b.js +++ b/assets/js/2b77ff19.7d69ff37.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3951],{789:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>d,contentTitle:()=>l,default:()=>u,frontMatter:()=>r,metadata:()=>t,toc:()=>a});const t=JSON.parse('{"id":"guides/troubleshooting","title":"Troubleshooting","description":"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them.","source":"@site/versioned_docs/version-29.2/guides/troubleshooting.md","sourceDirName":"guides","slug":"/guides/troubleshooting","permalink":"/ts-jest/docs/guides/troubleshooting","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/guides/troubleshooting.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"troubleshooting","title":"Troubleshooting"},"sidebar":"version-29.1-docs","previous":{"title":"Using with React Native","permalink":"/ts-jest/docs/guides/react-native"},"next":{"title":"Using with monorepo","permalink":"/ts-jest/docs/guides/using-with-monorepo"}}');var o=n(4848),i=n(8453);const r={id:"troubleshooting",title:"Troubleshooting"},l=void 0,d={},a=[{value:"Running ts-jest on CI tools",id:"running-ts-jest-on-ci-tools",level:2},{value:"PROBLEM",id:"problem",level:3},{value:"SOLUTION",id:"solution",level:3},{value:"Transform (node)-module explicitly",id:"transform-node-module-explicitly",level:2},{value:"PROBLEM",id:"problem-1",level:3},{value:"SOLUTION",id:"solution-1",level:3},{value:"Tests gets stuck when importing a dependency",id:"tests-gets-stuck-when-importing-a-dependency",level:2},{value:"PROBLEM",id:"problem-2",level:3},{value:"SOLUTION",id:"solution-2",level:3}];function c(e){const s={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(s.p,{children:"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them."}),"\n",(0,o.jsxs)(s.p,{children:["Please also check Jest ",(0,o.jsx)(s.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," if your issue is related to jest."]}),"\n",(0,o.jsx)(s.h2,{id:"running-ts-jest-on-ci-tools",children:"Running ts-jest on CI tools"}),"\n",(0,o.jsx)(s.h3,{id:"problem",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:'Cannot find module "" from ""'}),"\n",(0,o.jsx)(s.h3,{id:"solution",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check if ",(0,o.jsx)(s.code,{children:"rootDir"})," is referenced correctly. If not add this on your existing jest configuration."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n roots: [""]\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module directories are included on your jest configuration. If not add this on your existing jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleDirectories: ["node_modules",""],\n modulePaths: [""],\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module name is properly mapped and can be referenced by jest. If not, you can define moduleNameMapper for your jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleNameMapper: {\n "": "/",\n },\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check github folder names if its identical to you local folder names. Sometimes github never updates your folder names even if you rename it locally. If this happens rename your folders via github or use this command ",(0,o.jsx)(s.code,{children:"git mv "})," and commit changes."]}),"\n"]}),"\n",(0,o.jsx)(s.h2,{id:"transform-node-module-explicitly",children:"Transform (node)-module explicitly"}),"\n",(0,o.jsx)(s.h3,{id:"problem-1",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"SyntaxError: Cannot use import statement outside a module"}),"\n",(0,o.jsx)(s.h3,{id:"solution-1",children:"SOLUTION"}),"\n",(0,o.jsx)(s.p,{children:"One of the node modules hasn't the correct syntax for Jests execution step. It needs to\nbe transformed first."}),"\n",(0,o.jsx)(s.p,{children:"There is a good chance that the error message shows which module is affected:"}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-shell",children:' SyntaxError: Cannot use import statement outside a module\n > 22 | import Component from "../../node_modules/some-module/lib";\n | ^\n'})}),"\n",(0,o.jsxs)(s.p,{children:["In this case ",(0,o.jsx)(s.strong,{children:"some-module"})," is the problem and needs to be transformed.\nBy adding the following line to the configuration file it will tell Jest which modules\nshouldnt be ignored during the transformation step:"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n transformIgnorePatterns: ["node_modules/(?!(some-module|another-module))"]\n};\n'})}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.strong,{children:"some-module"})," and ",(0,o.jsx)(s.strong,{children:"another-module"})," will be transformed."]}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/63389757/jest-unit-test-syntaxerror-cannot-use-import-statement-outside-a-module",children:"here"})," and ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/52035066/how-to-write-jest-transformignorepatterns",children:"here"}),"."]}),"\n",(0,o.jsx)(s.h2,{id:"tests-gets-stuck-when-importing-a-dependency",children:"Tests gets stuck when importing a dependency"}),"\n",(0,o.jsx)(s.h3,{id:"problem-2",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"Without cache, jest takes an extremely long time to process files and appears to be stuck."}),"\n",(0,o.jsx)(s.h3,{id:"solution-2",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.code,{children:"ts-jest"})," internally uses TypeScript compiler API to transform ts/js file into js file. The recommendation is to only transform what is needed."]}),"\n",(0,o.jsxs)(s.p,{children:["A possible cause for that issue is that you may have enabled ",(0,o.jsx)(s.code,{children:"ts-jest"})," to process javascript files in addition to TypeScript files. This leads to the result that more files are loaded which can, in some cases, blow up the machine."]}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your tsconfig file, check if ",(0,o.jsx)(s.code,{children:"compilerOptions.allowJs"})," is unset or set to false."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'{\n "compilerOptions": {\n "allowJs": false,\n }\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your jest configuration, check if the transform property includes only ",(0,o.jsx)(s.code,{children:".ts"})," files for ts-jest. If not, change the regular expression to exclude js files. You can also add the attribute ",(0,o.jsx)(s.code,{children:"isolatedModules: true"})," for ts-jest to disable type checking for tests."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-diff",children:"module.exports = {\n ...\n 'transform': {\n- '^.+\\\\.(t|j)s$': ['ts-jest', {}],\n+ '^.+\\\\.ts$': ['ts-jest', { isolatedModules: true }],\n },\n};\n"})}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://github.com/kulshekhar/ts-jest/issues/4294",children:"here"})]})]})}function u(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,o.jsx)(s,{...e,children:(0,o.jsx)(c,{...e})}):c(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>r,x:()=>l});var t=n(6540);const o={},i=t.createContext(o);function r(e){const s=t.useContext(i);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function l(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),t.createElement(i.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3951],{789:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>d,contentTitle:()=>l,default:()=>u,frontMatter:()=>r,metadata:()=>t,toc:()=>a});const t=JSON.parse('{"id":"guides/troubleshooting","title":"Troubleshooting","description":"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them.","source":"@site/versioned_docs/version-29.2/guides/troubleshooting.md","sourceDirName":"guides","slug":"/guides/troubleshooting","permalink":"/ts-jest/docs/guides/troubleshooting","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/guides/troubleshooting.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"troubleshooting","title":"Troubleshooting"},"sidebar":"version-29.1-docs","previous":{"title":"Using with React Native","permalink":"/ts-jest/docs/guides/react-native"},"next":{"title":"Using with monorepo","permalink":"/ts-jest/docs/guides/using-with-monorepo"}}');var o=n(4848),i=n(8453);const r={id:"troubleshooting",title:"Troubleshooting"},l=void 0,d={},a=[{value:"Running ts-jest on CI tools",id:"running-ts-jest-on-ci-tools",level:2},{value:"PROBLEM",id:"problem",level:3},{value:"SOLUTION",id:"solution",level:3},{value:"Transform (node)-module explicitly",id:"transform-node-module-explicitly",level:2},{value:"PROBLEM",id:"problem-1",level:3},{value:"SOLUTION",id:"solution-1",level:3},{value:"Tests gets stuck when importing a dependency",id:"tests-gets-stuck-when-importing-a-dependency",level:2},{value:"PROBLEM",id:"problem-2",level:3},{value:"SOLUTION",id:"solution-2",level:3}];function c(e){const s={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(s.p,{children:"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them."}),"\n",(0,o.jsxs)(s.p,{children:["Please also check Jest ",(0,o.jsx)(s.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," if your issue is related to jest."]}),"\n",(0,o.jsx)(s.h2,{id:"running-ts-jest-on-ci-tools",children:"Running ts-jest on CI tools"}),"\n",(0,o.jsx)(s.h3,{id:"problem",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:'Cannot find module "" from ""'}),"\n",(0,o.jsx)(s.h3,{id:"solution",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check if ",(0,o.jsx)(s.code,{children:"rootDir"})," is referenced correctly. If not add this on your existing jest configuration."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n roots: [""]\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module directories are included on your jest configuration. If not add this on your existing jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleDirectories: ["node_modules",""],\n modulePaths: [""],\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module name is properly mapped and can be referenced by jest. If not, you can define moduleNameMapper for your jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleNameMapper: {\n "": "/",\n },\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check github folder names if its identical to you local folder names. Sometimes github never updates your folder names even if you rename it locally. If this happens rename your folders via github or use this command ",(0,o.jsx)(s.code,{children:"git mv "})," and commit changes."]}),"\n"]}),"\n",(0,o.jsx)(s.h2,{id:"transform-node-module-explicitly",children:"Transform (node)-module explicitly"}),"\n",(0,o.jsx)(s.h3,{id:"problem-1",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"SyntaxError: Cannot use import statement outside a module"}),"\n",(0,o.jsx)(s.h3,{id:"solution-1",children:"SOLUTION"}),"\n",(0,o.jsx)(s.p,{children:"One of the node modules hasn't the correct syntax for Jests execution step. It needs to\nbe transformed first."}),"\n",(0,o.jsx)(s.p,{children:"There is a good chance that the error message shows which module is affected:"}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-shell",children:' SyntaxError: Cannot use import statement outside a module\n > 22 | import Component from "../../node_modules/some-module/lib";\n | ^\n'})}),"\n",(0,o.jsxs)(s.p,{children:["In this case ",(0,o.jsx)(s.strong,{children:"some-module"})," is the problem and needs to be transformed.\nBy adding the following line to the configuration file it will tell Jest which modules\nshouldnt be ignored during the transformation step:"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n transformIgnorePatterns: ["node_modules/(?!(some-module|another-module))"]\n};\n'})}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.strong,{children:"some-module"})," and ",(0,o.jsx)(s.strong,{children:"another-module"})," will be transformed."]}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/63389757/jest-unit-test-syntaxerror-cannot-use-import-statement-outside-a-module",children:"here"})," and ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/52035066/how-to-write-jest-transformignorepatterns",children:"here"}),"."]}),"\n",(0,o.jsx)(s.h2,{id:"tests-gets-stuck-when-importing-a-dependency",children:"Tests gets stuck when importing a dependency"}),"\n",(0,o.jsx)(s.h3,{id:"problem-2",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"Without cache, jest takes an extremely long time to process files and appears to be stuck."}),"\n",(0,o.jsx)(s.h3,{id:"solution-2",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.code,{children:"ts-jest"})," internally uses TypeScript compiler API to transform ts/js file into js file. The recommendation is to only transform what is needed."]}),"\n",(0,o.jsxs)(s.p,{children:["A possible cause for that issue is that you may have enabled ",(0,o.jsx)(s.code,{children:"ts-jest"})," to process javascript files in addition to TypeScript files. This leads to the result that more files are loaded which can, in some cases, blow up the machine."]}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your tsconfig file, check if ",(0,o.jsx)(s.code,{children:"compilerOptions.allowJs"})," is unset or set to false."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'{\n "compilerOptions": {\n "allowJs": false,\n }\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your jest configuration, check if the transform property includes only ",(0,o.jsx)(s.code,{children:".ts"})," files for ts-jest. If not, change the regular expression to exclude js files. You can also add the attribute ",(0,o.jsx)(s.code,{children:"isolatedModules: true"})," for ts-jest to disable type checking for tests."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-diff",children:"module.exports = {\n ...\n 'transform': {\n- '^.+\\\\.(t|j)s$': ['ts-jest', {}],\n+ '^.+\\\\.ts$': ['ts-jest', { isolatedModules: true }],\n },\n};\n"})}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://github.com/kulshekhar/ts-jest/issues/4294",children:"here"})]})]})}function u(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,o.jsx)(s,{...e,children:(0,o.jsx)(c,{...e})}):c(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>r,x:()=>l});var t=n(6540);const o={},i=t.createContext(o);function r(e){const s=t.useContext(i);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function l(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),t.createElement(i.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/2b94ed59.d675dd5a.js b/assets/js/2b94ed59.5d2ddf62.js similarity index 97% rename from assets/js/2b94ed59.d675dd5a.js rename to assets/js/2b94ed59.5d2ddf62.js index 23eeae12d7..7848b73811 100644 --- a/assets/js/2b94ed59.d675dd5a.js +++ b/assets/js/2b94ed59.5d2ddf62.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6797],{3077:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>c,contentTitle:()=>l,default:()=>a,frontMatter:()=>r,metadata:()=>n,toc:()=>p});const n=JSON.parse('{"id":"getting-started/options/compiler","title":"Compiler option","description":"The compiler option allows you to define the compiler to be used. It\'ll be used to load the NodeJS module holding the TypeScript compiler.","source":"@site/versioned_docs/version-26.5/getting-started/options/compiler.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/compiler","permalink":"/ts-jest/docs/26.5/getting-started/options/compiler","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/getting-started/options/compiler.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Compiler option"}}');var s=o(4848),i=o(8453);const r={title:"Compiler option"},l=void 0,c={},p=[{value:"Example",id:"example",level:3}];function d(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["The ",(0,s.jsx)(t.code,{children:"compiler"})," option allows you to define the compiler to be used. It'll be used to load the NodeJS module holding the TypeScript compiler."]}),"\n",(0,s.jsxs)(t.p,{children:["The default value is ",(0,s.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,s.jsx)(t.a,{href:"https://www.npmjs.com/package/typescript",children:"TypeScript compiler module"}),".\nThe loaded version will depend on the one installed in your project."]}),"\n",(0,s.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,s.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,s.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n compiler: 'ttypescript',\n },\n },\n}\n"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "compiler": "ttypescript"\n }\n }\n }\n}\n'})})]})}function a(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}},8453:(e,t,o)=>{o.d(t,{R:()=>r,x:()=>l});var n=o(6540);const s={},i=n.createContext(s);function r(e){const t=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:r(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6797],{3077:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>c,contentTitle:()=>l,default:()=>a,frontMatter:()=>r,metadata:()=>n,toc:()=>p});const n=JSON.parse('{"id":"getting-started/options/compiler","title":"Compiler option","description":"The compiler option allows you to define the compiler to be used. It\'ll be used to load the NodeJS module holding the TypeScript compiler.","source":"@site/versioned_docs/version-26.5/getting-started/options/compiler.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/compiler","permalink":"/ts-jest/docs/26.5/getting-started/options/compiler","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/getting-started/options/compiler.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Compiler option"}}');var s=o(4848),i=o(8453);const r={title:"Compiler option"},l=void 0,c={},p=[{value:"Example",id:"example",level:3}];function d(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["The ",(0,s.jsx)(t.code,{children:"compiler"})," option allows you to define the compiler to be used. It'll be used to load the NodeJS module holding the TypeScript compiler."]}),"\n",(0,s.jsxs)(t.p,{children:["The default value is ",(0,s.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,s.jsx)(t.a,{href:"https://www.npmjs.com/package/typescript",children:"TypeScript compiler module"}),".\nThe loaded version will depend on the one installed in your project."]}),"\n",(0,s.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,s.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,s.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n compiler: 'ttypescript',\n },\n },\n}\n"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "compiler": "ttypescript"\n }\n }\n }\n}\n'})})]})}function a(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}},8453:(e,t,o)=>{o.d(t,{R:()=>r,x:()=>l});var n=o(6540);const s={},i=n.createContext(s);function r(e){const t=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:r(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/2bccb399.51fe225e.js b/assets/js/2bccb399.5edbe13a.js similarity index 99% rename from assets/js/2bccb399.51fe225e.js rename to assets/js/2bccb399.5edbe13a.js index 32a182deb5..619bdb31f7 100644 --- a/assets/js/2bccb399.51fe225e.js +++ b/assets/js/2bccb399.5edbe13a.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5154],{8010:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>h,frontMatter:()=>u,metadata:()=>r,toc:()=>d});const r=JSON.parse('{"id":"debugging","title":"Debugging ts-jest","description":"You can activate the debug logger by setting the environment variable TSJESTLOG before running tests.","source":"@site/docs/debugging.md","sourceDirName":".","slug":"/debugging","permalink":"/ts-jest/docs/next/debugging","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/debugging.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"debugging","title":"Debugging ts-jest"},"sidebar":"docs","previous":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/next/migration"}}');var a=n(4848),s=n(8453),o=n(9489),l=n(7227);const u={id:"debugging",title:"Debugging ts-jest"},i=void 0,c={},d=[];function g(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,s.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(t.p,{children:["You can activate the debug logger by setting the environment variable ",(0,a.jsx)(t.code,{children:"TS_JEST_LOG"})," before running tests.\nThe output of the logger will be in ",(0,a.jsx)(t.strong,{children:"ts-jest.log"})," in current working directory."]}),"\n",(0,a.jsxs)(t.p,{children:["The debug logger contains some useful information about how internal ",(0,a.jsx)(t.code,{children:"ts-jest"})," works, including which files are processed,\nwhich Jest config or TypeScript config is used etc."]}),"\n",(0,a.jsx)(t.p,{children:(0,a.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{children:"export TS_JEST_LOG=ts-jest.log\n"})}),"\n",(0,a.jsx)(t.p,{children:(0,a.jsx)(t.strong,{children:"Windows"})}),"\n",(0,a.jsxs)(o.A,{groupId:"code-examples",children:[(0,a.jsx)(l.A,{value:"Command",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-Command",metastring:"Prompt tab",children:"set TS_JEST_LOG=ts-jest.log\n"})})}),(0,a.jsx)(l.A,{value:"PowerShell",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-PowerShell",metastring:"tab",children:"$env:TS_JEST_LOG = 'ts-jest.log'\n"})})})]})]})}function h(e={}){const{wrapper:t}={...(0,s.R)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(g,{...e})}):g(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var r=n(4164);const a={tabItem:"tabItem_Ymn6"};var s=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.A)(a.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>y});var r=n(6540),a=n(4164),s=n(4245),o=n(6347),l=n(6494),u=n(2814),i=n(5167),c=n(9900);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function g(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(n);return function(e){const t=(0,i.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function b(e){let{queryString:t=!1,groupId:n}=e;const a=(0,o.W6)(),s=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,u.aZ)(s),(0,r.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function p(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,s=g(e),[o,u]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!h({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:s}))),[i,d]=b({queryString:n,groupId:a}),[p,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,c.Dv)(n);return[a,(0,r.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),m=(()=>{const e=i??p;return h({value:e,tabValues:s})?e:null})();(0,l.A)((()=>{m&&u(m)}),[m]);return{selectedValue:o,selectValue:(0,r.useCallback)((e=>{if(!h({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);u(e),d(e),f(e)}),[d,f,s]),tabValues:s}}var f=n(1062);const m={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=n(4848);function j(e){let{className:t,block:n,selectedValue:r,selectValue:o,tabValues:l}=e;const u=[],{blockElementScrollPositionUntilNextRender:i}=(0,s.a_)(),c=e=>{const t=e.currentTarget,n=u.indexOf(t),a=l[n].value;a!==r&&(i(t),o(a))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=u.indexOf(e.currentTarget)+1;t=u[n]??u[0];break}case"ArrowLeft":{const n=u.indexOf(e.currentTarget)-1;t=u[n]??u[u.length-1];break}}t?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.A)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>u.push(e),onKeyDown:d,onClick:c,...s,className:(0,a.A)("tabs__item",m.tabItem,s?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:s}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===s));return e?(0,r.cloneElement)(e,{className:(0,a.A)("margin-top--md",e.props.className)}):null}return(0,v.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==s})))})}function w(e){const t=p(e);return(0,v.jsxs)("div",{className:(0,a.A)("tabs-container",m.tabList),children:[(0,v.jsx)(j,{...t,...e}),(0,v.jsx)(x,{...t,...e})]})}function y(e){const t=(0,f.A)();return(0,v.jsx)(w,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>l});var r=n(6540);const a={},s=r.createContext(a);function o(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5154],{8010:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>h,frontMatter:()=>u,metadata:()=>r,toc:()=>d});const r=JSON.parse('{"id":"debugging","title":"Debugging ts-jest","description":"You can activate the debug logger by setting the environment variable TSJESTLOG before running tests.","source":"@site/docs/debugging.md","sourceDirName":".","slug":"/debugging","permalink":"/ts-jest/docs/next/debugging","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/debugging.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"debugging","title":"Debugging ts-jest"},"sidebar":"docs","previous":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/next/migration"}}');var a=n(4848),s=n(8453),o=n(9489),l=n(7227);const u={id:"debugging",title:"Debugging ts-jest"},i=void 0,c={},d=[];function g(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,s.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(t.p,{children:["You can activate the debug logger by setting the environment variable ",(0,a.jsx)(t.code,{children:"TS_JEST_LOG"})," before running tests.\nThe output of the logger will be in ",(0,a.jsx)(t.strong,{children:"ts-jest.log"})," in current working directory."]}),"\n",(0,a.jsxs)(t.p,{children:["The debug logger contains some useful information about how internal ",(0,a.jsx)(t.code,{children:"ts-jest"})," works, including which files are processed,\nwhich Jest config or TypeScript config is used etc."]}),"\n",(0,a.jsx)(t.p,{children:(0,a.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{children:"export TS_JEST_LOG=ts-jest.log\n"})}),"\n",(0,a.jsx)(t.p,{children:(0,a.jsx)(t.strong,{children:"Windows"})}),"\n",(0,a.jsxs)(o.A,{groupId:"code-examples",children:[(0,a.jsx)(l.A,{value:"Command",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-Command",metastring:"Prompt tab",children:"set TS_JEST_LOG=ts-jest.log\n"})})}),(0,a.jsx)(l.A,{value:"PowerShell",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-PowerShell",metastring:"tab",children:"$env:TS_JEST_LOG = 'ts-jest.log'\n"})})})]})]})}function h(e={}){const{wrapper:t}={...(0,s.R)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(g,{...e})}):g(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var r=n(4164);const a={tabItem:"tabItem_Ymn6"};var s=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.A)(a.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>y});var r=n(6540),a=n(4164),s=n(4245),o=n(6347),l=n(6494),u=n(2814),i=n(5167),c=n(9900);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function g(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(n);return function(e){const t=(0,i.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function b(e){let{queryString:t=!1,groupId:n}=e;const a=(0,o.W6)(),s=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,u.aZ)(s),(0,r.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function p(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,s=g(e),[o,u]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!h({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:s}))),[i,d]=b({queryString:n,groupId:a}),[p,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,c.Dv)(n);return[a,(0,r.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),m=(()=>{const e=i??p;return h({value:e,tabValues:s})?e:null})();(0,l.A)((()=>{m&&u(m)}),[m]);return{selectedValue:o,selectValue:(0,r.useCallback)((e=>{if(!h({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);u(e),d(e),f(e)}),[d,f,s]),tabValues:s}}var f=n(1062);const m={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=n(4848);function j(e){let{className:t,block:n,selectedValue:r,selectValue:o,tabValues:l}=e;const u=[],{blockElementScrollPositionUntilNextRender:i}=(0,s.a_)(),c=e=>{const t=e.currentTarget,n=u.indexOf(t),a=l[n].value;a!==r&&(i(t),o(a))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=u.indexOf(e.currentTarget)+1;t=u[n]??u[0];break}case"ArrowLeft":{const n=u.indexOf(e.currentTarget)-1;t=u[n]??u[u.length-1];break}}t?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.A)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>u.push(e),onKeyDown:d,onClick:c,...s,className:(0,a.A)("tabs__item",m.tabItem,s?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:s}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===s));return e?(0,r.cloneElement)(e,{className:(0,a.A)("margin-top--md",e.props.className)}):null}return(0,v.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==s})))})}function w(e){const t=p(e);return(0,v.jsxs)("div",{className:(0,a.A)("tabs-container",m.tabList),children:[(0,v.jsx)(j,{...t,...e}),(0,v.jsx)(x,{...t,...e})]})}function y(e){const t=(0,f.A)();return(0,v.jsx)(w,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>l});var r=n(6540);const a={},s=r.createContext(a);function o(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/2c53b5e4.3589b250.js b/assets/js/2c53b5e4.e23fa1b0.js similarity index 98% rename from assets/js/2c53b5e4.3589b250.js rename to assets/js/2c53b5e4.e23fa1b0.js index 97529f738d..302839053d 100644 --- a/assets/js/2c53b5e4.3589b250.js +++ b/assets/js/2c53b5e4.e23fa1b0.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8282],{7033:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>d,default:()=>p,frontMatter:()=>r,metadata:()=>o,toc:()=>l});const o=JSON.parse('{"id":"guides/test-helpers","title":"Test helpers","description":"ts-jest provides some test utilities to be used in your test, related to TypeScript.","source":"@site/versioned_docs/version-27.0/guides/test-helpers.md","sourceDirName":"guides","slug":"/guides/test-helpers","permalink":"/ts-jest/docs/27.0/guides/test-helpers","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/guides/test-helpers.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"test-helpers","title":"Test helpers"},"sidebar":"version-27.0-docs","previous":{"title":"Using with React Native","permalink":"/ts-jest/docs/27.0/guides/react-native"},"next":{"title":"Troubleshooting","permalink":"/ts-jest/docs/27.0/guides/troubleshooting"}}');var n=s(4848),i=s(8453);const r={id:"test-helpers",title:"Test helpers"},d=void 0,c={},l=[{value:"mocked<T>(item: T, deep = false)",id:"mockedtitem-t-deep--false",level:2},{value:"Example",id:"example",level:3}];function a(e){const t={code:"code",h2:"h2",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:[(0,n.jsx)(t.code,{children:"ts-jest"})," provides some test utilities to be used in your test, related to TypeScript."]}),"\n",(0,n.jsx)(t.h2,{id:"mockedtitem-t-deep--false",children:(0,n.jsx)(t.code,{children:"mocked(item: T, deep = false)"})}),"\n",(0,n.jsxs)(t.p,{children:["The ",(0,n.jsx)(t.code,{children:"mocked"})," test helper provides typings on your mocked modules and even their deep methods, based on the typing of its source. It makes use of the latest TypeScript feature, so you even have argument types completion in the IDE (as opposed to ",(0,n.jsx)(t.code,{children:"jest.MockInstance"}),")."]}),"\n",(0,n.jsxs)(t.p,{children:[(0,n.jsx)(t.strong,{children:"Note:"})," while it needs to be a function so that input type is changed, the helper itself does nothing else than returning the given input value."]}),"\n",(0,n.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-ts",children:"// foo.ts\nexport const foo = {\n a: {\n b: {\n c: {\n hello: (name: string) => `Hello, ${name}`,\n },\n },\n },\n name: () => 'foo',\n}\n"})}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-ts",children:"// foo.spec.ts\nimport { mocked } from 'ts-jest/utils'\nimport { foo } from './foo'\njest.mock('./foo')\n\n// here the whole foo var is mocked deeply\nconst mockedFoo = mocked(foo, true)\n\ntest('deep', () => {\n // there will be no TS error here, and you'll have completion in modern IDEs\n mockedFoo.a.b.c.hello('me')\n // same here\n expect(mockedFoo.a.b.c.hello.mock.calls).toHaveLength(1)\n})\n\ntest('direct', () => {\n foo.name()\n // here only foo.name is mocked (or its methods if it's an object)\n expect(mocked(foo.name).mock.calls).toHaveLength(1)\n})\n"})})]})}function p(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(a,{...e})}):a(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>r,x:()=>d});var o=s(6540);const n={},i=o.createContext(n);function r(e){const t=o.useContext(i);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function d(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:r(e.components),o.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8282],{7033:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>d,default:()=>p,frontMatter:()=>r,metadata:()=>o,toc:()=>l});const o=JSON.parse('{"id":"guides/test-helpers","title":"Test helpers","description":"ts-jest provides some test utilities to be used in your test, related to TypeScript.","source":"@site/versioned_docs/version-27.0/guides/test-helpers.md","sourceDirName":"guides","slug":"/guides/test-helpers","permalink":"/ts-jest/docs/27.0/guides/test-helpers","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/guides/test-helpers.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"test-helpers","title":"Test helpers"},"sidebar":"version-27.0-docs","previous":{"title":"Using with React Native","permalink":"/ts-jest/docs/27.0/guides/react-native"},"next":{"title":"Troubleshooting","permalink":"/ts-jest/docs/27.0/guides/troubleshooting"}}');var n=s(4848),i=s(8453);const r={id:"test-helpers",title:"Test helpers"},d=void 0,c={},l=[{value:"mocked<T>(item: T, deep = false)",id:"mockedtitem-t-deep--false",level:2},{value:"Example",id:"example",level:3}];function a(e){const t={code:"code",h2:"h2",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:[(0,n.jsx)(t.code,{children:"ts-jest"})," provides some test utilities to be used in your test, related to TypeScript."]}),"\n",(0,n.jsx)(t.h2,{id:"mockedtitem-t-deep--false",children:(0,n.jsx)(t.code,{children:"mocked(item: T, deep = false)"})}),"\n",(0,n.jsxs)(t.p,{children:["The ",(0,n.jsx)(t.code,{children:"mocked"})," test helper provides typings on your mocked modules and even their deep methods, based on the typing of its source. It makes use of the latest TypeScript feature, so you even have argument types completion in the IDE (as opposed to ",(0,n.jsx)(t.code,{children:"jest.MockInstance"}),")."]}),"\n",(0,n.jsxs)(t.p,{children:[(0,n.jsx)(t.strong,{children:"Note:"})," while it needs to be a function so that input type is changed, the helper itself does nothing else than returning the given input value."]}),"\n",(0,n.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-ts",children:"// foo.ts\nexport const foo = {\n a: {\n b: {\n c: {\n hello: (name: string) => `Hello, ${name}`,\n },\n },\n },\n name: () => 'foo',\n}\n"})}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-ts",children:"// foo.spec.ts\nimport { mocked } from 'ts-jest/utils'\nimport { foo } from './foo'\njest.mock('./foo')\n\n// here the whole foo var is mocked deeply\nconst mockedFoo = mocked(foo, true)\n\ntest('deep', () => {\n // there will be no TS error here, and you'll have completion in modern IDEs\n mockedFoo.a.b.c.hello('me')\n // same here\n expect(mockedFoo.a.b.c.hello.mock.calls).toHaveLength(1)\n})\n\ntest('direct', () => {\n foo.name()\n // here only foo.name is mocked (or its methods if it's an object)\n expect(mocked(foo.name).mock.calls).toHaveLength(1)\n})\n"})})]})}function p(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(a,{...e})}):a(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>r,x:()=>d});var o=s(6540);const n={},i=o.createContext(n);function r(e){const t=o.useContext(i);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function d(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:r(e.components),o.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/2d143bed.70765e71.js b/assets/js/2d143bed.a8f1abb0.js similarity index 98% rename from assets/js/2d143bed.70765e71.js rename to assets/js/2d143bed.a8f1abb0.js index 13814bc062..74b650895c 100644 --- a/assets/js/2d143bed.70765e71.js +++ b/assets/js/2d143bed.a8f1abb0.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1154],{1953:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>r,metadata:()=>s,toc:()=>l});const s=JSON.parse('{"id":"babel7-or-ts","title":"Babel7 or TypeScript","description":"In Sept. 2018 Babel7 got released with an interesting preset: @babel/preset-typescript.","source":"@site/versioned_docs/version-29.2/babel7-or-ts.md","sourceDirName":".","slug":"/babel7-or-ts","permalink":"/ts-jest/docs/babel7-or-ts","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/babel7-or-ts.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"babel7-or-ts","title":"Babel7 or TypeScript"},"sidebar":"version-29.1-docs","previous":{"title":"Using with monorepo","permalink":"/ts-jest/docs/guides/using-with-monorepo"},"next":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/migration"}}');var i=n(4848),o=n(8453);const r={id:"babel7-or-ts",title:"Babel7 or TypeScript"},c=void 0,a={},l=[{value:"Limitations",id:"limitations",level:2},{value:"No type-checking",id:"no-type-checking",level:4},{value:"No namespace",id:"no-namespace",level:4},{value:"No const enum",id:"no-const-enum",level:4},{value:"No declaration merging (enum, namespace, ...)",id:"no-declaration-merging-enum-namespace-",level:4},{value:"No legacy import/export",id:"no-legacy-importexport",level:4},{value:"No caret type-casting with JSX enabled",id:"no-caret-type-casting-with-jsx-enabled",level:4}];function d(e){const t={a:"a",code:"code",h2:"h2",h4:"h4",hr:"hr",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,i.jsxs)(t.p,{children:["The goal is to make it easy for users using Babel to try TypeScript without moving out from Babel, just by adding a preset in their Babel config (here is the ",(0,i.jsx)(t.a,{href:"https://blogs.msdn.microsoft.com/typescript/2018/08/27/typescript-and-babel-7/",children:"MSDN blog post"})," about TypeScript and Babel 7)."]}),"\n",(0,i.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,i.jsxs)(t.p,{children:["While ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"})," is a great preset, you must know the limitation of it. Here is what is possible with TypeScript (and ",(0,i.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,i.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,i.jsxs)(t.p,{children:["This is the big ",(0,i.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,i.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,i.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,i.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,i.jsx)(t.p,{children:'With Babel, files are transpiled as isolated modules, there is no notion of "project". With TypeScript, files are part of a project and are compiled in that scope.'}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,i.jsx)(t.code,{children:"namespace"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"namespace app {\n export const VERSION = '1.0.0'\n export class App {\n /* ... */\n }\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,i.jsx)(t.code,{children:"const enum"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,i.jsx)(t.code,{children:"enum"}),", ",(0,i.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,i.jsxs)(t.p,{children:["You won't be able to do ",(0,i.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,i.jsx)(t.code,{children:"import"}),"/",(0,i.jsx)(t.code,{children:"export"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>c});var s=n(6540);const i={},o=s.createContext(i);function r(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1154],{1953:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>r,metadata:()=>s,toc:()=>l});const s=JSON.parse('{"id":"babel7-or-ts","title":"Babel7 or TypeScript","description":"In Sept. 2018 Babel7 got released with an interesting preset: @babel/preset-typescript.","source":"@site/versioned_docs/version-29.2/babel7-or-ts.md","sourceDirName":".","slug":"/babel7-or-ts","permalink":"/ts-jest/docs/babel7-or-ts","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/babel7-or-ts.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"babel7-or-ts","title":"Babel7 or TypeScript"},"sidebar":"version-29.1-docs","previous":{"title":"Using with monorepo","permalink":"/ts-jest/docs/guides/using-with-monorepo"},"next":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/migration"}}');var i=n(4848),o=n(8453);const r={id:"babel7-or-ts",title:"Babel7 or TypeScript"},c=void 0,a={},l=[{value:"Limitations",id:"limitations",level:2},{value:"No type-checking",id:"no-type-checking",level:4},{value:"No namespace",id:"no-namespace",level:4},{value:"No const enum",id:"no-const-enum",level:4},{value:"No declaration merging (enum, namespace, ...)",id:"no-declaration-merging-enum-namespace-",level:4},{value:"No legacy import/export",id:"no-legacy-importexport",level:4},{value:"No caret type-casting with JSX enabled",id:"no-caret-type-casting-with-jsx-enabled",level:4}];function d(e){const t={a:"a",code:"code",h2:"h2",h4:"h4",hr:"hr",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,i.jsxs)(t.p,{children:["The goal is to make it easy for users using Babel to try TypeScript without moving out from Babel, just by adding a preset in their Babel config (here is the ",(0,i.jsx)(t.a,{href:"https://blogs.msdn.microsoft.com/typescript/2018/08/27/typescript-and-babel-7/",children:"MSDN blog post"})," about TypeScript and Babel 7)."]}),"\n",(0,i.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,i.jsxs)(t.p,{children:["While ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"})," is a great preset, you must know the limitation of it. Here is what is possible with TypeScript (and ",(0,i.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,i.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,i.jsxs)(t.p,{children:["This is the big ",(0,i.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,i.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,i.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,i.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,i.jsx)(t.p,{children:'With Babel, files are transpiled as isolated modules, there is no notion of "project". With TypeScript, files are part of a project and are compiled in that scope.'}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,i.jsx)(t.code,{children:"namespace"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"namespace app {\n export const VERSION = '1.0.0'\n export class App {\n /* ... */\n }\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,i.jsx)(t.code,{children:"const enum"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,i.jsx)(t.code,{children:"enum"}),", ",(0,i.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,i.jsxs)(t.p,{children:["You won't be able to do ",(0,i.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,i.jsx)(t.code,{children:"import"}),"/",(0,i.jsx)(t.code,{children:"export"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>c});var s=n(6540);const i={},o=s.createContext(i);function r(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/2e89f3c4.6f967198.js b/assets/js/2e89f3c4.01abed72.js similarity index 98% rename from assets/js/2e89f3c4.6f967198.js rename to assets/js/2e89f3c4.01abed72.js index c03244fea6..de69c34f75 100644 --- a/assets/js/2e89f3c4.6f967198.js +++ b/assets/js/2e89f3c4.01abed72.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4937],{7383:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>h,frontMatter:()=>l,metadata:()=>n,toc:()=>c});const n=JSON.parse('{"id":"getting-started/options/isolatedModules","title":"Isolated Modules option","description":"By default ts-jest uses TypeScript compiler in the context of a project (yours), with full type-checking and features.","source":"@site/versioned_docs/version-28.0/getting-started/options/isolatedModules.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/isolatedModules","permalink":"/ts-jest/docs/28.0/getting-started/options/isolatedModules","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/options/isolatedModules.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Isolated Modules option"}}');var o=s(4848),i=s(8453);const l={title:"Isolated Modules option"},a=void 0,d={},c=[{value:"Example",id:"example",level:3},{value:"Performance",id:"performance",level:2},{value:"Example",id:"example-1",level:3},{value:"Caveats",id:"caveats",level:2}];function r(e){const t={code:"code",h2:"h2",h3:"h3",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["By default ",(0,o.jsx)(t.code,{children:"ts-jest"})," uses TypeScript compiler in the context of a project (yours), with full type-checking and features.\nBut it can also be used to compile each file separately, what TypeScript calls an 'isolated module'.\nThat's what the ",(0,o.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,o.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,o.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,o.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,o.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,o.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n isolatedModules: true,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "isolatedModules": true\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,o.jsxs)(t.p,{children:["Using ",(0,o.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,o.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,o.jsx)(t.code,{children:"include"})," in ",(0,o.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,o.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,o.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,o.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,o.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,o.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,o.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,o.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,o.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,o.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,o.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function h(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(r,{...e})}):r(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>l,x:()=>a});var n=s(6540);const o={},i=n.createContext(o);function l(e){const t=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:l(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4937],{7383:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>h,frontMatter:()=>l,metadata:()=>n,toc:()=>c});const n=JSON.parse('{"id":"getting-started/options/isolatedModules","title":"Isolated Modules option","description":"By default ts-jest uses TypeScript compiler in the context of a project (yours), with full type-checking and features.","source":"@site/versioned_docs/version-28.0/getting-started/options/isolatedModules.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/isolatedModules","permalink":"/ts-jest/docs/28.0/getting-started/options/isolatedModules","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/options/isolatedModules.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Isolated Modules option"}}');var o=s(4848),i=s(8453);const l={title:"Isolated Modules option"},a=void 0,d={},c=[{value:"Example",id:"example",level:3},{value:"Performance",id:"performance",level:2},{value:"Example",id:"example-1",level:3},{value:"Caveats",id:"caveats",level:2}];function r(e){const t={code:"code",h2:"h2",h3:"h3",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["By default ",(0,o.jsx)(t.code,{children:"ts-jest"})," uses TypeScript compiler in the context of a project (yours), with full type-checking and features.\nBut it can also be used to compile each file separately, what TypeScript calls an 'isolated module'.\nThat's what the ",(0,o.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,o.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,o.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,o.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,o.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,o.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n isolatedModules: true,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "isolatedModules": true\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,o.jsxs)(t.p,{children:["Using ",(0,o.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,o.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,o.jsx)(t.code,{children:"include"})," in ",(0,o.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,o.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,o.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,o.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,o.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,o.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,o.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,o.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,o.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,o.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,o.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function h(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(r,{...e})}):r(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>l,x:()=>a});var n=s(6540);const o={},i=n.createContext(o);function l(e){const t=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:l(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/304054d0.b6c2bc75.js b/assets/js/304054d0.338556f9.js similarity index 99% rename from assets/js/304054d0.b6c2bc75.js rename to assets/js/304054d0.338556f9.js index ebb93a5505..fa33043c91 100644 --- a/assets/js/304054d0.b6c2bc75.js +++ b/assets/js/304054d0.338556f9.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5501],{2148:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>u,contentTitle:()=>c,default:()=>j,frontMatter:()=>l,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/tsconfig","title":"TypeScript Config option","description":"The tsconfig option allows you to define which tsconfig JSON file to use. An inline compiler options object can also be specified instead of a file path.","source":"@site/versioned_docs/version-29.2/getting-started/options/tsconfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/tsconfig","permalink":"/ts-jest/docs/getting-started/options/tsconfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/options/tsconfig.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"TypeScript Config option"}}');var o=s(4848),r=s(8453),i=s(9489),a=s(7227);const l={title:"TypeScript Config option"},c=void 0,u={},d=[{value:"Examples",id:"examples",level:3},{value:"Path to a tsconfig file",id:"path-to-a-tsconfig-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4},{value:"Disable auto-lookup",id:"disable-auto-lookup",level:4}];function p(t){const e={a:"a",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,r.R)(),...t.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(e.p,{children:["The ",(0,o.jsx)(e.code,{children:"tsconfig"})," option allows you to define which ",(0,o.jsx)(e.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,o.jsx)(e.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," object can also be specified instead of a file path."]}),"\n",(0,o.jsxs)(e.p,{children:["By default ",(0,o.jsx)(e.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(e.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,o.jsx)(e.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,o.jsx)(e.code,{children:"ES2015"})," is used as ",(0,o.jsx)(e.code,{children:"target"})," instead of ",(0,o.jsx)(e.code,{children:"ES5"}),"."]}),"\n",(0,o.jsxs)(e.p,{children:["If you need to use defaults and force ",(0,o.jsx)(e.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,o.jsx)(e.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,o.jsx)(e.code,{children:"false"}),"."]}),"\n",(0,o.jsx)(e.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsxs)(e.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,o.jsx)(e.code,{children:"tsconfig"})," file"]}),"\n",(0,o.jsxs)(e.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,o.jsx)(e.code,{children:""})," in the path to start from the project root dir."]}),"\n",(0,o.jsxs)(i.A,{groupId:"code-examples",children:[(0,o.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: 'tsconfig.test.json',\n },\n ],\n },\n}\n"})})}),(0,o.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: 'tsconfig.test.json',\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,o.jsx)(a.A,{value:"JSON",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "tsconfig": "tsconfig.test.json"\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,o.jsx)(e.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,o.jsxs)(e.p,{children:["Refer to the TypeScript ",(0,o.jsx)(e.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," for reference.\nIt's basically the same object you'd put in your ",(0,o.jsx)(e.code,{children:"tsconfig.json"}),"'s ",(0,o.jsx)(e.code,{children:"compilerOptions"}),"."]}),"\n",(0,o.jsxs)(i.A,{groupId:"code-examples",children:[(0,o.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: {\n importHelpers: true,\n },\n },\n ],\n },\n}\n"})})}),(0,o.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: {\n importHelpers: true,\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,o.jsx)(a.A,{value:"JSON",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "tsconfig": {\n "importHelpers": true\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,o.jsx)(e.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,o.jsxs)(e.p,{children:["By default ",(0,o.jsx)(e.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(e.code,{children:"tsconfig.json"})," in your project. But you may not want to use it at all and keep TypeScript default options. You can achieve this by setting ",(0,o.jsx)(e.code,{children:"tsconfig"})," to ",(0,o.jsx)(e.code,{children:"false"}),"."]}),"\n",(0,o.jsxs)(i.A,{groupId:"code-examples",children:[(0,o.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: false,\n },\n ],\n },\n}\n"})})}),(0,o.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: false,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,o.jsx)(a.A,{value:"JSON",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "tsconfig": {\n "tsconfig": false\n }\n }\n ]\n }\n }\n}\n'})})})]})]})}function j(t={}){const{wrapper:e}={...(0,r.R)(),...t.components};return e?(0,o.jsx)(e,{...t,children:(0,o.jsx)(p,{...t})}):p(t)}},7227:(t,e,s)=>{s.d(e,{A:()=>i});s(6540);var n=s(4164);const o={tabItem:"tabItem_Ymn6"};var r=s(4848);function i(t){let{children:e,hidden:s,className:i}=t;return(0,r.jsx)("div",{role:"tabpanel",className:(0,n.A)(o.tabItem,i),hidden:s,children:e})}},9489:(t,e,s)=>{s.d(e,{A:()=>w});var n=s(6540),o=s(4164),r=s(4245),i=s(6347),a=s(6494),l=s(2814),c=s(5167),u=s(9900);function d(t){return n.Children.toArray(t).filter((t=>"\n"!==t)).map((t=>{if(!t||(0,n.isValidElement)(t)&&function(t){const{props:e}=t;return!!e&&"object"==typeof e&&"value"in e}(t))return t;throw new Error(`Docusaurus error: Bad child <${"string"==typeof t.type?t.type:t.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(t){const{values:e,children:s}=t;return(0,n.useMemo)((()=>{const t=e??function(t){return d(t).map((t=>{let{props:{value:e,label:s,attributes:n,default:o}}=t;return{value:e,label:s,attributes:n,default:o}}))}(s);return function(t){const e=(0,c.XI)(t,((t,e)=>t.value===e.value));if(e.length>0)throw new Error(`Docusaurus error: Duplicate values "${e.map((t=>t.value)).join(", ")}" found in . Every value needs to be unique.`)}(t),t}),[e,s])}function j(t){let{value:e,tabValues:s}=t;return s.some((t=>t.value===e))}function h(t){let{queryString:e=!1,groupId:s}=t;const o=(0,i.W6)(),r=function(t){let{queryString:e=!1,groupId:s}=t;if("string"==typeof e)return e;if(!1===e)return null;if(!0===e&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:e,groupId:s});return[(0,l.aZ)(r),(0,n.useCallback)((t=>{if(!r)return;const e=new URLSearchParams(o.location.search);e.set(r,t),o.replace({...o.location,search:e.toString()})}),[r,o])]}function f(t){const{defaultValue:e,queryString:s=!1,groupId:o}=t,r=p(t),[i,l]=(0,n.useState)((()=>function(t){let{defaultValue:e,tabValues:s}=t;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(e){if(!j({value:e,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${e}" but none of its children has the corresponding value. Available values are: ${s.map((t=>t.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return e}const n=s.find((t=>t.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:e,tabValues:r}))),[c,d]=h({queryString:s,groupId:o}),[f,m]=function(t){let{groupId:e}=t;const s=function(t){return t?`docusaurus.tab.${t}`:null}(e),[o,r]=(0,u.Dv)(s);return[o,(0,n.useCallback)((t=>{s&&r.set(t)}),[s,r])]}({groupId:o}),x=(()=>{const t=c??f;return j({value:t,tabValues:r})?t:null})();(0,a.A)((()=>{x&&l(x)}),[x]);return{selectedValue:i,selectValue:(0,n.useCallback)((t=>{if(!j({value:t,tabValues:r}))throw new Error(`Can't select invalid tab value=${t}`);l(t),d(t),m(t)}),[d,m,r]),tabValues:r}}var m=s(1062);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=s(4848);function b(t){let{className:e,block:s,selectedValue:n,selectValue:i,tabValues:a}=t;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),u=t=>{const e=t.currentTarget,s=l.indexOf(e),o=a[s].value;o!==n&&(c(e),i(o))},d=t=>{let e=null;switch(t.key){case"Enter":u(t);break;case"ArrowRight":{const s=l.indexOf(t.currentTarget)+1;e=l[s]??l[0];break}case"ArrowLeft":{const s=l.indexOf(t.currentTarget)-1;e=l[s]??l[l.length-1];break}}e?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.A)("tabs",{"tabs--block":s},e),children:a.map((t=>{let{value:e,label:s,attributes:r}=t;return(0,g.jsx)("li",{role:"tab",tabIndex:n===e?0:-1,"aria-selected":n===e,ref:t=>l.push(t),onKeyDown:d,onClick:u,...r,className:(0,o.A)("tabs__item",x.tabItem,r?.className,{"tabs__item--active":n===e}),children:s??e},e)}))})}function v(t){let{lazy:e,children:s,selectedValue:r}=t;const i=(Array.isArray(s)?s:[s]).filter(Boolean);if(e){const t=i.find((t=>t.props.value===r));return t?(0,n.cloneElement)(t,{className:(0,o.A)("margin-top--md",t.props.className)}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:i.map(((t,e)=>(0,n.cloneElement)(t,{key:e,hidden:t.props.value!==r})))})}function y(t){const e=f(t);return(0,g.jsxs)("div",{className:(0,o.A)("tabs-container",x.tabList),children:[(0,g.jsx)(b,{...e,...t}),(0,g.jsx)(v,{...e,...t})]})}function w(t){const e=(0,m.A)();return(0,g.jsx)(y,{...t,children:d(t.children)},String(e))}},8453:(t,e,s)=>{s.d(e,{R:()=>i,x:()=>a});var n=s(6540);const o={},r=n.createContext(o);function i(t){const e=n.useContext(r);return n.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function a(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:i(t.components),n.createElement(r.Provider,{value:e},t.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5501],{2148:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>u,contentTitle:()=>c,default:()=>j,frontMatter:()=>l,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/tsconfig","title":"TypeScript Config option","description":"The tsconfig option allows you to define which tsconfig JSON file to use. An inline compiler options object can also be specified instead of a file path.","source":"@site/versioned_docs/version-29.2/getting-started/options/tsconfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/tsconfig","permalink":"/ts-jest/docs/getting-started/options/tsconfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/options/tsconfig.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"TypeScript Config option"}}');var o=s(4848),r=s(8453),i=s(9489),a=s(7227);const l={title:"TypeScript Config option"},c=void 0,u={},d=[{value:"Examples",id:"examples",level:3},{value:"Path to a tsconfig file",id:"path-to-a-tsconfig-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4},{value:"Disable auto-lookup",id:"disable-auto-lookup",level:4}];function p(t){const e={a:"a",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,r.R)(),...t.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(e.p,{children:["The ",(0,o.jsx)(e.code,{children:"tsconfig"})," option allows you to define which ",(0,o.jsx)(e.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,o.jsx)(e.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," object can also be specified instead of a file path."]}),"\n",(0,o.jsxs)(e.p,{children:["By default ",(0,o.jsx)(e.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(e.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,o.jsx)(e.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,o.jsx)(e.code,{children:"ES2015"})," is used as ",(0,o.jsx)(e.code,{children:"target"})," instead of ",(0,o.jsx)(e.code,{children:"ES5"}),"."]}),"\n",(0,o.jsxs)(e.p,{children:["If you need to use defaults and force ",(0,o.jsx)(e.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,o.jsx)(e.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,o.jsx)(e.code,{children:"false"}),"."]}),"\n",(0,o.jsx)(e.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsxs)(e.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,o.jsx)(e.code,{children:"tsconfig"})," file"]}),"\n",(0,o.jsxs)(e.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,o.jsx)(e.code,{children:""})," in the path to start from the project root dir."]}),"\n",(0,o.jsxs)(i.A,{groupId:"code-examples",children:[(0,o.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: 'tsconfig.test.json',\n },\n ],\n },\n}\n"})})}),(0,o.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: 'tsconfig.test.json',\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,o.jsx)(a.A,{value:"JSON",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "tsconfig": "tsconfig.test.json"\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,o.jsx)(e.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,o.jsxs)(e.p,{children:["Refer to the TypeScript ",(0,o.jsx)(e.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," for reference.\nIt's basically the same object you'd put in your ",(0,o.jsx)(e.code,{children:"tsconfig.json"}),"'s ",(0,o.jsx)(e.code,{children:"compilerOptions"}),"."]}),"\n",(0,o.jsxs)(i.A,{groupId:"code-examples",children:[(0,o.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: {\n importHelpers: true,\n },\n },\n ],\n },\n}\n"})})}),(0,o.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: {\n importHelpers: true,\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,o.jsx)(a.A,{value:"JSON",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "tsconfig": {\n "importHelpers": true\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,o.jsx)(e.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,o.jsxs)(e.p,{children:["By default ",(0,o.jsx)(e.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(e.code,{children:"tsconfig.json"})," in your project. But you may not want to use it at all and keep TypeScript default options. You can achieve this by setting ",(0,o.jsx)(e.code,{children:"tsconfig"})," to ",(0,o.jsx)(e.code,{children:"false"}),"."]}),"\n",(0,o.jsxs)(i.A,{groupId:"code-examples",children:[(0,o.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: false,\n },\n ],\n },\n}\n"})})}),(0,o.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: false,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,o.jsx)(a.A,{value:"JSON",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "tsconfig": {\n "tsconfig": false\n }\n }\n ]\n }\n }\n}\n'})})})]})]})}function j(t={}){const{wrapper:e}={...(0,r.R)(),...t.components};return e?(0,o.jsx)(e,{...t,children:(0,o.jsx)(p,{...t})}):p(t)}},7227:(t,e,s)=>{s.d(e,{A:()=>i});s(6540);var n=s(4164);const o={tabItem:"tabItem_Ymn6"};var r=s(4848);function i(t){let{children:e,hidden:s,className:i}=t;return(0,r.jsx)("div",{role:"tabpanel",className:(0,n.A)(o.tabItem,i),hidden:s,children:e})}},9489:(t,e,s)=>{s.d(e,{A:()=>w});var n=s(6540),o=s(4164),r=s(4245),i=s(6347),a=s(6494),l=s(2814),c=s(5167),u=s(9900);function d(t){return n.Children.toArray(t).filter((t=>"\n"!==t)).map((t=>{if(!t||(0,n.isValidElement)(t)&&function(t){const{props:e}=t;return!!e&&"object"==typeof e&&"value"in e}(t))return t;throw new Error(`Docusaurus error: Bad child <${"string"==typeof t.type?t.type:t.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(t){const{values:e,children:s}=t;return(0,n.useMemo)((()=>{const t=e??function(t){return d(t).map((t=>{let{props:{value:e,label:s,attributes:n,default:o}}=t;return{value:e,label:s,attributes:n,default:o}}))}(s);return function(t){const e=(0,c.XI)(t,((t,e)=>t.value===e.value));if(e.length>0)throw new Error(`Docusaurus error: Duplicate values "${e.map((t=>t.value)).join(", ")}" found in . Every value needs to be unique.`)}(t),t}),[e,s])}function j(t){let{value:e,tabValues:s}=t;return s.some((t=>t.value===e))}function h(t){let{queryString:e=!1,groupId:s}=t;const o=(0,i.W6)(),r=function(t){let{queryString:e=!1,groupId:s}=t;if("string"==typeof e)return e;if(!1===e)return null;if(!0===e&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:e,groupId:s});return[(0,l.aZ)(r),(0,n.useCallback)((t=>{if(!r)return;const e=new URLSearchParams(o.location.search);e.set(r,t),o.replace({...o.location,search:e.toString()})}),[r,o])]}function f(t){const{defaultValue:e,queryString:s=!1,groupId:o}=t,r=p(t),[i,l]=(0,n.useState)((()=>function(t){let{defaultValue:e,tabValues:s}=t;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(e){if(!j({value:e,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${e}" but none of its children has the corresponding value. Available values are: ${s.map((t=>t.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return e}const n=s.find((t=>t.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:e,tabValues:r}))),[c,d]=h({queryString:s,groupId:o}),[f,m]=function(t){let{groupId:e}=t;const s=function(t){return t?`docusaurus.tab.${t}`:null}(e),[o,r]=(0,u.Dv)(s);return[o,(0,n.useCallback)((t=>{s&&r.set(t)}),[s,r])]}({groupId:o}),x=(()=>{const t=c??f;return j({value:t,tabValues:r})?t:null})();(0,a.A)((()=>{x&&l(x)}),[x]);return{selectedValue:i,selectValue:(0,n.useCallback)((t=>{if(!j({value:t,tabValues:r}))throw new Error(`Can't select invalid tab value=${t}`);l(t),d(t),m(t)}),[d,m,r]),tabValues:r}}var m=s(1062);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=s(4848);function b(t){let{className:e,block:s,selectedValue:n,selectValue:i,tabValues:a}=t;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),u=t=>{const e=t.currentTarget,s=l.indexOf(e),o=a[s].value;o!==n&&(c(e),i(o))},d=t=>{let e=null;switch(t.key){case"Enter":u(t);break;case"ArrowRight":{const s=l.indexOf(t.currentTarget)+1;e=l[s]??l[0];break}case"ArrowLeft":{const s=l.indexOf(t.currentTarget)-1;e=l[s]??l[l.length-1];break}}e?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.A)("tabs",{"tabs--block":s},e),children:a.map((t=>{let{value:e,label:s,attributes:r}=t;return(0,g.jsx)("li",{role:"tab",tabIndex:n===e?0:-1,"aria-selected":n===e,ref:t=>l.push(t),onKeyDown:d,onClick:u,...r,className:(0,o.A)("tabs__item",x.tabItem,r?.className,{"tabs__item--active":n===e}),children:s??e},e)}))})}function v(t){let{lazy:e,children:s,selectedValue:r}=t;const i=(Array.isArray(s)?s:[s]).filter(Boolean);if(e){const t=i.find((t=>t.props.value===r));return t?(0,n.cloneElement)(t,{className:(0,o.A)("margin-top--md",t.props.className)}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:i.map(((t,e)=>(0,n.cloneElement)(t,{key:e,hidden:t.props.value!==r})))})}function y(t){const e=f(t);return(0,g.jsxs)("div",{className:(0,o.A)("tabs-container",x.tabList),children:[(0,g.jsx)(b,{...e,...t}),(0,g.jsx)(v,{...e,...t})]})}function w(t){const e=(0,m.A)();return(0,g.jsx)(y,{...t,children:d(t.children)},String(e))}},8453:(t,e,s)=>{s.d(e,{R:()=>i,x:()=>a});var n=s(6540);const o={},r=n.createContext(o);function i(t){const e=n.useContext(r);return n.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function a(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:i(t.components),n.createElement(r.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/334e0bf3.b5f04685.js b/assets/js/334e0bf3.a900e034.js similarity index 97% rename from assets/js/334e0bf3.b5f04685.js rename to assets/js/334e0bf3.a900e034.js index 2293a7494f..cda5018ecb 100644 --- a/assets/js/334e0bf3.b5f04685.js +++ b/assets/js/334e0bf3.a900e034.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3723],{2807:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>d,contentTitle:()=>c,default:()=>a,frontMatter:()=>i,metadata:()=>s,toc:()=>u});const s=JSON.parse('{"id":"guides/using-with-monorepo","title":"Using with monorepo","description":"To use ts-jest in a project with monorepo structure, you\'ll need to use Jest projects configuration.","source":"@site/versioned_docs/version-26.5/guides/using-with-monorepo.md","sourceDirName":"guides","slug":"/guides/using-with-monorepo","permalink":"/ts-jest/docs/26.5/guides/using-with-monorepo","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/guides/using-with-monorepo.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"using-with-monorepo","title":"Using with monorepo"},"sidebar":"version-26.5-docs","previous":{"title":"Troubleshooting","permalink":"/ts-jest/docs/26.5/guides/troubleshooting"},"next":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/26.5/babel7-or-ts"}}');var n=o(4848),r=o(8453);const i={id:"using-with-monorepo",title:"Using with monorepo"},c=void 0,d={},u=[];function p(e){const t={a:"a",code:"code",p:"p",strong:"strong",...(0,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["To use ",(0,n.jsx)(t.code,{children:"ts-jest"})," in a project with monorepo structure, you'll need to use ",(0,n.jsx)(t.a,{href:"https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig",children:"Jest projects configuration"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["When using Jest ",(0,n.jsx)(t.code,{children:"projects"})," configuration, Jest will run ",(0,n.jsx)(t.code,{children:"ts-jest"})," against each project which is defined in the configuration."]}),"\n",(0,n.jsxs)(t.p,{children:["One should not be confused between the term ",(0,n.jsx)(t.strong,{children:"monorepo"})," vs TypeScript ",(0,n.jsx)(t.strong,{children:"project references"}),". These are 2 different terms."]})]})}function a(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(p,{...e})}):p(e)}},8453:(e,t,o)=>{o.d(t,{R:()=>i,x:()=>c});var s=o(6540);const n={},r=s.createContext(n);function i(e){const t=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:i(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3723],{2807:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>d,contentTitle:()=>c,default:()=>a,frontMatter:()=>i,metadata:()=>s,toc:()=>u});const s=JSON.parse('{"id":"guides/using-with-monorepo","title":"Using with monorepo","description":"To use ts-jest in a project with monorepo structure, you\'ll need to use Jest projects configuration.","source":"@site/versioned_docs/version-26.5/guides/using-with-monorepo.md","sourceDirName":"guides","slug":"/guides/using-with-monorepo","permalink":"/ts-jest/docs/26.5/guides/using-with-monorepo","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/guides/using-with-monorepo.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"using-with-monorepo","title":"Using with monorepo"},"sidebar":"version-26.5-docs","previous":{"title":"Troubleshooting","permalink":"/ts-jest/docs/26.5/guides/troubleshooting"},"next":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/26.5/babel7-or-ts"}}');var n=o(4848),r=o(8453);const i={id:"using-with-monorepo",title:"Using with monorepo"},c=void 0,d={},u=[];function p(e){const t={a:"a",code:"code",p:"p",strong:"strong",...(0,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["To use ",(0,n.jsx)(t.code,{children:"ts-jest"})," in a project with monorepo structure, you'll need to use ",(0,n.jsx)(t.a,{href:"https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig",children:"Jest projects configuration"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["When using Jest ",(0,n.jsx)(t.code,{children:"projects"})," configuration, Jest will run ",(0,n.jsx)(t.code,{children:"ts-jest"})," against each project which is defined in the configuration."]}),"\n",(0,n.jsxs)(t.p,{children:["One should not be confused between the term ",(0,n.jsx)(t.strong,{children:"monorepo"})," vs TypeScript ",(0,n.jsx)(t.strong,{children:"project references"}),". These are 2 different terms."]})]})}function a(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(p,{...e})}):p(e)}},8453:(e,t,o)=>{o.d(t,{R:()=>i,x:()=>c});var s=o(6540);const n={},r=s.createContext(n);function i(e){const t=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:i(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/3432663a.4f4acd85.js b/assets/js/3432663a.9cff8df9.js similarity index 98% rename from assets/js/3432663a.4f4acd85.js rename to assets/js/3432663a.9cff8df9.js index 84a4ecf8f3..c23eff9054 100644 --- a/assets/js/3432663a.4f4acd85.js +++ b/assets/js/3432663a.9cff8df9.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9345],{7994:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>a,contentTitle:()=>c,default:()=>g,frontMatter:()=>r,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"migration","title":"Migration from <=23.10","description":"You can use the config:migrate tool of ts-jest CLI if you\'re coming from an older version to help you migrate your Jest configuration.","source":"@site/versioned_docs/version-27.1/migration.md","sourceDirName":".","slug":"/migration","permalink":"/ts-jest/docs/27.1/migration","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/migration.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"migration","title":"Migration from <=23.10"},"sidebar":"version-27.1-docs","previous":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/27.1/babel7-or-ts"},"next":{"title":"Debugging ts-jest","permalink":"/ts-jest/docs/27.1/debugging"}}');var o=t(4848),i=t(8453);const r={id:"migration",title:"Migration from <=23.10"},c=void 0,a={},d=[{value:"NPM",id:"npm",level:3},{value:"Yarn",id:"yarn",level:3},{value:"NPM",id:"npm-1",level:3},{value:"Yarn",id:"yarn-1",level:3}];function l(e){const n={code:"code",em:"em",h3:"h3",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:["You can use the ",(0,o.jsx)(n.code,{children:"config:migrate"})," tool of ",(0,o.jsx)(n.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsxs)(n.em,{children:["If you're using ",(0,o.jsx)(n.code,{children:"jest.config.js"}),":"]})}),"\n",(0,o.jsx)(n.h3,{id:"npm",children:"NPM"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate jest.config.js\n"})}),"\n",(0,o.jsx)(n.h3,{id:"yarn",children:"Yarn"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate jest.config.js\n"})}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsxs)(n.em,{children:["If you're using ",(0,o.jsx)(n.code,{children:"jest"})," config property of ",(0,o.jsx)(n.code,{children:"package.json"}),":"]})}),"\n",(0,o.jsx)(n.h3,{id:"npm-1",children:"NPM"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate package.json\n"})}),"\n",(0,o.jsx)(n.h3,{id:"yarn-1",children:"Yarn"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate package.json\n"})})]})}function g(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>r,x:()=>c});var s=t(6540);const o={},i=s.createContext(o);function r(e){const n=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function c(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9345],{7994:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>a,contentTitle:()=>c,default:()=>g,frontMatter:()=>r,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"migration","title":"Migration from <=23.10","description":"You can use the config:migrate tool of ts-jest CLI if you\'re coming from an older version to help you migrate your Jest configuration.","source":"@site/versioned_docs/version-27.1/migration.md","sourceDirName":".","slug":"/migration","permalink":"/ts-jest/docs/27.1/migration","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/migration.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"migration","title":"Migration from <=23.10"},"sidebar":"version-27.1-docs","previous":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/27.1/babel7-or-ts"},"next":{"title":"Debugging ts-jest","permalink":"/ts-jest/docs/27.1/debugging"}}');var o=t(4848),i=t(8453);const r={id:"migration",title:"Migration from <=23.10"},c=void 0,a={},d=[{value:"NPM",id:"npm",level:3},{value:"Yarn",id:"yarn",level:3},{value:"NPM",id:"npm-1",level:3},{value:"Yarn",id:"yarn-1",level:3}];function l(e){const n={code:"code",em:"em",h3:"h3",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:["You can use the ",(0,o.jsx)(n.code,{children:"config:migrate"})," tool of ",(0,o.jsx)(n.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsxs)(n.em,{children:["If you're using ",(0,o.jsx)(n.code,{children:"jest.config.js"}),":"]})}),"\n",(0,o.jsx)(n.h3,{id:"npm",children:"NPM"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate jest.config.js\n"})}),"\n",(0,o.jsx)(n.h3,{id:"yarn",children:"Yarn"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate jest.config.js\n"})}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsxs)(n.em,{children:["If you're using ",(0,o.jsx)(n.code,{children:"jest"})," config property of ",(0,o.jsx)(n.code,{children:"package.json"}),":"]})}),"\n",(0,o.jsx)(n.h3,{id:"npm-1",children:"NPM"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate package.json\n"})}),"\n",(0,o.jsx)(n.h3,{id:"yarn-1",children:"Yarn"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate package.json\n"})})]})}function g(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>r,x:()=>c});var s=t(6540);const o={},i=s.createContext(o);function r(e){const n=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function c(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/35779d9e.1967fc1e.js b/assets/js/35779d9e.e35fa0f5.js similarity index 99% rename from assets/js/35779d9e.1967fc1e.js rename to assets/js/35779d9e.e35fa0f5.js index 0651ed2c73..518a3793e5 100644 --- a/assets/js/35779d9e.1967fc1e.js +++ b/assets/js/35779d9e.e35fa0f5.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3152],{9372:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>i,metadata:()=>n,toc:()=>j});const n=JSON.parse('{"id":"getting-started/options/babelConfig","title":"Babel Config option","description":"ts-jest by default does NOT use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ts-jest can call the BabelJest processor once TypeScript has transformed the source into JavaScript.","source":"@site/versioned_docs/version-29.0/getting-started/options/babelConfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/babelConfig","permalink":"/ts-jest/docs/29.0/getting-started/options/babelConfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/options/babelConfig.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Babel Config option"}}');var r=s(4848),o=s(8453),a=s(9489),l=s(7227);const i={title:"Babel Config option"},c=void 0,u={},j=[{value:"Examples",id:"examples",level:3},{value:"Use default babelrc file",id:"use-default-babelrc-file",level:4},{value:"Path to a babelrc file",id:"path-to-a-babelrc-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4}];function d(e){const t={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"ts-jest"})," by default does ",(0,r.jsx)(t.strong,{children:"NOT"})," use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ",(0,r.jsx)(t.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,r.jsxs)(t.p,{children:["The option is ",(0,r.jsx)(t.code,{children:"babelConfig"})," and it works pretty much as the ",(0,r.jsx)(t.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"true"}),": enables Babel processing. ",(0,r.jsx)(t.code,{children:"ts-jest"})," will try to find a ",(0,r.jsx)(t.code,{children:".babelrc"}),", ",(0,r.jsx)(t.code,{children:".babelrc.js"}),", ",(0,r.jsx)(t.code,{children:"babel.config.js"})," file or a ",(0,r.jsx)(t.code,{children:"babel"})," section in the ",(0,r.jsx)(t.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,r.jsx)(t.code,{children:"babel-jest"})," processor."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"{ ... }"}),": inline ",(0,r.jsx)(t.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,r.jsx)(t.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,r.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,r.jsxs)(t.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,r.jsx)(t.code,{children:"babelrc"})," file"]}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: true,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: true,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "babelConfig": true\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsxs)(t.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,r.jsx)(t.code,{children:"babelrc"})," file"]}),"\n",(0,r.jsxs)(t.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,r.jsx)(t.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: 'babelrc.test.js',\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: 'babelrc.test.js',\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "babelConfig": "babelrc.test.js"\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsx)(t.p,{children:"or importing directly the config file:"}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: require('./babelrc.test.js'),\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\nimport babelConfig from './babelrc.test.js'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})})]}),"\n",(0,r.jsx)(t.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,r.jsxs)(t.p,{children:["Refer to the ",(0,r.jsx)(t.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: {\n comments: false,\n plugins: ['@babel/plugin-transform-for-of'],\n },\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: {\n comments: false,\n plugins: ['@babel/plugin-transform-for-of'],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "babelConfig": {\n "comments": false,\n "plugins": ["@babel/plugin-transform-for-of"]\n }\n }\n ]\n }\n }\n}\n'})})})]})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(d,{...e})}):d(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>a});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var o=s(4848);function a(e){let{children:t,hidden:s,className:a}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,a),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>w});var n=s(6540),r=s(4164),o=s(4245),a=s(6347),l=s(6494),i=s(2814),c=s(5167),u=s(9900);function j(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function d(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return j(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:r}}=e;return{value:t,label:s,attributes:n,default:r}}))}(s);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function p(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:s}=e;const r=(0,a.W6)(),o=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,i.aZ)(o),(0,n.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(r.location.search);t.set(o,e),r.replace({...r.location,search:t.toString()})}),[o,r])]}function x(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,o=d(e),[a,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:o}))),[c,j]=h({queryString:s,groupId:r}),[x,m]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,o]=(0,u.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&o.set(e)}),[s,o])]}({groupId:r}),f=(()=>{const e=c??x;return p({value:e,tabValues:o})?e:null})();(0,l.A)((()=>{f&&i(f)}),[f]);return{selectedValue:a,selectValue:(0,n.useCallback)((e=>{if(!p({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);i(e),j(e),m(e)}),[j,m,o]),tabValues:o}}var m=s(1062);const f={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=s(4848);function g(e){let{className:t,block:s,selectedValue:n,selectValue:a,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.a_)(),u=e=>{const t=e.currentTarget,s=i.indexOf(t),r=l[s].value;r!==n&&(c(t),a(r))},j=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const s=i.indexOf(e.currentTarget)+1;t=i[s]??i[0];break}case"ArrowLeft":{const s=i.indexOf(e.currentTarget)-1;t=i[s]??i[i.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":s},t),children:l.map((e=>{let{value:t,label:s,attributes:o}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:j,onClick:u,...o,className:(0,r.A)("tabs__item",f.tabItem,o?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:o}=e;const a=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=a.find((e=>e.props.value===o));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:a.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==o})))})}function y(e){const t=x(e);return(0,b.jsxs)("div",{className:(0,r.A)("tabs-container",f.tabList),children:[(0,b.jsx)(g,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function w(e){const t=(0,m.A)();return(0,b.jsx)(y,{...e,children:j(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>a,x:()=>l});var n=s(6540);const r={},o=n.createContext(r);function a(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3152],{9372:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>i,metadata:()=>n,toc:()=>j});const n=JSON.parse('{"id":"getting-started/options/babelConfig","title":"Babel Config option","description":"ts-jest by default does NOT use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ts-jest can call the BabelJest processor once TypeScript has transformed the source into JavaScript.","source":"@site/versioned_docs/version-29.0/getting-started/options/babelConfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/babelConfig","permalink":"/ts-jest/docs/29.0/getting-started/options/babelConfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/options/babelConfig.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Babel Config option"}}');var r=s(4848),o=s(8453),a=s(9489),l=s(7227);const i={title:"Babel Config option"},c=void 0,u={},j=[{value:"Examples",id:"examples",level:3},{value:"Use default babelrc file",id:"use-default-babelrc-file",level:4},{value:"Path to a babelrc file",id:"path-to-a-babelrc-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4}];function d(e){const t={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"ts-jest"})," by default does ",(0,r.jsx)(t.strong,{children:"NOT"})," use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ",(0,r.jsx)(t.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,r.jsxs)(t.p,{children:["The option is ",(0,r.jsx)(t.code,{children:"babelConfig"})," and it works pretty much as the ",(0,r.jsx)(t.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"true"}),": enables Babel processing. ",(0,r.jsx)(t.code,{children:"ts-jest"})," will try to find a ",(0,r.jsx)(t.code,{children:".babelrc"}),", ",(0,r.jsx)(t.code,{children:".babelrc.js"}),", ",(0,r.jsx)(t.code,{children:"babel.config.js"})," file or a ",(0,r.jsx)(t.code,{children:"babel"})," section in the ",(0,r.jsx)(t.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,r.jsx)(t.code,{children:"babel-jest"})," processor."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"{ ... }"}),": inline ",(0,r.jsx)(t.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,r.jsx)(t.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,r.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,r.jsxs)(t.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,r.jsx)(t.code,{children:"babelrc"})," file"]}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: true,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: true,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "babelConfig": true\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsxs)(t.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,r.jsx)(t.code,{children:"babelrc"})," file"]}),"\n",(0,r.jsxs)(t.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,r.jsx)(t.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: 'babelrc.test.js',\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: 'babelrc.test.js',\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "babelConfig": "babelrc.test.js"\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsx)(t.p,{children:"or importing directly the config file:"}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: require('./babelrc.test.js'),\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\nimport babelConfig from './babelrc.test.js'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})})]}),"\n",(0,r.jsx)(t.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,r.jsxs)(t.p,{children:["Refer to the ",(0,r.jsx)(t.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: {\n comments: false,\n plugins: ['@babel/plugin-transform-for-of'],\n },\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: {\n comments: false,\n plugins: ['@babel/plugin-transform-for-of'],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "babelConfig": {\n "comments": false,\n "plugins": ["@babel/plugin-transform-for-of"]\n }\n }\n ]\n }\n }\n}\n'})})})]})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(d,{...e})}):d(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>a});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var o=s(4848);function a(e){let{children:t,hidden:s,className:a}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,a),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>w});var n=s(6540),r=s(4164),o=s(4245),a=s(6347),l=s(6494),i=s(2814),c=s(5167),u=s(9900);function j(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function d(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return j(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:r}}=e;return{value:t,label:s,attributes:n,default:r}}))}(s);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function p(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:s}=e;const r=(0,a.W6)(),o=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,i.aZ)(o),(0,n.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(r.location.search);t.set(o,e),r.replace({...r.location,search:t.toString()})}),[o,r])]}function x(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,o=d(e),[a,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:o}))),[c,j]=h({queryString:s,groupId:r}),[x,m]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,o]=(0,u.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&o.set(e)}),[s,o])]}({groupId:r}),f=(()=>{const e=c??x;return p({value:e,tabValues:o})?e:null})();(0,l.A)((()=>{f&&i(f)}),[f]);return{selectedValue:a,selectValue:(0,n.useCallback)((e=>{if(!p({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);i(e),j(e),m(e)}),[j,m,o]),tabValues:o}}var m=s(1062);const f={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=s(4848);function g(e){let{className:t,block:s,selectedValue:n,selectValue:a,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.a_)(),u=e=>{const t=e.currentTarget,s=i.indexOf(t),r=l[s].value;r!==n&&(c(t),a(r))},j=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const s=i.indexOf(e.currentTarget)+1;t=i[s]??i[0];break}case"ArrowLeft":{const s=i.indexOf(e.currentTarget)-1;t=i[s]??i[i.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":s},t),children:l.map((e=>{let{value:t,label:s,attributes:o}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:j,onClick:u,...o,className:(0,r.A)("tabs__item",f.tabItem,o?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:o}=e;const a=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=a.find((e=>e.props.value===o));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:a.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==o})))})}function y(e){const t=x(e);return(0,b.jsxs)("div",{className:(0,r.A)("tabs-container",f.tabList),children:[(0,b.jsx)(g,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function w(e){const t=(0,m.A)();return(0,b.jsx)(y,{...e,children:j(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>a,x:()=>l});var n=s(6540);const r={},o=n.createContext(r);function a(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/35ce71d5.c5787073.js b/assets/js/35ce71d5.1ceeb43b.js similarity index 97% rename from assets/js/35ce71d5.c5787073.js rename to assets/js/35ce71d5.1ceeb43b.js index eba3c52f0a..78d9ea8cef 100644 --- a/assets/js/35ce71d5.c5787073.js +++ b/assets/js/35ce71d5.1ceeb43b.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9014],{7796:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>r,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"guides/using-with-monorepo","title":"Using with monorepo","description":"To use ts-jest in a project with monorepo structure, you\'ll need to use Jest projects configuration.","source":"@site/versioned_docs/version-29.0/guides/using-with-monorepo.md","sourceDirName":"guides","slug":"/guides/using-with-monorepo","permalink":"/ts-jest/docs/29.0/guides/using-with-monorepo","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/guides/using-with-monorepo.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"using-with-monorepo","title":"Using with monorepo"},"sidebar":"version-29.0-docs","previous":{"title":"Troubleshooting","permalink":"/ts-jest/docs/29.0/guides/troubleshooting"},"next":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/29.0/babel7-or-ts"}}');var n=o(4848),i=o(8453);const r={id:"using-with-monorepo",title:"Using with monorepo"},c=void 0,u={},d=[];function a(e){const t={a:"a",code:"code",p:"p",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["To use ",(0,n.jsx)(t.code,{children:"ts-jest"})," in a project with monorepo structure, you'll need to use ",(0,n.jsx)(t.a,{href:"https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig",children:"Jest projects configuration"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["When using Jest ",(0,n.jsx)(t.code,{children:"projects"})," configuration, Jest will run ",(0,n.jsx)(t.code,{children:"ts-jest"})," against each project which is defined in the configuration."]})]})}function p(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(a,{...e})}):a(e)}},8453:(e,t,o)=>{o.d(t,{R:()=>r,x:()=>c});var s=o(6540);const n={},i=s.createContext(n);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9014],{7796:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>r,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"guides/using-with-monorepo","title":"Using with monorepo","description":"To use ts-jest in a project with monorepo structure, you\'ll need to use Jest projects configuration.","source":"@site/versioned_docs/version-29.0/guides/using-with-monorepo.md","sourceDirName":"guides","slug":"/guides/using-with-monorepo","permalink":"/ts-jest/docs/29.0/guides/using-with-monorepo","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/guides/using-with-monorepo.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"using-with-monorepo","title":"Using with monorepo"},"sidebar":"version-29.0-docs","previous":{"title":"Troubleshooting","permalink":"/ts-jest/docs/29.0/guides/troubleshooting"},"next":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/29.0/babel7-or-ts"}}');var n=o(4848),i=o(8453);const r={id:"using-with-monorepo",title:"Using with monorepo"},c=void 0,u={},d=[];function a(e){const t={a:"a",code:"code",p:"p",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["To use ",(0,n.jsx)(t.code,{children:"ts-jest"})," in a project with monorepo structure, you'll need to use ",(0,n.jsx)(t.a,{href:"https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig",children:"Jest projects configuration"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["When using Jest ",(0,n.jsx)(t.code,{children:"projects"})," configuration, Jest will run ",(0,n.jsx)(t.code,{children:"ts-jest"})," against each project which is defined in the configuration."]})]})}function p(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(a,{...e})}):a(e)}},8453:(e,t,o)=>{o.d(t,{R:()=>r,x:()=>c});var s=o(6540);const n={},i=s.createContext(n);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/3787ba46.79103c8d.js b/assets/js/3787ba46.3187f2ee.js similarity index 98% rename from assets/js/3787ba46.79103c8d.js rename to assets/js/3787ba46.3187f2ee.js index 36265d0728..6dbc30a791 100644 --- a/assets/js/3787ba46.79103c8d.js +++ b/assets/js/3787ba46.3187f2ee.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[775],{9985:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>l,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>t,toc:()=>a});const t=JSON.parse('{"id":"guides/esm-support","title":"ESM Support","description":"To use ts-jest with ESM support:","source":"@site/versioned_docs/version-27.1/guides/esm-support.md","sourceDirName":"guides","slug":"/guides/esm-support","permalink":"/ts-jest/docs/27.1/guides/esm-support","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/guides/esm-support.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"esm-support","title":"ESM Support"},"sidebar":"version-27.1-docs","previous":{"title":"Version checking","permalink":"/ts-jest/docs/27.1/getting-started/version-checking"},"next":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/27.1/guides/mock-es6-class"}}');var r=n(4848),o=n(8453);const i={id:"esm-support",title:"ESM Support"},c=void 0,l={},a=[{value:"ESM presets",id:"esm-presets",level:3},{value:"Examples",id:"examples",level:3},{value:"Manual configuration",id:"manual-configuration",level:4},{value:"Use ESM presets",id:"use-esm-presets",level:4}];function d(e){const s={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(s.p,{children:["To use ",(0,r.jsx)(s.code,{children:"ts-jest"})," with ESM support:"]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:["Check ",(0,r.jsx)(s.a,{href:"https://jestjs.io/docs/en/ecmascript-modules",children:"ESM Jest documentation"}),"."]}),"\n",(0,r.jsxs)(s.li,{children:["Enable ",(0,r.jsx)(s.a,{href:"../getting-started/options/useESM",children:"useESM"})," ",(0,r.jsx)(s.code,{children:"true"})," for ",(0,r.jsx)(s.code,{children:"ts-jest"})," config."]}),"\n",(0,r.jsxs)(s.li,{children:["Include ",(0,r.jsx)(s.code,{children:".ts"})," in ",(0,r.jsx)(s.a,{href:"https://jestjs.io/docs/en/next/configuration#extensionstotreatasesm-arraystring",children:"extensionsToTreatAsEsm"})," Jest config option."]}),"\n",(0,r.jsxs)(s.li,{children:["Ensure that ",(0,r.jsx)(s.code,{children:"tsconfig"})," has ",(0,r.jsx)(s.code,{children:"module"})," with value for ESM, e.g. ",(0,r.jsx)(s.code,{children:"ES2015"})," or ",(0,r.jsx)(s.code,{children:"ES2020"})," etc..."]}),"\n"]}),"\n",(0,r.jsx)(s.h3,{id:"esm-presets",children:"ESM presets"}),"\n",(0,r.jsxs)(s.p,{children:["There are also ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/27.1/getting-started/presets",children:"3 presets"})," to work with ESM."]}),"\n",(0,r.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,r.jsx)(s.h4,{id:"manual-configuration",children:"Manual configuration"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n extensionsToTreatAsEsm: ['.ts'],\n globals: {\n 'ts-jest': {\n useESM: true,\n },\n },\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n}\n"})}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "extensionsToTreatAsEsm": [".ts"],\n "globals": {\n "ts-jest": {\n "useESM": true\n }\n },\n "moduleNameMapper": {\n "^(\\\\.{1,2}/.*)\\\\.js$": "$1"\n }\n }\n}\n'})}),"\n",(0,r.jsx)(s.h4,{id:"use-esm-presets",children:"Use ESM presets"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n preset: 'ts-jest/presets/default-esm', // or other ESM presets\n globals: {\n 'ts-jest': {\n useESM: true,\n },\n },\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n}\n"})}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "preset": "ts-jest/presets/default-esm", // or other ESM presets,\n "globals": {\n "ts-jest": {\n "useESM": true\n }\n },\n "moduleNameMapper": {\n "^(\\\\.{1,2}/.*)\\\\.js$": "$1"\n }\n }\n}\n'})})]})}function u(e={}){const{wrapper:s}={...(0,o.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(d,{...e})}):d(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>i,x:()=>c});var t=n(6540);const r={},o=t.createContext(r);function i(e){const s=t.useContext(o);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function c(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),t.createElement(o.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[775],{9985:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>l,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>t,toc:()=>a});const t=JSON.parse('{"id":"guides/esm-support","title":"ESM Support","description":"To use ts-jest with ESM support:","source":"@site/versioned_docs/version-27.1/guides/esm-support.md","sourceDirName":"guides","slug":"/guides/esm-support","permalink":"/ts-jest/docs/27.1/guides/esm-support","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/guides/esm-support.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"esm-support","title":"ESM Support"},"sidebar":"version-27.1-docs","previous":{"title":"Version checking","permalink":"/ts-jest/docs/27.1/getting-started/version-checking"},"next":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/27.1/guides/mock-es6-class"}}');var r=n(4848),o=n(8453);const i={id:"esm-support",title:"ESM Support"},c=void 0,l={},a=[{value:"ESM presets",id:"esm-presets",level:3},{value:"Examples",id:"examples",level:3},{value:"Manual configuration",id:"manual-configuration",level:4},{value:"Use ESM presets",id:"use-esm-presets",level:4}];function d(e){const s={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(s.p,{children:["To use ",(0,r.jsx)(s.code,{children:"ts-jest"})," with ESM support:"]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:["Check ",(0,r.jsx)(s.a,{href:"https://jestjs.io/docs/en/ecmascript-modules",children:"ESM Jest documentation"}),"."]}),"\n",(0,r.jsxs)(s.li,{children:["Enable ",(0,r.jsx)(s.a,{href:"../getting-started/options/useESM",children:"useESM"})," ",(0,r.jsx)(s.code,{children:"true"})," for ",(0,r.jsx)(s.code,{children:"ts-jest"})," config."]}),"\n",(0,r.jsxs)(s.li,{children:["Include ",(0,r.jsx)(s.code,{children:".ts"})," in ",(0,r.jsx)(s.a,{href:"https://jestjs.io/docs/en/next/configuration#extensionstotreatasesm-arraystring",children:"extensionsToTreatAsEsm"})," Jest config option."]}),"\n",(0,r.jsxs)(s.li,{children:["Ensure that ",(0,r.jsx)(s.code,{children:"tsconfig"})," has ",(0,r.jsx)(s.code,{children:"module"})," with value for ESM, e.g. ",(0,r.jsx)(s.code,{children:"ES2015"})," or ",(0,r.jsx)(s.code,{children:"ES2020"})," etc..."]}),"\n"]}),"\n",(0,r.jsx)(s.h3,{id:"esm-presets",children:"ESM presets"}),"\n",(0,r.jsxs)(s.p,{children:["There are also ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/27.1/getting-started/presets",children:"3 presets"})," to work with ESM."]}),"\n",(0,r.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,r.jsx)(s.h4,{id:"manual-configuration",children:"Manual configuration"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n extensionsToTreatAsEsm: ['.ts'],\n globals: {\n 'ts-jest': {\n useESM: true,\n },\n },\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n}\n"})}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "extensionsToTreatAsEsm": [".ts"],\n "globals": {\n "ts-jest": {\n "useESM": true\n }\n },\n "moduleNameMapper": {\n "^(\\\\.{1,2}/.*)\\\\.js$": "$1"\n }\n }\n}\n'})}),"\n",(0,r.jsx)(s.h4,{id:"use-esm-presets",children:"Use ESM presets"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n preset: 'ts-jest/presets/default-esm', // or other ESM presets\n globals: {\n 'ts-jest': {\n useESM: true,\n },\n },\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n}\n"})}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "preset": "ts-jest/presets/default-esm", // or other ESM presets,\n "globals": {\n "ts-jest": {\n "useESM": true\n }\n },\n "moduleNameMapper": {\n "^(\\\\.{1,2}/.*)\\\\.js$": "$1"\n }\n }\n}\n'})})]})}function u(e={}){const{wrapper:s}={...(0,o.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(d,{...e})}):d(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>i,x:()=>c});var t=n(6540);const r={},o=t.createContext(r);function i(e){const s=t.useContext(o);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function c(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),t.createElement(o.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/3bfdd655.815c18b5.js b/assets/js/3bfdd655.50e26fcc.js similarity index 99% rename from assets/js/3bfdd655.815c18b5.js rename to assets/js/3bfdd655.50e26fcc.js index 88bc0bfb93..a4580d2bf9 100644 --- a/assets/js/3bfdd655.815c18b5.js +++ b/assets/js/3bfdd655.50e26fcc.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4798],{2805:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>c,contentTitle:()=>d,default:()=>j,frontMatter:()=>o,metadata:()=>n,toc:()=>l});const n=JSON.parse('{"id":"getting-started/presets","title":"Presets","description":"The presets","source":"@site/versioned_docs/version-26.5/getting-started/presets.md","sourceDirName":"getting-started","slug":"/getting-started/presets","permalink":"/ts-jest/docs/26.5/getting-started/presets","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/getting-started/presets.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"presets","title":"Presets"},"sidebar":"version-26.5-docs","previous":{"title":"Installation","permalink":"/ts-jest/docs/26.5/getting-started/installation"},"next":{"title":"Options","permalink":"/ts-jest/docs/26.5/getting-started/options"}}');var r=t(4848),i=t(8453);const o={id:"presets",title:"Presets"},d=void 0,c={},l=[{value:"The presets",id:"the-presets",level:3},{value:"Basic usage",id:"basic-usage",level:3},{value:"Advanced",id:"advanced",level:3}];function a(e){const s={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,i.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(s.h3,{id:"the-presets",children:"The presets"}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.code,{children:"ts-jest"})," comes with several presets, covering most of the project's base configuration:"]}),"\n",(0,r.jsxs)(s.table,{children:[(0,r.jsx)(s.thead,{children:(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.th,{children:"Preset name"}),(0,r.jsx)(s.th,{children:"Description"})]})}),(0,r.jsxs)(s.tbody,{children:[(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default"}),(0,r.jsx)("br",{}),"or ",(0,r.jsx)(s.code,{children:"ts-jest"})]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts"})}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel"})}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]})]})]}),"\n",(0,r.jsx)(s.h3,{id:"basic-usage",children:"Basic usage"}),"\n",(0,r.jsxs)(s.p,{children:["In most cases, simply setting the ",(0,r.jsx)(s.code,{children:"preset"})," key to the desired preset name in your Jest config should be enough to start using TypeScript with Jest (assuming you added ",(0,r.jsx)(s.code,{children:"ts-jest"})," to your dev. dependencies of course):"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n // Replace `ts-jest` with the preset you want to use\n // from the above list\n preset: 'ts-jest',\n}\n"})}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n // Replace `ts-jest` with the preset you want to use\n // from the above list\n "preset": "ts-jest"\n }\n}\n'})}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.strong,{children:"Note:"})," presets use ",(0,r.jsx)(s.code,{children:"testMatch"}),", like Jest does in its defaults. If you want to use ",(0,r.jsx)(s.code,{children:"testRegex"})," instead in your configuration, you MUST set ",(0,r.jsx)(s.code,{children:"testMatch"})," to ",(0,r.jsx)(s.code,{children:"null"})," or Jest will bail."]}),"\n",(0,r.jsx)(s.h3,{id:"advanced",children:"Advanced"}),"\n",(0,r.jsxs)(s.p,{children:["Any preset can also be used with other options.\nIf you're already using another preset, you might want only some specific settings from the chosen ",(0,r.jsx)(s.code,{children:"ts-jest"})," preset.\nIn this case you'll need to use the JavaScript version of Jest config (comment/uncomment according to your use-case):"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n// const { jsWithTs: tsjPreset } = require('ts-jest/presets')\n// const { jsWithBabel: tsjPreset } = require('ts-jest/presets')\n\nmodule.exports = {\n // [...]\n transform: {\n ...tsjPreset.transform,\n // [...]\n },\n}\n"})}),"\n",(0,r.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,r.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport type { InitialOptionsTsJest } from 'ts-jest/dist/types'\nimport { defaults as tsjPreset } from 'ts-jest/presets'\n// import { jsWithTs as tsjPreset } from 'ts-jest/presets'\n// import { jsWithBabel as tsjPreset } from 'ts-jest/presets'\nconst config: InitialOptionsTsJest = {\n // [...]\n transform: {\n ...tsjPreset.transform,\n // [...]\n },\n}\nexport default config\n"})})]})}function j(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(a,{...e})}):a(e)}},8453:(e,s,t)=>{t.d(s,{R:()=>o,x:()=>d});var n=t(6540);const r={},i=n.createContext(r);function o(e){const s=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function d(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),n.createElement(i.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4798],{2805:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>c,contentTitle:()=>d,default:()=>j,frontMatter:()=>o,metadata:()=>n,toc:()=>l});const n=JSON.parse('{"id":"getting-started/presets","title":"Presets","description":"The presets","source":"@site/versioned_docs/version-26.5/getting-started/presets.md","sourceDirName":"getting-started","slug":"/getting-started/presets","permalink":"/ts-jest/docs/26.5/getting-started/presets","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/getting-started/presets.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"presets","title":"Presets"},"sidebar":"version-26.5-docs","previous":{"title":"Installation","permalink":"/ts-jest/docs/26.5/getting-started/installation"},"next":{"title":"Options","permalink":"/ts-jest/docs/26.5/getting-started/options"}}');var r=t(4848),i=t(8453);const o={id:"presets",title:"Presets"},d=void 0,c={},l=[{value:"The presets",id:"the-presets",level:3},{value:"Basic usage",id:"basic-usage",level:3},{value:"Advanced",id:"advanced",level:3}];function a(e){const s={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,i.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(s.h3,{id:"the-presets",children:"The presets"}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.code,{children:"ts-jest"})," comes with several presets, covering most of the project's base configuration:"]}),"\n",(0,r.jsxs)(s.table,{children:[(0,r.jsx)(s.thead,{children:(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.th,{children:"Preset name"}),(0,r.jsx)(s.th,{children:"Description"})]})}),(0,r.jsxs)(s.tbody,{children:[(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default"}),(0,r.jsx)("br",{}),"or ",(0,r.jsx)(s.code,{children:"ts-jest"})]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts"})}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel"})}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]})]})]}),"\n",(0,r.jsx)(s.h3,{id:"basic-usage",children:"Basic usage"}),"\n",(0,r.jsxs)(s.p,{children:["In most cases, simply setting the ",(0,r.jsx)(s.code,{children:"preset"})," key to the desired preset name in your Jest config should be enough to start using TypeScript with Jest (assuming you added ",(0,r.jsx)(s.code,{children:"ts-jest"})," to your dev. dependencies of course):"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n // Replace `ts-jest` with the preset you want to use\n // from the above list\n preset: 'ts-jest',\n}\n"})}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n // Replace `ts-jest` with the preset you want to use\n // from the above list\n "preset": "ts-jest"\n }\n}\n'})}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.strong,{children:"Note:"})," presets use ",(0,r.jsx)(s.code,{children:"testMatch"}),", like Jest does in its defaults. If you want to use ",(0,r.jsx)(s.code,{children:"testRegex"})," instead in your configuration, you MUST set ",(0,r.jsx)(s.code,{children:"testMatch"})," to ",(0,r.jsx)(s.code,{children:"null"})," or Jest will bail."]}),"\n",(0,r.jsx)(s.h3,{id:"advanced",children:"Advanced"}),"\n",(0,r.jsxs)(s.p,{children:["Any preset can also be used with other options.\nIf you're already using another preset, you might want only some specific settings from the chosen ",(0,r.jsx)(s.code,{children:"ts-jest"})," preset.\nIn this case you'll need to use the JavaScript version of Jest config (comment/uncomment according to your use-case):"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n// const { jsWithTs: tsjPreset } = require('ts-jest/presets')\n// const { jsWithBabel: tsjPreset } = require('ts-jest/presets')\n\nmodule.exports = {\n // [...]\n transform: {\n ...tsjPreset.transform,\n // [...]\n },\n}\n"})}),"\n",(0,r.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,r.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport type { InitialOptionsTsJest } from 'ts-jest/dist/types'\nimport { defaults as tsjPreset } from 'ts-jest/presets'\n// import { jsWithTs as tsjPreset } from 'ts-jest/presets'\n// import { jsWithBabel as tsjPreset } from 'ts-jest/presets'\nconst config: InitialOptionsTsJest = {\n // [...]\n transform: {\n ...tsjPreset.transform,\n // [...]\n },\n}\nexport default config\n"})})]})}function j(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(a,{...e})}):a(e)}},8453:(e,s,t)=>{t.d(s,{R:()=>o,x:()=>d});var n=t(6540);const r={},i=n.createContext(r);function o(e){const s=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function d(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),n.createElement(i.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/3e930f87.764f2b98.js b/assets/js/3e930f87.eaf4b848.js similarity index 99% rename from assets/js/3e930f87.764f2b98.js rename to assets/js/3e930f87.eaf4b848.js index 2baaa7ef9f..b040d5c9a5 100644 --- a/assets/js/3e930f87.764f2b98.js +++ b/assets/js/3e930f87.eaf4b848.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2078],{3439:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>m,frontMatter:()=>i,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/compiler","title":"Compiler option","description":"The compiler option allows you to define the compiler to be used. It\'ll be used to load the NodeJS module holding the TypeScript compiler.","source":"@site/docs/getting-started/options/compiler.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/compiler","permalink":"/ts-jest/docs/next/getting-started/options/compiler","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/compiler.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Compiler option"}}');var r=s(4848),a=s(8453),o=s(9489),l=s(7227);const i={title:"Compiler option"},c=void 0,u={},d=[{value:"Example",id:"example",level:3}];function p(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["The ",(0,r.jsx)(t.code,{children:"compiler"})," option allows you to define the compiler to be used. It'll be used to load the NodeJS module holding the TypeScript compiler."]}),"\n",(0,r.jsxs)(t.p,{children:["The default value is ",(0,r.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,r.jsx)(t.a,{href:"https://www.npmjs.com/package/typescript",children:"TypeScript compiler module"}),".\nThe loaded version will depend on the one installed in your project."]}),"\n",(0,r.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,r.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,r.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,r.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n compiler: 'ttypescript',\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n compiler: 'ttypescript',\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "compiler": "ttypescript"\n }\n ]\n }\n }\n}\n'})})})]})]})}function m(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>o});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var a=s(4848);function o(e){let{children:t,hidden:s,className:o}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,o),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>w});var n=s(6540),r=s(4164),a=s(4245),o=s(6347),l=s(6494),i=s(2814),c=s(5167),u=s(9900);function d(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:r}}=e;return{value:t,label:s,attributes:n,default:r}}))}(s);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function m(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:s}=e;const r=(0,o.W6)(),a=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,i.aZ)(a),(0,n.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function f(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,a=p(e),[o,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:a}))),[c,d]=h({queryString:s,groupId:r}),[f,j]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,u.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&a.set(e)}),[s,a])]}({groupId:r}),x=(()=>{const e=c??f;return m({value:e,tabValues:a})?e:null})();(0,l.A)((()=>{x&&i(x)}),[x]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);i(e),d(e),j(e)}),[d,j,a]),tabValues:a}}var j=s(1062);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=s(4848);function g(e){let{className:t,block:s,selectedValue:n,selectValue:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,a.a_)(),u=e=>{const t=e.currentTarget,s=i.indexOf(t),r=l[s].value;r!==n&&(c(t),o(r))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const s=i.indexOf(e.currentTarget)+1;t=i[s]??i[0];break}case"ArrowLeft":{const s=i.indexOf(e.currentTarget)-1;t=i[s]??i[i.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":s},t),children:l.map((e=>{let{value:t,label:s,attributes:a}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:d,onClick:u,...a,className:(0,r.A)("tabs__item",x.tabItem,a?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:a}=e;const o=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=f(e);return(0,b.jsxs)("div",{className:(0,r.A)("tabs-container",x.tabList),children:[(0,b.jsx)(g,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function w(e){const t=(0,j.A)();return(0,b.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>o,x:()=>l});var n=s(6540);const r={},a=n.createContext(r);function o(e){const t=n.useContext(a);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),n.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2078],{3439:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>m,frontMatter:()=>i,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/compiler","title":"Compiler option","description":"The compiler option allows you to define the compiler to be used. It\'ll be used to load the NodeJS module holding the TypeScript compiler.","source":"@site/docs/getting-started/options/compiler.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/compiler","permalink":"/ts-jest/docs/next/getting-started/options/compiler","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/compiler.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Compiler option"}}');var r=s(4848),a=s(8453),o=s(9489),l=s(7227);const i={title:"Compiler option"},c=void 0,u={},d=[{value:"Example",id:"example",level:3}];function p(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["The ",(0,r.jsx)(t.code,{children:"compiler"})," option allows you to define the compiler to be used. It'll be used to load the NodeJS module holding the TypeScript compiler."]}),"\n",(0,r.jsxs)(t.p,{children:["The default value is ",(0,r.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,r.jsx)(t.a,{href:"https://www.npmjs.com/package/typescript",children:"TypeScript compiler module"}),".\nThe loaded version will depend on the one installed in your project."]}),"\n",(0,r.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,r.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,r.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,r.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n compiler: 'ttypescript',\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n compiler: 'ttypescript',\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "compiler": "ttypescript"\n }\n ]\n }\n }\n}\n'})})})]})]})}function m(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>o});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var a=s(4848);function o(e){let{children:t,hidden:s,className:o}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,o),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>w});var n=s(6540),r=s(4164),a=s(4245),o=s(6347),l=s(6494),i=s(2814),c=s(5167),u=s(9900);function d(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:r}}=e;return{value:t,label:s,attributes:n,default:r}}))}(s);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function m(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:s}=e;const r=(0,o.W6)(),a=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,i.aZ)(a),(0,n.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function f(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,a=p(e),[o,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:a}))),[c,d]=h({queryString:s,groupId:r}),[f,j]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,u.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&a.set(e)}),[s,a])]}({groupId:r}),x=(()=>{const e=c??f;return m({value:e,tabValues:a})?e:null})();(0,l.A)((()=>{x&&i(x)}),[x]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);i(e),d(e),j(e)}),[d,j,a]),tabValues:a}}var j=s(1062);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=s(4848);function g(e){let{className:t,block:s,selectedValue:n,selectValue:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,a.a_)(),u=e=>{const t=e.currentTarget,s=i.indexOf(t),r=l[s].value;r!==n&&(c(t),o(r))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const s=i.indexOf(e.currentTarget)+1;t=i[s]??i[0];break}case"ArrowLeft":{const s=i.indexOf(e.currentTarget)-1;t=i[s]??i[i.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":s},t),children:l.map((e=>{let{value:t,label:s,attributes:a}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:d,onClick:u,...a,className:(0,r.A)("tabs__item",x.tabItem,a?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:a}=e;const o=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=f(e);return(0,b.jsxs)("div",{className:(0,r.A)("tabs-container",x.tabList),children:[(0,b.jsx)(g,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function w(e){const t=(0,j.A)();return(0,b.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>o,x:()=>l});var n=s(6540);const r={},a=n.createContext(r);function o(e){const t=n.useContext(a);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),n.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/4040fa6b.96207318.js b/assets/js/4040fa6b.9ea385db.js similarity index 97% rename from assets/js/4040fa6b.96207318.js rename to assets/js/4040fa6b.9ea385db.js index 468cdc5a16..5d930bc9ba 100644 --- a/assets/js/4040fa6b.96207318.js +++ b/assets/js/4040fa6b.9ea385db.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9032],{9182:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>n,toc:()=>a});const n=JSON.parse('{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","source":"@site/versioned_docs/version-26.5/introduction.md","sourceDirName":".","slug":"/","permalink":"/ts-jest/docs/26.5/","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/introduction.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","slug":"/"},"sidebar":"version-26.5-docs","next":{"title":"Processing flow","permalink":"/ts-jest/docs/26.5/processing"}}');var o=s(4848),r=s(8453);const i={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},c=void 0,d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,r.R)(),...t.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(e.p,{children:[(0,o.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,o.jsx)(e.a,{href:"https://jestjs.io/docs/next/code-transformation#writing-custom-transformers",children:"transformer"})," with source map support that lets you use Jest to test projects written in TypeScript."]}),"\n",(0,o.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,o.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,o.jsx)(e.code,{children:"preset-typescript"})," ",(0,o.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,o.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,o.jsx)(e.admonition,{type:"important",children:(0,o.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,o.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,o.jsx)(e.code,{children:'npm i -D ts-jest@"<23.10.0"'})," to go back to the previous version"]})})]})}function u(t={}){const{wrapper:e}={...(0,r.R)(),...t.components};return e?(0,o.jsx)(e,{...t,children:(0,o.jsx)(p,{...t})}):p(t)}},8453:(t,e,s)=>{s.d(e,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(t){const e=n.useContext(r);return n.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function c(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:i(t.components),n.createElement(r.Provider,{value:e},t.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9032],{9182:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>n,toc:()=>a});const n=JSON.parse('{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","source":"@site/versioned_docs/version-26.5/introduction.md","sourceDirName":".","slug":"/","permalink":"/ts-jest/docs/26.5/","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/introduction.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","slug":"/"},"sidebar":"version-26.5-docs","next":{"title":"Processing flow","permalink":"/ts-jest/docs/26.5/processing"}}');var o=s(4848),r=s(8453);const i={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},c=void 0,d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,r.R)(),...t.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(e.p,{children:[(0,o.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,o.jsx)(e.a,{href:"https://jestjs.io/docs/next/code-transformation#writing-custom-transformers",children:"transformer"})," with source map support that lets you use Jest to test projects written in TypeScript."]}),"\n",(0,o.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,o.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,o.jsx)(e.code,{children:"preset-typescript"})," ",(0,o.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,o.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,o.jsx)(e.admonition,{type:"important",children:(0,o.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,o.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,o.jsx)(e.code,{children:'npm i -D ts-jest@"<23.10.0"'})," to go back to the previous version"]})})]})}function u(t={}){const{wrapper:e}={...(0,r.R)(),...t.components};return e?(0,o.jsx)(e,{...t,children:(0,o.jsx)(p,{...t})}):p(t)}},8453:(t,e,s)=>{s.d(e,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(t){const e=n.useContext(r);return n.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function c(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:i(t.components),n.createElement(r.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/44207808.3a269b4f.js b/assets/js/44207808.8f0ac8c9.js similarity index 99% rename from assets/js/44207808.3a269b4f.js rename to assets/js/44207808.8f0ac8c9.js index 9cf3b21bcb..6a406f5292 100644 --- a/assets/js/44207808.3a269b4f.js +++ b/assets/js/44207808.8f0ac8c9.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8120],{4407:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>r,contentTitle:()=>i,default:()=>b,frontMatter:()=>a,metadata:()=>t,toc:()=>c});const t=JSON.parse('{"id":"getting-started/options/babelConfig","title":"Babel Config option","description":"ts-jest by default does NOT use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ts-jest can call the BabelJest processor once TypeScript has transformed the source into JavaScript.","source":"@site/versioned_docs/version-26.5/getting-started/options/babelConfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/babelConfig","permalink":"/ts-jest/docs/26.5/getting-started/options/babelConfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/getting-started/options/babelConfig.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Babel Config option"}}');var o=s(4848),l=s(8453);const a={title:"Babel Config option"},i=void 0,r={},c=[{value:"Examples",id:"examples",level:3},{value:"Use default babelrc file",id:"use-default-babelrc-file",level:4},{value:"Path to a babelrc file",id:"path-to-a-babelrc-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4}];function d(e){const n={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,l.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:[(0,o.jsx)(n.code,{children:"ts-jest"})," by default does ",(0,o.jsx)(n.strong,{children:"NOT"})," use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ",(0,o.jsx)(n.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,o.jsxs)(n.p,{children:["The option is ",(0,o.jsx)(n.code,{children:"babelConfig"})," and it works pretty much as the ",(0,o.jsx)(n.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"true"}),": enables Babel processing. ",(0,o.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(n.code,{children:".babelrc"}),", ",(0,o.jsx)(n.code,{children:".babelrc.js"}),", ",(0,o.jsx)(n.code,{children:"babel.config.js"})," file or a ",(0,o.jsx)(n.code,{children:"babel"})," section in the ",(0,o.jsx)(n.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,o.jsx)(n.code,{children:"babel-jest"})," processor."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"{ ... }"}),": inline ",(0,o.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,o.jsx)(n.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,o.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsxs)(n.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,o.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: true,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "babelConfig": true\n }\n }\n }\n}\n'})}),"\n",(0,o.jsxs)(n.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,o.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,o.jsxs)(n.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,o.jsx)(n.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: 'babelrc.test.js',\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.p,{children:"or"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: require('./babelrc.test.js'),\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "babelConfig": "babelrc.test.js"\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,o.jsxs)(n.p,{children:["Refer to the ",(0,o.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: {\n comments: false,\n plugins: ['@babel/plugin-transform-for-of'],\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "babelConfig": {\n "comments": false,\n "plugins": ["@babel/plugin-transform-for-of"]\n }\n }\n }\n }\n}\n'})})]})}function b(e={}){const{wrapper:n}={...(0,l.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,n,s)=>{s.d(n,{R:()=>a,x:()=>i});var t=s(6540);const o={},l=t.createContext(o);function a(e){const n=t.useContext(l);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),t.createElement(l.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8120],{4407:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>r,contentTitle:()=>i,default:()=>b,frontMatter:()=>a,metadata:()=>t,toc:()=>c});const t=JSON.parse('{"id":"getting-started/options/babelConfig","title":"Babel Config option","description":"ts-jest by default does NOT use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ts-jest can call the BabelJest processor once TypeScript has transformed the source into JavaScript.","source":"@site/versioned_docs/version-26.5/getting-started/options/babelConfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/babelConfig","permalink":"/ts-jest/docs/26.5/getting-started/options/babelConfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/getting-started/options/babelConfig.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Babel Config option"}}');var o=s(4848),l=s(8453);const a={title:"Babel Config option"},i=void 0,r={},c=[{value:"Examples",id:"examples",level:3},{value:"Use default babelrc file",id:"use-default-babelrc-file",level:4},{value:"Path to a babelrc file",id:"path-to-a-babelrc-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4}];function d(e){const n={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,l.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:[(0,o.jsx)(n.code,{children:"ts-jest"})," by default does ",(0,o.jsx)(n.strong,{children:"NOT"})," use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ",(0,o.jsx)(n.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,o.jsxs)(n.p,{children:["The option is ",(0,o.jsx)(n.code,{children:"babelConfig"})," and it works pretty much as the ",(0,o.jsx)(n.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"true"}),": enables Babel processing. ",(0,o.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(n.code,{children:".babelrc"}),", ",(0,o.jsx)(n.code,{children:".babelrc.js"}),", ",(0,o.jsx)(n.code,{children:"babel.config.js"})," file or a ",(0,o.jsx)(n.code,{children:"babel"})," section in the ",(0,o.jsx)(n.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,o.jsx)(n.code,{children:"babel-jest"})," processor."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"{ ... }"}),": inline ",(0,o.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,o.jsx)(n.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,o.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsxs)(n.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,o.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: true,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "babelConfig": true\n }\n }\n }\n}\n'})}),"\n",(0,o.jsxs)(n.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,o.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,o.jsxs)(n.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,o.jsx)(n.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: 'babelrc.test.js',\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.p,{children:"or"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: require('./babelrc.test.js'),\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "babelConfig": "babelrc.test.js"\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,o.jsxs)(n.p,{children:["Refer to the ",(0,o.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: {\n comments: false,\n plugins: ['@babel/plugin-transform-for-of'],\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "babelConfig": {\n "comments": false,\n "plugins": ["@babel/plugin-transform-for-of"]\n }\n }\n }\n }\n}\n'})})]})}function b(e={}){const{wrapper:n}={...(0,l.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,n,s)=>{s.d(n,{R:()=>a,x:()=>i});var t=s(6540);const o={},l=t.createContext(o);function a(e){const n=t.useContext(l);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),t.createElement(l.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/44d840ac.741a6c7e.js b/assets/js/44d840ac.9f1c89dc.js similarity index 99% rename from assets/js/44d840ac.741a6c7e.js rename to assets/js/44d840ac.9f1c89dc.js index ba2ad112d3..d891323210 100644 --- a/assets/js/44d840ac.741a6c7e.js +++ b/assets/js/44d840ac.9f1c89dc.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5775],{9353:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>l,metadata:()=>i,toc:()=>d});const i=JSON.parse('{"id":"getting-started/options/diagnostics","title":"Diagnostics option","description":"The diagnostics option configures error reporting.","source":"@site/versioned_docs/version-26.5/getting-started/options/diagnostics.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/diagnostics","permalink":"/ts-jest/docs/26.5/getting-started/options/diagnostics","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/getting-started/options/diagnostics.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Diagnostics option"}}');var o=s(4848),t=s(8453);const l={title:"Diagnostics option"},r=void 0,c={},d=[{value:"Disabling/enabling",id:"disablingenabling",level:3},{value:"Advanced configuration",id:"advanced-configuration",level:3},{value:"Examples",id:"examples",level:3},{value:"Disabling diagnostics",id:"disabling-diagnostics",level:4},{value:"Advanced options",id:"advanced-options",level:4},{value:"Enabling diagnostics for test files only",id:"enabling-diagnostics-for-test-files-only",level:5},{value:"Do not fail on first error",id:"do-not-fail-on-first-error",level:5},{value:"Ignoring some error codes",id:"ignoring-some-error-codes",level:5}];function a(e){const n={a:"a",code:"code",em:"em",h3:"h3",h4:"h4",h5:"h5",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,t.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:["The ",(0,o.jsx)(n.code,{children:"diagnostics"})," option configures error reporting.\nIt can both be enabled/disabled entirely or limited to a specific type of errors and/or files."]}),"\n",(0,o.jsxs)(n.p,{children:["If a diagnostic is not filtered out, ",(0,o.jsx)(n.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,o.jsx)(n.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,o.jsxs)(n.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,o.jsx)(n.code,{children:"diagnostics"})," option to ",(0,o.jsx)(n.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,o.jsx)(n.code,{children:"diagnostics"})," to ",(0,o.jsx)(n.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,o.jsx)(n.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,o.jsxs)(n.p,{children:["The ",(0,o.jsx)(n.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"warnOnly"})}),": If specified and ",(0,o.jsx)(n.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,o.jsx)(n.em,{children:"disabled"}),")."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,o.jsx)(n.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". By default here are the ones ignored:","\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"6059"}),": ",(0,o.jsx)(n.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"18002"}),": ",(0,o.jsx)(n.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"18003"}),": ",(0,o.jsx)(n.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"pathRegex"})})," (",(0,o.jsx)(n.strong,{children:"DEPRECATED"}),"): If specified, diagnostics of source files which path does ",(0,o.jsx)(n.strong,{children:"not"})," match will be ignored."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,o.jsx)(n.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,o.jsx)(n.code,{children:"tsconfig"})," option ",(0,o.jsx)(n.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,o.jsx)(n.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,o.jsx)(n.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,o.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsx)(n.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: false,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": false\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,o.jsx)(n.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,o.jsxs)(n.p,{children:["Assuming all your test files ends with ",(0,o.jsx)(n.code,{children:".spec.ts"})," or ",(0,o.jsx)(n.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: {\n exclude: ['!**/*.(spec|test).ts'],\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": {\n "exclude": ["!**/*.(spec|test).ts"]\n }\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,o.jsxs)(n.p,{children:["While some diagnostics are stop-blockers for the compilation, most of them are not. If you want the compilation (and so your tests) to continue when encountering those, set the ",(0,o.jsx)(n.code,{children:"warnOnly"})," to ",(0,o.jsx)(n.code,{children:"true"}),":"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: {\n warnOnly: true,\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": {\n "warnOnly": true\n }\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,o.jsxs)(n.p,{children:["All TypeScript error codes can be found ",(0,o.jsx)(n.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,o.jsx)(n.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,o.jsxs)(n.ol,{children:["\n",(0,o.jsxs)(n.li,{children:["A single ",(0,o.jsx)(n.code,{children:"number"})," (example: ",(0,o.jsx)(n.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,o.jsxs)(n.li,{children:["A ",(0,o.jsx)(n.code,{children:"string"})," with a code (example ",(0,o.jsx)(n.code,{children:'"1009"'}),", ",(0,o.jsx)(n.code,{children:'"TS1009"'})," or ",(0,o.jsx)(n.code,{children:'"TS1009"'}),")"]}),"\n",(0,o.jsxs)(n.li,{children:["A ",(0,o.jsx)(n.code,{children:"string"})," with a list of the above (example: ",(0,o.jsx)(n.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,o.jsxs)(n.li,{children:["An ",(0,o.jsx)(n.code,{children:"array"})," of one or more from ",(0,o.jsx)(n.code,{children:"1"})," or ",(0,o.jsx)(n.code,{children:"3"})," (example: ",(0,o.jsx)(n.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: {\n ignoreCodes: [2571, 6031, 18003],\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": {\n "ignoreCodes": [2571, 6031, 18003]\n }\n }\n }\n }\n}\n'})})]})}function h(e={}){const{wrapper:n}={...(0,t.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(a,{...e})}):a(e)}},8453:(e,n,s)=>{s.d(n,{R:()=>l,x:()=>r});var i=s(6540);const o={},t=i.createContext(o);function l(e){const n=i.useContext(t);return i.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function r(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:l(e.components),i.createElement(t.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5775],{9353:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>l,metadata:()=>i,toc:()=>d});const i=JSON.parse('{"id":"getting-started/options/diagnostics","title":"Diagnostics option","description":"The diagnostics option configures error reporting.","source":"@site/versioned_docs/version-26.5/getting-started/options/diagnostics.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/diagnostics","permalink":"/ts-jest/docs/26.5/getting-started/options/diagnostics","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/getting-started/options/diagnostics.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Diagnostics option"}}');var o=s(4848),t=s(8453);const l={title:"Diagnostics option"},r=void 0,c={},d=[{value:"Disabling/enabling",id:"disablingenabling",level:3},{value:"Advanced configuration",id:"advanced-configuration",level:3},{value:"Examples",id:"examples",level:3},{value:"Disabling diagnostics",id:"disabling-diagnostics",level:4},{value:"Advanced options",id:"advanced-options",level:4},{value:"Enabling diagnostics for test files only",id:"enabling-diagnostics-for-test-files-only",level:5},{value:"Do not fail on first error",id:"do-not-fail-on-first-error",level:5},{value:"Ignoring some error codes",id:"ignoring-some-error-codes",level:5}];function a(e){const n={a:"a",code:"code",em:"em",h3:"h3",h4:"h4",h5:"h5",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,t.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:["The ",(0,o.jsx)(n.code,{children:"diagnostics"})," option configures error reporting.\nIt can both be enabled/disabled entirely or limited to a specific type of errors and/or files."]}),"\n",(0,o.jsxs)(n.p,{children:["If a diagnostic is not filtered out, ",(0,o.jsx)(n.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,o.jsx)(n.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,o.jsxs)(n.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,o.jsx)(n.code,{children:"diagnostics"})," option to ",(0,o.jsx)(n.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,o.jsx)(n.code,{children:"diagnostics"})," to ",(0,o.jsx)(n.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,o.jsx)(n.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,o.jsxs)(n.p,{children:["The ",(0,o.jsx)(n.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"warnOnly"})}),": If specified and ",(0,o.jsx)(n.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,o.jsx)(n.em,{children:"disabled"}),")."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,o.jsx)(n.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". By default here are the ones ignored:","\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"6059"}),": ",(0,o.jsx)(n.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"18002"}),": ",(0,o.jsx)(n.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"18003"}),": ",(0,o.jsx)(n.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"pathRegex"})})," (",(0,o.jsx)(n.strong,{children:"DEPRECATED"}),"): If specified, diagnostics of source files which path does ",(0,o.jsx)(n.strong,{children:"not"})," match will be ignored."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,o.jsx)(n.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,o.jsx)(n.code,{children:"tsconfig"})," option ",(0,o.jsx)(n.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,o.jsx)(n.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,o.jsx)(n.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,o.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsx)(n.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: false,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": false\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,o.jsx)(n.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,o.jsxs)(n.p,{children:["Assuming all your test files ends with ",(0,o.jsx)(n.code,{children:".spec.ts"})," or ",(0,o.jsx)(n.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: {\n exclude: ['!**/*.(spec|test).ts'],\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": {\n "exclude": ["!**/*.(spec|test).ts"]\n }\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,o.jsxs)(n.p,{children:["While some diagnostics are stop-blockers for the compilation, most of them are not. If you want the compilation (and so your tests) to continue when encountering those, set the ",(0,o.jsx)(n.code,{children:"warnOnly"})," to ",(0,o.jsx)(n.code,{children:"true"}),":"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: {\n warnOnly: true,\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": {\n "warnOnly": true\n }\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,o.jsxs)(n.p,{children:["All TypeScript error codes can be found ",(0,o.jsx)(n.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,o.jsx)(n.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,o.jsxs)(n.ol,{children:["\n",(0,o.jsxs)(n.li,{children:["A single ",(0,o.jsx)(n.code,{children:"number"})," (example: ",(0,o.jsx)(n.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,o.jsxs)(n.li,{children:["A ",(0,o.jsx)(n.code,{children:"string"})," with a code (example ",(0,o.jsx)(n.code,{children:'"1009"'}),", ",(0,o.jsx)(n.code,{children:'"TS1009"'})," or ",(0,o.jsx)(n.code,{children:'"TS1009"'}),")"]}),"\n",(0,o.jsxs)(n.li,{children:["A ",(0,o.jsx)(n.code,{children:"string"})," with a list of the above (example: ",(0,o.jsx)(n.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,o.jsxs)(n.li,{children:["An ",(0,o.jsx)(n.code,{children:"array"})," of one or more from ",(0,o.jsx)(n.code,{children:"1"})," or ",(0,o.jsx)(n.code,{children:"3"})," (example: ",(0,o.jsx)(n.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: {\n ignoreCodes: [2571, 6031, 18003],\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": {\n "ignoreCodes": [2571, 6031, 18003]\n }\n }\n }\n }\n}\n'})})]})}function h(e={}){const{wrapper:n}={...(0,t.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(a,{...e})}):a(e)}},8453:(e,n,s)=>{s.d(n,{R:()=>l,x:()=>r});var i=s(6540);const o={},t=i.createContext(o);function l(e){const n=i.useContext(t);return i.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function r(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:l(e.components),i.createElement(t.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/4aabdf82.d312f6b1.js b/assets/js/4aabdf82.2a45d1cb.js similarity index 98% rename from assets/js/4aabdf82.d312f6b1.js rename to assets/js/4aabdf82.2a45d1cb.js index e602007534..7ea5809dfa 100644 --- a/assets/js/4aabdf82.d312f6b1.js +++ b/assets/js/4aabdf82.2a45d1cb.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8639],{9023:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>r,metadata:()=>s,toc:()=>l});const s=JSON.parse('{"id":"babel7-or-ts","title":"Babel7 or TypeScript","description":"In Sept. 2018 Babel7 got released with an interesting preset: @babel/preset-typescript.","source":"@site/docs/babel7-or-ts.md","sourceDirName":".","slug":"/babel7-or-ts","permalink":"/ts-jest/docs/next/babel7-or-ts","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/babel7-or-ts.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"babel7-or-ts","title":"Babel7 or TypeScript"},"sidebar":"docs","previous":{"title":"Using with monorepo","permalink":"/ts-jest/docs/next/guides/using-with-monorepo"},"next":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/next/migration"}}');var i=n(4848),o=n(8453);const r={id:"babel7-or-ts",title:"Babel7 or TypeScript"},c=void 0,a={},l=[{value:"Limitations",id:"limitations",level:2},{value:"No type-checking",id:"no-type-checking",level:4},{value:"No namespace",id:"no-namespace",level:4},{value:"No const enum",id:"no-const-enum",level:4},{value:"No declaration merging (enum, namespace, ...)",id:"no-declaration-merging-enum-namespace-",level:4},{value:"No legacy import/export",id:"no-legacy-importexport",level:4},{value:"No caret type-casting with JSX enabled",id:"no-caret-type-casting-with-jsx-enabled",level:4}];function d(e){const t={a:"a",code:"code",h2:"h2",h4:"h4",hr:"hr",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,i.jsxs)(t.p,{children:["The goal is to make it easy for users using Babel to try TypeScript without moving out from Babel, just by adding a preset in their Babel config (here is the ",(0,i.jsx)(t.a,{href:"https://blogs.msdn.microsoft.com/typescript/2018/08/27/typescript-and-babel-7/",children:"MSDN blog post"})," about TypeScript and Babel 7)."]}),"\n",(0,i.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,i.jsxs)(t.p,{children:["While ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"})," is a great preset, you must know the limitation of it. Here is what is possible with TypeScript (and ",(0,i.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,i.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,i.jsxs)(t.p,{children:["This is the big ",(0,i.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,i.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,i.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,i.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,i.jsx)(t.p,{children:'With Babel, files are transpiled as isolated modules, there is no notion of "project". With TypeScript, files are part of a project and are compiled in that scope.'}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,i.jsx)(t.code,{children:"namespace"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"namespace app {\n export const VERSION = '1.0.0'\n export class App {\n /* ... */\n }\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,i.jsx)(t.code,{children:"const enum"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,i.jsx)(t.code,{children:"enum"}),", ",(0,i.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,i.jsxs)(t.p,{children:["You won't be able to do ",(0,i.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,i.jsx)(t.code,{children:"import"}),"/",(0,i.jsx)(t.code,{children:"export"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>c});var s=n(6540);const i={},o=s.createContext(i);function r(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8639],{9023:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>r,metadata:()=>s,toc:()=>l});const s=JSON.parse('{"id":"babel7-or-ts","title":"Babel7 or TypeScript","description":"In Sept. 2018 Babel7 got released with an interesting preset: @babel/preset-typescript.","source":"@site/docs/babel7-or-ts.md","sourceDirName":".","slug":"/babel7-or-ts","permalink":"/ts-jest/docs/next/babel7-or-ts","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/babel7-or-ts.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"babel7-or-ts","title":"Babel7 or TypeScript"},"sidebar":"docs","previous":{"title":"Using with monorepo","permalink":"/ts-jest/docs/next/guides/using-with-monorepo"},"next":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/next/migration"}}');var i=n(4848),o=n(8453);const r={id:"babel7-or-ts",title:"Babel7 or TypeScript"},c=void 0,a={},l=[{value:"Limitations",id:"limitations",level:2},{value:"No type-checking",id:"no-type-checking",level:4},{value:"No namespace",id:"no-namespace",level:4},{value:"No const enum",id:"no-const-enum",level:4},{value:"No declaration merging (enum, namespace, ...)",id:"no-declaration-merging-enum-namespace-",level:4},{value:"No legacy import/export",id:"no-legacy-importexport",level:4},{value:"No caret type-casting with JSX enabled",id:"no-caret-type-casting-with-jsx-enabled",level:4}];function d(e){const t={a:"a",code:"code",h2:"h2",h4:"h4",hr:"hr",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,i.jsxs)(t.p,{children:["The goal is to make it easy for users using Babel to try TypeScript without moving out from Babel, just by adding a preset in their Babel config (here is the ",(0,i.jsx)(t.a,{href:"https://blogs.msdn.microsoft.com/typescript/2018/08/27/typescript-and-babel-7/",children:"MSDN blog post"})," about TypeScript and Babel 7)."]}),"\n",(0,i.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,i.jsxs)(t.p,{children:["While ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"})," is a great preset, you must know the limitation of it. Here is what is possible with TypeScript (and ",(0,i.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,i.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,i.jsxs)(t.p,{children:["This is the big ",(0,i.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,i.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,i.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,i.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,i.jsx)(t.p,{children:'With Babel, files are transpiled as isolated modules, there is no notion of "project". With TypeScript, files are part of a project and are compiled in that scope.'}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,i.jsx)(t.code,{children:"namespace"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"namespace app {\n export const VERSION = '1.0.0'\n export class App {\n /* ... */\n }\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,i.jsx)(t.code,{children:"const enum"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,i.jsx)(t.code,{children:"enum"}),", ",(0,i.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,i.jsxs)(t.p,{children:["You won't be able to do ",(0,i.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,i.jsx)(t.code,{children:"import"}),"/",(0,i.jsx)(t.code,{children:"export"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>c});var s=n(6540);const i={},o=s.createContext(i);function r(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/4c23203f.72c02dac.js b/assets/js/4c23203f.ae730044.js similarity index 98% rename from assets/js/4c23203f.72c02dac.js rename to assets/js/4c23203f.ae730044.js index 2f5e1493cc..c6c61ca40f 100644 --- a/assets/js/4c23203f.72c02dac.js +++ b/assets/js/4c23203f.ae730044.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8468],{8592:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>r,contentTitle:()=>a,default:()=>p,frontMatter:()=>c,metadata:()=>n,toc:()=>l});const n=JSON.parse('{"id":"guides/react-native","title":"Using with React Native","description":"To use ts-jest with React Native + TypeScript and Babel 7, you\'ll first need to follow this tutorial.","source":"@site/versioned_docs/version-26.5/guides/react-native.md","sourceDirName":"guides","slug":"/guides/react-native","permalink":"/ts-jest/docs/26.5/guides/react-native","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/guides/react-native.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"react-native","title":"Using with React Native"},"sidebar":"version-26.5-docs","previous":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/26.5/guides/mock-es6-class"},"next":{"title":"Test helpers","permalink":"/ts-jest/docs/26.5/guides/test-helpers"}}');var i=s(4848),o=s(8453);const c={id:"react-native",title:"Using with React Native"},a=void 0,r={},l=[{value:"Babel config",id:"babel-config",level:3},{value:"TypeScript Configuration",id:"typescript-configuration",level:3},{value:"Jest config",id:"jest-config",level:3}];function d(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["To use ",(0,i.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,i.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,i.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,i.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,i.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,i.jsx)(t.code,{children:".babelrc"})," to ",(0,i.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"// babel.config.js\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n"})}),"\n",(0,i.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,i.jsxs)(t.p,{children:["Create a new ",(0,i.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-json",children:'// tsconfig.spec.json\n{\n "extends": "./tsconfig.json",\n "compilerOptions": {\n "jsx": "react"\n }\n}\n'})}),"\n",(0,i.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,i.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,i.jsx)(t.code,{children:"jest"})," key of ",(0,i.jsx)(t.code,{children:"package.json"})," to ",(0,i.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n preset: 'react-native',\n globals: {\n 'ts-jest': {\n tsconfig: 'tsconfig.spec.json',\n },\n },\n transform: {\n '^.+\\\\.jsx$': 'babel-jest',\n '^.+\\\\.tsx?$': 'ts-jest',\n },\n moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],\n}\n"})})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>c,x:()=>a});var n=s(6540);const i={},o=n.createContext(i);function c(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:c(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8468],{8592:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>r,contentTitle:()=>a,default:()=>p,frontMatter:()=>c,metadata:()=>n,toc:()=>l});const n=JSON.parse('{"id":"guides/react-native","title":"Using with React Native","description":"To use ts-jest with React Native + TypeScript and Babel 7, you\'ll first need to follow this tutorial.","source":"@site/versioned_docs/version-26.5/guides/react-native.md","sourceDirName":"guides","slug":"/guides/react-native","permalink":"/ts-jest/docs/26.5/guides/react-native","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/guides/react-native.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"react-native","title":"Using with React Native"},"sidebar":"version-26.5-docs","previous":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/26.5/guides/mock-es6-class"},"next":{"title":"Test helpers","permalink":"/ts-jest/docs/26.5/guides/test-helpers"}}');var i=s(4848),o=s(8453);const c={id:"react-native",title:"Using with React Native"},a=void 0,r={},l=[{value:"Babel config",id:"babel-config",level:3},{value:"TypeScript Configuration",id:"typescript-configuration",level:3},{value:"Jest config",id:"jest-config",level:3}];function d(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["To use ",(0,i.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,i.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,i.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,i.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,i.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,i.jsx)(t.code,{children:".babelrc"})," to ",(0,i.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"// babel.config.js\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n"})}),"\n",(0,i.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,i.jsxs)(t.p,{children:["Create a new ",(0,i.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-json",children:'// tsconfig.spec.json\n{\n "extends": "./tsconfig.json",\n "compilerOptions": {\n "jsx": "react"\n }\n}\n'})}),"\n",(0,i.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,i.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,i.jsx)(t.code,{children:"jest"})," key of ",(0,i.jsx)(t.code,{children:"package.json"})," to ",(0,i.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n preset: 'react-native',\n globals: {\n 'ts-jest': {\n tsconfig: 'tsconfig.spec.json',\n },\n },\n transform: {\n '^.+\\\\.jsx$': 'babel-jest',\n '^.+\\\\.tsx?$': 'ts-jest',\n },\n moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],\n}\n"})})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>c,x:()=>a});var n=s(6540);const i={},o=n.createContext(i);function c(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:c(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/4c757249.9bb387a9.js b/assets/js/4c757249.c1884e45.js similarity index 98% rename from assets/js/4c757249.9bb387a9.js rename to assets/js/4c757249.c1884e45.js index 3ec47febcf..0b74081ddb 100644 --- a/assets/js/4c757249.9bb387a9.js +++ b/assets/js/4c757249.c1884e45.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[10],{4442:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>d,frontMatter:()=>r,metadata:()=>n,toc:()=>h});const n=JSON.parse('{"id":"contributing","title":"Contributing","description":"When contributing to this repository, please first discuss the change you wish to make via ts-jest GitHub discussion or issue with the owners of this repository before making a change.","source":"@site/versioned_docs/version-27.0/contributing.md","sourceDirName":".","slug":"/contributing","permalink":"/ts-jest/docs/27.0/contributing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/contributing.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"contributing","title":"Contributing"},"sidebar":"version-27.0-docs","previous":{"title":"Processing flow","permalink":"/ts-jest/docs/27.0/processing"},"next":{"title":"Installation","permalink":"/ts-jest/docs/27.0/getting-started/installation"}}');var i=s(4848),o=s(8453);const r={id:"contributing",title:"Contributing"},c=void 0,a={},h=[{value:"Pull Request Process",id:"pull-request-process",level:2},{value:"E2E Testing",id:"e2e-testing",level:2},{value:"Preparing",id:"preparing",level:3},{value:"Running",id:"running",level:3}];function l(e){const t={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,i.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,i.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,i.jsx)(t.a,{href:"https://github.com/kulshekhar/ts-jest/issues",children:"issue"})," with the owners of this repository before making a change."]}),"\n",(0,i.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,i.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,i.jsxs)(t.ol,{children:["\n",(0,i.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,i.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,i.jsxs)(t.li,{children:["Update the ",(0,i.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,i.jsx)(t.li,{children:"If possible, squash your commits. There must be only one commit in your PR (until a review). Then after each review requesting changes, DO NOT squash your commits with the one before the review, so that we can see intermediate modifications."}),"\n",(0,i.jsx)(t.li,{children:"You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you."}),"\n"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,i.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,i.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,i.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,i.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,i.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLBBRgGm4BpxA-eMEAmYxH6EEUrNW0StG--ODh9xGkQotnxP32D6YQ8z8L5TZovtKXlLcEPq5US9cdxzfQIjaQ24oET9pShUutHbxtOO9nf390oHhBASeHDXKp0a3fbiJ5DWWjAyO0tn0iVnIRcdt_Jwh-iow3XswJPxbalNzSZV10rWDVGnqA88WhS_87dd66GcqNGmMoVsX6eC4MI7gPXwgrGV_VQV2JOIMB07U01TzzeVL7b4jMClwLw2uqY3XdYhyzw2YZuuQQfDi_AIUr3q4XnrSt1NJwdVzYQV29K4nMD-AwZDXZpcmi9omyYU4iOOPXoi7SUjZKEATWkusE5YpmGVXajXVyaLoJhCfDPPjQqn0F0ZSx89msJbJAukqq0JQGxlzErg-uWiCrYIMkzHXOY1w-_1nnsLcxdFb89Auq_eJvd-JpDJvKMVsLldHMMDh8JhugpIKqzVd-p-KYJkVd0k2DN6D2N1uxnouRVMcAHX-GG0"}),"\n",(0,i.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,i.jsxs)(t.p,{children:["When a test-case needs to be run with a given template within tests, here is what's happening (in ",(0,i.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/hLHDRzim3BthLn3OOGcsfC2E3R2TUzfFI1I9ZjN8f23IJOAX--s3PBknksAdtGoQ7-yzFahKPZNcqMMqYd3XV0OVyiuGAq8EfrRDatwE4Ou8FZGDPYI5X1aKHJVE2XfBVenqAPOsHoj1jWR9G-bZDjy1l-73x_s-3F0Xx-NMnK3d_VxXrrJrMZx7bgyxOq83gzOAM23skE_Ozn6beFkn1csHO7L3MPl7iTSYRIGGiL5ZNpXuoBZ9FL6W4r3g892eZT4qd06jQoiTABEXq9b0xUuaC0h2YdXTGg4fed6wGHCAgYPpDokQgMTZ77C2tHNo8OFDQ1odW1wKP_Ed9HYyEamAXpcnGu5d3icwiptX9h8xRv-5wN07QYvjY0YhDsfb_31z6k53NbU1Wu2GJTAork27mjuDKVMS2kekq2ddW5BOm5Y0tYm82VVP3Po5GLkhfa_UQjc5jjZ1XVleeSO6e2sQiQZXw37FoDKrZD2VKNJhc9fmsZxB0dp9MFw68D3qv3GmlNEGAqkw16qXsUflnwH8kd1HZ7mHQBZiHOi5wFGFSmm1rXPpdS3fzYzRBAKoeprWPe_sFnXZm8RagqFkPoy9NR0Ze0LCuUxTxm5NhQjhRYtvYD0odwiwW5VRfLZFo9ooFS8XPNOeibeVuEbdpIatK6WaT6hBGcI6yd4qmaYbibY2GWKBhXVb3ewzGXEkw85iDxn5BvWbC1LbvptANRYssA0IQe8RXJLt_R-ydUWCq2VbpYe_vdvObUp-lh7fADQb_weB8iNTyzr-v8AXosLsESjkOgOJktq5makyJTBFKW81CG5UWzIJAkQvX1Y1i7h77D-Cn2-O8P2o6T_Z0ao6LtXwUcUclXibe_QP8AFqiV8NvVG7"})]})}function d(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>r,x:()=>c});var n=s(6540);const i={},o=n.createContext(i);function r(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[10],{4442:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>d,frontMatter:()=>r,metadata:()=>n,toc:()=>h});const n=JSON.parse('{"id":"contributing","title":"Contributing","description":"When contributing to this repository, please first discuss the change you wish to make via ts-jest GitHub discussion or issue with the owners of this repository before making a change.","source":"@site/versioned_docs/version-27.0/contributing.md","sourceDirName":".","slug":"/contributing","permalink":"/ts-jest/docs/27.0/contributing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/contributing.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"contributing","title":"Contributing"},"sidebar":"version-27.0-docs","previous":{"title":"Processing flow","permalink":"/ts-jest/docs/27.0/processing"},"next":{"title":"Installation","permalink":"/ts-jest/docs/27.0/getting-started/installation"}}');var i=s(4848),o=s(8453);const r={id:"contributing",title:"Contributing"},c=void 0,a={},h=[{value:"Pull Request Process",id:"pull-request-process",level:2},{value:"E2E Testing",id:"e2e-testing",level:2},{value:"Preparing",id:"preparing",level:3},{value:"Running",id:"running",level:3}];function l(e){const t={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,i.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,i.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,i.jsx)(t.a,{href:"https://github.com/kulshekhar/ts-jest/issues",children:"issue"})," with the owners of this repository before making a change."]}),"\n",(0,i.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,i.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,i.jsxs)(t.ol,{children:["\n",(0,i.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,i.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,i.jsxs)(t.li,{children:["Update the ",(0,i.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,i.jsx)(t.li,{children:"If possible, squash your commits. There must be only one commit in your PR (until a review). Then after each review requesting changes, DO NOT squash your commits with the one before the review, so that we can see intermediate modifications."}),"\n",(0,i.jsx)(t.li,{children:"You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you."}),"\n"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,i.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,i.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,i.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,i.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,i.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLBBRgGm4BpxA-eMEAmYxH6EEUrNW0StG--ODh9xGkQotnxP32D6YQ8z8L5TZovtKXlLcEPq5US9cdxzfQIjaQ24oET9pShUutHbxtOO9nf390oHhBASeHDXKp0a3fbiJ5DWWjAyO0tn0iVnIRcdt_Jwh-iow3XswJPxbalNzSZV10rWDVGnqA88WhS_87dd66GcqNGmMoVsX6eC4MI7gPXwgrGV_VQV2JOIMB07U01TzzeVL7b4jMClwLw2uqY3XdYhyzw2YZuuQQfDi_AIUr3q4XnrSt1NJwdVzYQV29K4nMD-AwZDXZpcmi9omyYU4iOOPXoi7SUjZKEATWkusE5YpmGVXajXVyaLoJhCfDPPjQqn0F0ZSx89msJbJAukqq0JQGxlzErg-uWiCrYIMkzHXOY1w-_1nnsLcxdFb89Auq_eJvd-JpDJvKMVsLldHMMDh8JhugpIKqzVd-p-KYJkVd0k2DN6D2N1uxnouRVMcAHX-GG0"}),"\n",(0,i.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,i.jsxs)(t.p,{children:["When a test-case needs to be run with a given template within tests, here is what's happening (in ",(0,i.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/hLHDRzim3BthLn3OOGcsfC2E3R2TUzfFI1I9ZjN8f23IJOAX--s3PBknksAdtGoQ7-yzFahKPZNcqMMqYd3XV0OVyiuGAq8EfrRDatwE4Ou8FZGDPYI5X1aKHJVE2XfBVenqAPOsHoj1jWR9G-bZDjy1l-73x_s-3F0Xx-NMnK3d_VxXrrJrMZx7bgyxOq83gzOAM23skE_Ozn6beFkn1csHO7L3MPl7iTSYRIGGiL5ZNpXuoBZ9FL6W4r3g892eZT4qd06jQoiTABEXq9b0xUuaC0h2YdXTGg4fed6wGHCAgYPpDokQgMTZ77C2tHNo8OFDQ1odW1wKP_Ed9HYyEamAXpcnGu5d3icwiptX9h8xRv-5wN07QYvjY0YhDsfb_31z6k53NbU1Wu2GJTAork27mjuDKVMS2kekq2ddW5BOm5Y0tYm82VVP3Po5GLkhfa_UQjc5jjZ1XVleeSO6e2sQiQZXw37FoDKrZD2VKNJhc9fmsZxB0dp9MFw68D3qv3GmlNEGAqkw16qXsUflnwH8kd1HZ7mHQBZiHOi5wFGFSmm1rXPpdS3fzYzRBAKoeprWPe_sFnXZm8RagqFkPoy9NR0Ze0LCuUxTxm5NhQjhRYtvYD0odwiwW5VRfLZFo9ooFS8XPNOeibeVuEbdpIatK6WaT6hBGcI6yd4qmaYbibY2GWKBhXVb3ewzGXEkw85iDxn5BvWbC1LbvptANRYssA0IQe8RXJLt_R-ydUWCq2VbpYe_vdvObUp-lh7fADQb_weB8iNTyzr-v8AXosLsESjkOgOJktq5makyJTBFKW81CG5UWzIJAkQvX1Y1i7h77D-Cn2-O8P2o6T_Z0ao6LtXwUcUclXibe_QP8AFqiV8NvVG7"})]})}function d(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>r,x:()=>c});var n=s(6540);const i={},o=n.createContext(i);function r(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/4d54d076.0dbbf9af.js b/assets/js/4d54d076.d01053ce.js similarity index 98% rename from assets/js/4d54d076.0dbbf9af.js rename to assets/js/4d54d076.d01053ce.js index 3bb97e6c1f..49fbcca51c 100644 --- a/assets/js/4d54d076.0dbbf9af.js +++ b/assets/js/4d54d076.d01053ce.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1459],{4776:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>d,frontMatter:()=>r,metadata:()=>n,toc:()=>h});const n=JSON.parse('{"id":"contributing","title":"Contributing","description":"When contributing to this repository, please first discuss the change you wish to make via ts-jest GitHub discussion or issue with the owners of this repository before making a change.","source":"@site/docs/contributing.md","sourceDirName":".","slug":"/contributing","permalink":"/ts-jest/docs/next/contributing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/contributing.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"contributing","title":"Contributing"},"sidebar":"docs","previous":{"title":"Processing flow","permalink":"/ts-jest/docs/next/processing"},"next":{"title":"Installation","permalink":"/ts-jest/docs/next/getting-started/installation"}}');var i=s(4848),o=s(8453);const r={id:"contributing",title:"Contributing"},c=void 0,a={},h=[{value:"Pull Request Process",id:"pull-request-process",level:2},{value:"E2E Testing",id:"e2e-testing",level:2},{value:"Preparing",id:"preparing",level:3},{value:"Running",id:"running",level:3}];function l(e){const t={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,i.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,i.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,i.jsx)(t.a,{href:"https://github.com/kulshekhar/ts-jest/issues",children:"issue"})," with the owners of this repository before making a change."]}),"\n",(0,i.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,i.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,i.jsxs)(t.ol,{children:["\n",(0,i.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,i.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,i.jsxs)(t.li,{children:["Update the ",(0,i.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,i.jsx)(t.li,{children:"If possible, squash your commits. There must be only one commit in your PR (until a review). Then after each review requesting changes, DO NOT squash your commits with the one before the review, so that we can see intermediate modifications."}),"\n",(0,i.jsx)(t.li,{children:"You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you."}),"\n"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,i.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,i.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,i.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,i.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,i.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLBBRgGm4BpxA-eMEAmYxH6EEUrNW0StG--ODh9xGkQotnxP32D6YQ8z8L5TZovtKXlLcEPq5US9cdxzfQIjaQ24oET9pShUutHbxtOO9nf390oHhBASeHDXKp0a3fbiJ5DWWjAyO0tn0iVnIRcdt_Jwh-iow3XswJPxbalNzSZV10rWDVGnqA88WhS_87dd66GcqNGmMoVsX6eC4MI7gPXwgrGV_VQV2JOIMB07U01TzzeVL7b4jMClwLw2uqY3XdYhyzw2YZuuQQfDi_AIUr3q4XnrSt1NJwdVzYQV29K4nMD-AwZDXZpcmi9omyYU4iOOPXoi7SUjZKEATWkusE5YpmGVXajXVyaLoJhCfDPPjQqn0F0ZSx89msJbJAukqq0JQGxlzErg-uWiCrYIMkzHXOY1w-_1nnsLcxdFb89Auq_eJvd-JpDJvKMVsLldHMMDh8JhugpIKqzVd-p-KYJkVd0k2DN6D2N1uxnouRVMcAHX-GG0"}),"\n",(0,i.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,i.jsxs)(t.p,{children:["When a test-case needs to be run with a given template within tests, here is what's happening (in ",(0,i.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/hLHDRzim3BthLn3OOGcsfC2E3R2TUzfFI1I9ZjN8f23IJOAX--s3PBknksAdtGoQ7-yzFahKPZNcqMMqYd3XV0OVyiuGAq8EfrRDatwE4Ou8FZGDPYI5X1aKHJVE2XfBVenqAPOsHoj1jWR9G-bZDjy1l-73x_s-3F0Xx-NMnK3d_VxXrrJrMZx7bgyxOq83gzOAM23skE_Ozn6beFkn1csHO7L3MPl7iTSYRIGGiL5ZNpXuoBZ9FL6W4r3g892eZT4qd06jQoiTABEXq9b0xUuaC0h2YdXTGg4fed6wGHCAgYPpDokQgMTZ77C2tHNo8OFDQ1odW1wKP_Ed9HYyEamAXpcnGu5d3icwiptX9h8xRv-5wN07QYvjY0YhDsfb_31z6k53NbU1Wu2GJTAork27mjuDKVMS2kekq2ddW5BOm5Y0tYm82VVP3Po5GLkhfa_UQjc5jjZ1XVleeSO6e2sQiQZXw37FoDKrZD2VKNJhc9fmsZxB0dp9MFw68D3qv3GmlNEGAqkw16qXsUflnwH8kd1HZ7mHQBZiHOi5wFGFSmm1rXPpdS3fzYzRBAKoeprWPe_sFnXZm8RagqFkPoy9NR0Ze0LCuUxTxm5NhQjhRYtvYD0odwiwW5VRfLZFo9ooFS8XPNOeibeVuEbdpIatK6WaT6hBGcI6yd4qmaYbibY2GWKBhXVb3ewzGXEkw85iDxn5BvWbC1LbvptANRYssA0IQe8RXJLt_R-ydUWCq2VbpYe_vdvObUp-lh7fADQb_weB8iNTyzr-v8AXosLsESjkOgOJktq5makyJTBFKW81CG5UWzIJAkQvX1Y1i7h77D-Cn2-O8P2o6T_Z0ao6LtXwUcUclXibe_QP8AFqiV8NvVG7"})]})}function d(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>r,x:()=>c});var n=s(6540);const i={},o=n.createContext(i);function r(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1459],{4776:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>d,frontMatter:()=>r,metadata:()=>n,toc:()=>h});const n=JSON.parse('{"id":"contributing","title":"Contributing","description":"When contributing to this repository, please first discuss the change you wish to make via ts-jest GitHub discussion or issue with the owners of this repository before making a change.","source":"@site/docs/contributing.md","sourceDirName":".","slug":"/contributing","permalink":"/ts-jest/docs/next/contributing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/contributing.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"contributing","title":"Contributing"},"sidebar":"docs","previous":{"title":"Processing flow","permalink":"/ts-jest/docs/next/processing"},"next":{"title":"Installation","permalink":"/ts-jest/docs/next/getting-started/installation"}}');var i=s(4848),o=s(8453);const r={id:"contributing",title:"Contributing"},c=void 0,a={},h=[{value:"Pull Request Process",id:"pull-request-process",level:2},{value:"E2E Testing",id:"e2e-testing",level:2},{value:"Preparing",id:"preparing",level:3},{value:"Running",id:"running",level:3}];function l(e){const t={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,i.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,i.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,i.jsx)(t.a,{href:"https://github.com/kulshekhar/ts-jest/issues",children:"issue"})," with the owners of this repository before making a change."]}),"\n",(0,i.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,i.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,i.jsxs)(t.ol,{children:["\n",(0,i.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,i.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,i.jsxs)(t.li,{children:["Update the ",(0,i.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,i.jsx)(t.li,{children:"If possible, squash your commits. There must be only one commit in your PR (until a review). Then after each review requesting changes, DO NOT squash your commits with the one before the review, so that we can see intermediate modifications."}),"\n",(0,i.jsx)(t.li,{children:"You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you."}),"\n"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,i.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,i.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,i.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,i.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,i.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLBBRgGm4BpxA-eMEAmYxH6EEUrNW0StG--ODh9xGkQotnxP32D6YQ8z8L5TZovtKXlLcEPq5US9cdxzfQIjaQ24oET9pShUutHbxtOO9nf390oHhBASeHDXKp0a3fbiJ5DWWjAyO0tn0iVnIRcdt_Jwh-iow3XswJPxbalNzSZV10rWDVGnqA88WhS_87dd66GcqNGmMoVsX6eC4MI7gPXwgrGV_VQV2JOIMB07U01TzzeVL7b4jMClwLw2uqY3XdYhyzw2YZuuQQfDi_AIUr3q4XnrSt1NJwdVzYQV29K4nMD-AwZDXZpcmi9omyYU4iOOPXoi7SUjZKEATWkusE5YpmGVXajXVyaLoJhCfDPPjQqn0F0ZSx89msJbJAukqq0JQGxlzErg-uWiCrYIMkzHXOY1w-_1nnsLcxdFb89Auq_eJvd-JpDJvKMVsLldHMMDh8JhugpIKqzVd-p-KYJkVd0k2DN6D2N1uxnouRVMcAHX-GG0"}),"\n",(0,i.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,i.jsxs)(t.p,{children:["When a test-case needs to be run with a given template within tests, here is what's happening (in ",(0,i.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/hLHDRzim3BthLn3OOGcsfC2E3R2TUzfFI1I9ZjN8f23IJOAX--s3PBknksAdtGoQ7-yzFahKPZNcqMMqYd3XV0OVyiuGAq8EfrRDatwE4Ou8FZGDPYI5X1aKHJVE2XfBVenqAPOsHoj1jWR9G-bZDjy1l-73x_s-3F0Xx-NMnK3d_VxXrrJrMZx7bgyxOq83gzOAM23skE_Ozn6beFkn1csHO7L3MPl7iTSYRIGGiL5ZNpXuoBZ9FL6W4r3g892eZT4qd06jQoiTABEXq9b0xUuaC0h2YdXTGg4fed6wGHCAgYPpDokQgMTZ77C2tHNo8OFDQ1odW1wKP_Ed9HYyEamAXpcnGu5d3icwiptX9h8xRv-5wN07QYvjY0YhDsfb_31z6k53NbU1Wu2GJTAork27mjuDKVMS2kekq2ddW5BOm5Y0tYm82VVP3Po5GLkhfa_UQjc5jjZ1XVleeSO6e2sQiQZXw37FoDKrZD2VKNJhc9fmsZxB0dp9MFw68D3qv3GmlNEGAqkw16qXsUflnwH8kd1HZ7mHQBZiHOi5wFGFSmm1rXPpdS3fzYzRBAKoeprWPe_sFnXZm8RagqFkPoy9NR0Ze0LCuUxTxm5NhQjhRYtvYD0odwiwW5VRfLZFo9ooFS8XPNOeibeVuEbdpIatK6WaT6hBGcI6yd4qmaYbibY2GWKBhXVb3ewzGXEkw85iDxn5BvWbC1LbvptANRYssA0IQe8RXJLt_R-ydUWCq2VbpYe_vdvObUp-lh7fADQb_weB8iNTyzr-v8AXosLsESjkOgOJktq5makyJTBFKW81CG5UWzIJAkQvX1Y1i7h77D-Cn2-O8P2o6T_Z0ao6LtXwUcUclXibe_QP8AFqiV8NvVG7"})]})}function d(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>r,x:()=>c});var n=s(6540);const i={},o=n.createContext(i);function r(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/4dd3fb5c.fb642566.js b/assets/js/4dd3fb5c.da93f493.js similarity index 99% rename from assets/js/4dd3fb5c.fb642566.js rename to assets/js/4dd3fb5c.da93f493.js index 74989ace0b..0488b641e9 100644 --- a/assets/js/4dd3fb5c.fb642566.js +++ b/assets/js/4dd3fb5c.da93f493.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2636],{2481:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>m,frontMatter:()=>u,metadata:()=>r,toc:()=>d});const r=JSON.parse('{"id":"guides/mock-es6-class","title":"Mock ES6 class","description":"TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.","source":"@site/versioned_docs/version-29.0/guides/mock-es6-class.md","sourceDirName":"guides","slug":"/guides/mock-es6-class","permalink":"/ts-jest/docs/29.0/guides/mock-es6-class","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/guides/mock-es6-class.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"mock-es6-class","title":"Mock ES6 class"},"sidebar":"version-29.0-docs","previous":{"title":"ESM Support","permalink":"/ts-jest/docs/29.0/guides/esm-support"},"next":{"title":"Using with React Native","permalink":"/ts-jest/docs/29.0/guides/react-native"}}');var s=n(4848),a=n(8453),l=n(9489),o=n(7227);const u={id:"mock-es6-class",title:"Mock ES6 class"},i=void 0,c={},d=[];function p(e){const t={code:"code",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,s.jsx)(t.code,{children:"const soundPlayer = require('./sound-player')"}),". Therefore creating an instance of the class that was exported as\na default will look like this: ",(0,s.jsx)(t.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\n",(0,s.jsxs)(l.A,{groupId:"code-examples",children:[(0,s.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",metastring:"tab",children:"jest.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\n })\n})\n"})})}),(0,s.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"jest.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\n })\n})\n"})})})]}),"\n",(0,s.jsx)(t.p,{children:"You will get the error"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,s.jsxs)(t.p,{children:["because ",(0,s.jsx)(t.code,{children:"soundPlayer.default"})," does not point to a function. Your mock has to return an object which has a property default\nthat points to a function."]}),"\n",(0,s.jsxs)(l.A,{groupId:"code-examples",children:[(0,s.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",metastring:"tab",children:"jest.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\n }\n }),\n }\n})\n"})})}),(0,s.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"jest.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\n }\n }),\n }\n})\n"})})})]}),"\n",(0,s.jsxs)(t.p,{children:["For named imports, like ",(0,s.jsx)(t.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,s.jsx)(t.code,{children:"default"})," with imported module name, ",(0,s.jsx)(t.code,{children:"OAuth2"})," in this example:"]}),"\n",(0,s.jsxs)(l.A,{groupId:"code-examples",children:[(0,s.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",metastring:"tab",children:"jest.mock('./oauth', () => {\n return {\n OAuth2: ... // mock here\n }\n})\n"})})}),(0,s.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"jest.mock('./oauth', () => {\n return {\n OAuth2: ... // mock here\n }\n})\n"})})})]})]})}function m(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(p,{...e})}):p(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>l});n(6540);var r=n(4164);const s={tabItem:"tabItem_Ymn6"};var a=n(4848);function l(e){let{children:t,hidden:n,className:l}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,r.A)(s.tabItem,l),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>k});var r=n(6540),s=n(4164),a=n(4245),l=n(6347),o=n(6494),u=n(2814),i=n(5167),c=n(9900);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:s}}=e;return{value:t,label:n,attributes:r,default:s}}))}(n);return function(e){const t=(0,i.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:n}=e;const s=(0,l.W6)(),a=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,u.aZ)(a),(0,r.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(s.location.search);t.set(a,e),s.replace({...s.location,search:t.toString()})}),[a,s])]}function f(e){const{defaultValue:t,queryString:n=!1,groupId:s}=e,a=p(e),[l,u]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:a}))),[i,d]=h({queryString:n,groupId:s}),[f,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[s,a]=(0,c.Dv)(n);return[s,(0,r.useCallback)((e=>{n&&a.set(e)}),[n,a])]}({groupId:s}),g=(()=>{const e=i??f;return m({value:e,tabValues:a})?e:null})();(0,o.A)((()=>{g&&u(g)}),[g]);return{selectedValue:l,selectValue:(0,r.useCallback)((e=>{if(!m({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);u(e),d(e),b(e)}),[d,b,a]),tabValues:a}}var b=n(1062);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var j=n(4848);function v(e){let{className:t,block:n,selectedValue:r,selectValue:l,tabValues:o}=e;const u=[],{blockElementScrollPositionUntilNextRender:i}=(0,a.a_)(),c=e=>{const t=e.currentTarget,n=u.indexOf(t),s=o[n].value;s!==r&&(i(t),l(s))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=u.indexOf(e.currentTarget)+1;t=u[n]??u[0];break}case"ArrowLeft":{const n=u.indexOf(e.currentTarget)-1;t=u[n]??u[u.length-1];break}}t?.focus()};return(0,j.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.A)("tabs",{"tabs--block":n},t),children:o.map((e=>{let{value:t,label:n,attributes:a}=e;return(0,j.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>u.push(e),onKeyDown:d,onClick:c,...a,className:(0,s.A)("tabs__item",g.tabItem,a?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:a}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:(0,s.A)("margin-top--md",e.props.className)}):null}return(0,j.jsx)("div",{className:"margin-top--md",children:l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=f(e);return(0,j.jsxs)("div",{className:(0,s.A)("tabs-container",g.tabList),children:[(0,j.jsx)(v,{...t,...e}),(0,j.jsx)(x,{...t,...e})]})}function k(e){const t=(0,b.A)();return(0,j.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>l,x:()=>o});var r=n(6540);const s={},a=r.createContext(s);function l(e){const t=r.useContext(a);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:l(e.components),r.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2636],{2481:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>m,frontMatter:()=>u,metadata:()=>r,toc:()=>d});const r=JSON.parse('{"id":"guides/mock-es6-class","title":"Mock ES6 class","description":"TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.","source":"@site/versioned_docs/version-29.0/guides/mock-es6-class.md","sourceDirName":"guides","slug":"/guides/mock-es6-class","permalink":"/ts-jest/docs/29.0/guides/mock-es6-class","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/guides/mock-es6-class.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"mock-es6-class","title":"Mock ES6 class"},"sidebar":"version-29.0-docs","previous":{"title":"ESM Support","permalink":"/ts-jest/docs/29.0/guides/esm-support"},"next":{"title":"Using with React Native","permalink":"/ts-jest/docs/29.0/guides/react-native"}}');var s=n(4848),a=n(8453),l=n(9489),o=n(7227);const u={id:"mock-es6-class",title:"Mock ES6 class"},i=void 0,c={},d=[];function p(e){const t={code:"code",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,s.jsx)(t.code,{children:"const soundPlayer = require('./sound-player')"}),". Therefore creating an instance of the class that was exported as\na default will look like this: ",(0,s.jsx)(t.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\n",(0,s.jsxs)(l.A,{groupId:"code-examples",children:[(0,s.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",metastring:"tab",children:"jest.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\n })\n})\n"})})}),(0,s.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"jest.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\n })\n})\n"})})})]}),"\n",(0,s.jsx)(t.p,{children:"You will get the error"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,s.jsxs)(t.p,{children:["because ",(0,s.jsx)(t.code,{children:"soundPlayer.default"})," does not point to a function. Your mock has to return an object which has a property default\nthat points to a function."]}),"\n",(0,s.jsxs)(l.A,{groupId:"code-examples",children:[(0,s.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",metastring:"tab",children:"jest.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\n }\n }),\n }\n})\n"})})}),(0,s.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"jest.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\n }\n }),\n }\n})\n"})})})]}),"\n",(0,s.jsxs)(t.p,{children:["For named imports, like ",(0,s.jsx)(t.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,s.jsx)(t.code,{children:"default"})," with imported module name, ",(0,s.jsx)(t.code,{children:"OAuth2"})," in this example:"]}),"\n",(0,s.jsxs)(l.A,{groupId:"code-examples",children:[(0,s.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",metastring:"tab",children:"jest.mock('./oauth', () => {\n return {\n OAuth2: ... // mock here\n }\n})\n"})})}),(0,s.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"jest.mock('./oauth', () => {\n return {\n OAuth2: ... // mock here\n }\n})\n"})})})]})]})}function m(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(p,{...e})}):p(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>l});n(6540);var r=n(4164);const s={tabItem:"tabItem_Ymn6"};var a=n(4848);function l(e){let{children:t,hidden:n,className:l}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,r.A)(s.tabItem,l),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>k});var r=n(6540),s=n(4164),a=n(4245),l=n(6347),o=n(6494),u=n(2814),i=n(5167),c=n(9900);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:s}}=e;return{value:t,label:n,attributes:r,default:s}}))}(n);return function(e){const t=(0,i.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:n}=e;const s=(0,l.W6)(),a=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,u.aZ)(a),(0,r.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(s.location.search);t.set(a,e),s.replace({...s.location,search:t.toString()})}),[a,s])]}function f(e){const{defaultValue:t,queryString:n=!1,groupId:s}=e,a=p(e),[l,u]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:a}))),[i,d]=h({queryString:n,groupId:s}),[f,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[s,a]=(0,c.Dv)(n);return[s,(0,r.useCallback)((e=>{n&&a.set(e)}),[n,a])]}({groupId:s}),g=(()=>{const e=i??f;return m({value:e,tabValues:a})?e:null})();(0,o.A)((()=>{g&&u(g)}),[g]);return{selectedValue:l,selectValue:(0,r.useCallback)((e=>{if(!m({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);u(e),d(e),b(e)}),[d,b,a]),tabValues:a}}var b=n(1062);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var j=n(4848);function v(e){let{className:t,block:n,selectedValue:r,selectValue:l,tabValues:o}=e;const u=[],{blockElementScrollPositionUntilNextRender:i}=(0,a.a_)(),c=e=>{const t=e.currentTarget,n=u.indexOf(t),s=o[n].value;s!==r&&(i(t),l(s))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=u.indexOf(e.currentTarget)+1;t=u[n]??u[0];break}case"ArrowLeft":{const n=u.indexOf(e.currentTarget)-1;t=u[n]??u[u.length-1];break}}t?.focus()};return(0,j.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.A)("tabs",{"tabs--block":n},t),children:o.map((e=>{let{value:t,label:n,attributes:a}=e;return(0,j.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>u.push(e),onKeyDown:d,onClick:c,...a,className:(0,s.A)("tabs__item",g.tabItem,a?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:a}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:(0,s.A)("margin-top--md",e.props.className)}):null}return(0,j.jsx)("div",{className:"margin-top--md",children:l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=f(e);return(0,j.jsxs)("div",{className:(0,s.A)("tabs-container",g.tabList),children:[(0,j.jsx)(v,{...t,...e}),(0,j.jsx)(x,{...t,...e})]})}function k(e){const t=(0,b.A)();return(0,j.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>l,x:()=>o});var r=n(6540);const s={},a=r.createContext(s);function l(e){const t=r.useContext(a);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:l(e.components),r.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/4e0c07c5.4112f062.js b/assets/js/4e0c07c5.57eedcdd.js similarity index 98% rename from assets/js/4e0c07c5.4112f062.js rename to assets/js/4e0c07c5.57eedcdd.js index cee0d6dd2a..f6d4485c3e 100644 --- a/assets/js/4e0c07c5.4112f062.js +++ b/assets/js/4e0c07c5.57eedcdd.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5250],{4422:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>j,frontMatter:()=>c,metadata:()=>s,toc:()=>u});const s=JSON.parse('{"id":"getting-started/options","title":"Options","description":"Introduction","source":"@site/docs/getting-started/options.md","sourceDirName":"getting-started","slug":"/getting-started/options","permalink":"/ts-jest/docs/next/getting-started/options","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"options","title":"Options"},"sidebar":"docs","previous":{"title":"Presets","permalink":"/ts-jest/docs/next/getting-started/presets"},"next":{"title":"Paths mapping","permalink":"/ts-jest/docs/next/getting-started/paths-mapping"}}');var r=n(4848),i=n(8453),o=n(9489),l=n(7227);const c={id:"options",title:"Options"},a=void 0,d={},u=[{value:"Introduction",id:"introduction",level:3},{value:"Options",id:"options",level:3}];function h(e){const t={a:"a",admonition:"admonition",code:"code",em:"em",h3:"h3",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,i.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.h3,{id:"introduction",children:"Introduction"}),"\n",(0,r.jsx)(t.admonition,{type:"caution",children:(0,r.jsxs)(t.p,{children:["If you are using custom ",(0,r.jsx)(t.code,{children:"transform"})," config, please remove ",(0,r.jsx)(t.code,{children:"preset"})," from your Jest config to avoid issues that Jest doesn't transform files correctly."]})}),"\n",(0,r.jsxs)(t.p,{children:["All ",(0,r.jsx)(t.code,{children:"ts-jest"})," specific options can be defined in Jest ",(0,r.jsx)(t.code,{children:"transform"})," config object in the ",(0,r.jsx)(t.code,{children:"package.json"})," file of your project,\nor through a ",(0,r.jsx)(t.code,{children:"jest.config.js"}),", or ",(0,r.jsx)(t.code,{children:"jest.config.ts"})," file."]}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\nconst { createDefaultPreset } = require('ts-jest')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n ...createDefaultPreset(),\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport { createDefaultPreset, JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n ...createDefaultPreset(),\n}\n"})})})]}),"\n",(0,r.jsx)(t.admonition,{type:"important",children:(0,r.jsxs)(t.p,{children:["When using TypeScript Jest config file, Jest will use ",(0,r.jsx)(t.code,{children:"ts-node"})," to compile the config file. ",(0,r.jsx)(t.code,{children:"ts-jest"})," doesn't take part in\nthat process."]})}),"\n",(0,r.jsx)(t.h3,{id:"options",children:"Options"}),"\n",(0,r.jsx)(t.p,{children:"All options have default values which should fit most of the projects. Click on the option's name to see details and example(s)."}),"\n",(0,r.jsxs)(t.table,{children:[(0,r.jsx)(t.thead,{children:(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.th,{children:"Option"}),(0,r.jsx)(t.th,{children:"Description"}),(0,r.jsx)(t.th,{children:"Type"}),(0,r.jsx)(t.th,{children:"Default"})]})}),(0,r.jsxs)(t.tbody,{children:[(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/compiler",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"compiler"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"string"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:'"typescript"'})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/tsconfig",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"tsconfig"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"string"}),"|",(0,r.jsx)(t.code,{children:"object"}),"|",(0,r.jsx)(t.code,{children:"boolean"})]}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"auto"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/isolatedModules",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"isolatedModules"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"boolean"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"disabled"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/astTransformers",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"astTransformers"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"object"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"auto"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/diagnostics",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"diagnostics"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"boolean"}),"|",(0,r.jsx)(t.code,{children:"object"})]}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"enabled"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/babelConfig",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"babelConfig"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"boolean"}),"|",(0,r.jsx)(t.code,{children:"string"}),"|",(0,r.jsx)(t.code,{children:"object"})]}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"disabled"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/stringifyContentPathRegex",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"stringifyContentPathRegex"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"string"}),"|",(0,r.jsx)(t.code,{children:"RegExp"})]}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"disabled"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/useESM",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"useESM"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/useESM",children:"Enable ESM support"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"boolean"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"auto"})})]})]})]})]})}function j(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var s=n(4164);const r={tabItem:"tabItem_Ymn6"};var i=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,i.jsx)("div",{role:"tabpanel",className:(0,s.A)(r.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),r=n(4164),i=n(4245),o=n(6347),l=n(6494),c=n(2814),a=n(5167),d=n(9900);function u(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return u(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:r}}=e;return{value:t,label:n,attributes:s,default:r}}))}(n);return function(e){const t=(0,a.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function j(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function p(e){let{queryString:t=!1,groupId:n}=e;const r=(0,o.W6)(),i=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,c.aZ)(i),(0,s.useCallback)((e=>{if(!i)return;const t=new URLSearchParams(r.location.search);t.set(i,e),r.replace({...r.location,search:t.toString()})}),[i,r])]}function x(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,i=h(e),[o,c]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!j({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:i}))),[a,u]=p({queryString:n,groupId:r}),[x,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,i]=(0,d.Dv)(n);return[r,(0,s.useCallback)((e=>{n&&i.set(e)}),[n,i])]}({groupId:r}),m=(()=>{const e=a??x;return j({value:e,tabValues:i})?e:null})();(0,l.A)((()=>{m&&c(m)}),[m]);return{selectedValue:o,selectValue:(0,s.useCallback)((e=>{if(!j({value:e,tabValues:i}))throw new Error(`Can't select invalid tab value=${e}`);c(e),u(e),f(e)}),[u,f,i]),tabValues:i}}var f=n(1062);const m={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=n(4848);function b(e){let{className:t,block:n,selectedValue:s,selectValue:o,tabValues:l}=e;const c=[],{blockElementScrollPositionUntilNextRender:a}=(0,i.a_)(),d=e=>{const t=e.currentTarget,n=c.indexOf(t),r=l[n].value;r!==s&&(a(t),o(r))},u=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const n=c.indexOf(e.currentTarget)+1;t=c[n]??c[0];break}case"ArrowLeft":{const n=c.indexOf(e.currentTarget)-1;t=c[n]??c[c.length-1];break}}t?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:i}=e;return(0,g.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>c.push(e),onKeyDown:u,onClick:d,...i,className:(0,r.A)("tabs__item",m.tabItem,i?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:i}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===i));return e?(0,s.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==i})))})}function y(e){const t=x(e);return(0,g.jsxs)("div",{className:(0,r.A)("tabs-container",m.tabList),children:[(0,g.jsx)(b,{...t,...e}),(0,g.jsx)(v,{...t,...e})]})}function w(e){const t=(0,f.A)();return(0,g.jsx)(y,{...e,children:u(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>l});var s=n(6540);const r={},i=s.createContext(r);function o(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5250],{4422:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>j,frontMatter:()=>c,metadata:()=>s,toc:()=>u});const s=JSON.parse('{"id":"getting-started/options","title":"Options","description":"Introduction","source":"@site/docs/getting-started/options.md","sourceDirName":"getting-started","slug":"/getting-started/options","permalink":"/ts-jest/docs/next/getting-started/options","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"options","title":"Options"},"sidebar":"docs","previous":{"title":"Presets","permalink":"/ts-jest/docs/next/getting-started/presets"},"next":{"title":"Paths mapping","permalink":"/ts-jest/docs/next/getting-started/paths-mapping"}}');var r=n(4848),i=n(8453),o=n(9489),l=n(7227);const c={id:"options",title:"Options"},a=void 0,d={},u=[{value:"Introduction",id:"introduction",level:3},{value:"Options",id:"options",level:3}];function h(e){const t={a:"a",admonition:"admonition",code:"code",em:"em",h3:"h3",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,i.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.h3,{id:"introduction",children:"Introduction"}),"\n",(0,r.jsx)(t.admonition,{type:"caution",children:(0,r.jsxs)(t.p,{children:["If you are using custom ",(0,r.jsx)(t.code,{children:"transform"})," config, please remove ",(0,r.jsx)(t.code,{children:"preset"})," from your Jest config to avoid issues that Jest doesn't transform files correctly."]})}),"\n",(0,r.jsxs)(t.p,{children:["All ",(0,r.jsx)(t.code,{children:"ts-jest"})," specific options can be defined in Jest ",(0,r.jsx)(t.code,{children:"transform"})," config object in the ",(0,r.jsx)(t.code,{children:"package.json"})," file of your project,\nor through a ",(0,r.jsx)(t.code,{children:"jest.config.js"}),", or ",(0,r.jsx)(t.code,{children:"jest.config.ts"})," file."]}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\nconst { createDefaultPreset } = require('ts-jest')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n ...createDefaultPreset(),\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport { createDefaultPreset, JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n ...createDefaultPreset(),\n}\n"})})})]}),"\n",(0,r.jsx)(t.admonition,{type:"important",children:(0,r.jsxs)(t.p,{children:["When using TypeScript Jest config file, Jest will use ",(0,r.jsx)(t.code,{children:"ts-node"})," to compile the config file. ",(0,r.jsx)(t.code,{children:"ts-jest"})," doesn't take part in\nthat process."]})}),"\n",(0,r.jsx)(t.h3,{id:"options",children:"Options"}),"\n",(0,r.jsx)(t.p,{children:"All options have default values which should fit most of the projects. Click on the option's name to see details and example(s)."}),"\n",(0,r.jsxs)(t.table,{children:[(0,r.jsx)(t.thead,{children:(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.th,{children:"Option"}),(0,r.jsx)(t.th,{children:"Description"}),(0,r.jsx)(t.th,{children:"Type"}),(0,r.jsx)(t.th,{children:"Default"})]})}),(0,r.jsxs)(t.tbody,{children:[(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/compiler",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"compiler"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"string"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:'"typescript"'})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/tsconfig",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"tsconfig"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"string"}),"|",(0,r.jsx)(t.code,{children:"object"}),"|",(0,r.jsx)(t.code,{children:"boolean"})]}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"auto"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/isolatedModules",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"isolatedModules"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"boolean"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"disabled"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/astTransformers",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"astTransformers"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"object"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"auto"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/diagnostics",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"diagnostics"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"boolean"}),"|",(0,r.jsx)(t.code,{children:"object"})]}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"enabled"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/babelConfig",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"babelConfig"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"boolean"}),"|",(0,r.jsx)(t.code,{children:"string"}),"|",(0,r.jsx)(t.code,{children:"object"})]}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"disabled"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/stringifyContentPathRegex",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"stringifyContentPathRegex"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"string"}),"|",(0,r.jsx)(t.code,{children:"RegExp"})]}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"disabled"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/useESM",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"useESM"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/useESM",children:"Enable ESM support"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"boolean"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"auto"})})]})]})]})]})}function j(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var s=n(4164);const r={tabItem:"tabItem_Ymn6"};var i=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,i.jsx)("div",{role:"tabpanel",className:(0,s.A)(r.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),r=n(4164),i=n(4245),o=n(6347),l=n(6494),c=n(2814),a=n(5167),d=n(9900);function u(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return u(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:r}}=e;return{value:t,label:n,attributes:s,default:r}}))}(n);return function(e){const t=(0,a.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function j(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function p(e){let{queryString:t=!1,groupId:n}=e;const r=(0,o.W6)(),i=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,c.aZ)(i),(0,s.useCallback)((e=>{if(!i)return;const t=new URLSearchParams(r.location.search);t.set(i,e),r.replace({...r.location,search:t.toString()})}),[i,r])]}function x(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,i=h(e),[o,c]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!j({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:i}))),[a,u]=p({queryString:n,groupId:r}),[x,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,i]=(0,d.Dv)(n);return[r,(0,s.useCallback)((e=>{n&&i.set(e)}),[n,i])]}({groupId:r}),m=(()=>{const e=a??x;return j({value:e,tabValues:i})?e:null})();(0,l.A)((()=>{m&&c(m)}),[m]);return{selectedValue:o,selectValue:(0,s.useCallback)((e=>{if(!j({value:e,tabValues:i}))throw new Error(`Can't select invalid tab value=${e}`);c(e),u(e),f(e)}),[u,f,i]),tabValues:i}}var f=n(1062);const m={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=n(4848);function b(e){let{className:t,block:n,selectedValue:s,selectValue:o,tabValues:l}=e;const c=[],{blockElementScrollPositionUntilNextRender:a}=(0,i.a_)(),d=e=>{const t=e.currentTarget,n=c.indexOf(t),r=l[n].value;r!==s&&(a(t),o(r))},u=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const n=c.indexOf(e.currentTarget)+1;t=c[n]??c[0];break}case"ArrowLeft":{const n=c.indexOf(e.currentTarget)-1;t=c[n]??c[c.length-1];break}}t?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:i}=e;return(0,g.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>c.push(e),onKeyDown:u,onClick:d,...i,className:(0,r.A)("tabs__item",m.tabItem,i?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:i}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===i));return e?(0,s.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==i})))})}function y(e){const t=x(e);return(0,g.jsxs)("div",{className:(0,r.A)("tabs-container",m.tabList),children:[(0,g.jsx)(b,{...t,...e}),(0,g.jsx)(v,{...t,...e})]})}function w(e){const t=(0,f.A)();return(0,g.jsx)(y,{...e,children:u(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>l});var s=n(6540);const r={},i=s.createContext(r);function o(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/5316ff60.5138fd7c.js b/assets/js/5316ff60.09d0f6fe.js similarity index 99% rename from assets/js/5316ff60.5138fd7c.js rename to assets/js/5316ff60.09d0f6fe.js index 78cab43cb8..424f982a19 100644 --- a/assets/js/5316ff60.5138fd7c.js +++ b/assets/js/5316ff60.09d0f6fe.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5520],{6874:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>i,default:()=>p,frontMatter:()=>a,metadata:()=>r,toc:()=>l});const r=JSON.parse('{"id":"getting-started/options/astTransformers","title":"AST transformers option","description":"ts-jest by default does hoisting for a few jest methods via a TypeScript AST transformer. One can also create custom","source":"@site/versioned_docs/version-27.0/getting-started/options/astTransformers.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/astTransformers","permalink":"/ts-jest/docs/27.0/getting-started/options/astTransformers","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/options/astTransformers.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"AST transformers option"}}');var t=n(4848),o=n(8453);const a={title:"AST transformers option"},i=void 0,c={},l=[{value:"Examples",id:"examples",level:3},{value:"Basic Transformers",id:"basic-transformers",level:4},{value:"Configuring transformers with options",id:"configuring-transformers-with-options",level:4},{value:"Public transformers",id:"public-transformers",level:3},{value:"Example of opt-in transformers",id:"example-of-opt-in-transformers",level:4},{value:"Writing custom TypeScript AST transformers",id:"writing-custom-typescript-ast-transformers",level:3}];function d(e){const s={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(s.p,{children:[(0,t.jsx)(s.code,{children:"ts-jest"})," by default does hoisting for a few ",(0,t.jsx)(s.code,{children:"jest"})," methods via a TypeScript AST transformer. One can also create custom\nTypeScript AST transformers and provide them to ",(0,t.jsx)(s.code,{children:"ts-jest"})," to include into compilation process."]}),"\n",(0,t.jsxs)(s.p,{children:["The option is ",(0,t.jsx)(s.code,{children:"astTransformers"})," and it allows ones to specify which 3 types of TypeScript AST transformers to use with ",(0,t.jsx)(s.code,{children:"ts-jest"}),":"]}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"before"})," means your transformers get run before TS ones, which means your transformers will get raw TS syntax\ninstead of transpiled syntax (e.g ",(0,t.jsx)(s.code,{children:"import"})," instead of ",(0,t.jsx)(s.code,{children:"require"})," or ",(0,t.jsx)(s.code,{children:"define"})," )."]}),"\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"after"})," means your transformers get run after TS ones, which gets transpiled syntax."]}),"\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"afterDeclarations"})," means your transformers get run during ",(0,t.jsx)(s.code,{children:"d.ts"})," generation phase, allowing you to transform output type declarations."]}),"\n"]}),"\n",(0,t.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,t.jsx)(s.h4,{id:"basic-transformers",children:"Basic Transformers"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n astTransformers: {\n before: ['my-custom-transformer'],\n },\n },\n },\n}\n"})}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "astTransformers": {\n "before": ["my-custom-transformer"]\n }\n }\n }\n }\n}\n'})}),"\n",(0,t.jsx)(s.h4,{id:"configuring-transformers-with-options",children:"Configuring transformers with options"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n astTransformers: {\n before: [\n {\n path: 'my-custom-transformer-that-needs-extra-opts',\n options: {}, // extra options to pass to transformers here\n },\n ],\n },\n },\n },\n}\n"})}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "astTransformers": {\n "before": [\n {\n "path": "my-custom-transformer-that-needs-extra-opts",\n "options": {} // extra options to pass to transformers here\n }\n ]\n }\n }\n }\n }\n}\n'})}),"\n",(0,t.jsx)(s.h3,{id:"public-transformers",children:"Public transformers"}),"\n",(0,t.jsxs)(s.p,{children:[(0,t.jsx)(s.code,{children:"ts-jest"})," is able to expose transformers for public usage to provide the possibility to opt-in/out for users. Currently\nthe exposed transformers are:"]}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"path-mapping"})," convert alias import/export to relative import/export path base on ",(0,t.jsx)(s.code,{children:"paths"})," in ",(0,t.jsx)(s.code,{children:"tsconfig"}),".\nThis transformer works similar to ",(0,t.jsx)(s.code,{children:"moduleNameMapper"})," in ",(0,t.jsx)(s.code,{children:"jest.config.js"}),". When using this transformer, one might not need\n",(0,t.jsx)(s.code,{children:"moduleNameMapper"})," anymore."]}),"\n"]}),"\n",(0,t.jsx)(s.h4,{id:"example-of-opt-in-transformers",children:"Example of opt-in transformers"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n astTransformers: {\n before: ['ts-jest/dist/transformers/path-mapping'],\n },\n },\n },\n}\n"})}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "astTransformers": {\n "before": ["ts-jest/dist/transformers/path-mapping"]\n }\n }\n }\n }\n}\n'})}),"\n",(0,t.jsx)(s.h3,{id:"writing-custom-typescript-ast-transformers",children:"Writing custom TypeScript AST transformers"}),"\n",(0,t.jsxs)(s.p,{children:["To write a custom TypeScript AST transformers, one can take a look at ",(0,t.jsx)(s.a,{href:"https://github.com/kulshekhar/ts-jest/tree/main/src/transformers",children:"the one"})," that ",(0,t.jsx)(s.code,{children:"ts-jest"})," is using."]})]})}function p(e={}){const{wrapper:s}={...(0,o.R)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.jsx)(d,{...e})}):d(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>a,x:()=>i});var r=n(6540);const t={},o=r.createContext(t);function a(e){const s=r.useContext(o);return r.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function i(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:a(e.components),r.createElement(o.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5520],{6874:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>i,default:()=>p,frontMatter:()=>a,metadata:()=>r,toc:()=>l});const r=JSON.parse('{"id":"getting-started/options/astTransformers","title":"AST transformers option","description":"ts-jest by default does hoisting for a few jest methods via a TypeScript AST transformer. One can also create custom","source":"@site/versioned_docs/version-27.0/getting-started/options/astTransformers.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/astTransformers","permalink":"/ts-jest/docs/27.0/getting-started/options/astTransformers","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/options/astTransformers.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"AST transformers option"}}');var t=n(4848),o=n(8453);const a={title:"AST transformers option"},i=void 0,c={},l=[{value:"Examples",id:"examples",level:3},{value:"Basic Transformers",id:"basic-transformers",level:4},{value:"Configuring transformers with options",id:"configuring-transformers-with-options",level:4},{value:"Public transformers",id:"public-transformers",level:3},{value:"Example of opt-in transformers",id:"example-of-opt-in-transformers",level:4},{value:"Writing custom TypeScript AST transformers",id:"writing-custom-typescript-ast-transformers",level:3}];function d(e){const s={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(s.p,{children:[(0,t.jsx)(s.code,{children:"ts-jest"})," by default does hoisting for a few ",(0,t.jsx)(s.code,{children:"jest"})," methods via a TypeScript AST transformer. One can also create custom\nTypeScript AST transformers and provide them to ",(0,t.jsx)(s.code,{children:"ts-jest"})," to include into compilation process."]}),"\n",(0,t.jsxs)(s.p,{children:["The option is ",(0,t.jsx)(s.code,{children:"astTransformers"})," and it allows ones to specify which 3 types of TypeScript AST transformers to use with ",(0,t.jsx)(s.code,{children:"ts-jest"}),":"]}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"before"})," means your transformers get run before TS ones, which means your transformers will get raw TS syntax\ninstead of transpiled syntax (e.g ",(0,t.jsx)(s.code,{children:"import"})," instead of ",(0,t.jsx)(s.code,{children:"require"})," or ",(0,t.jsx)(s.code,{children:"define"})," )."]}),"\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"after"})," means your transformers get run after TS ones, which gets transpiled syntax."]}),"\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"afterDeclarations"})," means your transformers get run during ",(0,t.jsx)(s.code,{children:"d.ts"})," generation phase, allowing you to transform output type declarations."]}),"\n"]}),"\n",(0,t.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,t.jsx)(s.h4,{id:"basic-transformers",children:"Basic Transformers"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n astTransformers: {\n before: ['my-custom-transformer'],\n },\n },\n },\n}\n"})}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "astTransformers": {\n "before": ["my-custom-transformer"]\n }\n }\n }\n }\n}\n'})}),"\n",(0,t.jsx)(s.h4,{id:"configuring-transformers-with-options",children:"Configuring transformers with options"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n astTransformers: {\n before: [\n {\n path: 'my-custom-transformer-that-needs-extra-opts',\n options: {}, // extra options to pass to transformers here\n },\n ],\n },\n },\n },\n}\n"})}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "astTransformers": {\n "before": [\n {\n "path": "my-custom-transformer-that-needs-extra-opts",\n "options": {} // extra options to pass to transformers here\n }\n ]\n }\n }\n }\n }\n}\n'})}),"\n",(0,t.jsx)(s.h3,{id:"public-transformers",children:"Public transformers"}),"\n",(0,t.jsxs)(s.p,{children:[(0,t.jsx)(s.code,{children:"ts-jest"})," is able to expose transformers for public usage to provide the possibility to opt-in/out for users. Currently\nthe exposed transformers are:"]}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"path-mapping"})," convert alias import/export to relative import/export path base on ",(0,t.jsx)(s.code,{children:"paths"})," in ",(0,t.jsx)(s.code,{children:"tsconfig"}),".\nThis transformer works similar to ",(0,t.jsx)(s.code,{children:"moduleNameMapper"})," in ",(0,t.jsx)(s.code,{children:"jest.config.js"}),". When using this transformer, one might not need\n",(0,t.jsx)(s.code,{children:"moduleNameMapper"})," anymore."]}),"\n"]}),"\n",(0,t.jsx)(s.h4,{id:"example-of-opt-in-transformers",children:"Example of opt-in transformers"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n astTransformers: {\n before: ['ts-jest/dist/transformers/path-mapping'],\n },\n },\n },\n}\n"})}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "astTransformers": {\n "before": ["ts-jest/dist/transformers/path-mapping"]\n }\n }\n }\n }\n}\n'})}),"\n",(0,t.jsx)(s.h3,{id:"writing-custom-typescript-ast-transformers",children:"Writing custom TypeScript AST transformers"}),"\n",(0,t.jsxs)(s.p,{children:["To write a custom TypeScript AST transformers, one can take a look at ",(0,t.jsx)(s.a,{href:"https://github.com/kulshekhar/ts-jest/tree/main/src/transformers",children:"the one"})," that ",(0,t.jsx)(s.code,{children:"ts-jest"})," is using."]})]})}function p(e={}){const{wrapper:s}={...(0,o.R)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.jsx)(d,{...e})}):d(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>a,x:()=>i});var r=n(6540);const t={},o=r.createContext(t);function a(e){const s=r.useContext(o);return r.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function i(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:a(e.components),r.createElement(o.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/544d8072.6eddd2c9.js b/assets/js/544d8072.4881b7d6.js similarity index 98% rename from assets/js/544d8072.6eddd2c9.js rename to assets/js/544d8072.4881b7d6.js index c9d346741d..136b6fed4a 100644 --- a/assets/js/544d8072.6eddd2c9.js +++ b/assets/js/544d8072.4881b7d6.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9979],{9058:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>a,contentTitle:()=>c,default:()=>g,frontMatter:()=>r,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"migration","title":"Migration from <=23.10","description":"You can use the config:migrate tool of ts-jest CLI if you\'re coming from an older version to help you migrate your Jest configuration.","source":"@site/versioned_docs/version-26.5/migration.md","sourceDirName":".","slug":"/migration","permalink":"/ts-jest/docs/26.5/migration","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/migration.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"migration","title":"Migration from <=23.10"},"sidebar":"version-26.5-docs","previous":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/26.5/babel7-or-ts"},"next":{"title":"Debugging ts-jest","permalink":"/ts-jest/docs/26.5/debugging"}}');var o=t(4848),i=t(8453);const r={id:"migration",title:"Migration from <=23.10"},c=void 0,a={},d=[{value:"NPM",id:"npm",level:3},{value:"Yarn",id:"yarn",level:3},{value:"NPM",id:"npm-1",level:3},{value:"Yarn",id:"yarn-1",level:3}];function l(e){const n={code:"code",em:"em",h3:"h3",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:["You can use the ",(0,o.jsx)(n.code,{children:"config:migrate"})," tool of ",(0,o.jsx)(n.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsxs)(n.em,{children:["If you're using ",(0,o.jsx)(n.code,{children:"jest.config.js"}),":"]})}),"\n",(0,o.jsx)(n.h3,{id:"npm",children:"NPM"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate jest.config.js\n"})}),"\n",(0,o.jsx)(n.h3,{id:"yarn",children:"Yarn"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate jest.config.js\n"})}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsxs)(n.em,{children:["If you're using ",(0,o.jsx)(n.code,{children:"jest"})," config property of ",(0,o.jsx)(n.code,{children:"package.json"}),":"]})}),"\n",(0,o.jsx)(n.h3,{id:"npm-1",children:"NPM"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate package.json\n"})}),"\n",(0,o.jsx)(n.h3,{id:"yarn-1",children:"Yarn"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate package.json\n"})})]})}function g(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>r,x:()=>c});var s=t(6540);const o={},i=s.createContext(o);function r(e){const n=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function c(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9979],{9058:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>a,contentTitle:()=>c,default:()=>g,frontMatter:()=>r,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"migration","title":"Migration from <=23.10","description":"You can use the config:migrate tool of ts-jest CLI if you\'re coming from an older version to help you migrate your Jest configuration.","source":"@site/versioned_docs/version-26.5/migration.md","sourceDirName":".","slug":"/migration","permalink":"/ts-jest/docs/26.5/migration","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/migration.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"migration","title":"Migration from <=23.10"},"sidebar":"version-26.5-docs","previous":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/26.5/babel7-or-ts"},"next":{"title":"Debugging ts-jest","permalink":"/ts-jest/docs/26.5/debugging"}}');var o=t(4848),i=t(8453);const r={id:"migration",title:"Migration from <=23.10"},c=void 0,a={},d=[{value:"NPM",id:"npm",level:3},{value:"Yarn",id:"yarn",level:3},{value:"NPM",id:"npm-1",level:3},{value:"Yarn",id:"yarn-1",level:3}];function l(e){const n={code:"code",em:"em",h3:"h3",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:["You can use the ",(0,o.jsx)(n.code,{children:"config:migrate"})," tool of ",(0,o.jsx)(n.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsxs)(n.em,{children:["If you're using ",(0,o.jsx)(n.code,{children:"jest.config.js"}),":"]})}),"\n",(0,o.jsx)(n.h3,{id:"npm",children:"NPM"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate jest.config.js\n"})}),"\n",(0,o.jsx)(n.h3,{id:"yarn",children:"Yarn"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate jest.config.js\n"})}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsxs)(n.em,{children:["If you're using ",(0,o.jsx)(n.code,{children:"jest"})," config property of ",(0,o.jsx)(n.code,{children:"package.json"}),":"]})}),"\n",(0,o.jsx)(n.h3,{id:"npm-1",children:"NPM"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate package.json\n"})}),"\n",(0,o.jsx)(n.h3,{id:"yarn-1",children:"Yarn"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate package.json\n"})})]})}function g(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>r,x:()=>c});var s=t(6540);const o={},i=s.createContext(o);function r(e){const n=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function c(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/54ceb25f.daee3545.js b/assets/js/54ceb25f.17d4f1b4.js similarity index 98% rename from assets/js/54ceb25f.daee3545.js rename to assets/js/54ceb25f.17d4f1b4.js index ae41e3b34e..acd8d8ef08 100644 --- a/assets/js/54ceb25f.daee3545.js +++ b/assets/js/54ceb25f.17d4f1b4.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4317],{9717:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>p,contentTitle:()=>a,default:()=>j,frontMatter:()=>d,metadata:()=>n,toc:()=>u});const n=JSON.parse('{"id":"guides/esm-support","title":"ESM Support","description":"References","source":"@site/versioned_docs/version-29.2/guides/esm-support.md","sourceDirName":"guides","slug":"/guides/esm-support","permalink":"/ts-jest/docs/guides/esm-support","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/guides/esm-support.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"esm-support","title":"ESM Support"},"sidebar":"version-29.1-docs","previous":{"title":"Version checking","permalink":"/ts-jest/docs/getting-started/version-checking"},"next":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/guides/mock-es6-class"}}');var r=t(4848),o=t(8453),i=t(9489),l=t(7227),c=t(1574);const d={id:"esm-support",title:"ESM Support"},a=void 0,p={},u=[{value:"References",id:"references",level:2},{value:"Configuration",id:"configuration",level:3},{value:"Example:",id:"example",level:4},{value:"Example:",id:"example-1",level:4},{value:"Resolve .mjs/.mts extensions",id:"resolve-mjsmts-extensions",level:3}];function h(e){const s={a:"a",code:"code",h2:"h2",h3:"h3",h4:"h4",hr:"hr",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(s.h2,{id:"references",children:"References"}),"\n","\n",(0,r.jsx)(c.A,{toc:u.slice(1)}),"\n",(0,r.jsx)(s.hr,{}),"\n",(0,r.jsx)(s.h3,{id:"configuration",children:"Configuration"}),"\n",(0,r.jsxs)(s.p,{children:["To use ",(0,r.jsx)(s.code,{children:"ts-jest"})," with ESM support:"]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:["Check ",(0,r.jsx)(s.a,{href:"https://jestjs.io/docs/en/ecmascript-modules",children:"ESM Jest documentation"}),"."]}),"\n",(0,r.jsxs)(s.li,{children:["Ensure that ",(0,r.jsx)(s.code,{children:"tsconfig"})," has ",(0,r.jsx)(s.code,{children:"module"})," with value for ESM, e.g. ",(0,r.jsx)(s.code,{children:"ES2022"}),"/",(0,r.jsx)(s.code,{children:"ESNext"})," etc..."]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"example",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'// tsconfig.spec.json\n{\n "compilerOptions": {\n "module": "ESNext", // or ES2022\n "target": "ESNext",\n "esModuleInterop": true\n }\n}\n'})}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:["Configure your Jest configuration use one of the ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/presets",children:"utility functions"})]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"example-1",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createDefaultEsmPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createDefaultEsmPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsxs)(s.h3,{id:"resolve-mjsmts-extensions",children:["Resolve ",(0,r.jsx)(s.code,{children:".mjs/.mts"})," extensions"]}),"\n",(0,r.jsxs)(s.p,{children:["To work with ",(0,r.jsx)(s.code,{children:".mts"})," extension, besides the requirement to run Jest and ",(0,r.jsx)(s.code,{children:"ts-jest"})," in ESM mode, there are a few extra requirements to be met:"]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"package.json"})," should contain ",(0,r.jsx)(s.code,{children:'"type": "module"'})]}),"\n",(0,r.jsxs)(s.li,{children:["A custom Jest resolver to resolve ",(0,r.jsx)(s.code,{children:".mjs"})," extension, for example:"]}),"\n"]}),"\n",(0,r.jsxs)(i.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"typescript-cjs",label:"TypeScript CJS",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",metastring:'tab={"label": "TypeScript CJS"}',children:"import type { SyncResolver } from 'jest-resolve'\n\nconst mjsResolver: SyncResolver = (path, options) => {\n const mjsExtRegex = /\\.mjs$/i\n const resolver = options.defaultResolver\n if (mjsExtRegex.test(path)) {\n try {\n return resolver(path.replace(mjsExtRegex, '.mts'), options)\n } catch {\n // use default resolver\n }\n }\n\n return resolver(path, options)\n}\n\nexport = mjsResolver\n"})})}),(0,r.jsx)(l.A,{value:"typescript-esm",label:"TypeScript ESM",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",metastring:'tab={"label": "TypeScript ESM"}',children:"import type { SyncResolver } from 'jest-resolve'\n\nconst mjsResolver: SyncResolver = (path, options) => {\n const mjsExtRegex = /\\.mjs$/i\n const resolver = options.defaultResolver\n if (mjsExtRegex.test(path)) {\n try {\n return resolver(path.replace(mjsExtRegex, '.mts'), options)\n } catch {\n // use default resolver\n }\n }\n\n return resolver(path, options)\n}\n\nexport default mjsResolver\n"})})})]})]})}function j(e={}){const{wrapper:s}={...(0,o.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4317],{9717:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>p,contentTitle:()=>a,default:()=>j,frontMatter:()=>d,metadata:()=>n,toc:()=>u});const n=JSON.parse('{"id":"guides/esm-support","title":"ESM Support","description":"References","source":"@site/versioned_docs/version-29.2/guides/esm-support.md","sourceDirName":"guides","slug":"/guides/esm-support","permalink":"/ts-jest/docs/guides/esm-support","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/guides/esm-support.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"esm-support","title":"ESM Support"},"sidebar":"version-29.1-docs","previous":{"title":"Version checking","permalink":"/ts-jest/docs/getting-started/version-checking"},"next":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/guides/mock-es6-class"}}');var r=t(4848),o=t(8453),i=t(9489),l=t(7227),c=t(1574);const d={id:"esm-support",title:"ESM Support"},a=void 0,p={},u=[{value:"References",id:"references",level:2},{value:"Configuration",id:"configuration",level:3},{value:"Example:",id:"example",level:4},{value:"Example:",id:"example-1",level:4},{value:"Resolve .mjs/.mts extensions",id:"resolve-mjsmts-extensions",level:3}];function h(e){const s={a:"a",code:"code",h2:"h2",h3:"h3",h4:"h4",hr:"hr",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(s.h2,{id:"references",children:"References"}),"\n","\n",(0,r.jsx)(c.A,{toc:u.slice(1)}),"\n",(0,r.jsx)(s.hr,{}),"\n",(0,r.jsx)(s.h3,{id:"configuration",children:"Configuration"}),"\n",(0,r.jsxs)(s.p,{children:["To use ",(0,r.jsx)(s.code,{children:"ts-jest"})," with ESM support:"]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:["Check ",(0,r.jsx)(s.a,{href:"https://jestjs.io/docs/en/ecmascript-modules",children:"ESM Jest documentation"}),"."]}),"\n",(0,r.jsxs)(s.li,{children:["Ensure that ",(0,r.jsx)(s.code,{children:"tsconfig"})," has ",(0,r.jsx)(s.code,{children:"module"})," with value for ESM, e.g. ",(0,r.jsx)(s.code,{children:"ES2022"}),"/",(0,r.jsx)(s.code,{children:"ESNext"})," etc..."]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"example",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'// tsconfig.spec.json\n{\n "compilerOptions": {\n "module": "ESNext", // or ES2022\n "target": "ESNext",\n "esModuleInterop": true\n }\n}\n'})}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:["Configure your Jest configuration use one of the ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/presets",children:"utility functions"})]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"example-1",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createDefaultEsmPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createDefaultEsmPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsxs)(s.h3,{id:"resolve-mjsmts-extensions",children:["Resolve ",(0,r.jsx)(s.code,{children:".mjs/.mts"})," extensions"]}),"\n",(0,r.jsxs)(s.p,{children:["To work with ",(0,r.jsx)(s.code,{children:".mts"})," extension, besides the requirement to run Jest and ",(0,r.jsx)(s.code,{children:"ts-jest"})," in ESM mode, there are a few extra requirements to be met:"]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"package.json"})," should contain ",(0,r.jsx)(s.code,{children:'"type": "module"'})]}),"\n",(0,r.jsxs)(s.li,{children:["A custom Jest resolver to resolve ",(0,r.jsx)(s.code,{children:".mjs"})," extension, for example:"]}),"\n"]}),"\n",(0,r.jsxs)(i.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"typescript-cjs",label:"TypeScript CJS",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",metastring:'tab={"label": "TypeScript CJS"}',children:"import type { SyncResolver } from 'jest-resolve'\n\nconst mjsResolver: SyncResolver = (path, options) => {\n const mjsExtRegex = /\\.mjs$/i\n const resolver = options.defaultResolver\n if (mjsExtRegex.test(path)) {\n try {\n return resolver(path.replace(mjsExtRegex, '.mts'), options)\n } catch {\n // use default resolver\n }\n }\n\n return resolver(path, options)\n}\n\nexport = mjsResolver\n"})})}),(0,r.jsx)(l.A,{value:"typescript-esm",label:"TypeScript ESM",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",metastring:'tab={"label": "TypeScript ESM"}',children:"import type { SyncResolver } from 'jest-resolve'\n\nconst mjsResolver: SyncResolver = (path, options) => {\n const mjsExtRegex = /\\.mjs$/i\n const resolver = options.defaultResolver\n if (mjsExtRegex.test(path)) {\n try {\n return resolver(path.replace(mjsExtRegex, '.mts'), options)\n } catch {\n // use default resolver\n }\n }\n\n return resolver(path, options)\n}\n\nexport default mjsResolver\n"})})})]})]})}function j(e={}){const{wrapper:s}={...(0,o.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}}}]); \ No newline at end of file diff --git a/assets/js/54f44165.7c5a3f91.js b/assets/js/54f44165.d90b0204.js similarity index 99% rename from assets/js/54f44165.7c5a3f91.js rename to assets/js/54f44165.d90b0204.js index 14d70b51b5..5cb570acf4 100644 --- a/assets/js/54f44165.7c5a3f91.js +++ b/assets/js/54f44165.d90b0204.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7924],{1226:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/installation","title":"Installation","description":"Dependencies","source":"@site/docs/getting-started/installation.md","sourceDirName":"getting-started","slug":"/getting-started/installation","permalink":"/ts-jest/docs/next/getting-started/installation","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/installation.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"installation","title":"Installation"},"sidebar":"docs","previous":{"title":"Contributing","permalink":"/ts-jest/docs/next/contributing"},"next":{"title":"Presets","permalink":"/ts-jest/docs/next/getting-started/presets"}}');var r=n(4848),a=n(8453),i=n(9489),l=n(7227);const o={id:"installation",title:"Installation"},c=void 0,u={},d=[{value:"Dependencies",id:"dependencies",level:3},{value:"Jest config file",id:"jest-config-file",level:3},{value:"Creating",id:"creating",level:4},{value:"Customizing",id:"customizing",level:4}];function h(e){const t={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,r.jsxs)(t.p,{children:["You can install ",(0,r.jsx)(t.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,r.jsxs)(i.A,{groupId:"npm2yarn",children:[(0,r.jsx)(l.A,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})})}),(0,r.jsx)(l.A,{value:"yarn",label:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})})}),(0,r.jsx)(l.A,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"pnpm add --save-dev jest typescript ts-jest @types/jest\n"})})})]}),"\n",(0,r.jsx)(t.admonition,{type:"tip",children:(0,r.jsxs)(t.p,{children:["Tip: If you get an error with the following ",(0,r.jsx)(t.code,{children:"npm"})," commands such as ",(0,r.jsx)(t.code,{children:"npx: command not found"}),", you can replace ",(0,r.jsx)(t.code,{children:"npx XXX"})," with ",(0,r.jsx)(t.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,r.jsx)(t.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,r.jsx)(t.h4,{id:"creating",children:"Creating"}),"\n",(0,r.jsxs)(t.p,{children:["By default, Jest can run without any config files, but it will not compile ",(0,r.jsx)(t.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,r.jsx)(t.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,r.jsx)(t.code,{children:"ts-jest"})," preset."]}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,r.jsxs)(i.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-npm",metastring:"tab",children:"npx ts-jest config:init\n"})})}),(0,r.jsx)(l.A,{value:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-Yarn",metastring:"tab",children:"yarn ts-jest config:init\n"})})})]}),"\n",(0,r.jsxs)(t.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,r.jsx)(t.code,{children:".ts"})," files correctly."]}),"\n",(0,r.jsxs)(t.p,{children:["You can also use the ",(0,r.jsx)(t.code,{children:"jest --init"})," command (prefixed with either ",(0,r.jsx)(t.code,{children:"npx"})," or ",(0,r.jsx)(t.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,r.jsx)(t.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,r.jsx)(t.code,{children:'preset: "ts-jest"'})," to the ",(0,r.jsx)(t.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,r.jsx)(t.h4,{id:"customizing",children:"Customizing"}),"\n",(0,r.jsxs)(t.p,{children:["For customizing jest, please follow their ",(0,r.jsx)(t.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"ts-jest"})," specific options can be found ",(0,r.jsx)(t.a,{href:"/ts-jest/docs/next/getting-started/options",children:"here"}),"."]})]})}function p(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>i});n(6540);var s=n(4164);const r={tabItem:"tabItem_Ymn6"};var a=n(4848);function i(e){let{children:t,hidden:n,className:i}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,s.A)(r.tabItem,i),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),r=n(4164),a=n(4245),i=n(6347),l=n(6494),o=n(2814),c=n(5167),u=n(9900);function d(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:r}}=e;return{value:t,label:n,attributes:s,default:r}}))}(n);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const r=(0,i.W6)(),a=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,o.aZ)(a),(0,s.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function m(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,a=h(e),[i,o]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:a}))),[c,d]=f({queryString:n,groupId:r}),[m,j]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,u.Dv)(n);return[r,(0,s.useCallback)((e=>{n&&a.set(e)}),[n,a])]}({groupId:r}),g=(()=>{const e=c??m;return p({value:e,tabValues:a})?e:null})();(0,l.A)((()=>{g&&o(g)}),[g]);return{selectedValue:i,selectValue:(0,s.useCallback)((e=>{if(!p({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);o(e),d(e),j(e)}),[d,j,a]),tabValues:a}}var j=n(1062);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=n(4848);function x(e){let{className:t,block:n,selectedValue:s,selectValue:i,tabValues:l}=e;const o=[],{blockElementScrollPositionUntilNextRender:c}=(0,a.a_)(),u=e=>{const t=e.currentTarget,n=o.indexOf(t),r=l[n].value;r!==s&&(c(t),i(r))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=o.indexOf(e.currentTarget)+1;t=o[n]??o[0];break}case"ArrowLeft":{const n=o.indexOf(e.currentTarget)-1;t=o[n]??o[o.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:a}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>o.push(e),onKeyDown:d,onClick:u,...a,className:(0,r.A)("tabs__item",g.tabItem,a?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:a}=e;const i=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=i.find((e=>e.props.value===a));return e?(0,s.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:i.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=m(e);return(0,b.jsxs)("div",{className:(0,r.A)("tabs-container",g.tabList),children:[(0,b.jsx)(x,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function w(e){const t=(0,j.A)();return(0,b.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>i,x:()=>l});var s=n(6540);const r={},a=s.createContext(r);function i(e){const t=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),s.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7924],{1226:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/installation","title":"Installation","description":"Dependencies","source":"@site/docs/getting-started/installation.md","sourceDirName":"getting-started","slug":"/getting-started/installation","permalink":"/ts-jest/docs/next/getting-started/installation","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/installation.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"installation","title":"Installation"},"sidebar":"docs","previous":{"title":"Contributing","permalink":"/ts-jest/docs/next/contributing"},"next":{"title":"Presets","permalink":"/ts-jest/docs/next/getting-started/presets"}}');var r=n(4848),a=n(8453),i=n(9489),l=n(7227);const o={id:"installation",title:"Installation"},c=void 0,u={},d=[{value:"Dependencies",id:"dependencies",level:3},{value:"Jest config file",id:"jest-config-file",level:3},{value:"Creating",id:"creating",level:4},{value:"Customizing",id:"customizing",level:4}];function h(e){const t={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,r.jsxs)(t.p,{children:["You can install ",(0,r.jsx)(t.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,r.jsxs)(i.A,{groupId:"npm2yarn",children:[(0,r.jsx)(l.A,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})})}),(0,r.jsx)(l.A,{value:"yarn",label:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})})}),(0,r.jsx)(l.A,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"pnpm add --save-dev jest typescript ts-jest @types/jest\n"})})})]}),"\n",(0,r.jsx)(t.admonition,{type:"tip",children:(0,r.jsxs)(t.p,{children:["Tip: If you get an error with the following ",(0,r.jsx)(t.code,{children:"npm"})," commands such as ",(0,r.jsx)(t.code,{children:"npx: command not found"}),", you can replace ",(0,r.jsx)(t.code,{children:"npx XXX"})," with ",(0,r.jsx)(t.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,r.jsx)(t.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,r.jsx)(t.h4,{id:"creating",children:"Creating"}),"\n",(0,r.jsxs)(t.p,{children:["By default, Jest can run without any config files, but it will not compile ",(0,r.jsx)(t.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,r.jsx)(t.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,r.jsx)(t.code,{children:"ts-jest"})," preset."]}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,r.jsxs)(i.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-npm",metastring:"tab",children:"npx ts-jest config:init\n"})})}),(0,r.jsx)(l.A,{value:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-Yarn",metastring:"tab",children:"yarn ts-jest config:init\n"})})})]}),"\n",(0,r.jsxs)(t.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,r.jsx)(t.code,{children:".ts"})," files correctly."]}),"\n",(0,r.jsxs)(t.p,{children:["You can also use the ",(0,r.jsx)(t.code,{children:"jest --init"})," command (prefixed with either ",(0,r.jsx)(t.code,{children:"npx"})," or ",(0,r.jsx)(t.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,r.jsx)(t.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,r.jsx)(t.code,{children:'preset: "ts-jest"'})," to the ",(0,r.jsx)(t.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,r.jsx)(t.h4,{id:"customizing",children:"Customizing"}),"\n",(0,r.jsxs)(t.p,{children:["For customizing jest, please follow their ",(0,r.jsx)(t.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"ts-jest"})," specific options can be found ",(0,r.jsx)(t.a,{href:"/ts-jest/docs/next/getting-started/options",children:"here"}),"."]})]})}function p(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>i});n(6540);var s=n(4164);const r={tabItem:"tabItem_Ymn6"};var a=n(4848);function i(e){let{children:t,hidden:n,className:i}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,s.A)(r.tabItem,i),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),r=n(4164),a=n(4245),i=n(6347),l=n(6494),o=n(2814),c=n(5167),u=n(9900);function d(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:r}}=e;return{value:t,label:n,attributes:s,default:r}}))}(n);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const r=(0,i.W6)(),a=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,o.aZ)(a),(0,s.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function m(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,a=h(e),[i,o]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:a}))),[c,d]=f({queryString:n,groupId:r}),[m,j]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,u.Dv)(n);return[r,(0,s.useCallback)((e=>{n&&a.set(e)}),[n,a])]}({groupId:r}),g=(()=>{const e=c??m;return p({value:e,tabValues:a})?e:null})();(0,l.A)((()=>{g&&o(g)}),[g]);return{selectedValue:i,selectValue:(0,s.useCallback)((e=>{if(!p({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);o(e),d(e),j(e)}),[d,j,a]),tabValues:a}}var j=n(1062);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=n(4848);function x(e){let{className:t,block:n,selectedValue:s,selectValue:i,tabValues:l}=e;const o=[],{blockElementScrollPositionUntilNextRender:c}=(0,a.a_)(),u=e=>{const t=e.currentTarget,n=o.indexOf(t),r=l[n].value;r!==s&&(c(t),i(r))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=o.indexOf(e.currentTarget)+1;t=o[n]??o[0];break}case"ArrowLeft":{const n=o.indexOf(e.currentTarget)-1;t=o[n]??o[o.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:a}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>o.push(e),onKeyDown:d,onClick:u,...a,className:(0,r.A)("tabs__item",g.tabItem,a?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:a}=e;const i=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=i.find((e=>e.props.value===a));return e?(0,s.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:i.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=m(e);return(0,b.jsxs)("div",{className:(0,r.A)("tabs-container",g.tabList),children:[(0,b.jsx)(x,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function w(e){const t=(0,j.A)();return(0,b.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>i,x:()=>l});var s=n(6540);const r={},a=s.createContext(r);function i(e){const t=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),s.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/5bf3837a.62777e91.js b/assets/js/5bf3837a.e9c81638.js similarity index 98% rename from assets/js/5bf3837a.62777e91.js rename to assets/js/5bf3837a.e9c81638.js index e77addbaeb..f4f221611e 100644 --- a/assets/js/5bf3837a.62777e91.js +++ b/assets/js/5bf3837a.e9c81638.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2276],{128:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>c,default:()=>a,frontMatter:()=>i,metadata:()=>n,toc:()=>u});const n=JSON.parse('{"id":"processing","title":"Processing flow","description":"These are internal technical documents. If you\'re not a contributor to ts-jest, but simply trying to use the library you\'ll find nothing of value here","source":"@site/versioned_docs/version-26.5/processing.md","sourceDirName":".","slug":"/processing","permalink":"/ts-jest/docs/26.5/processing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/processing.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"processing","title":"Processing flow"},"sidebar":"version-26.5-docs","previous":{"title":"Introduction","permalink":"/ts-jest/docs/26.5/"},"next":{"title":"Contributing","permalink":"/ts-jest/docs/26.5/contributing"}}');var o=s(4848),r=s(8453);const i={id:"processing",title:"Processing flow"},c=void 0,l={},u=[{value:"Jest process",id:"jest-process",level:2},{value:"ts-jest process",id:"ts-jest-process",level:2}];function d(e){const t={code:"code",em:"em",h2:"h2",img:"img",p:"p",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.p,{children:(0,o.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,o.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,o.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,o.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,o.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLJRRjim37tNLn3Omn9WwGUaG8Uz3YWmOFq1nQ9YjJ8PY7Iz0lduGHV7YHjWyvDruI7FuH7FfyGTYd0w6r6Rr9YzoayKVMWd6-4nTRXzD2Pus4ZFOtGWcW8TW__ulWNjaM3pWR8r-rTXMWuVpUu9nfEpYgR2F1g3KH0sn5k3v8Ali3v493iW83c1AMWF3-v1vHPz2YU46OXO4L8uzcg8WH0TA4F7mob4D0vzeA212JAsv6IGGwuBCESlBtqGZNXkSGasdUrwTDjpgIi8HwleO60tHfHRkWlIlaje5S6IWm9WL21QEe9WUW-vtiPsztHXK3CGd31944NI6hlIj0e80muDsYSUFWNTAFllqlUDSD7QQB8aUVbSxZPn8terHJsOGenmm5bUPwp0Ei6Ln000IpLGljkCTUyYJbqkMQ5zWtr360M1VQv-3hYSLzaTs0E_Nwdlp88momP1CfA3gKUw72UqBj2ncQJkhNZKlbKAeoWFyEFtIraNsJod0PDK3ci6FQQIU2e_FGVHd8rzEt_DBstWxYrVSapu3Qp0X362dSiP1TEk-3bRV4vfixVdAmURYJ51n-J3qNnciNkwz6xnN-7amv-s0uCzDHwVJ7UxVSzyHQRprJov-_YN9zycIMxkmHumhlnPzkuFeaNapiOeDNoNfJINz8iP_tS4zLR0UiNqgs90p_osVZGsDsPzwTwOMseCrRdv8YJKCP4OuG6rpqu8-hMyB5EiQGK8fzQEwv5LozmlXhlg8fBx2m00"})]})}function a(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2276],{128:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>c,default:()=>a,frontMatter:()=>i,metadata:()=>n,toc:()=>u});const n=JSON.parse('{"id":"processing","title":"Processing flow","description":"These are internal technical documents. If you\'re not a contributor to ts-jest, but simply trying to use the library you\'ll find nothing of value here","source":"@site/versioned_docs/version-26.5/processing.md","sourceDirName":".","slug":"/processing","permalink":"/ts-jest/docs/26.5/processing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/processing.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"processing","title":"Processing flow"},"sidebar":"version-26.5-docs","previous":{"title":"Introduction","permalink":"/ts-jest/docs/26.5/"},"next":{"title":"Contributing","permalink":"/ts-jest/docs/26.5/contributing"}}');var o=s(4848),r=s(8453);const i={id:"processing",title:"Processing flow"},c=void 0,l={},u=[{value:"Jest process",id:"jest-process",level:2},{value:"ts-jest process",id:"ts-jest-process",level:2}];function d(e){const t={code:"code",em:"em",h2:"h2",img:"img",p:"p",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.p,{children:(0,o.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,o.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,o.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,o.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,o.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLJRRjim37tNLn3Omn9WwGUaG8Uz3YWmOFq1nQ9YjJ8PY7Iz0lduGHV7YHjWyvDruI7FuH7FfyGTYd0w6r6Rr9YzoayKVMWd6-4nTRXzD2Pus4ZFOtGWcW8TW__ulWNjaM3pWR8r-rTXMWuVpUu9nfEpYgR2F1g3KH0sn5k3v8Ali3v493iW83c1AMWF3-v1vHPz2YU46OXO4L8uzcg8WH0TA4F7mob4D0vzeA212JAsv6IGGwuBCESlBtqGZNXkSGasdUrwTDjpgIi8HwleO60tHfHRkWlIlaje5S6IWm9WL21QEe9WUW-vtiPsztHXK3CGd31944NI6hlIj0e80muDsYSUFWNTAFllqlUDSD7QQB8aUVbSxZPn8terHJsOGenmm5bUPwp0Ei6Ln000IpLGljkCTUyYJbqkMQ5zWtr360M1VQv-3hYSLzaTs0E_Nwdlp88momP1CfA3gKUw72UqBj2ncQJkhNZKlbKAeoWFyEFtIraNsJod0PDK3ci6FQQIU2e_FGVHd8rzEt_DBstWxYrVSapu3Qp0X362dSiP1TEk-3bRV4vfixVdAmURYJ51n-J3qNnciNkwz6xnN-7amv-s0uCzDHwVJ7UxVSzyHQRprJov-_YN9zycIMxkmHumhlnPzkuFeaNapiOeDNoNfJINz8iP_tS4zLR0UiNqgs90p_osVZGsDsPzwTwOMseCrRdv8YJKCP4OuG6rpqu8-hMyB5EiQGK8fzQEwv5LozmlXhlg8fBx2m00"})]})}function a(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/61b42bb5.754d1be0.js b/assets/js/61b42bb5.539f1df0.js similarity index 98% rename from assets/js/61b42bb5.754d1be0.js rename to assets/js/61b42bb5.539f1df0.js index 3fe085ae62..d39b7c2406 100644 --- a/assets/js/61b42bb5.754d1be0.js +++ b/assets/js/61b42bb5.539f1df0.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[346],{3049:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>p,default:()=>d,frontMatter:()=>r,metadata:()=>s,toc:()=>c});const s=JSON.parse('{"id":"getting-started/paths-mapping","title":"Paths mapping","description":"If you use \\"baseUrl\\" and \\"paths\\" options in your tsconfig file, you should make sure the \\"moduleNameMapper\\" option in your Jest config is setup accordingly.","source":"@site/versioned_docs/version-26.5/getting-started/paths-mapping.md","sourceDirName":"getting-started","slug":"/getting-started/paths-mapping","permalink":"/ts-jest/docs/26.5/getting-started/paths-mapping","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/getting-started/paths-mapping.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"paths-mapping","title":"Paths mapping"},"sidebar":"version-26.5-docs","previous":{"title":"Options","permalink":"/ts-jest/docs/26.5/getting-started/options"},"next":{"title":"Version checking","permalink":"/ts-jest/docs/26.5/getting-started/version-checking"}}');var o=n(4848),i=n(8453);const r={id:"paths-mapping",title:"Paths mapping"},p=void 0,a={},c=[{value:"Example",id:"example",level:3},{value:"TypeScript config",id:"typescript-config",level:4},{value:"Jest config (without helper)",id:"jest-config-without-helper",level:4},{value:"Jest config (with helper)",id:"jest-config-with-helper",level:4}];function l(e){const t={a:"a",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["If you use ",(0,o.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,o.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,o.jsx)(t.a,{href:"https://jestjs.io/docs/configuration#modulenamemapper-objectstring-string--arraystring",children:'"moduleNameMapper"'})," option in your Jest config is setup accordingly."]}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,o.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,o.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,o.jsxs)(t.p,{children:["With the below config in your ",(0,o.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n "compilerOptions": {\n "baseUrl": ".",\n "paths": {\n "@App/*": ["src/*"],\n "lib/*": ["common/*"]\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n moduleNameMapper: {\n '^@App/(.*)$': '/src/$1',\n '^lib/(.*)$': '/common/$1',\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleNameMapper": {\n "^@App/(.*)$": "/src/$1",\n "^lib/(.*)$": "/common/$1"\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nconst { pathsToModuleNameMapper } = require('ts-jest/utils')\n// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file\n// which contains the path mapping (ie the `compilerOptions.paths` option):\nconst { compilerOptions } = require('./tsconfig')\n\nmodule.exports = {\n // [...]\n roots: [''],\n modulePaths: [compilerOptions.baseUrl], // <-- This will be set to 'baseUrl' value\n moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths /*, { prefix: '/' } */),\n}\n"})})]})}function d(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>p});var s=n(6540);const o={},i=s.createContext(o);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function p(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[346],{3049:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>p,default:()=>d,frontMatter:()=>r,metadata:()=>s,toc:()=>c});const s=JSON.parse('{"id":"getting-started/paths-mapping","title":"Paths mapping","description":"If you use \\"baseUrl\\" and \\"paths\\" options in your tsconfig file, you should make sure the \\"moduleNameMapper\\" option in your Jest config is setup accordingly.","source":"@site/versioned_docs/version-26.5/getting-started/paths-mapping.md","sourceDirName":"getting-started","slug":"/getting-started/paths-mapping","permalink":"/ts-jest/docs/26.5/getting-started/paths-mapping","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/getting-started/paths-mapping.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"paths-mapping","title":"Paths mapping"},"sidebar":"version-26.5-docs","previous":{"title":"Options","permalink":"/ts-jest/docs/26.5/getting-started/options"},"next":{"title":"Version checking","permalink":"/ts-jest/docs/26.5/getting-started/version-checking"}}');var o=n(4848),i=n(8453);const r={id:"paths-mapping",title:"Paths mapping"},p=void 0,a={},c=[{value:"Example",id:"example",level:3},{value:"TypeScript config",id:"typescript-config",level:4},{value:"Jest config (without helper)",id:"jest-config-without-helper",level:4},{value:"Jest config (with helper)",id:"jest-config-with-helper",level:4}];function l(e){const t={a:"a",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["If you use ",(0,o.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,o.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,o.jsx)(t.a,{href:"https://jestjs.io/docs/configuration#modulenamemapper-objectstring-string--arraystring",children:'"moduleNameMapper"'})," option in your Jest config is setup accordingly."]}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,o.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,o.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,o.jsxs)(t.p,{children:["With the below config in your ",(0,o.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n "compilerOptions": {\n "baseUrl": ".",\n "paths": {\n "@App/*": ["src/*"],\n "lib/*": ["common/*"]\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n moduleNameMapper: {\n '^@App/(.*)$': '/src/$1',\n '^lib/(.*)$': '/common/$1',\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleNameMapper": {\n "^@App/(.*)$": "/src/$1",\n "^lib/(.*)$": "/common/$1"\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nconst { pathsToModuleNameMapper } = require('ts-jest/utils')\n// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file\n// which contains the path mapping (ie the `compilerOptions.paths` option):\nconst { compilerOptions } = require('./tsconfig')\n\nmodule.exports = {\n // [...]\n roots: [''],\n modulePaths: [compilerOptions.baseUrl], // <-- This will be set to 'baseUrl' value\n moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths /*, { prefix: '/' } */),\n}\n"})})]})}function d(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>p});var s=n(6540);const o={},i=s.createContext(o);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function p(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/629085c0.5f85dd08.js b/assets/js/629085c0.97393345.js similarity index 99% rename from assets/js/629085c0.5f85dd08.js rename to assets/js/629085c0.97393345.js index 2e38c94ac1..6676008d0a 100644 --- a/assets/js/629085c0.5f85dd08.js +++ b/assets/js/629085c0.97393345.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2452],{3088:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>m,frontMatter:()=>i,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/compiler","title":"Compiler option","description":"The compiler option allows you to define the compiler to be used. It\'ll be used to load the NodeJS module holding the TypeScript compiler.","source":"@site/versioned_docs/version-29.2/getting-started/options/compiler.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/compiler","permalink":"/ts-jest/docs/getting-started/options/compiler","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/options/compiler.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Compiler option"}}');var r=s(4848),o=s(8453),a=s(9489),l=s(7227);const i={title:"Compiler option"},c=void 0,u={},d=[{value:"Example",id:"example",level:3}];function p(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["The ",(0,r.jsx)(t.code,{children:"compiler"})," option allows you to define the compiler to be used. It'll be used to load the NodeJS module holding the TypeScript compiler."]}),"\n",(0,r.jsxs)(t.p,{children:["The default value is ",(0,r.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,r.jsx)(t.a,{href:"https://www.npmjs.com/package/typescript",children:"TypeScript compiler module"}),".\nThe loaded version will depend on the one installed in your project."]}),"\n",(0,r.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,r.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,r.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,r.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n compiler: 'ttypescript',\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n compiler: 'ttypescript',\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "compiler": "ttypescript"\n }\n ]\n }\n }\n}\n'})})})]})]})}function m(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>a});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var o=s(4848);function a(e){let{children:t,hidden:s,className:a}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,a),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>w});var n=s(6540),r=s(4164),o=s(4245),a=s(6347),l=s(6494),i=s(2814),c=s(5167),u=s(9900);function d(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:r}}=e;return{value:t,label:s,attributes:n,default:r}}))}(s);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function m(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:s}=e;const r=(0,a.W6)(),o=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,i.aZ)(o),(0,n.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(r.location.search);t.set(o,e),r.replace({...r.location,search:t.toString()})}),[o,r])]}function f(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,o=p(e),[a,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:o}))),[c,d]=h({queryString:s,groupId:r}),[f,j]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,o]=(0,u.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&o.set(e)}),[s,o])]}({groupId:r}),b=(()=>{const e=c??f;return m({value:e,tabValues:o})?e:null})();(0,l.A)((()=>{b&&i(b)}),[b]);return{selectedValue:a,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);i(e),d(e),j(e)}),[d,j,o]),tabValues:o}}var j=s(1062);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=s(4848);function g(e){let{className:t,block:s,selectedValue:n,selectValue:a,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.a_)(),u=e=>{const t=e.currentTarget,s=i.indexOf(t),r=l[s].value;r!==n&&(c(t),a(r))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const s=i.indexOf(e.currentTarget)+1;t=i[s]??i[0];break}case"ArrowLeft":{const s=i.indexOf(e.currentTarget)-1;t=i[s]??i[i.length-1];break}}t?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":s},t),children:l.map((e=>{let{value:t,label:s,attributes:o}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:d,onClick:u,...o,className:(0,r.A)("tabs__item",b.tabItem,o?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:o}=e;const a=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=a.find((e=>e.props.value===o));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:a.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==o})))})}function y(e){const t=f(e);return(0,x.jsxs)("div",{className:(0,r.A)("tabs-container",b.tabList),children:[(0,x.jsx)(g,{...t,...e}),(0,x.jsx)(v,{...t,...e})]})}function w(e){const t=(0,j.A)();return(0,x.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>a,x:()=>l});var n=s(6540);const r={},o=n.createContext(r);function a(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2452],{3088:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>m,frontMatter:()=>i,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/compiler","title":"Compiler option","description":"The compiler option allows you to define the compiler to be used. It\'ll be used to load the NodeJS module holding the TypeScript compiler.","source":"@site/versioned_docs/version-29.2/getting-started/options/compiler.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/compiler","permalink":"/ts-jest/docs/getting-started/options/compiler","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/options/compiler.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Compiler option"}}');var r=s(4848),o=s(8453),a=s(9489),l=s(7227);const i={title:"Compiler option"},c=void 0,u={},d=[{value:"Example",id:"example",level:3}];function p(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["The ",(0,r.jsx)(t.code,{children:"compiler"})," option allows you to define the compiler to be used. It'll be used to load the NodeJS module holding the TypeScript compiler."]}),"\n",(0,r.jsxs)(t.p,{children:["The default value is ",(0,r.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,r.jsx)(t.a,{href:"https://www.npmjs.com/package/typescript",children:"TypeScript compiler module"}),".\nThe loaded version will depend on the one installed in your project."]}),"\n",(0,r.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,r.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,r.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,r.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n compiler: 'ttypescript',\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n compiler: 'ttypescript',\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "compiler": "ttypescript"\n }\n ]\n }\n }\n}\n'})})})]})]})}function m(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>a});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var o=s(4848);function a(e){let{children:t,hidden:s,className:a}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,a),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>w});var n=s(6540),r=s(4164),o=s(4245),a=s(6347),l=s(6494),i=s(2814),c=s(5167),u=s(9900);function d(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:r}}=e;return{value:t,label:s,attributes:n,default:r}}))}(s);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function m(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:s}=e;const r=(0,a.W6)(),o=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,i.aZ)(o),(0,n.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(r.location.search);t.set(o,e),r.replace({...r.location,search:t.toString()})}),[o,r])]}function f(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,o=p(e),[a,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:o}))),[c,d]=h({queryString:s,groupId:r}),[f,j]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,o]=(0,u.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&o.set(e)}),[s,o])]}({groupId:r}),b=(()=>{const e=c??f;return m({value:e,tabValues:o})?e:null})();(0,l.A)((()=>{b&&i(b)}),[b]);return{selectedValue:a,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);i(e),d(e),j(e)}),[d,j,o]),tabValues:o}}var j=s(1062);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=s(4848);function g(e){let{className:t,block:s,selectedValue:n,selectValue:a,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.a_)(),u=e=>{const t=e.currentTarget,s=i.indexOf(t),r=l[s].value;r!==n&&(c(t),a(r))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const s=i.indexOf(e.currentTarget)+1;t=i[s]??i[0];break}case"ArrowLeft":{const s=i.indexOf(e.currentTarget)-1;t=i[s]??i[i.length-1];break}}t?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":s},t),children:l.map((e=>{let{value:t,label:s,attributes:o}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:d,onClick:u,...o,className:(0,r.A)("tabs__item",b.tabItem,o?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:o}=e;const a=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=a.find((e=>e.props.value===o));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:a.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==o})))})}function y(e){const t=f(e);return(0,x.jsxs)("div",{className:(0,r.A)("tabs-container",b.tabList),children:[(0,x.jsx)(g,{...t,...e}),(0,x.jsx)(v,{...t,...e})]})}function w(e){const t=(0,j.A)();return(0,x.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>a,x:()=>l});var n=s(6540);const r={},o=n.createContext(r);function a(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/6625be2a.b983ec8c.js b/assets/js/6625be2a.de300dce.js similarity index 99% rename from assets/js/6625be2a.b983ec8c.js rename to assets/js/6625be2a.de300dce.js index 8ab6dec326..d4f12d3a77 100644 --- a/assets/js/6625be2a.b983ec8c.js +++ b/assets/js/6625be2a.de300dce.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4136],{6195:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>i,contentTitle:()=>c,default:()=>m,frontMatter:()=>u,metadata:()=>r,toc:()=>d});const r=JSON.parse('{"id":"guides/mock-es6-class","title":"Mock ES6 class","description":"TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.","source":"@site/docs/guides/mock-es6-class.md","sourceDirName":"guides","slug":"/guides/mock-es6-class","permalink":"/ts-jest/docs/next/guides/mock-es6-class","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/guides/mock-es6-class.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"mock-es6-class","title":"Mock ES6 class"},"sidebar":"docs","previous":{"title":"ESM Support","permalink":"/ts-jest/docs/next/guides/esm-support"},"next":{"title":"Using with React Native","permalink":"/ts-jest/docs/next/guides/react-native"}}');var a=n(4848),s=n(8453),l=n(9489),o=n(7227);const u={id:"mock-es6-class",title:"Mock ES6 class"},c=void 0,i={},d=[];function p(e){const t={code:"code",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(t.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,a.jsx)(t.code,{children:"const soundPlayer = require('./sound-player')"}),". Therefore creating an instance of the class that was exported as\na default will look like this: ",(0,a.jsx)(t.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\n",(0,a.jsxs)(l.A,{groupId:"code-examples",children:[(0,a.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-js",metastring:"tab",children:"jest.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\n })\n})\n"})})}),(0,a.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"jest.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\n })\n})\n"})})})]}),"\n",(0,a.jsx)(t.p,{children:"You will get the error"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,a.jsxs)(t.p,{children:["because ",(0,a.jsx)(t.code,{children:"soundPlayer.default"})," does not point to a function. Your mock has to return an object which has a property default\nthat points to a function."]}),"\n",(0,a.jsxs)(l.A,{groupId:"code-examples",children:[(0,a.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-js",metastring:"tab",children:"jest.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\n }\n }),\n }\n})\n"})})}),(0,a.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"jest.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\n }\n }),\n }\n})\n"})})})]}),"\n",(0,a.jsxs)(t.p,{children:["For named imports, like ",(0,a.jsx)(t.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,a.jsx)(t.code,{children:"default"})," with imported module name, ",(0,a.jsx)(t.code,{children:"OAuth2"})," in this example:"]}),"\n",(0,a.jsxs)(l.A,{groupId:"code-examples",children:[(0,a.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-js",metastring:"tab",children:"jest.mock('./oauth', () => {\n return {\n OAuth2: ... // mock here\n }\n})\n"})})}),(0,a.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"jest.mock('./oauth', () => {\n return {\n OAuth2: ... // mock here\n }\n})\n"})})})]})]})}function m(e={}){const{wrapper:t}={...(0,s.R)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(p,{...e})}):p(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>l});n(6540);var r=n(4164);const a={tabItem:"tabItem_Ymn6"};var s=n(4848);function l(e){let{children:t,hidden:n,className:l}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.A)(a.tabItem,l),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>k});var r=n(6540),a=n(4164),s=n(4245),l=n(6347),o=n(6494),u=n(2814),c=n(5167),i=n(9900);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(n);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:n}=e;const a=(0,l.W6)(),s=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,u.aZ)(s),(0,r.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function f(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,s=p(e),[l,u]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:s}))),[c,d]=h({queryString:n,groupId:a}),[f,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,i.Dv)(n);return[a,(0,r.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),g=(()=>{const e=c??f;return m({value:e,tabValues:s})?e:null})();(0,o.A)((()=>{g&&u(g)}),[g]);return{selectedValue:l,selectValue:(0,r.useCallback)((e=>{if(!m({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);u(e),d(e),b(e)}),[d,b,s]),tabValues:s}}var b=n(1062);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var j=n(4848);function x(e){let{className:t,block:n,selectedValue:r,selectValue:l,tabValues:o}=e;const u=[],{blockElementScrollPositionUntilNextRender:c}=(0,s.a_)(),i=e=>{const t=e.currentTarget,n=u.indexOf(t),a=o[n].value;a!==r&&(c(t),l(a))},d=e=>{let t=null;switch(e.key){case"Enter":i(e);break;case"ArrowRight":{const n=u.indexOf(e.currentTarget)+1;t=u[n]??u[0];break}case"ArrowLeft":{const n=u.indexOf(e.currentTarget)-1;t=u[n]??u[u.length-1];break}}t?.focus()};return(0,j.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.A)("tabs",{"tabs--block":n},t),children:o.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,j.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>u.push(e),onKeyDown:d,onClick:i,...s,className:(0,a.A)("tabs__item",g.tabItem,s?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:s}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===s));return e?(0,r.cloneElement)(e,{className:(0,a.A)("margin-top--md",e.props.className)}):null}return(0,j.jsx)("div",{className:"margin-top--md",children:l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==s})))})}function y(e){const t=f(e);return(0,j.jsxs)("div",{className:(0,a.A)("tabs-container",g.tabList),children:[(0,j.jsx)(x,{...t,...e}),(0,j.jsx)(v,{...t,...e})]})}function k(e){const t=(0,b.A)();return(0,j.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>l,x:()=>o});var r=n(6540);const a={},s=r.createContext(a);function l(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:l(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4136],{6195:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>i,contentTitle:()=>c,default:()=>m,frontMatter:()=>u,metadata:()=>r,toc:()=>d});const r=JSON.parse('{"id":"guides/mock-es6-class","title":"Mock ES6 class","description":"TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.","source":"@site/docs/guides/mock-es6-class.md","sourceDirName":"guides","slug":"/guides/mock-es6-class","permalink":"/ts-jest/docs/next/guides/mock-es6-class","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/guides/mock-es6-class.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"mock-es6-class","title":"Mock ES6 class"},"sidebar":"docs","previous":{"title":"ESM Support","permalink":"/ts-jest/docs/next/guides/esm-support"},"next":{"title":"Using with React Native","permalink":"/ts-jest/docs/next/guides/react-native"}}');var a=n(4848),s=n(8453),l=n(9489),o=n(7227);const u={id:"mock-es6-class",title:"Mock ES6 class"},c=void 0,i={},d=[];function p(e){const t={code:"code",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(t.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,a.jsx)(t.code,{children:"const soundPlayer = require('./sound-player')"}),". Therefore creating an instance of the class that was exported as\na default will look like this: ",(0,a.jsx)(t.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\n",(0,a.jsxs)(l.A,{groupId:"code-examples",children:[(0,a.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-js",metastring:"tab",children:"jest.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\n })\n})\n"})})}),(0,a.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"jest.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\n })\n})\n"})})})]}),"\n",(0,a.jsx)(t.p,{children:"You will get the error"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,a.jsxs)(t.p,{children:["because ",(0,a.jsx)(t.code,{children:"soundPlayer.default"})," does not point to a function. Your mock has to return an object which has a property default\nthat points to a function."]}),"\n",(0,a.jsxs)(l.A,{groupId:"code-examples",children:[(0,a.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-js",metastring:"tab",children:"jest.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\n }\n }),\n }\n})\n"})})}),(0,a.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"jest.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\n }\n }),\n }\n})\n"})})})]}),"\n",(0,a.jsxs)(t.p,{children:["For named imports, like ",(0,a.jsx)(t.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,a.jsx)(t.code,{children:"default"})," with imported module name, ",(0,a.jsx)(t.code,{children:"OAuth2"})," in this example:"]}),"\n",(0,a.jsxs)(l.A,{groupId:"code-examples",children:[(0,a.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-js",metastring:"tab",children:"jest.mock('./oauth', () => {\n return {\n OAuth2: ... // mock here\n }\n})\n"})})}),(0,a.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"jest.mock('./oauth', () => {\n return {\n OAuth2: ... // mock here\n }\n})\n"})})})]})]})}function m(e={}){const{wrapper:t}={...(0,s.R)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(p,{...e})}):p(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>l});n(6540);var r=n(4164);const a={tabItem:"tabItem_Ymn6"};var s=n(4848);function l(e){let{children:t,hidden:n,className:l}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.A)(a.tabItem,l),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>k});var r=n(6540),a=n(4164),s=n(4245),l=n(6347),o=n(6494),u=n(2814),c=n(5167),i=n(9900);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(n);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:n}=e;const a=(0,l.W6)(),s=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,u.aZ)(s),(0,r.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function f(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,s=p(e),[l,u]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:s}))),[c,d]=h({queryString:n,groupId:a}),[f,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,i.Dv)(n);return[a,(0,r.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),g=(()=>{const e=c??f;return m({value:e,tabValues:s})?e:null})();(0,o.A)((()=>{g&&u(g)}),[g]);return{selectedValue:l,selectValue:(0,r.useCallback)((e=>{if(!m({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);u(e),d(e),b(e)}),[d,b,s]),tabValues:s}}var b=n(1062);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var j=n(4848);function x(e){let{className:t,block:n,selectedValue:r,selectValue:l,tabValues:o}=e;const u=[],{blockElementScrollPositionUntilNextRender:c}=(0,s.a_)(),i=e=>{const t=e.currentTarget,n=u.indexOf(t),a=o[n].value;a!==r&&(c(t),l(a))},d=e=>{let t=null;switch(e.key){case"Enter":i(e);break;case"ArrowRight":{const n=u.indexOf(e.currentTarget)+1;t=u[n]??u[0];break}case"ArrowLeft":{const n=u.indexOf(e.currentTarget)-1;t=u[n]??u[u.length-1];break}}t?.focus()};return(0,j.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.A)("tabs",{"tabs--block":n},t),children:o.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,j.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>u.push(e),onKeyDown:d,onClick:i,...s,className:(0,a.A)("tabs__item",g.tabItem,s?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:s}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===s));return e?(0,r.cloneElement)(e,{className:(0,a.A)("margin-top--md",e.props.className)}):null}return(0,j.jsx)("div",{className:"margin-top--md",children:l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==s})))})}function y(e){const t=f(e);return(0,j.jsxs)("div",{className:(0,a.A)("tabs-container",g.tabList),children:[(0,j.jsx)(x,{...t,...e}),(0,j.jsx)(v,{...t,...e})]})}function k(e){const t=(0,b.A)();return(0,j.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>l,x:()=>o});var r=n(6540);const a={},s=r.createContext(a);function l(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:l(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/673550c0.c16d574d.js b/assets/js/673550c0.5a99e13d.js similarity index 99% rename from assets/js/673550c0.c16d574d.js rename to assets/js/673550c0.5a99e13d.js index 9363788a99..c68b263d99 100644 --- a/assets/js/673550c0.c16d574d.js +++ b/assets/js/673550c0.5a99e13d.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6460],{3732:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>l,default:()=>u,frontMatter:()=>i,metadata:()=>t,toc:()=>d});const t=JSON.parse('{"id":"guides/esm-support","title":"ESM Support","description":"To use ts-jest with ESM support:","source":"@site/versioned_docs/version-28.0/guides/esm-support.md","sourceDirName":"guides","slug":"/guides/esm-support","permalink":"/ts-jest/docs/28.0/guides/esm-support","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/guides/esm-support.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"esm-support","title":"ESM Support"},"sidebar":"version-28.0-docs","previous":{"title":"Version checking","permalink":"/ts-jest/docs/28.0/getting-started/version-checking"},"next":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/28.0/guides/mock-es6-class"}}');var o=n(4848),r=n(8453);const i={id:"esm-support",title:"ESM Support"},l=void 0,c={},d=[{value:"ESM presets",id:"esm-presets",level:3},{value:"Examples",id:"examples",level:3},{value:"Manual configuration",id:"manual-configuration",level:4},{value:"Use ESM presets",id:"use-esm-presets",level:4},{value:"Support .mts extension",id:"support-mts-extension",level:4}];function a(e){const s={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(s.p,{children:["To use ",(0,o.jsx)(s.code,{children:"ts-jest"})," with ESM support:"]}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check ",(0,o.jsx)(s.a,{href:"https://jestjs.io/docs/en/ecmascript-modules",children:"ESM Jest documentation"}),"."]}),"\n",(0,o.jsxs)(s.li,{children:["Enable ",(0,o.jsx)(s.a,{href:"../getting-started/options/useESM",children:"useESM"})," ",(0,o.jsx)(s.code,{children:"true"})," for ",(0,o.jsx)(s.code,{children:"ts-jest"})," config."]}),"\n",(0,o.jsxs)(s.li,{children:["Include ",(0,o.jsx)(s.code,{children:".ts"})," in ",(0,o.jsx)(s.a,{href:"https://jestjs.io/docs/en/next/configuration#extensionstotreatasesm-arraystring",children:"extensionsToTreatAsEsm"})," Jest config option."]}),"\n",(0,o.jsxs)(s.li,{children:["Ensure that ",(0,o.jsx)(s.code,{children:"tsconfig"})," has ",(0,o.jsx)(s.code,{children:"module"})," with value for ESM, e.g. ",(0,o.jsx)(s.code,{children:"ES2015"})," or ",(0,o.jsx)(s.code,{children:"ES2020"})," etc..."]}),"\n"]}),"\n",(0,o.jsx)(s.h3,{id:"esm-presets",children:"ESM presets"}),"\n",(0,o.jsxs)(s.p,{children:["There are also ",(0,o.jsx)(s.a,{href:"/ts-jest/docs/28.0/getting-started/presets",children:"3 presets"})," to work with ESM."]}),"\n",(0,o.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsx)(s.h4,{id:"manual-configuration",children:"Manual configuration"}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n extensionsToTreatAsEsm: ['.ts'],\n globals: {\n 'ts-jest': {\n useESM: true,\n },\n },\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n}\n"})}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "extensionsToTreatAsEsm": [".ts"],\n "globals": {\n "ts-jest": {\n "useESM": true\n }\n },\n "moduleNameMapper": {\n "^(\\\\.{1,2}/.*)\\\\.js$": "$1"\n }\n }\n}\n'})}),"\n",(0,o.jsx)(s.h4,{id:"use-esm-presets",children:"Use ESM presets"}),"\n",(0,o.jsx)(s.admonition,{type:"important",children:(0,o.jsxs)(s.p,{children:["Starting from ",(0,o.jsx)(s.strong,{children:"v28.0.0"}),", ",(0,o.jsx)(s.code,{children:"ts-jest"})," will gradually switch to ",(0,o.jsx)(s.code,{children:"esbuild"}),"/",(0,o.jsx)(s.code,{children:"swc"})," to transform ",(0,o.jsx)(s.code,{children:"ts"})," to ",(0,o.jsx)(s.code,{children:"js"}),". To make the transition smoothly, we introduce ",(0,o.jsx)(s.code,{children:"legacy"})," presets as a fallback when the new codes don't work yet."]})}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n preset: 'ts-jest/presets/default-esm', // or other ESM presets\n globals: {\n 'ts-jest': {\n useESM: true,\n },\n },\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n}\n"})}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "preset": "ts-jest/presets/default-esm", // or other ESM presets,\n "globals": {\n "ts-jest": {\n "useESM": true\n }\n },\n "moduleNameMapper": {\n "^(\\\\.{1,2}/.*)\\\\.js$": "$1"\n }\n }\n}\n'})}),"\n",(0,o.jsxs)(s.h4,{id:"support-mts-extension",children:["Support ",(0,o.jsx)(s.code,{children:".mts"})," extension"]}),"\n",(0,o.jsxs)(s.p,{children:["To work with ",(0,o.jsx)(s.code,{children:".mts"})," extension, besides the requirement to run Jest and ",(0,o.jsx)(s.code,{children:"ts-jest"})," in ESM mode, there are a few extra requirements to be met:"]}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:[(0,o.jsx)(s.code,{children:"package.json"})," should contain ",(0,o.jsx)(s.code,{children:'"type": "module"'})]}),"\n",(0,o.jsxs)(s.li,{children:["A custom Jest resolver to resolve ",(0,o.jsx)(s.code,{children:".mjs"})," extension, see our simple one at ",(0,o.jsx)(s.a,{href:"https://github.com/kulshekhar/ts-jest/blob/main/e2e/native-esm-ts/mjs-resolver.ts",children:"https://github.com/kulshekhar/ts-jest/blob/main/e2e/native-esm-ts/mjs-resolver.ts"})]}),"\n",(0,o.jsxs)(s.li,{children:[(0,o.jsx)(s.code,{children:"tsconfig.json"})," should at least contain these following options"]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-json",children:'// tsconfig.spec.json\n{\n "compilerOptions": {\n "module": "Node16", // or "NodeNext"\n "target": "ESNext",\n "moduleResolution": "Node16", // or "NodeNext"\n "esModuleInterop": true\n }\n}\n'})})]})}function u(e={}){const{wrapper:s}={...(0,r.R)(),...e.components};return s?(0,o.jsx)(s,{...e,children:(0,o.jsx)(a,{...e})}):a(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>i,x:()=>l});var t=n(6540);const o={},r=t.createContext(o);function i(e){const s=t.useContext(r);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function l(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),t.createElement(r.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6460],{3732:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>l,default:()=>u,frontMatter:()=>i,metadata:()=>t,toc:()=>d});const t=JSON.parse('{"id":"guides/esm-support","title":"ESM Support","description":"To use ts-jest with ESM support:","source":"@site/versioned_docs/version-28.0/guides/esm-support.md","sourceDirName":"guides","slug":"/guides/esm-support","permalink":"/ts-jest/docs/28.0/guides/esm-support","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/guides/esm-support.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"esm-support","title":"ESM Support"},"sidebar":"version-28.0-docs","previous":{"title":"Version checking","permalink":"/ts-jest/docs/28.0/getting-started/version-checking"},"next":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/28.0/guides/mock-es6-class"}}');var o=n(4848),r=n(8453);const i={id:"esm-support",title:"ESM Support"},l=void 0,c={},d=[{value:"ESM presets",id:"esm-presets",level:3},{value:"Examples",id:"examples",level:3},{value:"Manual configuration",id:"manual-configuration",level:4},{value:"Use ESM presets",id:"use-esm-presets",level:4},{value:"Support .mts extension",id:"support-mts-extension",level:4}];function a(e){const s={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(s.p,{children:["To use ",(0,o.jsx)(s.code,{children:"ts-jest"})," with ESM support:"]}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check ",(0,o.jsx)(s.a,{href:"https://jestjs.io/docs/en/ecmascript-modules",children:"ESM Jest documentation"}),"."]}),"\n",(0,o.jsxs)(s.li,{children:["Enable ",(0,o.jsx)(s.a,{href:"../getting-started/options/useESM",children:"useESM"})," ",(0,o.jsx)(s.code,{children:"true"})," for ",(0,o.jsx)(s.code,{children:"ts-jest"})," config."]}),"\n",(0,o.jsxs)(s.li,{children:["Include ",(0,o.jsx)(s.code,{children:".ts"})," in ",(0,o.jsx)(s.a,{href:"https://jestjs.io/docs/en/next/configuration#extensionstotreatasesm-arraystring",children:"extensionsToTreatAsEsm"})," Jest config option."]}),"\n",(0,o.jsxs)(s.li,{children:["Ensure that ",(0,o.jsx)(s.code,{children:"tsconfig"})," has ",(0,o.jsx)(s.code,{children:"module"})," with value for ESM, e.g. ",(0,o.jsx)(s.code,{children:"ES2015"})," or ",(0,o.jsx)(s.code,{children:"ES2020"})," etc..."]}),"\n"]}),"\n",(0,o.jsx)(s.h3,{id:"esm-presets",children:"ESM presets"}),"\n",(0,o.jsxs)(s.p,{children:["There are also ",(0,o.jsx)(s.a,{href:"/ts-jest/docs/28.0/getting-started/presets",children:"3 presets"})," to work with ESM."]}),"\n",(0,o.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsx)(s.h4,{id:"manual-configuration",children:"Manual configuration"}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n extensionsToTreatAsEsm: ['.ts'],\n globals: {\n 'ts-jest': {\n useESM: true,\n },\n },\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n}\n"})}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "extensionsToTreatAsEsm": [".ts"],\n "globals": {\n "ts-jest": {\n "useESM": true\n }\n },\n "moduleNameMapper": {\n "^(\\\\.{1,2}/.*)\\\\.js$": "$1"\n }\n }\n}\n'})}),"\n",(0,o.jsx)(s.h4,{id:"use-esm-presets",children:"Use ESM presets"}),"\n",(0,o.jsx)(s.admonition,{type:"important",children:(0,o.jsxs)(s.p,{children:["Starting from ",(0,o.jsx)(s.strong,{children:"v28.0.0"}),", ",(0,o.jsx)(s.code,{children:"ts-jest"})," will gradually switch to ",(0,o.jsx)(s.code,{children:"esbuild"}),"/",(0,o.jsx)(s.code,{children:"swc"})," to transform ",(0,o.jsx)(s.code,{children:"ts"})," to ",(0,o.jsx)(s.code,{children:"js"}),". To make the transition smoothly, we introduce ",(0,o.jsx)(s.code,{children:"legacy"})," presets as a fallback when the new codes don't work yet."]})}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n preset: 'ts-jest/presets/default-esm', // or other ESM presets\n globals: {\n 'ts-jest': {\n useESM: true,\n },\n },\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n}\n"})}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "preset": "ts-jest/presets/default-esm", // or other ESM presets,\n "globals": {\n "ts-jest": {\n "useESM": true\n }\n },\n "moduleNameMapper": {\n "^(\\\\.{1,2}/.*)\\\\.js$": "$1"\n }\n }\n}\n'})}),"\n",(0,o.jsxs)(s.h4,{id:"support-mts-extension",children:["Support ",(0,o.jsx)(s.code,{children:".mts"})," extension"]}),"\n",(0,o.jsxs)(s.p,{children:["To work with ",(0,o.jsx)(s.code,{children:".mts"})," extension, besides the requirement to run Jest and ",(0,o.jsx)(s.code,{children:"ts-jest"})," in ESM mode, there are a few extra requirements to be met:"]}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:[(0,o.jsx)(s.code,{children:"package.json"})," should contain ",(0,o.jsx)(s.code,{children:'"type": "module"'})]}),"\n",(0,o.jsxs)(s.li,{children:["A custom Jest resolver to resolve ",(0,o.jsx)(s.code,{children:".mjs"})," extension, see our simple one at ",(0,o.jsx)(s.a,{href:"https://github.com/kulshekhar/ts-jest/blob/main/e2e/native-esm-ts/mjs-resolver.ts",children:"https://github.com/kulshekhar/ts-jest/blob/main/e2e/native-esm-ts/mjs-resolver.ts"})]}),"\n",(0,o.jsxs)(s.li,{children:[(0,o.jsx)(s.code,{children:"tsconfig.json"})," should at least contain these following options"]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-json",children:'// tsconfig.spec.json\n{\n "compilerOptions": {\n "module": "Node16", // or "NodeNext"\n "target": "ESNext",\n "moduleResolution": "Node16", // or "NodeNext"\n "esModuleInterop": true\n }\n}\n'})})]})}function u(e={}){const{wrapper:s}={...(0,r.R)(),...e.components};return s?(0,o.jsx)(s,{...e,children:(0,o.jsx)(a,{...e})}):a(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>i,x:()=>l});var t=n(6540);const o={},r=t.createContext(o);function i(e){const s=t.useContext(r);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function l(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),t.createElement(r.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/6789ef91.1bfe1b39.js b/assets/js/6789ef91.31fd45fd.js similarity index 99% rename from assets/js/6789ef91.1bfe1b39.js rename to assets/js/6789ef91.31fd45fd.js index bc1885c906..c5900a815f 100644 --- a/assets/js/6789ef91.1bfe1b39.js +++ b/assets/js/6789ef91.31fd45fd.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3960],{7195:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>d,default:()=>a,frontMatter:()=>r,metadata:()=>t,toc:()=>l});const t=JSON.parse('{"id":"getting-started/options","title":"Options","description":"Introduction","source":"@site/versioned_docs/version-26.5/getting-started/options.md","sourceDirName":"getting-started","slug":"/getting-started/options","permalink":"/ts-jest/docs/26.5/getting-started/options","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/getting-started/options.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"options","title":"Options"},"sidebar":"version-26.5-docs","previous":{"title":"Presets","permalink":"/ts-jest/docs/26.5/getting-started/presets"},"next":{"title":"Paths mapping","permalink":"/ts-jest/docs/26.5/getting-started/paths-mapping"}}');var i=n(4848),o=n(8453);const r={id:"options",title:"Options"},d=void 0,c={},l=[{value:"Introduction",id:"introduction",level:3},{value:"Options",id:"options",level:3}];function h(e){const s={a:"a",admonition:"admonition",code:"code",em:"em",h3:"h3",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(s.h3,{id:"introduction",children:"Introduction"}),"\n",(0,i.jsxs)(s.p,{children:["All ",(0,i.jsx)(s.code,{children:"ts-jest"})," specific options are located under the ",(0,i.jsx)(s.code,{children:"globals"})," of Jest config object in the ",(0,i.jsx)(s.code,{children:"package.json"})," file of your project,\nor through a ",(0,i.jsx)(s.code,{children:"jest.config.js"}),", or ",(0,i.jsx)(s.code,{children:"jest.config.ts"})," file."]}),"\n",(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n // ts-jest configuration goes here\n }\n }\n }\n}\n'})}),"\n",(0,i.jsx)(s.p,{children:"Or through JavaScript:"}),"\n",(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n // ts-jest configuration goes here\n },\n },\n}\n"})}),"\n",(0,i.jsxs)(s.admonition,{type:"tip",children:[(0,i.jsxs)(s.p,{children:["To utilize IDE suggestions, you can use ",(0,i.jsx)(s.code,{children:"JSDoc"})," comments to provide suggested ",(0,i.jsx)(s.code,{children:"ts-jest"})," configs for your Jest config:"]}),(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",children:"// jest.config.js\n/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */\nmodule.exports = config = {\n // [...]\n globals: {\n 'ts-jest': {\n // ts-jest configuration goes here and your IDE will suggest which configs when typing\n },\n },\n}\n"})})]}),"\n",(0,i.jsx)(s.h3,{id:"options",children:"Options"}),"\n",(0,i.jsx)(s.p,{children:"All options have default values which should fit most of the projects. Click on the option's name to see details and example(s)."}),"\n",(0,i.jsxs)(s.table,{children:[(0,i.jsx)(s.thead,{children:(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.th,{children:"Option"}),(0,i.jsx)(s.th,{children:"Description"}),(0,i.jsx)(s.th,{children:"Type"}),(0,i.jsx)(s.th,{children:"Default"})]})}),(0,i.jsxs)(s.tbody,{children:[(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/compiler",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"compiler"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"string"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:'"typescript"'})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/tsconfig",children:(0,i.jsxs)(s.strong,{children:[(0,i.jsx)(s.code,{children:"tsconfig"})," or ",(0,i.jsx)(s.code,{children:"tsConfig(DEPRECATED)"})]})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"string"}),"|",(0,i.jsx)(s.code,{children:"object"}),"|",(0,i.jsx)(s.code,{children:"boolean"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"auto"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/isolatedModules",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"isolatedModules"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"boolean"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"disabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/astTransformers",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"astTransformers"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"object"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"auto"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/diagnostics",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"diagnostics"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"boolean"}),"|",(0,i.jsx)(s.code,{children:"object"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"enabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/babelConfig",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"babelConfig"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"boolean"}),"|",(0,i.jsx)(s.code,{children:"string"}),"|",(0,i.jsx)(s.code,{children:"object"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"disabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"stringifyContentPathRegex"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"string"}),"|",(0,i.jsx)(s.code,{children:"RegExp"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"disabled"})})]})]})]})]})}function a(e={}){const{wrapper:s}={...(0,o.R)(),...e.components};return s?(0,i.jsx)(s,{...e,children:(0,i.jsx)(h,{...e})}):h(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>r,x:()=>d});var t=n(6540);const i={},o=t.createContext(i);function r(e){const s=t.useContext(o);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function d(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),t.createElement(o.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3960],{7195:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>d,default:()=>a,frontMatter:()=>r,metadata:()=>t,toc:()=>l});const t=JSON.parse('{"id":"getting-started/options","title":"Options","description":"Introduction","source":"@site/versioned_docs/version-26.5/getting-started/options.md","sourceDirName":"getting-started","slug":"/getting-started/options","permalink":"/ts-jest/docs/26.5/getting-started/options","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/getting-started/options.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"options","title":"Options"},"sidebar":"version-26.5-docs","previous":{"title":"Presets","permalink":"/ts-jest/docs/26.5/getting-started/presets"},"next":{"title":"Paths mapping","permalink":"/ts-jest/docs/26.5/getting-started/paths-mapping"}}');var i=n(4848),o=n(8453);const r={id:"options",title:"Options"},d=void 0,c={},l=[{value:"Introduction",id:"introduction",level:3},{value:"Options",id:"options",level:3}];function h(e){const s={a:"a",admonition:"admonition",code:"code",em:"em",h3:"h3",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(s.h3,{id:"introduction",children:"Introduction"}),"\n",(0,i.jsxs)(s.p,{children:["All ",(0,i.jsx)(s.code,{children:"ts-jest"})," specific options are located under the ",(0,i.jsx)(s.code,{children:"globals"})," of Jest config object in the ",(0,i.jsx)(s.code,{children:"package.json"})," file of your project,\nor through a ",(0,i.jsx)(s.code,{children:"jest.config.js"}),", or ",(0,i.jsx)(s.code,{children:"jest.config.ts"})," file."]}),"\n",(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n // ts-jest configuration goes here\n }\n }\n }\n}\n'})}),"\n",(0,i.jsx)(s.p,{children:"Or through JavaScript:"}),"\n",(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n // ts-jest configuration goes here\n },\n },\n}\n"})}),"\n",(0,i.jsxs)(s.admonition,{type:"tip",children:[(0,i.jsxs)(s.p,{children:["To utilize IDE suggestions, you can use ",(0,i.jsx)(s.code,{children:"JSDoc"})," comments to provide suggested ",(0,i.jsx)(s.code,{children:"ts-jest"})," configs for your Jest config:"]}),(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",children:"// jest.config.js\n/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */\nmodule.exports = config = {\n // [...]\n globals: {\n 'ts-jest': {\n // ts-jest configuration goes here and your IDE will suggest which configs when typing\n },\n },\n}\n"})})]}),"\n",(0,i.jsx)(s.h3,{id:"options",children:"Options"}),"\n",(0,i.jsx)(s.p,{children:"All options have default values which should fit most of the projects. Click on the option's name to see details and example(s)."}),"\n",(0,i.jsxs)(s.table,{children:[(0,i.jsx)(s.thead,{children:(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.th,{children:"Option"}),(0,i.jsx)(s.th,{children:"Description"}),(0,i.jsx)(s.th,{children:"Type"}),(0,i.jsx)(s.th,{children:"Default"})]})}),(0,i.jsxs)(s.tbody,{children:[(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/compiler",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"compiler"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"string"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:'"typescript"'})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/tsconfig",children:(0,i.jsxs)(s.strong,{children:[(0,i.jsx)(s.code,{children:"tsconfig"})," or ",(0,i.jsx)(s.code,{children:"tsConfig(DEPRECATED)"})]})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"string"}),"|",(0,i.jsx)(s.code,{children:"object"}),"|",(0,i.jsx)(s.code,{children:"boolean"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"auto"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/isolatedModules",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"isolatedModules"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"boolean"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"disabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/astTransformers",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"astTransformers"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"object"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"auto"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/diagnostics",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"diagnostics"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"boolean"}),"|",(0,i.jsx)(s.code,{children:"object"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"enabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/babelConfig",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"babelConfig"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"boolean"}),"|",(0,i.jsx)(s.code,{children:"string"}),"|",(0,i.jsx)(s.code,{children:"object"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"disabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"stringifyContentPathRegex"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"string"}),"|",(0,i.jsx)(s.code,{children:"RegExp"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"disabled"})})]})]})]})]})}function a(e={}){const{wrapper:s}={...(0,o.R)(),...e.components};return s?(0,i.jsx)(s,{...e,children:(0,i.jsx)(h,{...e})}):h(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>r,x:()=>d});var t=n(6540);const i={},o=t.createContext(i);function r(e){const s=t.useContext(o);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function d(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),t.createElement(o.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/684ec830.9fd6bfb9.js b/assets/js/684ec830.fbea694e.js similarity index 99% rename from assets/js/684ec830.9fd6bfb9.js rename to assets/js/684ec830.fbea694e.js index 72c0556c7a..d7663bc2b7 100644 --- a/assets/js/684ec830.9fd6bfb9.js +++ b/assets/js/684ec830.fbea694e.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5584],{6563:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>m,frontMatter:()=>i,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/compiler","title":"Compiler option","description":"The compiler option allows you to define the compiler to be used. It\'ll be used to load the NodeJS module holding the TypeScript compiler.","source":"@site/versioned_docs/version-29.0/getting-started/options/compiler.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/compiler","permalink":"/ts-jest/docs/29.0/getting-started/options/compiler","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/options/compiler.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Compiler option"}}');var r=s(4848),o=s(8453),a=s(9489),l=s(7227);const i={title:"Compiler option"},c=void 0,u={},d=[{value:"Example",id:"example",level:3}];function p(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["The ",(0,r.jsx)(t.code,{children:"compiler"})," option allows you to define the compiler to be used. It'll be used to load the NodeJS module holding the TypeScript compiler."]}),"\n",(0,r.jsxs)(t.p,{children:["The default value is ",(0,r.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,r.jsx)(t.a,{href:"https://www.npmjs.com/package/typescript",children:"TypeScript compiler module"}),".\nThe loaded version will depend on the one installed in your project."]}),"\n",(0,r.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,r.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,r.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,r.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n compiler: 'ttypescript',\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n compiler: 'ttypescript',\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "compiler": "ttypescript"\n }\n ]\n }\n }\n}\n'})})})]})]})}function m(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>a});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var o=s(4848);function a(e){let{children:t,hidden:s,className:a}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,a),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>w});var n=s(6540),r=s(4164),o=s(4245),a=s(6347),l=s(6494),i=s(2814),c=s(5167),u=s(9900);function d(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:r}}=e;return{value:t,label:s,attributes:n,default:r}}))}(s);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function m(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:s}=e;const r=(0,a.W6)(),o=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,i.aZ)(o),(0,n.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(r.location.search);t.set(o,e),r.replace({...r.location,search:t.toString()})}),[o,r])]}function f(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,o=p(e),[a,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:o}))),[c,d]=h({queryString:s,groupId:r}),[f,j]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,o]=(0,u.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&o.set(e)}),[s,o])]}({groupId:r}),b=(()=>{const e=c??f;return m({value:e,tabValues:o})?e:null})();(0,l.A)((()=>{b&&i(b)}),[b]);return{selectedValue:a,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);i(e),d(e),j(e)}),[d,j,o]),tabValues:o}}var j=s(1062);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=s(4848);function g(e){let{className:t,block:s,selectedValue:n,selectValue:a,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.a_)(),u=e=>{const t=e.currentTarget,s=i.indexOf(t),r=l[s].value;r!==n&&(c(t),a(r))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const s=i.indexOf(e.currentTarget)+1;t=i[s]??i[0];break}case"ArrowLeft":{const s=i.indexOf(e.currentTarget)-1;t=i[s]??i[i.length-1];break}}t?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":s},t),children:l.map((e=>{let{value:t,label:s,attributes:o}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:d,onClick:u,...o,className:(0,r.A)("tabs__item",b.tabItem,o?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:o}=e;const a=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=a.find((e=>e.props.value===o));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:a.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==o})))})}function y(e){const t=f(e);return(0,x.jsxs)("div",{className:(0,r.A)("tabs-container",b.tabList),children:[(0,x.jsx)(g,{...t,...e}),(0,x.jsx)(v,{...t,...e})]})}function w(e){const t=(0,j.A)();return(0,x.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>a,x:()=>l});var n=s(6540);const r={},o=n.createContext(r);function a(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5584],{6563:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>m,frontMatter:()=>i,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/compiler","title":"Compiler option","description":"The compiler option allows you to define the compiler to be used. It\'ll be used to load the NodeJS module holding the TypeScript compiler.","source":"@site/versioned_docs/version-29.0/getting-started/options/compiler.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/compiler","permalink":"/ts-jest/docs/29.0/getting-started/options/compiler","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/options/compiler.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Compiler option"}}');var r=s(4848),o=s(8453),a=s(9489),l=s(7227);const i={title:"Compiler option"},c=void 0,u={},d=[{value:"Example",id:"example",level:3}];function p(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["The ",(0,r.jsx)(t.code,{children:"compiler"})," option allows you to define the compiler to be used. It'll be used to load the NodeJS module holding the TypeScript compiler."]}),"\n",(0,r.jsxs)(t.p,{children:["The default value is ",(0,r.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,r.jsx)(t.a,{href:"https://www.npmjs.com/package/typescript",children:"TypeScript compiler module"}),".\nThe loaded version will depend on the one installed in your project."]}),"\n",(0,r.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,r.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,r.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,r.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n compiler: 'ttypescript',\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n compiler: 'ttypescript',\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "compiler": "ttypescript"\n }\n ]\n }\n }\n}\n'})})})]})]})}function m(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>a});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var o=s(4848);function a(e){let{children:t,hidden:s,className:a}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,a),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>w});var n=s(6540),r=s(4164),o=s(4245),a=s(6347),l=s(6494),i=s(2814),c=s(5167),u=s(9900);function d(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:r}}=e;return{value:t,label:s,attributes:n,default:r}}))}(s);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function m(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:s}=e;const r=(0,a.W6)(),o=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,i.aZ)(o),(0,n.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(r.location.search);t.set(o,e),r.replace({...r.location,search:t.toString()})}),[o,r])]}function f(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,o=p(e),[a,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:o}))),[c,d]=h({queryString:s,groupId:r}),[f,j]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,o]=(0,u.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&o.set(e)}),[s,o])]}({groupId:r}),b=(()=>{const e=c??f;return m({value:e,tabValues:o})?e:null})();(0,l.A)((()=>{b&&i(b)}),[b]);return{selectedValue:a,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);i(e),d(e),j(e)}),[d,j,o]),tabValues:o}}var j=s(1062);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=s(4848);function g(e){let{className:t,block:s,selectedValue:n,selectValue:a,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.a_)(),u=e=>{const t=e.currentTarget,s=i.indexOf(t),r=l[s].value;r!==n&&(c(t),a(r))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const s=i.indexOf(e.currentTarget)+1;t=i[s]??i[0];break}case"ArrowLeft":{const s=i.indexOf(e.currentTarget)-1;t=i[s]??i[i.length-1];break}}t?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":s},t),children:l.map((e=>{let{value:t,label:s,attributes:o}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:d,onClick:u,...o,className:(0,r.A)("tabs__item",b.tabItem,o?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:o}=e;const a=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=a.find((e=>e.props.value===o));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:a.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==o})))})}function y(e){const t=f(e);return(0,x.jsxs)("div",{className:(0,r.A)("tabs-container",b.tabList),children:[(0,x.jsx)(g,{...t,...e}),(0,x.jsx)(v,{...t,...e})]})}function w(e){const t=(0,j.A)();return(0,x.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>a,x:()=>l});var n=s(6540);const r={},o=n.createContext(r);function a(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/6bc4332d.639b5dee.js b/assets/js/6bc4332d.c40d1ab1.js similarity index 98% rename from assets/js/6bc4332d.639b5dee.js rename to assets/js/6bc4332d.c40d1ab1.js index 31b54cef4b..812929df3c 100644 --- a/assets/js/6bc4332d.639b5dee.js +++ b/assets/js/6bc4332d.c40d1ab1.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7350],{5671:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>c,default:()=>a,frontMatter:()=>i,metadata:()=>n,toc:()=>u});const n=JSON.parse('{"id":"processing","title":"Processing flow","description":"These are internal technical documents. If you\'re not a contributor to ts-jest, but simply trying to use the library you\'ll find nothing of value here","source":"@site/versioned_docs/version-27.1/processing.md","sourceDirName":".","slug":"/processing","permalink":"/ts-jest/docs/27.1/processing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/processing.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"processing","title":"Processing flow"},"sidebar":"version-27.1-docs","previous":{"title":"Introduction","permalink":"/ts-jest/docs/27.1/"},"next":{"title":"Contributing","permalink":"/ts-jest/docs/27.1/contributing"}}');var o=s(4848),r=s(8453);const i={id:"processing",title:"Processing flow"},c=void 0,l={},u=[{value:"Jest process",id:"jest-process",level:2},{value:"ts-jest process",id:"ts-jest-process",level:2}];function d(e){const t={code:"code",em:"em",h2:"h2",img:"img",p:"p",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.p,{children:(0,o.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,o.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,o.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,o.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,o.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLJRRjim37tNLn3Omn9WwGUaG8Uz3YWmOFq1nQ9YjJ8PY7Iz0lduGHV7YHjWyvDruI7FuH7FfyGTYd0w6r6Rr9YzoayKVMWd6-4nTRXzD2Pus4ZFOtGWcW8TW__ulWNjaM3pWR8r-rTXMWuVpUu9nfEpYgR2F1g3KH0sn5k3v8Ali3v493iW83c1AMWF3-v1vHPz2YU46OXO4L8uzcg8WH0TA4F7mob4D0vzeA212JAsv6IGGwuBCESlBtqGZNXkSGasdUrwTDjpgIi8HwleO60tHfHRkWlIlaje5S6IWm9WL21QEe9WUW-vtiPsztHXK3CGd31944NI6hlIj0e80muDsYSUFWNTAFllqlUDSD7QQB8aUVbSxZPn8terHJsOGenmm5bUPwp0Ei6Ln000IpLGljkCTUyYJbqkMQ5zWtr360M1VQv-3hYSLzaTs0E_Nwdlp88momP1CfA3gKUw72UqBj2ncQJkhNZKlbKAeoWFyEFtIraNsJod0PDK3ci6FQQIU2e_FGVHd8rzEt_DBstWxYrVSapu3Qp0X362dSiP1TEk-3bRV4vfixVdAmURYJ51n-J3qNnciNkwz6xnN-7amv-s0uCzDHwVJ7UxVSzyHQRprJov-_YN9zycIMxkmHumhlnPzkuFeaNapiOeDNoNfJINz8iP_tS4zLR0UiNqgs90p_osVZGsDsPzwTwOMseCrRdv8YJKCP4OuG6rpqu8-hMyB5EiQGK8fzQEwv5LozmlXhlg8fBx2m00"})]})}function a(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7350],{5671:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>c,default:()=>a,frontMatter:()=>i,metadata:()=>n,toc:()=>u});const n=JSON.parse('{"id":"processing","title":"Processing flow","description":"These are internal technical documents. If you\'re not a contributor to ts-jest, but simply trying to use the library you\'ll find nothing of value here","source":"@site/versioned_docs/version-27.1/processing.md","sourceDirName":".","slug":"/processing","permalink":"/ts-jest/docs/27.1/processing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/processing.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"processing","title":"Processing flow"},"sidebar":"version-27.1-docs","previous":{"title":"Introduction","permalink":"/ts-jest/docs/27.1/"},"next":{"title":"Contributing","permalink":"/ts-jest/docs/27.1/contributing"}}');var o=s(4848),r=s(8453);const i={id:"processing",title:"Processing flow"},c=void 0,l={},u=[{value:"Jest process",id:"jest-process",level:2},{value:"ts-jest process",id:"ts-jest-process",level:2}];function d(e){const t={code:"code",em:"em",h2:"h2",img:"img",p:"p",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.p,{children:(0,o.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,o.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,o.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,o.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,o.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLJRRjim37tNLn3Omn9WwGUaG8Uz3YWmOFq1nQ9YjJ8PY7Iz0lduGHV7YHjWyvDruI7FuH7FfyGTYd0w6r6Rr9YzoayKVMWd6-4nTRXzD2Pus4ZFOtGWcW8TW__ulWNjaM3pWR8r-rTXMWuVpUu9nfEpYgR2F1g3KH0sn5k3v8Ali3v493iW83c1AMWF3-v1vHPz2YU46OXO4L8uzcg8WH0TA4F7mob4D0vzeA212JAsv6IGGwuBCESlBtqGZNXkSGasdUrwTDjpgIi8HwleO60tHfHRkWlIlaje5S6IWm9WL21QEe9WUW-vtiPsztHXK3CGd31944NI6hlIj0e80muDsYSUFWNTAFllqlUDSD7QQB8aUVbSxZPn8terHJsOGenmm5bUPwp0Ei6Ln000IpLGljkCTUyYJbqkMQ5zWtr360M1VQv-3hYSLzaTs0E_Nwdlp88momP1CfA3gKUw72UqBj2ncQJkhNZKlbKAeoWFyEFtIraNsJod0PDK3ci6FQQIU2e_FGVHd8rzEt_DBstWxYrVSapu3Qp0X362dSiP1TEk-3bRV4vfixVdAmURYJ51n-J3qNnciNkwz6xnN-7amv-s0uCzDHwVJ7UxVSzyHQRprJov-_YN9zycIMxkmHumhlnPzkuFeaNapiOeDNoNfJINz8iP_tS4zLR0UiNqgs90p_osVZGsDsPzwTwOMseCrRdv8YJKCP4OuG6rpqu8-hMyB5EiQGK8fzQEwv5LozmlXhlg8fBx2m00"})]})}function a(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/6cdc57e1.57b80edb.js b/assets/js/6cdc57e1.27f28efa.js similarity index 98% rename from assets/js/6cdc57e1.57b80edb.js rename to assets/js/6cdc57e1.27f28efa.js index f6208c581c..c1393b58d5 100644 --- a/assets/js/6cdc57e1.57b80edb.js +++ b/assets/js/6cdc57e1.27f28efa.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9995],{8544:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>c,default:()=>a,frontMatter:()=>i,metadata:()=>n,toc:()=>u});const n=JSON.parse('{"id":"processing","title":"Processing flow","description":"These are internal technical documents. If you\'re not a contributor to ts-jest, but simply trying to use the library you\'ll find nothing of value here","source":"@site/versioned_docs/version-27.0/processing.md","sourceDirName":".","slug":"/processing","permalink":"/ts-jest/docs/27.0/processing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/processing.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"processing","title":"Processing flow"},"sidebar":"version-27.0-docs","previous":{"title":"Introduction","permalink":"/ts-jest/docs/27.0/"},"next":{"title":"Contributing","permalink":"/ts-jest/docs/27.0/contributing"}}');var o=s(4848),r=s(8453);const i={id:"processing",title:"Processing flow"},c=void 0,l={},u=[{value:"Jest process",id:"jest-process",level:2},{value:"ts-jest process",id:"ts-jest-process",level:2}];function d(e){const t={code:"code",em:"em",h2:"h2",img:"img",p:"p",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.p,{children:(0,o.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,o.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,o.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,o.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,o.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLJRRjim37tNLn3Omn9WwGUaG8Uz3YWmOFq1nQ9YjJ8PY7Iz0lduGHV7YHjWyvDruI7FuH7FfyGTYd0w6r6Rr9YzoayKVMWd6-4nTRXzD2Pus4ZFOtGWcW8TW__ulWNjaM3pWR8r-rTXMWuVpUu9nfEpYgR2F1g3KH0sn5k3v8Ali3v493iW83c1AMWF3-v1vHPz2YU46OXO4L8uzcg8WH0TA4F7mob4D0vzeA212JAsv6IGGwuBCESlBtqGZNXkSGasdUrwTDjpgIi8HwleO60tHfHRkWlIlaje5S6IWm9WL21QEe9WUW-vtiPsztHXK3CGd31944NI6hlIj0e80muDsYSUFWNTAFllqlUDSD7QQB8aUVbSxZPn8terHJsOGenmm5bUPwp0Ei6Ln000IpLGljkCTUyYJbqkMQ5zWtr360M1VQv-3hYSLzaTs0E_Nwdlp88momP1CfA3gKUw72UqBj2ncQJkhNZKlbKAeoWFyEFtIraNsJod0PDK3ci6FQQIU2e_FGVHd8rzEt_DBstWxYrVSapu3Qp0X362dSiP1TEk-3bRV4vfixVdAmURYJ51n-J3qNnciNkwz6xnN-7amv-s0uCzDHwVJ7UxVSzyHQRprJov-_YN9zycIMxkmHumhlnPzkuFeaNapiOeDNoNfJINz8iP_tS4zLR0UiNqgs90p_osVZGsDsPzwTwOMseCrRdv8YJKCP4OuG6rpqu8-hMyB5EiQGK8fzQEwv5LozmlXhlg8fBx2m00"})]})}function a(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9995],{8544:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>c,default:()=>a,frontMatter:()=>i,metadata:()=>n,toc:()=>u});const n=JSON.parse('{"id":"processing","title":"Processing flow","description":"These are internal technical documents. If you\'re not a contributor to ts-jest, but simply trying to use the library you\'ll find nothing of value here","source":"@site/versioned_docs/version-27.0/processing.md","sourceDirName":".","slug":"/processing","permalink":"/ts-jest/docs/27.0/processing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/processing.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"processing","title":"Processing flow"},"sidebar":"version-27.0-docs","previous":{"title":"Introduction","permalink":"/ts-jest/docs/27.0/"},"next":{"title":"Contributing","permalink":"/ts-jest/docs/27.0/contributing"}}');var o=s(4848),r=s(8453);const i={id:"processing",title:"Processing flow"},c=void 0,l={},u=[{value:"Jest process",id:"jest-process",level:2},{value:"ts-jest process",id:"ts-jest-process",level:2}];function d(e){const t={code:"code",em:"em",h2:"h2",img:"img",p:"p",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.p,{children:(0,o.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,o.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,o.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,o.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,o.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLJRRjim37tNLn3Omn9WwGUaG8Uz3YWmOFq1nQ9YjJ8PY7Iz0lduGHV7YHjWyvDruI7FuH7FfyGTYd0w6r6Rr9YzoayKVMWd6-4nTRXzD2Pus4ZFOtGWcW8TW__ulWNjaM3pWR8r-rTXMWuVpUu9nfEpYgR2F1g3KH0sn5k3v8Ali3v493iW83c1AMWF3-v1vHPz2YU46OXO4L8uzcg8WH0TA4F7mob4D0vzeA212JAsv6IGGwuBCESlBtqGZNXkSGasdUrwTDjpgIi8HwleO60tHfHRkWlIlaje5S6IWm9WL21QEe9WUW-vtiPsztHXK3CGd31944NI6hlIj0e80muDsYSUFWNTAFllqlUDSD7QQB8aUVbSxZPn8terHJsOGenmm5bUPwp0Ei6Ln000IpLGljkCTUyYJbqkMQ5zWtr360M1VQv-3hYSLzaTs0E_Nwdlp88momP1CfA3gKUw72UqBj2ncQJkhNZKlbKAeoWFyEFtIraNsJod0PDK3ci6FQQIU2e_FGVHd8rzEt_DBstWxYrVSapu3Qp0X362dSiP1TEk-3bRV4vfixVdAmURYJ51n-J3qNnciNkwz6xnN-7amv-s0uCzDHwVJ7UxVSzyHQRprJov-_YN9zycIMxkmHumhlnPzkuFeaNapiOeDNoNfJINz8iP_tS4zLR0UiNqgs90p_osVZGsDsPzwTwOMseCrRdv8YJKCP4OuG6rpqu8-hMyB5EiQGK8fzQEwv5LozmlXhlg8fBx2m00"})]})}function a(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/6f04af8d.af15916e.js b/assets/js/6f04af8d.77c90ed6.js similarity index 99% rename from assets/js/6f04af8d.af15916e.js rename to assets/js/6f04af8d.77c90ed6.js index f116ef0217..82e7a8e682 100644 --- a/assets/js/6f04af8d.af15916e.js +++ b/assets/js/6f04af8d.77c90ed6.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6018],{4358:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>i,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/isolatedModules","title":"Isolated Modules option","description":"By default ts-jest uses TypeScript compiler in the context of a project (yours), with full type-checking and features.","source":"@site/docs/getting-started/options/isolatedModules.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/isolatedModules","permalink":"/ts-jest/docs/next/getting-started/options/isolatedModules","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/isolatedModules.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Isolated Modules option"}}');var a=s(4848),r=s(8453),o=s(9489),l=s(7227);const i={title:"Isolated Modules option"},c=void 0,u={},d=[{value:"Example",id:"example",level:3},{value:"Performance",id:"performance",level:2},{value:"Example",id:"example-1",level:3},{value:"Caveats",id:"caveats",level:2}];function h(e){const t={code:"code",h2:"h2",h3:"h3",p:"p",pre:"pre",...(0,r.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(t.p,{children:["By default ",(0,a.jsx)(t.code,{children:"ts-jest"})," uses TypeScript compiler in the context of a project (yours), with full type-checking and features.\nBut it can also be used to compile each file separately, what TypeScript calls an 'isolated module'.\nThat's what the ",(0,a.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,a.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,a.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,a.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,a.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,a.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\n",(0,a.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,a.jsxs)(o.A,{groupId:"code-examples",children:[(0,a.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n isolatedModules: true,\n },\n ],\n },\n}\n"})})}),(0,a.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process js/ts with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process js/ts/mjs/mts with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n isolatedModules: true,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,a.jsx)(l.A,{value:"JSON",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process js/ts with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process js/ts/mjs/mts with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "isolatedModules": true\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,a.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,a.jsxs)(t.p,{children:["Using ",(0,a.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,a.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,a.jsx)(t.code,{children:"include"})," in ",(0,a.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,a.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,a.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,a.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,a.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,a.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,a.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,a.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,a.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,a.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,a.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(h,{...e})}):h(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>o});s(6540);var n=s(4164);const a={tabItem:"tabItem_Ymn6"};var r=s(4848);function o(e){let{children:t,hidden:s,className:o}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,n.A)(a.tabItem,o),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>w});var n=s(6540),a=s(4164),r=s(4245),o=s(6347),l=s(6494),i=s(2814),c=s(5167),u=s(9900);function d(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:a}}=e;return{value:t,label:s,attributes:n,default:a}}))}(s);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function p(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:s}=e;const a=(0,o.W6)(),r=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,i.aZ)(r),(0,n.useCallback)((e=>{if(!r)return;const t=new URLSearchParams(a.location.search);t.set(r,e),a.replace({...a.location,search:t.toString()})}),[r,a])]}function f(e){const{defaultValue:t,queryString:s=!1,groupId:a}=e,r=h(e),[o,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:r}))),[c,d]=m({queryString:s,groupId:a}),[f,j]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,r]=(0,u.Dv)(s);return[a,(0,n.useCallback)((e=>{s&&r.set(e)}),[s,r])]}({groupId:a}),g=(()=>{const e=c??f;return p({value:e,tabValues:r})?e:null})();(0,l.A)((()=>{g&&i(g)}),[g]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!p({value:e,tabValues:r}))throw new Error(`Can't select invalid tab value=${e}`);i(e),d(e),j(e)}),[d,j,r]),tabValues:r}}var j=s(1062);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=s(4848);function x(e){let{className:t,block:s,selectedValue:n,selectValue:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),u=e=>{const t=e.currentTarget,s=i.indexOf(t),a=l[s].value;a!==n&&(c(t),o(a))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const s=i.indexOf(e.currentTarget)+1;t=i[s]??i[0];break}case"ArrowLeft":{const s=i.indexOf(e.currentTarget)-1;t=i[s]??i[i.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.A)("tabs",{"tabs--block":s},t),children:l.map((e=>{let{value:t,label:s,attributes:r}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:d,onClick:u,...r,className:(0,a.A)("tabs__item",g.tabItem,r?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:r}=e;const o=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===r));return e?(0,n.cloneElement)(e,{className:(0,a.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==r})))})}function y(e){const t=f(e);return(0,b.jsxs)("div",{className:(0,a.A)("tabs-container",g.tabList),children:[(0,b.jsx)(x,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function w(e){const t=(0,j.A)();return(0,b.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>o,x:()=>l});var n=s(6540);const a={},r=n.createContext(a);function o(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6018],{4358:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>i,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/isolatedModules","title":"Isolated Modules option","description":"By default ts-jest uses TypeScript compiler in the context of a project (yours), with full type-checking and features.","source":"@site/docs/getting-started/options/isolatedModules.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/isolatedModules","permalink":"/ts-jest/docs/next/getting-started/options/isolatedModules","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/isolatedModules.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Isolated Modules option"}}');var a=s(4848),r=s(8453),o=s(9489),l=s(7227);const i={title:"Isolated Modules option"},c=void 0,u={},d=[{value:"Example",id:"example",level:3},{value:"Performance",id:"performance",level:2},{value:"Example",id:"example-1",level:3},{value:"Caveats",id:"caveats",level:2}];function h(e){const t={code:"code",h2:"h2",h3:"h3",p:"p",pre:"pre",...(0,r.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(t.p,{children:["By default ",(0,a.jsx)(t.code,{children:"ts-jest"})," uses TypeScript compiler in the context of a project (yours), with full type-checking and features.\nBut it can also be used to compile each file separately, what TypeScript calls an 'isolated module'.\nThat's what the ",(0,a.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,a.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,a.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,a.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,a.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,a.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\n",(0,a.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,a.jsxs)(o.A,{groupId:"code-examples",children:[(0,a.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n isolatedModules: true,\n },\n ],\n },\n}\n"})})}),(0,a.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process js/ts with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process js/ts/mjs/mts with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n isolatedModules: true,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,a.jsx)(l.A,{value:"JSON",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process js/ts with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process js/ts/mjs/mts with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "isolatedModules": true\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,a.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,a.jsxs)(t.p,{children:["Using ",(0,a.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,a.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,a.jsx)(t.code,{children:"include"})," in ",(0,a.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,a.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,a.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,a.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,a.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,a.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,a.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,a.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,a.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,a.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,a.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(h,{...e})}):h(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>o});s(6540);var n=s(4164);const a={tabItem:"tabItem_Ymn6"};var r=s(4848);function o(e){let{children:t,hidden:s,className:o}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,n.A)(a.tabItem,o),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>w});var n=s(6540),a=s(4164),r=s(4245),o=s(6347),l=s(6494),i=s(2814),c=s(5167),u=s(9900);function d(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:a}}=e;return{value:t,label:s,attributes:n,default:a}}))}(s);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function p(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:s}=e;const a=(0,o.W6)(),r=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,i.aZ)(r),(0,n.useCallback)((e=>{if(!r)return;const t=new URLSearchParams(a.location.search);t.set(r,e),a.replace({...a.location,search:t.toString()})}),[r,a])]}function f(e){const{defaultValue:t,queryString:s=!1,groupId:a}=e,r=h(e),[o,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:r}))),[c,d]=m({queryString:s,groupId:a}),[f,j]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,r]=(0,u.Dv)(s);return[a,(0,n.useCallback)((e=>{s&&r.set(e)}),[s,r])]}({groupId:a}),g=(()=>{const e=c??f;return p({value:e,tabValues:r})?e:null})();(0,l.A)((()=>{g&&i(g)}),[g]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!p({value:e,tabValues:r}))throw new Error(`Can't select invalid tab value=${e}`);i(e),d(e),j(e)}),[d,j,r]),tabValues:r}}var j=s(1062);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=s(4848);function x(e){let{className:t,block:s,selectedValue:n,selectValue:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),u=e=>{const t=e.currentTarget,s=i.indexOf(t),a=l[s].value;a!==n&&(c(t),o(a))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const s=i.indexOf(e.currentTarget)+1;t=i[s]??i[0];break}case"ArrowLeft":{const s=i.indexOf(e.currentTarget)-1;t=i[s]??i[i.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.A)("tabs",{"tabs--block":s},t),children:l.map((e=>{let{value:t,label:s,attributes:r}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:d,onClick:u,...r,className:(0,a.A)("tabs__item",g.tabItem,r?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:r}=e;const o=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===r));return e?(0,n.cloneElement)(e,{className:(0,a.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==r})))})}function y(e){const t=f(e);return(0,b.jsxs)("div",{className:(0,a.A)("tabs-container",g.tabList),children:[(0,b.jsx)(x,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function w(e){const t=(0,j.A)();return(0,b.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>o,x:()=>l});var n=s(6540);const a={},r=n.createContext(a);function o(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/6f4d8994.117a0347.js b/assets/js/6f4d8994.59d7b33c.js similarity index 97% rename from assets/js/6f4d8994.117a0347.js rename to assets/js/6f4d8994.59d7b33c.js index e3860774e7..3b1519e057 100644 --- a/assets/js/6f4d8994.117a0347.js +++ b/assets/js/6f4d8994.59d7b33c.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3021],{6973:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/version-checking","title":"Version checking","description":"By default, ts-jest supports a range of versions for jest/typescript. One uses incompatible versions will receive a warning","source":"@site/versioned_docs/version-27.1/getting-started/version-checking.md","sourceDirName":"getting-started","slug":"/getting-started/version-checking","permalink":"/ts-jest/docs/27.1/getting-started/version-checking","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/version-checking.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"version-checking","title":"Version checking"},"sidebar":"version-27.1-docs","previous":{"title":"Paths mapping","permalink":"/ts-jest/docs/27.1/getting-started/paths-mapping"},"next":{"title":"ESM Support","permalink":"/ts-jest/docs/27.1/guides/esm-support"}}');var i=n(4848),r=n(8453);const o={id:"version-checking",title:"Version checking"},c=void 0,a={},d=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["By default, ",(0,i.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,i.jsx)(t.code,{children:"jest"}),"/",(0,i.jsx)(t.code,{children:"typescript"}),". One uses incompatible versions will receive a warning\nmessage while running tests. This warning message can be opt-out by setting environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"export TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Windows"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,i.jsxs)(t.p,{children:["As long as the environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"})," stays, the warning message will no longer show.\nThis can lead to unexpected errors due to the usage of incompatible versions' dependencies. Use this environment variable with precautions."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>c});var s=n(6540);const i={},r=s.createContext(i);function o(e){const t=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3021],{6973:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/version-checking","title":"Version checking","description":"By default, ts-jest supports a range of versions for jest/typescript. One uses incompatible versions will receive a warning","source":"@site/versioned_docs/version-27.1/getting-started/version-checking.md","sourceDirName":"getting-started","slug":"/getting-started/version-checking","permalink":"/ts-jest/docs/27.1/getting-started/version-checking","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/version-checking.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"version-checking","title":"Version checking"},"sidebar":"version-27.1-docs","previous":{"title":"Paths mapping","permalink":"/ts-jest/docs/27.1/getting-started/paths-mapping"},"next":{"title":"ESM Support","permalink":"/ts-jest/docs/27.1/guides/esm-support"}}');var i=n(4848),r=n(8453);const o={id:"version-checking",title:"Version checking"},c=void 0,a={},d=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["By default, ",(0,i.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,i.jsx)(t.code,{children:"jest"}),"/",(0,i.jsx)(t.code,{children:"typescript"}),". One uses incompatible versions will receive a warning\nmessage while running tests. This warning message can be opt-out by setting environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"export TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Windows"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,i.jsxs)(t.p,{children:["As long as the environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"})," stays, the warning message will no longer show.\nThis can lead to unexpected errors due to the usage of incompatible versions' dependencies. Use this environment variable with precautions."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>c});var s=n(6540);const i={},r=s.createContext(i);function o(e){const t=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/6f82a5f4.4fafb087.js b/assets/js/6f82a5f4.1082f97a.js similarity index 98% rename from assets/js/6f82a5f4.4fafb087.js rename to assets/js/6f82a5f4.1082f97a.js index d4817cc3ff..da26ccb7de 100644 --- a/assets/js/6f82a5f4.4fafb087.js +++ b/assets/js/6f82a5f4.1082f97a.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3429],{6164:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>d,default:()=>p,frontMatter:()=>r,metadata:()=>o,toc:()=>l});const o=JSON.parse('{"id":"guides/test-helpers","title":"Test helpers","description":"ts-jest provides some test utilities to be used in your test, related to TypeScript.","source":"@site/versioned_docs/version-26.5/guides/test-helpers.md","sourceDirName":"guides","slug":"/guides/test-helpers","permalink":"/ts-jest/docs/26.5/guides/test-helpers","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/guides/test-helpers.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"test-helpers","title":"Test helpers"},"sidebar":"version-26.5-docs","previous":{"title":"Using with React Native","permalink":"/ts-jest/docs/26.5/guides/react-native"},"next":{"title":"Troubleshooting","permalink":"/ts-jest/docs/26.5/guides/troubleshooting"}}');var n=s(4848),i=s(8453);const r={id:"test-helpers",title:"Test helpers"},d=void 0,c={},l=[{value:"mocked<T>(item: T, deep = false)",id:"mockedtitem-t-deep--false",level:2},{value:"Example",id:"example",level:3}];function a(e){const t={code:"code",h2:"h2",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:[(0,n.jsx)(t.code,{children:"ts-jest"})," provides some test utilities to be used in your test, related to TypeScript."]}),"\n",(0,n.jsx)(t.h2,{id:"mockedtitem-t-deep--false",children:(0,n.jsx)(t.code,{children:"mocked(item: T, deep = false)"})}),"\n",(0,n.jsxs)(t.p,{children:["The ",(0,n.jsx)(t.code,{children:"mocked"})," test helper provides typings on your mocked modules and even their deep methods, based on the typing of its source. It makes use of the latest TypeScript feature, so you even have argument types completion in the IDE (as opposed to ",(0,n.jsx)(t.code,{children:"jest.MockInstance"}),")."]}),"\n",(0,n.jsxs)(t.p,{children:[(0,n.jsx)(t.strong,{children:"Note:"})," while it needs to be a function so that input type is changed, the helper itself does nothing else than returning the given input value."]}),"\n",(0,n.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-ts",children:"// foo.ts\nexport const foo = {\n a: {\n b: {\n c: {\n hello: (name: string) => `Hello, ${name}`,\n },\n },\n },\n name: () => 'foo',\n}\n"})}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-ts",children:"// foo.spec.ts\nimport { mocked } from 'ts-jest/utils'\nimport { foo } from './foo'\njest.mock('./foo')\n\n// here the whole foo var is mocked deeply\nconst mockedFoo = mocked(foo, true)\n\ntest('deep', () => {\n // there will be no TS error here, and you'll have completion in modern IDEs\n mockedFoo.a.b.c.hello('me')\n // same here\n expect(mockedFoo.a.b.c.hello.mock.calls).toHaveLength(1)\n})\n\ntest('direct', () => {\n foo.name()\n // here only foo.name is mocked (or its methods if it's an object)\n expect(mocked(foo.name).mock.calls).toHaveLength(1)\n})\n"})})]})}function p(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(a,{...e})}):a(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>r,x:()=>d});var o=s(6540);const n={},i=o.createContext(n);function r(e){const t=o.useContext(i);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function d(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:r(e.components),o.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3429],{6164:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>d,default:()=>p,frontMatter:()=>r,metadata:()=>o,toc:()=>l});const o=JSON.parse('{"id":"guides/test-helpers","title":"Test helpers","description":"ts-jest provides some test utilities to be used in your test, related to TypeScript.","source":"@site/versioned_docs/version-26.5/guides/test-helpers.md","sourceDirName":"guides","slug":"/guides/test-helpers","permalink":"/ts-jest/docs/26.5/guides/test-helpers","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/guides/test-helpers.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"test-helpers","title":"Test helpers"},"sidebar":"version-26.5-docs","previous":{"title":"Using with React Native","permalink":"/ts-jest/docs/26.5/guides/react-native"},"next":{"title":"Troubleshooting","permalink":"/ts-jest/docs/26.5/guides/troubleshooting"}}');var n=s(4848),i=s(8453);const r={id:"test-helpers",title:"Test helpers"},d=void 0,c={},l=[{value:"mocked<T>(item: T, deep = false)",id:"mockedtitem-t-deep--false",level:2},{value:"Example",id:"example",level:3}];function a(e){const t={code:"code",h2:"h2",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:[(0,n.jsx)(t.code,{children:"ts-jest"})," provides some test utilities to be used in your test, related to TypeScript."]}),"\n",(0,n.jsx)(t.h2,{id:"mockedtitem-t-deep--false",children:(0,n.jsx)(t.code,{children:"mocked(item: T, deep = false)"})}),"\n",(0,n.jsxs)(t.p,{children:["The ",(0,n.jsx)(t.code,{children:"mocked"})," test helper provides typings on your mocked modules and even their deep methods, based on the typing of its source. It makes use of the latest TypeScript feature, so you even have argument types completion in the IDE (as opposed to ",(0,n.jsx)(t.code,{children:"jest.MockInstance"}),")."]}),"\n",(0,n.jsxs)(t.p,{children:[(0,n.jsx)(t.strong,{children:"Note:"})," while it needs to be a function so that input type is changed, the helper itself does nothing else than returning the given input value."]}),"\n",(0,n.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-ts",children:"// foo.ts\nexport const foo = {\n a: {\n b: {\n c: {\n hello: (name: string) => `Hello, ${name}`,\n },\n },\n },\n name: () => 'foo',\n}\n"})}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-ts",children:"// foo.spec.ts\nimport { mocked } from 'ts-jest/utils'\nimport { foo } from './foo'\njest.mock('./foo')\n\n// here the whole foo var is mocked deeply\nconst mockedFoo = mocked(foo, true)\n\ntest('deep', () => {\n // there will be no TS error here, and you'll have completion in modern IDEs\n mockedFoo.a.b.c.hello('me')\n // same here\n expect(mockedFoo.a.b.c.hello.mock.calls).toHaveLength(1)\n})\n\ntest('direct', () => {\n foo.name()\n // here only foo.name is mocked (or its methods if it's an object)\n expect(mocked(foo.name).mock.calls).toHaveLength(1)\n})\n"})})]})}function p(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(a,{...e})}):a(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>r,x:()=>d});var o=s(6540);const n={},i=o.createContext(n);function r(e){const t=o.useContext(i);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function d(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:r(e.components),o.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/7335c74d.c31a2be6.js b/assets/js/7335c74d.d595bd82.js similarity index 99% rename from assets/js/7335c74d.c31a2be6.js rename to assets/js/7335c74d.d595bd82.js index 44d310f087..6e06be8ac9 100644 --- a/assets/js/7335c74d.c31a2be6.js +++ b/assets/js/7335c74d.d595bd82.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7983],{5379:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>h,frontMatter:()=>i,metadata:()=>r,toc:()=>d});const r=JSON.parse('{"id":"debugging","title":"Debugging ts-jest","description":"You can activate the debug logger by setting the environment variable TSJESTLOG before running tests.","source":"@site/versioned_docs/version-29.0/debugging.md","sourceDirName":".","slug":"/debugging","permalink":"/ts-jest/docs/29.0/debugging","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/debugging.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"debugging","title":"Debugging ts-jest"},"sidebar":"version-29.0-docs","previous":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/29.0/migration"}}');var s=n(4848),a=n(8453),o=n(9489),l=n(7227);const i={id:"debugging",title:"Debugging ts-jest"},u=void 0,c={},d=[];function g(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,a.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["You can activate the debug logger by setting the environment variable ",(0,s.jsx)(t.code,{children:"TS_JEST_LOG"})," before running tests.\nThe output of the logger will be in ",(0,s.jsx)(t.strong,{children:"ts-jest.log"})," in current working directory."]}),"\n",(0,s.jsxs)(t.p,{children:["The debug logger contains some useful information about how internal ",(0,s.jsx)(t.code,{children:"ts-jest"})," works, including which files are processed,\nwhich Jest config or TypeScript config is used etc."]}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"export TS_JEST_LOG=ts-jest.log\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Windows"})}),"\n",(0,s.jsxs)(o.A,{groupId:"code-examples",children:[(0,s.jsx)(l.A,{value:"Command",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-Command",metastring:"Prompt tab",children:"set TS_JEST_LOG=ts-jest.log\n"})})}),(0,s.jsx)(l.A,{value:"PowerShell",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-PowerShell",metastring:"tab",children:"$env:TS_JEST_LOG = 'ts-jest.log'\n"})})})]})]})}function h(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(g,{...e})}):g(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var r=n(4164);const s={tabItem:"tabItem_Ymn6"};var a=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,r.A)(s.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>y});var r=n(6540),s=n(4164),a=n(4245),o=n(6347),l=n(6494),i=n(2814),u=n(5167),c=n(9900);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function g(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:s}}=e;return{value:t,label:n,attributes:r,default:s}}))}(n);return function(e){const t=(0,u.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function b(e){let{queryString:t=!1,groupId:n}=e;const s=(0,o.W6)(),a=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,i.aZ)(a),(0,r.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(s.location.search);t.set(a,e),s.replace({...s.location,search:t.toString()})}),[a,s])]}function p(e){const{defaultValue:t,queryString:n=!1,groupId:s}=e,a=g(e),[o,i]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!h({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:a}))),[u,d]=b({queryString:n,groupId:s}),[p,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[s,a]=(0,c.Dv)(n);return[s,(0,r.useCallback)((e=>{n&&a.set(e)}),[n,a])]}({groupId:s}),m=(()=>{const e=u??p;return h({value:e,tabValues:a})?e:null})();(0,l.A)((()=>{m&&i(m)}),[m]);return{selectedValue:o,selectValue:(0,r.useCallback)((e=>{if(!h({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);i(e),d(e),f(e)}),[d,f,a]),tabValues:a}}var f=n(1062);const m={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=n(4848);function j(e){let{className:t,block:n,selectedValue:r,selectValue:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:u}=(0,a.a_)(),c=e=>{const t=e.currentTarget,n=i.indexOf(t),s=l[n].value;s!==r&&(u(t),o(s))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=i.indexOf(e.currentTarget)+1;t=i[n]??i[0];break}case"ArrowLeft":{const n=i.indexOf(e.currentTarget)-1;t=i[n]??i[i.length-1];break}}t?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.A)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:a}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>i.push(e),onKeyDown:d,onClick:c,...a,className:(0,s.A)("tabs__item",m.tabItem,a?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:a}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:(0,s.A)("margin-top--md",e.props.className)}):null}return(0,v.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function w(e){const t=p(e);return(0,v.jsxs)("div",{className:(0,s.A)("tabs-container",m.tabList),children:[(0,v.jsx)(j,{...t,...e}),(0,v.jsx)(x,{...t,...e})]})}function y(e){const t=(0,f.A)();return(0,v.jsx)(w,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>l});var r=n(6540);const s={},a=r.createContext(s);function o(e){const t=r.useContext(a);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:o(e.components),r.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7983],{5379:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>h,frontMatter:()=>i,metadata:()=>r,toc:()=>d});const r=JSON.parse('{"id":"debugging","title":"Debugging ts-jest","description":"You can activate the debug logger by setting the environment variable TSJESTLOG before running tests.","source":"@site/versioned_docs/version-29.0/debugging.md","sourceDirName":".","slug":"/debugging","permalink":"/ts-jest/docs/29.0/debugging","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/debugging.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"debugging","title":"Debugging ts-jest"},"sidebar":"version-29.0-docs","previous":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/29.0/migration"}}');var s=n(4848),a=n(8453),o=n(9489),l=n(7227);const i={id:"debugging",title:"Debugging ts-jest"},u=void 0,c={},d=[];function g(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,a.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["You can activate the debug logger by setting the environment variable ",(0,s.jsx)(t.code,{children:"TS_JEST_LOG"})," before running tests.\nThe output of the logger will be in ",(0,s.jsx)(t.strong,{children:"ts-jest.log"})," in current working directory."]}),"\n",(0,s.jsxs)(t.p,{children:["The debug logger contains some useful information about how internal ",(0,s.jsx)(t.code,{children:"ts-jest"})," works, including which files are processed,\nwhich Jest config or TypeScript config is used etc."]}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"export TS_JEST_LOG=ts-jest.log\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Windows"})}),"\n",(0,s.jsxs)(o.A,{groupId:"code-examples",children:[(0,s.jsx)(l.A,{value:"Command",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-Command",metastring:"Prompt tab",children:"set TS_JEST_LOG=ts-jest.log\n"})})}),(0,s.jsx)(l.A,{value:"PowerShell",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-PowerShell",metastring:"tab",children:"$env:TS_JEST_LOG = 'ts-jest.log'\n"})})})]})]})}function h(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(g,{...e})}):g(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var r=n(4164);const s={tabItem:"tabItem_Ymn6"};var a=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,r.A)(s.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>y});var r=n(6540),s=n(4164),a=n(4245),o=n(6347),l=n(6494),i=n(2814),u=n(5167),c=n(9900);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function g(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:s}}=e;return{value:t,label:n,attributes:r,default:s}}))}(n);return function(e){const t=(0,u.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function b(e){let{queryString:t=!1,groupId:n}=e;const s=(0,o.W6)(),a=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,i.aZ)(a),(0,r.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(s.location.search);t.set(a,e),s.replace({...s.location,search:t.toString()})}),[a,s])]}function p(e){const{defaultValue:t,queryString:n=!1,groupId:s}=e,a=g(e),[o,i]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!h({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:a}))),[u,d]=b({queryString:n,groupId:s}),[p,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[s,a]=(0,c.Dv)(n);return[s,(0,r.useCallback)((e=>{n&&a.set(e)}),[n,a])]}({groupId:s}),m=(()=>{const e=u??p;return h({value:e,tabValues:a})?e:null})();(0,l.A)((()=>{m&&i(m)}),[m]);return{selectedValue:o,selectValue:(0,r.useCallback)((e=>{if(!h({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);i(e),d(e),f(e)}),[d,f,a]),tabValues:a}}var f=n(1062);const m={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=n(4848);function j(e){let{className:t,block:n,selectedValue:r,selectValue:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:u}=(0,a.a_)(),c=e=>{const t=e.currentTarget,n=i.indexOf(t),s=l[n].value;s!==r&&(u(t),o(s))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=i.indexOf(e.currentTarget)+1;t=i[n]??i[0];break}case"ArrowLeft":{const n=i.indexOf(e.currentTarget)-1;t=i[n]??i[i.length-1];break}}t?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.A)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:a}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>i.push(e),onKeyDown:d,onClick:c,...a,className:(0,s.A)("tabs__item",m.tabItem,a?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:a}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:(0,s.A)("margin-top--md",e.props.className)}):null}return(0,v.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function w(e){const t=p(e);return(0,v.jsxs)("div",{className:(0,s.A)("tabs-container",m.tabList),children:[(0,v.jsx)(j,{...t,...e}),(0,v.jsx)(x,{...t,...e})]})}function y(e){const t=(0,f.A)();return(0,v.jsx)(w,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>l});var r=n(6540);const s={},a=r.createContext(s);function o(e){const t=r.useContext(a);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:o(e.components),r.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/73f5a02c.77733def.js b/assets/js/73f5a02c.33e8cb11.js similarity index 99% rename from assets/js/73f5a02c.77733def.js rename to assets/js/73f5a02c.33e8cb11.js index 704aaba4d4..4b15317bb0 100644 --- a/assets/js/73f5a02c.77733def.js +++ b/assets/js/73f5a02c.33e8cb11.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8080],{6248:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>p,frontMatter:()=>l,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/options/stringifyContentPathRegex","title":"Stringify content option","description":"The stringifyContentPathRegex option has been kept for backward compatibility of HTML_TRANSFORM","source":"@site/docs/getting-started/options/stringifyContentPathRegex.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/stringifyContentPathRegex","permalink":"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/stringifyContentPathRegex.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Stringify content option"}}');var r=n(4848),o=n(8453),a=n(9489),i=n(7227);const l={title:"Stringify content option"},u=void 0,c={},d=[{value:"Example",id:"example",level:3}];function h(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["The ",(0,r.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,r.jsx)(t.code,{children:"__HTML_TRANSFORM__"}),"\nIt's a regular expression pattern used to match the path of file to be transformed.\nIf it matches, the file will be exported as a module exporting its content."]}),"\n",(0,r.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,r.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,r.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,r.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,r.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,r.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,r.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,r.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,r.jsx)(t.code,{children:"transform"})," option pointing to ",(0,r.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,r.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,r.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,r.jsxs)(t.p,{children:["In the ",(0,r.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,r.jsx)(t.code,{children:"package.json"})," version of the config, but extending from the preset will ensure more compatibility without any changes when updating."]}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n moduleFileExtensions: [...tsjPreset.moduleFileExtensions, 'html'],\n transform: {\n ...tsjPreset.transform,\n '\\\\.html$': [\n 'ts-jest',\n {\n stringifyContentPathRegex: /\\.html$/,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\nimport tsJestPresets from 'ts-jest/presets'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n moduleFileExtensions: [...tsJestPresets.defaults.moduleFileExtensions, 'html'],\n transform: {\n ...tsJestPresets.defaults.transform,\n '\\\\.html$': [\n 'ts-jest',\n {\n stringifyContentPathRegex: /\\.html$/,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleFileExtensions": ["js", "ts", "html"],\n "transform": {\n "\\\\.(html|ts|js)$": [\n "ts-jest",\n {\n "stringifyContentPathRegex": "\\\\.html$"\n }\n ]\n }\n }\n}\n'})})})]})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>a});n(6540);var s=n(4164);const r={tabItem:"tabItem_Ymn6"};var o=n(4848);function a(e){let{children:t,hidden:n,className:a}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,s.A)(r.tabItem,a),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),r=n(4164),o=n(4245),a=n(6347),i=n(6494),l=n(2814),u=n(5167),c=n(9900);function d(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:r}}=e;return{value:t,label:n,attributes:s,default:r}}))}(n);return function(e){const t=(0,u.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const r=(0,a.W6)(),o=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(o),(0,s.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(r.location.search);t.set(o,e),r.replace({...r.location,search:t.toString()})}),[o,r])]}function m(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,o=h(e),[a,l]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:o}))),[u,d]=f({queryString:n,groupId:r}),[m,g]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,o]=(0,c.Dv)(n);return[r,(0,s.useCallback)((e=>{n&&o.set(e)}),[n,o])]}({groupId:r}),b=(()=>{const e=u??m;return p({value:e,tabValues:o})?e:null})();(0,i.A)((()=>{b&&l(b)}),[b]);return{selectedValue:a,selectValue:(0,s.useCallback)((e=>{if(!p({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),g(e)}),[d,g,o]),tabValues:o}}var g=n(1062);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=n(4848);function j(e){let{className:t,block:n,selectedValue:s,selectValue:a,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:u}=(0,o.a_)(),c=e=>{const t=e.currentTarget,n=l.indexOf(t),r=i[n].value;r!==s&&(u(t),a(r))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:o}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>l.push(e),onKeyDown:d,onClick:c,...o,className:(0,r.A)("tabs__item",b.tabItem,o?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:o}=e;const a=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=a.find((e=>e.props.value===o));return e?(0,s.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:a.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==o})))})}function y(e){const t=m(e);return(0,x.jsxs)("div",{className:(0,r.A)("tabs-container",b.tabList),children:[(0,x.jsx)(j,{...t,...e}),(0,x.jsx)(v,{...t,...e})]})}function w(e){const t=(0,g.A)();return(0,x.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>a,x:()=>i});var s=n(6540);const r={},o=s.createContext(r);function a(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8080],{6248:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>p,frontMatter:()=>l,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/options/stringifyContentPathRegex","title":"Stringify content option","description":"The stringifyContentPathRegex option has been kept for backward compatibility of HTML_TRANSFORM","source":"@site/docs/getting-started/options/stringifyContentPathRegex.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/stringifyContentPathRegex","permalink":"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/stringifyContentPathRegex.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Stringify content option"}}');var r=n(4848),o=n(8453),a=n(9489),i=n(7227);const l={title:"Stringify content option"},u=void 0,c={},d=[{value:"Example",id:"example",level:3}];function h(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["The ",(0,r.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,r.jsx)(t.code,{children:"__HTML_TRANSFORM__"}),"\nIt's a regular expression pattern used to match the path of file to be transformed.\nIf it matches, the file will be exported as a module exporting its content."]}),"\n",(0,r.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,r.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,r.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,r.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,r.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,r.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,r.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,r.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,r.jsx)(t.code,{children:"transform"})," option pointing to ",(0,r.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,r.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,r.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,r.jsxs)(t.p,{children:["In the ",(0,r.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,r.jsx)(t.code,{children:"package.json"})," version of the config, but extending from the preset will ensure more compatibility without any changes when updating."]}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n moduleFileExtensions: [...tsjPreset.moduleFileExtensions, 'html'],\n transform: {\n ...tsjPreset.transform,\n '\\\\.html$': [\n 'ts-jest',\n {\n stringifyContentPathRegex: /\\.html$/,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\nimport tsJestPresets from 'ts-jest/presets'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n moduleFileExtensions: [...tsJestPresets.defaults.moduleFileExtensions, 'html'],\n transform: {\n ...tsJestPresets.defaults.transform,\n '\\\\.html$': [\n 'ts-jest',\n {\n stringifyContentPathRegex: /\\.html$/,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleFileExtensions": ["js", "ts", "html"],\n "transform": {\n "\\\\.(html|ts|js)$": [\n "ts-jest",\n {\n "stringifyContentPathRegex": "\\\\.html$"\n }\n ]\n }\n }\n}\n'})})})]})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>a});n(6540);var s=n(4164);const r={tabItem:"tabItem_Ymn6"};var o=n(4848);function a(e){let{children:t,hidden:n,className:a}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,s.A)(r.tabItem,a),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),r=n(4164),o=n(4245),a=n(6347),i=n(6494),l=n(2814),u=n(5167),c=n(9900);function d(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:r}}=e;return{value:t,label:n,attributes:s,default:r}}))}(n);return function(e){const t=(0,u.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const r=(0,a.W6)(),o=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(o),(0,s.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(r.location.search);t.set(o,e),r.replace({...r.location,search:t.toString()})}),[o,r])]}function m(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,o=h(e),[a,l]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:o}))),[u,d]=f({queryString:n,groupId:r}),[m,g]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,o]=(0,c.Dv)(n);return[r,(0,s.useCallback)((e=>{n&&o.set(e)}),[n,o])]}({groupId:r}),b=(()=>{const e=u??m;return p({value:e,tabValues:o})?e:null})();(0,i.A)((()=>{b&&l(b)}),[b]);return{selectedValue:a,selectValue:(0,s.useCallback)((e=>{if(!p({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),g(e)}),[d,g,o]),tabValues:o}}var g=n(1062);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=n(4848);function j(e){let{className:t,block:n,selectedValue:s,selectValue:a,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:u}=(0,o.a_)(),c=e=>{const t=e.currentTarget,n=l.indexOf(t),r=i[n].value;r!==s&&(u(t),a(r))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:o}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>l.push(e),onKeyDown:d,onClick:c,...o,className:(0,r.A)("tabs__item",b.tabItem,o?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:o}=e;const a=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=a.find((e=>e.props.value===o));return e?(0,s.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:a.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==o})))})}function y(e){const t=m(e);return(0,x.jsxs)("div",{className:(0,r.A)("tabs-container",b.tabList),children:[(0,x.jsx)(j,{...t,...e}),(0,x.jsx)(v,{...t,...e})]})}function w(e){const t=(0,g.A)();return(0,x.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>a,x:()=>i});var s=n(6540);const r={},o=s.createContext(r);function a(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/75ab14ad.eedd6538.js b/assets/js/75ab14ad.c68fd977.js similarity index 98% rename from assets/js/75ab14ad.eedd6538.js rename to assets/js/75ab14ad.c68fd977.js index 5a68f6c24f..a4151e43e4 100644 --- a/assets/js/75ab14ad.eedd6538.js +++ b/assets/js/75ab14ad.c68fd977.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6506],{59:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>h,frontMatter:()=>r,metadata:()=>s,toc:()=>l});const s=JSON.parse('{"id":"getting-started/options/stringifyContentPathRegex","title":"Stringify content option","description":"The stringifyContentPathRegex option has been kept for backward compatibility of HTML_TRANSFORM","source":"@site/versioned_docs/version-26.5/getting-started/options/stringifyContentPathRegex.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/stringifyContentPathRegex","permalink":"/ts-jest/docs/26.5/getting-started/options/stringifyContentPathRegex","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/getting-started/options/stringifyContentPathRegex.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Stringify content option"}}');var o=n(4848),i=n(8453);const r={title:"Stringify content option"},a=void 0,c={},l=[{value:"Example",id:"example",level:3}];function d(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["The ",(0,o.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,o.jsx)(t.code,{children:"__HTML_TRANSFORM__"}),"\nIt's a regular expression pattern used to match the path of file to be transformed.\nIf it matches, the file will be exported as a module exporting its content."]}),"\n",(0,o.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,o.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,o.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,o.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,o.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,o.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,o.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,o.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,o.jsx)(t.code,{children:"transform"})," option pointing to ",(0,o.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,o.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsxs)(t.p,{children:["In the ",(0,o.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,o.jsx)(t.code,{children:"package.json"})," version of the config, but extending from the preset will ensure more compatibility without any changes when updating."]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\n// Here `defaults` can be replaced with any other preset\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n\nmodule.exports = {\n // [...]\n moduleFileExtensions: [...tsjPreset.moduleFileExtensions, 'html'],\n transform: {\n ...tsjPreset.transform,\n '\\\\.html$': 'ts-jest',\n },\n globals: {\n 'ts-jest': {\n stringifyContentPathRegex: /\\.html$/,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleFileExtensions": ["js", "ts", "html"],\n "transform": {\n "\\\\.(html|ts|js)$": "ts-jest"\n },\n "globals": {\n "ts-jest": {\n "stringifyContentPathRegex": "\\\\.html$"\n }\n }\n }\n}\n'})})]})}function h(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>a});var s=n(6540);const o={},i=s.createContext(o);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6506],{59:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>h,frontMatter:()=>r,metadata:()=>s,toc:()=>l});const s=JSON.parse('{"id":"getting-started/options/stringifyContentPathRegex","title":"Stringify content option","description":"The stringifyContentPathRegex option has been kept for backward compatibility of HTML_TRANSFORM","source":"@site/versioned_docs/version-26.5/getting-started/options/stringifyContentPathRegex.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/stringifyContentPathRegex","permalink":"/ts-jest/docs/26.5/getting-started/options/stringifyContentPathRegex","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/getting-started/options/stringifyContentPathRegex.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Stringify content option"}}');var o=n(4848),i=n(8453);const r={title:"Stringify content option"},a=void 0,c={},l=[{value:"Example",id:"example",level:3}];function d(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["The ",(0,o.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,o.jsx)(t.code,{children:"__HTML_TRANSFORM__"}),"\nIt's a regular expression pattern used to match the path of file to be transformed.\nIf it matches, the file will be exported as a module exporting its content."]}),"\n",(0,o.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,o.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,o.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,o.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,o.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,o.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,o.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,o.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,o.jsx)(t.code,{children:"transform"})," option pointing to ",(0,o.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,o.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsxs)(t.p,{children:["In the ",(0,o.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,o.jsx)(t.code,{children:"package.json"})," version of the config, but extending from the preset will ensure more compatibility without any changes when updating."]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\n// Here `defaults` can be replaced with any other preset\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n\nmodule.exports = {\n // [...]\n moduleFileExtensions: [...tsjPreset.moduleFileExtensions, 'html'],\n transform: {\n ...tsjPreset.transform,\n '\\\\.html$': 'ts-jest',\n },\n globals: {\n 'ts-jest': {\n stringifyContentPathRegex: /\\.html$/,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleFileExtensions": ["js", "ts", "html"],\n "transform": {\n "\\\\.(html|ts|js)$": "ts-jest"\n },\n "globals": {\n "ts-jest": {\n "stringifyContentPathRegex": "\\\\.html$"\n }\n }\n }\n}\n'})})]})}function h(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>a});var s=n(6540);const o={},i=s.createContext(o);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/78f0a226.fcab7721.js b/assets/js/78f0a226.3bd0ffa6.js similarity index 99% rename from assets/js/78f0a226.fcab7721.js rename to assets/js/78f0a226.3bd0ffa6.js index c6967452a9..3bd0b4269a 100644 --- a/assets/js/78f0a226.fcab7721.js +++ b/assets/js/78f0a226.3bd0ffa6.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8313],{7329:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>r,contentTitle:()=>i,default:()=>b,frontMatter:()=>a,metadata:()=>t,toc:()=>c});const t=JSON.parse('{"id":"getting-started/options/babelConfig","title":"Babel Config option","description":"ts-jest by default does NOT use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ts-jest can call the BabelJest processor once TypeScript has transformed the source into JavaScript.","source":"@site/versioned_docs/version-27.1/getting-started/options/babelConfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/babelConfig","permalink":"/ts-jest/docs/27.1/getting-started/options/babelConfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/options/babelConfig.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Babel Config option"}}');var o=s(4848),l=s(8453);const a={title:"Babel Config option"},i=void 0,r={},c=[{value:"Examples",id:"examples",level:3},{value:"Use default babelrc file",id:"use-default-babelrc-file",level:4},{value:"Path to a babelrc file",id:"path-to-a-babelrc-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4}];function d(e){const n={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,l.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:[(0,o.jsx)(n.code,{children:"ts-jest"})," by default does ",(0,o.jsx)(n.strong,{children:"NOT"})," use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ",(0,o.jsx)(n.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,o.jsxs)(n.p,{children:["The option is ",(0,o.jsx)(n.code,{children:"babelConfig"})," and it works pretty much as the ",(0,o.jsx)(n.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"true"}),": enables Babel processing. ",(0,o.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(n.code,{children:".babelrc"}),", ",(0,o.jsx)(n.code,{children:".babelrc.js"}),", ",(0,o.jsx)(n.code,{children:"babel.config.js"})," file or a ",(0,o.jsx)(n.code,{children:"babel"})," section in the ",(0,o.jsx)(n.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,o.jsx)(n.code,{children:"babel-jest"})," processor."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"{ ... }"}),": inline ",(0,o.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,o.jsx)(n.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,o.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsxs)(n.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,o.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: true,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "babelConfig": true\n }\n }\n }\n}\n'})}),"\n",(0,o.jsxs)(n.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,o.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,o.jsxs)(n.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,o.jsx)(n.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: 'babelrc.test.js',\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.p,{children:"or"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: require('./babelrc.test.js'),\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "babelConfig": "babelrc.test.js"\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,o.jsxs)(n.p,{children:["Refer to the ",(0,o.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: {\n comments: false,\n plugins: ['@babel/plugin-transform-for-of'],\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "babelConfig": {\n "comments": false,\n "plugins": ["@babel/plugin-transform-for-of"]\n }\n }\n }\n }\n}\n'})})]})}function b(e={}){const{wrapper:n}={...(0,l.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,n,s)=>{s.d(n,{R:()=>a,x:()=>i});var t=s(6540);const o={},l=t.createContext(o);function a(e){const n=t.useContext(l);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),t.createElement(l.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8313],{7329:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>r,contentTitle:()=>i,default:()=>b,frontMatter:()=>a,metadata:()=>t,toc:()=>c});const t=JSON.parse('{"id":"getting-started/options/babelConfig","title":"Babel Config option","description":"ts-jest by default does NOT use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ts-jest can call the BabelJest processor once TypeScript has transformed the source into JavaScript.","source":"@site/versioned_docs/version-27.1/getting-started/options/babelConfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/babelConfig","permalink":"/ts-jest/docs/27.1/getting-started/options/babelConfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/options/babelConfig.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Babel Config option"}}');var o=s(4848),l=s(8453);const a={title:"Babel Config option"},i=void 0,r={},c=[{value:"Examples",id:"examples",level:3},{value:"Use default babelrc file",id:"use-default-babelrc-file",level:4},{value:"Path to a babelrc file",id:"path-to-a-babelrc-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4}];function d(e){const n={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,l.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:[(0,o.jsx)(n.code,{children:"ts-jest"})," by default does ",(0,o.jsx)(n.strong,{children:"NOT"})," use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ",(0,o.jsx)(n.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,o.jsxs)(n.p,{children:["The option is ",(0,o.jsx)(n.code,{children:"babelConfig"})," and it works pretty much as the ",(0,o.jsx)(n.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"true"}),": enables Babel processing. ",(0,o.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(n.code,{children:".babelrc"}),", ",(0,o.jsx)(n.code,{children:".babelrc.js"}),", ",(0,o.jsx)(n.code,{children:"babel.config.js"})," file or a ",(0,o.jsx)(n.code,{children:"babel"})," section in the ",(0,o.jsx)(n.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,o.jsx)(n.code,{children:"babel-jest"})," processor."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"{ ... }"}),": inline ",(0,o.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,o.jsx)(n.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,o.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsxs)(n.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,o.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: true,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "babelConfig": true\n }\n }\n }\n}\n'})}),"\n",(0,o.jsxs)(n.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,o.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,o.jsxs)(n.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,o.jsx)(n.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: 'babelrc.test.js',\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.p,{children:"or"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: require('./babelrc.test.js'),\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "babelConfig": "babelrc.test.js"\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,o.jsxs)(n.p,{children:["Refer to the ",(0,o.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: {\n comments: false,\n plugins: ['@babel/plugin-transform-for-of'],\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "babelConfig": {\n "comments": false,\n "plugins": ["@babel/plugin-transform-for-of"]\n }\n }\n }\n }\n}\n'})})]})}function b(e={}){const{wrapper:n}={...(0,l.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,n,s)=>{s.d(n,{R:()=>a,x:()=>i});var t=s(6540);const o={},l=t.createContext(o);function a(e){const n=t.useContext(l);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),t.createElement(l.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/7aac82f3.f98a61f2.js b/assets/js/7aac82f3.11f9b301.js similarity index 99% rename from assets/js/7aac82f3.f98a61f2.js rename to assets/js/7aac82f3.11f9b301.js index ab6da7f45a..fe195b2834 100644 --- a/assets/js/7aac82f3.f98a61f2.js +++ b/assets/js/7aac82f3.11f9b301.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6576],{9271:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>u,contentTitle:()=>c,default:()=>j,frontMatter:()=>l,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"guides/esm-support","title":"ESM Support","description":"To use ts-jest with ESM support:","source":"@site/versioned_docs/version-29.0/guides/esm-support.md","sourceDirName":"guides","slug":"/guides/esm-support","permalink":"/ts-jest/docs/29.0/guides/esm-support","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/guides/esm-support.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"esm-support","title":"ESM Support"},"sidebar":"version-29.0-docs","previous":{"title":"Version checking","permalink":"/ts-jest/docs/29.0/getting-started/version-checking"},"next":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/29.0/guides/mock-es6-class"}}');var r=t(4848),o=t(8453),a=t(9489),i=t(7227);const l={id:"esm-support",title:"ESM Support"},c=void 0,u={},d=[{value:"ESM presets",id:"esm-presets",level:3},{value:"Examples",id:"examples",level:3},{value:"Manual configuration",id:"manual-configuration",level:4},{value:"Use ESM presets",id:"use-esm-presets",level:4},{value:"Support .mts extension",id:"support-mts-extension",level:4}];function p(e){const s={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(s.p,{children:["To use ",(0,r.jsx)(s.code,{children:"ts-jest"})," with ESM support:"]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:["Check ",(0,r.jsx)(s.a,{href:"https://jestjs.io/docs/en/ecmascript-modules",children:"ESM Jest documentation"}),"."]}),"\n",(0,r.jsxs)(s.li,{children:["Enable ",(0,r.jsx)(s.a,{href:"../getting-started/options/useESM",children:"useESM"})," ",(0,r.jsx)(s.code,{children:"true"})," for ",(0,r.jsx)(s.code,{children:"ts-jest"})," config."]}),"\n",(0,r.jsxs)(s.li,{children:["Include ",(0,r.jsx)(s.code,{children:".ts"})," in ",(0,r.jsx)(s.a,{href:"https://jestjs.io/docs/en/next/configuration#extensionstotreatasesm-arraystring",children:"extensionsToTreatAsEsm"})," Jest config option."]}),"\n",(0,r.jsxs)(s.li,{children:["Ensure that ",(0,r.jsx)(s.code,{children:"tsconfig"})," has ",(0,r.jsx)(s.code,{children:"module"})," with value for ESM, e.g. ",(0,r.jsx)(s.code,{children:"ES2015"})," or ",(0,r.jsx)(s.code,{children:"ES2020"})," etc..."]}),"\n"]}),"\n",(0,r.jsx)(s.h3,{id:"esm-presets",children:"ESM presets"}),"\n",(0,r.jsxs)(s.p,{children:["There are also ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/29.0/getting-started/presets",children:"3 presets"})," to work with ESM."]}),"\n",(0,r.jsx)(s.admonition,{type:"caution",children:(0,r.jsxs)(s.p,{children:["If you are using custom ",(0,r.jsx)(s.code,{children:"transform"})," config, please remove ",(0,r.jsx)(s.code,{children:"preset"})," from your Jest config to avoid issues that Jest doesn't transform files correctly."]})}),"\n",(0,r.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,r.jsx)(s.h4,{id:"manual-configuration",children:"Manual configuration"}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n extensionsToTreatAsEsm: ['.ts'],\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n useESM: true,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n extensionsToTreatAsEsm: ['.ts'],\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n useESM: true,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(i.A,{value:"JSON",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "extensionsToTreatAsEsm": [".ts"],\n "moduleNameMapper": {\n "^(\\\\.{1,2}/.*)\\\\.js$": "$1"\n },\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "useESM": true\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsx)(s.h4,{id:"use-esm-presets",children:"Use ESM presets"}),"\n",(0,r.jsx)(s.admonition,{type:"important",children:(0,r.jsxs)(s.p,{children:["Starting from ",(0,r.jsx)(s.strong,{children:"v28.0.0"}),", ",(0,r.jsx)(s.code,{children:"ts-jest"})," will gradually switch to ",(0,r.jsx)(s.code,{children:"esbuild"}),"/",(0,r.jsx)(s.code,{children:"swc"})," to transform ",(0,r.jsx)(s.code,{children:"ts"})," to ",(0,r.jsx)(s.code,{children:"js"}),". To make the transition smoothly, we introduce ",(0,r.jsx)(s.code,{children:"legacy"})," presets as a fallback when the new codes don't work yet."]})}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n preset: 'ts-jest/presets/default-esm', // or other ESM presets\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n useESM: true,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n preset: 'ts-jest/presets/default-esm', // or other ESM presets\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n useESM: true,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(i.A,{value:"JSON",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "preset": "ts-jest/presets/default-esm", // or other ESM presets,\n "moduleNameMapper": {\n "^(\\\\.{1,2}/.*)\\\\.js$": "$1"\n },\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "useESM": true\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsxs)(s.h4,{id:"support-mts-extension",children:["Support ",(0,r.jsx)(s.code,{children:".mts"})," extension"]}),"\n",(0,r.jsxs)(s.p,{children:["To work with ",(0,r.jsx)(s.code,{children:".mts"})," extension, besides the requirement to run Jest and ",(0,r.jsx)(s.code,{children:"ts-jest"})," in ESM mode, there are a few extra requirements to be met:"]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"package.json"})," should contain ",(0,r.jsx)(s.code,{children:'"type": "module"'})]}),"\n",(0,r.jsxs)(s.li,{children:["A custom Jest resolver to resolve ",(0,r.jsx)(s.code,{children:".mjs"})," extension, see our simple one at ",(0,r.jsx)(s.a,{href:"https://github.com/kulshekhar/ts-jest/blob/main/e2e/native-esm-ts/mjs-resolver.ts",children:"https://github.com/kulshekhar/ts-jest/blob/main/e2e/native-esm-ts/mjs-resolver.ts"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig.json"})," should at least contain these following options"]}),"\n"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'// tsconfig.spec.json\n{\n "compilerOptions": {\n "module": "Node16", // or "NodeNext"\n "target": "ESNext",\n "moduleResolution": "Node16", // or "NodeNext"\n "esModuleInterop": true\n }\n}\n'})})]})}function j(e={}){const{wrapper:s}={...(0,o.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},7227:(e,s,t)=>{t.d(s,{A:()=>a});t(6540);var n=t(4164);const r={tabItem:"tabItem_Ymn6"};var o=t(4848);function a(e){let{children:s,hidden:t,className:a}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,a),hidden:t,children:s})}},9489:(e,s,t)=>{t.d(s,{A:()=>w});var n=t(6540),r=t(4164),o=t(4245),a=t(6347),i=t(6494),l=t(2814),c=t(5167),u=t(9900);function d(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:s}=e;return!!s&&"object"==typeof s&&"value"in s}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:s,children:t}=e;return(0,n.useMemo)((()=>{const e=s??function(e){return d(e).map((e=>{let{props:{value:s,label:t,attributes:n,default:r}}=e;return{value:s,label:t,attributes:n,default:r}}))}(t);return function(e){const s=(0,c.XI)(e,((e,s)=>e.value===s.value));if(s.length>0)throw new Error(`Docusaurus error: Duplicate values "${s.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[s,t])}function j(e){let{value:s,tabValues:t}=e;return t.some((e=>e.value===s))}function m(e){let{queryString:s=!1,groupId:t}=e;const r=(0,a.W6)(),o=function(e){let{queryString:s=!1,groupId:t}=e;if("string"==typeof s)return s;if(!1===s)return null;if(!0===s&&!t)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return t??null}({queryString:s,groupId:t});return[(0,l.aZ)(o),(0,n.useCallback)((e=>{if(!o)return;const s=new URLSearchParams(r.location.search);s.set(o,e),r.replace({...r.location,search:s.toString()})}),[o,r])]}function h(e){const{defaultValue:s,queryString:t=!1,groupId:r}=e,o=p(e),[a,l]=(0,n.useState)((()=>function(e){let{defaultValue:s,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(s){if(!j({value:s,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${s}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return s}const n=t.find((e=>e.default))??t[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:s,tabValues:o}))),[c,d]=m({queryString:t,groupId:r}),[h,x]=function(e){let{groupId:s}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(s),[r,o]=(0,u.Dv)(t);return[r,(0,n.useCallback)((e=>{t&&o.set(e)}),[t,o])]}({groupId:r}),f=(()=>{const e=c??h;return j({value:e,tabValues:o})?e:null})();(0,i.A)((()=>{f&&l(f)}),[f]);return{selectedValue:a,selectValue:(0,n.useCallback)((e=>{if(!j({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),x(e)}),[d,x,o]),tabValues:o}}var x=t(1062);const f={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=t(4848);function b(e){let{className:s,block:t,selectedValue:n,selectValue:a,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.a_)(),u=e=>{const s=e.currentTarget,t=l.indexOf(s),r=i[t].value;r!==n&&(c(s),a(r))},d=e=>{let s=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const t=l.indexOf(e.currentTarget)+1;s=l[t]??l[0];break}case"ArrowLeft":{const t=l.indexOf(e.currentTarget)-1;s=l[t]??l[l.length-1];break}}s?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":t},s),children:i.map((e=>{let{value:s,label:t,attributes:o}=e;return(0,g.jsx)("li",{role:"tab",tabIndex:n===s?0:-1,"aria-selected":n===s,ref:e=>l.push(e),onKeyDown:d,onClick:u,...o,className:(0,r.A)("tabs__item",f.tabItem,o?.className,{"tabs__item--active":n===s}),children:t??s},s)}))})}function v(e){let{lazy:s,children:t,selectedValue:o}=e;const a=(Array.isArray(t)?t:[t]).filter(Boolean);if(s){const e=a.find((e=>e.props.value===o));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:a.map(((e,s)=>(0,n.cloneElement)(e,{key:s,hidden:e.props.value!==o})))})}function S(e){const s=h(e);return(0,g.jsxs)("div",{className:(0,r.A)("tabs-container",f.tabList),children:[(0,g.jsx)(b,{...s,...e}),(0,g.jsx)(v,{...s,...e})]})}function w(e){const s=(0,x.A)();return(0,g.jsx)(S,{...e,children:d(e.children)},String(s))}},8453:(e,s,t)=>{t.d(s,{R:()=>a,x:()=>i});var n=t(6540);const r={},o=n.createContext(r);function a(e){const s=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function i(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),n.createElement(o.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6576],{9271:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>u,contentTitle:()=>c,default:()=>j,frontMatter:()=>l,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"guides/esm-support","title":"ESM Support","description":"To use ts-jest with ESM support:","source":"@site/versioned_docs/version-29.0/guides/esm-support.md","sourceDirName":"guides","slug":"/guides/esm-support","permalink":"/ts-jest/docs/29.0/guides/esm-support","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/guides/esm-support.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"esm-support","title":"ESM Support"},"sidebar":"version-29.0-docs","previous":{"title":"Version checking","permalink":"/ts-jest/docs/29.0/getting-started/version-checking"},"next":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/29.0/guides/mock-es6-class"}}');var r=t(4848),o=t(8453),a=t(9489),i=t(7227);const l={id:"esm-support",title:"ESM Support"},c=void 0,u={},d=[{value:"ESM presets",id:"esm-presets",level:3},{value:"Examples",id:"examples",level:3},{value:"Manual configuration",id:"manual-configuration",level:4},{value:"Use ESM presets",id:"use-esm-presets",level:4},{value:"Support .mts extension",id:"support-mts-extension",level:4}];function p(e){const s={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(s.p,{children:["To use ",(0,r.jsx)(s.code,{children:"ts-jest"})," with ESM support:"]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:["Check ",(0,r.jsx)(s.a,{href:"https://jestjs.io/docs/en/ecmascript-modules",children:"ESM Jest documentation"}),"."]}),"\n",(0,r.jsxs)(s.li,{children:["Enable ",(0,r.jsx)(s.a,{href:"../getting-started/options/useESM",children:"useESM"})," ",(0,r.jsx)(s.code,{children:"true"})," for ",(0,r.jsx)(s.code,{children:"ts-jest"})," config."]}),"\n",(0,r.jsxs)(s.li,{children:["Include ",(0,r.jsx)(s.code,{children:".ts"})," in ",(0,r.jsx)(s.a,{href:"https://jestjs.io/docs/en/next/configuration#extensionstotreatasesm-arraystring",children:"extensionsToTreatAsEsm"})," Jest config option."]}),"\n",(0,r.jsxs)(s.li,{children:["Ensure that ",(0,r.jsx)(s.code,{children:"tsconfig"})," has ",(0,r.jsx)(s.code,{children:"module"})," with value for ESM, e.g. ",(0,r.jsx)(s.code,{children:"ES2015"})," or ",(0,r.jsx)(s.code,{children:"ES2020"})," etc..."]}),"\n"]}),"\n",(0,r.jsx)(s.h3,{id:"esm-presets",children:"ESM presets"}),"\n",(0,r.jsxs)(s.p,{children:["There are also ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/29.0/getting-started/presets",children:"3 presets"})," to work with ESM."]}),"\n",(0,r.jsx)(s.admonition,{type:"caution",children:(0,r.jsxs)(s.p,{children:["If you are using custom ",(0,r.jsx)(s.code,{children:"transform"})," config, please remove ",(0,r.jsx)(s.code,{children:"preset"})," from your Jest config to avoid issues that Jest doesn't transform files correctly."]})}),"\n",(0,r.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,r.jsx)(s.h4,{id:"manual-configuration",children:"Manual configuration"}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n extensionsToTreatAsEsm: ['.ts'],\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n useESM: true,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n extensionsToTreatAsEsm: ['.ts'],\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n useESM: true,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(i.A,{value:"JSON",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "extensionsToTreatAsEsm": [".ts"],\n "moduleNameMapper": {\n "^(\\\\.{1,2}/.*)\\\\.js$": "$1"\n },\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "useESM": true\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsx)(s.h4,{id:"use-esm-presets",children:"Use ESM presets"}),"\n",(0,r.jsx)(s.admonition,{type:"important",children:(0,r.jsxs)(s.p,{children:["Starting from ",(0,r.jsx)(s.strong,{children:"v28.0.0"}),", ",(0,r.jsx)(s.code,{children:"ts-jest"})," will gradually switch to ",(0,r.jsx)(s.code,{children:"esbuild"}),"/",(0,r.jsx)(s.code,{children:"swc"})," to transform ",(0,r.jsx)(s.code,{children:"ts"})," to ",(0,r.jsx)(s.code,{children:"js"}),". To make the transition smoothly, we introduce ",(0,r.jsx)(s.code,{children:"legacy"})," presets as a fallback when the new codes don't work yet."]})}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n preset: 'ts-jest/presets/default-esm', // or other ESM presets\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n useESM: true,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n preset: 'ts-jest/presets/default-esm', // or other ESM presets\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n useESM: true,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(i.A,{value:"JSON",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "preset": "ts-jest/presets/default-esm", // or other ESM presets,\n "moduleNameMapper": {\n "^(\\\\.{1,2}/.*)\\\\.js$": "$1"\n },\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "useESM": true\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsxs)(s.h4,{id:"support-mts-extension",children:["Support ",(0,r.jsx)(s.code,{children:".mts"})," extension"]}),"\n",(0,r.jsxs)(s.p,{children:["To work with ",(0,r.jsx)(s.code,{children:".mts"})," extension, besides the requirement to run Jest and ",(0,r.jsx)(s.code,{children:"ts-jest"})," in ESM mode, there are a few extra requirements to be met:"]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"package.json"})," should contain ",(0,r.jsx)(s.code,{children:'"type": "module"'})]}),"\n",(0,r.jsxs)(s.li,{children:["A custom Jest resolver to resolve ",(0,r.jsx)(s.code,{children:".mjs"})," extension, see our simple one at ",(0,r.jsx)(s.a,{href:"https://github.com/kulshekhar/ts-jest/blob/main/e2e/native-esm-ts/mjs-resolver.ts",children:"https://github.com/kulshekhar/ts-jest/blob/main/e2e/native-esm-ts/mjs-resolver.ts"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig.json"})," should at least contain these following options"]}),"\n"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'// tsconfig.spec.json\n{\n "compilerOptions": {\n "module": "Node16", // or "NodeNext"\n "target": "ESNext",\n "moduleResolution": "Node16", // or "NodeNext"\n "esModuleInterop": true\n }\n}\n'})})]})}function j(e={}){const{wrapper:s}={...(0,o.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},7227:(e,s,t)=>{t.d(s,{A:()=>a});t(6540);var n=t(4164);const r={tabItem:"tabItem_Ymn6"};var o=t(4848);function a(e){let{children:s,hidden:t,className:a}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,a),hidden:t,children:s})}},9489:(e,s,t)=>{t.d(s,{A:()=>w});var n=t(6540),r=t(4164),o=t(4245),a=t(6347),i=t(6494),l=t(2814),c=t(5167),u=t(9900);function d(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:s}=e;return!!s&&"object"==typeof s&&"value"in s}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:s,children:t}=e;return(0,n.useMemo)((()=>{const e=s??function(e){return d(e).map((e=>{let{props:{value:s,label:t,attributes:n,default:r}}=e;return{value:s,label:t,attributes:n,default:r}}))}(t);return function(e){const s=(0,c.XI)(e,((e,s)=>e.value===s.value));if(s.length>0)throw new Error(`Docusaurus error: Duplicate values "${s.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[s,t])}function j(e){let{value:s,tabValues:t}=e;return t.some((e=>e.value===s))}function m(e){let{queryString:s=!1,groupId:t}=e;const r=(0,a.W6)(),o=function(e){let{queryString:s=!1,groupId:t}=e;if("string"==typeof s)return s;if(!1===s)return null;if(!0===s&&!t)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return t??null}({queryString:s,groupId:t});return[(0,l.aZ)(o),(0,n.useCallback)((e=>{if(!o)return;const s=new URLSearchParams(r.location.search);s.set(o,e),r.replace({...r.location,search:s.toString()})}),[o,r])]}function h(e){const{defaultValue:s,queryString:t=!1,groupId:r}=e,o=p(e),[a,l]=(0,n.useState)((()=>function(e){let{defaultValue:s,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(s){if(!j({value:s,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${s}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return s}const n=t.find((e=>e.default))??t[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:s,tabValues:o}))),[c,d]=m({queryString:t,groupId:r}),[h,x]=function(e){let{groupId:s}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(s),[r,o]=(0,u.Dv)(t);return[r,(0,n.useCallback)((e=>{t&&o.set(e)}),[t,o])]}({groupId:r}),f=(()=>{const e=c??h;return j({value:e,tabValues:o})?e:null})();(0,i.A)((()=>{f&&l(f)}),[f]);return{selectedValue:a,selectValue:(0,n.useCallback)((e=>{if(!j({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),x(e)}),[d,x,o]),tabValues:o}}var x=t(1062);const f={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=t(4848);function b(e){let{className:s,block:t,selectedValue:n,selectValue:a,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.a_)(),u=e=>{const s=e.currentTarget,t=l.indexOf(s),r=i[t].value;r!==n&&(c(s),a(r))},d=e=>{let s=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const t=l.indexOf(e.currentTarget)+1;s=l[t]??l[0];break}case"ArrowLeft":{const t=l.indexOf(e.currentTarget)-1;s=l[t]??l[l.length-1];break}}s?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":t},s),children:i.map((e=>{let{value:s,label:t,attributes:o}=e;return(0,g.jsx)("li",{role:"tab",tabIndex:n===s?0:-1,"aria-selected":n===s,ref:e=>l.push(e),onKeyDown:d,onClick:u,...o,className:(0,r.A)("tabs__item",f.tabItem,o?.className,{"tabs__item--active":n===s}),children:t??s},s)}))})}function v(e){let{lazy:s,children:t,selectedValue:o}=e;const a=(Array.isArray(t)?t:[t]).filter(Boolean);if(s){const e=a.find((e=>e.props.value===o));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:a.map(((e,s)=>(0,n.cloneElement)(e,{key:s,hidden:e.props.value!==o})))})}function S(e){const s=h(e);return(0,g.jsxs)("div",{className:(0,r.A)("tabs-container",f.tabList),children:[(0,g.jsx)(b,{...s,...e}),(0,g.jsx)(v,{...s,...e})]})}function w(e){const s=(0,x.A)();return(0,g.jsx)(S,{...e,children:d(e.children)},String(s))}},8453:(e,s,t)=>{t.d(s,{R:()=>a,x:()=>i});var n=t(6540);const r={},o=n.createContext(r);function a(e){const s=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function i(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),n.createElement(o.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/7b562fc7.d3988519.js b/assets/js/7b562fc7.b7aa5465.js similarity index 98% rename from assets/js/7b562fc7.d3988519.js rename to assets/js/7b562fc7.b7aa5465.js index beea8e1228..37399bb6c6 100644 --- a/assets/js/7b562fc7.d3988519.js +++ b/assets/js/7b562fc7.b7aa5465.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8647],{7662:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>d,frontMatter:()=>r,metadata:()=>n,toc:()=>h});const n=JSON.parse('{"id":"contributing","title":"Contributing","description":"When contributing to this repository, please first discuss the change you wish to make via ts-jest GitHub discussion or issue with the owners of this repository before making a change.","source":"@site/versioned_docs/version-29.2/contributing.md","sourceDirName":".","slug":"/contributing","permalink":"/ts-jest/docs/contributing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/contributing.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"contributing","title":"Contributing"},"sidebar":"version-29.1-docs","previous":{"title":"Processing flow","permalink":"/ts-jest/docs/processing"},"next":{"title":"Installation","permalink":"/ts-jest/docs/getting-started/installation"}}');var i=s(4848),o=s(8453);const r={id:"contributing",title:"Contributing"},c=void 0,a={},h=[{value:"Pull Request Process",id:"pull-request-process",level:2},{value:"E2E Testing",id:"e2e-testing",level:2},{value:"Preparing",id:"preparing",level:3},{value:"Running",id:"running",level:3}];function l(e){const t={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,i.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,i.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,i.jsx)(t.a,{href:"https://github.com/kulshekhar/ts-jest/issues",children:"issue"})," with the owners of this repository before making a change."]}),"\n",(0,i.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,i.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,i.jsxs)(t.ol,{children:["\n",(0,i.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,i.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,i.jsxs)(t.li,{children:["Update the ",(0,i.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,i.jsx)(t.li,{children:"If possible, squash your commits. There must be only one commit in your PR (until a review). Then after each review requesting changes, DO NOT squash your commits with the one before the review, so that we can see intermediate modifications."}),"\n",(0,i.jsx)(t.li,{children:"You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you."}),"\n"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,i.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,i.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,i.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,i.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,i.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLBBRgGm4BpxA-eMEAmYxH6EEUrNW0StG--ODh9xGkQotnxP32D6YQ8z8L5TZovtKXlLcEPq5US9cdxzfQIjaQ24oET9pShUutHbxtOO9nf390oHhBASeHDXKp0a3fbiJ5DWWjAyO0tn0iVnIRcdt_Jwh-iow3XswJPxbalNzSZV10rWDVGnqA88WhS_87dd66GcqNGmMoVsX6eC4MI7gPXwgrGV_VQV2JOIMB07U01TzzeVL7b4jMClwLw2uqY3XdYhyzw2YZuuQQfDi_AIUr3q4XnrSt1NJwdVzYQV29K4nMD-AwZDXZpcmi9omyYU4iOOPXoi7SUjZKEATWkusE5YpmGVXajXVyaLoJhCfDPPjQqn0F0ZSx89msJbJAukqq0JQGxlzErg-uWiCrYIMkzHXOY1w-_1nnsLcxdFb89Auq_eJvd-JpDJvKMVsLldHMMDh8JhugpIKqzVd-p-KYJkVd0k2DN6D2N1uxnouRVMcAHX-GG0"}),"\n",(0,i.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,i.jsxs)(t.p,{children:["When a test-case needs to be run with a given template within tests, here is what's happening (in ",(0,i.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/hLHDRzim3BthLn3OOGcsfC2E3R2TUzfFI1I9ZjN8f23IJOAX--s3PBknksAdtGoQ7-yzFahKPZNcqMMqYd3XV0OVyiuGAq8EfrRDatwE4Ou8FZGDPYI5X1aKHJVE2XfBVenqAPOsHoj1jWR9G-bZDjy1l-73x_s-3F0Xx-NMnK3d_VxXrrJrMZx7bgyxOq83gzOAM23skE_Ozn6beFkn1csHO7L3MPl7iTSYRIGGiL5ZNpXuoBZ9FL6W4r3g892eZT4qd06jQoiTABEXq9b0xUuaC0h2YdXTGg4fed6wGHCAgYPpDokQgMTZ77C2tHNo8OFDQ1odW1wKP_Ed9HYyEamAXpcnGu5d3icwiptX9h8xRv-5wN07QYvjY0YhDsfb_31z6k53NbU1Wu2GJTAork27mjuDKVMS2kekq2ddW5BOm5Y0tYm82VVP3Po5GLkhfa_UQjc5jjZ1XVleeSO6e2sQiQZXw37FoDKrZD2VKNJhc9fmsZxB0dp9MFw68D3qv3GmlNEGAqkw16qXsUflnwH8kd1HZ7mHQBZiHOi5wFGFSmm1rXPpdS3fzYzRBAKoeprWPe_sFnXZm8RagqFkPoy9NR0Ze0LCuUxTxm5NhQjhRYtvYD0odwiwW5VRfLZFo9ooFS8XPNOeibeVuEbdpIatK6WaT6hBGcI6yd4qmaYbibY2GWKBhXVb3ewzGXEkw85iDxn5BvWbC1LbvptANRYssA0IQe8RXJLt_R-ydUWCq2VbpYe_vdvObUp-lh7fADQb_weB8iNTyzr-v8AXosLsESjkOgOJktq5makyJTBFKW81CG5UWzIJAkQvX1Y1i7h77D-Cn2-O8P2o6T_Z0ao6LtXwUcUclXibe_QP8AFqiV8NvVG7"})]})}function d(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>r,x:()=>c});var n=s(6540);const i={},o=n.createContext(i);function r(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8647],{7662:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>d,frontMatter:()=>r,metadata:()=>n,toc:()=>h});const n=JSON.parse('{"id":"contributing","title":"Contributing","description":"When contributing to this repository, please first discuss the change you wish to make via ts-jest GitHub discussion or issue with the owners of this repository before making a change.","source":"@site/versioned_docs/version-29.2/contributing.md","sourceDirName":".","slug":"/contributing","permalink":"/ts-jest/docs/contributing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/contributing.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"contributing","title":"Contributing"},"sidebar":"version-29.1-docs","previous":{"title":"Processing flow","permalink":"/ts-jest/docs/processing"},"next":{"title":"Installation","permalink":"/ts-jest/docs/getting-started/installation"}}');var i=s(4848),o=s(8453);const r={id:"contributing",title:"Contributing"},c=void 0,a={},h=[{value:"Pull Request Process",id:"pull-request-process",level:2},{value:"E2E Testing",id:"e2e-testing",level:2},{value:"Preparing",id:"preparing",level:3},{value:"Running",id:"running",level:3}];function l(e){const t={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,i.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,i.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,i.jsx)(t.a,{href:"https://github.com/kulshekhar/ts-jest/issues",children:"issue"})," with the owners of this repository before making a change."]}),"\n",(0,i.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,i.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,i.jsxs)(t.ol,{children:["\n",(0,i.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,i.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,i.jsxs)(t.li,{children:["Update the ",(0,i.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,i.jsx)(t.li,{children:"If possible, squash your commits. There must be only one commit in your PR (until a review). Then after each review requesting changes, DO NOT squash your commits with the one before the review, so that we can see intermediate modifications."}),"\n",(0,i.jsx)(t.li,{children:"You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you."}),"\n"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,i.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,i.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,i.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,i.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,i.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLBBRgGm4BpxA-eMEAmYxH6EEUrNW0StG--ODh9xGkQotnxP32D6YQ8z8L5TZovtKXlLcEPq5US9cdxzfQIjaQ24oET9pShUutHbxtOO9nf390oHhBASeHDXKp0a3fbiJ5DWWjAyO0tn0iVnIRcdt_Jwh-iow3XswJPxbalNzSZV10rWDVGnqA88WhS_87dd66GcqNGmMoVsX6eC4MI7gPXwgrGV_VQV2JOIMB07U01TzzeVL7b4jMClwLw2uqY3XdYhyzw2YZuuQQfDi_AIUr3q4XnrSt1NJwdVzYQV29K4nMD-AwZDXZpcmi9omyYU4iOOPXoi7SUjZKEATWkusE5YpmGVXajXVyaLoJhCfDPPjQqn0F0ZSx89msJbJAukqq0JQGxlzErg-uWiCrYIMkzHXOY1w-_1nnsLcxdFb89Auq_eJvd-JpDJvKMVsLldHMMDh8JhugpIKqzVd-p-KYJkVd0k2DN6D2N1uxnouRVMcAHX-GG0"}),"\n",(0,i.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,i.jsxs)(t.p,{children:["When a test-case needs to be run with a given template within tests, here is what's happening (in ",(0,i.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/hLHDRzim3BthLn3OOGcsfC2E3R2TUzfFI1I9ZjN8f23IJOAX--s3PBknksAdtGoQ7-yzFahKPZNcqMMqYd3XV0OVyiuGAq8EfrRDatwE4Ou8FZGDPYI5X1aKHJVE2XfBVenqAPOsHoj1jWR9G-bZDjy1l-73x_s-3F0Xx-NMnK3d_VxXrrJrMZx7bgyxOq83gzOAM23skE_Ozn6beFkn1csHO7L3MPl7iTSYRIGGiL5ZNpXuoBZ9FL6W4r3g892eZT4qd06jQoiTABEXq9b0xUuaC0h2YdXTGg4fed6wGHCAgYPpDokQgMTZ77C2tHNo8OFDQ1odW1wKP_Ed9HYyEamAXpcnGu5d3icwiptX9h8xRv-5wN07QYvjY0YhDsfb_31z6k53NbU1Wu2GJTAork27mjuDKVMS2kekq2ddW5BOm5Y0tYm82VVP3Po5GLkhfa_UQjc5jjZ1XVleeSO6e2sQiQZXw37FoDKrZD2VKNJhc9fmsZxB0dp9MFw68D3qv3GmlNEGAqkw16qXsUflnwH8kd1HZ7mHQBZiHOi5wFGFSmm1rXPpdS3fzYzRBAKoeprWPe_sFnXZm8RagqFkPoy9NR0Ze0LCuUxTxm5NhQjhRYtvYD0odwiwW5VRfLZFo9ooFS8XPNOeibeVuEbdpIatK6WaT6hBGcI6yd4qmaYbibY2GWKBhXVb3ewzGXEkw85iDxn5BvWbC1LbvptANRYssA0IQe8RXJLt_R-ydUWCq2VbpYe_vdvObUp-lh7fADQb_weB8iNTyzr-v8AXosLsESjkOgOJktq5makyJTBFKW81CG5UWzIJAkQvX1Y1i7h77D-Cn2-O8P2o6T_Z0ao6LtXwUcUclXibe_QP8AFqiV8NvVG7"})]})}function d(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>r,x:()=>c});var n=s(6540);const i={},o=n.createContext(i);function r(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/7d1a64ae.a6037b4f.js b/assets/js/7d1a64ae.4f6fa23f.js similarity index 98% rename from assets/js/7d1a64ae.a6037b4f.js rename to assets/js/7d1a64ae.4f6fa23f.js index 68cddff264..8e1fbdfda4 100644 --- a/assets/js/7d1a64ae.a6037b4f.js +++ b/assets/js/7d1a64ae.4f6fa23f.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7352],{1946:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>d,frontMatter:()=>r,metadata:()=>n,toc:()=>h});const n=JSON.parse('{"id":"contributing","title":"Contributing","description":"When contributing to this repository, please first discuss the change you wish to make via ts-jest GitHub discussion or issue with the owners of this repository before making a change.","source":"@site/versioned_docs/version-27.1/contributing.md","sourceDirName":".","slug":"/contributing","permalink":"/ts-jest/docs/27.1/contributing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/contributing.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"contributing","title":"Contributing"},"sidebar":"version-27.1-docs","previous":{"title":"Processing flow","permalink":"/ts-jest/docs/27.1/processing"},"next":{"title":"Installation","permalink":"/ts-jest/docs/27.1/getting-started/installation"}}');var i=s(4848),o=s(8453);const r={id:"contributing",title:"Contributing"},c=void 0,a={},h=[{value:"Pull Request Process",id:"pull-request-process",level:2},{value:"E2E Testing",id:"e2e-testing",level:2},{value:"Preparing",id:"preparing",level:3},{value:"Running",id:"running",level:3}];function l(e){const t={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,i.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,i.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,i.jsx)(t.a,{href:"https://github.com/kulshekhar/ts-jest/issues",children:"issue"})," with the owners of this repository before making a change."]}),"\n",(0,i.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,i.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,i.jsxs)(t.ol,{children:["\n",(0,i.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,i.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,i.jsxs)(t.li,{children:["Update the ",(0,i.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,i.jsx)(t.li,{children:"If possible, squash your commits. There must be only one commit in your PR (until a review). Then after each review requesting changes, DO NOT squash your commits with the one before the review, so that we can see intermediate modifications."}),"\n",(0,i.jsx)(t.li,{children:"You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you."}),"\n"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,i.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,i.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,i.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,i.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,i.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLBBRgGm4BpxA-eMEAmYxH6EEUrNW0StG--ODh9xGkQotnxP32D6YQ8z8L5TZovtKXlLcEPq5US9cdxzfQIjaQ24oET9pShUutHbxtOO9nf390oHhBASeHDXKp0a3fbiJ5DWWjAyO0tn0iVnIRcdt_Jwh-iow3XswJPxbalNzSZV10rWDVGnqA88WhS_87dd66GcqNGmMoVsX6eC4MI7gPXwgrGV_VQV2JOIMB07U01TzzeVL7b4jMClwLw2uqY3XdYhyzw2YZuuQQfDi_AIUr3q4XnrSt1NJwdVzYQV29K4nMD-AwZDXZpcmi9omyYU4iOOPXoi7SUjZKEATWkusE5YpmGVXajXVyaLoJhCfDPPjQqn0F0ZSx89msJbJAukqq0JQGxlzErg-uWiCrYIMkzHXOY1w-_1nnsLcxdFb89Auq_eJvd-JpDJvKMVsLldHMMDh8JhugpIKqzVd-p-KYJkVd0k2DN6D2N1uxnouRVMcAHX-GG0"}),"\n",(0,i.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,i.jsxs)(t.p,{children:["When a test-case needs to be run with a given template within tests, here is what's happening (in ",(0,i.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/hLHDRzim3BthLn3OOGcsfC2E3R2TUzfFI1I9ZjN8f23IJOAX--s3PBknksAdtGoQ7-yzFahKPZNcqMMqYd3XV0OVyiuGAq8EfrRDatwE4Ou8FZGDPYI5X1aKHJVE2XfBVenqAPOsHoj1jWR9G-bZDjy1l-73x_s-3F0Xx-NMnK3d_VxXrrJrMZx7bgyxOq83gzOAM23skE_Ozn6beFkn1csHO7L3MPl7iTSYRIGGiL5ZNpXuoBZ9FL6W4r3g892eZT4qd06jQoiTABEXq9b0xUuaC0h2YdXTGg4fed6wGHCAgYPpDokQgMTZ77C2tHNo8OFDQ1odW1wKP_Ed9HYyEamAXpcnGu5d3icwiptX9h8xRv-5wN07QYvjY0YhDsfb_31z6k53NbU1Wu2GJTAork27mjuDKVMS2kekq2ddW5BOm5Y0tYm82VVP3Po5GLkhfa_UQjc5jjZ1XVleeSO6e2sQiQZXw37FoDKrZD2VKNJhc9fmsZxB0dp9MFw68D3qv3GmlNEGAqkw16qXsUflnwH8kd1HZ7mHQBZiHOi5wFGFSmm1rXPpdS3fzYzRBAKoeprWPe_sFnXZm8RagqFkPoy9NR0Ze0LCuUxTxm5NhQjhRYtvYD0odwiwW5VRfLZFo9ooFS8XPNOeibeVuEbdpIatK6WaT6hBGcI6yd4qmaYbibY2GWKBhXVb3ewzGXEkw85iDxn5BvWbC1LbvptANRYssA0IQe8RXJLt_R-ydUWCq2VbpYe_vdvObUp-lh7fADQb_weB8iNTyzr-v8AXosLsESjkOgOJktq5makyJTBFKW81CG5UWzIJAkQvX1Y1i7h77D-Cn2-O8P2o6T_Z0ao6LtXwUcUclXibe_QP8AFqiV8NvVG7"})]})}function d(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>r,x:()=>c});var n=s(6540);const i={},o=n.createContext(i);function r(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7352],{1946:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>d,frontMatter:()=>r,metadata:()=>n,toc:()=>h});const n=JSON.parse('{"id":"contributing","title":"Contributing","description":"When contributing to this repository, please first discuss the change you wish to make via ts-jest GitHub discussion or issue with the owners of this repository before making a change.","source":"@site/versioned_docs/version-27.1/contributing.md","sourceDirName":".","slug":"/contributing","permalink":"/ts-jest/docs/27.1/contributing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/contributing.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"contributing","title":"Contributing"},"sidebar":"version-27.1-docs","previous":{"title":"Processing flow","permalink":"/ts-jest/docs/27.1/processing"},"next":{"title":"Installation","permalink":"/ts-jest/docs/27.1/getting-started/installation"}}');var i=s(4848),o=s(8453);const r={id:"contributing",title:"Contributing"},c=void 0,a={},h=[{value:"Pull Request Process",id:"pull-request-process",level:2},{value:"E2E Testing",id:"e2e-testing",level:2},{value:"Preparing",id:"preparing",level:3},{value:"Running",id:"running",level:3}];function l(e){const t={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,i.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,i.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,i.jsx)(t.a,{href:"https://github.com/kulshekhar/ts-jest/issues",children:"issue"})," with the owners of this repository before making a change."]}),"\n",(0,i.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,i.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,i.jsxs)(t.ol,{children:["\n",(0,i.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,i.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,i.jsxs)(t.li,{children:["Update the ",(0,i.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,i.jsx)(t.li,{children:"If possible, squash your commits. There must be only one commit in your PR (until a review). Then after each review requesting changes, DO NOT squash your commits with the one before the review, so that we can see intermediate modifications."}),"\n",(0,i.jsx)(t.li,{children:"You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you."}),"\n"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,i.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,i.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,i.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,i.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,i.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLBBRgGm4BpxA-eMEAmYxH6EEUrNW0StG--ODh9xGkQotnxP32D6YQ8z8L5TZovtKXlLcEPq5US9cdxzfQIjaQ24oET9pShUutHbxtOO9nf390oHhBASeHDXKp0a3fbiJ5DWWjAyO0tn0iVnIRcdt_Jwh-iow3XswJPxbalNzSZV10rWDVGnqA88WhS_87dd66GcqNGmMoVsX6eC4MI7gPXwgrGV_VQV2JOIMB07U01TzzeVL7b4jMClwLw2uqY3XdYhyzw2YZuuQQfDi_AIUr3q4XnrSt1NJwdVzYQV29K4nMD-AwZDXZpcmi9omyYU4iOOPXoi7SUjZKEATWkusE5YpmGVXajXVyaLoJhCfDPPjQqn0F0ZSx89msJbJAukqq0JQGxlzErg-uWiCrYIMkzHXOY1w-_1nnsLcxdFb89Auq_eJvd-JpDJvKMVsLldHMMDh8JhugpIKqzVd-p-KYJkVd0k2DN6D2N1uxnouRVMcAHX-GG0"}),"\n",(0,i.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,i.jsxs)(t.p,{children:["When a test-case needs to be run with a given template within tests, here is what's happening (in ",(0,i.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/hLHDRzim3BthLn3OOGcsfC2E3R2TUzfFI1I9ZjN8f23IJOAX--s3PBknksAdtGoQ7-yzFahKPZNcqMMqYd3XV0OVyiuGAq8EfrRDatwE4Ou8FZGDPYI5X1aKHJVE2XfBVenqAPOsHoj1jWR9G-bZDjy1l-73x_s-3F0Xx-NMnK3d_VxXrrJrMZx7bgyxOq83gzOAM23skE_Ozn6beFkn1csHO7L3MPl7iTSYRIGGiL5ZNpXuoBZ9FL6W4r3g892eZT4qd06jQoiTABEXq9b0xUuaC0h2YdXTGg4fed6wGHCAgYPpDokQgMTZ77C2tHNo8OFDQ1odW1wKP_Ed9HYyEamAXpcnGu5d3icwiptX9h8xRv-5wN07QYvjY0YhDsfb_31z6k53NbU1Wu2GJTAork27mjuDKVMS2kekq2ddW5BOm5Y0tYm82VVP3Po5GLkhfa_UQjc5jjZ1XVleeSO6e2sQiQZXw37FoDKrZD2VKNJhc9fmsZxB0dp9MFw68D3qv3GmlNEGAqkw16qXsUflnwH8kd1HZ7mHQBZiHOi5wFGFSmm1rXPpdS3fzYzRBAKoeprWPe_sFnXZm8RagqFkPoy9NR0Ze0LCuUxTxm5NhQjhRYtvYD0odwiwW5VRfLZFo9ooFS8XPNOeibeVuEbdpIatK6WaT6hBGcI6yd4qmaYbibY2GWKBhXVb3ewzGXEkw85iDxn5BvWbC1LbvptANRYssA0IQe8RXJLt_R-ydUWCq2VbpYe_vdvObUp-lh7fADQb_weB8iNTyzr-v8AXosLsESjkOgOJktq5makyJTBFKW81CG5UWzIJAkQvX1Y1i7h77D-Cn2-O8P2o6T_Z0ao6LtXwUcUclXibe_QP8AFqiV8NvVG7"})]})}function d(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>r,x:()=>c});var n=s(6540);const i={},o=n.createContext(i);function r(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/7dafce35.8f740fa3.js b/assets/js/7dafce35.6c17d5d2.js similarity index 99% rename from assets/js/7dafce35.8f740fa3.js rename to assets/js/7dafce35.6c17d5d2.js index cf2d26ad4c..c855666a03 100644 --- a/assets/js/7dafce35.8f740fa3.js +++ b/assets/js/7dafce35.6c17d5d2.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7083],{8366:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>l,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/astTransformers","title":"AST transformers option","description":"ts-jest by default does hoisting for a few jest methods via a TypeScript AST transformer. One can also create custom","source":"@site/versioned_docs/version-29.0/getting-started/options/astTransformers.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/astTransformers","permalink":"/ts-jest/docs/29.0/getting-started/options/astTransformers","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/options/astTransformers.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"AST transformers option"}}');var r=s(4848),a=s(8453),o=s(9489),i=s(7227);const l={title:"AST transformers option"},c=void 0,u={},d=[{value:"Examples",id:"examples",level:3},{value:"Basic Transformers",id:"basic-transformers",level:4},{value:"Configuring transformers with options",id:"configuring-transformers-with-options",level:4},{value:"Writing custom TypeScript AST transformers",id:"writing-custom-typescript-ast-transformers",level:3}];function m(e){const t={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"ts-jest"})," by default does hoisting for a few ",(0,r.jsx)(t.code,{children:"jest"})," methods via a TypeScript AST transformer. One can also create custom\nTypeScript AST transformers and provide them to ",(0,r.jsx)(t.code,{children:"ts-jest"})," to include into compilation process."]}),"\n",(0,r.jsxs)(t.p,{children:["The option is ",(0,r.jsx)(t.code,{children:"astTransformers"})," and it allows ones to specify which 3 types of TypeScript AST transformers to use with ",(0,r.jsx)(t.code,{children:"ts-jest"}),":"]}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"before"})," means your transformers get run before TS ones, which means your transformers will get raw TS syntax\ninstead of transpiled syntax (e.g ",(0,r.jsx)(t.code,{children:"import"})," instead of ",(0,r.jsx)(t.code,{children:"require"})," or ",(0,r.jsx)(t.code,{children:"define"})," )."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"after"})," means your transformers get run after TS ones, which gets transpiled syntax."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"afterDeclarations"})," means your transformers get run during ",(0,r.jsx)(t.code,{children:"d.ts"})," generation phase, allowing you to transform output type declarations."]}),"\n"]}),"\n",(0,r.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,r.jsx)(t.h4,{id:"basic-transformers",children:"Basic Transformers"}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n astTransformers: {\n before: ['my-custom-transformer'],\n },\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n astTransformers: {\n before: ['my-custom-transformer'],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(i.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "astTransformers": {\n "before": ["my-custom-transformer"]\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsx)(t.h4,{id:"configuring-transformers-with-options",children:"Configuring transformers with options"}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n astTransformers: {\n before: [\n {\n path: 'my-custom-transformer-that-needs-extra-opts',\n options: {}, // extra options to pass to transformers here\n },\n ],\n },\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n astTransformers: {\n before: [\n {\n path: 'my-custom-transformer-that-needs-extra-opts',\n options: {}, // extra options to pass to transformers here\n },\n ],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(i.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "astTransformers": {\n "before": [\n {\n "path": "my-custom-transformer-that-needs-extra-opts",\n "options": {} // extra options to pass to transformers here\n }\n ]\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsx)(t.h3,{id:"writing-custom-typescript-ast-transformers",children:"Writing custom TypeScript AST transformers"}),"\n",(0,r.jsxs)(t.p,{children:["To write a custom TypeScript AST transformers, one can take a look at ",(0,r.jsx)(t.a,{href:"https://github.com/kulshekhar/ts-jest/tree/main/src/transformers",children:"the one"})," that ",(0,r.jsx)(t.code,{children:"ts-jest"})," is using."]})]})}function p(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(m,{...e})}):m(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>o});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var a=s(4848);function o(e){let{children:t,hidden:s,className:o}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,o),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>T});var n=s(6540),r=s(4164),a=s(4245),o=s(6347),i=s(6494),l=s(2814),c=s(5167),u=s(9900);function d(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function m(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:r}}=e;return{value:t,label:s,attributes:n,default:r}}))}(s);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function p(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:s}=e;const r=(0,o.W6)(),a=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,l.aZ)(a),(0,n.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function h(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,a=m(e),[o,l]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:a}))),[c,d]=f({queryString:s,groupId:r}),[h,j]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,u.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&a.set(e)}),[s,a])]}({groupId:r}),x=(()=>{const e=c??h;return p({value:e,tabValues:a})?e:null})();(0,i.A)((()=>{x&&l(x)}),[x]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!p({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),j(e)}),[d,j,a]),tabValues:a}}var j=s(1062);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=s(4848);function b(e){let{className:t,block:s,selectedValue:n,selectValue:o,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,a.a_)(),u=e=>{const t=e.currentTarget,s=l.indexOf(t),r=i[s].value;r!==n&&(c(t),o(r))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const s=l.indexOf(e.currentTarget)+1;t=l[s]??l[0];break}case"ArrowLeft":{const s=l.indexOf(e.currentTarget)-1;t=l[s]??l[l.length-1];break}}t?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":s},t),children:i.map((e=>{let{value:t,label:s,attributes:a}=e;return(0,g.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>l.push(e),onKeyDown:d,onClick:u,...a,className:(0,r.A)("tabs__item",x.tabItem,a?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:a}=e;const o=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=h(e);return(0,g.jsxs)("div",{className:(0,r.A)("tabs-container",x.tabList),children:[(0,g.jsx)(b,{...t,...e}),(0,g.jsx)(v,{...t,...e})]})}function T(e){const t=(0,j.A)();return(0,g.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>o,x:()=>i});var n=s(6540);const r={},a=n.createContext(r);function o(e){const t=n.useContext(a);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),n.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7083],{8366:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>l,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/astTransformers","title":"AST transformers option","description":"ts-jest by default does hoisting for a few jest methods via a TypeScript AST transformer. One can also create custom","source":"@site/versioned_docs/version-29.0/getting-started/options/astTransformers.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/astTransformers","permalink":"/ts-jest/docs/29.0/getting-started/options/astTransformers","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/options/astTransformers.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"AST transformers option"}}');var r=s(4848),a=s(8453),o=s(9489),i=s(7227);const l={title:"AST transformers option"},c=void 0,u={},d=[{value:"Examples",id:"examples",level:3},{value:"Basic Transformers",id:"basic-transformers",level:4},{value:"Configuring transformers with options",id:"configuring-transformers-with-options",level:4},{value:"Writing custom TypeScript AST transformers",id:"writing-custom-typescript-ast-transformers",level:3}];function m(e){const t={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"ts-jest"})," by default does hoisting for a few ",(0,r.jsx)(t.code,{children:"jest"})," methods via a TypeScript AST transformer. One can also create custom\nTypeScript AST transformers and provide them to ",(0,r.jsx)(t.code,{children:"ts-jest"})," to include into compilation process."]}),"\n",(0,r.jsxs)(t.p,{children:["The option is ",(0,r.jsx)(t.code,{children:"astTransformers"})," and it allows ones to specify which 3 types of TypeScript AST transformers to use with ",(0,r.jsx)(t.code,{children:"ts-jest"}),":"]}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"before"})," means your transformers get run before TS ones, which means your transformers will get raw TS syntax\ninstead of transpiled syntax (e.g ",(0,r.jsx)(t.code,{children:"import"})," instead of ",(0,r.jsx)(t.code,{children:"require"})," or ",(0,r.jsx)(t.code,{children:"define"})," )."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"after"})," means your transformers get run after TS ones, which gets transpiled syntax."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"afterDeclarations"})," means your transformers get run during ",(0,r.jsx)(t.code,{children:"d.ts"})," generation phase, allowing you to transform output type declarations."]}),"\n"]}),"\n",(0,r.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,r.jsx)(t.h4,{id:"basic-transformers",children:"Basic Transformers"}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n astTransformers: {\n before: ['my-custom-transformer'],\n },\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n astTransformers: {\n before: ['my-custom-transformer'],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(i.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "astTransformers": {\n "before": ["my-custom-transformer"]\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsx)(t.h4,{id:"configuring-transformers-with-options",children:"Configuring transformers with options"}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n astTransformers: {\n before: [\n {\n path: 'my-custom-transformer-that-needs-extra-opts',\n options: {}, // extra options to pass to transformers here\n },\n ],\n },\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n astTransformers: {\n before: [\n {\n path: 'my-custom-transformer-that-needs-extra-opts',\n options: {}, // extra options to pass to transformers here\n },\n ],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(i.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "astTransformers": {\n "before": [\n {\n "path": "my-custom-transformer-that-needs-extra-opts",\n "options": {} // extra options to pass to transformers here\n }\n ]\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsx)(t.h3,{id:"writing-custom-typescript-ast-transformers",children:"Writing custom TypeScript AST transformers"}),"\n",(0,r.jsxs)(t.p,{children:["To write a custom TypeScript AST transformers, one can take a look at ",(0,r.jsx)(t.a,{href:"https://github.com/kulshekhar/ts-jest/tree/main/src/transformers",children:"the one"})," that ",(0,r.jsx)(t.code,{children:"ts-jest"})," is using."]})]})}function p(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(m,{...e})}):m(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>o});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var a=s(4848);function o(e){let{children:t,hidden:s,className:o}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,o),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>T});var n=s(6540),r=s(4164),a=s(4245),o=s(6347),i=s(6494),l=s(2814),c=s(5167),u=s(9900);function d(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function m(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:r}}=e;return{value:t,label:s,attributes:n,default:r}}))}(s);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function p(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:s}=e;const r=(0,o.W6)(),a=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,l.aZ)(a),(0,n.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function h(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,a=m(e),[o,l]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:a}))),[c,d]=f({queryString:s,groupId:r}),[h,j]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,u.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&a.set(e)}),[s,a])]}({groupId:r}),x=(()=>{const e=c??h;return p({value:e,tabValues:a})?e:null})();(0,i.A)((()=>{x&&l(x)}),[x]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!p({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),j(e)}),[d,j,a]),tabValues:a}}var j=s(1062);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=s(4848);function b(e){let{className:t,block:s,selectedValue:n,selectValue:o,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,a.a_)(),u=e=>{const t=e.currentTarget,s=l.indexOf(t),r=i[s].value;r!==n&&(c(t),o(r))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const s=l.indexOf(e.currentTarget)+1;t=l[s]??l[0];break}case"ArrowLeft":{const s=l.indexOf(e.currentTarget)-1;t=l[s]??l[l.length-1];break}}t?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":s},t),children:i.map((e=>{let{value:t,label:s,attributes:a}=e;return(0,g.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>l.push(e),onKeyDown:d,onClick:u,...a,className:(0,r.A)("tabs__item",x.tabItem,a?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:a}=e;const o=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=h(e);return(0,g.jsxs)("div",{className:(0,r.A)("tabs-container",x.tabList),children:[(0,g.jsx)(b,{...t,...e}),(0,g.jsx)(v,{...t,...e})]})}function T(e){const t=(0,j.A)();return(0,g.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>o,x:()=>i});var n=s(6540);const r={},a=n.createContext(r);function o(e){const t=n.useContext(a);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),n.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/7ec61308.9c63e66e.js b/assets/js/7ec61308.e2b86301.js similarity index 99% rename from assets/js/7ec61308.9c63e66e.js rename to assets/js/7ec61308.e2b86301.js index 21037b7f13..55c2a8ceca 100644 --- a/assets/js/7ec61308.9c63e66e.js +++ b/assets/js/7ec61308.e2b86301.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[992],{6723:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>p,contentTitle:()=>c,default:()=>h,frontMatter:()=>l,metadata:()=>s,toc:()=>u});const s=JSON.parse('{"id":"getting-started/paths-mapping","title":"Paths mapping","description":"If you use \\"baseUrl\\" and \\"paths\\" options in your tsconfig file, you should make sure the \\"moduleNameMapper\\" option in your Jest config is setup accordingly.","source":"@site/docs/getting-started/paths-mapping.md","sourceDirName":"getting-started","slug":"/getting-started/paths-mapping","permalink":"/ts-jest/docs/next/getting-started/paths-mapping","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/paths-mapping.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"paths-mapping","title":"Paths mapping"},"sidebar":"docs","previous":{"title":"Options","permalink":"/ts-jest/docs/next/getting-started/options"},"next":{"title":"Version checking","permalink":"/ts-jest/docs/next/getting-started/version-checking"}}');var o=n(4848),r=n(8453),a=n(9489),i=n(7227);const l={id:"paths-mapping",title:"Paths mapping"},c=void 0,p={},u=[{value:"Example",id:"example",level:3},{value:"TypeScript config",id:"typescript-config",level:4},{value:"Jest config (without helper)",id:"jest-config-without-helper",level:4},{value:"Jest config (with helper)",id:"jest-config-with-helper",level:4},{value:"If using globalSetup or globalTeardown",id:"if-using-globalsetup-or-globalteardown",level:4},{value:"Global setup file with tsconfig-paths",id:"global-setup-file-with-tsconfig-paths",level:5}];function d(e){const t={a:"a",code:"code",h3:"h3",h4:"h4",h5:"h5",li:"li",p:"p",pre:"pre",ul:"ul",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["If you use ",(0,o.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,o.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,o.jsx)(t.a,{href:"https://jestjs.io/docs/configuration#modulenamemapper-objectstring-string--arraystring",children:'"moduleNameMapper"'})," option in your Jest config is setup accordingly."]}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,o.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,o.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,o.jsxs)(t.p,{children:["With the below config in your ",(0,o.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n "compilerOptions": {\n "baseUrl": ".",\n "paths": {\n "@App/*": ["src/*"],\n "lib/*": ["common/*"]\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,o.jsxs)(a.A,{groupId:"code-examples",children:[(0,o.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n moduleNameMapper: {\n '^@App/(.*)$': '/src/$1',\n '^lib/(.*)$': '/common/$1',\n },\n}\n"})})}),(0,o.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n moduleNameMapper: {\n '^@App/(.*)$': '/src/$1',\n '^lib/(.*)$': '/common/$1',\n },\n}\n\nexport default jestConfig\n"})})}),(0,o.jsx)(i.A,{value:"JSON",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleNameMapper": {\n "^@App/(.*)$": "/src/$1",\n "^lib/(.*)$": "/common/$1"\n }\n }\n}\n'})})})]}),"\n",(0,o.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,o.jsxs)(a.A,{groupId:"code-examples",children:[(0,o.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\nconst { pathsToModuleNameMapper } = require('ts-jest')\n// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file\n// which contains the path mapping (ie the `compilerOptions.paths` option):\nconst { compilerOptions } = require('./tsconfig')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n roots: [''],\n modulePaths: [compilerOptions.baseUrl], // <-- This will be set to 'baseUrl' value\n moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths /*, { prefix: '/' } */),\n}\n"})})}),(0,o.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport { pathsToModuleNameMapper } from 'ts-jest'\n// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file\n// which contains the path mapping (ie the `compilerOptions.paths` option):\nimport { compilerOptions } from './tsconfig'\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n roots: [''],\n modulePaths: [compilerOptions.baseUrl], // <-- This will be set to 'baseUrl' value\n moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths /*, { prefix: '/' } */),\n}\n\nexport default jestConfig\n"})})})]}),"\n",(0,o.jsx)(t.p,{children:"With extra options as 2nd argument:"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsxs)(t.li,{children:[(0,o.jsx)(t.code,{children:"prefix"}),": append prefix to each of mapped config in the result"]}),"\n",(0,o.jsxs)(t.li,{children:[(0,o.jsx)(t.code,{children:"useESM"}),": when using ",(0,o.jsx)(t.code,{children:"type: module"})," in ",(0,o.jsx)(t.code,{children:"package.json"}),", TypeScript enforces users to have explicit ",(0,o.jsx)(t.code,{children:"js"})," extension when importing\na ",(0,o.jsx)(t.code,{children:"ts"})," file. This option is to help ",(0,o.jsx)(t.code,{children:"pathsToModuleNameMapper"})," to create a config to suit with this scenario."]}),"\n"]}),"\n",(0,o.jsxs)(t.h4,{id:"if-using-globalsetup-or-globalteardown",children:["If using ",(0,o.jsx)(t.code,{children:"globalSetup"})," or ",(0,o.jsx)(t.code,{children:"globalTeardown"})]}),"\n",(0,o.jsxs)(t.p,{children:["Files used for ",(0,o.jsx)(t.a,{href:"https://jestjs.io/docs/configuration#globalsetup-string",children:(0,o.jsx)(t.code,{children:"globalSetup"})})," or ",(0,o.jsx)(t.a,{href:"https://jestjs.io/docs/configuration#globalteardown-string",children:(0,o.jsx)(t.code,{children:"globalTeardown"})})," are not directly processes by ",(0,o.jsx)(t.code,{children:"jest"}),", so those do not use the ",(0,o.jsx)(t.a,{href:"https://jestjs.io/docs/configuration#modulenamemapper-objectstring-string--arraystring",children:'"moduleNameMapper"'})," mapping. So you have to make sure those are able to map the paths themselves."]}),"\n",(0,o.jsxs)(t.h5,{id:"global-setup-file-with-tsconfig-paths",children:["Global setup file with ",(0,o.jsx)(t.code,{children:"tsconfig-paths"})]}),"\n",(0,o.jsxs)(t.p,{children:["For those files to be able to use ",(0,o.jsx)(t.a,{href:"https://www.npmjs.com/package/tsconfig-paths",children:(0,o.jsx)(t.code,{children:"tsconfig-paths"})}),", you have to import it directly"]}),"\n",(0,o.jsxs)(a.A,{groupId:"code-examples",children:[(0,o.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// ./path/to/globalSetup.js\nrequire('tsconfig-paths/register')\n\n/**\n * Your global setup\n */\n\n// ./path/to/globalTeardown.js\nrequire('tsconfig-paths/register')\n\n/**\n * Your global teardown\n */\n"})})}),(0,o.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// ./path/to/globalSetup.ts\nimport 'tsconfig-paths/register'\n\n/**\n * Your global setup\n */\n\n// ./path/to/globalTeardown.ts\nimport 'tsconfig-paths/register'\n\n/**\n * Your global teardown\n */\n"})})})]})]})}function h(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>a});n(6540);var s=n(4164);const o={tabItem:"tabItem_Ymn6"};var r=n(4848);function a(e){let{children:t,hidden:n,className:a}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,s.A)(o.tabItem,a),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>y});var s=n(6540),o=n(4164),r=n(4245),a=n(6347),i=n(6494),l=n(2814),c=n(5167),p=n(9900);function u(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function d(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return u(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:o}}=e;return{value:t,label:n,attributes:s,default:o}}))}(n);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function g(e){let{queryString:t=!1,groupId:n}=e;const o=(0,a.W6)(),r=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(r),(0,s.useCallback)((e=>{if(!r)return;const t=new URLSearchParams(o.location.search);t.set(r,e),o.replace({...o.location,search:t.toString()})}),[r,o])]}function m(e){const{defaultValue:t,queryString:n=!1,groupId:o}=e,r=d(e),[a,l]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!h({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:r}))),[c,u]=g({queryString:n,groupId:o}),[m,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[o,r]=(0,p.Dv)(n);return[o,(0,s.useCallback)((e=>{n&&r.set(e)}),[n,r])]}({groupId:o}),j=(()=>{const e=c??m;return h({value:e,tabValues:r})?e:null})();(0,i.A)((()=>{j&&l(j)}),[j]);return{selectedValue:a,selectValue:(0,s.useCallback)((e=>{if(!h({value:e,tabValues:r}))throw new Error(`Can't select invalid tab value=${e}`);l(e),u(e),f(e)}),[u,f,r]),tabValues:r}}var f=n(1062);const j={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=n(4848);function x(e){let{className:t,block:n,selectedValue:s,selectValue:a,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),p=e=>{const t=e.currentTarget,n=l.indexOf(t),o=i[n].value;o!==s&&(c(t),a(o))},u=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.A)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:r}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>l.push(e),onKeyDown:u,onClick:p,...r,className:(0,o.A)("tabs__item",j.tabItem,r?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:r}=e;const a=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=a.find((e=>e.props.value===r));return e?(0,s.cloneElement)(e,{className:(0,o.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:a.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==r})))})}function w(e){const t=m(e);return(0,b.jsxs)("div",{className:(0,o.A)("tabs-container",j.tabList),children:[(0,b.jsx)(x,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function y(e){const t=(0,f.A)();return(0,b.jsx)(w,{...e,children:u(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>a,x:()=>i});var s=n(6540);const o={},r=s.createContext(o);function a(e){const t=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[992],{6723:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>p,contentTitle:()=>c,default:()=>h,frontMatter:()=>l,metadata:()=>s,toc:()=>u});const s=JSON.parse('{"id":"getting-started/paths-mapping","title":"Paths mapping","description":"If you use \\"baseUrl\\" and \\"paths\\" options in your tsconfig file, you should make sure the \\"moduleNameMapper\\" option in your Jest config is setup accordingly.","source":"@site/docs/getting-started/paths-mapping.md","sourceDirName":"getting-started","slug":"/getting-started/paths-mapping","permalink":"/ts-jest/docs/next/getting-started/paths-mapping","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/paths-mapping.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"paths-mapping","title":"Paths mapping"},"sidebar":"docs","previous":{"title":"Options","permalink":"/ts-jest/docs/next/getting-started/options"},"next":{"title":"Version checking","permalink":"/ts-jest/docs/next/getting-started/version-checking"}}');var o=n(4848),r=n(8453),a=n(9489),i=n(7227);const l={id:"paths-mapping",title:"Paths mapping"},c=void 0,p={},u=[{value:"Example",id:"example",level:3},{value:"TypeScript config",id:"typescript-config",level:4},{value:"Jest config (without helper)",id:"jest-config-without-helper",level:4},{value:"Jest config (with helper)",id:"jest-config-with-helper",level:4},{value:"If using globalSetup or globalTeardown",id:"if-using-globalsetup-or-globalteardown",level:4},{value:"Global setup file with tsconfig-paths",id:"global-setup-file-with-tsconfig-paths",level:5}];function d(e){const t={a:"a",code:"code",h3:"h3",h4:"h4",h5:"h5",li:"li",p:"p",pre:"pre",ul:"ul",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["If you use ",(0,o.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,o.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,o.jsx)(t.a,{href:"https://jestjs.io/docs/configuration#modulenamemapper-objectstring-string--arraystring",children:'"moduleNameMapper"'})," option in your Jest config is setup accordingly."]}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,o.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,o.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,o.jsxs)(t.p,{children:["With the below config in your ",(0,o.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n "compilerOptions": {\n "baseUrl": ".",\n "paths": {\n "@App/*": ["src/*"],\n "lib/*": ["common/*"]\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,o.jsxs)(a.A,{groupId:"code-examples",children:[(0,o.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n moduleNameMapper: {\n '^@App/(.*)$': '/src/$1',\n '^lib/(.*)$': '/common/$1',\n },\n}\n"})})}),(0,o.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n moduleNameMapper: {\n '^@App/(.*)$': '/src/$1',\n '^lib/(.*)$': '/common/$1',\n },\n}\n\nexport default jestConfig\n"})})}),(0,o.jsx)(i.A,{value:"JSON",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleNameMapper": {\n "^@App/(.*)$": "/src/$1",\n "^lib/(.*)$": "/common/$1"\n }\n }\n}\n'})})})]}),"\n",(0,o.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,o.jsxs)(a.A,{groupId:"code-examples",children:[(0,o.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\nconst { pathsToModuleNameMapper } = require('ts-jest')\n// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file\n// which contains the path mapping (ie the `compilerOptions.paths` option):\nconst { compilerOptions } = require('./tsconfig')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n roots: [''],\n modulePaths: [compilerOptions.baseUrl], // <-- This will be set to 'baseUrl' value\n moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths /*, { prefix: '/' } */),\n}\n"})})}),(0,o.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport { pathsToModuleNameMapper } from 'ts-jest'\n// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file\n// which contains the path mapping (ie the `compilerOptions.paths` option):\nimport { compilerOptions } from './tsconfig'\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n roots: [''],\n modulePaths: [compilerOptions.baseUrl], // <-- This will be set to 'baseUrl' value\n moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths /*, { prefix: '/' } */),\n}\n\nexport default jestConfig\n"})})})]}),"\n",(0,o.jsx)(t.p,{children:"With extra options as 2nd argument:"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsxs)(t.li,{children:[(0,o.jsx)(t.code,{children:"prefix"}),": append prefix to each of mapped config in the result"]}),"\n",(0,o.jsxs)(t.li,{children:[(0,o.jsx)(t.code,{children:"useESM"}),": when using ",(0,o.jsx)(t.code,{children:"type: module"})," in ",(0,o.jsx)(t.code,{children:"package.json"}),", TypeScript enforces users to have explicit ",(0,o.jsx)(t.code,{children:"js"})," extension when importing\na ",(0,o.jsx)(t.code,{children:"ts"})," file. This option is to help ",(0,o.jsx)(t.code,{children:"pathsToModuleNameMapper"})," to create a config to suit with this scenario."]}),"\n"]}),"\n",(0,o.jsxs)(t.h4,{id:"if-using-globalsetup-or-globalteardown",children:["If using ",(0,o.jsx)(t.code,{children:"globalSetup"})," or ",(0,o.jsx)(t.code,{children:"globalTeardown"})]}),"\n",(0,o.jsxs)(t.p,{children:["Files used for ",(0,o.jsx)(t.a,{href:"https://jestjs.io/docs/configuration#globalsetup-string",children:(0,o.jsx)(t.code,{children:"globalSetup"})})," or ",(0,o.jsx)(t.a,{href:"https://jestjs.io/docs/configuration#globalteardown-string",children:(0,o.jsx)(t.code,{children:"globalTeardown"})})," are not directly processes by ",(0,o.jsx)(t.code,{children:"jest"}),", so those do not use the ",(0,o.jsx)(t.a,{href:"https://jestjs.io/docs/configuration#modulenamemapper-objectstring-string--arraystring",children:'"moduleNameMapper"'})," mapping. So you have to make sure those are able to map the paths themselves."]}),"\n",(0,o.jsxs)(t.h5,{id:"global-setup-file-with-tsconfig-paths",children:["Global setup file with ",(0,o.jsx)(t.code,{children:"tsconfig-paths"})]}),"\n",(0,o.jsxs)(t.p,{children:["For those files to be able to use ",(0,o.jsx)(t.a,{href:"https://www.npmjs.com/package/tsconfig-paths",children:(0,o.jsx)(t.code,{children:"tsconfig-paths"})}),", you have to import it directly"]}),"\n",(0,o.jsxs)(a.A,{groupId:"code-examples",children:[(0,o.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// ./path/to/globalSetup.js\nrequire('tsconfig-paths/register')\n\n/**\n * Your global setup\n */\n\n// ./path/to/globalTeardown.js\nrequire('tsconfig-paths/register')\n\n/**\n * Your global teardown\n */\n"})})}),(0,o.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// ./path/to/globalSetup.ts\nimport 'tsconfig-paths/register'\n\n/**\n * Your global setup\n */\n\n// ./path/to/globalTeardown.ts\nimport 'tsconfig-paths/register'\n\n/**\n * Your global teardown\n */\n"})})})]})]})}function h(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>a});n(6540);var s=n(4164);const o={tabItem:"tabItem_Ymn6"};var r=n(4848);function a(e){let{children:t,hidden:n,className:a}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,s.A)(o.tabItem,a),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>y});var s=n(6540),o=n(4164),r=n(4245),a=n(6347),i=n(6494),l=n(2814),c=n(5167),p=n(9900);function u(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function d(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return u(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:o}}=e;return{value:t,label:n,attributes:s,default:o}}))}(n);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function g(e){let{queryString:t=!1,groupId:n}=e;const o=(0,a.W6)(),r=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(r),(0,s.useCallback)((e=>{if(!r)return;const t=new URLSearchParams(o.location.search);t.set(r,e),o.replace({...o.location,search:t.toString()})}),[r,o])]}function m(e){const{defaultValue:t,queryString:n=!1,groupId:o}=e,r=d(e),[a,l]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!h({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:r}))),[c,u]=g({queryString:n,groupId:o}),[m,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[o,r]=(0,p.Dv)(n);return[o,(0,s.useCallback)((e=>{n&&r.set(e)}),[n,r])]}({groupId:o}),j=(()=>{const e=c??m;return h({value:e,tabValues:r})?e:null})();(0,i.A)((()=>{j&&l(j)}),[j]);return{selectedValue:a,selectValue:(0,s.useCallback)((e=>{if(!h({value:e,tabValues:r}))throw new Error(`Can't select invalid tab value=${e}`);l(e),u(e),f(e)}),[u,f,r]),tabValues:r}}var f=n(1062);const j={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=n(4848);function x(e){let{className:t,block:n,selectedValue:s,selectValue:a,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),p=e=>{const t=e.currentTarget,n=l.indexOf(t),o=i[n].value;o!==s&&(c(t),a(o))},u=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.A)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:r}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>l.push(e),onKeyDown:u,onClick:p,...r,className:(0,o.A)("tabs__item",j.tabItem,r?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:r}=e;const a=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=a.find((e=>e.props.value===r));return e?(0,s.cloneElement)(e,{className:(0,o.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:a.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==r})))})}function w(e){const t=m(e);return(0,b.jsxs)("div",{className:(0,o.A)("tabs-container",j.tabList),children:[(0,b.jsx)(x,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function y(e){const t=(0,f.A)();return(0,b.jsx)(w,{...e,children:u(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>a,x:()=>i});var s=n(6540);const o={},r=s.createContext(o);function a(e){const t=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/801c4327.10205da7.js b/assets/js/801c4327.c006a379.js similarity index 99% rename from assets/js/801c4327.10205da7.js rename to assets/js/801c4327.c006a379.js index 7609b35a42..50672286a5 100644 --- a/assets/js/801c4327.10205da7.js +++ b/assets/js/801c4327.c006a379.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2817],{1369:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>o,contentTitle:()=>c,default:()=>a,frontMatter:()=>d,metadata:()=>n,toc:()=>l});const n=JSON.parse('{"id":"getting-started/presets","title":"Presets","description":"The presets","source":"@site/versioned_docs/version-27.1/getting-started/presets.md","sourceDirName":"getting-started","slug":"/getting-started/presets","permalink":"/ts-jest/docs/27.1/getting-started/presets","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/presets.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"presets","title":"Presets"},"sidebar":"version-27.1-docs","previous":{"title":"Installation","permalink":"/ts-jest/docs/27.1/getting-started/installation"},"next":{"title":"Options","permalink":"/ts-jest/docs/27.1/getting-started/options"}}');var r=t(4848),i=t(8453);const d={id:"presets",title:"Presets"},c=void 0,o={},l=[{value:"The presets",id:"the-presets",level:3},{value:"Basic usage",id:"basic-usage",level:3},{value:"Advanced",id:"advanced",level:3}];function j(e){const s={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,i.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(s.h3,{id:"the-presets",children:"The presets"}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.code,{children:"ts-jest"})," comes with several presets, covering most of the project's base configuration:"]}),"\n",(0,r.jsxs)(s.table,{children:[(0,r.jsx)(s.thead,{children:(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.th,{children:"Preset name"}),(0,r.jsx)(s.th,{children:"Description"})]})}),(0,r.jsxs)(s.tbody,{children:[(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default"}),(0,r.jsx)("br",{}),"or ",(0,r.jsx)(s.code,{children:"ts-jest"})]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default-esm"}),(0,r.jsx)("br",{})]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts"})}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-esm"})}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel"})}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-esm"})}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]})]})]}),"\n",(0,r.jsx)(s.h3,{id:"basic-usage",children:"Basic usage"}),"\n",(0,r.jsxs)(s.p,{children:["In most cases, simply setting the ",(0,r.jsx)(s.code,{children:"preset"})," key to the desired preset name in your Jest config should be enough to start\nusing TypeScript with Jest (assuming you added ",(0,r.jsx)(s.code,{children:"ts-jest"})," to your ",(0,r.jsx)(s.code,{children:"devDependencies"})," of course):"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n // Replace `ts-jest` with the preset you want to use\n // from the above list\n preset: 'ts-jest',\n}\n"})}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n // Replace `ts-jest` with the preset you want to use\n // from the above list\n "preset": "ts-jest"\n }\n}\n'})}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.strong,{children:"Note:"})," presets use ",(0,r.jsx)(s.code,{children:"testMatch"}),", like Jest does in its defaults. If you want to use ",(0,r.jsx)(s.code,{children:"testRegex"})," instead in your configuration, you MUST set ",(0,r.jsx)(s.code,{children:"testMatch"})," to ",(0,r.jsx)(s.code,{children:"null"})," or Jest will bail."]}),"\n",(0,r.jsx)(s.h3,{id:"advanced",children:"Advanced"}),"\n",(0,r.jsxs)(s.p,{children:["Any preset can also be used with other options.\nIf you're already using another preset, you might want only some specific settings from the chosen ",(0,r.jsx)(s.code,{children:"ts-jest"})," preset.\nIn this case you'll need to use the JavaScript version of Jest config (comment/uncomment according to your use case):"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n// const { defaultsESM: tsjPreset } = require('ts-jest/presets')\n// const { jsWithTs: tsjPreset } = require('ts-jest/presets')\n// const { jsWithTsESM: tsjPreset } = require('ts-jest/presets')\n// const { jsWithBabel: tsjPreset } = require('ts-jest/presets')\n// const { jsWithBabelESM: tsjPreset } = require('ts-jest/presets')\n\nmodule.exports = {\n // [...]\n transform: {\n ...tsjPreset.transform,\n // [...]\n },\n}\n"})}),"\n",(0,r.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,r.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport type { InitialOptionsTsJest } from 'ts-jest'\nimport { defaults as tsjPreset } from 'ts-jest/presets'\n// import { defaultsESM as tsjPreset } from 'ts-jest/presets'\n// import { jsWithTs as tsjPreset } from 'ts-jest/presets'\n// import { jsWithTsESM as tsjPreset } from 'ts-jest/presets'\n// import { jsWithBabel as tsjPreset } from 'ts-jest/presets'\n// import { jsWithBabelESM as tsjPreset } from 'ts-jest/presets'\n\nconst config: InitialOptionsTsJest = {\n // [...]\n transform: {\n ...tsjPreset.transform,\n // [...]\n },\n}\n\nexport default config\n"})})]})}function a(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(j,{...e})}):j(e)}},8453:(e,s,t)=>{t.d(s,{R:()=>d,x:()=>c});var n=t(6540);const r={},i=n.createContext(r);function d(e){const s=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function c(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:d(e.components),n.createElement(i.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2817],{1369:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>o,contentTitle:()=>c,default:()=>a,frontMatter:()=>d,metadata:()=>n,toc:()=>l});const n=JSON.parse('{"id":"getting-started/presets","title":"Presets","description":"The presets","source":"@site/versioned_docs/version-27.1/getting-started/presets.md","sourceDirName":"getting-started","slug":"/getting-started/presets","permalink":"/ts-jest/docs/27.1/getting-started/presets","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/presets.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"presets","title":"Presets"},"sidebar":"version-27.1-docs","previous":{"title":"Installation","permalink":"/ts-jest/docs/27.1/getting-started/installation"},"next":{"title":"Options","permalink":"/ts-jest/docs/27.1/getting-started/options"}}');var r=t(4848),i=t(8453);const d={id:"presets",title:"Presets"},c=void 0,o={},l=[{value:"The presets",id:"the-presets",level:3},{value:"Basic usage",id:"basic-usage",level:3},{value:"Advanced",id:"advanced",level:3}];function j(e){const s={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,i.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(s.h3,{id:"the-presets",children:"The presets"}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.code,{children:"ts-jest"})," comes with several presets, covering most of the project's base configuration:"]}),"\n",(0,r.jsxs)(s.table,{children:[(0,r.jsx)(s.thead,{children:(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.th,{children:"Preset name"}),(0,r.jsx)(s.th,{children:"Description"})]})}),(0,r.jsxs)(s.tbody,{children:[(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default"}),(0,r.jsx)("br",{}),"or ",(0,r.jsx)(s.code,{children:"ts-jest"})]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default-esm"}),(0,r.jsx)("br",{})]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts"})}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-esm"})}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel"})}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-esm"})}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]})]})]}),"\n",(0,r.jsx)(s.h3,{id:"basic-usage",children:"Basic usage"}),"\n",(0,r.jsxs)(s.p,{children:["In most cases, simply setting the ",(0,r.jsx)(s.code,{children:"preset"})," key to the desired preset name in your Jest config should be enough to start\nusing TypeScript with Jest (assuming you added ",(0,r.jsx)(s.code,{children:"ts-jest"})," to your ",(0,r.jsx)(s.code,{children:"devDependencies"})," of course):"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n // Replace `ts-jest` with the preset you want to use\n // from the above list\n preset: 'ts-jest',\n}\n"})}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n // Replace `ts-jest` with the preset you want to use\n // from the above list\n "preset": "ts-jest"\n }\n}\n'})}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.strong,{children:"Note:"})," presets use ",(0,r.jsx)(s.code,{children:"testMatch"}),", like Jest does in its defaults. If you want to use ",(0,r.jsx)(s.code,{children:"testRegex"})," instead in your configuration, you MUST set ",(0,r.jsx)(s.code,{children:"testMatch"})," to ",(0,r.jsx)(s.code,{children:"null"})," or Jest will bail."]}),"\n",(0,r.jsx)(s.h3,{id:"advanced",children:"Advanced"}),"\n",(0,r.jsxs)(s.p,{children:["Any preset can also be used with other options.\nIf you're already using another preset, you might want only some specific settings from the chosen ",(0,r.jsx)(s.code,{children:"ts-jest"})," preset.\nIn this case you'll need to use the JavaScript version of Jest config (comment/uncomment according to your use case):"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n// const { defaultsESM: tsjPreset } = require('ts-jest/presets')\n// const { jsWithTs: tsjPreset } = require('ts-jest/presets')\n// const { jsWithTsESM: tsjPreset } = require('ts-jest/presets')\n// const { jsWithBabel: tsjPreset } = require('ts-jest/presets')\n// const { jsWithBabelESM: tsjPreset } = require('ts-jest/presets')\n\nmodule.exports = {\n // [...]\n transform: {\n ...tsjPreset.transform,\n // [...]\n },\n}\n"})}),"\n",(0,r.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,r.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport type { InitialOptionsTsJest } from 'ts-jest'\nimport { defaults as tsjPreset } from 'ts-jest/presets'\n// import { defaultsESM as tsjPreset } from 'ts-jest/presets'\n// import { jsWithTs as tsjPreset } from 'ts-jest/presets'\n// import { jsWithTsESM as tsjPreset } from 'ts-jest/presets'\n// import { jsWithBabel as tsjPreset } from 'ts-jest/presets'\n// import { jsWithBabelESM as tsjPreset } from 'ts-jest/presets'\n\nconst config: InitialOptionsTsJest = {\n // [...]\n transform: {\n ...tsjPreset.transform,\n // [...]\n },\n}\n\nexport default config\n"})})]})}function a(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(j,{...e})}):j(e)}},8453:(e,s,t)=>{t.d(s,{R:()=>d,x:()=>c});var n=t(6540);const r={},i=n.createContext(r);function d(e){const s=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function c(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:d(e.components),n.createElement(i.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/850a2979.647ee6bf.js b/assets/js/850a2979.ad40f081.js similarity index 99% rename from assets/js/850a2979.647ee6bf.js rename to assets/js/850a2979.ad40f081.js index 5208e59a7b..2d56cab1a2 100644 --- a/assets/js/850a2979.647ee6bf.js +++ b/assets/js/850a2979.ad40f081.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6964],{6113:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>o,contentTitle:()=>c,default:()=>a,frontMatter:()=>d,metadata:()=>n,toc:()=>l});const n=JSON.parse('{"id":"getting-started/presets","title":"Presets","description":"The presets","source":"@site/versioned_docs/version-27.0/getting-started/presets.md","sourceDirName":"getting-started","slug":"/getting-started/presets","permalink":"/ts-jest/docs/27.0/getting-started/presets","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/presets.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"presets","title":"Presets"},"sidebar":"version-27.0-docs","previous":{"title":"Installation","permalink":"/ts-jest/docs/27.0/getting-started/installation"},"next":{"title":"Options","permalink":"/ts-jest/docs/27.0/getting-started/options"}}');var r=t(4848),i=t(8453);const d={id:"presets",title:"Presets"},c=void 0,o={},l=[{value:"The presets",id:"the-presets",level:3},{value:"Basic usage",id:"basic-usage",level:3},{value:"Advanced",id:"advanced",level:3}];function j(e){const s={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,i.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(s.h3,{id:"the-presets",children:"The presets"}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.code,{children:"ts-jest"})," comes with several presets, covering most of the project's base configuration:"]}),"\n",(0,r.jsxs)(s.table,{children:[(0,r.jsx)(s.thead,{children:(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.th,{children:"Preset name"}),(0,r.jsx)(s.th,{children:"Description"})]})}),(0,r.jsxs)(s.tbody,{children:[(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default"}),(0,r.jsx)("br",{}),"or ",(0,r.jsx)(s.code,{children:"ts-jest"})]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default-esm"}),(0,r.jsx)("br",{})]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts"})}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-esm"})}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel"})}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-esm"})}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]})]})]}),"\n",(0,r.jsx)(s.h3,{id:"basic-usage",children:"Basic usage"}),"\n",(0,r.jsxs)(s.p,{children:["In most cases, simply setting the ",(0,r.jsx)(s.code,{children:"preset"})," key to the desired preset name in your Jest config should be enough to start\nusing TypeScript with Jest (assuming you added ",(0,r.jsx)(s.code,{children:"ts-jest"})," to your ",(0,r.jsx)(s.code,{children:"devDependencies"})," of course):"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n // Replace `ts-jest` with the preset you want to use\n // from the above list\n preset: 'ts-jest',\n}\n"})}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n // Replace `ts-jest` with the preset you want to use\n // from the above list\n "preset": "ts-jest"\n }\n}\n'})}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.strong,{children:"Note:"})," presets use ",(0,r.jsx)(s.code,{children:"testMatch"}),", like Jest does in its defaults. If you want to use ",(0,r.jsx)(s.code,{children:"testRegex"})," instead in your configuration, you MUST set ",(0,r.jsx)(s.code,{children:"testMatch"})," to ",(0,r.jsx)(s.code,{children:"null"})," or Jest will bail."]}),"\n",(0,r.jsx)(s.h3,{id:"advanced",children:"Advanced"}),"\n",(0,r.jsxs)(s.p,{children:["Any preset can also be used with other options.\nIf you're already using another preset, you might want only some specific settings from the chosen ",(0,r.jsx)(s.code,{children:"ts-jest"})," preset.\nIn this case you'll need to use the JavaScript version of Jest config (comment/uncomment according to your use case):"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n// const { defaultsESM: tsjPreset } = require('ts-jest/presets')\n// const { jsWithTs: tsjPreset } = require('ts-jest/presets')\n// const { jsWithTsESM: tsjPreset } = require('ts-jest/presets')\n// const { jsWithBabel: tsjPreset } = require('ts-jest/presets')\n// const { jsWithBabelESM: tsjPreset } = require('ts-jest/presets')\n\nmodule.exports = {\n // [...]\n transform: {\n ...tsjPreset.transform,\n // [...]\n },\n}\n"})}),"\n",(0,r.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,r.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport type { InitialOptionsTsJest } from 'ts-jest/dist/types'\nimport { defaults as tsjPreset } from 'ts-jest/presets'\n// import { defaultsESM as tsjPreset } from 'ts-jest/presets'\n// import { jsWithTs as tsjPreset } from 'ts-jest/presets'\n// import { jsWithTsESM as tsjPreset } from 'ts-jest/presets'\n// import { jsWithBabel as tsjPreset } from 'ts-jest/presets'\n// import { jsWithBabelESM as tsjPreset } from 'ts-jest/presets'\n\nconst config: InitialOptionsTsJest = {\n // [...]\n transform: {\n ...tsjPreset.transform,\n // [...]\n },\n}\n\nexport default config\n"})})]})}function a(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(j,{...e})}):j(e)}},8453:(e,s,t)=>{t.d(s,{R:()=>d,x:()=>c});var n=t(6540);const r={},i=n.createContext(r);function d(e){const s=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function c(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:d(e.components),n.createElement(i.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6964],{6113:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>o,contentTitle:()=>c,default:()=>a,frontMatter:()=>d,metadata:()=>n,toc:()=>l});const n=JSON.parse('{"id":"getting-started/presets","title":"Presets","description":"The presets","source":"@site/versioned_docs/version-27.0/getting-started/presets.md","sourceDirName":"getting-started","slug":"/getting-started/presets","permalink":"/ts-jest/docs/27.0/getting-started/presets","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/presets.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"presets","title":"Presets"},"sidebar":"version-27.0-docs","previous":{"title":"Installation","permalink":"/ts-jest/docs/27.0/getting-started/installation"},"next":{"title":"Options","permalink":"/ts-jest/docs/27.0/getting-started/options"}}');var r=t(4848),i=t(8453);const d={id:"presets",title:"Presets"},c=void 0,o={},l=[{value:"The presets",id:"the-presets",level:3},{value:"Basic usage",id:"basic-usage",level:3},{value:"Advanced",id:"advanced",level:3}];function j(e){const s={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,i.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(s.h3,{id:"the-presets",children:"The presets"}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.code,{children:"ts-jest"})," comes with several presets, covering most of the project's base configuration:"]}),"\n",(0,r.jsxs)(s.table,{children:[(0,r.jsx)(s.thead,{children:(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.th,{children:"Preset name"}),(0,r.jsx)(s.th,{children:"Description"})]})}),(0,r.jsxs)(s.tbody,{children:[(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default"}),(0,r.jsx)("br",{}),"or ",(0,r.jsx)(s.code,{children:"ts-jest"})]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default-esm"}),(0,r.jsx)("br",{})]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts"})}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-esm"})}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel"})}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-esm"})}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]})]})]}),"\n",(0,r.jsx)(s.h3,{id:"basic-usage",children:"Basic usage"}),"\n",(0,r.jsxs)(s.p,{children:["In most cases, simply setting the ",(0,r.jsx)(s.code,{children:"preset"})," key to the desired preset name in your Jest config should be enough to start\nusing TypeScript with Jest (assuming you added ",(0,r.jsx)(s.code,{children:"ts-jest"})," to your ",(0,r.jsx)(s.code,{children:"devDependencies"})," of course):"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n // Replace `ts-jest` with the preset you want to use\n // from the above list\n preset: 'ts-jest',\n}\n"})}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n // Replace `ts-jest` with the preset you want to use\n // from the above list\n "preset": "ts-jest"\n }\n}\n'})}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.strong,{children:"Note:"})," presets use ",(0,r.jsx)(s.code,{children:"testMatch"}),", like Jest does in its defaults. If you want to use ",(0,r.jsx)(s.code,{children:"testRegex"})," instead in your configuration, you MUST set ",(0,r.jsx)(s.code,{children:"testMatch"})," to ",(0,r.jsx)(s.code,{children:"null"})," or Jest will bail."]}),"\n",(0,r.jsx)(s.h3,{id:"advanced",children:"Advanced"}),"\n",(0,r.jsxs)(s.p,{children:["Any preset can also be used with other options.\nIf you're already using another preset, you might want only some specific settings from the chosen ",(0,r.jsx)(s.code,{children:"ts-jest"})," preset.\nIn this case you'll need to use the JavaScript version of Jest config (comment/uncomment according to your use case):"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n// const { defaultsESM: tsjPreset } = require('ts-jest/presets')\n// const { jsWithTs: tsjPreset } = require('ts-jest/presets')\n// const { jsWithTsESM: tsjPreset } = require('ts-jest/presets')\n// const { jsWithBabel: tsjPreset } = require('ts-jest/presets')\n// const { jsWithBabelESM: tsjPreset } = require('ts-jest/presets')\n\nmodule.exports = {\n // [...]\n transform: {\n ...tsjPreset.transform,\n // [...]\n },\n}\n"})}),"\n",(0,r.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,r.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport type { InitialOptionsTsJest } from 'ts-jest/dist/types'\nimport { defaults as tsjPreset } from 'ts-jest/presets'\n// import { defaultsESM as tsjPreset } from 'ts-jest/presets'\n// import { jsWithTs as tsjPreset } from 'ts-jest/presets'\n// import { jsWithTsESM as tsjPreset } from 'ts-jest/presets'\n// import { jsWithBabel as tsjPreset } from 'ts-jest/presets'\n// import { jsWithBabelESM as tsjPreset } from 'ts-jest/presets'\n\nconst config: InitialOptionsTsJest = {\n // [...]\n transform: {\n ...tsjPreset.transform,\n // [...]\n },\n}\n\nexport default config\n"})})]})}function a(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(j,{...e})}):j(e)}},8453:(e,s,t)=>{t.d(s,{R:()=>d,x:()=>c});var n=t(6540);const r={},i=n.createContext(r);function d(e){const s=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function c(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:d(e.components),n.createElement(i.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/86b5844b.d350fa07.js b/assets/js/86b5844b.f61f80de.js similarity index 99% rename from assets/js/86b5844b.d350fa07.js rename to assets/js/86b5844b.f61f80de.js index 7af2454d96..a81202ac69 100644 --- a/assets/js/86b5844b.d350fa07.js +++ b/assets/js/86b5844b.f61f80de.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[988],{1471:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>l,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"guides/react-native","title":"Using with React Native","description":"To use ts-jest with React Native + TypeScript and Babel 7, you\'ll first need to follow this tutorial.","source":"@site/docs/guides/react-native.md","sourceDirName":"guides","slug":"/guides/react-native","permalink":"/ts-jest/docs/next/guides/react-native","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/guides/react-native.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"react-native","title":"Using with React Native"},"sidebar":"docs","previous":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/next/guides/mock-es6-class"},"next":{"title":"Troubleshooting","permalink":"/ts-jest/docs/next/guides/troubleshooting"}}');var r=n(4848),a=n(8453),o=n(9489),i=n(7227);const l={id:"react-native",title:"Using with React Native"},c=void 0,u={},d=[{value:"Babel config",id:"babel-config",level:3},{value:"TypeScript Configuration",id:"typescript-configuration",level:3},{value:"Jest config",id:"jest-config",level:3}];function f(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["To use ",(0,r.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,r.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,r.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,r.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,r.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,r.jsx)(t.code,{children:".babelrc"})," to ",(0,r.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n\nexport default jestConfig\n"})})})]}),"\n",(0,r.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,r.jsxs)(t.p,{children:["Create a new ",(0,r.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-json",children:'// tsconfig.spec.json\n{\n "extends": "./tsconfig.json",\n "compilerOptions": {\n "jsx": "react"\n }\n}\n'})}),"\n",(0,r.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,r.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,r.jsx)(t.code,{children:"jest"})," key of ",(0,r.jsx)(t.code,{children:"package.json"})," to ",(0,r.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\nconst { createJsWithBabelPreset } = require('ts-jest')\n\nconst jsWithBabelPreset = createJsWithBabelPreset({\n tsconfig: 'tsconfig.spec.json',\n babelConfig: true,\n})\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n preset: 'react-native',\n transform: jsWithBabelPreset.transform,\n moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport { createJsWithBabelPreset, JestConfigWithTsJest } from 'ts-jest'\n\nconst jsWithBabelPreset = createJsWithBabelPreset({\n tsconfig: 'tsconfig.spec.json',\n babelConfig: true,\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n preset: 'react-native',\n transform: jsWithBabelPreset.transform,\n moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],\n}\n\nexport default jestConfig\n"})})})]})]})}function p(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(f,{...e})}):f(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var s=n(4164);const r={tabItem:"tabItem_Ymn6"};var a=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,s.A)(r.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),r=n(4164),a=n(4245),o=n(6347),i=n(6494),l=n(2814),c=n(5167),u=n(9900);function d(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function f(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:r}}=e;return{value:t,label:n,attributes:s,default:r}}))}(n);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:n}=e;const r=(0,o.W6)(),a=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(a),(0,s.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,a=f(e),[o,l]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:a}))),[c,d]=h({queryString:n,groupId:r}),[b,g]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,u.Dv)(n);return[r,(0,s.useCallback)((e=>{n&&a.set(e)}),[n,a])]}({groupId:r}),m=(()=>{const e=c??b;return p({value:e,tabValues:a})?e:null})();(0,i.A)((()=>{m&&l(m)}),[m]);return{selectedValue:o,selectValue:(0,s.useCallback)((e=>{if(!p({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),g(e)}),[d,g,a]),tabValues:a}}var g=n(1062);const m={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var j=n(4848);function v(e){let{className:t,block:n,selectedValue:s,selectValue:o,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,a.a_)(),u=e=>{const t=e.currentTarget,n=l.indexOf(t),r=i[n].value;r!==s&&(c(t),o(r))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,j.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:a}=e;return(0,j.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>l.push(e),onKeyDown:d,onClick:u,...a,className:(0,r.A)("tabs__item",m.tabItem,a?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:a}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,s.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,j.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=b(e);return(0,j.jsxs)("div",{className:(0,r.A)("tabs-container",m.tabList),children:[(0,j.jsx)(v,{...t,...e}),(0,j.jsx)(x,{...t,...e})]})}function w(e){const t=(0,g.A)();return(0,j.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>i});var s=n(6540);const r={},a=s.createContext(r);function o(e){const t=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),s.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[988],{1471:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>l,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"guides/react-native","title":"Using with React Native","description":"To use ts-jest with React Native + TypeScript and Babel 7, you\'ll first need to follow this tutorial.","source":"@site/docs/guides/react-native.md","sourceDirName":"guides","slug":"/guides/react-native","permalink":"/ts-jest/docs/next/guides/react-native","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/guides/react-native.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"react-native","title":"Using with React Native"},"sidebar":"docs","previous":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/next/guides/mock-es6-class"},"next":{"title":"Troubleshooting","permalink":"/ts-jest/docs/next/guides/troubleshooting"}}');var r=n(4848),a=n(8453),o=n(9489),i=n(7227);const l={id:"react-native",title:"Using with React Native"},c=void 0,u={},d=[{value:"Babel config",id:"babel-config",level:3},{value:"TypeScript Configuration",id:"typescript-configuration",level:3},{value:"Jest config",id:"jest-config",level:3}];function f(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["To use ",(0,r.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,r.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,r.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,r.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,r.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,r.jsx)(t.code,{children:".babelrc"})," to ",(0,r.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n\nexport default jestConfig\n"})})})]}),"\n",(0,r.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,r.jsxs)(t.p,{children:["Create a new ",(0,r.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-json",children:'// tsconfig.spec.json\n{\n "extends": "./tsconfig.json",\n "compilerOptions": {\n "jsx": "react"\n }\n}\n'})}),"\n",(0,r.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,r.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,r.jsx)(t.code,{children:"jest"})," key of ",(0,r.jsx)(t.code,{children:"package.json"})," to ",(0,r.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\nconst { createJsWithBabelPreset } = require('ts-jest')\n\nconst jsWithBabelPreset = createJsWithBabelPreset({\n tsconfig: 'tsconfig.spec.json',\n babelConfig: true,\n})\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n preset: 'react-native',\n transform: jsWithBabelPreset.transform,\n moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport { createJsWithBabelPreset, JestConfigWithTsJest } from 'ts-jest'\n\nconst jsWithBabelPreset = createJsWithBabelPreset({\n tsconfig: 'tsconfig.spec.json',\n babelConfig: true,\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n preset: 'react-native',\n transform: jsWithBabelPreset.transform,\n moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],\n}\n\nexport default jestConfig\n"})})})]})]})}function p(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(f,{...e})}):f(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var s=n(4164);const r={tabItem:"tabItem_Ymn6"};var a=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,s.A)(r.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),r=n(4164),a=n(4245),o=n(6347),i=n(6494),l=n(2814),c=n(5167),u=n(9900);function d(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function f(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:r}}=e;return{value:t,label:n,attributes:s,default:r}}))}(n);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:n}=e;const r=(0,o.W6)(),a=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(a),(0,s.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,a=f(e),[o,l]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:a}))),[c,d]=h({queryString:n,groupId:r}),[b,g]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,u.Dv)(n);return[r,(0,s.useCallback)((e=>{n&&a.set(e)}),[n,a])]}({groupId:r}),m=(()=>{const e=c??b;return p({value:e,tabValues:a})?e:null})();(0,i.A)((()=>{m&&l(m)}),[m]);return{selectedValue:o,selectValue:(0,s.useCallback)((e=>{if(!p({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),g(e)}),[d,g,a]),tabValues:a}}var g=n(1062);const m={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var j=n(4848);function v(e){let{className:t,block:n,selectedValue:s,selectValue:o,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,a.a_)(),u=e=>{const t=e.currentTarget,n=l.indexOf(t),r=i[n].value;r!==s&&(c(t),o(r))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,j.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:a}=e;return(0,j.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>l.push(e),onKeyDown:d,onClick:u,...a,className:(0,r.A)("tabs__item",m.tabItem,a?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:a}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,s.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,j.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=b(e);return(0,j.jsxs)("div",{className:(0,r.A)("tabs-container",m.tabList),children:[(0,j.jsx)(v,{...t,...e}),(0,j.jsx)(x,{...t,...e})]})}function w(e){const t=(0,g.A)();return(0,j.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>i});var s=n(6540);const r={},a=s.createContext(r);function o(e){const t=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),s.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/8b2f9623.cd44d226.js b/assets/js/8b2f9623.f045538d.js similarity index 98% rename from assets/js/8b2f9623.cd44d226.js rename to assets/js/8b2f9623.f045538d.js index 7e2ddef568..020526dbd4 100644 --- a/assets/js/8b2f9623.cd44d226.js +++ b/assets/js/8b2f9623.f045538d.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8629],{5035:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>d,contentTitle:()=>l,default:()=>u,frontMatter:()=>r,metadata:()=>t,toc:()=>a});const t=JSON.parse('{"id":"guides/troubleshooting","title":"Troubleshooting","description":"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them.","source":"@site/versioned_docs/version-29.0/guides/troubleshooting.md","sourceDirName":"guides","slug":"/guides/troubleshooting","permalink":"/ts-jest/docs/29.0/guides/troubleshooting","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/guides/troubleshooting.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"troubleshooting","title":"Troubleshooting"},"sidebar":"version-29.0-docs","previous":{"title":"Using with React Native","permalink":"/ts-jest/docs/29.0/guides/react-native"},"next":{"title":"Using with monorepo","permalink":"/ts-jest/docs/29.0/guides/using-with-monorepo"}}');var o=n(4848),i=n(8453);const r={id:"troubleshooting",title:"Troubleshooting"},l=void 0,d={},a=[{value:"Running ts-jest on CI tools",id:"running-ts-jest-on-ci-tools",level:2},{value:"PROBLEM",id:"problem",level:3},{value:"SOLUTION",id:"solution",level:3},{value:"Transform (node)-module explicitly",id:"transform-node-module-explicitly",level:2},{value:"PROBLEM",id:"problem-1",level:3},{value:"SOLUTION",id:"solution-1",level:3},{value:"Tests gets stuck when importing a dependency",id:"tests-gets-stuck-when-importing-a-dependency",level:2},{value:"PROBLEM",id:"problem-2",level:3},{value:"SOLUTION",id:"solution-2",level:3}];function c(e){const s={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(s.p,{children:"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them."}),"\n",(0,o.jsxs)(s.p,{children:["Please also check Jest ",(0,o.jsx)(s.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," if your issue is related to jest."]}),"\n",(0,o.jsx)(s.h2,{id:"running-ts-jest-on-ci-tools",children:"Running ts-jest on CI tools"}),"\n",(0,o.jsx)(s.h3,{id:"problem",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:'Cannot find module "" from ""'}),"\n",(0,o.jsx)(s.h3,{id:"solution",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check if ",(0,o.jsx)(s.code,{children:"rootDir"})," is referenced correctly. If not add this on your existing jest configuration."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n roots: [""]\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module directories are included on your jest configuration. If not add this on your existing jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleDirectories: ["node_modules",""],\n modulePaths: [""],\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module name is properly mapped and can be referenced by jest. If not, you can define moduleNameMapper for your jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleNameMapper: {\n "": "/",\n },\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check github folder names if its identical to you local folder names. Sometimes github never updates your folder names even if you rename it locally. If this happens rename your folders via github or use this command ",(0,o.jsx)(s.code,{children:"git mv "})," and commit changes."]}),"\n"]}),"\n",(0,o.jsx)(s.h2,{id:"transform-node-module-explicitly",children:"Transform (node)-module explicitly"}),"\n",(0,o.jsx)(s.h3,{id:"problem-1",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"SyntaxError: Cannot use import statement outside a module"}),"\n",(0,o.jsx)(s.h3,{id:"solution-1",children:"SOLUTION"}),"\n",(0,o.jsx)(s.p,{children:"One of the node modules hasn't the correct syntax for Jests execution step. It needs to\nbe transformed first."}),"\n",(0,o.jsx)(s.p,{children:"There is a good chance that the error message shows which module is affected:"}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-shell",children:' SyntaxError: Cannot use import statement outside a module\n > 22 | import Component from "../../node_modules/some-module/lib";\n | ^\n'})}),"\n",(0,o.jsxs)(s.p,{children:["In this case ",(0,o.jsx)(s.strong,{children:"some-module"})," is the problem and needs to be transformed.\nBy adding the following line to the configuration file it will tell Jest which modules\nshouldnt be ignored during the transformation step:"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n transformIgnorePatterns: ["node_modules/(?!(some-module|another-module))"]\n};\n'})}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.strong,{children:"some-module"})," and ",(0,o.jsx)(s.strong,{children:"another-module"})," will be transformed."]}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/63389757/jest-unit-test-syntaxerror-cannot-use-import-statement-outside-a-module",children:"here"})," and ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/52035066/how-to-write-jest-transformignorepatterns",children:"here"}),"."]}),"\n",(0,o.jsx)(s.h2,{id:"tests-gets-stuck-when-importing-a-dependency",children:"Tests gets stuck when importing a dependency"}),"\n",(0,o.jsx)(s.h3,{id:"problem-2",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"Without cache, jest takes an extremely long time to process files and appears to be stuck."}),"\n",(0,o.jsx)(s.h3,{id:"solution-2",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.code,{children:"ts-jest"})," internally uses TypeScript compiler API to transform ts/js file into js file. The recommendation is to only transform what is needed."]}),"\n",(0,o.jsxs)(s.p,{children:["A possible cause for that issue is that you may have enabled ",(0,o.jsx)(s.code,{children:"ts-jest"})," to process javascript files in addition to TypeScript files. This leads to the result that more files are loaded which can, in some cases, blow up the machine."]}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your tsconfig file, check if ",(0,o.jsx)(s.code,{children:"compilerOptions.allowJs"})," is unset or set to false."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'{\n "compilerOptions": {\n "allowJs": false,\n }\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your jest configuration, check if the transform property includes only ",(0,o.jsx)(s.code,{children:".ts"})," files for ts-jest. If not, change the regular expression to exclude js files. You can also add the attribute ",(0,o.jsx)(s.code,{children:"isolatedModules: true"})," for ts-jest to disable type checking for tests."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-diff",children:"module.exports = {\n ...\n 'transform': {\n- '^.+\\\\.(t|j)s$': ['ts-jest', {}],\n+ '^.+\\\\.ts$': ['ts-jest', { isolatedModules: true }],\n },\n};\n"})}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://github.com/kulshekhar/ts-jest/issues/4294",children:"here"})]})]})}function u(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,o.jsx)(s,{...e,children:(0,o.jsx)(c,{...e})}):c(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>r,x:()=>l});var t=n(6540);const o={},i=t.createContext(o);function r(e){const s=t.useContext(i);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function l(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),t.createElement(i.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8629],{5035:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>d,contentTitle:()=>l,default:()=>u,frontMatter:()=>r,metadata:()=>t,toc:()=>a});const t=JSON.parse('{"id":"guides/troubleshooting","title":"Troubleshooting","description":"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them.","source":"@site/versioned_docs/version-29.0/guides/troubleshooting.md","sourceDirName":"guides","slug":"/guides/troubleshooting","permalink":"/ts-jest/docs/29.0/guides/troubleshooting","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/guides/troubleshooting.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"troubleshooting","title":"Troubleshooting"},"sidebar":"version-29.0-docs","previous":{"title":"Using with React Native","permalink":"/ts-jest/docs/29.0/guides/react-native"},"next":{"title":"Using with monorepo","permalink":"/ts-jest/docs/29.0/guides/using-with-monorepo"}}');var o=n(4848),i=n(8453);const r={id:"troubleshooting",title:"Troubleshooting"},l=void 0,d={},a=[{value:"Running ts-jest on CI tools",id:"running-ts-jest-on-ci-tools",level:2},{value:"PROBLEM",id:"problem",level:3},{value:"SOLUTION",id:"solution",level:3},{value:"Transform (node)-module explicitly",id:"transform-node-module-explicitly",level:2},{value:"PROBLEM",id:"problem-1",level:3},{value:"SOLUTION",id:"solution-1",level:3},{value:"Tests gets stuck when importing a dependency",id:"tests-gets-stuck-when-importing-a-dependency",level:2},{value:"PROBLEM",id:"problem-2",level:3},{value:"SOLUTION",id:"solution-2",level:3}];function c(e){const s={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(s.p,{children:"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them."}),"\n",(0,o.jsxs)(s.p,{children:["Please also check Jest ",(0,o.jsx)(s.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," if your issue is related to jest."]}),"\n",(0,o.jsx)(s.h2,{id:"running-ts-jest-on-ci-tools",children:"Running ts-jest on CI tools"}),"\n",(0,o.jsx)(s.h3,{id:"problem",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:'Cannot find module "" from ""'}),"\n",(0,o.jsx)(s.h3,{id:"solution",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check if ",(0,o.jsx)(s.code,{children:"rootDir"})," is referenced correctly. If not add this on your existing jest configuration."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n roots: [""]\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module directories are included on your jest configuration. If not add this on your existing jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleDirectories: ["node_modules",""],\n modulePaths: [""],\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module name is properly mapped and can be referenced by jest. If not, you can define moduleNameMapper for your jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleNameMapper: {\n "": "/",\n },\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check github folder names if its identical to you local folder names. Sometimes github never updates your folder names even if you rename it locally. If this happens rename your folders via github or use this command ",(0,o.jsx)(s.code,{children:"git mv "})," and commit changes."]}),"\n"]}),"\n",(0,o.jsx)(s.h2,{id:"transform-node-module-explicitly",children:"Transform (node)-module explicitly"}),"\n",(0,o.jsx)(s.h3,{id:"problem-1",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"SyntaxError: Cannot use import statement outside a module"}),"\n",(0,o.jsx)(s.h3,{id:"solution-1",children:"SOLUTION"}),"\n",(0,o.jsx)(s.p,{children:"One of the node modules hasn't the correct syntax for Jests execution step. It needs to\nbe transformed first."}),"\n",(0,o.jsx)(s.p,{children:"There is a good chance that the error message shows which module is affected:"}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-shell",children:' SyntaxError: Cannot use import statement outside a module\n > 22 | import Component from "../../node_modules/some-module/lib";\n | ^\n'})}),"\n",(0,o.jsxs)(s.p,{children:["In this case ",(0,o.jsx)(s.strong,{children:"some-module"})," is the problem and needs to be transformed.\nBy adding the following line to the configuration file it will tell Jest which modules\nshouldnt be ignored during the transformation step:"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n transformIgnorePatterns: ["node_modules/(?!(some-module|another-module))"]\n};\n'})}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.strong,{children:"some-module"})," and ",(0,o.jsx)(s.strong,{children:"another-module"})," will be transformed."]}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/63389757/jest-unit-test-syntaxerror-cannot-use-import-statement-outside-a-module",children:"here"})," and ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/52035066/how-to-write-jest-transformignorepatterns",children:"here"}),"."]}),"\n",(0,o.jsx)(s.h2,{id:"tests-gets-stuck-when-importing-a-dependency",children:"Tests gets stuck when importing a dependency"}),"\n",(0,o.jsx)(s.h3,{id:"problem-2",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"Without cache, jest takes an extremely long time to process files and appears to be stuck."}),"\n",(0,o.jsx)(s.h3,{id:"solution-2",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.code,{children:"ts-jest"})," internally uses TypeScript compiler API to transform ts/js file into js file. The recommendation is to only transform what is needed."]}),"\n",(0,o.jsxs)(s.p,{children:["A possible cause for that issue is that you may have enabled ",(0,o.jsx)(s.code,{children:"ts-jest"})," to process javascript files in addition to TypeScript files. This leads to the result that more files are loaded which can, in some cases, blow up the machine."]}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your tsconfig file, check if ",(0,o.jsx)(s.code,{children:"compilerOptions.allowJs"})," is unset or set to false."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'{\n "compilerOptions": {\n "allowJs": false,\n }\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your jest configuration, check if the transform property includes only ",(0,o.jsx)(s.code,{children:".ts"})," files for ts-jest. If not, change the regular expression to exclude js files. You can also add the attribute ",(0,o.jsx)(s.code,{children:"isolatedModules: true"})," for ts-jest to disable type checking for tests."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-diff",children:"module.exports = {\n ...\n 'transform': {\n- '^.+\\\\.(t|j)s$': ['ts-jest', {}],\n+ '^.+\\\\.ts$': ['ts-jest', { isolatedModules: true }],\n },\n};\n"})}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://github.com/kulshekhar/ts-jest/issues/4294",children:"here"})]})]})}function u(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,o.jsx)(s,{...e,children:(0,o.jsx)(c,{...e})}):c(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>r,x:()=>l});var t=n(6540);const o={},i=t.createContext(o);function r(e){const s=t.useContext(i);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function l(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),t.createElement(i.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/8b622911.ec34731d.js b/assets/js/8b622911.633e729a.js similarity index 98% rename from assets/js/8b622911.ec34731d.js rename to assets/js/8b622911.633e729a.js index f1bede58ec..e0afd14e88 100644 --- a/assets/js/8b622911.ec34731d.js +++ b/assets/js/8b622911.633e729a.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1268],{8119:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>r,contentTitle:()=>l,default:()=>p,frontMatter:()=>c,metadata:()=>o,toc:()=>a});const o=JSON.parse('{"id":"getting-started/options/tsconfig","title":"TypeScript Config option","description":"The tsconfig option allows you to define which tsconfig JSON file to use. An inline compiler options object can also be specified instead of a file path.","source":"@site/versioned_docs/version-27.1/getting-started/options/tsconfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/tsconfig","permalink":"/ts-jest/docs/27.1/getting-started/options/tsconfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/options/tsconfig.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"TypeScript Config option"}}');var s=t(4848),i=t(8453);const c={title:"TypeScript Config option"},l=void 0,r={},a=[{value:"Examples",id:"examples",level:3},{value:"Path to a tsconfig file",id:"path-to-a-tsconfig-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4},{value:"Disable auto-lookup",id:"disable-auto-lookup",level:4}];function d(e){const n={a:"a",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"tsconfig"})," option allows you to define which ",(0,s.jsx)(n.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,s.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," object can also be specified instead of a file path."]}),"\n",(0,s.jsxs)(n.p,{children:["By default ",(0,s.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,s.jsx)(n.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,s.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,s.jsx)(n.code,{children:"ES2015"})," is used as ",(0,s.jsx)(n.code,{children:"target"})," instead of ",(0,s.jsx)(n.code,{children:"ES5"}),"."]}),"\n",(0,s.jsxs)(n.p,{children:["If you need to use defaults and force ",(0,s.jsx)(n.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,s.jsx)(n.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,s.jsx)(n.code,{children:"false"}),"."]}),"\n",(0,s.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,s.jsxs)(n.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,s.jsx)(n.code,{children:"tsconfig"})," file"]}),"\n",(0,s.jsxs)(n.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,s.jsx)(n.code,{children:""})," in the path to start from the project root dir."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n tsconfig: 'tsconfig.test.json',\n },\n },\n}\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "tsconfig": "tsconfig.test.json"\n }\n }\n }\n}\n'})}),"\n",(0,s.jsx)(n.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,s.jsxs)(n.p,{children:["Refer to the TypeScript ",(0,s.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," for reference.\nIt's basically the same object you'd put in your ",(0,s.jsx)(n.code,{children:"tsconfig.json"}),"'s ",(0,s.jsx)(n.code,{children:"compilerOptions"}),"."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n tsconfig: {\n importHelpers: true,\n },\n },\n },\n}\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "tsconfig": {\n "importHelpers": true\n }\n }\n }\n }\n}\n'})}),"\n",(0,s.jsx)(n.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,s.jsxs)(n.p,{children:["By default ",(0,s.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,s.jsx)(n.code,{children:"tsconfig.json"})," in your project. But you may not want to use it at all and keep TypeScript default options. You can achieve this by setting ",(0,s.jsx)(n.code,{children:"tsconfig"})," to ",(0,s.jsx)(n.code,{children:"false"}),"."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n tsconfig: false,\n },\n },\n}\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "tsconfig": false\n }\n }\n }\n}\n'})})]})}function p(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>c,x:()=>l});var o=t(6540);const s={},i=o.createContext(s);function c(e){const n=o.useContext(i);return o.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:c(e.components),o.createElement(i.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1268],{8119:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>r,contentTitle:()=>l,default:()=>p,frontMatter:()=>c,metadata:()=>o,toc:()=>a});const o=JSON.parse('{"id":"getting-started/options/tsconfig","title":"TypeScript Config option","description":"The tsconfig option allows you to define which tsconfig JSON file to use. An inline compiler options object can also be specified instead of a file path.","source":"@site/versioned_docs/version-27.1/getting-started/options/tsconfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/tsconfig","permalink":"/ts-jest/docs/27.1/getting-started/options/tsconfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/options/tsconfig.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"TypeScript Config option"}}');var s=t(4848),i=t(8453);const c={title:"TypeScript Config option"},l=void 0,r={},a=[{value:"Examples",id:"examples",level:3},{value:"Path to a tsconfig file",id:"path-to-a-tsconfig-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4},{value:"Disable auto-lookup",id:"disable-auto-lookup",level:4}];function d(e){const n={a:"a",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"tsconfig"})," option allows you to define which ",(0,s.jsx)(n.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,s.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," object can also be specified instead of a file path."]}),"\n",(0,s.jsxs)(n.p,{children:["By default ",(0,s.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,s.jsx)(n.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,s.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,s.jsx)(n.code,{children:"ES2015"})," is used as ",(0,s.jsx)(n.code,{children:"target"})," instead of ",(0,s.jsx)(n.code,{children:"ES5"}),"."]}),"\n",(0,s.jsxs)(n.p,{children:["If you need to use defaults and force ",(0,s.jsx)(n.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,s.jsx)(n.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,s.jsx)(n.code,{children:"false"}),"."]}),"\n",(0,s.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,s.jsxs)(n.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,s.jsx)(n.code,{children:"tsconfig"})," file"]}),"\n",(0,s.jsxs)(n.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,s.jsx)(n.code,{children:""})," in the path to start from the project root dir."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n tsconfig: 'tsconfig.test.json',\n },\n },\n}\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "tsconfig": "tsconfig.test.json"\n }\n }\n }\n}\n'})}),"\n",(0,s.jsx)(n.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,s.jsxs)(n.p,{children:["Refer to the TypeScript ",(0,s.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," for reference.\nIt's basically the same object you'd put in your ",(0,s.jsx)(n.code,{children:"tsconfig.json"}),"'s ",(0,s.jsx)(n.code,{children:"compilerOptions"}),"."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n tsconfig: {\n importHelpers: true,\n },\n },\n },\n}\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "tsconfig": {\n "importHelpers": true\n }\n }\n }\n }\n}\n'})}),"\n",(0,s.jsx)(n.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,s.jsxs)(n.p,{children:["By default ",(0,s.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,s.jsx)(n.code,{children:"tsconfig.json"})," in your project. But you may not want to use it at all and keep TypeScript default options. You can achieve this by setting ",(0,s.jsx)(n.code,{children:"tsconfig"})," to ",(0,s.jsx)(n.code,{children:"false"}),"."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n tsconfig: false,\n },\n },\n}\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "tsconfig": false\n }\n }\n }\n}\n'})})]})}function p(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>c,x:()=>l});var o=t(6540);const s={},i=o.createContext(s);function c(e){const n=o.useContext(i);return o.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:c(e.components),o.createElement(i.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/8cf61ec4.18a24356.js b/assets/js/8cf61ec4.a78c37c1.js similarity index 98% rename from assets/js/8cf61ec4.18a24356.js rename to assets/js/8cf61ec4.a78c37c1.js index 3d07f3159c..6fc4a6d2a0 100644 --- a/assets/js/8cf61ec4.18a24356.js +++ b/assets/js/8cf61ec4.a78c37c1.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5799],{3977:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>h,frontMatter:()=>l,metadata:()=>n,toc:()=>c});const n=JSON.parse('{"id":"getting-started/options/isolatedModules","title":"Isolated Modules option","description":"By default ts-jest uses TypeScript compiler in the context of a project (yours), with full type-checking and features.","source":"@site/versioned_docs/version-27.0/getting-started/options/isolatedModules.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/isolatedModules","permalink":"/ts-jest/docs/27.0/getting-started/options/isolatedModules","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/options/isolatedModules.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Isolated Modules option"}}');var o=s(4848),i=s(8453);const l={title:"Isolated Modules option"},a=void 0,d={},c=[{value:"Example",id:"example",level:3},{value:"Performance",id:"performance",level:2},{value:"Example",id:"example-1",level:3},{value:"Caveats",id:"caveats",level:2}];function r(e){const t={code:"code",h2:"h2",h3:"h3",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["By default ",(0,o.jsx)(t.code,{children:"ts-jest"})," uses TypeScript compiler in the context of a project (yours), with full type-checking and features.\nBut it can also be used to compile each file separately, what TypeScript calls an 'isolated module'.\nThat's what the ",(0,o.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,o.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,o.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,o.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,o.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,o.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n isolatedModules: true,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "isolatedModules": true\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,o.jsxs)(t.p,{children:["Using ",(0,o.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,o.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,o.jsx)(t.code,{children:"include"})," in ",(0,o.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,o.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,o.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,o.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,o.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,o.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,o.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,o.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,o.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,o.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,o.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function h(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(r,{...e})}):r(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>l,x:()=>a});var n=s(6540);const o={},i=n.createContext(o);function l(e){const t=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:l(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5799],{3977:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>h,frontMatter:()=>l,metadata:()=>n,toc:()=>c});const n=JSON.parse('{"id":"getting-started/options/isolatedModules","title":"Isolated Modules option","description":"By default ts-jest uses TypeScript compiler in the context of a project (yours), with full type-checking and features.","source":"@site/versioned_docs/version-27.0/getting-started/options/isolatedModules.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/isolatedModules","permalink":"/ts-jest/docs/27.0/getting-started/options/isolatedModules","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/options/isolatedModules.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Isolated Modules option"}}');var o=s(4848),i=s(8453);const l={title:"Isolated Modules option"},a=void 0,d={},c=[{value:"Example",id:"example",level:3},{value:"Performance",id:"performance",level:2},{value:"Example",id:"example-1",level:3},{value:"Caveats",id:"caveats",level:2}];function r(e){const t={code:"code",h2:"h2",h3:"h3",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["By default ",(0,o.jsx)(t.code,{children:"ts-jest"})," uses TypeScript compiler in the context of a project (yours), with full type-checking and features.\nBut it can also be used to compile each file separately, what TypeScript calls an 'isolated module'.\nThat's what the ",(0,o.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,o.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,o.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,o.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,o.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,o.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n isolatedModules: true,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "isolatedModules": true\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,o.jsxs)(t.p,{children:["Using ",(0,o.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,o.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,o.jsx)(t.code,{children:"include"})," in ",(0,o.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,o.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,o.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,o.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,o.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,o.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,o.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,o.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,o.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,o.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,o.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function h(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(r,{...e})}):r(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>l,x:()=>a});var n=s(6540);const o={},i=n.createContext(o);function l(e){const t=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:l(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/8d536cde.a8645fee.js b/assets/js/8d536cde.26af3277.js similarity index 98% rename from assets/js/8d536cde.a8645fee.js rename to assets/js/8d536cde.26af3277.js index 402dd2fff7..5eeeb35758 100644 --- a/assets/js/8d536cde.a8645fee.js +++ b/assets/js/8d536cde.26af3277.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8979],{102:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>d,frontMatter:()=>r,metadata:()=>n,toc:()=>h});const n=JSON.parse('{"id":"contributing","title":"Contributing","description":"When contributing to this repository, please first discuss the change you wish to make via ts-jest GitHub discussion or issue with the owners of this repository before making a change.","source":"@site/versioned_docs/version-28.0/contributing.md","sourceDirName":".","slug":"/contributing","permalink":"/ts-jest/docs/28.0/contributing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/contributing.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"contributing","title":"Contributing"},"sidebar":"version-28.0-docs","previous":{"title":"Processing flow","permalink":"/ts-jest/docs/28.0/processing"},"next":{"title":"Installation","permalink":"/ts-jest/docs/28.0/getting-started/installation"}}');var i=s(4848),o=s(8453);const r={id:"contributing",title:"Contributing"},c=void 0,a={},h=[{value:"Pull Request Process",id:"pull-request-process",level:2},{value:"E2E Testing",id:"e2e-testing",level:2},{value:"Preparing",id:"preparing",level:3},{value:"Running",id:"running",level:3}];function l(e){const t={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,i.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,i.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,i.jsx)(t.a,{href:"https://github.com/kulshekhar/ts-jest/issues",children:"issue"})," with the owners of this repository before making a change."]}),"\n",(0,i.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,i.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,i.jsxs)(t.ol,{children:["\n",(0,i.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,i.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,i.jsxs)(t.li,{children:["Update the ",(0,i.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,i.jsx)(t.li,{children:"If possible, squash your commits. There must be only one commit in your PR (until a review). Then after each review requesting changes, DO NOT squash your commits with the one before the review, so that we can see intermediate modifications."}),"\n",(0,i.jsx)(t.li,{children:"You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you."}),"\n"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,i.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,i.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,i.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,i.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,i.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLBBRgGm4BpxA-eMEAmYxH6EEUrNW0StG--ODh9xGkQotnxP32D6YQ8z8L5TZovtKXlLcEPq5US9cdxzfQIjaQ24oET9pShUutHbxtOO9nf390oHhBASeHDXKp0a3fbiJ5DWWjAyO0tn0iVnIRcdt_Jwh-iow3XswJPxbalNzSZV10rWDVGnqA88WhS_87dd66GcqNGmMoVsX6eC4MI7gPXwgrGV_VQV2JOIMB07U01TzzeVL7b4jMClwLw2uqY3XdYhyzw2YZuuQQfDi_AIUr3q4XnrSt1NJwdVzYQV29K4nMD-AwZDXZpcmi9omyYU4iOOPXoi7SUjZKEATWkusE5YpmGVXajXVyaLoJhCfDPPjQqn0F0ZSx89msJbJAukqq0JQGxlzErg-uWiCrYIMkzHXOY1w-_1nnsLcxdFb89Auq_eJvd-JpDJvKMVsLldHMMDh8JhugpIKqzVd-p-KYJkVd0k2DN6D2N1uxnouRVMcAHX-GG0"}),"\n",(0,i.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,i.jsxs)(t.p,{children:["When a test-case needs to be run with a given template within tests, here is what's happening (in ",(0,i.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/hLHDRzim3BthLn3OOGcsfC2E3R2TUzfFI1I9ZjN8f23IJOAX--s3PBknksAdtGoQ7-yzFahKPZNcqMMqYd3XV0OVyiuGAq8EfrRDatwE4Ou8FZGDPYI5X1aKHJVE2XfBVenqAPOsHoj1jWR9G-bZDjy1l-73x_s-3F0Xx-NMnK3d_VxXrrJrMZx7bgyxOq83gzOAM23skE_Ozn6beFkn1csHO7L3MPl7iTSYRIGGiL5ZNpXuoBZ9FL6W4r3g892eZT4qd06jQoiTABEXq9b0xUuaC0h2YdXTGg4fed6wGHCAgYPpDokQgMTZ77C2tHNo8OFDQ1odW1wKP_Ed9HYyEamAXpcnGu5d3icwiptX9h8xRv-5wN07QYvjY0YhDsfb_31z6k53NbU1Wu2GJTAork27mjuDKVMS2kekq2ddW5BOm5Y0tYm82VVP3Po5GLkhfa_UQjc5jjZ1XVleeSO6e2sQiQZXw37FoDKrZD2VKNJhc9fmsZxB0dp9MFw68D3qv3GmlNEGAqkw16qXsUflnwH8kd1HZ7mHQBZiHOi5wFGFSmm1rXPpdS3fzYzRBAKoeprWPe_sFnXZm8RagqFkPoy9NR0Ze0LCuUxTxm5NhQjhRYtvYD0odwiwW5VRfLZFo9ooFS8XPNOeibeVuEbdpIatK6WaT6hBGcI6yd4qmaYbibY2GWKBhXVb3ewzGXEkw85iDxn5BvWbC1LbvptANRYssA0IQe8RXJLt_R-ydUWCq2VbpYe_vdvObUp-lh7fADQb_weB8iNTyzr-v8AXosLsESjkOgOJktq5makyJTBFKW81CG5UWzIJAkQvX1Y1i7h77D-Cn2-O8P2o6T_Z0ao6LtXwUcUclXibe_QP8AFqiV8NvVG7"})]})}function d(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>r,x:()=>c});var n=s(6540);const i={},o=n.createContext(i);function r(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8979],{102:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>d,frontMatter:()=>r,metadata:()=>n,toc:()=>h});const n=JSON.parse('{"id":"contributing","title":"Contributing","description":"When contributing to this repository, please first discuss the change you wish to make via ts-jest GitHub discussion or issue with the owners of this repository before making a change.","source":"@site/versioned_docs/version-28.0/contributing.md","sourceDirName":".","slug":"/contributing","permalink":"/ts-jest/docs/28.0/contributing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/contributing.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"contributing","title":"Contributing"},"sidebar":"version-28.0-docs","previous":{"title":"Processing flow","permalink":"/ts-jest/docs/28.0/processing"},"next":{"title":"Installation","permalink":"/ts-jest/docs/28.0/getting-started/installation"}}');var i=s(4848),o=s(8453);const r={id:"contributing",title:"Contributing"},c=void 0,a={},h=[{value:"Pull Request Process",id:"pull-request-process",level:2},{value:"E2E Testing",id:"e2e-testing",level:2},{value:"Preparing",id:"preparing",level:3},{value:"Running",id:"running",level:3}];function l(e){const t={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,i.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,i.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,i.jsx)(t.a,{href:"https://github.com/kulshekhar/ts-jest/issues",children:"issue"})," with the owners of this repository before making a change."]}),"\n",(0,i.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,i.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,i.jsxs)(t.ol,{children:["\n",(0,i.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,i.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,i.jsxs)(t.li,{children:["Update the ",(0,i.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,i.jsx)(t.li,{children:"If possible, squash your commits. There must be only one commit in your PR (until a review). Then after each review requesting changes, DO NOT squash your commits with the one before the review, so that we can see intermediate modifications."}),"\n",(0,i.jsx)(t.li,{children:"You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you."}),"\n"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,i.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,i.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,i.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,i.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,i.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLBBRgGm4BpxA-eMEAmYxH6EEUrNW0StG--ODh9xGkQotnxP32D6YQ8z8L5TZovtKXlLcEPq5US9cdxzfQIjaQ24oET9pShUutHbxtOO9nf390oHhBASeHDXKp0a3fbiJ5DWWjAyO0tn0iVnIRcdt_Jwh-iow3XswJPxbalNzSZV10rWDVGnqA88WhS_87dd66GcqNGmMoVsX6eC4MI7gPXwgrGV_VQV2JOIMB07U01TzzeVL7b4jMClwLw2uqY3XdYhyzw2YZuuQQfDi_AIUr3q4XnrSt1NJwdVzYQV29K4nMD-AwZDXZpcmi9omyYU4iOOPXoi7SUjZKEATWkusE5YpmGVXajXVyaLoJhCfDPPjQqn0F0ZSx89msJbJAukqq0JQGxlzErg-uWiCrYIMkzHXOY1w-_1nnsLcxdFb89Auq_eJvd-JpDJvKMVsLldHMMDh8JhugpIKqzVd-p-KYJkVd0k2DN6D2N1uxnouRVMcAHX-GG0"}),"\n",(0,i.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,i.jsxs)(t.p,{children:["When a test-case needs to be run with a given template within tests, here is what's happening (in ",(0,i.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/hLHDRzim3BthLn3OOGcsfC2E3R2TUzfFI1I9ZjN8f23IJOAX--s3PBknksAdtGoQ7-yzFahKPZNcqMMqYd3XV0OVyiuGAq8EfrRDatwE4Ou8FZGDPYI5X1aKHJVE2XfBVenqAPOsHoj1jWR9G-bZDjy1l-73x_s-3F0Xx-NMnK3d_VxXrrJrMZx7bgyxOq83gzOAM23skE_Ozn6beFkn1csHO7L3MPl7iTSYRIGGiL5ZNpXuoBZ9FL6W4r3g892eZT4qd06jQoiTABEXq9b0xUuaC0h2YdXTGg4fed6wGHCAgYPpDokQgMTZ77C2tHNo8OFDQ1odW1wKP_Ed9HYyEamAXpcnGu5d3icwiptX9h8xRv-5wN07QYvjY0YhDsfb_31z6k53NbU1Wu2GJTAork27mjuDKVMS2kekq2ddW5BOm5Y0tYm82VVP3Po5GLkhfa_UQjc5jjZ1XVleeSO6e2sQiQZXw37FoDKrZD2VKNJhc9fmsZxB0dp9MFw68D3qv3GmlNEGAqkw16qXsUflnwH8kd1HZ7mHQBZiHOi5wFGFSmm1rXPpdS3fzYzRBAKoeprWPe_sFnXZm8RagqFkPoy9NR0Ze0LCuUxTxm5NhQjhRYtvYD0odwiwW5VRfLZFo9ooFS8XPNOeibeVuEbdpIatK6WaT6hBGcI6yd4qmaYbibY2GWKBhXVb3ewzGXEkw85iDxn5BvWbC1LbvptANRYssA0IQe8RXJLt_R-ydUWCq2VbpYe_vdvObUp-lh7fADQb_weB8iNTyzr-v8AXosLsESjkOgOJktq5makyJTBFKW81CG5UWzIJAkQvX1Y1i7h77D-Cn2-O8P2o6T_Z0ao6LtXwUcUclXibe_QP8AFqiV8NvVG7"})]})}function d(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>r,x:()=>c});var n=s(6540);const i={},o=n.createContext(i);function r(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/8e5d45d9.93e6e394.js b/assets/js/8e5d45d9.849fbe21.js similarity index 97% rename from assets/js/8e5d45d9.93e6e394.js rename to assets/js/8e5d45d9.849fbe21.js index 06d3a1d222..997395afb7 100644 --- a/assets/js/8e5d45d9.93e6e394.js +++ b/assets/js/8e5d45d9.849fbe21.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7425],{2261:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>n,toc:()=>a});const n=JSON.parse('{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","source":"@site/versioned_docs/version-29.0/introduction.md","sourceDirName":".","slug":"/","permalink":"/ts-jest/docs/29.0/","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/introduction.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","slug":"/"},"sidebar":"version-29.0-docs","next":{"title":"Processing flow","permalink":"/ts-jest/docs/29.0/processing"}}');var o=s(4848),r=s(8453);const i={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},c=void 0,d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,r.R)(),...t.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(e.p,{children:[(0,o.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,o.jsx)(e.a,{href:"https://jestjs.io/docs/next/code-transformation#writing-custom-transformers",children:"transformer"})," with source map support that lets you use Jest to test projects written in TypeScript."]}),"\n",(0,o.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,o.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,o.jsx)(e.code,{children:"preset-typescript"})," ",(0,o.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,o.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,o.jsx)(e.admonition,{type:"important",children:(0,o.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,o.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,o.jsx)(e.code,{children:'npm i -D ts-jest@"<23.10.0"'})," to go back to the previous version"]})})]})}function u(t={}){const{wrapper:e}={...(0,r.R)(),...t.components};return e?(0,o.jsx)(e,{...t,children:(0,o.jsx)(p,{...t})}):p(t)}},8453:(t,e,s)=>{s.d(e,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(t){const e=n.useContext(r);return n.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function c(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:i(t.components),n.createElement(r.Provider,{value:e},t.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7425],{2261:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>n,toc:()=>a});const n=JSON.parse('{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","source":"@site/versioned_docs/version-29.0/introduction.md","sourceDirName":".","slug":"/","permalink":"/ts-jest/docs/29.0/","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/introduction.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","slug":"/"},"sidebar":"version-29.0-docs","next":{"title":"Processing flow","permalink":"/ts-jest/docs/29.0/processing"}}');var o=s(4848),r=s(8453);const i={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},c=void 0,d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,r.R)(),...t.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(e.p,{children:[(0,o.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,o.jsx)(e.a,{href:"https://jestjs.io/docs/next/code-transformation#writing-custom-transformers",children:"transformer"})," with source map support that lets you use Jest to test projects written in TypeScript."]}),"\n",(0,o.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,o.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,o.jsx)(e.code,{children:"preset-typescript"})," ",(0,o.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,o.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,o.jsx)(e.admonition,{type:"important",children:(0,o.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,o.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,o.jsx)(e.code,{children:'npm i -D ts-jest@"<23.10.0"'})," to go back to the previous version"]})})]})}function u(t={}){const{wrapper:e}={...(0,r.R)(),...t.components};return e?(0,o.jsx)(e,{...t,children:(0,o.jsx)(p,{...t})}):p(t)}},8453:(t,e,s)=>{s.d(e,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(t){const e=n.useContext(r);return n.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function c(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:i(t.components),n.createElement(r.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/8e81f9bb.a7990d5d.js b/assets/js/8e81f9bb.d4682633.js similarity index 99% rename from assets/js/8e81f9bb.a7990d5d.js rename to assets/js/8e81f9bb.d4682633.js index 398e777e99..7a06346708 100644 --- a/assets/js/8e81f9bb.a7990d5d.js +++ b/assets/js/8e81f9bb.d4682633.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8192],{1172:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>d,default:()=>j,frontMatter:()=>r,metadata:()=>t,toc:()=>l});const t=JSON.parse('{"id":"getting-started/options","title":"Options","description":"Introduction","source":"@site/versioned_docs/version-28.0/getting-started/options.md","sourceDirName":"getting-started","slug":"/getting-started/options","permalink":"/ts-jest/docs/28.0/getting-started/options","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/options.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"options","title":"Options"},"sidebar":"version-28.0-docs","previous":{"title":"Presets","permalink":"/ts-jest/docs/28.0/getting-started/presets"},"next":{"title":"Paths mapping","permalink":"/ts-jest/docs/28.0/getting-started/paths-mapping"}}');var i=n(4848),o=n(8453);const r={id:"options",title:"Options"},d=void 0,c={},l=[{value:"Introduction",id:"introduction",level:3},{value:"Options",id:"options",level:3}];function h(e){const s={a:"a",admonition:"admonition",code:"code",em:"em",h3:"h3",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(s.h3,{id:"introduction",children:"Introduction"}),"\n",(0,i.jsxs)(s.p,{children:["All ",(0,i.jsx)(s.code,{children:"ts-jest"})," specific options are located under the ",(0,i.jsx)(s.code,{children:"globals"})," of Jest config object in the ",(0,i.jsx)(s.code,{children:"package.json"})," file of your project,\nor through a ",(0,i.jsx)(s.code,{children:"jest.config.js"}),", or ",(0,i.jsx)(s.code,{children:"jest.config.ts"})," file."]}),"\n",(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n // ts-jest configuration goes here\n }\n }\n }\n}\n'})}),"\n",(0,i.jsx)(s.p,{children:"Or through JavaScript:"}),"\n",(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n // ts-jest configuration goes here\n },\n },\n}\n"})}),"\n",(0,i.jsxs)(s.admonition,{type:"tip",children:[(0,i.jsxs)(s.p,{children:["To utilize IDE suggestions, you can use ",(0,i.jsx)(s.code,{children:"JSDoc"})," comments to provide suggested ",(0,i.jsx)(s.code,{children:"ts-jest"})," configs for your Jest config:"]}),(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",children:"// jest.config.js\n/** @type {import('ts-jest').InitialOptionsTsJest} */\nmodule.exports = config = {\n // [...]\n globals: {\n 'ts-jest': {\n // ts-jest configuration goes here and your IDE will suggest which configs when typing\n },\n },\n}\n"})})]}),"\n",(0,i.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,i.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport type { InitialOptionsTsJest } from 'ts-jest'\n\nconst config: InitialOptionsTsJest = {\n globals: {\n 'ts-jest': {\n // ts-jest configuration goes here\n },\n },\n}\nexport default config\n"})}),"\n",(0,i.jsx)(s.admonition,{type:"important",children:(0,i.jsxs)(s.p,{children:["When using TypeScript Jest config file, Jest will use ",(0,i.jsx)(s.code,{children:"ts-node"})," to compile the config file. ",(0,i.jsx)(s.code,{children:"ts-jest"})," doesn't take part in\nthat process."]})}),"\n",(0,i.jsx)(s.h3,{id:"options",children:"Options"}),"\n",(0,i.jsx)(s.p,{children:"All options have default values which should fit most of the projects. Click on the option's name to see details and example(s)."}),"\n",(0,i.jsxs)(s.table,{children:[(0,i.jsx)(s.thead,{children:(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.th,{children:"Option"}),(0,i.jsx)(s.th,{children:"Description"}),(0,i.jsx)(s.th,{children:"Type"}),(0,i.jsx)(s.th,{children:"Default"})]})}),(0,i.jsxs)(s.tbody,{children:[(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/compiler",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"compiler"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"string"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:'"typescript"'})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/tsconfig",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"tsconfig"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"string"}),"|",(0,i.jsx)(s.code,{children:"object"}),"|",(0,i.jsx)(s.code,{children:"boolean"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"auto"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/isolatedModules",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"isolatedModules"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"boolean"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"disabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/astTransformers",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"astTransformers"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"object"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"auto"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/diagnostics",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"diagnostics"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"boolean"}),"|",(0,i.jsx)(s.code,{children:"object"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"enabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/babelConfig",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"babelConfig"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"boolean"}),"|",(0,i.jsx)(s.code,{children:"string"}),"|",(0,i.jsx)(s.code,{children:"object"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"disabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"stringifyContentPathRegex"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"string"}),"|",(0,i.jsx)(s.code,{children:"RegExp"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"disabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/useESM",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"useESM"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/useESM",children:"Enable ESM support"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"boolean"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"auto"})})]})]})]})]})}function j(e={}){const{wrapper:s}={...(0,o.R)(),...e.components};return s?(0,i.jsx)(s,{...e,children:(0,i.jsx)(h,{...e})}):h(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>r,x:()=>d});var t=n(6540);const i={},o=t.createContext(i);function r(e){const s=t.useContext(o);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function d(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),t.createElement(o.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8192],{1172:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>d,default:()=>j,frontMatter:()=>r,metadata:()=>t,toc:()=>l});const t=JSON.parse('{"id":"getting-started/options","title":"Options","description":"Introduction","source":"@site/versioned_docs/version-28.0/getting-started/options.md","sourceDirName":"getting-started","slug":"/getting-started/options","permalink":"/ts-jest/docs/28.0/getting-started/options","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/options.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"options","title":"Options"},"sidebar":"version-28.0-docs","previous":{"title":"Presets","permalink":"/ts-jest/docs/28.0/getting-started/presets"},"next":{"title":"Paths mapping","permalink":"/ts-jest/docs/28.0/getting-started/paths-mapping"}}');var i=n(4848),o=n(8453);const r={id:"options",title:"Options"},d=void 0,c={},l=[{value:"Introduction",id:"introduction",level:3},{value:"Options",id:"options",level:3}];function h(e){const s={a:"a",admonition:"admonition",code:"code",em:"em",h3:"h3",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(s.h3,{id:"introduction",children:"Introduction"}),"\n",(0,i.jsxs)(s.p,{children:["All ",(0,i.jsx)(s.code,{children:"ts-jest"})," specific options are located under the ",(0,i.jsx)(s.code,{children:"globals"})," of Jest config object in the ",(0,i.jsx)(s.code,{children:"package.json"})," file of your project,\nor through a ",(0,i.jsx)(s.code,{children:"jest.config.js"}),", or ",(0,i.jsx)(s.code,{children:"jest.config.ts"})," file."]}),"\n",(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n // ts-jest configuration goes here\n }\n }\n }\n}\n'})}),"\n",(0,i.jsx)(s.p,{children:"Or through JavaScript:"}),"\n",(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n // ts-jest configuration goes here\n },\n },\n}\n"})}),"\n",(0,i.jsxs)(s.admonition,{type:"tip",children:[(0,i.jsxs)(s.p,{children:["To utilize IDE suggestions, you can use ",(0,i.jsx)(s.code,{children:"JSDoc"})," comments to provide suggested ",(0,i.jsx)(s.code,{children:"ts-jest"})," configs for your Jest config:"]}),(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",children:"// jest.config.js\n/** @type {import('ts-jest').InitialOptionsTsJest} */\nmodule.exports = config = {\n // [...]\n globals: {\n 'ts-jest': {\n // ts-jest configuration goes here and your IDE will suggest which configs when typing\n },\n },\n}\n"})})]}),"\n",(0,i.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,i.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport type { InitialOptionsTsJest } from 'ts-jest'\n\nconst config: InitialOptionsTsJest = {\n globals: {\n 'ts-jest': {\n // ts-jest configuration goes here\n },\n },\n}\nexport default config\n"})}),"\n",(0,i.jsx)(s.admonition,{type:"important",children:(0,i.jsxs)(s.p,{children:["When using TypeScript Jest config file, Jest will use ",(0,i.jsx)(s.code,{children:"ts-node"})," to compile the config file. ",(0,i.jsx)(s.code,{children:"ts-jest"})," doesn't take part in\nthat process."]})}),"\n",(0,i.jsx)(s.h3,{id:"options",children:"Options"}),"\n",(0,i.jsx)(s.p,{children:"All options have default values which should fit most of the projects. Click on the option's name to see details and example(s)."}),"\n",(0,i.jsxs)(s.table,{children:[(0,i.jsx)(s.thead,{children:(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.th,{children:"Option"}),(0,i.jsx)(s.th,{children:"Description"}),(0,i.jsx)(s.th,{children:"Type"}),(0,i.jsx)(s.th,{children:"Default"})]})}),(0,i.jsxs)(s.tbody,{children:[(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/compiler",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"compiler"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"string"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:'"typescript"'})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/tsconfig",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"tsconfig"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"string"}),"|",(0,i.jsx)(s.code,{children:"object"}),"|",(0,i.jsx)(s.code,{children:"boolean"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"auto"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/isolatedModules",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"isolatedModules"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"boolean"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"disabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/astTransformers",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"astTransformers"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"object"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"auto"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/diagnostics",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"diagnostics"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"boolean"}),"|",(0,i.jsx)(s.code,{children:"object"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"enabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/babelConfig",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"babelConfig"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"boolean"}),"|",(0,i.jsx)(s.code,{children:"string"}),"|",(0,i.jsx)(s.code,{children:"object"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"disabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"stringifyContentPathRegex"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"string"}),"|",(0,i.jsx)(s.code,{children:"RegExp"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"disabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/useESM",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"useESM"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/useESM",children:"Enable ESM support"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"boolean"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"auto"})})]})]})]})]})}function j(e={}){const{wrapper:s}={...(0,o.R)(),...e.components};return s?(0,i.jsx)(s,{...e,children:(0,i.jsx)(h,{...e})}):h(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>r,x:()=>d});var t=n(6540);const i={},o=t.createContext(i);function r(e){const s=t.useContext(o);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function d(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),t.createElement(o.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/902acc05.763dfe6c.js b/assets/js/902acc05.f0269b39.js similarity index 98% rename from assets/js/902acc05.763dfe6c.js rename to assets/js/902acc05.f0269b39.js index 174adb5f66..325c5ba2ce 100644 --- a/assets/js/902acc05.763dfe6c.js +++ b/assets/js/902acc05.f0269b39.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8632],{2373:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>l,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>t,toc:()=>a});const t=JSON.parse('{"id":"guides/esm-support","title":"ESM Support","description":"To use ts-jest with ESM support:","source":"@site/versioned_docs/version-27.0/guides/esm-support.md","sourceDirName":"guides","slug":"/guides/esm-support","permalink":"/ts-jest/docs/27.0/guides/esm-support","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/guides/esm-support.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"esm-support","title":"ESM Support"},"sidebar":"version-27.0-docs","previous":{"title":"Version checking","permalink":"/ts-jest/docs/27.0/getting-started/version-checking"},"next":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/27.0/guides/mock-es6-class"}}');var r=n(4848),o=n(8453);const i={id:"esm-support",title:"ESM Support"},c=void 0,l={},a=[{value:"ESM presets",id:"esm-presets",level:3},{value:"Examples",id:"examples",level:3},{value:"Manual configuration",id:"manual-configuration",level:4},{value:"Use ESM presets",id:"use-esm-presets",level:4}];function d(e){const s={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(s.p,{children:["To use ",(0,r.jsx)(s.code,{children:"ts-jest"})," with ESM support:"]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:["Check ",(0,r.jsx)(s.a,{href:"https://jestjs.io/docs/en/ecmascript-modules",children:"ESM Jest documentation"}),"."]}),"\n",(0,r.jsxs)(s.li,{children:["Enable ",(0,r.jsx)(s.a,{href:"../getting-started/options/useESM",children:"useESM"})," ",(0,r.jsx)(s.code,{children:"true"})," for ",(0,r.jsx)(s.code,{children:"ts-jest"})," config."]}),"\n",(0,r.jsxs)(s.li,{children:["Include ",(0,r.jsx)(s.code,{children:".ts"})," in ",(0,r.jsx)(s.a,{href:"https://jestjs.io/docs/en/next/configuration#extensionstotreatasesm-arraystring",children:"extensionsToTreatAsEsm"})," Jest config option."]}),"\n",(0,r.jsxs)(s.li,{children:["Ensure that ",(0,r.jsx)(s.code,{children:"tsconfig"})," has ",(0,r.jsx)(s.code,{children:"module"})," with value for ESM, e.g. ",(0,r.jsx)(s.code,{children:"ES2015"})," or ",(0,r.jsx)(s.code,{children:"ES2020"})," etc..."]}),"\n"]}),"\n",(0,r.jsx)(s.h3,{id:"esm-presets",children:"ESM presets"}),"\n",(0,r.jsxs)(s.p,{children:["There are also ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/27.0/getting-started/presets",children:"3 presets"})," to work with ESM."]}),"\n",(0,r.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,r.jsx)(s.h4,{id:"manual-configuration",children:"Manual configuration"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n extensionsToTreatAsEsm: ['.ts'],\n globals: {\n 'ts-jest': {\n useESM: true,\n },\n },\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n}\n"})}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "extensionsToTreatAsEsm": [".ts"],\n "globals": {\n "ts-jest": {\n "useESM": true\n }\n },\n "moduleNameMapper": {\n "^(\\\\.{1,2}/.*)\\\\.js$": "$1"\n }\n }\n}\n'})}),"\n",(0,r.jsx)(s.h4,{id:"use-esm-presets",children:"Use ESM presets"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n preset: 'ts-jest/presets/default-esm', // or other ESM presets\n globals: {\n 'ts-jest': {\n useESM: true,\n },\n },\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n}\n"})}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "preset": "ts-jest/presets/default-esm", // or other ESM presets,\n "globals": {\n "ts-jest": {\n "useESM": true\n }\n },\n "moduleNameMapper": {\n "^(\\\\.{1,2}/.*)\\\\.js$": "$1"\n }\n }\n}\n'})})]})}function u(e={}){const{wrapper:s}={...(0,o.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(d,{...e})}):d(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>i,x:()=>c});var t=n(6540);const r={},o=t.createContext(r);function i(e){const s=t.useContext(o);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function c(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),t.createElement(o.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8632],{2373:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>l,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>t,toc:()=>a});const t=JSON.parse('{"id":"guides/esm-support","title":"ESM Support","description":"To use ts-jest with ESM support:","source":"@site/versioned_docs/version-27.0/guides/esm-support.md","sourceDirName":"guides","slug":"/guides/esm-support","permalink":"/ts-jest/docs/27.0/guides/esm-support","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/guides/esm-support.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"esm-support","title":"ESM Support"},"sidebar":"version-27.0-docs","previous":{"title":"Version checking","permalink":"/ts-jest/docs/27.0/getting-started/version-checking"},"next":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/27.0/guides/mock-es6-class"}}');var r=n(4848),o=n(8453);const i={id:"esm-support",title:"ESM Support"},c=void 0,l={},a=[{value:"ESM presets",id:"esm-presets",level:3},{value:"Examples",id:"examples",level:3},{value:"Manual configuration",id:"manual-configuration",level:4},{value:"Use ESM presets",id:"use-esm-presets",level:4}];function d(e){const s={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(s.p,{children:["To use ",(0,r.jsx)(s.code,{children:"ts-jest"})," with ESM support:"]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:["Check ",(0,r.jsx)(s.a,{href:"https://jestjs.io/docs/en/ecmascript-modules",children:"ESM Jest documentation"}),"."]}),"\n",(0,r.jsxs)(s.li,{children:["Enable ",(0,r.jsx)(s.a,{href:"../getting-started/options/useESM",children:"useESM"})," ",(0,r.jsx)(s.code,{children:"true"})," for ",(0,r.jsx)(s.code,{children:"ts-jest"})," config."]}),"\n",(0,r.jsxs)(s.li,{children:["Include ",(0,r.jsx)(s.code,{children:".ts"})," in ",(0,r.jsx)(s.a,{href:"https://jestjs.io/docs/en/next/configuration#extensionstotreatasesm-arraystring",children:"extensionsToTreatAsEsm"})," Jest config option."]}),"\n",(0,r.jsxs)(s.li,{children:["Ensure that ",(0,r.jsx)(s.code,{children:"tsconfig"})," has ",(0,r.jsx)(s.code,{children:"module"})," with value for ESM, e.g. ",(0,r.jsx)(s.code,{children:"ES2015"})," or ",(0,r.jsx)(s.code,{children:"ES2020"})," etc..."]}),"\n"]}),"\n",(0,r.jsx)(s.h3,{id:"esm-presets",children:"ESM presets"}),"\n",(0,r.jsxs)(s.p,{children:["There are also ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/27.0/getting-started/presets",children:"3 presets"})," to work with ESM."]}),"\n",(0,r.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,r.jsx)(s.h4,{id:"manual-configuration",children:"Manual configuration"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n extensionsToTreatAsEsm: ['.ts'],\n globals: {\n 'ts-jest': {\n useESM: true,\n },\n },\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n}\n"})}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "extensionsToTreatAsEsm": [".ts"],\n "globals": {\n "ts-jest": {\n "useESM": true\n }\n },\n "moduleNameMapper": {\n "^(\\\\.{1,2}/.*)\\\\.js$": "$1"\n }\n }\n}\n'})}),"\n",(0,r.jsx)(s.h4,{id:"use-esm-presets",children:"Use ESM presets"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n preset: 'ts-jest/presets/default-esm', // or other ESM presets\n globals: {\n 'ts-jest': {\n useESM: true,\n },\n },\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n}\n"})}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "preset": "ts-jest/presets/default-esm", // or other ESM presets,\n "globals": {\n "ts-jest": {\n "useESM": true\n }\n },\n "moduleNameMapper": {\n "^(\\\\.{1,2}/.*)\\\\.js$": "$1"\n }\n }\n}\n'})})]})}function u(e={}){const{wrapper:s}={...(0,o.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(d,{...e})}):d(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>i,x:()=>c});var t=n(6540);const r={},o=t.createContext(r);function i(e){const s=t.useContext(o);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function c(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),t.createElement(o.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/90645308.39c8de4b.js b/assets/js/90645308.49eba68d.js similarity index 99% rename from assets/js/90645308.39c8de4b.js rename to assets/js/90645308.49eba68d.js index 76b81a07e7..5bb0e5a76e 100644 --- a/assets/js/90645308.39c8de4b.js +++ b/assets/js/90645308.49eba68d.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1626],{6747:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>m,frontMatter:()=>i,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/useESM","title":"useESM option","description":"The useESM option allows ts-jest to transform codes to ESM syntax if possible.","source":"@site/versioned_docs/version-29.2/getting-started/options/useESM.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/useESM","permalink":"/ts-jest/docs/getting-started/options/useESM","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/options/useESM.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"useESM option"}}');var r=s(4848),a=s(8453),o=s(9489),l=s(7227);const i={title:"useESM option"},u=void 0,c={},d=[{value:"Examples",id:"examples",level:3}];function p(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["The ",(0,r.jsx)(t.code,{children:"useESM"})," option allows ",(0,r.jsx)(t.code,{children:"ts-jest"})," to transform codes to ESM syntax ",(0,r.jsx)(t.strong,{children:"if possible"}),"."]}),"\n",(0,r.jsxs)(t.p,{children:["The default value is ",(0,r.jsx)(t.strong,{children:"false"}),", ",(0,r.jsx)(t.code,{children:"ts-jest"})," will transform codes to ",(0,r.jsx)(t.code,{children:"CommonJS"})," syntax."]}),"\n",(0,r.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n useESM: true,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n useESM: true,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "useESM": true\n }\n ]\n }\n }\n}\n'})})})]})]})}function m(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>o});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var a=s(4848);function o(e){let{children:t,hidden:s,className:o}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,o),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>y});var n=s(6540),r=s(4164),a=s(4245),o=s(6347),l=s(6494),i=s(2814),u=s(5167),c=s(9900);function d(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:r}}=e;return{value:t,label:s,attributes:n,default:r}}))}(s);return function(e){const t=(0,u.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function m(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:s}=e;const r=(0,o.W6)(),a=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,i.aZ)(a),(0,n.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function f(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,a=p(e),[o,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:a}))),[u,d]=h({queryString:s,groupId:r}),[f,j]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,c.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&a.set(e)}),[s,a])]}({groupId:r}),x=(()=>{const e=u??f;return m({value:e,tabValues:a})?e:null})();(0,l.A)((()=>{x&&i(x)}),[x]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);i(e),d(e),j(e)}),[d,j,a]),tabValues:a}}var j=s(1062);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=s(4848);function g(e){let{className:t,block:s,selectedValue:n,selectValue:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:u}=(0,a.a_)(),c=e=>{const t=e.currentTarget,s=i.indexOf(t),r=l[s].value;r!==n&&(u(t),o(r))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const s=i.indexOf(e.currentTarget)+1;t=i[s]??i[0];break}case"ArrowLeft":{const s=i.indexOf(e.currentTarget)-1;t=i[s]??i[i.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":s},t),children:l.map((e=>{let{value:t,label:s,attributes:a}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:d,onClick:c,...a,className:(0,r.A)("tabs__item",x.tabItem,a?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:a}=e;const o=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function w(e){const t=f(e);return(0,b.jsxs)("div",{className:(0,r.A)("tabs-container",x.tabList),children:[(0,b.jsx)(g,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function y(e){const t=(0,j.A)();return(0,b.jsx)(w,{...e,children:d(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>o,x:()=>l});var n=s(6540);const r={},a=n.createContext(r);function o(e){const t=n.useContext(a);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),n.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1626],{6747:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>m,frontMatter:()=>i,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/useESM","title":"useESM option","description":"The useESM option allows ts-jest to transform codes to ESM syntax if possible.","source":"@site/versioned_docs/version-29.2/getting-started/options/useESM.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/useESM","permalink":"/ts-jest/docs/getting-started/options/useESM","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/options/useESM.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"useESM option"}}');var r=s(4848),a=s(8453),o=s(9489),l=s(7227);const i={title:"useESM option"},u=void 0,c={},d=[{value:"Examples",id:"examples",level:3}];function p(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["The ",(0,r.jsx)(t.code,{children:"useESM"})," option allows ",(0,r.jsx)(t.code,{children:"ts-jest"})," to transform codes to ESM syntax ",(0,r.jsx)(t.strong,{children:"if possible"}),"."]}),"\n",(0,r.jsxs)(t.p,{children:["The default value is ",(0,r.jsx)(t.strong,{children:"false"}),", ",(0,r.jsx)(t.code,{children:"ts-jest"})," will transform codes to ",(0,r.jsx)(t.code,{children:"CommonJS"})," syntax."]}),"\n",(0,r.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n useESM: true,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n useESM: true,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "useESM": true\n }\n ]\n }\n }\n}\n'})})})]})]})}function m(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>o});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var a=s(4848);function o(e){let{children:t,hidden:s,className:o}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,o),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>y});var n=s(6540),r=s(4164),a=s(4245),o=s(6347),l=s(6494),i=s(2814),u=s(5167),c=s(9900);function d(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:r}}=e;return{value:t,label:s,attributes:n,default:r}}))}(s);return function(e){const t=(0,u.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function m(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:s}=e;const r=(0,o.W6)(),a=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,i.aZ)(a),(0,n.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function f(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,a=p(e),[o,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:a}))),[u,d]=h({queryString:s,groupId:r}),[f,j]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,c.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&a.set(e)}),[s,a])]}({groupId:r}),x=(()=>{const e=u??f;return m({value:e,tabValues:a})?e:null})();(0,l.A)((()=>{x&&i(x)}),[x]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);i(e),d(e),j(e)}),[d,j,a]),tabValues:a}}var j=s(1062);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=s(4848);function g(e){let{className:t,block:s,selectedValue:n,selectValue:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:u}=(0,a.a_)(),c=e=>{const t=e.currentTarget,s=i.indexOf(t),r=l[s].value;r!==n&&(u(t),o(r))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const s=i.indexOf(e.currentTarget)+1;t=i[s]??i[0];break}case"ArrowLeft":{const s=i.indexOf(e.currentTarget)-1;t=i[s]??i[i.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":s},t),children:l.map((e=>{let{value:t,label:s,attributes:a}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:d,onClick:c,...a,className:(0,r.A)("tabs__item",x.tabItem,a?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:a}=e;const o=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function w(e){const t=f(e);return(0,b.jsxs)("div",{className:(0,r.A)("tabs-container",x.tabList),children:[(0,b.jsx)(g,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function y(e){const t=(0,j.A)();return(0,b.jsx)(w,{...e,children:d(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>o,x:()=>l});var n=s(6540);const r={},a=n.createContext(r);function o(e){const t=n.useContext(a);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),n.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/9226f379.a45c386e.js b/assets/js/9226f379.5f1c5b18.js similarity index 99% rename from assets/js/9226f379.a45c386e.js rename to assets/js/9226f379.5f1c5b18.js index 1bc6d3d619..08ac6d6d51 100644 --- a/assets/js/9226f379.a45c386e.js +++ b/assets/js/9226f379.5f1c5b18.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5567],{7204:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>o,contentTitle:()=>i,default:()=>h,frontMatter:()=>c,metadata:()=>n,toc:()=>l});const n=JSON.parse('{"id":"getting-started/presets","title":"Presets","description":"The presets","source":"@site/versioned_docs/version-28.0/getting-started/presets.md","sourceDirName":"getting-started","slug":"/getting-started/presets","permalink":"/ts-jest/docs/28.0/getting-started/presets","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/presets.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"presets","title":"Presets"},"sidebar":"version-28.0-docs","previous":{"title":"Installation","permalink":"/ts-jest/docs/28.0/getting-started/installation"},"next":{"title":"Options","permalink":"/ts-jest/docs/28.0/getting-started/options"}}');var r=t(4848),d=t(8453);const c={id:"presets",title:"Presets"},i=void 0,o={},l=[{value:"The presets",id:"the-presets",level:3},{value:"Basic usage",id:"basic-usage",level:3},{value:"Advanced",id:"advanced",level:3}];function j(e){const s={admonition:"admonition",code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,d.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(s.h3,{id:"the-presets",children:"The presets"}),"\n",(0,r.jsx)(s.admonition,{type:"important",children:(0,r.jsxs)(s.p,{children:["Starting from ",(0,r.jsx)(s.strong,{children:"v28.0.0"}),", ",(0,r.jsx)(s.code,{children:"ts-jest"})," will gradually opt in adoption of ",(0,r.jsx)(s.code,{children:"esbuild"}),"/",(0,r.jsx)(s.code,{children:"swc"})," more to improve the performance. To make the transition smoothly, we introduce ",(0,r.jsx)(s.code,{children:"legacy"})," presets as a fallback when the new codes don't work yet."]})}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.code,{children:"ts-jest"})," comes with several presets, covering most of the project's base configuration:"]}),"\n",(0,r.jsxs)(s.table,{children:[(0,r.jsx)(s.thead,{children:(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.th,{children:"Preset name"}),(0,r.jsx)(s.th,{children:"Description"})]})}),(0,r.jsxs)(s.tbody,{children:[(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default"}),(0,r.jsx)("br",{}),"or ",(0,r.jsx)(s.code,{children:"ts-jest"})]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default-legacy"}),(0,r.jsx)("br",{}),"or ",(0,r.jsx)(s.code,{children:"ts-jest/legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default-esm"}),(0,r.jsx)("br",{})]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default-esm-legacy"}),(0,r.jsx)("br",{})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts"})}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-esm"})}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-esm-legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel"})}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-esm"})}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-esm-legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]})]})]}),"\n",(0,r.jsx)(s.h3,{id:"basic-usage",children:"Basic usage"}),"\n",(0,r.jsxs)(s.p,{children:["In most cases, simply setting the ",(0,r.jsx)(s.code,{children:"preset"})," key to the desired preset name in your Jest config should be enough to start\nusing TypeScript with Jest (assuming you added ",(0,r.jsx)(s.code,{children:"ts-jest"})," to your ",(0,r.jsx)(s.code,{children:"devDependencies"})," of course):"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n // Replace `ts-jest` with the preset you want to use\n // from the above list\n preset: 'ts-jest',\n}\n"})}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n // Replace `ts-jest` with the preset you want to use\n // from the above list\n "preset": "ts-jest"\n }\n}\n'})}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.strong,{children:"Note:"})," presets use ",(0,r.jsx)(s.code,{children:"testMatch"}),", like Jest does in its defaults. If you want to use ",(0,r.jsx)(s.code,{children:"testRegex"})," instead in your configuration, you MUST set ",(0,r.jsx)(s.code,{children:"testMatch"})," to ",(0,r.jsx)(s.code,{children:"null"})," or Jest will bail."]}),"\n",(0,r.jsx)(s.h3,{id:"advanced",children:"Advanced"}),"\n",(0,r.jsxs)(s.p,{children:["Any preset can also be used with other options.\nIf you're already using another preset, you might want only some specific settings from the chosen ",(0,r.jsx)(s.code,{children:"ts-jest"})," preset.\nIn this case you'll need to use the JavaScript version of Jest config (comment/uncomment according to your use case):"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n// const { defaultsESM: tsjPreset } = require('ts-jest/presets')\n// const { jsWithTs: tsjPreset } = require('ts-jest/presets')\n// const { jsWithTsESM: tsjPreset } = require('ts-jest/presets')\n// const { jsWithBabel: tsjPreset } = require('ts-jest/presets')\n// const { jsWithBabelESM: tsjPreset } = require('ts-jest/presets')\n\nmodule.exports = {\n // [...]\n transform: {\n ...tsjPreset.transform,\n // [...]\n },\n}\n"})}),"\n",(0,r.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,r.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport type { InitialOptionsTsJest } from 'ts-jest'\nimport { defaults as tsjPreset } from 'ts-jest/presets'\n// import { defaultsESM as tsjPreset } from 'ts-jest/presets'\n// import { jsWithTs as tsjPreset } from 'ts-jest/presets'\n// import { jsWithTsESM as tsjPreset } from 'ts-jest/presets'\n// import { jsWithBabel as tsjPreset } from 'ts-jest/presets'\n// import { jsWithBabelESM as tsjPreset } from 'ts-jest/presets'\n\nconst config: InitialOptionsTsJest = {\n // [...]\n transform: {\n ...tsjPreset.transform,\n // [...]\n },\n}\n\nexport default config\n"})})]})}function h(e={}){const{wrapper:s}={...(0,d.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(j,{...e})}):j(e)}},8453:(e,s,t)=>{t.d(s,{R:()=>c,x:()=>i});var n=t(6540);const r={},d=n.createContext(r);function c(e){const s=n.useContext(d);return n.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function i(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:c(e.components),n.createElement(d.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5567],{7204:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>o,contentTitle:()=>i,default:()=>h,frontMatter:()=>c,metadata:()=>n,toc:()=>l});const n=JSON.parse('{"id":"getting-started/presets","title":"Presets","description":"The presets","source":"@site/versioned_docs/version-28.0/getting-started/presets.md","sourceDirName":"getting-started","slug":"/getting-started/presets","permalink":"/ts-jest/docs/28.0/getting-started/presets","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/presets.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"presets","title":"Presets"},"sidebar":"version-28.0-docs","previous":{"title":"Installation","permalink":"/ts-jest/docs/28.0/getting-started/installation"},"next":{"title":"Options","permalink":"/ts-jest/docs/28.0/getting-started/options"}}');var r=t(4848),d=t(8453);const c={id:"presets",title:"Presets"},i=void 0,o={},l=[{value:"The presets",id:"the-presets",level:3},{value:"Basic usage",id:"basic-usage",level:3},{value:"Advanced",id:"advanced",level:3}];function j(e){const s={admonition:"admonition",code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,d.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(s.h3,{id:"the-presets",children:"The presets"}),"\n",(0,r.jsx)(s.admonition,{type:"important",children:(0,r.jsxs)(s.p,{children:["Starting from ",(0,r.jsx)(s.strong,{children:"v28.0.0"}),", ",(0,r.jsx)(s.code,{children:"ts-jest"})," will gradually opt in adoption of ",(0,r.jsx)(s.code,{children:"esbuild"}),"/",(0,r.jsx)(s.code,{children:"swc"})," more to improve the performance. To make the transition smoothly, we introduce ",(0,r.jsx)(s.code,{children:"legacy"})," presets as a fallback when the new codes don't work yet."]})}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.code,{children:"ts-jest"})," comes with several presets, covering most of the project's base configuration:"]}),"\n",(0,r.jsxs)(s.table,{children:[(0,r.jsx)(s.thead,{children:(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.th,{children:"Preset name"}),(0,r.jsx)(s.th,{children:"Description"})]})}),(0,r.jsxs)(s.tbody,{children:[(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default"}),(0,r.jsx)("br",{}),"or ",(0,r.jsx)(s.code,{children:"ts-jest"})]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default-legacy"}),(0,r.jsx)("br",{}),"or ",(0,r.jsx)(s.code,{children:"ts-jest/legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default-esm"}),(0,r.jsx)("br",{})]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default-esm-legacy"}),(0,r.jsx)("br",{})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts"})}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-esm"})}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-esm-legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel"})}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-esm"})}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-esm-legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]})]})]}),"\n",(0,r.jsx)(s.h3,{id:"basic-usage",children:"Basic usage"}),"\n",(0,r.jsxs)(s.p,{children:["In most cases, simply setting the ",(0,r.jsx)(s.code,{children:"preset"})," key to the desired preset name in your Jest config should be enough to start\nusing TypeScript with Jest (assuming you added ",(0,r.jsx)(s.code,{children:"ts-jest"})," to your ",(0,r.jsx)(s.code,{children:"devDependencies"})," of course):"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n // Replace `ts-jest` with the preset you want to use\n // from the above list\n preset: 'ts-jest',\n}\n"})}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n // Replace `ts-jest` with the preset you want to use\n // from the above list\n "preset": "ts-jest"\n }\n}\n'})}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.strong,{children:"Note:"})," presets use ",(0,r.jsx)(s.code,{children:"testMatch"}),", like Jest does in its defaults. If you want to use ",(0,r.jsx)(s.code,{children:"testRegex"})," instead in your configuration, you MUST set ",(0,r.jsx)(s.code,{children:"testMatch"})," to ",(0,r.jsx)(s.code,{children:"null"})," or Jest will bail."]}),"\n",(0,r.jsx)(s.h3,{id:"advanced",children:"Advanced"}),"\n",(0,r.jsxs)(s.p,{children:["Any preset can also be used with other options.\nIf you're already using another preset, you might want only some specific settings from the chosen ",(0,r.jsx)(s.code,{children:"ts-jest"})," preset.\nIn this case you'll need to use the JavaScript version of Jest config (comment/uncomment according to your use case):"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n// const { defaultsESM: tsjPreset } = require('ts-jest/presets')\n// const { jsWithTs: tsjPreset } = require('ts-jest/presets')\n// const { jsWithTsESM: tsjPreset } = require('ts-jest/presets')\n// const { jsWithBabel: tsjPreset } = require('ts-jest/presets')\n// const { jsWithBabelESM: tsjPreset } = require('ts-jest/presets')\n\nmodule.exports = {\n // [...]\n transform: {\n ...tsjPreset.transform,\n // [...]\n },\n}\n"})}),"\n",(0,r.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,r.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport type { InitialOptionsTsJest } from 'ts-jest'\nimport { defaults as tsjPreset } from 'ts-jest/presets'\n// import { defaultsESM as tsjPreset } from 'ts-jest/presets'\n// import { jsWithTs as tsjPreset } from 'ts-jest/presets'\n// import { jsWithTsESM as tsjPreset } from 'ts-jest/presets'\n// import { jsWithBabel as tsjPreset } from 'ts-jest/presets'\n// import { jsWithBabelESM as tsjPreset } from 'ts-jest/presets'\n\nconst config: InitialOptionsTsJest = {\n // [...]\n transform: {\n ...tsjPreset.transform,\n // [...]\n },\n}\n\nexport default config\n"})})]})}function h(e={}){const{wrapper:s}={...(0,d.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(j,{...e})}):j(e)}},8453:(e,s,t)=>{t.d(s,{R:()=>c,x:()=>i});var n=t(6540);const r={},d=n.createContext(r);function c(e){const s=n.useContext(d);return n.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function i(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:c(e.components),n.createElement(d.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/96f7df01.8bfb600d.js b/assets/js/96f7df01.48c01edb.js similarity index 98% rename from assets/js/96f7df01.8bfb600d.js rename to assets/js/96f7df01.48c01edb.js index 332310f788..ab0513bd81 100644 --- a/assets/js/96f7df01.8bfb600d.js +++ b/assets/js/96f7df01.48c01edb.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4316],{7827:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>r,metadata:()=>s,toc:()=>l});const s=JSON.parse('{"id":"babel7-or-ts","title":"Babel7 or TypeScript","description":"In Sept. 2018 Babel7 got released with an interesting preset: @babel/preset-typescript.","source":"@site/versioned_docs/version-27.0/babel7-or-ts.md","sourceDirName":".","slug":"/babel7-or-ts","permalink":"/ts-jest/docs/27.0/babel7-or-ts","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/babel7-or-ts.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"babel7-or-ts","title":"Babel7 or TypeScript"},"sidebar":"version-27.0-docs","previous":{"title":"Using with monorepo","permalink":"/ts-jest/docs/27.0/guides/using-with-monorepo"},"next":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/27.0/migration"}}');var i=n(4848),o=n(8453);const r={id:"babel7-or-ts",title:"Babel7 or TypeScript"},c=void 0,a={},l=[{value:"Limitations",id:"limitations",level:2},{value:"No type-checking",id:"no-type-checking",level:4},{value:"No namespace",id:"no-namespace",level:4},{value:"No const enum",id:"no-const-enum",level:4},{value:"No declaration merging (enum, namespace, ...)",id:"no-declaration-merging-enum-namespace-",level:4},{value:"No legacy import/export",id:"no-legacy-importexport",level:4},{value:"No caret type-casting with JSX enabled",id:"no-caret-type-casting-with-jsx-enabled",level:4}];function d(e){const t={a:"a",code:"code",h2:"h2",h4:"h4",hr:"hr",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,i.jsxs)(t.p,{children:["The goal is to make it easy for users using Babel to try TypeScript without moving out from Babel, just by adding a preset in their Babel config (here is the ",(0,i.jsx)(t.a,{href:"https://blogs.msdn.microsoft.com/typescript/2018/08/27/typescript-and-babel-7/",children:"MSDN blog post"})," about TypeScript and Babel 7)."]}),"\n",(0,i.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,i.jsxs)(t.p,{children:["While ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"})," is a great preset, you must know the limitation of it. Here is what is possible with TypeScript (and ",(0,i.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,i.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,i.jsxs)(t.p,{children:["This is the big ",(0,i.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,i.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,i.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,i.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,i.jsx)(t.p,{children:'With Babel, files are transpiled as isolated modules, there is no notion of "project". With TypeScript, files are part of a project and are compiled in that scope.'}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,i.jsx)(t.code,{children:"namespace"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"namespace app {\n export const VERSION = '1.0.0'\n export class App {\n /* ... */\n }\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,i.jsx)(t.code,{children:"const enum"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,i.jsx)(t.code,{children:"enum"}),", ",(0,i.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,i.jsxs)(t.p,{children:["You won't be able to do ",(0,i.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,i.jsx)(t.code,{children:"import"}),"/",(0,i.jsx)(t.code,{children:"export"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>c});var s=n(6540);const i={},o=s.createContext(i);function r(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4316],{7827:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>r,metadata:()=>s,toc:()=>l});const s=JSON.parse('{"id":"babel7-or-ts","title":"Babel7 or TypeScript","description":"In Sept. 2018 Babel7 got released with an interesting preset: @babel/preset-typescript.","source":"@site/versioned_docs/version-27.0/babel7-or-ts.md","sourceDirName":".","slug":"/babel7-or-ts","permalink":"/ts-jest/docs/27.0/babel7-or-ts","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/babel7-or-ts.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"babel7-or-ts","title":"Babel7 or TypeScript"},"sidebar":"version-27.0-docs","previous":{"title":"Using with monorepo","permalink":"/ts-jest/docs/27.0/guides/using-with-monorepo"},"next":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/27.0/migration"}}');var i=n(4848),o=n(8453);const r={id:"babel7-or-ts",title:"Babel7 or TypeScript"},c=void 0,a={},l=[{value:"Limitations",id:"limitations",level:2},{value:"No type-checking",id:"no-type-checking",level:4},{value:"No namespace",id:"no-namespace",level:4},{value:"No const enum",id:"no-const-enum",level:4},{value:"No declaration merging (enum, namespace, ...)",id:"no-declaration-merging-enum-namespace-",level:4},{value:"No legacy import/export",id:"no-legacy-importexport",level:4},{value:"No caret type-casting with JSX enabled",id:"no-caret-type-casting-with-jsx-enabled",level:4}];function d(e){const t={a:"a",code:"code",h2:"h2",h4:"h4",hr:"hr",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,i.jsxs)(t.p,{children:["The goal is to make it easy for users using Babel to try TypeScript without moving out from Babel, just by adding a preset in their Babel config (here is the ",(0,i.jsx)(t.a,{href:"https://blogs.msdn.microsoft.com/typescript/2018/08/27/typescript-and-babel-7/",children:"MSDN blog post"})," about TypeScript and Babel 7)."]}),"\n",(0,i.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,i.jsxs)(t.p,{children:["While ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"})," is a great preset, you must know the limitation of it. Here is what is possible with TypeScript (and ",(0,i.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,i.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,i.jsxs)(t.p,{children:["This is the big ",(0,i.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,i.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,i.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,i.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,i.jsx)(t.p,{children:'With Babel, files are transpiled as isolated modules, there is no notion of "project". With TypeScript, files are part of a project and are compiled in that scope.'}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,i.jsx)(t.code,{children:"namespace"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"namespace app {\n export const VERSION = '1.0.0'\n export class App {\n /* ... */\n }\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,i.jsx)(t.code,{children:"const enum"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,i.jsx)(t.code,{children:"enum"}),", ",(0,i.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,i.jsxs)(t.p,{children:["You won't be able to do ",(0,i.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,i.jsx)(t.code,{children:"import"}),"/",(0,i.jsx)(t.code,{children:"export"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>c});var s=n(6540);const i={},o=s.createContext(i);function r(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/9762b2e9.a60a5583.js b/assets/js/9762b2e9.c07ce416.js similarity index 98% rename from assets/js/9762b2e9.a60a5583.js rename to assets/js/9762b2e9.c07ce416.js index 33b438d94b..945d13aedd 100644 --- a/assets/js/9762b2e9.a60a5583.js +++ b/assets/js/9762b2e9.c07ce416.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6553],{5862:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>p,default:()=>d,frontMatter:()=>r,metadata:()=>s,toc:()=>c});const s=JSON.parse('{"id":"getting-started/paths-mapping","title":"Paths mapping","description":"If you use \\"baseUrl\\" and \\"paths\\" options in your tsconfig file, you should make sure the \\"moduleNameMapper\\" option in your Jest config is setup accordingly.","source":"@site/versioned_docs/version-27.1/getting-started/paths-mapping.md","sourceDirName":"getting-started","slug":"/getting-started/paths-mapping","permalink":"/ts-jest/docs/27.1/getting-started/paths-mapping","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/paths-mapping.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"paths-mapping","title":"Paths mapping"},"sidebar":"version-27.1-docs","previous":{"title":"Options","permalink":"/ts-jest/docs/27.1/getting-started/options"},"next":{"title":"Version checking","permalink":"/ts-jest/docs/27.1/getting-started/version-checking"}}');var o=n(4848),i=n(8453);const r={id:"paths-mapping",title:"Paths mapping"},p=void 0,a={},c=[{value:"Example",id:"example",level:3},{value:"TypeScript config",id:"typescript-config",level:4},{value:"Jest config (without helper)",id:"jest-config-without-helper",level:4},{value:"Jest config (with helper)",id:"jest-config-with-helper",level:4}];function l(e){const t={a:"a",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["If you use ",(0,o.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,o.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,o.jsx)(t.a,{href:"https://jestjs.io/docs/configuration#modulenamemapper-objectstring-string--arraystring",children:'"moduleNameMapper"'})," option in your Jest config is setup accordingly."]}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,o.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,o.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,o.jsxs)(t.p,{children:["With the below config in your ",(0,o.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n "compilerOptions": {\n "baseUrl": ".",\n "paths": {\n "@App/*": ["src/*"],\n "lib/*": ["common/*"]\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n moduleNameMapper: {\n '^@App/(.*)$': '/src/$1',\n '^lib/(.*)$': '/common/$1',\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleNameMapper": {\n "^@App/(.*)$": "/src/$1",\n "^lib/(.*)$": "/common/$1"\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nconst { pathsToModuleNameMapper } = require('ts-jest/utils')\n// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file\n// which contains the path mapping (ie the `compilerOptions.paths` option):\nconst { compilerOptions } = require('./tsconfig')\n\nmodule.exports = {\n // [...]\n roots: [''],\n modulePaths: [compilerOptions.baseUrl], // <-- This will be set to 'baseUrl' value\n moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths /*, { prefix: '/' } */),\n}\n"})})]})}function d(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>p});var s=n(6540);const o={},i=s.createContext(o);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function p(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6553],{5862:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>p,default:()=>d,frontMatter:()=>r,metadata:()=>s,toc:()=>c});const s=JSON.parse('{"id":"getting-started/paths-mapping","title":"Paths mapping","description":"If you use \\"baseUrl\\" and \\"paths\\" options in your tsconfig file, you should make sure the \\"moduleNameMapper\\" option in your Jest config is setup accordingly.","source":"@site/versioned_docs/version-27.1/getting-started/paths-mapping.md","sourceDirName":"getting-started","slug":"/getting-started/paths-mapping","permalink":"/ts-jest/docs/27.1/getting-started/paths-mapping","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/paths-mapping.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"paths-mapping","title":"Paths mapping"},"sidebar":"version-27.1-docs","previous":{"title":"Options","permalink":"/ts-jest/docs/27.1/getting-started/options"},"next":{"title":"Version checking","permalink":"/ts-jest/docs/27.1/getting-started/version-checking"}}');var o=n(4848),i=n(8453);const r={id:"paths-mapping",title:"Paths mapping"},p=void 0,a={},c=[{value:"Example",id:"example",level:3},{value:"TypeScript config",id:"typescript-config",level:4},{value:"Jest config (without helper)",id:"jest-config-without-helper",level:4},{value:"Jest config (with helper)",id:"jest-config-with-helper",level:4}];function l(e){const t={a:"a",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["If you use ",(0,o.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,o.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,o.jsx)(t.a,{href:"https://jestjs.io/docs/configuration#modulenamemapper-objectstring-string--arraystring",children:'"moduleNameMapper"'})," option in your Jest config is setup accordingly."]}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,o.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,o.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,o.jsxs)(t.p,{children:["With the below config in your ",(0,o.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n "compilerOptions": {\n "baseUrl": ".",\n "paths": {\n "@App/*": ["src/*"],\n "lib/*": ["common/*"]\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n moduleNameMapper: {\n '^@App/(.*)$': '/src/$1',\n '^lib/(.*)$': '/common/$1',\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleNameMapper": {\n "^@App/(.*)$": "/src/$1",\n "^lib/(.*)$": "/common/$1"\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nconst { pathsToModuleNameMapper } = require('ts-jest/utils')\n// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file\n// which contains the path mapping (ie the `compilerOptions.paths` option):\nconst { compilerOptions } = require('./tsconfig')\n\nmodule.exports = {\n // [...]\n roots: [''],\n modulePaths: [compilerOptions.baseUrl], // <-- This will be set to 'baseUrl' value\n moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths /*, { prefix: '/' } */),\n}\n"})})]})}function d(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>p});var s=n(6540);const o={},i=s.createContext(o);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function p(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/981dc414.57664b9f.js b/assets/js/981dc414.d0180d50.js similarity index 99% rename from assets/js/981dc414.57664b9f.js rename to assets/js/981dc414.d0180d50.js index ace06394d6..56dd4f4dbd 100644 --- a/assets/js/981dc414.57664b9f.js +++ b/assets/js/981dc414.d0180d50.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2777],{1263:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>m,frontMatter:()=>i,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/useESM","title":"useESM option","description":"The useESM option allows ts-jest to transform codes to ESM syntax if possible.","source":"@site/versioned_docs/version-29.0/getting-started/options/useESM.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/useESM","permalink":"/ts-jest/docs/29.0/getting-started/options/useESM","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/options/useESM.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"useESM option"}}');var r=s(4848),a=s(8453),o=s(9489),l=s(7227);const i={title:"useESM option"},u=void 0,c={},d=[{value:"Examples",id:"examples",level:3}];function p(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["The ",(0,r.jsx)(t.code,{children:"useESM"})," option allows ",(0,r.jsx)(t.code,{children:"ts-jest"})," to transform codes to ESM syntax ",(0,r.jsx)(t.strong,{children:"if possible"}),"."]}),"\n",(0,r.jsxs)(t.p,{children:["The default value is ",(0,r.jsx)(t.strong,{children:"false"}),", ",(0,r.jsx)(t.code,{children:"ts-jest"})," will transform codes to ",(0,r.jsx)(t.code,{children:"CommonJS"})," syntax."]}),"\n",(0,r.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n useESM: true,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n useESM: true,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "useESM": true\n }\n ]\n }\n }\n}\n'})})})]})]})}function m(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>o});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var a=s(4848);function o(e){let{children:t,hidden:s,className:o}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,o),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>y});var n=s(6540),r=s(4164),a=s(4245),o=s(6347),l=s(6494),i=s(2814),u=s(5167),c=s(9900);function d(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:r}}=e;return{value:t,label:s,attributes:n,default:r}}))}(s);return function(e){const t=(0,u.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function m(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:s}=e;const r=(0,o.W6)(),a=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,i.aZ)(a),(0,n.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function f(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,a=p(e),[o,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:a}))),[u,d]=h({queryString:s,groupId:r}),[f,j]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,c.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&a.set(e)}),[s,a])]}({groupId:r}),x=(()=>{const e=u??f;return m({value:e,tabValues:a})?e:null})();(0,l.A)((()=>{x&&i(x)}),[x]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);i(e),d(e),j(e)}),[d,j,a]),tabValues:a}}var j=s(1062);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=s(4848);function g(e){let{className:t,block:s,selectedValue:n,selectValue:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:u}=(0,a.a_)(),c=e=>{const t=e.currentTarget,s=i.indexOf(t),r=l[s].value;r!==n&&(u(t),o(r))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const s=i.indexOf(e.currentTarget)+1;t=i[s]??i[0];break}case"ArrowLeft":{const s=i.indexOf(e.currentTarget)-1;t=i[s]??i[i.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":s},t),children:l.map((e=>{let{value:t,label:s,attributes:a}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:d,onClick:c,...a,className:(0,r.A)("tabs__item",x.tabItem,a?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:a}=e;const o=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function w(e){const t=f(e);return(0,b.jsxs)("div",{className:(0,r.A)("tabs-container",x.tabList),children:[(0,b.jsx)(g,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function y(e){const t=(0,j.A)();return(0,b.jsx)(w,{...e,children:d(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>o,x:()=>l});var n=s(6540);const r={},a=n.createContext(r);function o(e){const t=n.useContext(a);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),n.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2777],{1263:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>m,frontMatter:()=>i,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/useESM","title":"useESM option","description":"The useESM option allows ts-jest to transform codes to ESM syntax if possible.","source":"@site/versioned_docs/version-29.0/getting-started/options/useESM.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/useESM","permalink":"/ts-jest/docs/29.0/getting-started/options/useESM","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/options/useESM.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"useESM option"}}');var r=s(4848),a=s(8453),o=s(9489),l=s(7227);const i={title:"useESM option"},u=void 0,c={},d=[{value:"Examples",id:"examples",level:3}];function p(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["The ",(0,r.jsx)(t.code,{children:"useESM"})," option allows ",(0,r.jsx)(t.code,{children:"ts-jest"})," to transform codes to ESM syntax ",(0,r.jsx)(t.strong,{children:"if possible"}),"."]}),"\n",(0,r.jsxs)(t.p,{children:["The default value is ",(0,r.jsx)(t.strong,{children:"false"}),", ",(0,r.jsx)(t.code,{children:"ts-jest"})," will transform codes to ",(0,r.jsx)(t.code,{children:"CommonJS"})," syntax."]}),"\n",(0,r.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n useESM: true,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n useESM: true,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "useESM": true\n }\n ]\n }\n }\n}\n'})})})]})]})}function m(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>o});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var a=s(4848);function o(e){let{children:t,hidden:s,className:o}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,o),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>y});var n=s(6540),r=s(4164),a=s(4245),o=s(6347),l=s(6494),i=s(2814),u=s(5167),c=s(9900);function d(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:r}}=e;return{value:t,label:s,attributes:n,default:r}}))}(s);return function(e){const t=(0,u.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function m(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:s}=e;const r=(0,o.W6)(),a=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,i.aZ)(a),(0,n.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function f(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,a=p(e),[o,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:a}))),[u,d]=h({queryString:s,groupId:r}),[f,j]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,c.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&a.set(e)}),[s,a])]}({groupId:r}),x=(()=>{const e=u??f;return m({value:e,tabValues:a})?e:null})();(0,l.A)((()=>{x&&i(x)}),[x]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);i(e),d(e),j(e)}),[d,j,a]),tabValues:a}}var j=s(1062);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=s(4848);function g(e){let{className:t,block:s,selectedValue:n,selectValue:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:u}=(0,a.a_)(),c=e=>{const t=e.currentTarget,s=i.indexOf(t),r=l[s].value;r!==n&&(u(t),o(r))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const s=i.indexOf(e.currentTarget)+1;t=i[s]??i[0];break}case"ArrowLeft":{const s=i.indexOf(e.currentTarget)-1;t=i[s]??i[i.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":s},t),children:l.map((e=>{let{value:t,label:s,attributes:a}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:d,onClick:c,...a,className:(0,r.A)("tabs__item",x.tabItem,a?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:a}=e;const o=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function w(e){const t=f(e);return(0,b.jsxs)("div",{className:(0,r.A)("tabs-container",x.tabList),children:[(0,b.jsx)(g,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function y(e){const t=(0,j.A)();return(0,b.jsx)(w,{...e,children:d(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>o,x:()=>l});var n=s(6540);const r={},a=n.createContext(r);function o(e){const t=n.useContext(a);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),n.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/9920b385.f93e0231.js b/assets/js/9920b385.c2b915d3.js similarity index 99% rename from assets/js/9920b385.f93e0231.js rename to assets/js/9920b385.c2b915d3.js index 5f68a01372..bf9b122593 100644 --- a/assets/js/9920b385.f93e0231.js +++ b/assets/js/9920b385.c2b915d3.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4571],{9482:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>i,metadata:()=>n,toc:()=>j});const n=JSON.parse('{"id":"getting-started/options/babelConfig","title":"Babel Config option","description":"ts-jest by default does NOT use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ts-jest can call the BabelJest processor once TypeScript has transformed the source into JavaScript.","source":"@site/docs/getting-started/options/babelConfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/babelConfig","permalink":"/ts-jest/docs/next/getting-started/options/babelConfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/babelConfig.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Babel Config option"}}');var r=s(4848),o=s(8453),a=s(9489),l=s(7227);const i={title:"Babel Config option"},c=void 0,u={},j=[{value:"Examples",id:"examples",level:3},{value:"Use default babelrc file",id:"use-default-babelrc-file",level:4},{value:"Path to a babelrc file",id:"path-to-a-babelrc-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4}];function d(e){const t={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"ts-jest"})," by default does ",(0,r.jsx)(t.strong,{children:"NOT"})," use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ",(0,r.jsx)(t.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,r.jsxs)(t.p,{children:["The option is ",(0,r.jsx)(t.code,{children:"babelConfig"})," and it works pretty much as the ",(0,r.jsx)(t.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"true"}),": enables Babel processing. ",(0,r.jsx)(t.code,{children:"ts-jest"})," will try to find a ",(0,r.jsx)(t.code,{children:".babelrc"}),", ",(0,r.jsx)(t.code,{children:".babelrc.js"}),", ",(0,r.jsx)(t.code,{children:"babel.config.js"})," file or a ",(0,r.jsx)(t.code,{children:"babel"})," section in the ",(0,r.jsx)(t.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,r.jsx)(t.code,{children:"babel-jest"})," processor."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"{ ... }"}),": inline ",(0,r.jsx)(t.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,r.jsx)(t.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,r.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,r.jsxs)(t.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,r.jsx)(t.code,{children:"babelrc"})," file"]}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: true,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: true,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "babelConfig": true\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsxs)(t.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,r.jsx)(t.code,{children:"babelrc"})," file"]}),"\n",(0,r.jsxs)(t.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,r.jsx)(t.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: 'babelrc.test.js',\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: 'babelrc.test.js',\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "babelConfig": "babelrc.test.js"\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsx)(t.p,{children:"or importing directly the config file:"}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: require('./babelrc.test.js'),\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\nimport babelConfig from './babelrc.test.js'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})})]}),"\n",(0,r.jsx)(t.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,r.jsxs)(t.p,{children:["Refer to the ",(0,r.jsx)(t.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: {\n comments: false,\n plugins: ['@babel/plugin-transform-for-of'],\n },\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: {\n comments: false,\n plugins: ['@babel/plugin-transform-for-of'],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "babelConfig": {\n "comments": false,\n "plugins": ["@babel/plugin-transform-for-of"]\n }\n }\n ]\n }\n }\n}\n'})})})]})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(d,{...e})}):d(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>a});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var o=s(4848);function a(e){let{children:t,hidden:s,className:a}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,a),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>w});var n=s(6540),r=s(4164),o=s(4245),a=s(6347),l=s(6494),i=s(2814),c=s(5167),u=s(9900);function j(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function d(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return j(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:r}}=e;return{value:t,label:s,attributes:n,default:r}}))}(s);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function p(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:s}=e;const r=(0,a.W6)(),o=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,i.aZ)(o),(0,n.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(r.location.search);t.set(o,e),r.replace({...r.location,search:t.toString()})}),[o,r])]}function x(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,o=d(e),[a,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:o}))),[c,j]=h({queryString:s,groupId:r}),[x,m]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,o]=(0,u.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&o.set(e)}),[s,o])]}({groupId:r}),f=(()=>{const e=c??x;return p({value:e,tabValues:o})?e:null})();(0,l.A)((()=>{f&&i(f)}),[f]);return{selectedValue:a,selectValue:(0,n.useCallback)((e=>{if(!p({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);i(e),j(e),m(e)}),[j,m,o]),tabValues:o}}var m=s(1062);const f={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=s(4848);function g(e){let{className:t,block:s,selectedValue:n,selectValue:a,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.a_)(),u=e=>{const t=e.currentTarget,s=i.indexOf(t),r=l[s].value;r!==n&&(c(t),a(r))},j=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const s=i.indexOf(e.currentTarget)+1;t=i[s]??i[0];break}case"ArrowLeft":{const s=i.indexOf(e.currentTarget)-1;t=i[s]??i[i.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":s},t),children:l.map((e=>{let{value:t,label:s,attributes:o}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:j,onClick:u,...o,className:(0,r.A)("tabs__item",f.tabItem,o?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:o}=e;const a=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=a.find((e=>e.props.value===o));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:a.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==o})))})}function y(e){const t=x(e);return(0,b.jsxs)("div",{className:(0,r.A)("tabs-container",f.tabList),children:[(0,b.jsx)(g,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function w(e){const t=(0,m.A)();return(0,b.jsx)(y,{...e,children:j(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>a,x:()=>l});var n=s(6540);const r={},o=n.createContext(r);function a(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4571],{9482:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>i,metadata:()=>n,toc:()=>j});const n=JSON.parse('{"id":"getting-started/options/babelConfig","title":"Babel Config option","description":"ts-jest by default does NOT use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ts-jest can call the BabelJest processor once TypeScript has transformed the source into JavaScript.","source":"@site/docs/getting-started/options/babelConfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/babelConfig","permalink":"/ts-jest/docs/next/getting-started/options/babelConfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/babelConfig.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Babel Config option"}}');var r=s(4848),o=s(8453),a=s(9489),l=s(7227);const i={title:"Babel Config option"},c=void 0,u={},j=[{value:"Examples",id:"examples",level:3},{value:"Use default babelrc file",id:"use-default-babelrc-file",level:4},{value:"Path to a babelrc file",id:"path-to-a-babelrc-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4}];function d(e){const t={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"ts-jest"})," by default does ",(0,r.jsx)(t.strong,{children:"NOT"})," use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ",(0,r.jsx)(t.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,r.jsxs)(t.p,{children:["The option is ",(0,r.jsx)(t.code,{children:"babelConfig"})," and it works pretty much as the ",(0,r.jsx)(t.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"true"}),": enables Babel processing. ",(0,r.jsx)(t.code,{children:"ts-jest"})," will try to find a ",(0,r.jsx)(t.code,{children:".babelrc"}),", ",(0,r.jsx)(t.code,{children:".babelrc.js"}),", ",(0,r.jsx)(t.code,{children:"babel.config.js"})," file or a ",(0,r.jsx)(t.code,{children:"babel"})," section in the ",(0,r.jsx)(t.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,r.jsx)(t.code,{children:"babel-jest"})," processor."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"{ ... }"}),": inline ",(0,r.jsx)(t.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,r.jsx)(t.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,r.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,r.jsxs)(t.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,r.jsx)(t.code,{children:"babelrc"})," file"]}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: true,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: true,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "babelConfig": true\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsxs)(t.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,r.jsx)(t.code,{children:"babelrc"})," file"]}),"\n",(0,r.jsxs)(t.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,r.jsx)(t.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: 'babelrc.test.js',\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: 'babelrc.test.js',\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "babelConfig": "babelrc.test.js"\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsx)(t.p,{children:"or importing directly the config file:"}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: require('./babelrc.test.js'),\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\nimport babelConfig from './babelrc.test.js'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})})]}),"\n",(0,r.jsx)(t.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,r.jsxs)(t.p,{children:["Refer to the ",(0,r.jsx)(t.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: {\n comments: false,\n plugins: ['@babel/plugin-transform-for-of'],\n },\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: {\n comments: false,\n plugins: ['@babel/plugin-transform-for-of'],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "babelConfig": {\n "comments": false,\n "plugins": ["@babel/plugin-transform-for-of"]\n }\n }\n ]\n }\n }\n}\n'})})})]})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(d,{...e})}):d(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>a});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var o=s(4848);function a(e){let{children:t,hidden:s,className:a}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,a),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>w});var n=s(6540),r=s(4164),o=s(4245),a=s(6347),l=s(6494),i=s(2814),c=s(5167),u=s(9900);function j(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function d(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return j(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:r}}=e;return{value:t,label:s,attributes:n,default:r}}))}(s);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function p(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:s}=e;const r=(0,a.W6)(),o=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,i.aZ)(o),(0,n.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(r.location.search);t.set(o,e),r.replace({...r.location,search:t.toString()})}),[o,r])]}function x(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,o=d(e),[a,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:o}))),[c,j]=h({queryString:s,groupId:r}),[x,m]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,o]=(0,u.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&o.set(e)}),[s,o])]}({groupId:r}),f=(()=>{const e=c??x;return p({value:e,tabValues:o})?e:null})();(0,l.A)((()=>{f&&i(f)}),[f]);return{selectedValue:a,selectValue:(0,n.useCallback)((e=>{if(!p({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);i(e),j(e),m(e)}),[j,m,o]),tabValues:o}}var m=s(1062);const f={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=s(4848);function g(e){let{className:t,block:s,selectedValue:n,selectValue:a,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.a_)(),u=e=>{const t=e.currentTarget,s=i.indexOf(t),r=l[s].value;r!==n&&(c(t),a(r))},j=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const s=i.indexOf(e.currentTarget)+1;t=i[s]??i[0];break}case"ArrowLeft":{const s=i.indexOf(e.currentTarget)-1;t=i[s]??i[i.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":s},t),children:l.map((e=>{let{value:t,label:s,attributes:o}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:j,onClick:u,...o,className:(0,r.A)("tabs__item",f.tabItem,o?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:o}=e;const a=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=a.find((e=>e.props.value===o));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:a.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==o})))})}function y(e){const t=x(e);return(0,b.jsxs)("div",{className:(0,r.A)("tabs-container",f.tabList),children:[(0,b.jsx)(g,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function w(e){const t=(0,m.A)();return(0,b.jsx)(y,{...e,children:j(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>a,x:()=>l});var n=s(6540);const r={},o=n.createContext(r);function a(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/9d036230.992329cf.js b/assets/js/9d036230.f9704aa5.js similarity index 98% rename from assets/js/9d036230.992329cf.js rename to assets/js/9d036230.f9704aa5.js index d16cbbb43a..819e3a416f 100644 --- a/assets/js/9d036230.992329cf.js +++ b/assets/js/9d036230.f9704aa5.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8810],{1592:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>d,frontMatter:()=>r,metadata:()=>n,toc:()=>h});const n=JSON.parse('{"id":"contributing","title":"Contributing","description":"When contributing to this repository, please first discuss the change you wish to make via ts-jest GitHub discussion or issue with the owners of this repository before making a change.","source":"@site/versioned_docs/version-29.0/contributing.md","sourceDirName":".","slug":"/contributing","permalink":"/ts-jest/docs/29.0/contributing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/contributing.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"contributing","title":"Contributing"},"sidebar":"version-29.0-docs","previous":{"title":"Processing flow","permalink":"/ts-jest/docs/29.0/processing"},"next":{"title":"Installation","permalink":"/ts-jest/docs/29.0/getting-started/installation"}}');var i=s(4848),o=s(8453);const r={id:"contributing",title:"Contributing"},c=void 0,a={},h=[{value:"Pull Request Process",id:"pull-request-process",level:2},{value:"E2E Testing",id:"e2e-testing",level:2},{value:"Preparing",id:"preparing",level:3},{value:"Running",id:"running",level:3}];function l(e){const t={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,i.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,i.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,i.jsx)(t.a,{href:"https://github.com/kulshekhar/ts-jest/issues",children:"issue"})," with the owners of this repository before making a change."]}),"\n",(0,i.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,i.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,i.jsxs)(t.ol,{children:["\n",(0,i.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,i.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,i.jsxs)(t.li,{children:["Update the ",(0,i.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,i.jsx)(t.li,{children:"If possible, squash your commits. There must be only one commit in your PR (until a review). Then after each review requesting changes, DO NOT squash your commits with the one before the review, so that we can see intermediate modifications."}),"\n",(0,i.jsx)(t.li,{children:"You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you."}),"\n"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,i.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,i.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,i.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,i.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,i.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLBBRgGm4BpxA-eMEAmYxH6EEUrNW0StG--ODh9xGkQotnxP32D6YQ8z8L5TZovtKXlLcEPq5US9cdxzfQIjaQ24oET9pShUutHbxtOO9nf390oHhBASeHDXKp0a3fbiJ5DWWjAyO0tn0iVnIRcdt_Jwh-iow3XswJPxbalNzSZV10rWDVGnqA88WhS_87dd66GcqNGmMoVsX6eC4MI7gPXwgrGV_VQV2JOIMB07U01TzzeVL7b4jMClwLw2uqY3XdYhyzw2YZuuQQfDi_AIUr3q4XnrSt1NJwdVzYQV29K4nMD-AwZDXZpcmi9omyYU4iOOPXoi7SUjZKEATWkusE5YpmGVXajXVyaLoJhCfDPPjQqn0F0ZSx89msJbJAukqq0JQGxlzErg-uWiCrYIMkzHXOY1w-_1nnsLcxdFb89Auq_eJvd-JpDJvKMVsLldHMMDh8JhugpIKqzVd-p-KYJkVd0k2DN6D2N1uxnouRVMcAHX-GG0"}),"\n",(0,i.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,i.jsxs)(t.p,{children:["When a test-case needs to be run with a given template within tests, here is what's happening (in ",(0,i.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/hLHDRzim3BthLn3OOGcsfC2E3R2TUzfFI1I9ZjN8f23IJOAX--s3PBknksAdtGoQ7-yzFahKPZNcqMMqYd3XV0OVyiuGAq8EfrRDatwE4Ou8FZGDPYI5X1aKHJVE2XfBVenqAPOsHoj1jWR9G-bZDjy1l-73x_s-3F0Xx-NMnK3d_VxXrrJrMZx7bgyxOq83gzOAM23skE_Ozn6beFkn1csHO7L3MPl7iTSYRIGGiL5ZNpXuoBZ9FL6W4r3g892eZT4qd06jQoiTABEXq9b0xUuaC0h2YdXTGg4fed6wGHCAgYPpDokQgMTZ77C2tHNo8OFDQ1odW1wKP_Ed9HYyEamAXpcnGu5d3icwiptX9h8xRv-5wN07QYvjY0YhDsfb_31z6k53NbU1Wu2GJTAork27mjuDKVMS2kekq2ddW5BOm5Y0tYm82VVP3Po5GLkhfa_UQjc5jjZ1XVleeSO6e2sQiQZXw37FoDKrZD2VKNJhc9fmsZxB0dp9MFw68D3qv3GmlNEGAqkw16qXsUflnwH8kd1HZ7mHQBZiHOi5wFGFSmm1rXPpdS3fzYzRBAKoeprWPe_sFnXZm8RagqFkPoy9NR0Ze0LCuUxTxm5NhQjhRYtvYD0odwiwW5VRfLZFo9ooFS8XPNOeibeVuEbdpIatK6WaT6hBGcI6yd4qmaYbibY2GWKBhXVb3ewzGXEkw85iDxn5BvWbC1LbvptANRYssA0IQe8RXJLt_R-ydUWCq2VbpYe_vdvObUp-lh7fADQb_weB8iNTyzr-v8AXosLsESjkOgOJktq5makyJTBFKW81CG5UWzIJAkQvX1Y1i7h77D-Cn2-O8P2o6T_Z0ao6LtXwUcUclXibe_QP8AFqiV8NvVG7"})]})}function d(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>r,x:()=>c});var n=s(6540);const i={},o=n.createContext(i);function r(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8810],{1592:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>d,frontMatter:()=>r,metadata:()=>n,toc:()=>h});const n=JSON.parse('{"id":"contributing","title":"Contributing","description":"When contributing to this repository, please first discuss the change you wish to make via ts-jest GitHub discussion or issue with the owners of this repository before making a change.","source":"@site/versioned_docs/version-29.0/contributing.md","sourceDirName":".","slug":"/contributing","permalink":"/ts-jest/docs/29.0/contributing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/contributing.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"contributing","title":"Contributing"},"sidebar":"version-29.0-docs","previous":{"title":"Processing flow","permalink":"/ts-jest/docs/29.0/processing"},"next":{"title":"Installation","permalink":"/ts-jest/docs/29.0/getting-started/installation"}}');var i=s(4848),o=s(8453);const r={id:"contributing",title:"Contributing"},c=void 0,a={},h=[{value:"Pull Request Process",id:"pull-request-process",level:2},{value:"E2E Testing",id:"e2e-testing",level:2},{value:"Preparing",id:"preparing",level:3},{value:"Running",id:"running",level:3}];function l(e){const t={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,i.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,i.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,i.jsx)(t.a,{href:"https://github.com/kulshekhar/ts-jest/issues",children:"issue"})," with the owners of this repository before making a change."]}),"\n",(0,i.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,i.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,i.jsxs)(t.ol,{children:["\n",(0,i.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,i.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,i.jsxs)(t.li,{children:["Update the ",(0,i.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,i.jsx)(t.li,{children:"If possible, squash your commits. There must be only one commit in your PR (until a review). Then after each review requesting changes, DO NOT squash your commits with the one before the review, so that we can see intermediate modifications."}),"\n",(0,i.jsx)(t.li,{children:"You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you."}),"\n"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,i.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,i.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,i.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,i.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,i.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLBBRgGm4BpxA-eMEAmYxH6EEUrNW0StG--ODh9xGkQotnxP32D6YQ8z8L5TZovtKXlLcEPq5US9cdxzfQIjaQ24oET9pShUutHbxtOO9nf390oHhBASeHDXKp0a3fbiJ5DWWjAyO0tn0iVnIRcdt_Jwh-iow3XswJPxbalNzSZV10rWDVGnqA88WhS_87dd66GcqNGmMoVsX6eC4MI7gPXwgrGV_VQV2JOIMB07U01TzzeVL7b4jMClwLw2uqY3XdYhyzw2YZuuQQfDi_AIUr3q4XnrSt1NJwdVzYQV29K4nMD-AwZDXZpcmi9omyYU4iOOPXoi7SUjZKEATWkusE5YpmGVXajXVyaLoJhCfDPPjQqn0F0ZSx89msJbJAukqq0JQGxlzErg-uWiCrYIMkzHXOY1w-_1nnsLcxdFb89Auq_eJvd-JpDJvKMVsLldHMMDh8JhugpIKqzVd-p-KYJkVd0k2DN6D2N1uxnouRVMcAHX-GG0"}),"\n",(0,i.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,i.jsxs)(t.p,{children:["When a test-case needs to be run with a given template within tests, here is what's happening (in ",(0,i.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/hLHDRzim3BthLn3OOGcsfC2E3R2TUzfFI1I9ZjN8f23IJOAX--s3PBknksAdtGoQ7-yzFahKPZNcqMMqYd3XV0OVyiuGAq8EfrRDatwE4Ou8FZGDPYI5X1aKHJVE2XfBVenqAPOsHoj1jWR9G-bZDjy1l-73x_s-3F0Xx-NMnK3d_VxXrrJrMZx7bgyxOq83gzOAM23skE_Ozn6beFkn1csHO7L3MPl7iTSYRIGGiL5ZNpXuoBZ9FL6W4r3g892eZT4qd06jQoiTABEXq9b0xUuaC0h2YdXTGg4fed6wGHCAgYPpDokQgMTZ77C2tHNo8OFDQ1odW1wKP_Ed9HYyEamAXpcnGu5d3icwiptX9h8xRv-5wN07QYvjY0YhDsfb_31z6k53NbU1Wu2GJTAork27mjuDKVMS2kekq2ddW5BOm5Y0tYm82VVP3Po5GLkhfa_UQjc5jjZ1XVleeSO6e2sQiQZXw37FoDKrZD2VKNJhc9fmsZxB0dp9MFw68D3qv3GmlNEGAqkw16qXsUflnwH8kd1HZ7mHQBZiHOi5wFGFSmm1rXPpdS3fzYzRBAKoeprWPe_sFnXZm8RagqFkPoy9NR0Ze0LCuUxTxm5NhQjhRYtvYD0odwiwW5VRfLZFo9ooFS8XPNOeibeVuEbdpIatK6WaT6hBGcI6yd4qmaYbibY2GWKBhXVb3ewzGXEkw85iDxn5BvWbC1LbvptANRYssA0IQe8RXJLt_R-ydUWCq2VbpYe_vdvObUp-lh7fADQb_weB8iNTyzr-v8AXosLsESjkOgOJktq5makyJTBFKW81CG5UWzIJAkQvX1Y1i7h77D-Cn2-O8P2o6T_Z0ao6LtXwUcUclXibe_QP8AFqiV8NvVG7"})]})}function d(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>r,x:()=>c});var n=s(6540);const i={},o=n.createContext(i);function r(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/9ed06f50.296535f3.js b/assets/js/9ed06f50.04a0976b.js similarity index 98% rename from assets/js/9ed06f50.296535f3.js rename to assets/js/9ed06f50.04a0976b.js index 9431494c1f..2784b6aef8 100644 --- a/assets/js/9ed06f50.296535f3.js +++ b/assets/js/9ed06f50.04a0976b.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5174],{1128:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>a,contentTitle:()=>c,default:()=>g,frontMatter:()=>r,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"migration","title":"Migration from <=23.10","description":"You can use the config:migrate tool of ts-jest CLI if you\'re coming from an older version to help you migrate your Jest configuration.","source":"@site/versioned_docs/version-28.0/migration.md","sourceDirName":".","slug":"/migration","permalink":"/ts-jest/docs/28.0/migration","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/migration.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"migration","title":"Migration from <=23.10"},"sidebar":"version-28.0-docs","previous":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/28.0/babel7-or-ts"},"next":{"title":"Debugging ts-jest","permalink":"/ts-jest/docs/28.0/debugging"}}');var o=t(4848),i=t(8453);const r={id:"migration",title:"Migration from <=23.10"},c=void 0,a={},d=[{value:"NPM",id:"npm",level:3},{value:"Yarn",id:"yarn",level:3},{value:"NPM",id:"npm-1",level:3},{value:"Yarn",id:"yarn-1",level:3}];function l(e){const n={code:"code",em:"em",h3:"h3",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:["You can use the ",(0,o.jsx)(n.code,{children:"config:migrate"})," tool of ",(0,o.jsx)(n.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsxs)(n.em,{children:["If you're using ",(0,o.jsx)(n.code,{children:"jest.config.js"}),":"]})}),"\n",(0,o.jsx)(n.h3,{id:"npm",children:"NPM"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate jest.config.js\n"})}),"\n",(0,o.jsx)(n.h3,{id:"yarn",children:"Yarn"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate jest.config.js\n"})}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsxs)(n.em,{children:["If you're using ",(0,o.jsx)(n.code,{children:"jest"})," config property of ",(0,o.jsx)(n.code,{children:"package.json"}),":"]})}),"\n",(0,o.jsx)(n.h3,{id:"npm-1",children:"NPM"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate package.json\n"})}),"\n",(0,o.jsx)(n.h3,{id:"yarn-1",children:"Yarn"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate package.json\n"})})]})}function g(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>r,x:()=>c});var s=t(6540);const o={},i=s.createContext(o);function r(e){const n=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function c(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5174],{1128:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>a,contentTitle:()=>c,default:()=>g,frontMatter:()=>r,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"migration","title":"Migration from <=23.10","description":"You can use the config:migrate tool of ts-jest CLI if you\'re coming from an older version to help you migrate your Jest configuration.","source":"@site/versioned_docs/version-28.0/migration.md","sourceDirName":".","slug":"/migration","permalink":"/ts-jest/docs/28.0/migration","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/migration.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"migration","title":"Migration from <=23.10"},"sidebar":"version-28.0-docs","previous":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/28.0/babel7-or-ts"},"next":{"title":"Debugging ts-jest","permalink":"/ts-jest/docs/28.0/debugging"}}');var o=t(4848),i=t(8453);const r={id:"migration",title:"Migration from <=23.10"},c=void 0,a={},d=[{value:"NPM",id:"npm",level:3},{value:"Yarn",id:"yarn",level:3},{value:"NPM",id:"npm-1",level:3},{value:"Yarn",id:"yarn-1",level:3}];function l(e){const n={code:"code",em:"em",h3:"h3",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:["You can use the ",(0,o.jsx)(n.code,{children:"config:migrate"})," tool of ",(0,o.jsx)(n.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsxs)(n.em,{children:["If you're using ",(0,o.jsx)(n.code,{children:"jest.config.js"}),":"]})}),"\n",(0,o.jsx)(n.h3,{id:"npm",children:"NPM"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate jest.config.js\n"})}),"\n",(0,o.jsx)(n.h3,{id:"yarn",children:"Yarn"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate jest.config.js\n"})}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsxs)(n.em,{children:["If you're using ",(0,o.jsx)(n.code,{children:"jest"})," config property of ",(0,o.jsx)(n.code,{children:"package.json"}),":"]})}),"\n",(0,o.jsx)(n.h3,{id:"npm-1",children:"NPM"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate package.json\n"})}),"\n",(0,o.jsx)(n.h3,{id:"yarn-1",children:"Yarn"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate package.json\n"})})]})}function g(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>r,x:()=>c});var s=t(6540);const o={},i=s.createContext(o);function r(e){const n=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function c(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/a09c2993.e6b9df8d.js b/assets/js/a09c2993.bdfd098b.js similarity index 97% rename from assets/js/a09c2993.e6b9df8d.js rename to assets/js/a09c2993.bdfd098b.js index dbd79661d1..17f7d0fe03 100644 --- a/assets/js/a09c2993.e6b9df8d.js +++ b/assets/js/a09c2993.bdfd098b.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5899],{4778:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>n,toc:()=>a});const n=JSON.parse('{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","source":"@site/docs/introduction.md","sourceDirName":".","slug":"/","permalink":"/ts-jest/docs/next/","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/introduction.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","slug":"/"},"sidebar":"docs","next":{"title":"Processing flow","permalink":"/ts-jest/docs/next/processing"}}');var o=s(4848),r=s(8453);const i={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},c=void 0,d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,r.R)(),...t.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(e.p,{children:[(0,o.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,o.jsx)(e.a,{href:"https://jestjs.io/docs/next/code-transformation#writing-custom-transformers",children:"transformer"})," with source map support that lets you use Jest to test projects written in TypeScript."]}),"\n",(0,o.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,o.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,o.jsx)(e.code,{children:"preset-typescript"})," ",(0,o.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,o.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,o.jsx)(e.admonition,{type:"important",children:(0,o.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,o.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,o.jsx)(e.code,{children:'npm i -D ts-jest@"<23.10.0"'})," to go back to the previous version"]})})]})}function u(t={}){const{wrapper:e}={...(0,r.R)(),...t.components};return e?(0,o.jsx)(e,{...t,children:(0,o.jsx)(p,{...t})}):p(t)}},8453:(t,e,s)=>{s.d(e,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(t){const e=n.useContext(r);return n.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function c(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:i(t.components),n.createElement(r.Provider,{value:e},t.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5899],{4778:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>n,toc:()=>a});const n=JSON.parse('{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","source":"@site/docs/introduction.md","sourceDirName":".","slug":"/","permalink":"/ts-jest/docs/next/","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/introduction.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","slug":"/"},"sidebar":"docs","next":{"title":"Processing flow","permalink":"/ts-jest/docs/next/processing"}}');var o=s(4848),r=s(8453);const i={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},c=void 0,d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,r.R)(),...t.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(e.p,{children:[(0,o.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,o.jsx)(e.a,{href:"https://jestjs.io/docs/next/code-transformation#writing-custom-transformers",children:"transformer"})," with source map support that lets you use Jest to test projects written in TypeScript."]}),"\n",(0,o.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,o.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,o.jsx)(e.code,{children:"preset-typescript"})," ",(0,o.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,o.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,o.jsx)(e.admonition,{type:"important",children:(0,o.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,o.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,o.jsx)(e.code,{children:'npm i -D ts-jest@"<23.10.0"'})," to go back to the previous version"]})})]})}function u(t={}){const{wrapper:e}={...(0,r.R)(),...t.components};return e?(0,o.jsx)(e,{...t,children:(0,o.jsx)(p,{...t})}):p(t)}},8453:(t,e,s)=>{s.d(e,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(t){const e=n.useContext(r);return n.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function c(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:i(t.components),n.createElement(r.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/a132b5de.645f7642.js b/assets/js/a132b5de.53d8d570.js similarity index 99% rename from assets/js/a132b5de.645f7642.js rename to assets/js/a132b5de.53d8d570.js index 5dc73927c4..2154d319a5 100644 --- a/assets/js/a132b5de.645f7642.js +++ b/assets/js/a132b5de.53d8d570.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7132],{6376:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>l,metadata:()=>i,toc:()=>d});const i=JSON.parse('{"id":"getting-started/options/diagnostics","title":"Diagnostics option","description":"The diagnostics option configures error reporting.","source":"@site/versioned_docs/version-27.0/getting-started/options/diagnostics.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/diagnostics","permalink":"/ts-jest/docs/27.0/getting-started/options/diagnostics","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/options/diagnostics.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Diagnostics option"}}');var o=s(4848),t=s(8453);const l={title:"Diagnostics option"},r=void 0,c={},d=[{value:"Disabling/enabling",id:"disablingenabling",level:3},{value:"Advanced configuration",id:"advanced-configuration",level:3},{value:"Examples",id:"examples",level:3},{value:"Disabling diagnostics",id:"disabling-diagnostics",level:4},{value:"Advanced options",id:"advanced-options",level:4},{value:"Enabling diagnostics for test files only",id:"enabling-diagnostics-for-test-files-only",level:5},{value:"Do not fail on first error",id:"do-not-fail-on-first-error",level:5},{value:"Ignoring some error codes",id:"ignoring-some-error-codes",level:5}];function a(e){const n={a:"a",code:"code",em:"em",h3:"h3",h4:"h4",h5:"h5",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,t.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:["The ",(0,o.jsx)(n.code,{children:"diagnostics"})," option configures error reporting.\nIt can both be enabled/disabled entirely or limited to a specific type of errors and/or files."]}),"\n",(0,o.jsxs)(n.p,{children:["If a diagnostic is not filtered out, ",(0,o.jsx)(n.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,o.jsx)(n.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,o.jsxs)(n.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,o.jsx)(n.code,{children:"diagnostics"})," option to ",(0,o.jsx)(n.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,o.jsx)(n.code,{children:"diagnostics"})," to ",(0,o.jsx)(n.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,o.jsx)(n.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,o.jsxs)(n.p,{children:["The ",(0,o.jsx)(n.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"warnOnly"})}),": If specified and ",(0,o.jsx)(n.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,o.jsx)(n.em,{children:"disabled"}),")."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,o.jsx)(n.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". By default here are the ones ignored:","\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"6059"}),": ",(0,o.jsx)(n.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"18002"}),": ",(0,o.jsx)(n.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"18003"}),": ",(0,o.jsx)(n.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,o.jsx)(n.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,o.jsx)(n.code,{children:"tsconfig"})," option ",(0,o.jsx)(n.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,o.jsx)(n.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,o.jsx)(n.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,o.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsx)(n.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: false,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": false\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,o.jsx)(n.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,o.jsxs)(n.p,{children:["Assuming all your test files ends with ",(0,o.jsx)(n.code,{children:".spec.ts"})," or ",(0,o.jsx)(n.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: {\n exclude: ['!**/*.(spec|test).ts'],\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": {\n "exclude": ["!**/*.(spec|test).ts"]\n }\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,o.jsxs)(n.p,{children:["While some diagnostics are stop-blockers for the compilation, most of them are not. If you want the compilation (and so your tests) to continue when encountering those, set the ",(0,o.jsx)(n.code,{children:"warnOnly"})," to ",(0,o.jsx)(n.code,{children:"true"}),":"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: {\n warnOnly: true,\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": {\n "warnOnly": true\n }\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,o.jsxs)(n.p,{children:["All TypeScript error codes can be found ",(0,o.jsx)(n.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,o.jsx)(n.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,o.jsxs)(n.ol,{children:["\n",(0,o.jsxs)(n.li,{children:["A single ",(0,o.jsx)(n.code,{children:"number"})," (example: ",(0,o.jsx)(n.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,o.jsxs)(n.li,{children:["A ",(0,o.jsx)(n.code,{children:"string"})," with a code (example ",(0,o.jsx)(n.code,{children:'"1009"'}),", ",(0,o.jsx)(n.code,{children:'"TS1009"'})," or ",(0,o.jsx)(n.code,{children:'"TS1009"'}),")"]}),"\n",(0,o.jsxs)(n.li,{children:["A ",(0,o.jsx)(n.code,{children:"string"})," with a list of the above (example: ",(0,o.jsx)(n.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,o.jsxs)(n.li,{children:["An ",(0,o.jsx)(n.code,{children:"array"})," of one or more from ",(0,o.jsx)(n.code,{children:"1"})," or ",(0,o.jsx)(n.code,{children:"3"})," (example: ",(0,o.jsx)(n.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: {\n ignoreCodes: [2571, 6031, 18003],\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": {\n "ignoreCodes": [2571, 6031, 18003]\n }\n }\n }\n }\n}\n'})})]})}function h(e={}){const{wrapper:n}={...(0,t.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(a,{...e})}):a(e)}},8453:(e,n,s)=>{s.d(n,{R:()=>l,x:()=>r});var i=s(6540);const o={},t=i.createContext(o);function l(e){const n=i.useContext(t);return i.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function r(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:l(e.components),i.createElement(t.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7132],{6376:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>l,metadata:()=>i,toc:()=>d});const i=JSON.parse('{"id":"getting-started/options/diagnostics","title":"Diagnostics option","description":"The diagnostics option configures error reporting.","source":"@site/versioned_docs/version-27.0/getting-started/options/diagnostics.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/diagnostics","permalink":"/ts-jest/docs/27.0/getting-started/options/diagnostics","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/options/diagnostics.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Diagnostics option"}}');var o=s(4848),t=s(8453);const l={title:"Diagnostics option"},r=void 0,c={},d=[{value:"Disabling/enabling",id:"disablingenabling",level:3},{value:"Advanced configuration",id:"advanced-configuration",level:3},{value:"Examples",id:"examples",level:3},{value:"Disabling diagnostics",id:"disabling-diagnostics",level:4},{value:"Advanced options",id:"advanced-options",level:4},{value:"Enabling diagnostics for test files only",id:"enabling-diagnostics-for-test-files-only",level:5},{value:"Do not fail on first error",id:"do-not-fail-on-first-error",level:5},{value:"Ignoring some error codes",id:"ignoring-some-error-codes",level:5}];function a(e){const n={a:"a",code:"code",em:"em",h3:"h3",h4:"h4",h5:"h5",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,t.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:["The ",(0,o.jsx)(n.code,{children:"diagnostics"})," option configures error reporting.\nIt can both be enabled/disabled entirely or limited to a specific type of errors and/or files."]}),"\n",(0,o.jsxs)(n.p,{children:["If a diagnostic is not filtered out, ",(0,o.jsx)(n.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,o.jsx)(n.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,o.jsxs)(n.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,o.jsx)(n.code,{children:"diagnostics"})," option to ",(0,o.jsx)(n.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,o.jsx)(n.code,{children:"diagnostics"})," to ",(0,o.jsx)(n.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,o.jsx)(n.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,o.jsxs)(n.p,{children:["The ",(0,o.jsx)(n.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"warnOnly"})}),": If specified and ",(0,o.jsx)(n.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,o.jsx)(n.em,{children:"disabled"}),")."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,o.jsx)(n.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". By default here are the ones ignored:","\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"6059"}),": ",(0,o.jsx)(n.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"18002"}),": ",(0,o.jsx)(n.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"18003"}),": ",(0,o.jsx)(n.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,o.jsx)(n.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,o.jsx)(n.code,{children:"tsconfig"})," option ",(0,o.jsx)(n.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,o.jsx)(n.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,o.jsx)(n.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,o.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsx)(n.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: false,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": false\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,o.jsx)(n.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,o.jsxs)(n.p,{children:["Assuming all your test files ends with ",(0,o.jsx)(n.code,{children:".spec.ts"})," or ",(0,o.jsx)(n.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: {\n exclude: ['!**/*.(spec|test).ts'],\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": {\n "exclude": ["!**/*.(spec|test).ts"]\n }\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,o.jsxs)(n.p,{children:["While some diagnostics are stop-blockers for the compilation, most of them are not. If you want the compilation (and so your tests) to continue when encountering those, set the ",(0,o.jsx)(n.code,{children:"warnOnly"})," to ",(0,o.jsx)(n.code,{children:"true"}),":"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: {\n warnOnly: true,\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": {\n "warnOnly": true\n }\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,o.jsxs)(n.p,{children:["All TypeScript error codes can be found ",(0,o.jsx)(n.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,o.jsx)(n.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,o.jsxs)(n.ol,{children:["\n",(0,o.jsxs)(n.li,{children:["A single ",(0,o.jsx)(n.code,{children:"number"})," (example: ",(0,o.jsx)(n.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,o.jsxs)(n.li,{children:["A ",(0,o.jsx)(n.code,{children:"string"})," with a code (example ",(0,o.jsx)(n.code,{children:'"1009"'}),", ",(0,o.jsx)(n.code,{children:'"TS1009"'})," or ",(0,o.jsx)(n.code,{children:'"TS1009"'}),")"]}),"\n",(0,o.jsxs)(n.li,{children:["A ",(0,o.jsx)(n.code,{children:"string"})," with a list of the above (example: ",(0,o.jsx)(n.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,o.jsxs)(n.li,{children:["An ",(0,o.jsx)(n.code,{children:"array"})," of one or more from ",(0,o.jsx)(n.code,{children:"1"})," or ",(0,o.jsx)(n.code,{children:"3"})," (example: ",(0,o.jsx)(n.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: {\n ignoreCodes: [2571, 6031, 18003],\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": {\n "ignoreCodes": [2571, 6031, 18003]\n }\n }\n }\n }\n}\n'})})]})}function h(e={}){const{wrapper:n}={...(0,t.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(a,{...e})}):a(e)}},8453:(e,n,s)=>{s.d(n,{R:()=>l,x:()=>r});var i=s(6540);const o={},t=i.createContext(o);function l(e){const n=i.useContext(t);return i.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function r(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:l(e.components),i.createElement(t.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/a21658d9.27d7fd56.js b/assets/js/a21658d9.f60aa266.js similarity index 98% rename from assets/js/a21658d9.27d7fd56.js rename to assets/js/a21658d9.f60aa266.js index e0db66ef23..7ec40a3a19 100644 --- a/assets/js/a21658d9.27d7fd56.js +++ b/assets/js/a21658d9.f60aa266.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1173],{1297:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>u,frontMatter:()=>c,metadata:()=>n,toc:()=>l});const n=JSON.parse('{"id":"guides/react-native","title":"Using with React Native","description":"To use ts-jest with React Native + TypeScript and Babel 7, you\'ll first need to follow this tutorial.","source":"@site/versioned_docs/version-28.0/guides/react-native.md","sourceDirName":"guides","slug":"/guides/react-native","permalink":"/ts-jest/docs/28.0/guides/react-native","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/guides/react-native.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"react-native","title":"Using with React Native"},"sidebar":"version-28.0-docs","previous":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/28.0/guides/mock-es6-class"},"next":{"title":"Troubleshooting","permalink":"/ts-jest/docs/28.0/guides/troubleshooting"}}');var o=s(4848),i=s(8453);const c={id:"react-native",title:"Using with React Native"},r=void 0,a={},l=[{value:"Babel config",id:"babel-config",level:3},{value:"TypeScript Configuration",id:"typescript-configuration",level:3},{value:"Jest config",id:"jest-config",level:3}];function d(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["To use ",(0,o.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,o.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,o.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,o.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,o.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,o.jsx)(t.code,{children:".babelrc"})," to ",(0,o.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// babel.config.js\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n"})}),"\n",(0,o.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,o.jsxs)(t.p,{children:["Create a new ",(0,o.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// tsconfig.spec.json\n{\n "extends": "./tsconfig.json",\n "compilerOptions": {\n "jsx": "react"\n }\n}\n'})}),"\n",(0,o.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,o.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,o.jsx)(t.code,{children:"jest"})," key of ",(0,o.jsx)(t.code,{children:"package.json"})," to ",(0,o.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n\nmodule.exports = {\n preset: 'react-native',\n globals: {\n 'ts-jest': {\n tsconfig: 'tsconfig.spec.json',\n },\n },\n transform: {\n '^.+\\\\.jsx$': 'babel-jest',\n '^.+\\\\.tsx?$': 'ts-jest',\n },\n moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],\n}\n"})})]})}function u(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>c,x:()=>r});var n=s(6540);const o={},i=n.createContext(o);function c(e){const t=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:c(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1173],{1297:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>u,frontMatter:()=>c,metadata:()=>n,toc:()=>l});const n=JSON.parse('{"id":"guides/react-native","title":"Using with React Native","description":"To use ts-jest with React Native + TypeScript and Babel 7, you\'ll first need to follow this tutorial.","source":"@site/versioned_docs/version-28.0/guides/react-native.md","sourceDirName":"guides","slug":"/guides/react-native","permalink":"/ts-jest/docs/28.0/guides/react-native","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/guides/react-native.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"react-native","title":"Using with React Native"},"sidebar":"version-28.0-docs","previous":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/28.0/guides/mock-es6-class"},"next":{"title":"Troubleshooting","permalink":"/ts-jest/docs/28.0/guides/troubleshooting"}}');var o=s(4848),i=s(8453);const c={id:"react-native",title:"Using with React Native"},r=void 0,a={},l=[{value:"Babel config",id:"babel-config",level:3},{value:"TypeScript Configuration",id:"typescript-configuration",level:3},{value:"Jest config",id:"jest-config",level:3}];function d(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["To use ",(0,o.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,o.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,o.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,o.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,o.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,o.jsx)(t.code,{children:".babelrc"})," to ",(0,o.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// babel.config.js\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n"})}),"\n",(0,o.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,o.jsxs)(t.p,{children:["Create a new ",(0,o.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// tsconfig.spec.json\n{\n "extends": "./tsconfig.json",\n "compilerOptions": {\n "jsx": "react"\n }\n}\n'})}),"\n",(0,o.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,o.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,o.jsx)(t.code,{children:"jest"})," key of ",(0,o.jsx)(t.code,{children:"package.json"})," to ",(0,o.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n\nmodule.exports = {\n preset: 'react-native',\n globals: {\n 'ts-jest': {\n tsconfig: 'tsconfig.spec.json',\n },\n },\n transform: {\n '^.+\\\\.jsx$': 'babel-jest',\n '^.+\\\\.tsx?$': 'ts-jest',\n },\n moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],\n}\n"})})]})}function u(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>c,x:()=>r});var n=s(6540);const o={},i=n.createContext(o);function c(e){const t=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:c(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/a5ea8355.63e9e00c.js b/assets/js/a5ea8355.2199c8e1.js similarity index 98% rename from assets/js/a5ea8355.63e9e00c.js rename to assets/js/a5ea8355.2199c8e1.js index c7f479e440..028cd268bd 100644 --- a/assets/js/a5ea8355.63e9e00c.js +++ b/assets/js/a5ea8355.2199c8e1.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3762],{9687:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>h,frontMatter:()=>l,metadata:()=>n,toc:()=>c});const n=JSON.parse('{"id":"getting-started/options/isolatedModules","title":"Isolated Modules option","description":"By default ts-jest uses TypeScript compiler in the context of a project (yours), with full type-checking and features.","source":"@site/versioned_docs/version-27.1/getting-started/options/isolatedModules.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/isolatedModules","permalink":"/ts-jest/docs/27.1/getting-started/options/isolatedModules","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/options/isolatedModules.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Isolated Modules option"}}');var o=s(4848),i=s(8453);const l={title:"Isolated Modules option"},a=void 0,d={},c=[{value:"Example",id:"example",level:3},{value:"Performance",id:"performance",level:2},{value:"Example",id:"example-1",level:3},{value:"Caveats",id:"caveats",level:2}];function r(e){const t={code:"code",h2:"h2",h3:"h3",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["By default ",(0,o.jsx)(t.code,{children:"ts-jest"})," uses TypeScript compiler in the context of a project (yours), with full type-checking and features.\nBut it can also be used to compile each file separately, what TypeScript calls an 'isolated module'.\nThat's what the ",(0,o.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,o.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,o.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,o.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,o.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,o.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n isolatedModules: true,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "isolatedModules": true\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,o.jsxs)(t.p,{children:["Using ",(0,o.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,o.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,o.jsx)(t.code,{children:"include"})," in ",(0,o.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,o.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,o.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,o.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,o.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,o.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,o.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,o.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,o.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,o.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,o.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function h(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(r,{...e})}):r(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>l,x:()=>a});var n=s(6540);const o={},i=n.createContext(o);function l(e){const t=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:l(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3762],{9687:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>h,frontMatter:()=>l,metadata:()=>n,toc:()=>c});const n=JSON.parse('{"id":"getting-started/options/isolatedModules","title":"Isolated Modules option","description":"By default ts-jest uses TypeScript compiler in the context of a project (yours), with full type-checking and features.","source":"@site/versioned_docs/version-27.1/getting-started/options/isolatedModules.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/isolatedModules","permalink":"/ts-jest/docs/27.1/getting-started/options/isolatedModules","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/options/isolatedModules.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Isolated Modules option"}}');var o=s(4848),i=s(8453);const l={title:"Isolated Modules option"},a=void 0,d={},c=[{value:"Example",id:"example",level:3},{value:"Performance",id:"performance",level:2},{value:"Example",id:"example-1",level:3},{value:"Caveats",id:"caveats",level:2}];function r(e){const t={code:"code",h2:"h2",h3:"h3",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["By default ",(0,o.jsx)(t.code,{children:"ts-jest"})," uses TypeScript compiler in the context of a project (yours), with full type-checking and features.\nBut it can also be used to compile each file separately, what TypeScript calls an 'isolated module'.\nThat's what the ",(0,o.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,o.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,o.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,o.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,o.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,o.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n isolatedModules: true,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "isolatedModules": true\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,o.jsxs)(t.p,{children:["Using ",(0,o.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,o.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,o.jsx)(t.code,{children:"include"})," in ",(0,o.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,o.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,o.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,o.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,o.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,o.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,o.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,o.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,o.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,o.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,o.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function h(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(r,{...e})}):r(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>l,x:()=>a});var n=s(6540);const o={},i=n.createContext(o);function l(e){const t=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:l(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/a6267c3c.9fe1c460.js b/assets/js/a6267c3c.bf4e5e2b.js similarity index 97% rename from assets/js/a6267c3c.9fe1c460.js rename to assets/js/a6267c3c.bf4e5e2b.js index d372703480..bd65795845 100644 --- a/assets/js/a6267c3c.9fe1c460.js +++ b/assets/js/a6267c3c.bf4e5e2b.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6586],{4967:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>n,toc:()=>a});const n=JSON.parse('{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","source":"@site/versioned_docs/version-28.0/introduction.md","sourceDirName":".","slug":"/","permalink":"/ts-jest/docs/28.0/","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/introduction.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","slug":"/"},"sidebar":"version-28.0-docs","next":{"title":"Processing flow","permalink":"/ts-jest/docs/28.0/processing"}}');var o=s(4848),r=s(8453);const i={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},c=void 0,d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,r.R)(),...t.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(e.p,{children:[(0,o.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,o.jsx)(e.a,{href:"https://jestjs.io/docs/next/code-transformation#writing-custom-transformers",children:"transformer"})," with source map support that lets you use Jest to test projects written in TypeScript."]}),"\n",(0,o.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,o.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,o.jsx)(e.code,{children:"preset-typescript"})," ",(0,o.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,o.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,o.jsx)(e.admonition,{type:"important",children:(0,o.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,o.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,o.jsx)(e.code,{children:'npm i -D ts-jest@"<23.10.0"'})," to go back to the previous version"]})})]})}function u(t={}){const{wrapper:e}={...(0,r.R)(),...t.components};return e?(0,o.jsx)(e,{...t,children:(0,o.jsx)(p,{...t})}):p(t)}},8453:(t,e,s)=>{s.d(e,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(t){const e=n.useContext(r);return n.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function c(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:i(t.components),n.createElement(r.Provider,{value:e},t.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6586],{4967:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>n,toc:()=>a});const n=JSON.parse('{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","source":"@site/versioned_docs/version-28.0/introduction.md","sourceDirName":".","slug":"/","permalink":"/ts-jest/docs/28.0/","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/introduction.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","slug":"/"},"sidebar":"version-28.0-docs","next":{"title":"Processing flow","permalink":"/ts-jest/docs/28.0/processing"}}');var o=s(4848),r=s(8453);const i={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},c=void 0,d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,r.R)(),...t.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(e.p,{children:[(0,o.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,o.jsx)(e.a,{href:"https://jestjs.io/docs/next/code-transformation#writing-custom-transformers",children:"transformer"})," with source map support that lets you use Jest to test projects written in TypeScript."]}),"\n",(0,o.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,o.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,o.jsx)(e.code,{children:"preset-typescript"})," ",(0,o.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,o.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,o.jsx)(e.admonition,{type:"important",children:(0,o.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,o.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,o.jsx)(e.code,{children:'npm i -D ts-jest@"<23.10.0"'})," to go back to the previous version"]})})]})}function u(t={}){const{wrapper:e}={...(0,r.R)(),...t.components};return e?(0,o.jsx)(e,{...t,children:(0,o.jsx)(p,{...t})}):p(t)}},8453:(t,e,s)=>{s.d(e,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(t){const e=n.useContext(r);return n.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function c(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:i(t.components),n.createElement(r.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/a7423e3b.47f3318d.js b/assets/js/a7423e3b.635b1547.js similarity index 98% rename from assets/js/a7423e3b.47f3318d.js rename to assets/js/a7423e3b.635b1547.js index 1b1c552b4d..b7e56d88e5 100644 --- a/assets/js/a7423e3b.47f3318d.js +++ b/assets/js/a7423e3b.635b1547.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3322],{4374:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/installation","title":"Installation","description":"Dependencies","source":"@site/versioned_docs/version-29.2/getting-started/installation.md","sourceDirName":"getting-started","slug":"/getting-started/installation","permalink":"/ts-jest/docs/getting-started/installation","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/installation.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"installation","title":"Installation"},"sidebar":"version-29.1-docs","previous":{"title":"Contributing","permalink":"/ts-jest/docs/contributing"},"next":{"title":"Presets","permalink":"/ts-jest/docs/getting-started/presets"}}');var r=n(4848),a=n(8453),i=n(9489),l=n(7227);const o={id:"installation",title:"Installation"},c=void 0,u={},d=[{value:"Dependencies",id:"dependencies",level:3},{value:"Jest config file",id:"jest-config-file",level:3},{value:"Creating",id:"creating",level:4},{value:"Customizing",id:"customizing",level:4}];function h(e){const t={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,r.jsxs)(t.p,{children:["You can install ",(0,r.jsx)(t.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,r.jsxs)(i.A,{groupId:"npm2yarn",children:[(0,r.jsx)(l.A,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})})}),(0,r.jsx)(l.A,{value:"yarn",label:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})})}),(0,r.jsx)(l.A,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"pnpm add --save-dev jest typescript ts-jest @types/jest\n"})})})]}),"\n",(0,r.jsx)(t.admonition,{type:"tip",children:(0,r.jsxs)(t.p,{children:["Tip: If you get an error with the following ",(0,r.jsx)(t.code,{children:"npm"})," commands such as ",(0,r.jsx)(t.code,{children:"npx: command not found"}),", you can replace ",(0,r.jsx)(t.code,{children:"npx XXX"})," with ",(0,r.jsx)(t.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,r.jsx)(t.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,r.jsx)(t.h4,{id:"creating",children:"Creating"}),"\n",(0,r.jsxs)(t.p,{children:["By default, Jest can run without any config files, but it will not compile ",(0,r.jsx)(t.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,r.jsx)(t.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,r.jsx)(t.code,{children:"ts-jest"})," preset."]}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,r.jsxs)(i.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-npm",metastring:"tab",children:"npx ts-jest config:init\n"})})}),(0,r.jsx)(l.A,{value:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-Yarn",metastring:"tab",children:"yarn ts-jest config:init\n"})})})]}),"\n",(0,r.jsxs)(t.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,r.jsx)(t.code,{children:".ts"})," files correctly."]}),"\n",(0,r.jsxs)(t.p,{children:["You can also use the ",(0,r.jsx)(t.code,{children:"jest --init"})," command (prefixed with either ",(0,r.jsx)(t.code,{children:"npx"})," or ",(0,r.jsx)(t.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,r.jsx)(t.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,r.jsx)(t.code,{children:'preset: "ts-jest"'})," to the ",(0,r.jsx)(t.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,r.jsx)(t.h4,{id:"customizing",children:"Customizing"}),"\n",(0,r.jsxs)(t.p,{children:["For customizing jest, please follow their ",(0,r.jsx)(t.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"ts-jest"})," specific options can be found ",(0,r.jsx)(t.a,{href:"/ts-jest/docs/getting-started/options",children:"here"}),"."]})]})}function p(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>i});n(6540);var s=n(4164);const r={tabItem:"tabItem_Ymn6"};var a=n(4848);function i(e){let{children:t,hidden:n,className:i}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,s.A)(r.tabItem,i),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),r=n(4164),a=n(4245),i=n(6347),l=n(6494),o=n(2814),c=n(5167),u=n(9900);function d(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:r}}=e;return{value:t,label:n,attributes:s,default:r}}))}(n);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const r=(0,i.W6)(),a=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,o.aZ)(a),(0,s.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function m(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,a=h(e),[i,o]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:a}))),[c,d]=f({queryString:n,groupId:r}),[m,j]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,u.Dv)(n);return[r,(0,s.useCallback)((e=>{n&&a.set(e)}),[n,a])]}({groupId:r}),g=(()=>{const e=c??m;return p({value:e,tabValues:a})?e:null})();(0,l.A)((()=>{g&&o(g)}),[g]);return{selectedValue:i,selectValue:(0,s.useCallback)((e=>{if(!p({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);o(e),d(e),j(e)}),[d,j,a]),tabValues:a}}var j=n(1062);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=n(4848);function x(e){let{className:t,block:n,selectedValue:s,selectValue:i,tabValues:l}=e;const o=[],{blockElementScrollPositionUntilNextRender:c}=(0,a.a_)(),u=e=>{const t=e.currentTarget,n=o.indexOf(t),r=l[n].value;r!==s&&(c(t),i(r))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=o.indexOf(e.currentTarget)+1;t=o[n]??o[0];break}case"ArrowLeft":{const n=o.indexOf(e.currentTarget)-1;t=o[n]??o[o.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:a}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>o.push(e),onKeyDown:d,onClick:u,...a,className:(0,r.A)("tabs__item",g.tabItem,a?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:a}=e;const i=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=i.find((e=>e.props.value===a));return e?(0,s.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:i.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=m(e);return(0,b.jsxs)("div",{className:(0,r.A)("tabs-container",g.tabList),children:[(0,b.jsx)(x,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function w(e){const t=(0,j.A)();return(0,b.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>i,x:()=>l});var s=n(6540);const r={},a=s.createContext(r);function i(e){const t=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),s.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3322],{4374:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/installation","title":"Installation","description":"Dependencies","source":"@site/versioned_docs/version-29.2/getting-started/installation.md","sourceDirName":"getting-started","slug":"/getting-started/installation","permalink":"/ts-jest/docs/getting-started/installation","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/installation.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"installation","title":"Installation"},"sidebar":"version-29.1-docs","previous":{"title":"Contributing","permalink":"/ts-jest/docs/contributing"},"next":{"title":"Presets","permalink":"/ts-jest/docs/getting-started/presets"}}');var r=n(4848),a=n(8453),i=n(9489),l=n(7227);const o={id:"installation",title:"Installation"},c=void 0,u={},d=[{value:"Dependencies",id:"dependencies",level:3},{value:"Jest config file",id:"jest-config-file",level:3},{value:"Creating",id:"creating",level:4},{value:"Customizing",id:"customizing",level:4}];function h(e){const t={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,r.jsxs)(t.p,{children:["You can install ",(0,r.jsx)(t.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,r.jsxs)(i.A,{groupId:"npm2yarn",children:[(0,r.jsx)(l.A,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})})}),(0,r.jsx)(l.A,{value:"yarn",label:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})})}),(0,r.jsx)(l.A,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"pnpm add --save-dev jest typescript ts-jest @types/jest\n"})})})]}),"\n",(0,r.jsx)(t.admonition,{type:"tip",children:(0,r.jsxs)(t.p,{children:["Tip: If you get an error with the following ",(0,r.jsx)(t.code,{children:"npm"})," commands such as ",(0,r.jsx)(t.code,{children:"npx: command not found"}),", you can replace ",(0,r.jsx)(t.code,{children:"npx XXX"})," with ",(0,r.jsx)(t.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,r.jsx)(t.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,r.jsx)(t.h4,{id:"creating",children:"Creating"}),"\n",(0,r.jsxs)(t.p,{children:["By default, Jest can run without any config files, but it will not compile ",(0,r.jsx)(t.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,r.jsx)(t.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,r.jsx)(t.code,{children:"ts-jest"})," preset."]}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,r.jsxs)(i.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-npm",metastring:"tab",children:"npx ts-jest config:init\n"})})}),(0,r.jsx)(l.A,{value:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-Yarn",metastring:"tab",children:"yarn ts-jest config:init\n"})})})]}),"\n",(0,r.jsxs)(t.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,r.jsx)(t.code,{children:".ts"})," files correctly."]}),"\n",(0,r.jsxs)(t.p,{children:["You can also use the ",(0,r.jsx)(t.code,{children:"jest --init"})," command (prefixed with either ",(0,r.jsx)(t.code,{children:"npx"})," or ",(0,r.jsx)(t.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,r.jsx)(t.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,r.jsx)(t.code,{children:'preset: "ts-jest"'})," to the ",(0,r.jsx)(t.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,r.jsx)(t.h4,{id:"customizing",children:"Customizing"}),"\n",(0,r.jsxs)(t.p,{children:["For customizing jest, please follow their ",(0,r.jsx)(t.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"ts-jest"})," specific options can be found ",(0,r.jsx)(t.a,{href:"/ts-jest/docs/getting-started/options",children:"here"}),"."]})]})}function p(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>i});n(6540);var s=n(4164);const r={tabItem:"tabItem_Ymn6"};var a=n(4848);function i(e){let{children:t,hidden:n,className:i}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,s.A)(r.tabItem,i),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),r=n(4164),a=n(4245),i=n(6347),l=n(6494),o=n(2814),c=n(5167),u=n(9900);function d(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:r}}=e;return{value:t,label:n,attributes:s,default:r}}))}(n);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const r=(0,i.W6)(),a=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,o.aZ)(a),(0,s.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function m(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,a=h(e),[i,o]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:a}))),[c,d]=f({queryString:n,groupId:r}),[m,j]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,u.Dv)(n);return[r,(0,s.useCallback)((e=>{n&&a.set(e)}),[n,a])]}({groupId:r}),g=(()=>{const e=c??m;return p({value:e,tabValues:a})?e:null})();(0,l.A)((()=>{g&&o(g)}),[g]);return{selectedValue:i,selectValue:(0,s.useCallback)((e=>{if(!p({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);o(e),d(e),j(e)}),[d,j,a]),tabValues:a}}var j=n(1062);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=n(4848);function x(e){let{className:t,block:n,selectedValue:s,selectValue:i,tabValues:l}=e;const o=[],{blockElementScrollPositionUntilNextRender:c}=(0,a.a_)(),u=e=>{const t=e.currentTarget,n=o.indexOf(t),r=l[n].value;r!==s&&(c(t),i(r))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=o.indexOf(e.currentTarget)+1;t=o[n]??o[0];break}case"ArrowLeft":{const n=o.indexOf(e.currentTarget)-1;t=o[n]??o[o.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:a}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>o.push(e),onKeyDown:d,onClick:u,...a,className:(0,r.A)("tabs__item",g.tabItem,a?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:a}=e;const i=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=i.find((e=>e.props.value===a));return e?(0,s.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:i.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=m(e);return(0,b.jsxs)("div",{className:(0,r.A)("tabs-container",g.tabList),children:[(0,b.jsx)(x,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function w(e){const t=(0,j.A)();return(0,b.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>i,x:()=>l});var s=n(6540);const r={},a=s.createContext(r);function i(e){const t=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),s.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/a7bc29db.005cdfe9.js b/assets/js/a7bc29db.e33e8aff.js similarity index 99% rename from assets/js/a7bc29db.005cdfe9.js rename to assets/js/a7bc29db.e33e8aff.js index 04330685db..8fecd3c83e 100644 --- a/assets/js/a7bc29db.005cdfe9.js +++ b/assets/js/a7bc29db.e33e8aff.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9123],{8486:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>h,contentTitle:()=>a,default:()=>p,frontMatter:()=>l,metadata:()=>t,toc:()=>j});const t=JSON.parse('{"id":"getting-started/presets","title":"Presets","description":"In Jest, presets are pre-defined configurations that help streamline and standardize the process of setting up testing environments.","source":"@site/versioned_docs/version-29.2/getting-started/presets.md","sourceDirName":"getting-started","slug":"/getting-started/presets","permalink":"/ts-jest/docs/getting-started/presets","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/presets.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"presets","title":"Presets"},"sidebar":"version-29.1-docs","previous":{"title":"Installation","permalink":"/ts-jest/docs/getting-started/installation"},"next":{"title":"Options","permalink":"/ts-jest/docs/getting-started/options"}}');var r=n(4848),i=n(8453),o=n(9489),c=n(7227),d=n(1574);const l={id:"presets",title:"Presets"},a=void 0,h={},j=[{value:"Functions",id:"functions",level:2},{value:"createDefaultPreset(options)",id:"createdefaultpresetoptions",level:3},{value:"Parameters",id:"parameters",level:4},{value:"Returns",id:"returns",level:4},{value:"Example:",id:"example",level:4},{value:"createDefaultLegacyPreset(options)",id:"createdefaultlegacypresetoptions",level:3},{value:"Parameters",id:"parameters-1",level:4},{value:"Returns",id:"returns-1",level:4},{value:"Example:",id:"example-1",level:4},{value:"createDefaultEsmPreset(options)",id:"createdefaultesmpresetoptions",level:3},{value:"Parameters",id:"parameters-2",level:4},{value:"Returns",id:"returns-2",level:4},{value:"Example:",id:"example-2",level:4},{value:"createDefaultLegacyEsmPreset(options)",id:"createdefaultlegacyesmpresetoptions",level:3},{value:"Parameters",id:"parameters-3",level:4},{value:"Returns",id:"returns-3",level:4},{value:"Example:",id:"example-3",level:4},{value:"createJsWithTsPreset(options)",id:"createjswithtspresetoptions",level:3},{value:"Parameters",id:"parameters-4",level:4},{value:"Returns",id:"returns-4",level:4},{value:"Example:",id:"example-4",level:4},{value:"createJsWithTsLegacyPreset(options)",id:"createjswithtslegacypresetoptions",level:3},{value:"Parameters",id:"parameters-5",level:4},{value:"Returns",id:"returns-5",level:4},{value:"Example:",id:"example-5",level:4},{value:"createJsWithTsEsmPreset(options)",id:"createjswithtsesmpresetoptions",level:3},{value:"Parameters",id:"parameters-6",level:4},{value:"Returns",id:"returns-6",level:4},{value:"Example:",id:"example-6",level:4},{value:"createJsWithTsEsmLegacyPreset(options)",id:"createjswithtsesmlegacypresetoptions",level:3},{value:"Parameters",id:"parameters-7",level:4},{value:"Returns",id:"returns-7",level:4},{value:"Example:",id:"example-7",level:4},{value:"createJsWithBabelPreset(options)",id:"createjswithbabelpresetoptions",level:3},{value:"Parameters",id:"parameters-8",level:4},{value:"Returns",id:"returns-8",level:4},{value:"Example:",id:"example-8",level:4},{value:"createJsWithBabelLegacyPreset(options)",id:"createjswithbabellegacypresetoptions",level:3},{value:"Parameters",id:"parameters-9",level:4},{value:"Returns",id:"returns-9",level:4},{value:"Example:",id:"example-9",level:4},{value:"createJsWithBabelEsmPreset(options)",id:"createjswithbabelesmpresetoptions",level:3},{value:"Parameters",id:"parameters-10",level:4},{value:"Returns",id:"returns-10",level:4},{value:"Example:",id:"example-10",level:4},{value:"createJsWithBabelEsmLegacyPreset(options)",id:"createjswithbabelesmlegacypresetoptions",level:3},{value:"Parameters",id:"parameters-11",level:4},{value:"Returns",id:"returns-11",level:4},{value:"Example:",id:"example-11",level:4},{value:"Legacy presets",id:"legacy-presets",level:3},{value:"Example",id:"example-12",level:4}];function x(e){const s={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",h4:"h4",hr:"hr",li:"li",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,i.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(s.p,{children:["In Jest, ",(0,r.jsx)(s.strong,{children:"presets"})," are pre-defined configurations that help streamline and standardize the process of setting up testing environments.\nThey allow developers to quickly configure Jest with specific transformers, file extensions, and other options."]}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.code,{children:"ts-jest"})," provides very opinionated presets and based on what we found to be useful."]}),"\n",(0,r.jsx)(s.admonition,{type:"important",children:(0,r.jsx)(s.p,{children:"The current best practice for using presets is to call one of the utility functions below to create (and optionally extend) presets. Legacy presets are listed at the bottom of the page."})}),"\n",(0,r.jsx)(s.h2,{id:"functions",children:"Functions"}),"\n","\n",(0,r.jsx)(d.A,{toc:j.slice(1)}),"\n",(0,r.jsx)(s.hr,{}),"\n",(0,r.jsx)(s.h3,{id:"createdefaultpresetoptions",children:(0,r.jsx)(s.code,{children:"createDefaultPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a configuration to process TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type DefaultPreset = {\n transform: {\n '^.+.tsx?$': ['ts-jest', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport { createDefaultPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createDefaultPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createdefaultlegacypresetoptions",children:(0,r.jsx)(s.code,{children:"createDefaultLegacyPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ",(0,r.jsx)(s.strong,{children:"LEGACY"})," configuration to process TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-1",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-1",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type DefaultPreset = {\n transform: {\n '^.+.tsx?$': ['ts-jest/legacy', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-1",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport { createDefaultLegacyPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createDefaultPreset({\n //...optionsa\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createdefaultesmpresetoptions",children:(0,r.jsx)(s.code,{children:"createDefaultEsmPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create an ESM configuration to process TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".mts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),"/",(0,r.jsx)(s.code,{children:".mtsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-2",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-2",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type DefaultEsmPreset = {\n extensionsToTreatAsEsm: string[]\n transform: {\n '^.+\\\\.m?tsx?$': ['ts-jest', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-2",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createDefaultEsmPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createDefaultEsmPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createdefaultlegacyesmpresetoptions",children:(0,r.jsx)(s.code,{children:"createDefaultLegacyEsmPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ",(0,r.jsx)(s.strong,{children:"LEGACY"})," ESM configuration to process TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".mts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),"/",(0,r.jsx)(s.code,{children:".mtsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-3",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-3",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type DefaultEsmPreset = {\n extensionsToTreatAsEsm: string[]\n transform: {\n '^.+\\\\.m?tsx?$': ['ts-jest/legacy', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-3",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createDefaultLegacyEsmPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createDefaultLegacyEsmPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithtspresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithTsPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-4",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-4",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithTsPreset = {\n transform: {\n '^.+.[tj]sx?$': ['ts-jest', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-4",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport { createJsWithTsPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithTsPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithtslegacypresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithTsLegacyPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ",(0,r.jsx)(s.strong,{children:"LEGACY"})," configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-5",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-5",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithTsPreset = {\n transform: {\n '^.+.[tj]sx?$': ['ts-jest/legacy', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-5",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport { createJsWithTsLegacyPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithTsLegacyPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithtsesmpresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithTsEsmPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ESM configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".mjs"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".mjsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".mts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),"/",(0,r.jsx)(s.code,{children:".mtsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-6",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-6",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithTsPreset = {\n transform: {\n '^.+\\\\.m?[tj]sx?$': ['ts-jest', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-6",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createJsWithTsEsmPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithTsEsmPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithtsesmlegacypresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithTsEsmLegacyPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ",(0,r.jsx)(s.strong,{children:"LEGACY"})," ESM configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".mjs"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".mjsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".mts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),"/",(0,r.jsx)(s.code,{children:".mtsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-7",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-7",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithTsPreset = {\n transform: {\n '^.+\\\\.m?[tj]sx?$': ['ts-jest/legacy', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-7",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createJsWithTsEsmLegacyPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithTsEsmLegacyPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithbabelpresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithBabelPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),") which uses ",(0,r.jsx)(s.code,{children:"babel-jest"})," to perform additional transformation."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-8",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),"):","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"babelConfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/babelConfig",children:"babelConfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-8",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n babelConfig?: boolean | string | BabelConfig\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithBabelPreset = {\n transform: {\n '^.+.[tj]sx?$': ['ts-jest', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-8",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport { createJsWithBabelPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithBabelPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithbabellegacypresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithBabelLegacyPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ",(0,r.jsx)(s.strong,{children:"LEGACY"})," configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),") which uses ",(0,r.jsx)(s.code,{children:"babel-jest"})," to perform additional transformation."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-9",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),"):","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"babelConfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/babelConfig",children:"babelConfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-9",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n babelConfig?: boolean | string | BabelConfig\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithBabelPreset = {\n transform: {\n '^.+.[tj]sx?$': ['ts-jest/legacy', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-9",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport { createJsWithBabelLegacyPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithBabelLegacyPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithbabelesmpresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithBabelEsmPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ESM configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".mjs"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".mjsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".mts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),"/",(0,r.jsx)(s.code,{children:".mtsx"}),") which uses ",(0,r.jsx)(s.code,{children:"babel-jest"})," to perform additional transformation."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-10",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),"):","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"babelConfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/babelConfig",children:"babelConfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-10",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n babelConfig?: boolean | string | BabelConfig\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithBabelPreset = {\n transform: {\n '^.+.[tj]sx?$': ['ts-jest', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-10",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createJsWithBabelEsmPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithBabelEsmPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithbabelesmlegacypresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithBabelEsmLegacyPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ",(0,r.jsx)(s.strong,{children:"LEGACY"})," ESM configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".mjs"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".mjsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".mts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),"/",(0,r.jsx)(s.code,{children:".mtsx"}),") which uses ",(0,r.jsx)(s.code,{children:"babel-jest"})," to perform additional transformation."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-11",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),"):","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"babelConfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/babelConfig",children:"babelConfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-11",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n babelConfig?: boolean | string | BabelConfig\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithBabelPreset = {\n transform: {\n '^.+.[tj]sx?$': ['ts-jest/legacy', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-11",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createJsWithBabelEsmLegacyPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithBabelEsmLegacyPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"legacy-presets",children:"Legacy presets"}),"\n",(0,r.jsx)(s.admonition,{type:"warning",children:(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.code,{children:"ts-jest"})," ",(0,r.jsx)(s.strong,{children:"DON'T RECOMMEND"})," to use legacy presets because this approach is not flexible to configure Jest configuration.\nThese legacy presets will be removed in the next major release and users are ",(0,r.jsx)(s.strong,{children:"HIGHLY RECOMMENDED"})," to migrate to use the above utility functions."]})}),"\n",(0,r.jsxs)(s.table,{children:[(0,r.jsx)(s.thead,{children:(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.th,{children:"Preset name"}),(0,r.jsx)(s.th,{children:"Description"})]})}),(0,r.jsxs)(s.tbody,{children:[(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default"}),(0,r.jsx)("br",{}),"or ",(0,r.jsx)(s.code,{children:"ts-jest"})]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default-legacy"}),(0,r.jsx)("br",{}),"or ",(0,r.jsx)(s.code,{children:"ts-jest/legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default-esm"}),(0,r.jsx)("br",{})]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default-esm-legacy"}),(0,r.jsx)("br",{})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts"})}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-esm"})}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-esm-legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel"})}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-esm"})}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-esm-legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]})]})]}),"\n",(0,r.jsx)(s.h4,{id:"example-12",children:"Example"}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(c.A,{value:"typescript-cjs",label:"TypeScript CJS",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",metastring:'tab={"label": "TypeScript CJS"}',children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // Replace `` with the one of the preset names from the table above\n preset: '',\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(c.A,{value:"typescript-esm",label:"TypeScript ESM",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",metastring:'tab={"label": "TypeScript ESM"}',children:"// jest.config.mts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // Replace `` with the one of the preset names from the table above\n preset: '',\n}\n\nexport default jestConfig\n"})})})]})]})}function p(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(x,{...e})}):x(e)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9123],{8486:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>h,contentTitle:()=>a,default:()=>p,frontMatter:()=>l,metadata:()=>t,toc:()=>j});const t=JSON.parse('{"id":"getting-started/presets","title":"Presets","description":"In Jest, presets are pre-defined configurations that help streamline and standardize the process of setting up testing environments.","source":"@site/versioned_docs/version-29.2/getting-started/presets.md","sourceDirName":"getting-started","slug":"/getting-started/presets","permalink":"/ts-jest/docs/getting-started/presets","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/presets.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"presets","title":"Presets"},"sidebar":"version-29.1-docs","previous":{"title":"Installation","permalink":"/ts-jest/docs/getting-started/installation"},"next":{"title":"Options","permalink":"/ts-jest/docs/getting-started/options"}}');var r=n(4848),i=n(8453),o=n(9489),c=n(7227),d=n(1574);const l={id:"presets",title:"Presets"},a=void 0,h={},j=[{value:"Functions",id:"functions",level:2},{value:"createDefaultPreset(options)",id:"createdefaultpresetoptions",level:3},{value:"Parameters",id:"parameters",level:4},{value:"Returns",id:"returns",level:4},{value:"Example:",id:"example",level:4},{value:"createDefaultLegacyPreset(options)",id:"createdefaultlegacypresetoptions",level:3},{value:"Parameters",id:"parameters-1",level:4},{value:"Returns",id:"returns-1",level:4},{value:"Example:",id:"example-1",level:4},{value:"createDefaultEsmPreset(options)",id:"createdefaultesmpresetoptions",level:3},{value:"Parameters",id:"parameters-2",level:4},{value:"Returns",id:"returns-2",level:4},{value:"Example:",id:"example-2",level:4},{value:"createDefaultLegacyEsmPreset(options)",id:"createdefaultlegacyesmpresetoptions",level:3},{value:"Parameters",id:"parameters-3",level:4},{value:"Returns",id:"returns-3",level:4},{value:"Example:",id:"example-3",level:4},{value:"createJsWithTsPreset(options)",id:"createjswithtspresetoptions",level:3},{value:"Parameters",id:"parameters-4",level:4},{value:"Returns",id:"returns-4",level:4},{value:"Example:",id:"example-4",level:4},{value:"createJsWithTsLegacyPreset(options)",id:"createjswithtslegacypresetoptions",level:3},{value:"Parameters",id:"parameters-5",level:4},{value:"Returns",id:"returns-5",level:4},{value:"Example:",id:"example-5",level:4},{value:"createJsWithTsEsmPreset(options)",id:"createjswithtsesmpresetoptions",level:3},{value:"Parameters",id:"parameters-6",level:4},{value:"Returns",id:"returns-6",level:4},{value:"Example:",id:"example-6",level:4},{value:"createJsWithTsEsmLegacyPreset(options)",id:"createjswithtsesmlegacypresetoptions",level:3},{value:"Parameters",id:"parameters-7",level:4},{value:"Returns",id:"returns-7",level:4},{value:"Example:",id:"example-7",level:4},{value:"createJsWithBabelPreset(options)",id:"createjswithbabelpresetoptions",level:3},{value:"Parameters",id:"parameters-8",level:4},{value:"Returns",id:"returns-8",level:4},{value:"Example:",id:"example-8",level:4},{value:"createJsWithBabelLegacyPreset(options)",id:"createjswithbabellegacypresetoptions",level:3},{value:"Parameters",id:"parameters-9",level:4},{value:"Returns",id:"returns-9",level:4},{value:"Example:",id:"example-9",level:4},{value:"createJsWithBabelEsmPreset(options)",id:"createjswithbabelesmpresetoptions",level:3},{value:"Parameters",id:"parameters-10",level:4},{value:"Returns",id:"returns-10",level:4},{value:"Example:",id:"example-10",level:4},{value:"createJsWithBabelEsmLegacyPreset(options)",id:"createjswithbabelesmlegacypresetoptions",level:3},{value:"Parameters",id:"parameters-11",level:4},{value:"Returns",id:"returns-11",level:4},{value:"Example:",id:"example-11",level:4},{value:"Legacy presets",id:"legacy-presets",level:3},{value:"Example",id:"example-12",level:4}];function x(e){const s={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",h4:"h4",hr:"hr",li:"li",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,i.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(s.p,{children:["In Jest, ",(0,r.jsx)(s.strong,{children:"presets"})," are pre-defined configurations that help streamline and standardize the process of setting up testing environments.\nThey allow developers to quickly configure Jest with specific transformers, file extensions, and other options."]}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.code,{children:"ts-jest"})," provides very opinionated presets and based on what we found to be useful."]}),"\n",(0,r.jsx)(s.admonition,{type:"important",children:(0,r.jsx)(s.p,{children:"The current best practice for using presets is to call one of the utility functions below to create (and optionally extend) presets. Legacy presets are listed at the bottom of the page."})}),"\n",(0,r.jsx)(s.h2,{id:"functions",children:"Functions"}),"\n","\n",(0,r.jsx)(d.A,{toc:j.slice(1)}),"\n",(0,r.jsx)(s.hr,{}),"\n",(0,r.jsx)(s.h3,{id:"createdefaultpresetoptions",children:(0,r.jsx)(s.code,{children:"createDefaultPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a configuration to process TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type DefaultPreset = {\n transform: {\n '^.+.tsx?$': ['ts-jest', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport { createDefaultPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createDefaultPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createdefaultlegacypresetoptions",children:(0,r.jsx)(s.code,{children:"createDefaultLegacyPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ",(0,r.jsx)(s.strong,{children:"LEGACY"})," configuration to process TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-1",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-1",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type DefaultPreset = {\n transform: {\n '^.+.tsx?$': ['ts-jest/legacy', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-1",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport { createDefaultLegacyPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createDefaultPreset({\n //...optionsa\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createdefaultesmpresetoptions",children:(0,r.jsx)(s.code,{children:"createDefaultEsmPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create an ESM configuration to process TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".mts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),"/",(0,r.jsx)(s.code,{children:".mtsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-2",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-2",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type DefaultEsmPreset = {\n extensionsToTreatAsEsm: string[]\n transform: {\n '^.+\\\\.m?tsx?$': ['ts-jest', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-2",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createDefaultEsmPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createDefaultEsmPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createdefaultlegacyesmpresetoptions",children:(0,r.jsx)(s.code,{children:"createDefaultLegacyEsmPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ",(0,r.jsx)(s.strong,{children:"LEGACY"})," ESM configuration to process TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".mts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),"/",(0,r.jsx)(s.code,{children:".mtsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-3",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-3",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type DefaultEsmPreset = {\n extensionsToTreatAsEsm: string[]\n transform: {\n '^.+\\\\.m?tsx?$': ['ts-jest/legacy', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-3",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createDefaultLegacyEsmPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createDefaultLegacyEsmPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithtspresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithTsPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-4",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-4",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithTsPreset = {\n transform: {\n '^.+.[tj]sx?$': ['ts-jest', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-4",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport { createJsWithTsPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithTsPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithtslegacypresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithTsLegacyPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ",(0,r.jsx)(s.strong,{children:"LEGACY"})," configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-5",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-5",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithTsPreset = {\n transform: {\n '^.+.[tj]sx?$': ['ts-jest/legacy', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-5",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport { createJsWithTsLegacyPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithTsLegacyPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithtsesmpresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithTsEsmPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ESM configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".mjs"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".mjsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".mts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),"/",(0,r.jsx)(s.code,{children:".mtsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-6",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-6",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithTsPreset = {\n transform: {\n '^.+\\\\.m?[tj]sx?$': ['ts-jest', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-6",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createJsWithTsEsmPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithTsEsmPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithtsesmlegacypresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithTsEsmLegacyPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ",(0,r.jsx)(s.strong,{children:"LEGACY"})," ESM configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".mjs"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".mjsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".mts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),"/",(0,r.jsx)(s.code,{children:".mtsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-7",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-7",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithTsPreset = {\n transform: {\n '^.+\\\\.m?[tj]sx?$': ['ts-jest/legacy', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-7",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createJsWithTsEsmLegacyPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithTsEsmLegacyPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithbabelpresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithBabelPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),") which uses ",(0,r.jsx)(s.code,{children:"babel-jest"})," to perform additional transformation."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-8",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),"):","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"babelConfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/babelConfig",children:"babelConfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-8",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n babelConfig?: boolean | string | BabelConfig\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithBabelPreset = {\n transform: {\n '^.+.[tj]sx?$': ['ts-jest', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-8",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport { createJsWithBabelPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithBabelPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithbabellegacypresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithBabelLegacyPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ",(0,r.jsx)(s.strong,{children:"LEGACY"})," configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),") which uses ",(0,r.jsx)(s.code,{children:"babel-jest"})," to perform additional transformation."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-9",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),"):","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"babelConfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/babelConfig",children:"babelConfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-9",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n babelConfig?: boolean | string | BabelConfig\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithBabelPreset = {\n transform: {\n '^.+.[tj]sx?$': ['ts-jest/legacy', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-9",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport { createJsWithBabelLegacyPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithBabelLegacyPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithbabelesmpresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithBabelEsmPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ESM configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".mjs"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".mjsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".mts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),"/",(0,r.jsx)(s.code,{children:".mtsx"}),") which uses ",(0,r.jsx)(s.code,{children:"babel-jest"})," to perform additional transformation."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-10",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),"):","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"babelConfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/babelConfig",children:"babelConfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-10",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n babelConfig?: boolean | string | BabelConfig\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithBabelPreset = {\n transform: {\n '^.+.[tj]sx?$': ['ts-jest', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-10",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createJsWithBabelEsmPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithBabelEsmPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithbabelesmlegacypresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithBabelEsmLegacyPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ",(0,r.jsx)(s.strong,{children:"LEGACY"})," ESM configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".mjs"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".mjsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".mts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),"/",(0,r.jsx)(s.code,{children:".mtsx"}),") which uses ",(0,r.jsx)(s.code,{children:"babel-jest"})," to perform additional transformation."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-11",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),"):","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"babelConfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/babelConfig",children:"babelConfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-11",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n babelConfig?: boolean | string | BabelConfig\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithBabelPreset = {\n transform: {\n '^.+.[tj]sx?$': ['ts-jest/legacy', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-11",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createJsWithBabelEsmLegacyPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithBabelEsmLegacyPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"legacy-presets",children:"Legacy presets"}),"\n",(0,r.jsx)(s.admonition,{type:"warning",children:(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.code,{children:"ts-jest"})," ",(0,r.jsx)(s.strong,{children:"DON'T RECOMMEND"})," to use legacy presets because this approach is not flexible to configure Jest configuration.\nThese legacy presets will be removed in the next major release and users are ",(0,r.jsx)(s.strong,{children:"HIGHLY RECOMMENDED"})," to migrate to use the above utility functions."]})}),"\n",(0,r.jsxs)(s.table,{children:[(0,r.jsx)(s.thead,{children:(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.th,{children:"Preset name"}),(0,r.jsx)(s.th,{children:"Description"})]})}),(0,r.jsxs)(s.tbody,{children:[(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default"}),(0,r.jsx)("br",{}),"or ",(0,r.jsx)(s.code,{children:"ts-jest"})]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default-legacy"}),(0,r.jsx)("br",{}),"or ",(0,r.jsx)(s.code,{children:"ts-jest/legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default-esm"}),(0,r.jsx)("br",{})]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default-esm-legacy"}),(0,r.jsx)("br",{})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts"})}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-esm"})}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-esm-legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel"})}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-esm"})}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-esm-legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]})]})]}),"\n",(0,r.jsx)(s.h4,{id:"example-12",children:"Example"}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(c.A,{value:"typescript-cjs",label:"TypeScript CJS",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",metastring:'tab={"label": "TypeScript CJS"}',children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // Replace `` with the one of the preset names from the table above\n preset: '',\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(c.A,{value:"typescript-esm",label:"TypeScript ESM",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",metastring:'tab={"label": "TypeScript ESM"}',children:"// jest.config.mts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // Replace `` with the one of the preset names from the table above\n preset: '',\n}\n\nexport default jestConfig\n"})})})]})]})}function p(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(x,{...e})}):x(e)}}}]); \ No newline at end of file diff --git a/assets/js/a8c654d7.ed76a70f.js b/assets/js/a8c654d7.6ecb388a.js similarity index 97% rename from assets/js/a8c654d7.ed76a70f.js rename to assets/js/a8c654d7.6ecb388a.js index 678bd40182..b52323a091 100644 --- a/assets/js/a8c654d7.ed76a70f.js +++ b/assets/js/a8c654d7.6ecb388a.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2587],{4149:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>c,default:()=>a,frontMatter:()=>i,metadata:()=>s,toc:()=>g});const s=JSON.parse('{"id":"debugging","title":"Debugging ts-jest","description":"You can activate the debug logger by setting the environment variable TSJESTLOG before running tests.","source":"@site/versioned_docs/version-28.0/debugging.md","sourceDirName":".","slug":"/debugging","permalink":"/ts-jest/docs/28.0/debugging","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/debugging.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"debugging","title":"Debugging ts-jest"},"sidebar":"version-28.0-docs","previous":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/28.0/migration"}}');var o=n(4848),r=n(8453);const i={id:"debugging",title:"Debugging ts-jest"},c=void 0,d={},g=[];function l(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["You can activate the debug logger by setting the environment variable ",(0,o.jsx)(t.code,{children:"TS_JEST_LOG"})," before running tests.\nThe output of the logger will be in ",(0,o.jsx)(t.strong,{children:"ts-jest.log"})," in current working directory."]}),"\n",(0,o.jsxs)(t.p,{children:["The debug logger contains some useful information about how internal ",(0,o.jsx)(t.code,{children:"ts-jest"})," works, including which files are processed,\nwhich Jest config or TypeScript config is used etc."]}),"\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{children:"export TS_JEST_LOG=ts-jest.log\n"})}),"\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.strong,{children:"Windows"})}),"\n",(0,o.jsx)(t.p,{children:"Command Prompt (cmd)"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{children:"set TS_JEST_LOG=ts-jest.log\n"})}),"\n",(0,o.jsx)(t.p,{children:"PowerShell"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{children:"$env:TS_JEST_LOG = 'ts-jest.log'\n"})})]})}function a(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>i,x:()=>c});var s=n(6540);const o={},r=s.createContext(o);function i(e){const t=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2587],{4149:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>c,default:()=>a,frontMatter:()=>i,metadata:()=>s,toc:()=>g});const s=JSON.parse('{"id":"debugging","title":"Debugging ts-jest","description":"You can activate the debug logger by setting the environment variable TSJESTLOG before running tests.","source":"@site/versioned_docs/version-28.0/debugging.md","sourceDirName":".","slug":"/debugging","permalink":"/ts-jest/docs/28.0/debugging","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/debugging.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"debugging","title":"Debugging ts-jest"},"sidebar":"version-28.0-docs","previous":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/28.0/migration"}}');var o=n(4848),r=n(8453);const i={id:"debugging",title:"Debugging ts-jest"},c=void 0,d={},g=[];function l(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["You can activate the debug logger by setting the environment variable ",(0,o.jsx)(t.code,{children:"TS_JEST_LOG"})," before running tests.\nThe output of the logger will be in ",(0,o.jsx)(t.strong,{children:"ts-jest.log"})," in current working directory."]}),"\n",(0,o.jsxs)(t.p,{children:["The debug logger contains some useful information about how internal ",(0,o.jsx)(t.code,{children:"ts-jest"})," works, including which files are processed,\nwhich Jest config or TypeScript config is used etc."]}),"\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{children:"export TS_JEST_LOG=ts-jest.log\n"})}),"\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.strong,{children:"Windows"})}),"\n",(0,o.jsx)(t.p,{children:"Command Prompt (cmd)"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{children:"set TS_JEST_LOG=ts-jest.log\n"})}),"\n",(0,o.jsx)(t.p,{children:"PowerShell"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{children:"$env:TS_JEST_LOG = 'ts-jest.log'\n"})})]})}function a(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>i,x:()=>c});var s=n(6540);const o={},r=s.createContext(o);function i(e){const t=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/a8e3f14e.c57728a2.js b/assets/js/a8e3f14e.667ab091.js similarity index 99% rename from assets/js/a8e3f14e.c57728a2.js rename to assets/js/a8e3f14e.667ab091.js index e612facf5e..b0d475a48e 100644 --- a/assets/js/a8e3f14e.c57728a2.js +++ b/assets/js/a8e3f14e.667ab091.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2234],{2257:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>p,frontMatter:()=>l,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/options/stringifyContentPathRegex","title":"Stringify content option","description":"The stringifyContentPathRegex option has been kept for backward compatibility of HTML_TRANSFORM","source":"@site/versioned_docs/version-29.0/getting-started/options/stringifyContentPathRegex.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/stringifyContentPathRegex","permalink":"/ts-jest/docs/29.0/getting-started/options/stringifyContentPathRegex","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/options/stringifyContentPathRegex.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Stringify content option"}}');var r=n(4848),o=n(8453),a=n(9489),i=n(7227);const l={title:"Stringify content option"},u=void 0,c={},d=[{value:"Example",id:"example",level:3}];function h(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["The ",(0,r.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,r.jsx)(t.code,{children:"__HTML_TRANSFORM__"}),"\nIt's a regular expression pattern used to match the path of file to be transformed.\nIf it matches, the file will be exported as a module exporting its content."]}),"\n",(0,r.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,r.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,r.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,r.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,r.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,r.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,r.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,r.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,r.jsx)(t.code,{children:"transform"})," option pointing to ",(0,r.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,r.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,r.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,r.jsxs)(t.p,{children:["In the ",(0,r.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,r.jsx)(t.code,{children:"package.json"})," version of the config, but extending from the preset will ensure more compatibility without any changes when updating."]}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n moduleFileExtensions: [...tsjPreset.moduleFileExtensions, 'html'],\n transform: {\n ...tsjPreset.transform,\n '\\\\.html$': [\n 'ts-jest',\n {\n stringifyContentPathRegex: /\\.html$/,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\nimport tsJestPresets from 'ts-jest/presets'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n moduleFileExtensions: [...tsJestPresets.defaults.moduleFileExtensions, 'html'],\n transform: {\n ...tsJestPresets.defaults.transform,\n '\\\\.html$': [\n 'ts-jest',\n {\n stringifyContentPathRegex: /\\.html$/,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleFileExtensions": ["js", "ts", "html"],\n "transform": {\n "\\\\.(html|ts|js)$": [\n "ts-jest",\n {\n "stringifyContentPathRegex": "\\\\.html$"\n }\n ]\n }\n }\n}\n'})})})]})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>a});n(6540);var s=n(4164);const r={tabItem:"tabItem_Ymn6"};var o=n(4848);function a(e){let{children:t,hidden:n,className:a}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,s.A)(r.tabItem,a),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),r=n(4164),o=n(4245),a=n(6347),i=n(6494),l=n(2814),u=n(5167),c=n(9900);function d(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:r}}=e;return{value:t,label:n,attributes:s,default:r}}))}(n);return function(e){const t=(0,u.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const r=(0,a.W6)(),o=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(o),(0,s.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(r.location.search);t.set(o,e),r.replace({...r.location,search:t.toString()})}),[o,r])]}function m(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,o=h(e),[a,l]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:o}))),[u,d]=f({queryString:n,groupId:r}),[m,g]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,o]=(0,c.Dv)(n);return[r,(0,s.useCallback)((e=>{n&&o.set(e)}),[n,o])]}({groupId:r}),b=(()=>{const e=u??m;return p({value:e,tabValues:o})?e:null})();(0,i.A)((()=>{b&&l(b)}),[b]);return{selectedValue:a,selectValue:(0,s.useCallback)((e=>{if(!p({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),g(e)}),[d,g,o]),tabValues:o}}var g=n(1062);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=n(4848);function j(e){let{className:t,block:n,selectedValue:s,selectValue:a,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:u}=(0,o.a_)(),c=e=>{const t=e.currentTarget,n=l.indexOf(t),r=i[n].value;r!==s&&(u(t),a(r))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:o}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>l.push(e),onKeyDown:d,onClick:c,...o,className:(0,r.A)("tabs__item",b.tabItem,o?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:o}=e;const a=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=a.find((e=>e.props.value===o));return e?(0,s.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:a.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==o})))})}function y(e){const t=m(e);return(0,x.jsxs)("div",{className:(0,r.A)("tabs-container",b.tabList),children:[(0,x.jsx)(j,{...t,...e}),(0,x.jsx)(v,{...t,...e})]})}function w(e){const t=(0,g.A)();return(0,x.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>a,x:()=>i});var s=n(6540);const r={},o=s.createContext(r);function a(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2234],{2257:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>p,frontMatter:()=>l,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/options/stringifyContentPathRegex","title":"Stringify content option","description":"The stringifyContentPathRegex option has been kept for backward compatibility of HTML_TRANSFORM","source":"@site/versioned_docs/version-29.0/getting-started/options/stringifyContentPathRegex.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/stringifyContentPathRegex","permalink":"/ts-jest/docs/29.0/getting-started/options/stringifyContentPathRegex","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/options/stringifyContentPathRegex.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Stringify content option"}}');var r=n(4848),o=n(8453),a=n(9489),i=n(7227);const l={title:"Stringify content option"},u=void 0,c={},d=[{value:"Example",id:"example",level:3}];function h(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["The ",(0,r.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,r.jsx)(t.code,{children:"__HTML_TRANSFORM__"}),"\nIt's a regular expression pattern used to match the path of file to be transformed.\nIf it matches, the file will be exported as a module exporting its content."]}),"\n",(0,r.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,r.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,r.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,r.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,r.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,r.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,r.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,r.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,r.jsx)(t.code,{children:"transform"})," option pointing to ",(0,r.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,r.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,r.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,r.jsxs)(t.p,{children:["In the ",(0,r.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,r.jsx)(t.code,{children:"package.json"})," version of the config, but extending from the preset will ensure more compatibility without any changes when updating."]}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n moduleFileExtensions: [...tsjPreset.moduleFileExtensions, 'html'],\n transform: {\n ...tsjPreset.transform,\n '\\\\.html$': [\n 'ts-jest',\n {\n stringifyContentPathRegex: /\\.html$/,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\nimport tsJestPresets from 'ts-jest/presets'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n moduleFileExtensions: [...tsJestPresets.defaults.moduleFileExtensions, 'html'],\n transform: {\n ...tsJestPresets.defaults.transform,\n '\\\\.html$': [\n 'ts-jest',\n {\n stringifyContentPathRegex: /\\.html$/,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleFileExtensions": ["js", "ts", "html"],\n "transform": {\n "\\\\.(html|ts|js)$": [\n "ts-jest",\n {\n "stringifyContentPathRegex": "\\\\.html$"\n }\n ]\n }\n }\n}\n'})})})]})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>a});n(6540);var s=n(4164);const r={tabItem:"tabItem_Ymn6"};var o=n(4848);function a(e){let{children:t,hidden:n,className:a}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,s.A)(r.tabItem,a),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),r=n(4164),o=n(4245),a=n(6347),i=n(6494),l=n(2814),u=n(5167),c=n(9900);function d(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:r}}=e;return{value:t,label:n,attributes:s,default:r}}))}(n);return function(e){const t=(0,u.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const r=(0,a.W6)(),o=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(o),(0,s.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(r.location.search);t.set(o,e),r.replace({...r.location,search:t.toString()})}),[o,r])]}function m(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,o=h(e),[a,l]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:o}))),[u,d]=f({queryString:n,groupId:r}),[m,g]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,o]=(0,c.Dv)(n);return[r,(0,s.useCallback)((e=>{n&&o.set(e)}),[n,o])]}({groupId:r}),b=(()=>{const e=u??m;return p({value:e,tabValues:o})?e:null})();(0,i.A)((()=>{b&&l(b)}),[b]);return{selectedValue:a,selectValue:(0,s.useCallback)((e=>{if(!p({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),g(e)}),[d,g,o]),tabValues:o}}var g=n(1062);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=n(4848);function j(e){let{className:t,block:n,selectedValue:s,selectValue:a,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:u}=(0,o.a_)(),c=e=>{const t=e.currentTarget,n=l.indexOf(t),r=i[n].value;r!==s&&(u(t),a(r))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:o}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>l.push(e),onKeyDown:d,onClick:c,...o,className:(0,r.A)("tabs__item",b.tabItem,o?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:o}=e;const a=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=a.find((e=>e.props.value===o));return e?(0,s.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:a.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==o})))})}function y(e){const t=m(e);return(0,x.jsxs)("div",{className:(0,r.A)("tabs-container",b.tabList),children:[(0,x.jsx)(j,{...t,...e}),(0,x.jsx)(v,{...t,...e})]})}function w(e){const t=(0,g.A)();return(0,x.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>a,x:()=>i});var s=n(6540);const r={},o=s.createContext(r);function a(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/aaf1bd4c.a76bf8b2.js b/assets/js/aaf1bd4c.33ec191c.js similarity index 98% rename from assets/js/aaf1bd4c.a76bf8b2.js rename to assets/js/aaf1bd4c.33ec191c.js index 2bbf9a3c68..84eb1ba05f 100644 --- a/assets/js/aaf1bd4c.a76bf8b2.js +++ b/assets/js/aaf1bd4c.33ec191c.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[863],{706:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>h,frontMatter:()=>l,metadata:()=>n,toc:()=>c});const n=JSON.parse('{"id":"getting-started/options/isolatedModules","title":"Isolated Modules option","description":"By default ts-jest uses TypeScript compiler in the context of a project (yours), with full type-checking and features.","source":"@site/versioned_docs/version-26.5/getting-started/options/isolatedModules.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/isolatedModules","permalink":"/ts-jest/docs/26.5/getting-started/options/isolatedModules","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/getting-started/options/isolatedModules.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Isolated Modules option"}}');var o=s(4848),i=s(8453);const l={title:"Isolated Modules option"},a=void 0,d={},c=[{value:"Example",id:"example",level:3},{value:"Performance",id:"performance",level:2},{value:"Example",id:"example-1",level:3},{value:"Caveats",id:"caveats",level:2}];function r(e){const t={code:"code",h2:"h2",h3:"h3",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["By default ",(0,o.jsx)(t.code,{children:"ts-jest"})," uses TypeScript compiler in the context of a project (yours), with full type-checking and features.\nBut it can also be used to compile each file separately, what TypeScript calls an 'isolated module'.\nThat's what the ",(0,o.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,o.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,o.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,o.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,o.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,o.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n isolatedModules: true,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "isolatedModules": true\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,o.jsxs)(t.p,{children:["Using ",(0,o.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,o.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,o.jsx)(t.code,{children:"include"})," in ",(0,o.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,o.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,o.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,o.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,o.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,o.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,o.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,o.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,o.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,o.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,o.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function h(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(r,{...e})}):r(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>l,x:()=>a});var n=s(6540);const o={},i=n.createContext(o);function l(e){const t=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:l(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[863],{706:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>h,frontMatter:()=>l,metadata:()=>n,toc:()=>c});const n=JSON.parse('{"id":"getting-started/options/isolatedModules","title":"Isolated Modules option","description":"By default ts-jest uses TypeScript compiler in the context of a project (yours), with full type-checking and features.","source":"@site/versioned_docs/version-26.5/getting-started/options/isolatedModules.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/isolatedModules","permalink":"/ts-jest/docs/26.5/getting-started/options/isolatedModules","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/getting-started/options/isolatedModules.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Isolated Modules option"}}');var o=s(4848),i=s(8453);const l={title:"Isolated Modules option"},a=void 0,d={},c=[{value:"Example",id:"example",level:3},{value:"Performance",id:"performance",level:2},{value:"Example",id:"example-1",level:3},{value:"Caveats",id:"caveats",level:2}];function r(e){const t={code:"code",h2:"h2",h3:"h3",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["By default ",(0,o.jsx)(t.code,{children:"ts-jest"})," uses TypeScript compiler in the context of a project (yours), with full type-checking and features.\nBut it can also be used to compile each file separately, what TypeScript calls an 'isolated module'.\nThat's what the ",(0,o.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,o.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,o.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,o.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,o.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,o.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n isolatedModules: true,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "isolatedModules": true\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,o.jsxs)(t.p,{children:["Using ",(0,o.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,o.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,o.jsx)(t.code,{children:"include"})," in ",(0,o.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,o.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,o.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,o.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,o.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,o.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,o.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,o.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,o.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,o.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,o.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function h(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(r,{...e})}):r(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>l,x:()=>a});var n=s(6540);const o={},i=n.createContext(o);function l(e){const t=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:l(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/ae1ffb77.e2a0d769.js b/assets/js/ae1ffb77.bb67cfb5.js similarity index 97% rename from assets/js/ae1ffb77.e2a0d769.js rename to assets/js/ae1ffb77.bb67cfb5.js index edf53fb780..d33d907927 100644 --- a/assets/js/ae1ffb77.e2a0d769.js +++ b/assets/js/ae1ffb77.bb67cfb5.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[698],{4369:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/version-checking","title":"Version checking","description":"By default, ts-jest supports a range of versions for jest/typescript. One uses incompatible versions will receive a warning","source":"@site/versioned_docs/version-28.0/getting-started/version-checking.md","sourceDirName":"getting-started","slug":"/getting-started/version-checking","permalink":"/ts-jest/docs/28.0/getting-started/version-checking","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/version-checking.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"version-checking","title":"Version checking"},"sidebar":"version-28.0-docs","previous":{"title":"Paths mapping","permalink":"/ts-jest/docs/28.0/getting-started/paths-mapping"},"next":{"title":"ESM Support","permalink":"/ts-jest/docs/28.0/guides/esm-support"}}');var i=n(4848),r=n(8453);const o={id:"version-checking",title:"Version checking"},c=void 0,a={},d=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["By default, ",(0,i.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,i.jsx)(t.code,{children:"jest"}),"/",(0,i.jsx)(t.code,{children:"typescript"}),". One uses incompatible versions will receive a warning\nmessage while running tests. This warning message can be opt-out by setting environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"export TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Windows"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,i.jsxs)(t.p,{children:["As long as the environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"})," stays, the warning message will no longer show.\nThis can lead to unexpected errors due to the usage of incompatible versions' dependencies. Use this environment variable with precautions."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>c});var s=n(6540);const i={},r=s.createContext(i);function o(e){const t=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[698],{4369:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/version-checking","title":"Version checking","description":"By default, ts-jest supports a range of versions for jest/typescript. One uses incompatible versions will receive a warning","source":"@site/versioned_docs/version-28.0/getting-started/version-checking.md","sourceDirName":"getting-started","slug":"/getting-started/version-checking","permalink":"/ts-jest/docs/28.0/getting-started/version-checking","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/version-checking.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"version-checking","title":"Version checking"},"sidebar":"version-28.0-docs","previous":{"title":"Paths mapping","permalink":"/ts-jest/docs/28.0/getting-started/paths-mapping"},"next":{"title":"ESM Support","permalink":"/ts-jest/docs/28.0/guides/esm-support"}}');var i=n(4848),r=n(8453);const o={id:"version-checking",title:"Version checking"},c=void 0,a={},d=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["By default, ",(0,i.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,i.jsx)(t.code,{children:"jest"}),"/",(0,i.jsx)(t.code,{children:"typescript"}),". One uses incompatible versions will receive a warning\nmessage while running tests. This warning message can be opt-out by setting environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"export TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Windows"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,i.jsxs)(t.p,{children:["As long as the environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"})," stays, the warning message will no longer show.\nThis can lead to unexpected errors due to the usage of incompatible versions' dependencies. Use this environment variable with precautions."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>c});var s=n(6540);const i={},r=s.createContext(i);function o(e){const t=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/aeb5491d.11795c71.js b/assets/js/aeb5491d.2140da85.js similarity index 98% rename from assets/js/aeb5491d.11795c71.js rename to assets/js/aeb5491d.2140da85.js index c3401d5185..520ff278be 100644 --- a/assets/js/aeb5491d.11795c71.js +++ b/assets/js/aeb5491d.2140da85.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4572],{3497:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>r,metadata:()=>s,toc:()=>l});const s=JSON.parse('{"id":"babel7-or-ts","title":"Babel7 or TypeScript","description":"In Sept. 2018 Babel7 got released with an interesting preset: @babel/preset-typescript.","source":"@site/versioned_docs/version-28.0/babel7-or-ts.md","sourceDirName":".","slug":"/babel7-or-ts","permalink":"/ts-jest/docs/28.0/babel7-or-ts","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/babel7-or-ts.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"babel7-or-ts","title":"Babel7 or TypeScript"},"sidebar":"version-28.0-docs","previous":{"title":"Using with monorepo","permalink":"/ts-jest/docs/28.0/guides/using-with-monorepo"},"next":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/28.0/migration"}}');var i=n(4848),o=n(8453);const r={id:"babel7-or-ts",title:"Babel7 or TypeScript"},c=void 0,a={},l=[{value:"Limitations",id:"limitations",level:2},{value:"No type-checking",id:"no-type-checking",level:4},{value:"No namespace",id:"no-namespace",level:4},{value:"No const enum",id:"no-const-enum",level:4},{value:"No declaration merging (enum, namespace, ...)",id:"no-declaration-merging-enum-namespace-",level:4},{value:"No legacy import/export",id:"no-legacy-importexport",level:4},{value:"No caret type-casting with JSX enabled",id:"no-caret-type-casting-with-jsx-enabled",level:4}];function d(e){const t={a:"a",code:"code",h2:"h2",h4:"h4",hr:"hr",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,i.jsxs)(t.p,{children:["The goal is to make it easy for users using Babel to try TypeScript without moving out from Babel, just by adding a preset in their Babel config (here is the ",(0,i.jsx)(t.a,{href:"https://blogs.msdn.microsoft.com/typescript/2018/08/27/typescript-and-babel-7/",children:"MSDN blog post"})," about TypeScript and Babel 7)."]}),"\n",(0,i.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,i.jsxs)(t.p,{children:["While ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"})," is a great preset, you must know the limitation of it. Here is what is possible with TypeScript (and ",(0,i.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,i.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,i.jsxs)(t.p,{children:["This is the big ",(0,i.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,i.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,i.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,i.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,i.jsx)(t.p,{children:'With Babel, files are transpiled as isolated modules, there is no notion of "project". With TypeScript, files are part of a project and are compiled in that scope.'}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,i.jsx)(t.code,{children:"namespace"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"namespace app {\n export const VERSION = '1.0.0'\n export class App {\n /* ... */\n }\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,i.jsx)(t.code,{children:"const enum"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,i.jsx)(t.code,{children:"enum"}),", ",(0,i.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,i.jsxs)(t.p,{children:["You won't be able to do ",(0,i.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,i.jsx)(t.code,{children:"import"}),"/",(0,i.jsx)(t.code,{children:"export"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>c});var s=n(6540);const i={},o=s.createContext(i);function r(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4572],{3497:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>r,metadata:()=>s,toc:()=>l});const s=JSON.parse('{"id":"babel7-or-ts","title":"Babel7 or TypeScript","description":"In Sept. 2018 Babel7 got released with an interesting preset: @babel/preset-typescript.","source":"@site/versioned_docs/version-28.0/babel7-or-ts.md","sourceDirName":".","slug":"/babel7-or-ts","permalink":"/ts-jest/docs/28.0/babel7-or-ts","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/babel7-or-ts.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"babel7-or-ts","title":"Babel7 or TypeScript"},"sidebar":"version-28.0-docs","previous":{"title":"Using with monorepo","permalink":"/ts-jest/docs/28.0/guides/using-with-monorepo"},"next":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/28.0/migration"}}');var i=n(4848),o=n(8453);const r={id:"babel7-or-ts",title:"Babel7 or TypeScript"},c=void 0,a={},l=[{value:"Limitations",id:"limitations",level:2},{value:"No type-checking",id:"no-type-checking",level:4},{value:"No namespace",id:"no-namespace",level:4},{value:"No const enum",id:"no-const-enum",level:4},{value:"No declaration merging (enum, namespace, ...)",id:"no-declaration-merging-enum-namespace-",level:4},{value:"No legacy import/export",id:"no-legacy-importexport",level:4},{value:"No caret type-casting with JSX enabled",id:"no-caret-type-casting-with-jsx-enabled",level:4}];function d(e){const t={a:"a",code:"code",h2:"h2",h4:"h4",hr:"hr",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,i.jsxs)(t.p,{children:["The goal is to make it easy for users using Babel to try TypeScript without moving out from Babel, just by adding a preset in their Babel config (here is the ",(0,i.jsx)(t.a,{href:"https://blogs.msdn.microsoft.com/typescript/2018/08/27/typescript-and-babel-7/",children:"MSDN blog post"})," about TypeScript and Babel 7)."]}),"\n",(0,i.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,i.jsxs)(t.p,{children:["While ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"})," is a great preset, you must know the limitation of it. Here is what is possible with TypeScript (and ",(0,i.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,i.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,i.jsxs)(t.p,{children:["This is the big ",(0,i.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,i.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,i.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,i.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,i.jsx)(t.p,{children:'With Babel, files are transpiled as isolated modules, there is no notion of "project". With TypeScript, files are part of a project and are compiled in that scope.'}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,i.jsx)(t.code,{children:"namespace"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"namespace app {\n export const VERSION = '1.0.0'\n export class App {\n /* ... */\n }\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,i.jsx)(t.code,{children:"const enum"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,i.jsx)(t.code,{children:"enum"}),", ",(0,i.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,i.jsxs)(t.p,{children:["You won't be able to do ",(0,i.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,i.jsx)(t.code,{children:"import"}),"/",(0,i.jsx)(t.code,{children:"export"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>c});var s=n(6540);const i={},o=s.createContext(i);function r(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/aeb823d8.e763955c.js b/assets/js/aeb823d8.f4474cf0.js similarity index 99% rename from assets/js/aeb823d8.e763955c.js rename to assets/js/aeb823d8.f4474cf0.js index 376837784d..06480fa850 100644 --- a/assets/js/aeb823d8.e763955c.js +++ b/assets/js/aeb823d8.f4474cf0.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3790],{1286:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>i,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/isolatedModules","title":"Isolated Modules option","description":"By default ts-jest uses TypeScript compiler in the context of a project (yours), with full type-checking and features.","source":"@site/versioned_docs/version-29.2/getting-started/options/isolatedModules.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/isolatedModules","permalink":"/ts-jest/docs/getting-started/options/isolatedModules","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/options/isolatedModules.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Isolated Modules option"}}');var a=s(4848),r=s(8453),o=s(9489),l=s(7227);const i={title:"Isolated Modules option"},c=void 0,u={},d=[{value:"Example",id:"example",level:3},{value:"Performance",id:"performance",level:2},{value:"Example",id:"example-1",level:3},{value:"Caveats",id:"caveats",level:2}];function h(e){const t={code:"code",h2:"h2",h3:"h3",p:"p",pre:"pre",...(0,r.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(t.p,{children:["By default ",(0,a.jsx)(t.code,{children:"ts-jest"})," uses TypeScript compiler in the context of a project (yours), with full type-checking and features.\nBut it can also be used to compile each file separately, what TypeScript calls an 'isolated module'.\nThat's what the ",(0,a.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,a.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,a.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,a.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,a.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,a.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\n",(0,a.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,a.jsxs)(o.A,{groupId:"code-examples",children:[(0,a.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n isolatedModules: true,\n },\n ],\n },\n}\n"})})}),(0,a.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process js/ts with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process js/ts/mjs/mts with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n isolatedModules: true,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,a.jsx)(l.A,{value:"JSON",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process js/ts with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process js/ts/mjs/mts with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "isolatedModules": true\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,a.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,a.jsxs)(t.p,{children:["Using ",(0,a.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,a.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,a.jsx)(t.code,{children:"include"})," in ",(0,a.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,a.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,a.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,a.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,a.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,a.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,a.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,a.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,a.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,a.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,a.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(h,{...e})}):h(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>o});s(6540);var n=s(4164);const a={tabItem:"tabItem_Ymn6"};var r=s(4848);function o(e){let{children:t,hidden:s,className:o}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,n.A)(a.tabItem,o),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>w});var n=s(6540),a=s(4164),r=s(4245),o=s(6347),l=s(6494),i=s(2814),c=s(5167),u=s(9900);function d(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:a}}=e;return{value:t,label:s,attributes:n,default:a}}))}(s);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function p(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:s}=e;const a=(0,o.W6)(),r=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,i.aZ)(r),(0,n.useCallback)((e=>{if(!r)return;const t=new URLSearchParams(a.location.search);t.set(r,e),a.replace({...a.location,search:t.toString()})}),[r,a])]}function f(e){const{defaultValue:t,queryString:s=!1,groupId:a}=e,r=h(e),[o,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:r}))),[c,d]=m({queryString:s,groupId:a}),[f,j]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,r]=(0,u.Dv)(s);return[a,(0,n.useCallback)((e=>{s&&r.set(e)}),[s,r])]}({groupId:a}),g=(()=>{const e=c??f;return p({value:e,tabValues:r})?e:null})();(0,l.A)((()=>{g&&i(g)}),[g]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!p({value:e,tabValues:r}))throw new Error(`Can't select invalid tab value=${e}`);i(e),d(e),j(e)}),[d,j,r]),tabValues:r}}var j=s(1062);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=s(4848);function x(e){let{className:t,block:s,selectedValue:n,selectValue:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),u=e=>{const t=e.currentTarget,s=i.indexOf(t),a=l[s].value;a!==n&&(c(t),o(a))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const s=i.indexOf(e.currentTarget)+1;t=i[s]??i[0];break}case"ArrowLeft":{const s=i.indexOf(e.currentTarget)-1;t=i[s]??i[i.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.A)("tabs",{"tabs--block":s},t),children:l.map((e=>{let{value:t,label:s,attributes:r}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:d,onClick:u,...r,className:(0,a.A)("tabs__item",g.tabItem,r?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:r}=e;const o=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===r));return e?(0,n.cloneElement)(e,{className:(0,a.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==r})))})}function y(e){const t=f(e);return(0,b.jsxs)("div",{className:(0,a.A)("tabs-container",g.tabList),children:[(0,b.jsx)(x,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function w(e){const t=(0,j.A)();return(0,b.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>o,x:()=>l});var n=s(6540);const a={},r=n.createContext(a);function o(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3790],{1286:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>i,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/isolatedModules","title":"Isolated Modules option","description":"By default ts-jest uses TypeScript compiler in the context of a project (yours), with full type-checking and features.","source":"@site/versioned_docs/version-29.2/getting-started/options/isolatedModules.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/isolatedModules","permalink":"/ts-jest/docs/getting-started/options/isolatedModules","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/options/isolatedModules.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Isolated Modules option"}}');var a=s(4848),r=s(8453),o=s(9489),l=s(7227);const i={title:"Isolated Modules option"},c=void 0,u={},d=[{value:"Example",id:"example",level:3},{value:"Performance",id:"performance",level:2},{value:"Example",id:"example-1",level:3},{value:"Caveats",id:"caveats",level:2}];function h(e){const t={code:"code",h2:"h2",h3:"h3",p:"p",pre:"pre",...(0,r.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(t.p,{children:["By default ",(0,a.jsx)(t.code,{children:"ts-jest"})," uses TypeScript compiler in the context of a project (yours), with full type-checking and features.\nBut it can also be used to compile each file separately, what TypeScript calls an 'isolated module'.\nThat's what the ",(0,a.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,a.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,a.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,a.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,a.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,a.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\n",(0,a.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,a.jsxs)(o.A,{groupId:"code-examples",children:[(0,a.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n isolatedModules: true,\n },\n ],\n },\n}\n"})})}),(0,a.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process js/ts with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process js/ts/mjs/mts with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n isolatedModules: true,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,a.jsx)(l.A,{value:"JSON",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process js/ts with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process js/ts/mjs/mts with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "isolatedModules": true\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,a.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,a.jsxs)(t.p,{children:["Using ",(0,a.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,a.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,a.jsx)(t.code,{children:"include"})," in ",(0,a.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,a.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,a.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,a.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,a.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,a.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,a.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,a.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,a.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,a.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,a.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(h,{...e})}):h(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>o});s(6540);var n=s(4164);const a={tabItem:"tabItem_Ymn6"};var r=s(4848);function o(e){let{children:t,hidden:s,className:o}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,n.A)(a.tabItem,o),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>w});var n=s(6540),a=s(4164),r=s(4245),o=s(6347),l=s(6494),i=s(2814),c=s(5167),u=s(9900);function d(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:a}}=e;return{value:t,label:s,attributes:n,default:a}}))}(s);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function p(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:s}=e;const a=(0,o.W6)(),r=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,i.aZ)(r),(0,n.useCallback)((e=>{if(!r)return;const t=new URLSearchParams(a.location.search);t.set(r,e),a.replace({...a.location,search:t.toString()})}),[r,a])]}function f(e){const{defaultValue:t,queryString:s=!1,groupId:a}=e,r=h(e),[o,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:r}))),[c,d]=m({queryString:s,groupId:a}),[f,j]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,r]=(0,u.Dv)(s);return[a,(0,n.useCallback)((e=>{s&&r.set(e)}),[s,r])]}({groupId:a}),g=(()=>{const e=c??f;return p({value:e,tabValues:r})?e:null})();(0,l.A)((()=>{g&&i(g)}),[g]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!p({value:e,tabValues:r}))throw new Error(`Can't select invalid tab value=${e}`);i(e),d(e),j(e)}),[d,j,r]),tabValues:r}}var j=s(1062);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=s(4848);function x(e){let{className:t,block:s,selectedValue:n,selectValue:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),u=e=>{const t=e.currentTarget,s=i.indexOf(t),a=l[s].value;a!==n&&(c(t),o(a))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const s=i.indexOf(e.currentTarget)+1;t=i[s]??i[0];break}case"ArrowLeft":{const s=i.indexOf(e.currentTarget)-1;t=i[s]??i[i.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.A)("tabs",{"tabs--block":s},t),children:l.map((e=>{let{value:t,label:s,attributes:r}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:d,onClick:u,...r,className:(0,a.A)("tabs__item",g.tabItem,r?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:r}=e;const o=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===r));return e?(0,n.cloneElement)(e,{className:(0,a.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==r})))})}function y(e){const t=f(e);return(0,b.jsxs)("div",{className:(0,a.A)("tabs-container",g.tabList),children:[(0,b.jsx)(x,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function w(e){const t=(0,j.A)();return(0,b.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>o,x:()=>l});var n=s(6540);const a={},r=n.createContext(a);function o(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/afb030c9.0176420a.js b/assets/js/afb030c9.cd6a94fc.js similarity index 98% rename from assets/js/afb030c9.0176420a.js rename to assets/js/afb030c9.cd6a94fc.js index abff921ca9..2d7b0198dc 100644 --- a/assets/js/afb030c9.0176420a.js +++ b/assets/js/afb030c9.cd6a94fc.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4746],{7833:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>c,default:()=>a,frontMatter:()=>i,metadata:()=>n,toc:()=>u});const n=JSON.parse('{"id":"processing","title":"Processing flow","description":"These are internal technical documents. If you\'re not a contributor to ts-jest, but simply trying to use the library you\'ll find nothing of value here","source":"@site/versioned_docs/version-28.0/processing.md","sourceDirName":".","slug":"/processing","permalink":"/ts-jest/docs/28.0/processing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/processing.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"processing","title":"Processing flow"},"sidebar":"version-28.0-docs","previous":{"title":"Introduction","permalink":"/ts-jest/docs/28.0/"},"next":{"title":"Contributing","permalink":"/ts-jest/docs/28.0/contributing"}}');var o=s(4848),r=s(8453);const i={id:"processing",title:"Processing flow"},c=void 0,l={},u=[{value:"Jest process",id:"jest-process",level:2},{value:"ts-jest process",id:"ts-jest-process",level:2}];function d(e){const t={code:"code",em:"em",h2:"h2",img:"img",p:"p",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.p,{children:(0,o.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,o.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,o.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,o.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,o.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLJRRjim37tNLn3Omn9WwGUaG8Uz3YWmOFq1nQ9YjJ8PY7Iz0lduGHV7YHjWyvDruI7FuH7FfyGTYd0w6r6Rr9YzoayKVMWd6-4nTRXzD2Pus4ZFOtGWcW8TW__ulWNjaM3pWR8r-rTXMWuVpUu9nfEpYgR2F1g3KH0sn5k3v8Ali3v493iW83c1AMWF3-v1vHPz2YU46OXO4L8uzcg8WH0TA4F7mob4D0vzeA212JAsv6IGGwuBCESlBtqGZNXkSGasdUrwTDjpgIi8HwleO60tHfHRkWlIlaje5S6IWm9WL21QEe9WUW-vtiPsztHXK3CGd31944NI6hlIj0e80muDsYSUFWNTAFllqlUDSD7QQB8aUVbSxZPn8terHJsOGenmm5bUPwp0Ei6Ln000IpLGljkCTUyYJbqkMQ5zWtr360M1VQv-3hYSLzaTs0E_Nwdlp88momP1CfA3gKUw72UqBj2ncQJkhNZKlbKAeoWFyEFtIraNsJod0PDK3ci6FQQIU2e_FGVHd8rzEt_DBstWxYrVSapu3Qp0X362dSiP1TEk-3bRV4vfixVdAmURYJ51n-J3qNnciNkwz6xnN-7amv-s0uCzDHwVJ7UxVSzyHQRprJov-_YN9zycIMxkmHumhlnPzkuFeaNapiOeDNoNfJINz8iP_tS4zLR0UiNqgs90p_osVZGsDsPzwTwOMseCrRdv8YJKCP4OuG6rpqu8-hMyB5EiQGK8fzQEwv5LozmlXhlg8fBx2m00"})]})}function a(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4746],{7833:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>c,default:()=>a,frontMatter:()=>i,metadata:()=>n,toc:()=>u});const n=JSON.parse('{"id":"processing","title":"Processing flow","description":"These are internal technical documents. If you\'re not a contributor to ts-jest, but simply trying to use the library you\'ll find nothing of value here","source":"@site/versioned_docs/version-28.0/processing.md","sourceDirName":".","slug":"/processing","permalink":"/ts-jest/docs/28.0/processing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/processing.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"processing","title":"Processing flow"},"sidebar":"version-28.0-docs","previous":{"title":"Introduction","permalink":"/ts-jest/docs/28.0/"},"next":{"title":"Contributing","permalink":"/ts-jest/docs/28.0/contributing"}}');var o=s(4848),r=s(8453);const i={id:"processing",title:"Processing flow"},c=void 0,l={},u=[{value:"Jest process",id:"jest-process",level:2},{value:"ts-jest process",id:"ts-jest-process",level:2}];function d(e){const t={code:"code",em:"em",h2:"h2",img:"img",p:"p",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.p,{children:(0,o.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,o.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,o.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,o.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,o.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLJRRjim37tNLn3Omn9WwGUaG8Uz3YWmOFq1nQ9YjJ8PY7Iz0lduGHV7YHjWyvDruI7FuH7FfyGTYd0w6r6Rr9YzoayKVMWd6-4nTRXzD2Pus4ZFOtGWcW8TW__ulWNjaM3pWR8r-rTXMWuVpUu9nfEpYgR2F1g3KH0sn5k3v8Ali3v493iW83c1AMWF3-v1vHPz2YU46OXO4L8uzcg8WH0TA4F7mob4D0vzeA212JAsv6IGGwuBCESlBtqGZNXkSGasdUrwTDjpgIi8HwleO60tHfHRkWlIlaje5S6IWm9WL21QEe9WUW-vtiPsztHXK3CGd31944NI6hlIj0e80muDsYSUFWNTAFllqlUDSD7QQB8aUVbSxZPn8terHJsOGenmm5bUPwp0Ei6Ln000IpLGljkCTUyYJbqkMQ5zWtr360M1VQv-3hYSLzaTs0E_Nwdlp88momP1CfA3gKUw72UqBj2ncQJkhNZKlbKAeoWFyEFtIraNsJod0PDK3ci6FQQIU2e_FGVHd8rzEt_DBstWxYrVSapu3Qp0X362dSiP1TEk-3bRV4vfixVdAmURYJ51n-J3qNnciNkwz6xnN-7amv-s0uCzDHwVJ7UxVSzyHQRprJov-_YN9zycIMxkmHumhlnPzkuFeaNapiOeDNoNfJINz8iP_tS4zLR0UiNqgs90p_osVZGsDsPzwTwOMseCrRdv8YJKCP4OuG6rpqu8-hMyB5EiQGK8fzQEwv5LozmlXhlg8fBx2m00"})]})}function a(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/b317f538.6b770618.js b/assets/js/b317f538.35c80c6c.js similarity index 97% rename from assets/js/b317f538.6b770618.js rename to assets/js/b317f538.35c80c6c.js index 31bb5c9157..b0585f47ed 100644 --- a/assets/js/b317f538.6b770618.js +++ b/assets/js/b317f538.35c80c6c.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8392],{9211:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/version-checking","title":"Version checking","description":"By default, ts-jest supports a range of versions for jest/typescript. One uses incompatible versions will receive a warning","source":"@site/versioned_docs/version-29.0/getting-started/version-checking.md","sourceDirName":"getting-started","slug":"/getting-started/version-checking","permalink":"/ts-jest/docs/29.0/getting-started/version-checking","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/version-checking.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"version-checking","title":"Version checking"},"sidebar":"version-29.0-docs","previous":{"title":"Paths mapping","permalink":"/ts-jest/docs/29.0/getting-started/paths-mapping"},"next":{"title":"ESM Support","permalink":"/ts-jest/docs/29.0/guides/esm-support"}}');var i=n(4848),r=n(8453);const o={id:"version-checking",title:"Version checking"},c=void 0,a={},d=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["By default, ",(0,i.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,i.jsx)(t.code,{children:"jest"}),"/",(0,i.jsx)(t.code,{children:"typescript"}),". One uses incompatible versions will receive a warning\nmessage while running tests. This warning message can be opt-out by setting environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"export TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Windows"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,i.jsxs)(t.p,{children:["As long as the environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"})," stays, the warning message will no longer show.\nThis can lead to unexpected errors due to the usage of incompatible versions' dependencies. Use this environment variable with precautions."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>c});var s=n(6540);const i={},r=s.createContext(i);function o(e){const t=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8392],{9211:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/version-checking","title":"Version checking","description":"By default, ts-jest supports a range of versions for jest/typescript. One uses incompatible versions will receive a warning","source":"@site/versioned_docs/version-29.0/getting-started/version-checking.md","sourceDirName":"getting-started","slug":"/getting-started/version-checking","permalink":"/ts-jest/docs/29.0/getting-started/version-checking","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/version-checking.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"version-checking","title":"Version checking"},"sidebar":"version-29.0-docs","previous":{"title":"Paths mapping","permalink":"/ts-jest/docs/29.0/getting-started/paths-mapping"},"next":{"title":"ESM Support","permalink":"/ts-jest/docs/29.0/guides/esm-support"}}');var i=n(4848),r=n(8453);const o={id:"version-checking",title:"Version checking"},c=void 0,a={},d=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["By default, ",(0,i.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,i.jsx)(t.code,{children:"jest"}),"/",(0,i.jsx)(t.code,{children:"typescript"}),". One uses incompatible versions will receive a warning\nmessage while running tests. This warning message can be opt-out by setting environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"export TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Windows"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,i.jsxs)(t.p,{children:["As long as the environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"})," stays, the warning message will no longer show.\nThis can lead to unexpected errors due to the usage of incompatible versions' dependencies. Use this environment variable with precautions."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>c});var s=n(6540);const i={},r=s.createContext(i);function o(e){const t=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/b519512b.be96fda8.js b/assets/js/b519512b.18577b7e.js similarity index 98% rename from assets/js/b519512b.be96fda8.js rename to assets/js/b519512b.18577b7e.js index f19ff15f12..2988c2d3cb 100644 --- a/assets/js/b519512b.be96fda8.js +++ b/assets/js/b519512b.18577b7e.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8116],{6468:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>r,contentTitle:()=>a,default:()=>p,frontMatter:()=>c,metadata:()=>n,toc:()=>l});const n=JSON.parse('{"id":"guides/react-native","title":"Using with React Native","description":"To use ts-jest with React Native + TypeScript and Babel 7, you\'ll first need to follow this tutorial.","source":"@site/versioned_docs/version-27.0/guides/react-native.md","sourceDirName":"guides","slug":"/guides/react-native","permalink":"/ts-jest/docs/27.0/guides/react-native","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/guides/react-native.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"react-native","title":"Using with React Native"},"sidebar":"version-27.0-docs","previous":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/27.0/guides/mock-es6-class"},"next":{"title":"Test helpers","permalink":"/ts-jest/docs/27.0/guides/test-helpers"}}');var i=s(4848),o=s(8453);const c={id:"react-native",title:"Using with React Native"},a=void 0,r={},l=[{value:"Babel config",id:"babel-config",level:3},{value:"TypeScript Configuration",id:"typescript-configuration",level:3},{value:"Jest config",id:"jest-config",level:3}];function d(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["To use ",(0,i.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,i.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,i.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,i.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,i.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,i.jsx)(t.code,{children:".babelrc"})," to ",(0,i.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"// babel.config.js\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n"})}),"\n",(0,i.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,i.jsxs)(t.p,{children:["Create a new ",(0,i.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-json",children:'// tsconfig.spec.json\n{\n "extends": "./tsconfig.json",\n "compilerOptions": {\n "jsx": "react"\n }\n}\n'})}),"\n",(0,i.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,i.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,i.jsx)(t.code,{children:"jest"})," key of ",(0,i.jsx)(t.code,{children:"package.json"})," to ",(0,i.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n preset: 'react-native',\n globals: {\n 'ts-jest': {\n tsconfig: 'tsconfig.spec.json',\n },\n },\n transform: {\n '^.+\\\\.jsx$': 'babel-jest',\n '^.+\\\\.tsx?$': 'ts-jest',\n },\n moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],\n}\n"})})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>c,x:()=>a});var n=s(6540);const i={},o=n.createContext(i);function c(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:c(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8116],{6468:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>r,contentTitle:()=>a,default:()=>p,frontMatter:()=>c,metadata:()=>n,toc:()=>l});const n=JSON.parse('{"id":"guides/react-native","title":"Using with React Native","description":"To use ts-jest with React Native + TypeScript and Babel 7, you\'ll first need to follow this tutorial.","source":"@site/versioned_docs/version-27.0/guides/react-native.md","sourceDirName":"guides","slug":"/guides/react-native","permalink":"/ts-jest/docs/27.0/guides/react-native","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/guides/react-native.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"react-native","title":"Using with React Native"},"sidebar":"version-27.0-docs","previous":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/27.0/guides/mock-es6-class"},"next":{"title":"Test helpers","permalink":"/ts-jest/docs/27.0/guides/test-helpers"}}');var i=s(4848),o=s(8453);const c={id:"react-native",title:"Using with React Native"},a=void 0,r={},l=[{value:"Babel config",id:"babel-config",level:3},{value:"TypeScript Configuration",id:"typescript-configuration",level:3},{value:"Jest config",id:"jest-config",level:3}];function d(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["To use ",(0,i.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,i.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,i.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,i.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,i.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,i.jsx)(t.code,{children:".babelrc"})," to ",(0,i.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"// babel.config.js\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n"})}),"\n",(0,i.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,i.jsxs)(t.p,{children:["Create a new ",(0,i.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-json",children:'// tsconfig.spec.json\n{\n "extends": "./tsconfig.json",\n "compilerOptions": {\n "jsx": "react"\n }\n}\n'})}),"\n",(0,i.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,i.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,i.jsx)(t.code,{children:"jest"})," key of ",(0,i.jsx)(t.code,{children:"package.json"})," to ",(0,i.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n preset: 'react-native',\n globals: {\n 'ts-jest': {\n tsconfig: 'tsconfig.spec.json',\n },\n },\n transform: {\n '^.+\\\\.jsx$': 'babel-jest',\n '^.+\\\\.tsx?$': 'ts-jest',\n },\n moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],\n}\n"})})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>c,x:()=>a});var n=s(6540);const i={},o=n.createContext(i);function c(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:c(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/b72fc7f8.205d41b7.js b/assets/js/b72fc7f8.69e0097e.js similarity index 99% rename from assets/js/b72fc7f8.205d41b7.js rename to assets/js/b72fc7f8.69e0097e.js index e46d7f7c54..cea643baf9 100644 --- a/assets/js/b72fc7f8.205d41b7.js +++ b/assets/js/b72fc7f8.69e0097e.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9610],{831:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>p,frontMatter:()=>l,metadata:()=>r,toc:()=>d});const r=JSON.parse('{"id":"migration","title":"Migration from <=23.10","description":"You can use the config:migrate tool of ts-jest CLI if you\'re coming from an older version to help you migrate your Jest configuration.","source":"@site/versioned_docs/version-29.2/migration.md","sourceDirName":".","slug":"/migration","permalink":"/ts-jest/docs/migration","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/migration.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"migration","title":"Migration from <=23.10"},"sidebar":"version-29.1-docs","previous":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/babel7-or-ts"},"next":{"title":"Debugging ts-jest","permalink":"/ts-jest/docs/debugging"}}');var a=n(4848),s=n(8453),o=n(9489),i=n(7227);const l={id:"migration",title:"Migration from <=23.10"},u=void 0,c={},d=[];function m(e){const t={code:"code",em:"em",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(t.p,{children:["You can use the ",(0,a.jsx)(t.code,{children:"config:migrate"})," tool of ",(0,a.jsx)(t.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,a.jsx)(t.p,{children:(0,a.jsxs)(t.em,{children:["If you're using ",(0,a.jsx)(t.code,{children:"jest.config.js"}),":"]})}),"\n",(0,a.jsxs)(o.A,{groupId:"code-examples",children:[(0,a.jsx)(i.A,{value:"npm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-npm",metastring:"tab",children:"npx ts-jest config:migrate jest.config.js\n"})})}),(0,a.jsx)(i.A,{value:"Yarn",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-Yarn",metastring:"tab",children:"yarn ts-jest config:migrate jest.config.js\n"})})})]}),"\n",(0,a.jsx)(t.p,{children:(0,a.jsxs)(t.em,{children:["If you're using ",(0,a.jsx)(t.code,{children:"jest"})," config property of ",(0,a.jsx)(t.code,{children:"package.json"}),":"]})}),"\n",(0,a.jsxs)(o.A,{groupId:"code-examples",children:[(0,a.jsx)(i.A,{value:"npm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-npm",metastring:"tab",children:"npx ts-jest config:migrate package.json\n"})})}),(0,a.jsx)(i.A,{value:"Yarn",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-Yarn",metastring:"tab",children:"yarn ts-jest config:migrate package.json\n"})})})]})]})}function p(e={}){const{wrapper:t}={...(0,s.R)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(m,{...e})}):m(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var r=n(4164);const a={tabItem:"tabItem_Ymn6"};var s=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.A)(a.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>I});var r=n(6540),a=n(4164),s=n(4245),o=n(6347),i=n(6494),l=n(2814),u=n(5167),c=n(9900);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function m(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(n);return function(e){const t=(0,u.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const a=(0,o.W6)(),s=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(s),(0,r.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function g(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,s=m(e),[o,l]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:s}))),[u,d]=f({queryString:n,groupId:a}),[g,h]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,c.Dv)(n);return[a,(0,r.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),b=(()=>{const e=u??g;return p({value:e,tabValues:s})?e:null})();(0,i.A)((()=>{b&&l(b)}),[b]);return{selectedValue:o,selectValue:(0,r.useCallback)((e=>{if(!p({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),h(e)}),[d,h,s]),tabValues:s}}var h=n(1062);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var j=n(4848);function v(e){let{className:t,block:n,selectedValue:r,selectValue:o,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:u}=(0,s.a_)(),c=e=>{const t=e.currentTarget,n=l.indexOf(t),a=i[n].value;a!==r&&(u(t),o(a))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,j.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.A)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,j.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>l.push(e),onKeyDown:d,onClick:c,...s,className:(0,a.A)("tabs__item",b.tabItem,s?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:s}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===s));return e?(0,r.cloneElement)(e,{className:(0,a.A)("margin-top--md",e.props.className)}):null}return(0,j.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==s})))})}function y(e){const t=g(e);return(0,j.jsxs)("div",{className:(0,a.A)("tabs-container",b.tabList),children:[(0,j.jsx)(v,{...t,...e}),(0,j.jsx)(x,{...t,...e})]})}function I(e){const t=(0,h.A)();return(0,j.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>i});var r=n(6540);const a={},s=r.createContext(a);function o(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9610],{831:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>p,frontMatter:()=>l,metadata:()=>r,toc:()=>d});const r=JSON.parse('{"id":"migration","title":"Migration from <=23.10","description":"You can use the config:migrate tool of ts-jest CLI if you\'re coming from an older version to help you migrate your Jest configuration.","source":"@site/versioned_docs/version-29.2/migration.md","sourceDirName":".","slug":"/migration","permalink":"/ts-jest/docs/migration","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/migration.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"migration","title":"Migration from <=23.10"},"sidebar":"version-29.1-docs","previous":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/babel7-or-ts"},"next":{"title":"Debugging ts-jest","permalink":"/ts-jest/docs/debugging"}}');var a=n(4848),s=n(8453),o=n(9489),i=n(7227);const l={id:"migration",title:"Migration from <=23.10"},u=void 0,c={},d=[];function m(e){const t={code:"code",em:"em",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(t.p,{children:["You can use the ",(0,a.jsx)(t.code,{children:"config:migrate"})," tool of ",(0,a.jsx)(t.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,a.jsx)(t.p,{children:(0,a.jsxs)(t.em,{children:["If you're using ",(0,a.jsx)(t.code,{children:"jest.config.js"}),":"]})}),"\n",(0,a.jsxs)(o.A,{groupId:"code-examples",children:[(0,a.jsx)(i.A,{value:"npm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-npm",metastring:"tab",children:"npx ts-jest config:migrate jest.config.js\n"})})}),(0,a.jsx)(i.A,{value:"Yarn",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-Yarn",metastring:"tab",children:"yarn ts-jest config:migrate jest.config.js\n"})})})]}),"\n",(0,a.jsx)(t.p,{children:(0,a.jsxs)(t.em,{children:["If you're using ",(0,a.jsx)(t.code,{children:"jest"})," config property of ",(0,a.jsx)(t.code,{children:"package.json"}),":"]})}),"\n",(0,a.jsxs)(o.A,{groupId:"code-examples",children:[(0,a.jsx)(i.A,{value:"npm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-npm",metastring:"tab",children:"npx ts-jest config:migrate package.json\n"})})}),(0,a.jsx)(i.A,{value:"Yarn",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-Yarn",metastring:"tab",children:"yarn ts-jest config:migrate package.json\n"})})})]})]})}function p(e={}){const{wrapper:t}={...(0,s.R)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(m,{...e})}):m(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var r=n(4164);const a={tabItem:"tabItem_Ymn6"};var s=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.A)(a.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>I});var r=n(6540),a=n(4164),s=n(4245),o=n(6347),i=n(6494),l=n(2814),u=n(5167),c=n(9900);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function m(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(n);return function(e){const t=(0,u.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const a=(0,o.W6)(),s=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(s),(0,r.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function g(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,s=m(e),[o,l]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:s}))),[u,d]=f({queryString:n,groupId:a}),[g,h]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,c.Dv)(n);return[a,(0,r.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),b=(()=>{const e=u??g;return p({value:e,tabValues:s})?e:null})();(0,i.A)((()=>{b&&l(b)}),[b]);return{selectedValue:o,selectValue:(0,r.useCallback)((e=>{if(!p({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),h(e)}),[d,h,s]),tabValues:s}}var h=n(1062);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var j=n(4848);function v(e){let{className:t,block:n,selectedValue:r,selectValue:o,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:u}=(0,s.a_)(),c=e=>{const t=e.currentTarget,n=l.indexOf(t),a=i[n].value;a!==r&&(u(t),o(a))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,j.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.A)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,j.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>l.push(e),onKeyDown:d,onClick:c,...s,className:(0,a.A)("tabs__item",b.tabItem,s?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:s}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===s));return e?(0,r.cloneElement)(e,{className:(0,a.A)("margin-top--md",e.props.className)}):null}return(0,j.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==s})))})}function y(e){const t=g(e);return(0,j.jsxs)("div",{className:(0,a.A)("tabs-container",b.tabList),children:[(0,j.jsx)(v,{...t,...e}),(0,j.jsx)(x,{...t,...e})]})}function I(e){const t=(0,h.A)();return(0,j.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>i});var r=n(6540);const a={},s=r.createContext(a);function o(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/b809b403.4d8874bb.js b/assets/js/b809b403.a5ae287c.js similarity index 97% rename from assets/js/b809b403.4d8874bb.js rename to assets/js/b809b403.a5ae287c.js index 7c04a62f53..38117b82b1 100644 --- a/assets/js/b809b403.4d8874bb.js +++ b/assets/js/b809b403.a5ae287c.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7693],{8982:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>p,frontMatter:()=>i,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/useESM","title":"useESM option","description":"The useESM option allows ts-jest to transform codes to ESM syntax if possible.","source":"@site/versioned_docs/version-27.0/getting-started/options/useESM.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/useESM","permalink":"/ts-jest/docs/27.0/getting-started/options/useESM","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/options/useESM.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"useESM option"}}');var o=s(4848),r=s(8453);const i={title:"useESM option"},a=void 0,c={},d=[{value:"Examples",id:"examples",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["The ",(0,o.jsx)(t.code,{children:"useESM"})," option allows ",(0,o.jsx)(t.code,{children:"ts-jest"})," to transform codes to ESM syntax ",(0,o.jsx)(t.strong,{children:"if possible"}),"."]}),"\n",(0,o.jsxs)(t.p,{children:["The default value is ",(0,o.jsx)(t.strong,{children:"false"}),", ",(0,o.jsx)(t.code,{children:"ts-jest"})," will transform codes to ",(0,o.jsx)(t.code,{children:"CommonJS"})," syntax."]}),"\n",(0,o.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n useESM: true,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "useESM": true\n }\n }\n }\n}\n'})})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>i,x:()=>a});var n=s(6540);const o={},r=n.createContext(o);function i(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7693],{8982:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>p,frontMatter:()=>i,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/useESM","title":"useESM option","description":"The useESM option allows ts-jest to transform codes to ESM syntax if possible.","source":"@site/versioned_docs/version-27.0/getting-started/options/useESM.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/useESM","permalink":"/ts-jest/docs/27.0/getting-started/options/useESM","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/options/useESM.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"useESM option"}}');var o=s(4848),r=s(8453);const i={title:"useESM option"},a=void 0,c={},d=[{value:"Examples",id:"examples",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["The ",(0,o.jsx)(t.code,{children:"useESM"})," option allows ",(0,o.jsx)(t.code,{children:"ts-jest"})," to transform codes to ESM syntax ",(0,o.jsx)(t.strong,{children:"if possible"}),"."]}),"\n",(0,o.jsxs)(t.p,{children:["The default value is ",(0,o.jsx)(t.strong,{children:"false"}),", ",(0,o.jsx)(t.code,{children:"ts-jest"})," will transform codes to ",(0,o.jsx)(t.code,{children:"CommonJS"})," syntax."]}),"\n",(0,o.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n useESM: true,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "useESM": true\n }\n }\n }\n}\n'})})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>i,x:()=>a});var n=s(6540);const o={},r=n.createContext(o);function i(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/b96776d9.c20e4410.js b/assets/js/b96776d9.c3b55621.js similarity index 99% rename from assets/js/b96776d9.c20e4410.js rename to assets/js/b96776d9.c3b55621.js index f62d74d153..07224897b2 100644 --- a/assets/js/b96776d9.c20e4410.js +++ b/assets/js/b96776d9.c3b55621.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4623],{2845:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>l,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"guides/react-native","title":"Using with React Native","description":"To use ts-jest with React Native + TypeScript and Babel 7, you\'ll first need to follow this tutorial.","source":"@site/versioned_docs/version-29.2/guides/react-native.md","sourceDirName":"guides","slug":"/guides/react-native","permalink":"/ts-jest/docs/guides/react-native","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/guides/react-native.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"react-native","title":"Using with React Native"},"sidebar":"version-29.1-docs","previous":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/guides/mock-es6-class"},"next":{"title":"Troubleshooting","permalink":"/ts-jest/docs/guides/troubleshooting"}}');var r=n(4848),a=n(8453),o=n(9489),i=n(7227);const l={id:"react-native",title:"Using with React Native"},c=void 0,u={},d=[{value:"Babel config",id:"babel-config",level:3},{value:"TypeScript Configuration",id:"typescript-configuration",level:3},{value:"Jest config",id:"jest-config",level:3}];function f(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["To use ",(0,r.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,r.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,r.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,r.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,r.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,r.jsx)(t.code,{children:".babelrc"})," to ",(0,r.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n\nexport default jestConfig\n"})})})]}),"\n",(0,r.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,r.jsxs)(t.p,{children:["Create a new ",(0,r.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-json",children:'// tsconfig.spec.json\n{\n "extends": "./tsconfig.json",\n "compilerOptions": {\n "jsx": "react"\n }\n}\n'})}),"\n",(0,r.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,r.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,r.jsx)(t.code,{children:"jest"})," key of ",(0,r.jsx)(t.code,{children:"package.json"})," to ",(0,r.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\nconst { createJsWithBabelPreset } = require('ts-jest')\n\nconst jsWithBabelPreset = createJsWithBabelPreset({\n tsconfig: 'tsconfig.spec.json',\n babelConfig: true,\n})\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n preset: 'react-native',\n transform: jsWithBabelPreset.transform,\n moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport { createJsWithBabelPreset, JestConfigWithTsJest } from 'ts-jest'\n\nconst jsWithBabelPreset = createJsWithBabelPreset({\n tsconfig: 'tsconfig.spec.json',\n babelConfig: true,\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n preset: 'react-native',\n transform: jsWithBabelPreset.transform,\n moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],\n}\n\nexport default jestConfig\n"})})})]})]})}function p(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(f,{...e})}):f(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var s=n(4164);const r={tabItem:"tabItem_Ymn6"};var a=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,s.A)(r.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),r=n(4164),a=n(4245),o=n(6347),i=n(6494),l=n(2814),c=n(5167),u=n(9900);function d(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function f(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:r}}=e;return{value:t,label:n,attributes:s,default:r}}))}(n);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:n}=e;const r=(0,o.W6)(),a=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(a),(0,s.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,a=f(e),[o,l]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:a}))),[c,d]=h({queryString:n,groupId:r}),[b,g]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,u.Dv)(n);return[r,(0,s.useCallback)((e=>{n&&a.set(e)}),[n,a])]}({groupId:r}),m=(()=>{const e=c??b;return p({value:e,tabValues:a})?e:null})();(0,i.A)((()=>{m&&l(m)}),[m]);return{selectedValue:o,selectValue:(0,s.useCallback)((e=>{if(!p({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),g(e)}),[d,g,a]),tabValues:a}}var g=n(1062);const m={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var j=n(4848);function v(e){let{className:t,block:n,selectedValue:s,selectValue:o,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,a.a_)(),u=e=>{const t=e.currentTarget,n=l.indexOf(t),r=i[n].value;r!==s&&(c(t),o(r))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,j.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:a}=e;return(0,j.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>l.push(e),onKeyDown:d,onClick:u,...a,className:(0,r.A)("tabs__item",m.tabItem,a?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:a}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,s.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,j.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=b(e);return(0,j.jsxs)("div",{className:(0,r.A)("tabs-container",m.tabList),children:[(0,j.jsx)(v,{...t,...e}),(0,j.jsx)(x,{...t,...e})]})}function w(e){const t=(0,g.A)();return(0,j.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>i});var s=n(6540);const r={},a=s.createContext(r);function o(e){const t=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),s.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4623],{2845:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>l,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"guides/react-native","title":"Using with React Native","description":"To use ts-jest with React Native + TypeScript and Babel 7, you\'ll first need to follow this tutorial.","source":"@site/versioned_docs/version-29.2/guides/react-native.md","sourceDirName":"guides","slug":"/guides/react-native","permalink":"/ts-jest/docs/guides/react-native","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/guides/react-native.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"react-native","title":"Using with React Native"},"sidebar":"version-29.1-docs","previous":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/guides/mock-es6-class"},"next":{"title":"Troubleshooting","permalink":"/ts-jest/docs/guides/troubleshooting"}}');var r=n(4848),a=n(8453),o=n(9489),i=n(7227);const l={id:"react-native",title:"Using with React Native"},c=void 0,u={},d=[{value:"Babel config",id:"babel-config",level:3},{value:"TypeScript Configuration",id:"typescript-configuration",level:3},{value:"Jest config",id:"jest-config",level:3}];function f(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["To use ",(0,r.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,r.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,r.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,r.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,r.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,r.jsx)(t.code,{children:".babelrc"})," to ",(0,r.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n\nexport default jestConfig\n"})})})]}),"\n",(0,r.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,r.jsxs)(t.p,{children:["Create a new ",(0,r.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-json",children:'// tsconfig.spec.json\n{\n "extends": "./tsconfig.json",\n "compilerOptions": {\n "jsx": "react"\n }\n}\n'})}),"\n",(0,r.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,r.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,r.jsx)(t.code,{children:"jest"})," key of ",(0,r.jsx)(t.code,{children:"package.json"})," to ",(0,r.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\nconst { createJsWithBabelPreset } = require('ts-jest')\n\nconst jsWithBabelPreset = createJsWithBabelPreset({\n tsconfig: 'tsconfig.spec.json',\n babelConfig: true,\n})\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n preset: 'react-native',\n transform: jsWithBabelPreset.transform,\n moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport { createJsWithBabelPreset, JestConfigWithTsJest } from 'ts-jest'\n\nconst jsWithBabelPreset = createJsWithBabelPreset({\n tsconfig: 'tsconfig.spec.json',\n babelConfig: true,\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n preset: 'react-native',\n transform: jsWithBabelPreset.transform,\n moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],\n}\n\nexport default jestConfig\n"})})})]})]})}function p(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(f,{...e})}):f(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var s=n(4164);const r={tabItem:"tabItem_Ymn6"};var a=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,s.A)(r.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),r=n(4164),a=n(4245),o=n(6347),i=n(6494),l=n(2814),c=n(5167),u=n(9900);function d(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function f(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:r}}=e;return{value:t,label:n,attributes:s,default:r}}))}(n);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:n}=e;const r=(0,o.W6)(),a=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(a),(0,s.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,a=f(e),[o,l]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:a}))),[c,d]=h({queryString:n,groupId:r}),[b,g]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,u.Dv)(n);return[r,(0,s.useCallback)((e=>{n&&a.set(e)}),[n,a])]}({groupId:r}),m=(()=>{const e=c??b;return p({value:e,tabValues:a})?e:null})();(0,i.A)((()=>{m&&l(m)}),[m]);return{selectedValue:o,selectValue:(0,s.useCallback)((e=>{if(!p({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),g(e)}),[d,g,a]),tabValues:a}}var g=n(1062);const m={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var j=n(4848);function v(e){let{className:t,block:n,selectedValue:s,selectValue:o,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,a.a_)(),u=e=>{const t=e.currentTarget,n=l.indexOf(t),r=i[n].value;r!==s&&(c(t),o(r))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,j.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:a}=e;return(0,j.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>l.push(e),onKeyDown:d,onClick:u,...a,className:(0,r.A)("tabs__item",m.tabItem,a?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:a}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,s.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,j.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=b(e);return(0,j.jsxs)("div",{className:(0,r.A)("tabs-container",m.tabList),children:[(0,j.jsx)(v,{...t,...e}),(0,j.jsx)(x,{...t,...e})]})}function w(e){const t=(0,g.A)();return(0,j.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>i});var s=n(6540);const r={},a=s.createContext(r);function o(e){const t=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),s.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/bdf18d96.ef8ea76d.js b/assets/js/bdf18d96.26b56a84.js similarity index 98% rename from assets/js/bdf18d96.ef8ea76d.js rename to assets/js/bdf18d96.26b56a84.js index db99a3933f..75718f371b 100644 --- a/assets/js/bdf18d96.ef8ea76d.js +++ b/assets/js/bdf18d96.26b56a84.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7555],{4078:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>a,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>t,toc:()=>l});const t=JSON.parse('{"id":"guides/mock-es6-class","title":"Mock ES6 class","description":"TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.","source":"@site/versioned_docs/version-27.0/guides/mock-es6-class.md","sourceDirName":"guides","slug":"/guides/mock-es6-class","permalink":"/ts-jest/docs/27.0/guides/mock-es6-class","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/guides/mock-es6-class.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"mock-es6-class","title":"Mock ES6 class"},"sidebar":"version-27.0-docs","previous":{"title":"ESM Support","permalink":"/ts-jest/docs/27.0/guides/esm-support"},"next":{"title":"Using with React Native","permalink":"/ts-jest/docs/27.0/guides/react-native"}}');var o=n(4848),r=n(8453);const i={id:"mock-es6-class",title:"Mock ES6 class"},c=void 0,a={},l=[];function d(e){const s={code:"code",p:"p",pre:"pre",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(s.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,o.jsx)(s.code,{children:"const soundPlayer = require('./sound-player')"}),". Therefore creating an instance of the class that was exported as\na default will look like this: ",(0,o.jsx)(s.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"jest.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\n })\n})\n"})}),"\n",(0,o.jsx)(s.p,{children:"You will get the error"}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,o.jsxs)(s.p,{children:["because ",(0,o.jsx)(s.code,{children:"soundPlayer.default"})," does not point to a function. Your mock has to return an object which has a property default\nthat points to a function."]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"jest.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\n }\n }),\n }\n})\n"})}),"\n",(0,o.jsxs)(s.p,{children:["For named imports, like ",(0,o.jsx)(s.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,o.jsx)(s.code,{children:"default"})," with imported module name, ",(0,o.jsx)(s.code,{children:"OAuth2"})," in this example:"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"jest.mock('./oauth', () => {\n return {\n OAuth2: ... // mock here\n }\n})\n"})})]})}function u(e={}){const{wrapper:s}={...(0,r.R)(),...e.components};return s?(0,o.jsx)(s,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>i,x:()=>c});var t=n(6540);const o={},r=t.createContext(o);function i(e){const s=t.useContext(r);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function c(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),t.createElement(r.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7555],{4078:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>a,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>t,toc:()=>l});const t=JSON.parse('{"id":"guides/mock-es6-class","title":"Mock ES6 class","description":"TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.","source":"@site/versioned_docs/version-27.0/guides/mock-es6-class.md","sourceDirName":"guides","slug":"/guides/mock-es6-class","permalink":"/ts-jest/docs/27.0/guides/mock-es6-class","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/guides/mock-es6-class.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"mock-es6-class","title":"Mock ES6 class"},"sidebar":"version-27.0-docs","previous":{"title":"ESM Support","permalink":"/ts-jest/docs/27.0/guides/esm-support"},"next":{"title":"Using with React Native","permalink":"/ts-jest/docs/27.0/guides/react-native"}}');var o=n(4848),r=n(8453);const i={id:"mock-es6-class",title:"Mock ES6 class"},c=void 0,a={},l=[];function d(e){const s={code:"code",p:"p",pre:"pre",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(s.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,o.jsx)(s.code,{children:"const soundPlayer = require('./sound-player')"}),". Therefore creating an instance of the class that was exported as\na default will look like this: ",(0,o.jsx)(s.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"jest.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\n })\n})\n"})}),"\n",(0,o.jsx)(s.p,{children:"You will get the error"}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,o.jsxs)(s.p,{children:["because ",(0,o.jsx)(s.code,{children:"soundPlayer.default"})," does not point to a function. Your mock has to return an object which has a property default\nthat points to a function."]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"jest.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\n }\n }),\n }\n})\n"})}),"\n",(0,o.jsxs)(s.p,{children:["For named imports, like ",(0,o.jsx)(s.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,o.jsx)(s.code,{children:"default"})," with imported module name, ",(0,o.jsx)(s.code,{children:"OAuth2"})," in this example:"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"jest.mock('./oauth', () => {\n return {\n OAuth2: ... // mock here\n }\n})\n"})})]})}function u(e={}){const{wrapper:s}={...(0,r.R)(),...e.components};return s?(0,o.jsx)(s,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>i,x:()=>c});var t=n(6540);const o={},r=t.createContext(o);function i(e){const s=t.useContext(r);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function c(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),t.createElement(r.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/bdfec613.fae4d7a9.js b/assets/js/bdfec613.dee9370f.js similarity index 99% rename from assets/js/bdfec613.fae4d7a9.js rename to assets/js/bdfec613.dee9370f.js index b36dc493a8..8e3eea3b7a 100644 --- a/assets/js/bdfec613.fae4d7a9.js +++ b/assets/js/bdfec613.dee9370f.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4733],{2219:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>d,default:()=>j,frontMatter:()=>r,metadata:()=>t,toc:()=>l});const t=JSON.parse('{"id":"getting-started/options","title":"Options","description":"Introduction","source":"@site/versioned_docs/version-27.0/getting-started/options.md","sourceDirName":"getting-started","slug":"/getting-started/options","permalink":"/ts-jest/docs/27.0/getting-started/options","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/options.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"options","title":"Options"},"sidebar":"version-27.0-docs","previous":{"title":"Presets","permalink":"/ts-jest/docs/27.0/getting-started/presets"},"next":{"title":"Paths mapping","permalink":"/ts-jest/docs/27.0/getting-started/paths-mapping"}}');var i=n(4848),o=n(8453);const r={id:"options",title:"Options"},d=void 0,c={},l=[{value:"Introduction",id:"introduction",level:3},{value:"Options",id:"options",level:3}];function h(e){const s={a:"a",admonition:"admonition",code:"code",em:"em",h3:"h3",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(s.h3,{id:"introduction",children:"Introduction"}),"\n",(0,i.jsxs)(s.p,{children:["All ",(0,i.jsx)(s.code,{children:"ts-jest"})," specific options are located under the ",(0,i.jsx)(s.code,{children:"globals"})," of Jest config object in the ",(0,i.jsx)(s.code,{children:"package.json"})," file of your project,\nor through a ",(0,i.jsx)(s.code,{children:"jest.config.js"}),", or ",(0,i.jsx)(s.code,{children:"jest.config.ts"})," file."]}),"\n",(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n // ts-jest configuration goes here\n }\n }\n }\n}\n'})}),"\n",(0,i.jsx)(s.p,{children:"Or through JavaScript:"}),"\n",(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n // ts-jest configuration goes here\n },\n },\n}\n"})}),"\n",(0,i.jsxs)(s.admonition,{type:"tip",children:[(0,i.jsxs)(s.p,{children:["To utilize IDE suggestions, you can use ",(0,i.jsx)(s.code,{children:"JSDoc"})," comments to provide suggested ",(0,i.jsx)(s.code,{children:"ts-jest"})," configs for your Jest config:"]}),(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",children:"// jest.config.js\n/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */\nmodule.exports = config = {\n // [...]\n globals: {\n 'ts-jest': {\n // ts-jest configuration goes here and your IDE will suggest which configs when typing\n },\n },\n}\n"})})]}),"\n",(0,i.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,i.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport type { InitialOptionsTsJest } from 'ts-jest/dist/types'\n\nconst config: InitialOptionsTsJest = {\n globals: {\n 'ts-jest': {\n // ts-jest configuration goes here\n },\n },\n}\nexport default config\n"})}),"\n",(0,i.jsx)(s.admonition,{type:"important",children:(0,i.jsxs)(s.p,{children:["When using TypeScript Jest config file, Jest will use ",(0,i.jsx)(s.code,{children:"ts-node"})," to compile the config file. ",(0,i.jsx)(s.code,{children:"ts-jest"})," doesn't take part in\nthat process."]})}),"\n",(0,i.jsx)(s.h3,{id:"options",children:"Options"}),"\n",(0,i.jsx)(s.p,{children:"All options have default values which should fit most of the projects. Click on the option's name to see details and example(s)."}),"\n",(0,i.jsxs)(s.table,{children:[(0,i.jsx)(s.thead,{children:(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.th,{children:"Option"}),(0,i.jsx)(s.th,{children:"Description"}),(0,i.jsx)(s.th,{children:"Type"}),(0,i.jsx)(s.th,{children:"Default"})]})}),(0,i.jsxs)(s.tbody,{children:[(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/compiler",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"compiler"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"string"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:'"typescript"'})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/tsconfig",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"tsconfig"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"string"}),"|",(0,i.jsx)(s.code,{children:"object"}),"|",(0,i.jsx)(s.code,{children:"boolean"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"auto"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/isolatedModules",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"isolatedModules"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"boolean"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"disabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/astTransformers",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"astTransformers"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"object"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"auto"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/diagnostics",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"diagnostics"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"boolean"}),"|",(0,i.jsx)(s.code,{children:"object"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"enabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/babelConfig",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"babelConfig"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"boolean"}),"|",(0,i.jsx)(s.code,{children:"string"}),"|",(0,i.jsx)(s.code,{children:"object"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"disabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"stringifyContentPathRegex"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"string"}),"|",(0,i.jsx)(s.code,{children:"RegExp"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"disabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/useESM",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"useESM"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/useESM",children:"Enable ESM support"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"boolean"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"auto"})})]})]})]})]})}function j(e={}){const{wrapper:s}={...(0,o.R)(),...e.components};return s?(0,i.jsx)(s,{...e,children:(0,i.jsx)(h,{...e})}):h(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>r,x:()=>d});var t=n(6540);const i={},o=t.createContext(i);function r(e){const s=t.useContext(o);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function d(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),t.createElement(o.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4733],{2219:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>d,default:()=>j,frontMatter:()=>r,metadata:()=>t,toc:()=>l});const t=JSON.parse('{"id":"getting-started/options","title":"Options","description":"Introduction","source":"@site/versioned_docs/version-27.0/getting-started/options.md","sourceDirName":"getting-started","slug":"/getting-started/options","permalink":"/ts-jest/docs/27.0/getting-started/options","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/options.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"options","title":"Options"},"sidebar":"version-27.0-docs","previous":{"title":"Presets","permalink":"/ts-jest/docs/27.0/getting-started/presets"},"next":{"title":"Paths mapping","permalink":"/ts-jest/docs/27.0/getting-started/paths-mapping"}}');var i=n(4848),o=n(8453);const r={id:"options",title:"Options"},d=void 0,c={},l=[{value:"Introduction",id:"introduction",level:3},{value:"Options",id:"options",level:3}];function h(e){const s={a:"a",admonition:"admonition",code:"code",em:"em",h3:"h3",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(s.h3,{id:"introduction",children:"Introduction"}),"\n",(0,i.jsxs)(s.p,{children:["All ",(0,i.jsx)(s.code,{children:"ts-jest"})," specific options are located under the ",(0,i.jsx)(s.code,{children:"globals"})," of Jest config object in the ",(0,i.jsx)(s.code,{children:"package.json"})," file of your project,\nor through a ",(0,i.jsx)(s.code,{children:"jest.config.js"}),", or ",(0,i.jsx)(s.code,{children:"jest.config.ts"})," file."]}),"\n",(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n // ts-jest configuration goes here\n }\n }\n }\n}\n'})}),"\n",(0,i.jsx)(s.p,{children:"Or through JavaScript:"}),"\n",(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n // ts-jest configuration goes here\n },\n },\n}\n"})}),"\n",(0,i.jsxs)(s.admonition,{type:"tip",children:[(0,i.jsxs)(s.p,{children:["To utilize IDE suggestions, you can use ",(0,i.jsx)(s.code,{children:"JSDoc"})," comments to provide suggested ",(0,i.jsx)(s.code,{children:"ts-jest"})," configs for your Jest config:"]}),(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",children:"// jest.config.js\n/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */\nmodule.exports = config = {\n // [...]\n globals: {\n 'ts-jest': {\n // ts-jest configuration goes here and your IDE will suggest which configs when typing\n },\n },\n}\n"})})]}),"\n",(0,i.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,i.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport type { InitialOptionsTsJest } from 'ts-jest/dist/types'\n\nconst config: InitialOptionsTsJest = {\n globals: {\n 'ts-jest': {\n // ts-jest configuration goes here\n },\n },\n}\nexport default config\n"})}),"\n",(0,i.jsx)(s.admonition,{type:"important",children:(0,i.jsxs)(s.p,{children:["When using TypeScript Jest config file, Jest will use ",(0,i.jsx)(s.code,{children:"ts-node"})," to compile the config file. ",(0,i.jsx)(s.code,{children:"ts-jest"})," doesn't take part in\nthat process."]})}),"\n",(0,i.jsx)(s.h3,{id:"options",children:"Options"}),"\n",(0,i.jsx)(s.p,{children:"All options have default values which should fit most of the projects. Click on the option's name to see details and example(s)."}),"\n",(0,i.jsxs)(s.table,{children:[(0,i.jsx)(s.thead,{children:(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.th,{children:"Option"}),(0,i.jsx)(s.th,{children:"Description"}),(0,i.jsx)(s.th,{children:"Type"}),(0,i.jsx)(s.th,{children:"Default"})]})}),(0,i.jsxs)(s.tbody,{children:[(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/compiler",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"compiler"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"string"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:'"typescript"'})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/tsconfig",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"tsconfig"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"string"}),"|",(0,i.jsx)(s.code,{children:"object"}),"|",(0,i.jsx)(s.code,{children:"boolean"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"auto"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/isolatedModules",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"isolatedModules"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"boolean"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"disabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/astTransformers",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"astTransformers"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"object"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"auto"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/diagnostics",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"diagnostics"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"boolean"}),"|",(0,i.jsx)(s.code,{children:"object"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"enabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/babelConfig",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"babelConfig"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"boolean"}),"|",(0,i.jsx)(s.code,{children:"string"}),"|",(0,i.jsx)(s.code,{children:"object"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"disabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"stringifyContentPathRegex"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"string"}),"|",(0,i.jsx)(s.code,{children:"RegExp"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"disabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/useESM",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"useESM"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/useESM",children:"Enable ESM support"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"boolean"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"auto"})})]})]})]})]})}function j(e={}){const{wrapper:s}={...(0,o.R)(),...e.components};return s?(0,i.jsx)(s,{...e,children:(0,i.jsx)(h,{...e})}):h(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>r,x:()=>d});var t=n(6540);const i={},o=t.createContext(i);function r(e){const s=t.useContext(o);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function d(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),t.createElement(o.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/bf341476.28157d87.js b/assets/js/bf341476.06c38444.js similarity index 97% rename from assets/js/bf341476.28157d87.js rename to assets/js/bf341476.06c38444.js index b3b307ca37..0e7c00f45e 100644 --- a/assets/js/bf341476.28157d87.js +++ b/assets/js/bf341476.06c38444.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2402],{4306:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>n,toc:()=>a});const n=JSON.parse('{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","source":"@site/versioned_docs/version-27.0/introduction.md","sourceDirName":".","slug":"/","permalink":"/ts-jest/docs/27.0/","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/introduction.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","slug":"/"},"sidebar":"version-27.0-docs","next":{"title":"Processing flow","permalink":"/ts-jest/docs/27.0/processing"}}');var o=s(4848),r=s(8453);const i={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},c=void 0,d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,r.R)(),...t.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(e.p,{children:[(0,o.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,o.jsx)(e.a,{href:"https://jestjs.io/docs/next/code-transformation#writing-custom-transformers",children:"transformer"})," with source map support that lets you use Jest to test projects written in TypeScript."]}),"\n",(0,o.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,o.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,o.jsx)(e.code,{children:"preset-typescript"})," ",(0,o.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,o.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,o.jsx)(e.admonition,{type:"important",children:(0,o.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,o.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,o.jsx)(e.code,{children:'npm i -D ts-jest@"<23.10.0"'})," to go back to the previous version"]})})]})}function u(t={}){const{wrapper:e}={...(0,r.R)(),...t.components};return e?(0,o.jsx)(e,{...t,children:(0,o.jsx)(p,{...t})}):p(t)}},8453:(t,e,s)=>{s.d(e,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(t){const e=n.useContext(r);return n.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function c(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:i(t.components),n.createElement(r.Provider,{value:e},t.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2402],{4306:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>n,toc:()=>a});const n=JSON.parse('{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","source":"@site/versioned_docs/version-27.0/introduction.md","sourceDirName":".","slug":"/","permalink":"/ts-jest/docs/27.0/","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/introduction.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"introduction","title":"Introduction","description":"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.","slug":"/"},"sidebar":"version-27.0-docs","next":{"title":"Processing flow","permalink":"/ts-jest/docs/27.0/processing"}}');var o=s(4848),r=s(8453);const i={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},c=void 0,d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,r.R)(),...t.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(e.p,{children:[(0,o.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,o.jsx)(e.a,{href:"https://jestjs.io/docs/next/code-transformation#writing-custom-transformers",children:"transformer"})," with source map support that lets you use Jest to test projects written in TypeScript."]}),"\n",(0,o.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,o.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,o.jsx)(e.code,{children:"preset-typescript"})," ",(0,o.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,o.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,o.jsx)(e.admonition,{type:"important",children:(0,o.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,o.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,o.jsx)(e.code,{children:'npm i -D ts-jest@"<23.10.0"'})," to go back to the previous version"]})})]})}function u(t={}){const{wrapper:e}={...(0,r.R)(),...t.components};return e?(0,o.jsx)(e,{...t,children:(0,o.jsx)(p,{...t})}):p(t)}},8453:(t,e,s)=>{s.d(e,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(t){const e=n.useContext(r);return n.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function c(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:i(t.components),n.createElement(r.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/c010a830.565e8076.js b/assets/js/c010a830.7a17d40e.js similarity index 97% rename from assets/js/c010a830.565e8076.js rename to assets/js/c010a830.7a17d40e.js index b15a05795b..bbffb20a8c 100644 --- a/assets/js/c010a830.565e8076.js +++ b/assets/js/c010a830.7a17d40e.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7015],{8945:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>p,frontMatter:()=>i,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/useESM","title":"useESM option","description":"The useESM option allows ts-jest to transform codes to ESM syntax if possible.","source":"@site/versioned_docs/version-27.1/getting-started/options/useESM.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/useESM","permalink":"/ts-jest/docs/27.1/getting-started/options/useESM","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/options/useESM.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"useESM option"}}');var o=s(4848),r=s(8453);const i={title:"useESM option"},a=void 0,c={},d=[{value:"Examples",id:"examples",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["The ",(0,o.jsx)(t.code,{children:"useESM"})," option allows ",(0,o.jsx)(t.code,{children:"ts-jest"})," to transform codes to ESM syntax ",(0,o.jsx)(t.strong,{children:"if possible"}),"."]}),"\n",(0,o.jsxs)(t.p,{children:["The default value is ",(0,o.jsx)(t.strong,{children:"false"}),", ",(0,o.jsx)(t.code,{children:"ts-jest"})," will transform codes to ",(0,o.jsx)(t.code,{children:"CommonJS"})," syntax."]}),"\n",(0,o.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n useESM: true,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "useESM": true\n }\n }\n }\n}\n'})})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>i,x:()=>a});var n=s(6540);const o={},r=n.createContext(o);function i(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7015],{8945:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>p,frontMatter:()=>i,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/useESM","title":"useESM option","description":"The useESM option allows ts-jest to transform codes to ESM syntax if possible.","source":"@site/versioned_docs/version-27.1/getting-started/options/useESM.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/useESM","permalink":"/ts-jest/docs/27.1/getting-started/options/useESM","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/options/useESM.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"useESM option"}}');var o=s(4848),r=s(8453);const i={title:"useESM option"},a=void 0,c={},d=[{value:"Examples",id:"examples",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["The ",(0,o.jsx)(t.code,{children:"useESM"})," option allows ",(0,o.jsx)(t.code,{children:"ts-jest"})," to transform codes to ESM syntax ",(0,o.jsx)(t.strong,{children:"if possible"}),"."]}),"\n",(0,o.jsxs)(t.p,{children:["The default value is ",(0,o.jsx)(t.strong,{children:"false"}),", ",(0,o.jsx)(t.code,{children:"ts-jest"})," will transform codes to ",(0,o.jsx)(t.code,{children:"CommonJS"})," syntax."]}),"\n",(0,o.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n useESM: true,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "useESM": true\n }\n }\n }\n}\n'})})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>i,x:()=>a});var n=s(6540);const o={},r=n.createContext(o);function i(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/c1932cab.7674b66d.js b/assets/js/c1932cab.28f8c650.js similarity index 99% rename from assets/js/c1932cab.7674b66d.js rename to assets/js/c1932cab.28f8c650.js index 4f58366214..11c9aa4fc9 100644 --- a/assets/js/c1932cab.7674b66d.js +++ b/assets/js/c1932cab.28f8c650.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8719],{1386:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>r,contentTitle:()=>i,default:()=>b,frontMatter:()=>a,metadata:()=>t,toc:()=>c});const t=JSON.parse('{"id":"getting-started/options/babelConfig","title":"Babel Config option","description":"ts-jest by default does NOT use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ts-jest can call the BabelJest processor once TypeScript has transformed the source into JavaScript.","source":"@site/versioned_docs/version-28.0/getting-started/options/babelConfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/babelConfig","permalink":"/ts-jest/docs/28.0/getting-started/options/babelConfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/options/babelConfig.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Babel Config option"}}');var o=s(4848),l=s(8453);const a={title:"Babel Config option"},i=void 0,r={},c=[{value:"Examples",id:"examples",level:3},{value:"Use default babelrc file",id:"use-default-babelrc-file",level:4},{value:"Path to a babelrc file",id:"path-to-a-babelrc-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4}];function d(e){const n={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,l.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:[(0,o.jsx)(n.code,{children:"ts-jest"})," by default does ",(0,o.jsx)(n.strong,{children:"NOT"})," use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ",(0,o.jsx)(n.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,o.jsxs)(n.p,{children:["The option is ",(0,o.jsx)(n.code,{children:"babelConfig"})," and it works pretty much as the ",(0,o.jsx)(n.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"true"}),": enables Babel processing. ",(0,o.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(n.code,{children:".babelrc"}),", ",(0,o.jsx)(n.code,{children:".babelrc.js"}),", ",(0,o.jsx)(n.code,{children:"babel.config.js"})," file or a ",(0,o.jsx)(n.code,{children:"babel"})," section in the ",(0,o.jsx)(n.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,o.jsx)(n.code,{children:"babel-jest"})," processor."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"{ ... }"}),": inline ",(0,o.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,o.jsx)(n.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,o.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsxs)(n.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,o.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: true,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "babelConfig": true\n }\n }\n }\n}\n'})}),"\n",(0,o.jsxs)(n.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,o.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,o.jsxs)(n.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,o.jsx)(n.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: 'babelrc.test.js',\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.p,{children:"or"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: require('./babelrc.test.js'),\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "babelConfig": "babelrc.test.js"\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,o.jsxs)(n.p,{children:["Refer to the ",(0,o.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: {\n comments: false,\n plugins: ['@babel/plugin-transform-for-of'],\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "babelConfig": {\n "comments": false,\n "plugins": ["@babel/plugin-transform-for-of"]\n }\n }\n }\n }\n}\n'})})]})}function b(e={}){const{wrapper:n}={...(0,l.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,n,s)=>{s.d(n,{R:()=>a,x:()=>i});var t=s(6540);const o={},l=t.createContext(o);function a(e){const n=t.useContext(l);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),t.createElement(l.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8719],{1386:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>r,contentTitle:()=>i,default:()=>b,frontMatter:()=>a,metadata:()=>t,toc:()=>c});const t=JSON.parse('{"id":"getting-started/options/babelConfig","title":"Babel Config option","description":"ts-jest by default does NOT use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ts-jest can call the BabelJest processor once TypeScript has transformed the source into JavaScript.","source":"@site/versioned_docs/version-28.0/getting-started/options/babelConfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/babelConfig","permalink":"/ts-jest/docs/28.0/getting-started/options/babelConfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/options/babelConfig.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Babel Config option"}}');var o=s(4848),l=s(8453);const a={title:"Babel Config option"},i=void 0,r={},c=[{value:"Examples",id:"examples",level:3},{value:"Use default babelrc file",id:"use-default-babelrc-file",level:4},{value:"Path to a babelrc file",id:"path-to-a-babelrc-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4}];function d(e){const n={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,l.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:[(0,o.jsx)(n.code,{children:"ts-jest"})," by default does ",(0,o.jsx)(n.strong,{children:"NOT"})," use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ",(0,o.jsx)(n.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,o.jsxs)(n.p,{children:["The option is ",(0,o.jsx)(n.code,{children:"babelConfig"})," and it works pretty much as the ",(0,o.jsx)(n.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"true"}),": enables Babel processing. ",(0,o.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(n.code,{children:".babelrc"}),", ",(0,o.jsx)(n.code,{children:".babelrc.js"}),", ",(0,o.jsx)(n.code,{children:"babel.config.js"})," file or a ",(0,o.jsx)(n.code,{children:"babel"})," section in the ",(0,o.jsx)(n.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,o.jsx)(n.code,{children:"babel-jest"})," processor."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"{ ... }"}),": inline ",(0,o.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,o.jsx)(n.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,o.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsxs)(n.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,o.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: true,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "babelConfig": true\n }\n }\n }\n}\n'})}),"\n",(0,o.jsxs)(n.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,o.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,o.jsxs)(n.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,o.jsx)(n.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: 'babelrc.test.js',\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.p,{children:"or"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: require('./babelrc.test.js'),\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "babelConfig": "babelrc.test.js"\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,o.jsxs)(n.p,{children:["Refer to the ",(0,o.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: {\n comments: false,\n plugins: ['@babel/plugin-transform-for-of'],\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "babelConfig": {\n "comments": false,\n "plugins": ["@babel/plugin-transform-for-of"]\n }\n }\n }\n }\n}\n'})})]})}function b(e={}){const{wrapper:n}={...(0,l.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,n,s)=>{s.d(n,{R:()=>a,x:()=>i});var t=s(6540);const o={},l=t.createContext(o);function a(e){const n=t.useContext(l);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),t.createElement(l.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/c1a7450f.47d4c4ee.js b/assets/js/c1a7450f.bc600371.js similarity index 99% rename from assets/js/c1a7450f.47d4c4ee.js rename to assets/js/c1a7450f.bc600371.js index 231e226e2e..6b85357703 100644 --- a/assets/js/c1a7450f.47d4c4ee.js +++ b/assets/js/c1a7450f.bc600371.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6120],{9156:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>m,frontMatter:()=>u,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/useESM","title":"useESM option","description":"The useESM option allows ts-jest to transform codes to ESM syntax if possible.","source":"@site/docs/getting-started/options/useESM.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/useESM","permalink":"/ts-jest/docs/next/getting-started/options/useESM","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/useESM.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"useESM option"}}');var r=s(4848),a=s(8453),o=s(9489),l=s(7227);const u={title:"useESM option"},i=void 0,c={},d=[{value:"Examples",id:"examples",level:3}];function p(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["The ",(0,r.jsx)(t.code,{children:"useESM"})," option allows ",(0,r.jsx)(t.code,{children:"ts-jest"})," to transform codes to ESM syntax ",(0,r.jsx)(t.strong,{children:"if possible"}),"."]}),"\n",(0,r.jsxs)(t.p,{children:["The default value is ",(0,r.jsx)(t.strong,{children:"false"}),", ",(0,r.jsx)(t.code,{children:"ts-jest"})," will transform codes to ",(0,r.jsx)(t.code,{children:"CommonJS"})," syntax."]}),"\n",(0,r.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n useESM: true,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n useESM: true,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "useESM": true\n }\n ]\n }\n }\n}\n'})})})]})]})}function m(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>o});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var a=s(4848);function o(e){let{children:t,hidden:s,className:o}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,o),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>y});var n=s(6540),r=s(4164),a=s(4245),o=s(6347),l=s(6494),u=s(2814),i=s(5167),c=s(9900);function d(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:r}}=e;return{value:t,label:s,attributes:n,default:r}}))}(s);return function(e){const t=(0,i.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function m(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:s}=e;const r=(0,o.W6)(),a=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,u.aZ)(a),(0,n.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function f(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,a=p(e),[o,u]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:a}))),[i,d]=h({queryString:s,groupId:r}),[f,j]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,c.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&a.set(e)}),[s,a])]}({groupId:r}),x=(()=>{const e=i??f;return m({value:e,tabValues:a})?e:null})();(0,l.A)((()=>{x&&u(x)}),[x]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);u(e),d(e),j(e)}),[d,j,a]),tabValues:a}}var j=s(1062);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=s(4848);function g(e){let{className:t,block:s,selectedValue:n,selectValue:o,tabValues:l}=e;const u=[],{blockElementScrollPositionUntilNextRender:i}=(0,a.a_)(),c=e=>{const t=e.currentTarget,s=u.indexOf(t),r=l[s].value;r!==n&&(i(t),o(r))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const s=u.indexOf(e.currentTarget)+1;t=u[s]??u[0];break}case"ArrowLeft":{const s=u.indexOf(e.currentTarget)-1;t=u[s]??u[u.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":s},t),children:l.map((e=>{let{value:t,label:s,attributes:a}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>u.push(e),onKeyDown:d,onClick:c,...a,className:(0,r.A)("tabs__item",x.tabItem,a?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:a}=e;const o=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function w(e){const t=f(e);return(0,b.jsxs)("div",{className:(0,r.A)("tabs-container",x.tabList),children:[(0,b.jsx)(g,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function y(e){const t=(0,j.A)();return(0,b.jsx)(w,{...e,children:d(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>o,x:()=>l});var n=s(6540);const r={},a=n.createContext(r);function o(e){const t=n.useContext(a);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),n.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6120],{9156:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>m,frontMatter:()=>u,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/useESM","title":"useESM option","description":"The useESM option allows ts-jest to transform codes to ESM syntax if possible.","source":"@site/docs/getting-started/options/useESM.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/useESM","permalink":"/ts-jest/docs/next/getting-started/options/useESM","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/useESM.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"useESM option"}}');var r=s(4848),a=s(8453),o=s(9489),l=s(7227);const u={title:"useESM option"},i=void 0,c={},d=[{value:"Examples",id:"examples",level:3}];function p(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["The ",(0,r.jsx)(t.code,{children:"useESM"})," option allows ",(0,r.jsx)(t.code,{children:"ts-jest"})," to transform codes to ESM syntax ",(0,r.jsx)(t.strong,{children:"if possible"}),"."]}),"\n",(0,r.jsxs)(t.p,{children:["The default value is ",(0,r.jsx)(t.strong,{children:"false"}),", ",(0,r.jsx)(t.code,{children:"ts-jest"})," will transform codes to ",(0,r.jsx)(t.code,{children:"CommonJS"})," syntax."]}),"\n",(0,r.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n useESM: true,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n useESM: true,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "useESM": true\n }\n ]\n }\n }\n}\n'})})})]})]})}function m(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>o});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var a=s(4848);function o(e){let{children:t,hidden:s,className:o}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,o),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>y});var n=s(6540),r=s(4164),a=s(4245),o=s(6347),l=s(6494),u=s(2814),i=s(5167),c=s(9900);function d(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:r}}=e;return{value:t,label:s,attributes:n,default:r}}))}(s);return function(e){const t=(0,i.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function m(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:s}=e;const r=(0,o.W6)(),a=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,u.aZ)(a),(0,n.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function f(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,a=p(e),[o,u]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:a}))),[i,d]=h({queryString:s,groupId:r}),[f,j]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,c.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&a.set(e)}),[s,a])]}({groupId:r}),x=(()=>{const e=i??f;return m({value:e,tabValues:a})?e:null})();(0,l.A)((()=>{x&&u(x)}),[x]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);u(e),d(e),j(e)}),[d,j,a]),tabValues:a}}var j=s(1062);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=s(4848);function g(e){let{className:t,block:s,selectedValue:n,selectValue:o,tabValues:l}=e;const u=[],{blockElementScrollPositionUntilNextRender:i}=(0,a.a_)(),c=e=>{const t=e.currentTarget,s=u.indexOf(t),r=l[s].value;r!==n&&(i(t),o(r))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const s=u.indexOf(e.currentTarget)+1;t=u[s]??u[0];break}case"ArrowLeft":{const s=u.indexOf(e.currentTarget)-1;t=u[s]??u[u.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":s},t),children:l.map((e=>{let{value:t,label:s,attributes:a}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>u.push(e),onKeyDown:d,onClick:c,...a,className:(0,r.A)("tabs__item",x.tabItem,a?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:a}=e;const o=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function w(e){const t=f(e);return(0,b.jsxs)("div",{className:(0,r.A)("tabs-container",x.tabList),children:[(0,b.jsx)(g,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function y(e){const t=(0,j.A)();return(0,b.jsx)(w,{...e,children:d(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>o,x:()=>l});var n=s(6540);const r={},a=n.createContext(r);function o(e){const t=n.useContext(a);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),n.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/c6326909.213084ed.js b/assets/js/c6326909.a8d572e1.js similarity index 97% rename from assets/js/c6326909.213084ed.js rename to assets/js/c6326909.a8d572e1.js index 90a48b5bda..667e5e62fe 100644 --- a/assets/js/c6326909.213084ed.js +++ b/assets/js/c6326909.a8d572e1.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6121],{4616:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/version-checking","title":"Version checking","description":"By default, ts-jest supports a range of versions for jest/typescript. One uses incompatible versions will receive a warning","source":"@site/versioned_docs/version-27.0/getting-started/version-checking.md","sourceDirName":"getting-started","slug":"/getting-started/version-checking","permalink":"/ts-jest/docs/27.0/getting-started/version-checking","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/version-checking.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"version-checking","title":"Version checking"},"sidebar":"version-27.0-docs","previous":{"title":"Paths mapping","permalink":"/ts-jest/docs/27.0/getting-started/paths-mapping"},"next":{"title":"ESM Support","permalink":"/ts-jest/docs/27.0/guides/esm-support"}}');var i=n(4848),r=n(8453);const o={id:"version-checking",title:"Version checking"},c=void 0,a={},d=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["By default, ",(0,i.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,i.jsx)(t.code,{children:"jest"}),"/",(0,i.jsx)(t.code,{children:"typescript"}),". One uses incompatible versions will receive a warning\nmessage while running tests. This warning message can be opt-out by setting environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"export TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Windows"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,i.jsxs)(t.p,{children:["As long as the environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"})," stays, the warning message will no longer show.\nThis can lead to unexpected errors due to the usage of incompatible versions' dependencies. Use this environment variable with precautions."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>c});var s=n(6540);const i={},r=s.createContext(i);function o(e){const t=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6121],{4616:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/version-checking","title":"Version checking","description":"By default, ts-jest supports a range of versions for jest/typescript. One uses incompatible versions will receive a warning","source":"@site/versioned_docs/version-27.0/getting-started/version-checking.md","sourceDirName":"getting-started","slug":"/getting-started/version-checking","permalink":"/ts-jest/docs/27.0/getting-started/version-checking","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/version-checking.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"version-checking","title":"Version checking"},"sidebar":"version-27.0-docs","previous":{"title":"Paths mapping","permalink":"/ts-jest/docs/27.0/getting-started/paths-mapping"},"next":{"title":"ESM Support","permalink":"/ts-jest/docs/27.0/guides/esm-support"}}');var i=n(4848),r=n(8453);const o={id:"version-checking",title:"Version checking"},c=void 0,a={},d=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["By default, ",(0,i.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,i.jsx)(t.code,{children:"jest"}),"/",(0,i.jsx)(t.code,{children:"typescript"}),". One uses incompatible versions will receive a warning\nmessage while running tests. This warning message can be opt-out by setting environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"export TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Windows"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,i.jsxs)(t.p,{children:["As long as the environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"})," stays, the warning message will no longer show.\nThis can lead to unexpected errors due to the usage of incompatible versions' dependencies. Use this environment variable with precautions."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>c});var s=n(6540);const i={},r=s.createContext(i);function o(e){const t=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/c8c88a41.06eff6cf.js b/assets/js/c8c88a41.444eb5d2.js similarity index 98% rename from assets/js/c8c88a41.06eff6cf.js rename to assets/js/c8c88a41.444eb5d2.js index 7390a86c20..efe2c4508f 100644 --- a/assets/js/c8c88a41.06eff6cf.js +++ b/assets/js/c8c88a41.444eb5d2.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1907],{5937:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>p,default:()=>d,frontMatter:()=>r,metadata:()=>s,toc:()=>c});const s=JSON.parse('{"id":"getting-started/paths-mapping","title":"Paths mapping","description":"If you use \\"baseUrl\\" and \\"paths\\" options in your tsconfig file, you should make sure the \\"moduleNameMapper\\" option in your Jest config is setup accordingly.","source":"@site/versioned_docs/version-28.0/getting-started/paths-mapping.md","sourceDirName":"getting-started","slug":"/getting-started/paths-mapping","permalink":"/ts-jest/docs/28.0/getting-started/paths-mapping","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/paths-mapping.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"paths-mapping","title":"Paths mapping"},"sidebar":"version-28.0-docs","previous":{"title":"Options","permalink":"/ts-jest/docs/28.0/getting-started/options"},"next":{"title":"Version checking","permalink":"/ts-jest/docs/28.0/getting-started/version-checking"}}');var o=n(4848),i=n(8453);const r={id:"paths-mapping",title:"Paths mapping"},p=void 0,a={},c=[{value:"Example",id:"example",level:3},{value:"TypeScript config",id:"typescript-config",level:4},{value:"Jest config (without helper)",id:"jest-config-without-helper",level:4},{value:"Jest config (with helper)",id:"jest-config-with-helper",level:4}];function l(e){const t={a:"a",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["If you use ",(0,o.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,o.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,o.jsx)(t.a,{href:"https://jestjs.io/docs/configuration#modulenamemapper-objectstring-string--arraystring",children:'"moduleNameMapper"'})," option in your Jest config is setup accordingly."]}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,o.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,o.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,o.jsxs)(t.p,{children:["With the below config in your ",(0,o.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n "compilerOptions": {\n "baseUrl": ".",\n "paths": {\n "@App/*": ["src/*"],\n "lib/*": ["common/*"]\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n moduleNameMapper: {\n '^@App/(.*)$': '/src/$1',\n '^lib/(.*)$': '/common/$1',\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleNameMapper": {\n "^@App/(.*)$": "/src/$1",\n "^lib/(.*)$": "/common/$1"\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nconst { pathsToModuleNameMapper } = require('ts-jest')\n// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file\n// which contains the path mapping (ie the `compilerOptions.paths` option):\nconst { compilerOptions } = require('./tsconfig')\n\nmodule.exports = {\n // [...]\n roots: [''],\n modulePaths: [compilerOptions.baseUrl], // <-- This will be set to 'baseUrl' value\n moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths /*, { prefix: '/' } */),\n}\n"})})]})}function d(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>p});var s=n(6540);const o={},i=s.createContext(o);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function p(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1907],{5937:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>p,default:()=>d,frontMatter:()=>r,metadata:()=>s,toc:()=>c});const s=JSON.parse('{"id":"getting-started/paths-mapping","title":"Paths mapping","description":"If you use \\"baseUrl\\" and \\"paths\\" options in your tsconfig file, you should make sure the \\"moduleNameMapper\\" option in your Jest config is setup accordingly.","source":"@site/versioned_docs/version-28.0/getting-started/paths-mapping.md","sourceDirName":"getting-started","slug":"/getting-started/paths-mapping","permalink":"/ts-jest/docs/28.0/getting-started/paths-mapping","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/paths-mapping.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"paths-mapping","title":"Paths mapping"},"sidebar":"version-28.0-docs","previous":{"title":"Options","permalink":"/ts-jest/docs/28.0/getting-started/options"},"next":{"title":"Version checking","permalink":"/ts-jest/docs/28.0/getting-started/version-checking"}}');var o=n(4848),i=n(8453);const r={id:"paths-mapping",title:"Paths mapping"},p=void 0,a={},c=[{value:"Example",id:"example",level:3},{value:"TypeScript config",id:"typescript-config",level:4},{value:"Jest config (without helper)",id:"jest-config-without-helper",level:4},{value:"Jest config (with helper)",id:"jest-config-with-helper",level:4}];function l(e){const t={a:"a",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["If you use ",(0,o.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,o.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,o.jsx)(t.a,{href:"https://jestjs.io/docs/configuration#modulenamemapper-objectstring-string--arraystring",children:'"moduleNameMapper"'})," option in your Jest config is setup accordingly."]}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,o.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,o.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,o.jsxs)(t.p,{children:["With the below config in your ",(0,o.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n "compilerOptions": {\n "baseUrl": ".",\n "paths": {\n "@App/*": ["src/*"],\n "lib/*": ["common/*"]\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n moduleNameMapper: {\n '^@App/(.*)$': '/src/$1',\n '^lib/(.*)$': '/common/$1',\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleNameMapper": {\n "^@App/(.*)$": "/src/$1",\n "^lib/(.*)$": "/common/$1"\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nconst { pathsToModuleNameMapper } = require('ts-jest')\n// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file\n// which contains the path mapping (ie the `compilerOptions.paths` option):\nconst { compilerOptions } = require('./tsconfig')\n\nmodule.exports = {\n // [...]\n roots: [''],\n modulePaths: [compilerOptions.baseUrl], // <-- This will be set to 'baseUrl' value\n moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths /*, { prefix: '/' } */),\n}\n"})})]})}function d(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>p});var s=n(6540);const o={},i=s.createContext(o);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function p(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/c8eced56.2b96d068.js b/assets/js/c8eced56.d8927fa4.js similarity index 97% rename from assets/js/c8eced56.2b96d068.js rename to assets/js/c8eced56.d8927fa4.js index fbfddab74d..dcf1778319 100644 --- a/assets/js/c8eced56.2b96d068.js +++ b/assets/js/c8eced56.d8927fa4.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1344],{6329:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>p,frontMatter:()=>i,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/useESM","title":"useESM option","description":"The useESM option allows ts-jest to transform codes to ESM syntax if possible.","source":"@site/versioned_docs/version-28.0/getting-started/options/useESM.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/useESM","permalink":"/ts-jest/docs/28.0/getting-started/options/useESM","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/options/useESM.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"useESM option"}}');var o=s(4848),r=s(8453);const i={title:"useESM option"},a=void 0,c={},d=[{value:"Examples",id:"examples",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["The ",(0,o.jsx)(t.code,{children:"useESM"})," option allows ",(0,o.jsx)(t.code,{children:"ts-jest"})," to transform codes to ESM syntax ",(0,o.jsx)(t.strong,{children:"if possible"}),"."]}),"\n",(0,o.jsxs)(t.p,{children:["The default value is ",(0,o.jsx)(t.strong,{children:"false"}),", ",(0,o.jsx)(t.code,{children:"ts-jest"})," will transform codes to ",(0,o.jsx)(t.code,{children:"CommonJS"})," syntax."]}),"\n",(0,o.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n useESM: true,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "useESM": true\n }\n }\n }\n}\n'})})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>i,x:()=>a});var n=s(6540);const o={},r=n.createContext(o);function i(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1344],{6329:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>p,frontMatter:()=>i,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/useESM","title":"useESM option","description":"The useESM option allows ts-jest to transform codes to ESM syntax if possible.","source":"@site/versioned_docs/version-28.0/getting-started/options/useESM.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/useESM","permalink":"/ts-jest/docs/28.0/getting-started/options/useESM","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/options/useESM.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"useESM option"}}');var o=s(4848),r=s(8453);const i={title:"useESM option"},a=void 0,c={},d=[{value:"Examples",id:"examples",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["The ",(0,o.jsx)(t.code,{children:"useESM"})," option allows ",(0,o.jsx)(t.code,{children:"ts-jest"})," to transform codes to ESM syntax ",(0,o.jsx)(t.strong,{children:"if possible"}),"."]}),"\n",(0,o.jsxs)(t.p,{children:["The default value is ",(0,o.jsx)(t.strong,{children:"false"}),", ",(0,o.jsx)(t.code,{children:"ts-jest"})," will transform codes to ",(0,o.jsx)(t.code,{children:"CommonJS"})," syntax."]}),"\n",(0,o.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n useESM: true,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "useESM": true\n }\n }\n }\n}\n'})})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>i,x:()=>a});var n=s(6540);const o={},r=n.createContext(o);function i(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/ceaad8ca.26b23793.js b/assets/js/ceaad8ca.7a2881e9.js similarity index 99% rename from assets/js/ceaad8ca.26b23793.js rename to assets/js/ceaad8ca.7a2881e9.js index 18d78f15bb..48f8872df0 100644 --- a/assets/js/ceaad8ca.26b23793.js +++ b/assets/js/ceaad8ca.7a2881e9.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4681],{7705:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>d,contentTitle:()=>c,default:()=>h,frontMatter:()=>l,metadata:()=>n,toc:()=>j});const n=JSON.parse('{"id":"getting-started/options/diagnostics","title":"Diagnostics option","description":"The diagnostics option configures error reporting.","source":"@site/docs/getting-started/options/diagnostics.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/diagnostics","permalink":"/ts-jest/docs/next/getting-started/options/diagnostics","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/diagnostics.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Diagnostics option"}}');var i=t(4848),r=t(8453),o=t(9489),a=t(7227);const l={title:"Diagnostics option"},c=void 0,d={},j=[{value:"Disabling/enabling",id:"disablingenabling",level:3},{value:"Advanced configuration",id:"advanced-configuration",level:3},{value:"Examples",id:"examples",level:3},{value:"Disabling diagnostics",id:"disabling-diagnostics",level:4},{value:"Advanced options",id:"advanced-options",level:4},{value:"Enabling diagnostics for test files only",id:"enabling-diagnostics-for-test-files-only",level:5},{value:"Do not fail on first error",id:"do-not-fail-on-first-error",level:5},{value:"Ignoring some error codes",id:"ignoring-some-error-codes",level:5}];function u(e){const s={a:"a",code:"code",em:"em",h3:"h3",h4:"h4",h5:"h5",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(s.p,{children:["The ",(0,i.jsx)(s.code,{children:"diagnostics"})," option configures error reporting.\nIt can both be enabled/disabled entirely or limited to a specific type of errors and/or files."]}),"\n",(0,i.jsxs)(s.p,{children:["If a diagnostic is not filtered out, ",(0,i.jsx)(s.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,i.jsx)(s.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,i.jsxs)(s.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,i.jsx)(s.code,{children:"diagnostics"})," option to ",(0,i.jsx)(s.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,i.jsx)(s.code,{children:"diagnostics"})," to ",(0,i.jsx)(s.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,i.jsx)(s.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,i.jsxs)(s.p,{children:["The ",(0,i.jsx)(s.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,i.jsxs)(s.ul,{children:["\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"warnOnly"})}),": If specified and ",(0,i.jsx)(s.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,i.jsx)(s.em,{children:"disabled"}),")."]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,i.jsx)(s.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". By default here are the ones ignored:","\n",(0,i.jsxs)(s.ul,{children:["\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.code,{children:"6059"}),": ",(0,i.jsx)(s.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.code,{children:"18002"}),": ",(0,i.jsx)(s.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.code,{children:"18003"}),": ",(0,i.jsx)(s.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,i.jsx)(s.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,i.jsx)(s.code,{children:"tsconfig"})," option ",(0,i.jsx)(s.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,i.jsx)(s.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,i.jsx)(s.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,i.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,i.jsx)(s.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,i.jsxs)(o.A,{groupId:"code-examples",children:[(0,i.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: false,\n },\n ],\n },\n}\n"})})}),(0,i.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: false,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,i.jsx)(a.A,{value:"JSON",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "diagnostics": false\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,i.jsx)(s.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,i.jsx)(s.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,i.jsxs)(s.p,{children:["Assuming all your test files ends with ",(0,i.jsx)(s.code,{children:".spec.ts"})," or ",(0,i.jsx)(s.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,i.jsxs)(o.A,{groupId:"code-examples",children:[(0,i.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n exclude: ['!**/*.(spec|test).ts'],\n },\n },\n ],\n },\n}\n"})})}),(0,i.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n exclude: ['!**/*.(spec|test).ts'],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,i.jsx)(a.A,{value:"JSON",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "diagnostics": {\n "exclude": ["!**/*.(spec|test).ts"]\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,i.jsx)(s.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,i.jsxs)(s.p,{children:["While some diagnostics are stop-blockers for the compilation, most of them are not. If you want the compilation (and so your tests) to continue when encountering those, set the ",(0,i.jsx)(s.code,{children:"warnOnly"})," to ",(0,i.jsx)(s.code,{children:"true"}),":"]}),"\n",(0,i.jsxs)(o.A,{groupId:"code-examples",children:[(0,i.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n warnOnly: true,\n },\n },\n ],\n },\n}\n"})})}),(0,i.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n warnOnly: true,\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,i.jsx)(a.A,{value:"JSON",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "diagnostics": {\n "warnOnly": true\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,i.jsx)(s.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,i.jsxs)(s.p,{children:["All TypeScript error codes can be found ",(0,i.jsx)(s.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,i.jsx)(s.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,i.jsxs)(s.ol,{children:["\n",(0,i.jsxs)(s.li,{children:["A single ",(0,i.jsx)(s.code,{children:"number"})," (example: ",(0,i.jsx)(s.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,i.jsxs)(s.li,{children:["A ",(0,i.jsx)(s.code,{children:"string"})," with a code (example ",(0,i.jsx)(s.code,{children:'"1009"'}),", ",(0,i.jsx)(s.code,{children:'"TS1009"'})," or ",(0,i.jsx)(s.code,{children:'"TS1009"'}),")"]}),"\n",(0,i.jsxs)(s.li,{children:["A ",(0,i.jsx)(s.code,{children:"string"})," with a list of the above (example: ",(0,i.jsx)(s.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,i.jsxs)(s.li,{children:["An ",(0,i.jsx)(s.code,{children:"array"})," of one or more from ",(0,i.jsx)(s.code,{children:"1"})," or ",(0,i.jsx)(s.code,{children:"3"})," (example: ",(0,i.jsx)(s.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,i.jsxs)(o.A,{groupId:"code-examples",children:[(0,i.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n ignoreCodes: [2571, 6031, 18003],\n },\n },\n ],\n },\n}\n"})})}),(0,i.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n ignoreCodes: [2571, 6031, 18003],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,i.jsx)(a.A,{value:"JSON",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "diagnostics": {\n "ignoreCodes": [2571, 6031, 18003]\n }\n }\n ]\n }\n }\n}\n'})})})]})]})}function h(e={}){const{wrapper:s}={...(0,r.R)(),...e.components};return s?(0,i.jsx)(s,{...e,children:(0,i.jsx)(u,{...e})}):u(e)}},7227:(e,s,t)=>{t.d(s,{A:()=>o});t(6540);var n=t(4164);const i={tabItem:"tabItem_Ymn6"};var r=t(4848);function o(e){let{children:s,hidden:t,className:o}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,n.A)(i.tabItem,o),hidden:t,children:s})}},9489:(e,s,t)=>{t.d(s,{A:()=>w});var n=t(6540),i=t(4164),r=t(4245),o=t(6347),a=t(6494),l=t(2814),c=t(5167),d=t(9900);function j(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:s}=e;return!!s&&"object"==typeof s&&"value"in s}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function u(e){const{values:s,children:t}=e;return(0,n.useMemo)((()=>{const e=s??function(e){return j(e).map((e=>{let{props:{value:s,label:t,attributes:n,default:i}}=e;return{value:s,label:t,attributes:n,default:i}}))}(t);return function(e){const s=(0,c.XI)(e,((e,s)=>e.value===s.value));if(s.length>0)throw new Error(`Docusaurus error: Duplicate values "${s.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[s,t])}function h(e){let{value:s,tabValues:t}=e;return t.some((e=>e.value===s))}function x(e){let{queryString:s=!1,groupId:t}=e;const i=(0,o.W6)(),r=function(e){let{queryString:s=!1,groupId:t}=e;if("string"==typeof s)return s;if(!1===s)return null;if(!0===s&&!t)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return t??null}({queryString:s,groupId:t});return[(0,l.aZ)(r),(0,n.useCallback)((e=>{if(!r)return;const s=new URLSearchParams(i.location.search);s.set(r,e),i.replace({...i.location,search:s.toString()})}),[r,i])]}function p(e){const{defaultValue:s,queryString:t=!1,groupId:i}=e,r=u(e),[o,l]=(0,n.useState)((()=>function(e){let{defaultValue:s,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(s){if(!h({value:s,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${s}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return s}const n=t.find((e=>e.default))??t[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:s,tabValues:r}))),[c,j]=x({queryString:t,groupId:i}),[p,g]=function(e){let{groupId:s}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(s),[i,r]=(0,d.Dv)(t);return[i,(0,n.useCallback)((e=>{t&&r.set(e)}),[t,r])]}({groupId:i}),m=(()=>{const e=c??p;return h({value:e,tabValues:r})?e:null})();(0,a.A)((()=>{m&&l(m)}),[m]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!h({value:e,tabValues:r}))throw new Error(`Can't select invalid tab value=${e}`);l(e),j(e),g(e)}),[j,g,r]),tabValues:r}}var g=t(1062);const m={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var f=t(4848);function b(e){let{className:s,block:t,selectedValue:n,selectValue:o,tabValues:a}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),d=e=>{const s=e.currentTarget,t=l.indexOf(s),i=a[t].value;i!==n&&(c(s),o(i))},j=e=>{let s=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const t=l.indexOf(e.currentTarget)+1;s=l[t]??l[0];break}case"ArrowLeft":{const t=l.indexOf(e.currentTarget)-1;s=l[t]??l[l.length-1];break}}s?.focus()};return(0,f.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,i.A)("tabs",{"tabs--block":t},s),children:a.map((e=>{let{value:s,label:t,attributes:r}=e;return(0,f.jsx)("li",{role:"tab",tabIndex:n===s?0:-1,"aria-selected":n===s,ref:e=>l.push(e),onKeyDown:j,onClick:d,...r,className:(0,i.A)("tabs__item",m.tabItem,r?.className,{"tabs__item--active":n===s}),children:t??s},s)}))})}function v(e){let{lazy:s,children:t,selectedValue:r}=e;const o=(Array.isArray(t)?t:[t]).filter(Boolean);if(s){const e=o.find((e=>e.props.value===r));return e?(0,n.cloneElement)(e,{className:(0,i.A)("margin-top--md",e.props.className)}):null}return(0,f.jsx)("div",{className:"margin-top--md",children:o.map(((e,s)=>(0,n.cloneElement)(e,{key:s,hidden:e.props.value!==r})))})}function y(e){const s=p(e);return(0,f.jsxs)("div",{className:(0,i.A)("tabs-container",m.tabList),children:[(0,f.jsx)(b,{...s,...e}),(0,f.jsx)(v,{...s,...e})]})}function w(e){const s=(0,g.A)();return(0,f.jsx)(y,{...e,children:j(e.children)},String(s))}},8453:(e,s,t)=>{t.d(s,{R:()=>o,x:()=>a});var n=t(6540);const i={},r=n.createContext(i);function o(e){const s=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function a(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),n.createElement(r.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4681],{7705:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>d,contentTitle:()=>c,default:()=>h,frontMatter:()=>l,metadata:()=>n,toc:()=>j});const n=JSON.parse('{"id":"getting-started/options/diagnostics","title":"Diagnostics option","description":"The diagnostics option configures error reporting.","source":"@site/docs/getting-started/options/diagnostics.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/diagnostics","permalink":"/ts-jest/docs/next/getting-started/options/diagnostics","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/diagnostics.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Diagnostics option"}}');var i=t(4848),r=t(8453),o=t(9489),a=t(7227);const l={title:"Diagnostics option"},c=void 0,d={},j=[{value:"Disabling/enabling",id:"disablingenabling",level:3},{value:"Advanced configuration",id:"advanced-configuration",level:3},{value:"Examples",id:"examples",level:3},{value:"Disabling diagnostics",id:"disabling-diagnostics",level:4},{value:"Advanced options",id:"advanced-options",level:4},{value:"Enabling diagnostics for test files only",id:"enabling-diagnostics-for-test-files-only",level:5},{value:"Do not fail on first error",id:"do-not-fail-on-first-error",level:5},{value:"Ignoring some error codes",id:"ignoring-some-error-codes",level:5}];function u(e){const s={a:"a",code:"code",em:"em",h3:"h3",h4:"h4",h5:"h5",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(s.p,{children:["The ",(0,i.jsx)(s.code,{children:"diagnostics"})," option configures error reporting.\nIt can both be enabled/disabled entirely or limited to a specific type of errors and/or files."]}),"\n",(0,i.jsxs)(s.p,{children:["If a diagnostic is not filtered out, ",(0,i.jsx)(s.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,i.jsx)(s.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,i.jsxs)(s.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,i.jsx)(s.code,{children:"diagnostics"})," option to ",(0,i.jsx)(s.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,i.jsx)(s.code,{children:"diagnostics"})," to ",(0,i.jsx)(s.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,i.jsx)(s.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,i.jsxs)(s.p,{children:["The ",(0,i.jsx)(s.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,i.jsxs)(s.ul,{children:["\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"warnOnly"})}),": If specified and ",(0,i.jsx)(s.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,i.jsx)(s.em,{children:"disabled"}),")."]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,i.jsx)(s.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". By default here are the ones ignored:","\n",(0,i.jsxs)(s.ul,{children:["\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.code,{children:"6059"}),": ",(0,i.jsx)(s.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.code,{children:"18002"}),": ",(0,i.jsx)(s.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.code,{children:"18003"}),": ",(0,i.jsx)(s.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,i.jsx)(s.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,i.jsx)(s.code,{children:"tsconfig"})," option ",(0,i.jsx)(s.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,i.jsx)(s.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,i.jsx)(s.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,i.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,i.jsx)(s.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,i.jsxs)(o.A,{groupId:"code-examples",children:[(0,i.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: false,\n },\n ],\n },\n}\n"})})}),(0,i.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: false,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,i.jsx)(a.A,{value:"JSON",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "diagnostics": false\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,i.jsx)(s.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,i.jsx)(s.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,i.jsxs)(s.p,{children:["Assuming all your test files ends with ",(0,i.jsx)(s.code,{children:".spec.ts"})," or ",(0,i.jsx)(s.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,i.jsxs)(o.A,{groupId:"code-examples",children:[(0,i.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n exclude: ['!**/*.(spec|test).ts'],\n },\n },\n ],\n },\n}\n"})})}),(0,i.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n exclude: ['!**/*.(spec|test).ts'],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,i.jsx)(a.A,{value:"JSON",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "diagnostics": {\n "exclude": ["!**/*.(spec|test).ts"]\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,i.jsx)(s.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,i.jsxs)(s.p,{children:["While some diagnostics are stop-blockers for the compilation, most of them are not. If you want the compilation (and so your tests) to continue when encountering those, set the ",(0,i.jsx)(s.code,{children:"warnOnly"})," to ",(0,i.jsx)(s.code,{children:"true"}),":"]}),"\n",(0,i.jsxs)(o.A,{groupId:"code-examples",children:[(0,i.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n warnOnly: true,\n },\n },\n ],\n },\n}\n"})})}),(0,i.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n warnOnly: true,\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,i.jsx)(a.A,{value:"JSON",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "diagnostics": {\n "warnOnly": true\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,i.jsx)(s.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,i.jsxs)(s.p,{children:["All TypeScript error codes can be found ",(0,i.jsx)(s.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,i.jsx)(s.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,i.jsxs)(s.ol,{children:["\n",(0,i.jsxs)(s.li,{children:["A single ",(0,i.jsx)(s.code,{children:"number"})," (example: ",(0,i.jsx)(s.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,i.jsxs)(s.li,{children:["A ",(0,i.jsx)(s.code,{children:"string"})," with a code (example ",(0,i.jsx)(s.code,{children:'"1009"'}),", ",(0,i.jsx)(s.code,{children:'"TS1009"'})," or ",(0,i.jsx)(s.code,{children:'"TS1009"'}),")"]}),"\n",(0,i.jsxs)(s.li,{children:["A ",(0,i.jsx)(s.code,{children:"string"})," with a list of the above (example: ",(0,i.jsx)(s.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,i.jsxs)(s.li,{children:["An ",(0,i.jsx)(s.code,{children:"array"})," of one or more from ",(0,i.jsx)(s.code,{children:"1"})," or ",(0,i.jsx)(s.code,{children:"3"})," (example: ",(0,i.jsx)(s.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,i.jsxs)(o.A,{groupId:"code-examples",children:[(0,i.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n ignoreCodes: [2571, 6031, 18003],\n },\n },\n ],\n },\n}\n"})})}),(0,i.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n ignoreCodes: [2571, 6031, 18003],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,i.jsx)(a.A,{value:"JSON",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "diagnostics": {\n "ignoreCodes": [2571, 6031, 18003]\n }\n }\n ]\n }\n }\n}\n'})})})]})]})}function h(e={}){const{wrapper:s}={...(0,r.R)(),...e.components};return s?(0,i.jsx)(s,{...e,children:(0,i.jsx)(u,{...e})}):u(e)}},7227:(e,s,t)=>{t.d(s,{A:()=>o});t(6540);var n=t(4164);const i={tabItem:"tabItem_Ymn6"};var r=t(4848);function o(e){let{children:s,hidden:t,className:o}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,n.A)(i.tabItem,o),hidden:t,children:s})}},9489:(e,s,t)=>{t.d(s,{A:()=>w});var n=t(6540),i=t(4164),r=t(4245),o=t(6347),a=t(6494),l=t(2814),c=t(5167),d=t(9900);function j(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:s}=e;return!!s&&"object"==typeof s&&"value"in s}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function u(e){const{values:s,children:t}=e;return(0,n.useMemo)((()=>{const e=s??function(e){return j(e).map((e=>{let{props:{value:s,label:t,attributes:n,default:i}}=e;return{value:s,label:t,attributes:n,default:i}}))}(t);return function(e){const s=(0,c.XI)(e,((e,s)=>e.value===s.value));if(s.length>0)throw new Error(`Docusaurus error: Duplicate values "${s.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[s,t])}function h(e){let{value:s,tabValues:t}=e;return t.some((e=>e.value===s))}function x(e){let{queryString:s=!1,groupId:t}=e;const i=(0,o.W6)(),r=function(e){let{queryString:s=!1,groupId:t}=e;if("string"==typeof s)return s;if(!1===s)return null;if(!0===s&&!t)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return t??null}({queryString:s,groupId:t});return[(0,l.aZ)(r),(0,n.useCallback)((e=>{if(!r)return;const s=new URLSearchParams(i.location.search);s.set(r,e),i.replace({...i.location,search:s.toString()})}),[r,i])]}function p(e){const{defaultValue:s,queryString:t=!1,groupId:i}=e,r=u(e),[o,l]=(0,n.useState)((()=>function(e){let{defaultValue:s,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(s){if(!h({value:s,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${s}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return s}const n=t.find((e=>e.default))??t[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:s,tabValues:r}))),[c,j]=x({queryString:t,groupId:i}),[p,g]=function(e){let{groupId:s}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(s),[i,r]=(0,d.Dv)(t);return[i,(0,n.useCallback)((e=>{t&&r.set(e)}),[t,r])]}({groupId:i}),m=(()=>{const e=c??p;return h({value:e,tabValues:r})?e:null})();(0,a.A)((()=>{m&&l(m)}),[m]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!h({value:e,tabValues:r}))throw new Error(`Can't select invalid tab value=${e}`);l(e),j(e),g(e)}),[j,g,r]),tabValues:r}}var g=t(1062);const m={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var f=t(4848);function b(e){let{className:s,block:t,selectedValue:n,selectValue:o,tabValues:a}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),d=e=>{const s=e.currentTarget,t=l.indexOf(s),i=a[t].value;i!==n&&(c(s),o(i))},j=e=>{let s=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const t=l.indexOf(e.currentTarget)+1;s=l[t]??l[0];break}case"ArrowLeft":{const t=l.indexOf(e.currentTarget)-1;s=l[t]??l[l.length-1];break}}s?.focus()};return(0,f.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,i.A)("tabs",{"tabs--block":t},s),children:a.map((e=>{let{value:s,label:t,attributes:r}=e;return(0,f.jsx)("li",{role:"tab",tabIndex:n===s?0:-1,"aria-selected":n===s,ref:e=>l.push(e),onKeyDown:j,onClick:d,...r,className:(0,i.A)("tabs__item",m.tabItem,r?.className,{"tabs__item--active":n===s}),children:t??s},s)}))})}function v(e){let{lazy:s,children:t,selectedValue:r}=e;const o=(Array.isArray(t)?t:[t]).filter(Boolean);if(s){const e=o.find((e=>e.props.value===r));return e?(0,n.cloneElement)(e,{className:(0,i.A)("margin-top--md",e.props.className)}):null}return(0,f.jsx)("div",{className:"margin-top--md",children:o.map(((e,s)=>(0,n.cloneElement)(e,{key:s,hidden:e.props.value!==r})))})}function y(e){const s=p(e);return(0,f.jsxs)("div",{className:(0,i.A)("tabs-container",m.tabList),children:[(0,f.jsx)(b,{...s,...e}),(0,f.jsx)(v,{...s,...e})]})}function w(e){const s=(0,g.A)();return(0,f.jsx)(y,{...e,children:j(e.children)},String(s))}},8453:(e,s,t)=>{t.d(s,{R:()=>o,x:()=>a});var n=t(6540);const i={},r=n.createContext(i);function o(e){const s=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function a(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),n.createElement(r.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/cf5c42a2.595bac99.js b/assets/js/cf5c42a2.aaa08e62.js similarity index 98% rename from assets/js/cf5c42a2.595bac99.js rename to assets/js/cf5c42a2.aaa08e62.js index 8b5b949d89..3d0878697a 100644 --- a/assets/js/cf5c42a2.595bac99.js +++ b/assets/js/cf5c42a2.aaa08e62.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2659],{4920:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>h,frontMatter:()=>r,metadata:()=>s,toc:()=>l});const s=JSON.parse('{"id":"getting-started/options/stringifyContentPathRegex","title":"Stringify content option","description":"The stringifyContentPathRegex option has been kept for backward compatibility of HTML_TRANSFORM","source":"@site/versioned_docs/version-27.1/getting-started/options/stringifyContentPathRegex.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/stringifyContentPathRegex","permalink":"/ts-jest/docs/27.1/getting-started/options/stringifyContentPathRegex","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/options/stringifyContentPathRegex.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Stringify content option"}}');var o=n(4848),i=n(8453);const r={title:"Stringify content option"},a=void 0,c={},l=[{value:"Example",id:"example",level:3}];function d(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["The ",(0,o.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,o.jsx)(t.code,{children:"__HTML_TRANSFORM__"}),"\nIt's a regular expression pattern used to match the path of file to be transformed.\nIf it matches, the file will be exported as a module exporting its content."]}),"\n",(0,o.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,o.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,o.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,o.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,o.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,o.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,o.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,o.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,o.jsx)(t.code,{children:"transform"})," option pointing to ",(0,o.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,o.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsxs)(t.p,{children:["In the ",(0,o.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,o.jsx)(t.code,{children:"package.json"})," version of the config, but extending from the preset will ensure more compatibility without any changes when updating."]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\n// Here `defaults` can be replaced with any other preset\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n\nmodule.exports = {\n // [...]\n moduleFileExtensions: [...tsjPreset.moduleFileExtensions, 'html'],\n transform: {\n ...tsjPreset.transform,\n '\\\\.html$': 'ts-jest',\n },\n globals: {\n 'ts-jest': {\n stringifyContentPathRegex: /\\.html$/,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleFileExtensions": ["js", "ts", "html"],\n "transform": {\n "\\\\.(html|ts|js)$": "ts-jest"\n },\n "globals": {\n "ts-jest": {\n "stringifyContentPathRegex": "\\\\.html$"\n }\n }\n }\n}\n'})})]})}function h(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>a});var s=n(6540);const o={},i=s.createContext(o);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2659],{4920:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>h,frontMatter:()=>r,metadata:()=>s,toc:()=>l});const s=JSON.parse('{"id":"getting-started/options/stringifyContentPathRegex","title":"Stringify content option","description":"The stringifyContentPathRegex option has been kept for backward compatibility of HTML_TRANSFORM","source":"@site/versioned_docs/version-27.1/getting-started/options/stringifyContentPathRegex.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/stringifyContentPathRegex","permalink":"/ts-jest/docs/27.1/getting-started/options/stringifyContentPathRegex","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/options/stringifyContentPathRegex.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Stringify content option"}}');var o=n(4848),i=n(8453);const r={title:"Stringify content option"},a=void 0,c={},l=[{value:"Example",id:"example",level:3}];function d(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["The ",(0,o.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,o.jsx)(t.code,{children:"__HTML_TRANSFORM__"}),"\nIt's a regular expression pattern used to match the path of file to be transformed.\nIf it matches, the file will be exported as a module exporting its content."]}),"\n",(0,o.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,o.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,o.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,o.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,o.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,o.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,o.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,o.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,o.jsx)(t.code,{children:"transform"})," option pointing to ",(0,o.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,o.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsxs)(t.p,{children:["In the ",(0,o.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,o.jsx)(t.code,{children:"package.json"})," version of the config, but extending from the preset will ensure more compatibility without any changes when updating."]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\n// Here `defaults` can be replaced with any other preset\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n\nmodule.exports = {\n // [...]\n moduleFileExtensions: [...tsjPreset.moduleFileExtensions, 'html'],\n transform: {\n ...tsjPreset.transform,\n '\\\\.html$': 'ts-jest',\n },\n globals: {\n 'ts-jest': {\n stringifyContentPathRegex: /\\.html$/,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleFileExtensions": ["js", "ts", "html"],\n "transform": {\n "\\\\.(html|ts|js)$": "ts-jest"\n },\n "globals": {\n "ts-jest": {\n "stringifyContentPathRegex": "\\\\.html$"\n }\n }\n }\n}\n'})})]})}function h(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>a});var s=n(6540);const o={},i=s.createContext(o);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/cffdf1e5.cf2f418e.js b/assets/js/cffdf1e5.1d9ce4e5.js similarity index 99% rename from assets/js/cffdf1e5.cf2f418e.js rename to assets/js/cffdf1e5.1d9ce4e5.js index 6f53571abc..f1226934a3 100644 --- a/assets/js/cffdf1e5.cf2f418e.js +++ b/assets/js/cffdf1e5.1d9ce4e5.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4631],{92:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>d,contentTitle:()=>l,default:()=>u,frontMatter:()=>r,metadata:()=>t,toc:()=>a});const t=JSON.parse('{"id":"guides/troubleshooting","title":"Troubleshooting","description":"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them.","source":"@site/versioned_docs/version-28.0/guides/troubleshooting.md","sourceDirName":"guides","slug":"/guides/troubleshooting","permalink":"/ts-jest/docs/28.0/guides/troubleshooting","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/guides/troubleshooting.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"troubleshooting","title":"Troubleshooting"},"sidebar":"version-28.0-docs","previous":{"title":"Using with React Native","permalink":"/ts-jest/docs/28.0/guides/react-native"},"next":{"title":"Using with monorepo","permalink":"/ts-jest/docs/28.0/guides/using-with-monorepo"}}');var o=n(4848),i=n(8453);const r={id:"troubleshooting",title:"Troubleshooting"},l=void 0,d={},a=[{value:"Running ts-jest on CI tools",id:"running-ts-jest-on-ci-tools",level:2},{value:"PROBLEM",id:"problem",level:3},{value:"SOLUTION",id:"solution",level:3},{value:"Transform (node)-module explicitly",id:"transform-node-module-explicitly",level:2},{value:"PROBLEM",id:"problem-1",level:3},{value:"SOLUTION",id:"solution-1",level:3},{value:"Tests gets stuck when importing a dependency",id:"tests-gets-stuck-when-importing-a-dependency",level:2},{value:"PROBLEM",id:"problem-2",level:3},{value:"SOLUTION",id:"solution-2",level:3}];function c(e){const s={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(s.p,{children:"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them."}),"\n",(0,o.jsxs)(s.p,{children:["Please also check Jest ",(0,o.jsx)(s.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," if your issue is related to jest."]}),"\n",(0,o.jsx)(s.h2,{id:"running-ts-jest-on-ci-tools",children:"Running ts-jest on CI tools"}),"\n",(0,o.jsx)(s.h3,{id:"problem",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:'Cannot find module "" from ""'}),"\n",(0,o.jsx)(s.h3,{id:"solution",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check if ",(0,o.jsx)(s.code,{children:"rootDir"})," is referenced correctly. If not add this on your existing jest configuration."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n roots: [""]\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module directories are included on your jest configuration. If not add this on your existing jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleDirectories: ["node_modules",""],\n modulePaths: [""],\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module name is properly mapped and can be referenced by jest. If not, you can define moduleNameMapper for your jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleNameMapper: {\n "": "/",\n },\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check github folder names if its identical to you local folder names. Sometimes github never updates your folder names even if you rename it locally. If this happens rename your folders via github or use this command ",(0,o.jsx)(s.code,{children:"git mv "})," and commit changes."]}),"\n"]}),"\n",(0,o.jsx)(s.h2,{id:"transform-node-module-explicitly",children:"Transform (node)-module explicitly"}),"\n",(0,o.jsx)(s.h3,{id:"problem-1",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"SyntaxError: Cannot use import statement outside a module"}),"\n",(0,o.jsx)(s.h3,{id:"solution-1",children:"SOLUTION"}),"\n",(0,o.jsx)(s.p,{children:"One of the node modules hasn't the correct syntax for Jests execution step. It needs to\nbe transformed first."}),"\n",(0,o.jsx)(s.p,{children:"There is a good chance that the error message shows which module is affected:"}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-shell",children:' SyntaxError: Cannot use import statement outside a module\n > 22 | import Component from "../../node_modules/some-module/lib";\n | ^\n'})}),"\n",(0,o.jsxs)(s.p,{children:["In this case ",(0,o.jsx)(s.strong,{children:"some-module"})," is the problem and needs to be transformed.\nBy adding the following line to the configuration file it will tell Jest which modules\nshouldnt be ignored during the transformation step:"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n transformIgnorePatterns: ["node_modules/(?!(some-module|another-module))"]\n};\n'})}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.strong,{children:"some-module"})," and ",(0,o.jsx)(s.strong,{children:"another-module"})," will be transformed."]}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/63389757/jest-unit-test-syntaxerror-cannot-use-import-statement-outside-a-module",children:"here"})," and ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/52035066/how-to-write-jest-transformignorepatterns",children:"here"}),"."]}),"\n",(0,o.jsx)(s.h2,{id:"tests-gets-stuck-when-importing-a-dependency",children:"Tests gets stuck when importing a dependency"}),"\n",(0,o.jsx)(s.h3,{id:"problem-2",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"Without cache, jest takes an extremely long time to process files and appears to be stuck."}),"\n",(0,o.jsx)(s.h3,{id:"solution-2",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.code,{children:"ts-jest"})," internally uses TypeScript compiler API to transform ts/js file into js file. The recommendation is to only transform what is needed."]}),"\n",(0,o.jsxs)(s.p,{children:["A possible cause for that issue is that you may have enabled ",(0,o.jsx)(s.code,{children:"ts-jest"})," to process javascript files in addition to TypeScript files. This leads to the result that more files are loaded which can, in some cases, blow up the machine."]}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your tsconfig file, check if ",(0,o.jsx)(s.code,{children:"compilerOptions.allowJs"})," is unset or set to false."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'{\n "compilerOptions": {\n "allowJs": false,\n }\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your jest configuration, check if the transform property includes only ",(0,o.jsx)(s.code,{children:".ts"})," files for ts-jest. If not, change the regular expression to exclude js files. You can also add the attribute ",(0,o.jsx)(s.code,{children:"isolatedModules: true"})," for ts-jest to disable type checking for tests."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-diff",children:"module.exports = {\n ...\n 'transform': {\n- '^.+\\\\.(t|j)s$': ['ts-jest', {}],\n+ '^.+\\\\.ts$': ['ts-jest', { isolatedModules: true }],\n },\n};\n"})}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://github.com/kulshekhar/ts-jest/issues/4294",children:"here"})]})]})}function u(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,o.jsx)(s,{...e,children:(0,o.jsx)(c,{...e})}):c(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>r,x:()=>l});var t=n(6540);const o={},i=t.createContext(o);function r(e){const s=t.useContext(i);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function l(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),t.createElement(i.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4631],{92:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>d,contentTitle:()=>l,default:()=>u,frontMatter:()=>r,metadata:()=>t,toc:()=>a});const t=JSON.parse('{"id":"guides/troubleshooting","title":"Troubleshooting","description":"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them.","source":"@site/versioned_docs/version-28.0/guides/troubleshooting.md","sourceDirName":"guides","slug":"/guides/troubleshooting","permalink":"/ts-jest/docs/28.0/guides/troubleshooting","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/guides/troubleshooting.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"troubleshooting","title":"Troubleshooting"},"sidebar":"version-28.0-docs","previous":{"title":"Using with React Native","permalink":"/ts-jest/docs/28.0/guides/react-native"},"next":{"title":"Using with monorepo","permalink":"/ts-jest/docs/28.0/guides/using-with-monorepo"}}');var o=n(4848),i=n(8453);const r={id:"troubleshooting",title:"Troubleshooting"},l=void 0,d={},a=[{value:"Running ts-jest on CI tools",id:"running-ts-jest-on-ci-tools",level:2},{value:"PROBLEM",id:"problem",level:3},{value:"SOLUTION",id:"solution",level:3},{value:"Transform (node)-module explicitly",id:"transform-node-module-explicitly",level:2},{value:"PROBLEM",id:"problem-1",level:3},{value:"SOLUTION",id:"solution-1",level:3},{value:"Tests gets stuck when importing a dependency",id:"tests-gets-stuck-when-importing-a-dependency",level:2},{value:"PROBLEM",id:"problem-2",level:3},{value:"SOLUTION",id:"solution-2",level:3}];function c(e){const s={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(s.p,{children:"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them."}),"\n",(0,o.jsxs)(s.p,{children:["Please also check Jest ",(0,o.jsx)(s.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," if your issue is related to jest."]}),"\n",(0,o.jsx)(s.h2,{id:"running-ts-jest-on-ci-tools",children:"Running ts-jest on CI tools"}),"\n",(0,o.jsx)(s.h3,{id:"problem",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:'Cannot find module "" from ""'}),"\n",(0,o.jsx)(s.h3,{id:"solution",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check if ",(0,o.jsx)(s.code,{children:"rootDir"})," is referenced correctly. If not add this on your existing jest configuration."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n roots: [""]\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module directories are included on your jest configuration. If not add this on your existing jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleDirectories: ["node_modules",""],\n modulePaths: [""],\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module name is properly mapped and can be referenced by jest. If not, you can define moduleNameMapper for your jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleNameMapper: {\n "": "/",\n },\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check github folder names if its identical to you local folder names. Sometimes github never updates your folder names even if you rename it locally. If this happens rename your folders via github or use this command ",(0,o.jsx)(s.code,{children:"git mv "})," and commit changes."]}),"\n"]}),"\n",(0,o.jsx)(s.h2,{id:"transform-node-module-explicitly",children:"Transform (node)-module explicitly"}),"\n",(0,o.jsx)(s.h3,{id:"problem-1",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"SyntaxError: Cannot use import statement outside a module"}),"\n",(0,o.jsx)(s.h3,{id:"solution-1",children:"SOLUTION"}),"\n",(0,o.jsx)(s.p,{children:"One of the node modules hasn't the correct syntax for Jests execution step. It needs to\nbe transformed first."}),"\n",(0,o.jsx)(s.p,{children:"There is a good chance that the error message shows which module is affected:"}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-shell",children:' SyntaxError: Cannot use import statement outside a module\n > 22 | import Component from "../../node_modules/some-module/lib";\n | ^\n'})}),"\n",(0,o.jsxs)(s.p,{children:["In this case ",(0,o.jsx)(s.strong,{children:"some-module"})," is the problem and needs to be transformed.\nBy adding the following line to the configuration file it will tell Jest which modules\nshouldnt be ignored during the transformation step:"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n transformIgnorePatterns: ["node_modules/(?!(some-module|another-module))"]\n};\n'})}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.strong,{children:"some-module"})," and ",(0,o.jsx)(s.strong,{children:"another-module"})," will be transformed."]}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/63389757/jest-unit-test-syntaxerror-cannot-use-import-statement-outside-a-module",children:"here"})," and ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/52035066/how-to-write-jest-transformignorepatterns",children:"here"}),"."]}),"\n",(0,o.jsx)(s.h2,{id:"tests-gets-stuck-when-importing-a-dependency",children:"Tests gets stuck when importing a dependency"}),"\n",(0,o.jsx)(s.h3,{id:"problem-2",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"Without cache, jest takes an extremely long time to process files and appears to be stuck."}),"\n",(0,o.jsx)(s.h3,{id:"solution-2",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.code,{children:"ts-jest"})," internally uses TypeScript compiler API to transform ts/js file into js file. The recommendation is to only transform what is needed."]}),"\n",(0,o.jsxs)(s.p,{children:["A possible cause for that issue is that you may have enabled ",(0,o.jsx)(s.code,{children:"ts-jest"})," to process javascript files in addition to TypeScript files. This leads to the result that more files are loaded which can, in some cases, blow up the machine."]}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your tsconfig file, check if ",(0,o.jsx)(s.code,{children:"compilerOptions.allowJs"})," is unset or set to false."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'{\n "compilerOptions": {\n "allowJs": false,\n }\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your jest configuration, check if the transform property includes only ",(0,o.jsx)(s.code,{children:".ts"})," files for ts-jest. If not, change the regular expression to exclude js files. You can also add the attribute ",(0,o.jsx)(s.code,{children:"isolatedModules: true"})," for ts-jest to disable type checking for tests."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-diff",children:"module.exports = {\n ...\n 'transform': {\n- '^.+\\\\.(t|j)s$': ['ts-jest', {}],\n+ '^.+\\\\.ts$': ['ts-jest', { isolatedModules: true }],\n },\n};\n"})}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://github.com/kulshekhar/ts-jest/issues/4294",children:"here"})]})]})}function u(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,o.jsx)(s,{...e,children:(0,o.jsx)(c,{...e})}):c(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>r,x:()=>l});var t=n(6540);const o={},i=t.createContext(o);function r(e){const s=t.useContext(i);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function l(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),t.createElement(i.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/d0e697d4.c6440020.js b/assets/js/d0e697d4.8469c21f.js similarity index 97% rename from assets/js/d0e697d4.c6440020.js rename to assets/js/d0e697d4.8469c21f.js index da61101165..b25f8361d8 100644 --- a/assets/js/d0e697d4.c6440020.js +++ b/assets/js/d0e697d4.8469c21f.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6842],{4061:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>r,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"guides/using-with-monorepo","title":"Using with monorepo","description":"To use ts-jest in a project with monorepo structure, you\'ll need to use Jest projects configuration.","source":"@site/versioned_docs/version-27.1/guides/using-with-monorepo.md","sourceDirName":"guides","slug":"/guides/using-with-monorepo","permalink":"/ts-jest/docs/27.1/guides/using-with-monorepo","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/guides/using-with-monorepo.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"using-with-monorepo","title":"Using with monorepo"},"sidebar":"version-27.1-docs","previous":{"title":"Troubleshooting","permalink":"/ts-jest/docs/27.1/guides/troubleshooting"},"next":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/27.1/babel7-or-ts"}}');var n=o(4848),i=o(8453);const r={id:"using-with-monorepo",title:"Using with monorepo"},c=void 0,u={},d=[];function a(e){const t={a:"a",code:"code",p:"p",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["To use ",(0,n.jsx)(t.code,{children:"ts-jest"})," in a project with monorepo structure, you'll need to use ",(0,n.jsx)(t.a,{href:"https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig",children:"Jest projects configuration"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["When using Jest ",(0,n.jsx)(t.code,{children:"projects"})," configuration, Jest will run ",(0,n.jsx)(t.code,{children:"ts-jest"})," against each project which is defined in the configuration."]})]})}function p(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(a,{...e})}):a(e)}},8453:(e,t,o)=>{o.d(t,{R:()=>r,x:()=>c});var s=o(6540);const n={},i=s.createContext(n);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6842],{4061:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>r,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"guides/using-with-monorepo","title":"Using with monorepo","description":"To use ts-jest in a project with monorepo structure, you\'ll need to use Jest projects configuration.","source":"@site/versioned_docs/version-27.1/guides/using-with-monorepo.md","sourceDirName":"guides","slug":"/guides/using-with-monorepo","permalink":"/ts-jest/docs/27.1/guides/using-with-monorepo","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/guides/using-with-monorepo.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"using-with-monorepo","title":"Using with monorepo"},"sidebar":"version-27.1-docs","previous":{"title":"Troubleshooting","permalink":"/ts-jest/docs/27.1/guides/troubleshooting"},"next":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/27.1/babel7-or-ts"}}');var n=o(4848),i=o(8453);const r={id:"using-with-monorepo",title:"Using with monorepo"},c=void 0,u={},d=[];function a(e){const t={a:"a",code:"code",p:"p",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["To use ",(0,n.jsx)(t.code,{children:"ts-jest"})," in a project with monorepo structure, you'll need to use ",(0,n.jsx)(t.a,{href:"https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig",children:"Jest projects configuration"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["When using Jest ",(0,n.jsx)(t.code,{children:"projects"})," configuration, Jest will run ",(0,n.jsx)(t.code,{children:"ts-jest"})," against each project which is defined in the configuration."]})]})}function p(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(a,{...e})}):a(e)}},8453:(e,t,o)=>{o.d(t,{R:()=>r,x:()=>c});var s=o(6540);const n={},i=s.createContext(n);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/d296dded.f75bff98.js b/assets/js/d296dded.e85b0aff.js similarity index 97% rename from assets/js/d296dded.f75bff98.js rename to assets/js/d296dded.e85b0aff.js index ca0d4910ec..ede137b76a 100644 --- a/assets/js/d296dded.f75bff98.js +++ b/assets/js/d296dded.e85b0aff.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8563],{3791:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>r,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"guides/using-with-monorepo","title":"Using with monorepo","description":"To use ts-jest in a project with monorepo structure, you\'ll need to use Jest projects configuration.","source":"@site/versioned_docs/version-29.2/guides/using-with-monorepo.md","sourceDirName":"guides","slug":"/guides/using-with-monorepo","permalink":"/ts-jest/docs/guides/using-with-monorepo","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/guides/using-with-monorepo.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"using-with-monorepo","title":"Using with monorepo"},"sidebar":"version-29.1-docs","previous":{"title":"Troubleshooting","permalink":"/ts-jest/docs/guides/troubleshooting"},"next":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/babel7-or-ts"}}');var n=o(4848),i=o(8453);const r={id:"using-with-monorepo",title:"Using with monorepo"},c=void 0,u={},d=[];function a(e){const t={a:"a",code:"code",p:"p",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["To use ",(0,n.jsx)(t.code,{children:"ts-jest"})," in a project with monorepo structure, you'll need to use ",(0,n.jsx)(t.a,{href:"https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig",children:"Jest projects configuration"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["When using Jest ",(0,n.jsx)(t.code,{children:"projects"})," configuration, Jest will run ",(0,n.jsx)(t.code,{children:"ts-jest"})," against each project which is defined in the configuration."]})]})}function p(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(a,{...e})}):a(e)}},8453:(e,t,o)=>{o.d(t,{R:()=>r,x:()=>c});var s=o(6540);const n={},i=s.createContext(n);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8563],{3791:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>r,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"guides/using-with-monorepo","title":"Using with monorepo","description":"To use ts-jest in a project with monorepo structure, you\'ll need to use Jest projects configuration.","source":"@site/versioned_docs/version-29.2/guides/using-with-monorepo.md","sourceDirName":"guides","slug":"/guides/using-with-monorepo","permalink":"/ts-jest/docs/guides/using-with-monorepo","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/guides/using-with-monorepo.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"using-with-monorepo","title":"Using with monorepo"},"sidebar":"version-29.1-docs","previous":{"title":"Troubleshooting","permalink":"/ts-jest/docs/guides/troubleshooting"},"next":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/babel7-or-ts"}}');var n=o(4848),i=o(8453);const r={id:"using-with-monorepo",title:"Using with monorepo"},c=void 0,u={},d=[];function a(e){const t={a:"a",code:"code",p:"p",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["To use ",(0,n.jsx)(t.code,{children:"ts-jest"})," in a project with monorepo structure, you'll need to use ",(0,n.jsx)(t.a,{href:"https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig",children:"Jest projects configuration"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["When using Jest ",(0,n.jsx)(t.code,{children:"projects"})," configuration, Jest will run ",(0,n.jsx)(t.code,{children:"ts-jest"})," against each project which is defined in the configuration."]})]})}function p(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(a,{...e})}):a(e)}},8453:(e,t,o)=>{o.d(t,{R:()=>r,x:()=>c});var s=o(6540);const n={},i=s.createContext(n);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/d3b43630.fcc5105a.js b/assets/js/d3b43630.eccf12e3.js similarity index 98% rename from assets/js/d3b43630.fcc5105a.js rename to assets/js/d3b43630.eccf12e3.js index 594b41914d..3d4dd15359 100644 --- a/assets/js/d3b43630.fcc5105a.js +++ b/assets/js/d3b43630.eccf12e3.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9592],{5216:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>a,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>t,toc:()=>l});const t=JSON.parse('{"id":"guides/mock-es6-class","title":"Mock ES6 class","description":"TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.","source":"@site/versioned_docs/version-27.1/guides/mock-es6-class.md","sourceDirName":"guides","slug":"/guides/mock-es6-class","permalink":"/ts-jest/docs/27.1/guides/mock-es6-class","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/guides/mock-es6-class.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"mock-es6-class","title":"Mock ES6 class"},"sidebar":"version-27.1-docs","previous":{"title":"ESM Support","permalink":"/ts-jest/docs/27.1/guides/esm-support"},"next":{"title":"Using with React Native","permalink":"/ts-jest/docs/27.1/guides/react-native"}}');var o=n(4848),r=n(8453);const i={id:"mock-es6-class",title:"Mock ES6 class"},c=void 0,a={},l=[];function d(e){const s={code:"code",p:"p",pre:"pre",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(s.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,o.jsx)(s.code,{children:"const soundPlayer = require('./sound-player')"}),". Therefore creating an instance of the class that was exported as\na default will look like this: ",(0,o.jsx)(s.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"jest.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\n })\n})\n"})}),"\n",(0,o.jsx)(s.p,{children:"You will get the error"}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,o.jsxs)(s.p,{children:["because ",(0,o.jsx)(s.code,{children:"soundPlayer.default"})," does not point to a function. Your mock has to return an object which has a property default\nthat points to a function."]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"jest.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\n }\n }),\n }\n})\n"})}),"\n",(0,o.jsxs)(s.p,{children:["For named imports, like ",(0,o.jsx)(s.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,o.jsx)(s.code,{children:"default"})," with imported module name, ",(0,o.jsx)(s.code,{children:"OAuth2"})," in this example:"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"jest.mock('./oauth', () => {\n return {\n OAuth2: ... // mock here\n }\n})\n"})})]})}function u(e={}){const{wrapper:s}={...(0,r.R)(),...e.components};return s?(0,o.jsx)(s,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>i,x:()=>c});var t=n(6540);const o={},r=t.createContext(o);function i(e){const s=t.useContext(r);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function c(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),t.createElement(r.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9592],{5216:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>a,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>t,toc:()=>l});const t=JSON.parse('{"id":"guides/mock-es6-class","title":"Mock ES6 class","description":"TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.","source":"@site/versioned_docs/version-27.1/guides/mock-es6-class.md","sourceDirName":"guides","slug":"/guides/mock-es6-class","permalink":"/ts-jest/docs/27.1/guides/mock-es6-class","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/guides/mock-es6-class.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"mock-es6-class","title":"Mock ES6 class"},"sidebar":"version-27.1-docs","previous":{"title":"ESM Support","permalink":"/ts-jest/docs/27.1/guides/esm-support"},"next":{"title":"Using with React Native","permalink":"/ts-jest/docs/27.1/guides/react-native"}}');var o=n(4848),r=n(8453);const i={id:"mock-es6-class",title:"Mock ES6 class"},c=void 0,a={},l=[];function d(e){const s={code:"code",p:"p",pre:"pre",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(s.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,o.jsx)(s.code,{children:"const soundPlayer = require('./sound-player')"}),". Therefore creating an instance of the class that was exported as\na default will look like this: ",(0,o.jsx)(s.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"jest.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\n })\n})\n"})}),"\n",(0,o.jsx)(s.p,{children:"You will get the error"}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,o.jsxs)(s.p,{children:["because ",(0,o.jsx)(s.code,{children:"soundPlayer.default"})," does not point to a function. Your mock has to return an object which has a property default\nthat points to a function."]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"jest.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\n }\n }),\n }\n})\n"})}),"\n",(0,o.jsxs)(s.p,{children:["For named imports, like ",(0,o.jsx)(s.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,o.jsx)(s.code,{children:"default"})," with imported module name, ",(0,o.jsx)(s.code,{children:"OAuth2"})," in this example:"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"jest.mock('./oauth', () => {\n return {\n OAuth2: ... // mock here\n }\n})\n"})})]})}function u(e={}){const{wrapper:s}={...(0,r.R)(),...e.components};return s?(0,o.jsx)(s,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>i,x:()=>c});var t=n(6540);const o={},r=t.createContext(o);function i(e){const s=t.useContext(r);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function c(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),t.createElement(r.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/d4836a8e.b1763707.js b/assets/js/d4836a8e.49a40161.js similarity index 98% rename from assets/js/d4836a8e.b1763707.js rename to assets/js/d4836a8e.49a40161.js index 60e8a92d16..164a0df647 100644 --- a/assets/js/d4836a8e.b1763707.js +++ b/assets/js/d4836a8e.49a40161.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[106],{3191:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>p,contentTitle:()=>a,default:()=>x,frontMatter:()=>d,metadata:()=>n,toc:()=>u});const n=JSON.parse('{"id":"guides/esm-support","title":"ESM Support","description":"References","source":"@site/docs/guides/esm-support.md","sourceDirName":"guides","slug":"/guides/esm-support","permalink":"/ts-jest/docs/next/guides/esm-support","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/guides/esm-support.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"esm-support","title":"ESM Support"},"sidebar":"docs","previous":{"title":"Version checking","permalink":"/ts-jest/docs/next/getting-started/version-checking"},"next":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/next/guides/mock-es6-class"}}');var r=t(4848),o=t(8453),i=t(9489),l=t(7227),c=t(1574);const d={id:"esm-support",title:"ESM Support"},a=void 0,p={},u=[{value:"References",id:"references",level:2},{value:"Configuration",id:"configuration",level:3},{value:"Example:",id:"example",level:4},{value:"Example:",id:"example-1",level:4},{value:"Resolve .mjs/.mts extensions",id:"resolve-mjsmts-extensions",level:3}];function h(e){const s={a:"a",code:"code",h2:"h2",h3:"h3",h4:"h4",hr:"hr",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(s.h2,{id:"references",children:"References"}),"\n","\n",(0,r.jsx)(c.A,{toc:u.slice(1)}),"\n",(0,r.jsx)(s.hr,{}),"\n",(0,r.jsx)(s.h3,{id:"configuration",children:"Configuration"}),"\n",(0,r.jsxs)(s.p,{children:["To use ",(0,r.jsx)(s.code,{children:"ts-jest"})," with ESM support:"]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:["Check ",(0,r.jsx)(s.a,{href:"https://jestjs.io/docs/en/ecmascript-modules",children:"ESM Jest documentation"}),"."]}),"\n",(0,r.jsxs)(s.li,{children:["Ensure that ",(0,r.jsx)(s.code,{children:"tsconfig"})," has ",(0,r.jsx)(s.code,{children:"module"})," with value for ESM, e.g. ",(0,r.jsx)(s.code,{children:"ES2022"}),"/",(0,r.jsx)(s.code,{children:"ESNext"})," etc..."]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"example",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'// tsconfig.spec.json\n{\n "compilerOptions": {\n "module": "ESNext", // or ES2022\n "target": "ESNext",\n "esModuleInterop": true\n }\n}\n'})}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:["Configure your Jest configuration use one of the ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/presets",children:"utility functions"})]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"example-1",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createDefaultEsmPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createDefaultEsmPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsxs)(s.h3,{id:"resolve-mjsmts-extensions",children:["Resolve ",(0,r.jsx)(s.code,{children:".mjs/.mts"})," extensions"]}),"\n",(0,r.jsxs)(s.p,{children:["To work with ",(0,r.jsx)(s.code,{children:".mts"})," extension, besides the requirement to run Jest and ",(0,r.jsx)(s.code,{children:"ts-jest"})," in ESM mode, there are a few extra requirements to be met:"]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"package.json"})," should contain ",(0,r.jsx)(s.code,{children:'"type": "module"'})]}),"\n",(0,r.jsxs)(s.li,{children:["A custom Jest resolver to resolve ",(0,r.jsx)(s.code,{children:".mjs"})," extension, for example:"]}),"\n"]}),"\n",(0,r.jsxs)(i.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"typescript-cjs",label:"TypeScript CJS",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",metastring:'tab={"label": "TypeScript CJS"}',children:"import type { SyncResolver } from 'jest-resolve'\n\nconst mjsResolver: SyncResolver = (path, options) => {\n const mjsExtRegex = /\\.mjs$/i\n const resolver = options.defaultResolver\n if (mjsExtRegex.test(path)) {\n try {\n return resolver(path.replace(mjsExtRegex, '.mts'), options)\n } catch {\n // use default resolver\n }\n }\n\n return resolver(path, options)\n}\n\nexport = mjsResolver\n"})})}),(0,r.jsx)(l.A,{value:"typescript-esm",label:"TypeScript ESM",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",metastring:'tab={"label": "TypeScript ESM"}',children:"import type { SyncResolver } from 'jest-resolve'\n\nconst mjsResolver: SyncResolver = (path, options) => {\n const mjsExtRegex = /\\.mjs$/i\n const resolver = options.defaultResolver\n if (mjsExtRegex.test(path)) {\n try {\n return resolver(path.replace(mjsExtRegex, '.mts'), options)\n } catch {\n // use default resolver\n }\n }\n\n return resolver(path, options)\n}\n\nexport default mjsResolver\n"})})})]})]})}function x(e={}){const{wrapper:s}={...(0,o.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[106],{3191:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>p,contentTitle:()=>a,default:()=>x,frontMatter:()=>d,metadata:()=>n,toc:()=>u});const n=JSON.parse('{"id":"guides/esm-support","title":"ESM Support","description":"References","source":"@site/docs/guides/esm-support.md","sourceDirName":"guides","slug":"/guides/esm-support","permalink":"/ts-jest/docs/next/guides/esm-support","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/guides/esm-support.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"esm-support","title":"ESM Support"},"sidebar":"docs","previous":{"title":"Version checking","permalink":"/ts-jest/docs/next/getting-started/version-checking"},"next":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/next/guides/mock-es6-class"}}');var r=t(4848),o=t(8453),i=t(9489),l=t(7227),c=t(1574);const d={id:"esm-support",title:"ESM Support"},a=void 0,p={},u=[{value:"References",id:"references",level:2},{value:"Configuration",id:"configuration",level:3},{value:"Example:",id:"example",level:4},{value:"Example:",id:"example-1",level:4},{value:"Resolve .mjs/.mts extensions",id:"resolve-mjsmts-extensions",level:3}];function h(e){const s={a:"a",code:"code",h2:"h2",h3:"h3",h4:"h4",hr:"hr",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(s.h2,{id:"references",children:"References"}),"\n","\n",(0,r.jsx)(c.A,{toc:u.slice(1)}),"\n",(0,r.jsx)(s.hr,{}),"\n",(0,r.jsx)(s.h3,{id:"configuration",children:"Configuration"}),"\n",(0,r.jsxs)(s.p,{children:["To use ",(0,r.jsx)(s.code,{children:"ts-jest"})," with ESM support:"]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:["Check ",(0,r.jsx)(s.a,{href:"https://jestjs.io/docs/en/ecmascript-modules",children:"ESM Jest documentation"}),"."]}),"\n",(0,r.jsxs)(s.li,{children:["Ensure that ",(0,r.jsx)(s.code,{children:"tsconfig"})," has ",(0,r.jsx)(s.code,{children:"module"})," with value for ESM, e.g. ",(0,r.jsx)(s.code,{children:"ES2022"}),"/",(0,r.jsx)(s.code,{children:"ESNext"})," etc..."]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"example",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'// tsconfig.spec.json\n{\n "compilerOptions": {\n "module": "ESNext", // or ES2022\n "target": "ESNext",\n "esModuleInterop": true\n }\n}\n'})}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:["Configure your Jest configuration use one of the ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/presets",children:"utility functions"})]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"example-1",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createDefaultEsmPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createDefaultEsmPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsxs)(s.h3,{id:"resolve-mjsmts-extensions",children:["Resolve ",(0,r.jsx)(s.code,{children:".mjs/.mts"})," extensions"]}),"\n",(0,r.jsxs)(s.p,{children:["To work with ",(0,r.jsx)(s.code,{children:".mts"})," extension, besides the requirement to run Jest and ",(0,r.jsx)(s.code,{children:"ts-jest"})," in ESM mode, there are a few extra requirements to be met:"]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"package.json"})," should contain ",(0,r.jsx)(s.code,{children:'"type": "module"'})]}),"\n",(0,r.jsxs)(s.li,{children:["A custom Jest resolver to resolve ",(0,r.jsx)(s.code,{children:".mjs"})," extension, for example:"]}),"\n"]}),"\n",(0,r.jsxs)(i.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"typescript-cjs",label:"TypeScript CJS",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",metastring:'tab={"label": "TypeScript CJS"}',children:"import type { SyncResolver } from 'jest-resolve'\n\nconst mjsResolver: SyncResolver = (path, options) => {\n const mjsExtRegex = /\\.mjs$/i\n const resolver = options.defaultResolver\n if (mjsExtRegex.test(path)) {\n try {\n return resolver(path.replace(mjsExtRegex, '.mts'), options)\n } catch {\n // use default resolver\n }\n }\n\n return resolver(path, options)\n}\n\nexport = mjsResolver\n"})})}),(0,r.jsx)(l.A,{value:"typescript-esm",label:"TypeScript ESM",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",metastring:'tab={"label": "TypeScript ESM"}',children:"import type { SyncResolver } from 'jest-resolve'\n\nconst mjsResolver: SyncResolver = (path, options) => {\n const mjsExtRegex = /\\.mjs$/i\n const resolver = options.defaultResolver\n if (mjsExtRegex.test(path)) {\n try {\n return resolver(path.replace(mjsExtRegex, '.mts'), options)\n } catch {\n // use default resolver\n }\n }\n\n return resolver(path, options)\n}\n\nexport default mjsResolver\n"})})})]})]})}function x(e={}){const{wrapper:s}={...(0,o.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}}}]); \ No newline at end of file diff --git a/assets/js/d4a6dd78.ebdffa88.js b/assets/js/d4a6dd78.99b839a8.js similarity index 99% rename from assets/js/d4a6dd78.ebdffa88.js rename to assets/js/d4a6dd78.99b839a8.js index aed98434dc..4abd02065f 100644 --- a/assets/js/d4a6dd78.ebdffa88.js +++ b/assets/js/d4a6dd78.99b839a8.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1163],{1435:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>r,contentTitle:()=>i,default:()=>b,frontMatter:()=>a,metadata:()=>t,toc:()=>c});const t=JSON.parse('{"id":"getting-started/options/babelConfig","title":"Babel Config option","description":"ts-jest by default does NOT use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ts-jest can call the BabelJest processor once TypeScript has transformed the source into JavaScript.","source":"@site/versioned_docs/version-27.0/getting-started/options/babelConfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/babelConfig","permalink":"/ts-jest/docs/27.0/getting-started/options/babelConfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/options/babelConfig.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Babel Config option"}}');var o=s(4848),l=s(8453);const a={title:"Babel Config option"},i=void 0,r={},c=[{value:"Examples",id:"examples",level:3},{value:"Use default babelrc file",id:"use-default-babelrc-file",level:4},{value:"Path to a babelrc file",id:"path-to-a-babelrc-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4}];function d(e){const n={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,l.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:[(0,o.jsx)(n.code,{children:"ts-jest"})," by default does ",(0,o.jsx)(n.strong,{children:"NOT"})," use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ",(0,o.jsx)(n.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,o.jsxs)(n.p,{children:["The option is ",(0,o.jsx)(n.code,{children:"babelConfig"})," and it works pretty much as the ",(0,o.jsx)(n.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"true"}),": enables Babel processing. ",(0,o.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(n.code,{children:".babelrc"}),", ",(0,o.jsx)(n.code,{children:".babelrc.js"}),", ",(0,o.jsx)(n.code,{children:"babel.config.js"})," file or a ",(0,o.jsx)(n.code,{children:"babel"})," section in the ",(0,o.jsx)(n.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,o.jsx)(n.code,{children:"babel-jest"})," processor."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"{ ... }"}),": inline ",(0,o.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,o.jsx)(n.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,o.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsxs)(n.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,o.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: true,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "babelConfig": true\n }\n }\n }\n}\n'})}),"\n",(0,o.jsxs)(n.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,o.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,o.jsxs)(n.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,o.jsx)(n.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: 'babelrc.test.js',\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.p,{children:"or"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: require('./babelrc.test.js'),\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "babelConfig": "babelrc.test.js"\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,o.jsxs)(n.p,{children:["Refer to the ",(0,o.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: {\n comments: false,\n plugins: ['@babel/plugin-transform-for-of'],\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "babelConfig": {\n "comments": false,\n "plugins": ["@babel/plugin-transform-for-of"]\n }\n }\n }\n }\n}\n'})})]})}function b(e={}){const{wrapper:n}={...(0,l.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,n,s)=>{s.d(n,{R:()=>a,x:()=>i});var t=s(6540);const o={},l=t.createContext(o);function a(e){const n=t.useContext(l);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),t.createElement(l.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1163],{1435:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>r,contentTitle:()=>i,default:()=>b,frontMatter:()=>a,metadata:()=>t,toc:()=>c});const t=JSON.parse('{"id":"getting-started/options/babelConfig","title":"Babel Config option","description":"ts-jest by default does NOT use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ts-jest can call the BabelJest processor once TypeScript has transformed the source into JavaScript.","source":"@site/versioned_docs/version-27.0/getting-started/options/babelConfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/babelConfig","permalink":"/ts-jest/docs/27.0/getting-started/options/babelConfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/options/babelConfig.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Babel Config option"}}');var o=s(4848),l=s(8453);const a={title:"Babel Config option"},i=void 0,r={},c=[{value:"Examples",id:"examples",level:3},{value:"Use default babelrc file",id:"use-default-babelrc-file",level:4},{value:"Path to a babelrc file",id:"path-to-a-babelrc-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4}];function d(e){const n={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,l.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:[(0,o.jsx)(n.code,{children:"ts-jest"})," by default does ",(0,o.jsx)(n.strong,{children:"NOT"})," use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ",(0,o.jsx)(n.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,o.jsxs)(n.p,{children:["The option is ",(0,o.jsx)(n.code,{children:"babelConfig"})," and it works pretty much as the ",(0,o.jsx)(n.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"true"}),": enables Babel processing. ",(0,o.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(n.code,{children:".babelrc"}),", ",(0,o.jsx)(n.code,{children:".babelrc.js"}),", ",(0,o.jsx)(n.code,{children:"babel.config.js"})," file or a ",(0,o.jsx)(n.code,{children:"babel"})," section in the ",(0,o.jsx)(n.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,o.jsx)(n.code,{children:"babel-jest"})," processor."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"{ ... }"}),": inline ",(0,o.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,o.jsx)(n.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,o.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsxs)(n.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,o.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: true,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "babelConfig": true\n }\n }\n }\n}\n'})}),"\n",(0,o.jsxs)(n.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,o.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,o.jsxs)(n.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,o.jsx)(n.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: 'babelrc.test.js',\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.p,{children:"or"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: require('./babelrc.test.js'),\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "babelConfig": "babelrc.test.js"\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,o.jsxs)(n.p,{children:["Refer to the ",(0,o.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n babelConfig: {\n comments: false,\n plugins: ['@babel/plugin-transform-for-of'],\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "babelConfig": {\n "comments": false,\n "plugins": ["@babel/plugin-transform-for-of"]\n }\n }\n }\n }\n}\n'})})]})}function b(e={}){const{wrapper:n}={...(0,l.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,n,s)=>{s.d(n,{R:()=>a,x:()=>i});var t=s(6540);const o={},l=t.createContext(o);function a(e){const n=t.useContext(l);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),t.createElement(l.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/d6f9473b.1f6aa8d3.js b/assets/js/d6f9473b.4ea96a3d.js similarity index 99% rename from assets/js/d6f9473b.1f6aa8d3.js rename to assets/js/d6f9473b.4ea96a3d.js index b2cdd0b3c5..f3cb7a8612 100644 --- a/assets/js/d6f9473b.1f6aa8d3.js +++ b/assets/js/d6f9473b.4ea96a3d.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9314],{4904:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>i,default:()=>p,frontMatter:()=>a,metadata:()=>r,toc:()=>l});const r=JSON.parse('{"id":"getting-started/options/astTransformers","title":"AST transformers option","description":"ts-jest by default does hoisting for a few jest methods via a TypeScript AST transformer. One can also create custom","source":"@site/versioned_docs/version-27.1/getting-started/options/astTransformers.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/astTransformers","permalink":"/ts-jest/docs/27.1/getting-started/options/astTransformers","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/options/astTransformers.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"AST transformers option"}}');var t=n(4848),o=n(8453);const a={title:"AST transformers option"},i=void 0,c={},l=[{value:"Examples",id:"examples",level:3},{value:"Basic Transformers",id:"basic-transformers",level:4},{value:"Configuring transformers with options",id:"configuring-transformers-with-options",level:4},{value:"Public transformers",id:"public-transformers",level:3},{value:"Example of opt-in transformers",id:"example-of-opt-in-transformers",level:4},{value:"Writing custom TypeScript AST transformers",id:"writing-custom-typescript-ast-transformers",level:3}];function d(e){const s={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(s.p,{children:[(0,t.jsx)(s.code,{children:"ts-jest"})," by default does hoisting for a few ",(0,t.jsx)(s.code,{children:"jest"})," methods via a TypeScript AST transformer. One can also create custom\nTypeScript AST transformers and provide them to ",(0,t.jsx)(s.code,{children:"ts-jest"})," to include into compilation process."]}),"\n",(0,t.jsxs)(s.p,{children:["The option is ",(0,t.jsx)(s.code,{children:"astTransformers"})," and it allows ones to specify which 3 types of TypeScript AST transformers to use with ",(0,t.jsx)(s.code,{children:"ts-jest"}),":"]}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"before"})," means your transformers get run before TS ones, which means your transformers will get raw TS syntax\ninstead of transpiled syntax (e.g ",(0,t.jsx)(s.code,{children:"import"})," instead of ",(0,t.jsx)(s.code,{children:"require"})," or ",(0,t.jsx)(s.code,{children:"define"})," )."]}),"\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"after"})," means your transformers get run after TS ones, which gets transpiled syntax."]}),"\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"afterDeclarations"})," means your transformers get run during ",(0,t.jsx)(s.code,{children:"d.ts"})," generation phase, allowing you to transform output type declarations."]}),"\n"]}),"\n",(0,t.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,t.jsx)(s.h4,{id:"basic-transformers",children:"Basic Transformers"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n astTransformers: {\n before: ['my-custom-transformer'],\n },\n },\n },\n}\n"})}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "astTransformers": {\n "before": ["my-custom-transformer"]\n }\n }\n }\n }\n}\n'})}),"\n",(0,t.jsx)(s.h4,{id:"configuring-transformers-with-options",children:"Configuring transformers with options"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n astTransformers: {\n before: [\n {\n path: 'my-custom-transformer-that-needs-extra-opts',\n options: {}, // extra options to pass to transformers here\n },\n ],\n },\n },\n },\n}\n"})}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-json",children:'// OR package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "astTransformers": {\n "before": [\n {\n "path": "my-custom-transformer-that-needs-extra-opts",\n "options": {} // extra options to pass to transformers here\n }\n ]\n }\n }\n }\n }\n}\n'})}),"\n",(0,t.jsx)(s.h3,{id:"public-transformers",children:"Public transformers"}),"\n",(0,t.jsxs)(s.p,{children:[(0,t.jsx)(s.code,{children:"ts-jest"})," is able to expose transformers for public usage to provide the possibility to opt-in/out for users. Currently\nthe exposed transformers are:"]}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"path-mapping"})," convert alias import/export to relative import/export path base on ",(0,t.jsx)(s.code,{children:"paths"})," in ",(0,t.jsx)(s.code,{children:"tsconfig"}),".\nThis transformer works similar to ",(0,t.jsx)(s.code,{children:"moduleNameMapper"})," in ",(0,t.jsx)(s.code,{children:"jest.config.js"}),". When using this transformer, one might not need\n",(0,t.jsx)(s.code,{children:"moduleNameMapper"})," anymore."]}),"\n"]}),"\n",(0,t.jsx)(s.admonition,{type:"warning",children:(0,t.jsxs)(s.p,{children:[(0,t.jsx)(s.code,{children:"path-mapping"})," AST transformer is now deprecated. Please should use an alternative one like ",(0,t.jsx)(s.a,{href:"https://github.com/LeDDGroup/typescript-transform-paths",children:"https://github.com/LeDDGroup/typescript-transform-paths"})," instead."]})}),"\n",(0,t.jsx)(s.h4,{id:"example-of-opt-in-transformers",children:"Example of opt-in transformers"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n astTransformers: {\n before: ['ts-jest/dist/transformers/path-mapping'],\n },\n },\n },\n}\n"})}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "astTransformers": {\n "before": ["ts-jest/dist/transformers/path-mapping"]\n }\n }\n }\n }\n}\n'})}),"\n",(0,t.jsx)(s.h3,{id:"writing-custom-typescript-ast-transformers",children:"Writing custom TypeScript AST transformers"}),"\n",(0,t.jsxs)(s.p,{children:["To write a custom TypeScript AST transformers, one can take a look at ",(0,t.jsx)(s.a,{href:"https://github.com/kulshekhar/ts-jest/tree/main/src/transformers",children:"the one"})," that ",(0,t.jsx)(s.code,{children:"ts-jest"})," is using."]})]})}function p(e={}){const{wrapper:s}={...(0,o.R)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.jsx)(d,{...e})}):d(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>a,x:()=>i});var r=n(6540);const t={},o=r.createContext(t);function a(e){const s=r.useContext(o);return r.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function i(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:a(e.components),r.createElement(o.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9314],{4904:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>i,default:()=>p,frontMatter:()=>a,metadata:()=>r,toc:()=>l});const r=JSON.parse('{"id":"getting-started/options/astTransformers","title":"AST transformers option","description":"ts-jest by default does hoisting for a few jest methods via a TypeScript AST transformer. One can also create custom","source":"@site/versioned_docs/version-27.1/getting-started/options/astTransformers.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/astTransformers","permalink":"/ts-jest/docs/27.1/getting-started/options/astTransformers","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/options/astTransformers.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"AST transformers option"}}');var t=n(4848),o=n(8453);const a={title:"AST transformers option"},i=void 0,c={},l=[{value:"Examples",id:"examples",level:3},{value:"Basic Transformers",id:"basic-transformers",level:4},{value:"Configuring transformers with options",id:"configuring-transformers-with-options",level:4},{value:"Public transformers",id:"public-transformers",level:3},{value:"Example of opt-in transformers",id:"example-of-opt-in-transformers",level:4},{value:"Writing custom TypeScript AST transformers",id:"writing-custom-typescript-ast-transformers",level:3}];function d(e){const s={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(s.p,{children:[(0,t.jsx)(s.code,{children:"ts-jest"})," by default does hoisting for a few ",(0,t.jsx)(s.code,{children:"jest"})," methods via a TypeScript AST transformer. One can also create custom\nTypeScript AST transformers and provide them to ",(0,t.jsx)(s.code,{children:"ts-jest"})," to include into compilation process."]}),"\n",(0,t.jsxs)(s.p,{children:["The option is ",(0,t.jsx)(s.code,{children:"astTransformers"})," and it allows ones to specify which 3 types of TypeScript AST transformers to use with ",(0,t.jsx)(s.code,{children:"ts-jest"}),":"]}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"before"})," means your transformers get run before TS ones, which means your transformers will get raw TS syntax\ninstead of transpiled syntax (e.g ",(0,t.jsx)(s.code,{children:"import"})," instead of ",(0,t.jsx)(s.code,{children:"require"})," or ",(0,t.jsx)(s.code,{children:"define"})," )."]}),"\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"after"})," means your transformers get run after TS ones, which gets transpiled syntax."]}),"\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"afterDeclarations"})," means your transformers get run during ",(0,t.jsx)(s.code,{children:"d.ts"})," generation phase, allowing you to transform output type declarations."]}),"\n"]}),"\n",(0,t.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,t.jsx)(s.h4,{id:"basic-transformers",children:"Basic Transformers"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n astTransformers: {\n before: ['my-custom-transformer'],\n },\n },\n },\n}\n"})}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "astTransformers": {\n "before": ["my-custom-transformer"]\n }\n }\n }\n }\n}\n'})}),"\n",(0,t.jsx)(s.h4,{id:"configuring-transformers-with-options",children:"Configuring transformers with options"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n astTransformers: {\n before: [\n {\n path: 'my-custom-transformer-that-needs-extra-opts',\n options: {}, // extra options to pass to transformers here\n },\n ],\n },\n },\n },\n}\n"})}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-json",children:'// OR package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "astTransformers": {\n "before": [\n {\n "path": "my-custom-transformer-that-needs-extra-opts",\n "options": {} // extra options to pass to transformers here\n }\n ]\n }\n }\n }\n }\n}\n'})}),"\n",(0,t.jsx)(s.h3,{id:"public-transformers",children:"Public transformers"}),"\n",(0,t.jsxs)(s.p,{children:[(0,t.jsx)(s.code,{children:"ts-jest"})," is able to expose transformers for public usage to provide the possibility to opt-in/out for users. Currently\nthe exposed transformers are:"]}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"path-mapping"})," convert alias import/export to relative import/export path base on ",(0,t.jsx)(s.code,{children:"paths"})," in ",(0,t.jsx)(s.code,{children:"tsconfig"}),".\nThis transformer works similar to ",(0,t.jsx)(s.code,{children:"moduleNameMapper"})," in ",(0,t.jsx)(s.code,{children:"jest.config.js"}),". When using this transformer, one might not need\n",(0,t.jsx)(s.code,{children:"moduleNameMapper"})," anymore."]}),"\n"]}),"\n",(0,t.jsx)(s.admonition,{type:"warning",children:(0,t.jsxs)(s.p,{children:[(0,t.jsx)(s.code,{children:"path-mapping"})," AST transformer is now deprecated. Please should use an alternative one like ",(0,t.jsx)(s.a,{href:"https://github.com/LeDDGroup/typescript-transform-paths",children:"https://github.com/LeDDGroup/typescript-transform-paths"})," instead."]})}),"\n",(0,t.jsx)(s.h4,{id:"example-of-opt-in-transformers",children:"Example of opt-in transformers"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n astTransformers: {\n before: ['ts-jest/dist/transformers/path-mapping'],\n },\n },\n },\n}\n"})}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "astTransformers": {\n "before": ["ts-jest/dist/transformers/path-mapping"]\n }\n }\n }\n }\n}\n'})}),"\n",(0,t.jsx)(s.h3,{id:"writing-custom-typescript-ast-transformers",children:"Writing custom TypeScript AST transformers"}),"\n",(0,t.jsxs)(s.p,{children:["To write a custom TypeScript AST transformers, one can take a look at ",(0,t.jsx)(s.a,{href:"https://github.com/kulshekhar/ts-jest/tree/main/src/transformers",children:"the one"})," that ",(0,t.jsx)(s.code,{children:"ts-jest"})," is using."]})]})}function p(e={}){const{wrapper:s}={...(0,o.R)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.jsx)(d,{...e})}):d(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>a,x:()=>i});var r=n(6540);const t={},o=r.createContext(t);function a(e){const s=r.useContext(o);return r.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function i(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:a(e.components),r.createElement(o.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/d8357ecf.29f91670.js b/assets/js/d8357ecf.f1f3fca7.js similarity index 97% rename from assets/js/d8357ecf.29f91670.js rename to assets/js/d8357ecf.f1f3fca7.js index 637faaaad6..b1fdc330bb 100644 --- a/assets/js/d8357ecf.29f91670.js +++ b/assets/js/d8357ecf.f1f3fca7.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5580],{5145:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>c,contentTitle:()=>l,default:()=>a,frontMatter:()=>r,metadata:()=>n,toc:()=>p});const n=JSON.parse('{"id":"getting-started/options/compiler","title":"Compiler option","description":"The compiler option allows you to define the compiler to be used. It\'ll be used to load the NodeJS module holding the TypeScript compiler.","source":"@site/versioned_docs/version-27.1/getting-started/options/compiler.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/compiler","permalink":"/ts-jest/docs/27.1/getting-started/options/compiler","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/options/compiler.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Compiler option"}}');var s=o(4848),i=o(8453);const r={title:"Compiler option"},l=void 0,c={},p=[{value:"Example",id:"example",level:3}];function d(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["The ",(0,s.jsx)(t.code,{children:"compiler"})," option allows you to define the compiler to be used. It'll be used to load the NodeJS module holding the TypeScript compiler."]}),"\n",(0,s.jsxs)(t.p,{children:["The default value is ",(0,s.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,s.jsx)(t.a,{href:"https://www.npmjs.com/package/typescript",children:"TypeScript compiler module"}),".\nThe loaded version will depend on the one installed in your project."]}),"\n",(0,s.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,s.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,s.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n compiler: 'ttypescript',\n },\n },\n}\n"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "compiler": "ttypescript"\n }\n }\n }\n}\n'})})]})}function a(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}},8453:(e,t,o)=>{o.d(t,{R:()=>r,x:()=>l});var n=o(6540);const s={},i=n.createContext(s);function r(e){const t=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:r(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5580],{5145:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>c,contentTitle:()=>l,default:()=>a,frontMatter:()=>r,metadata:()=>n,toc:()=>p});const n=JSON.parse('{"id":"getting-started/options/compiler","title":"Compiler option","description":"The compiler option allows you to define the compiler to be used. It\'ll be used to load the NodeJS module holding the TypeScript compiler.","source":"@site/versioned_docs/version-27.1/getting-started/options/compiler.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/compiler","permalink":"/ts-jest/docs/27.1/getting-started/options/compiler","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/options/compiler.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Compiler option"}}');var s=o(4848),i=o(8453);const r={title:"Compiler option"},l=void 0,c={},p=[{value:"Example",id:"example",level:3}];function d(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["The ",(0,s.jsx)(t.code,{children:"compiler"})," option allows you to define the compiler to be used. It'll be used to load the NodeJS module holding the TypeScript compiler."]}),"\n",(0,s.jsxs)(t.p,{children:["The default value is ",(0,s.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,s.jsx)(t.a,{href:"https://www.npmjs.com/package/typescript",children:"TypeScript compiler module"}),".\nThe loaded version will depend on the one installed in your project."]}),"\n",(0,s.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,s.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,s.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n compiler: 'ttypescript',\n },\n },\n}\n"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "compiler": "ttypescript"\n }\n }\n }\n}\n'})})]})}function a(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}},8453:(e,t,o)=>{o.d(t,{R:()=>r,x:()=>l});var n=o(6540);const s={},i=n.createContext(s);function r(e){const t=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:r(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/d9f7da4b.16f670ec.js b/assets/js/d9f7da4b.d4b6ce02.js similarity index 97% rename from assets/js/d9f7da4b.16f670ec.js rename to assets/js/d9f7da4b.d4b6ce02.js index f0cd2d50d4..308adc92a9 100644 --- a/assets/js/d9f7da4b.16f670ec.js +++ b/assets/js/d9f7da4b.d4b6ce02.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6556],{7332:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/version-checking","title":"Version checking","description":"By default, ts-jest supports a range of versions for jest/typescript. One uses incompatible versions will receive a warning","source":"@site/versioned_docs/version-26.5/getting-started/version-checking.md","sourceDirName":"getting-started","slug":"/getting-started/version-checking","permalink":"/ts-jest/docs/26.5/getting-started/version-checking","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/getting-started/version-checking.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"version-checking","title":"Version checking"},"sidebar":"version-26.5-docs","previous":{"title":"Paths mapping","permalink":"/ts-jest/docs/26.5/getting-started/paths-mapping"},"next":{"title":"ESM Support","permalink":"/ts-jest/docs/26.5/guides/esm-support"}}');var i=n(4848),r=n(8453);const o={id:"version-checking",title:"Version checking"},c=void 0,a={},d=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["By default, ",(0,i.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,i.jsx)(t.code,{children:"jest"}),"/",(0,i.jsx)(t.code,{children:"typescript"}),". One uses incompatible versions will receive a warning\nmessage while running tests. This warning message can be opt-out by setting environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"export TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Windows"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,i.jsxs)(t.p,{children:["As long as the environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"})," stays, the warning message will no longer show.\nThis can lead to unexpected errors due to the usage of incompatible versions' dependencies. Use this environment variable with precautions."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>c});var s=n(6540);const i={},r=s.createContext(i);function o(e){const t=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6556],{7332:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/version-checking","title":"Version checking","description":"By default, ts-jest supports a range of versions for jest/typescript. One uses incompatible versions will receive a warning","source":"@site/versioned_docs/version-26.5/getting-started/version-checking.md","sourceDirName":"getting-started","slug":"/getting-started/version-checking","permalink":"/ts-jest/docs/26.5/getting-started/version-checking","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/getting-started/version-checking.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"version-checking","title":"Version checking"},"sidebar":"version-26.5-docs","previous":{"title":"Paths mapping","permalink":"/ts-jest/docs/26.5/getting-started/paths-mapping"},"next":{"title":"ESM Support","permalink":"/ts-jest/docs/26.5/guides/esm-support"}}');var i=n(4848),r=n(8453);const o={id:"version-checking",title:"Version checking"},c=void 0,a={},d=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["By default, ",(0,i.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,i.jsx)(t.code,{children:"jest"}),"/",(0,i.jsx)(t.code,{children:"typescript"}),". One uses incompatible versions will receive a warning\nmessage while running tests. This warning message can be opt-out by setting environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"export TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Windows"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,i.jsxs)(t.p,{children:["As long as the environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"})," stays, the warning message will no longer show.\nThis can lead to unexpected errors due to the usage of incompatible versions' dependencies. Use this environment variable with precautions."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>c});var s=n(6540);const i={},r=s.createContext(i);function o(e){const t=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/da431c38.1b5c02ee.js b/assets/js/da431c38.df55fcc1.js similarity index 99% rename from assets/js/da431c38.1b5c02ee.js rename to assets/js/da431c38.df55fcc1.js index 8ab63cb230..e1eaaf9107 100644 --- a/assets/js/da431c38.1b5c02ee.js +++ b/assets/js/da431c38.df55fcc1.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1952],{9319:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/installation","title":"Installation","description":"Dependencies","source":"@site/versioned_docs/version-29.0/getting-started/installation.md","sourceDirName":"getting-started","slug":"/getting-started/installation","permalink":"/ts-jest/docs/29.0/getting-started/installation","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/installation.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"installation","title":"Installation"},"sidebar":"version-29.0-docs","previous":{"title":"Contributing","permalink":"/ts-jest/docs/29.0/contributing"},"next":{"title":"Presets","permalink":"/ts-jest/docs/29.0/getting-started/presets"}}');var r=n(4848),a=n(8453),i=n(9489),l=n(7227);const o={id:"installation",title:"Installation"},c=void 0,u={},d=[{value:"Dependencies",id:"dependencies",level:3},{value:"Jest config file",id:"jest-config-file",level:3},{value:"Creating",id:"creating",level:4},{value:"Customizing",id:"customizing",level:4}];function h(e){const t={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,r.jsxs)(t.p,{children:["You can install ",(0,r.jsx)(t.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,r.jsxs)(i.A,{groupId:"npm2yarn",children:[(0,r.jsx)(l.A,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})})}),(0,r.jsx)(l.A,{value:"yarn",label:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})})}),(0,r.jsx)(l.A,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"pnpm add --save-dev jest typescript ts-jest @types/jest\n"})})})]}),"\n",(0,r.jsx)(t.admonition,{type:"tip",children:(0,r.jsxs)(t.p,{children:["Tip: If you get an error with the following ",(0,r.jsx)(t.code,{children:"npm"})," commands such as ",(0,r.jsx)(t.code,{children:"npx: command not found"}),", you can replace ",(0,r.jsx)(t.code,{children:"npx XXX"})," with ",(0,r.jsx)(t.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,r.jsx)(t.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,r.jsx)(t.h4,{id:"creating",children:"Creating"}),"\n",(0,r.jsxs)(t.p,{children:["By default, Jest can run without any config files, but it will not compile ",(0,r.jsx)(t.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,r.jsx)(t.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,r.jsx)(t.code,{children:"ts-jest"})," preset."]}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,r.jsxs)(i.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-npm",metastring:"tab",children:"npx ts-jest config:init\n"})})}),(0,r.jsx)(l.A,{value:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-Yarn",metastring:"tab",children:"yarn ts-jest config:init\n"})})})]}),"\n",(0,r.jsxs)(t.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,r.jsx)(t.code,{children:".ts"})," files correctly."]}),"\n",(0,r.jsxs)(t.p,{children:["You can also use the ",(0,r.jsx)(t.code,{children:"jest --init"})," command (prefixed with either ",(0,r.jsx)(t.code,{children:"npx"})," or ",(0,r.jsx)(t.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,r.jsx)(t.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,r.jsx)(t.code,{children:'preset: "ts-jest"'})," to the ",(0,r.jsx)(t.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,r.jsx)(t.h4,{id:"customizing",children:"Customizing"}),"\n",(0,r.jsxs)(t.p,{children:["For customizing jest, please follow their ",(0,r.jsx)(t.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"ts-jest"})," specific options can be found ",(0,r.jsx)(t.a,{href:"/ts-jest/docs/29.0/getting-started/options",children:"here"}),"."]})]})}function p(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>i});n(6540);var s=n(4164);const r={tabItem:"tabItem_Ymn6"};var a=n(4848);function i(e){let{children:t,hidden:n,className:i}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,s.A)(r.tabItem,i),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),r=n(4164),a=n(4245),i=n(6347),l=n(6494),o=n(2814),c=n(5167),u=n(9900);function d(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:r}}=e;return{value:t,label:n,attributes:s,default:r}}))}(n);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const r=(0,i.W6)(),a=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,o.aZ)(a),(0,s.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function m(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,a=h(e),[i,o]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:a}))),[c,d]=f({queryString:n,groupId:r}),[m,j]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,u.Dv)(n);return[r,(0,s.useCallback)((e=>{n&&a.set(e)}),[n,a])]}({groupId:r}),g=(()=>{const e=c??m;return p({value:e,tabValues:a})?e:null})();(0,l.A)((()=>{g&&o(g)}),[g]);return{selectedValue:i,selectValue:(0,s.useCallback)((e=>{if(!p({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);o(e),d(e),j(e)}),[d,j,a]),tabValues:a}}var j=n(1062);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=n(4848);function x(e){let{className:t,block:n,selectedValue:s,selectValue:i,tabValues:l}=e;const o=[],{blockElementScrollPositionUntilNextRender:c}=(0,a.a_)(),u=e=>{const t=e.currentTarget,n=o.indexOf(t),r=l[n].value;r!==s&&(c(t),i(r))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=o.indexOf(e.currentTarget)+1;t=o[n]??o[0];break}case"ArrowLeft":{const n=o.indexOf(e.currentTarget)-1;t=o[n]??o[o.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:a}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>o.push(e),onKeyDown:d,onClick:u,...a,className:(0,r.A)("tabs__item",g.tabItem,a?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:a}=e;const i=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=i.find((e=>e.props.value===a));return e?(0,s.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:i.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=m(e);return(0,b.jsxs)("div",{className:(0,r.A)("tabs-container",g.tabList),children:[(0,b.jsx)(x,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function w(e){const t=(0,j.A)();return(0,b.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>i,x:()=>l});var s=n(6540);const r={},a=s.createContext(r);function i(e){const t=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),s.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1952],{9319:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/installation","title":"Installation","description":"Dependencies","source":"@site/versioned_docs/version-29.0/getting-started/installation.md","sourceDirName":"getting-started","slug":"/getting-started/installation","permalink":"/ts-jest/docs/29.0/getting-started/installation","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/installation.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"installation","title":"Installation"},"sidebar":"version-29.0-docs","previous":{"title":"Contributing","permalink":"/ts-jest/docs/29.0/contributing"},"next":{"title":"Presets","permalink":"/ts-jest/docs/29.0/getting-started/presets"}}');var r=n(4848),a=n(8453),i=n(9489),l=n(7227);const o={id:"installation",title:"Installation"},c=void 0,u={},d=[{value:"Dependencies",id:"dependencies",level:3},{value:"Jest config file",id:"jest-config-file",level:3},{value:"Creating",id:"creating",level:4},{value:"Customizing",id:"customizing",level:4}];function h(e){const t={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,r.jsxs)(t.p,{children:["You can install ",(0,r.jsx)(t.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,r.jsxs)(i.A,{groupId:"npm2yarn",children:[(0,r.jsx)(l.A,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})})}),(0,r.jsx)(l.A,{value:"yarn",label:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})})}),(0,r.jsx)(l.A,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"pnpm add --save-dev jest typescript ts-jest @types/jest\n"})})})]}),"\n",(0,r.jsx)(t.admonition,{type:"tip",children:(0,r.jsxs)(t.p,{children:["Tip: If you get an error with the following ",(0,r.jsx)(t.code,{children:"npm"})," commands such as ",(0,r.jsx)(t.code,{children:"npx: command not found"}),", you can replace ",(0,r.jsx)(t.code,{children:"npx XXX"})," with ",(0,r.jsx)(t.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,r.jsx)(t.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,r.jsx)(t.h4,{id:"creating",children:"Creating"}),"\n",(0,r.jsxs)(t.p,{children:["By default, Jest can run without any config files, but it will not compile ",(0,r.jsx)(t.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,r.jsx)(t.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,r.jsx)(t.code,{children:"ts-jest"})," preset."]}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,r.jsxs)(i.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-npm",metastring:"tab",children:"npx ts-jest config:init\n"})})}),(0,r.jsx)(l.A,{value:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-Yarn",metastring:"tab",children:"yarn ts-jest config:init\n"})})})]}),"\n",(0,r.jsxs)(t.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,r.jsx)(t.code,{children:".ts"})," files correctly."]}),"\n",(0,r.jsxs)(t.p,{children:["You can also use the ",(0,r.jsx)(t.code,{children:"jest --init"})," command (prefixed with either ",(0,r.jsx)(t.code,{children:"npx"})," or ",(0,r.jsx)(t.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,r.jsx)(t.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,r.jsx)(t.code,{children:'preset: "ts-jest"'})," to the ",(0,r.jsx)(t.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,r.jsx)(t.h4,{id:"customizing",children:"Customizing"}),"\n",(0,r.jsxs)(t.p,{children:["For customizing jest, please follow their ",(0,r.jsx)(t.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"ts-jest"})," specific options can be found ",(0,r.jsx)(t.a,{href:"/ts-jest/docs/29.0/getting-started/options",children:"here"}),"."]})]})}function p(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>i});n(6540);var s=n(4164);const r={tabItem:"tabItem_Ymn6"};var a=n(4848);function i(e){let{children:t,hidden:n,className:i}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,s.A)(r.tabItem,i),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),r=n(4164),a=n(4245),i=n(6347),l=n(6494),o=n(2814),c=n(5167),u=n(9900);function d(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:r}}=e;return{value:t,label:n,attributes:s,default:r}}))}(n);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const r=(0,i.W6)(),a=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,o.aZ)(a),(0,s.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function m(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,a=h(e),[i,o]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:a}))),[c,d]=f({queryString:n,groupId:r}),[m,j]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,u.Dv)(n);return[r,(0,s.useCallback)((e=>{n&&a.set(e)}),[n,a])]}({groupId:r}),g=(()=>{const e=c??m;return p({value:e,tabValues:a})?e:null})();(0,l.A)((()=>{g&&o(g)}),[g]);return{selectedValue:i,selectValue:(0,s.useCallback)((e=>{if(!p({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);o(e),d(e),j(e)}),[d,j,a]),tabValues:a}}var j=n(1062);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=n(4848);function x(e){let{className:t,block:n,selectedValue:s,selectValue:i,tabValues:l}=e;const o=[],{blockElementScrollPositionUntilNextRender:c}=(0,a.a_)(),u=e=>{const t=e.currentTarget,n=o.indexOf(t),r=l[n].value;r!==s&&(c(t),i(r))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=o.indexOf(e.currentTarget)+1;t=o[n]??o[0];break}case"ArrowLeft":{const n=o.indexOf(e.currentTarget)-1;t=o[n]??o[o.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:a}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>o.push(e),onKeyDown:d,onClick:u,...a,className:(0,r.A)("tabs__item",g.tabItem,a?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:a}=e;const i=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=i.find((e=>e.props.value===a));return e?(0,s.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:i.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=m(e);return(0,b.jsxs)("div",{className:(0,r.A)("tabs-container",g.tabList),children:[(0,b.jsx)(x,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function w(e){const t=(0,j.A)();return(0,b.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>i,x:()=>l});var s=n(6540);const r={},a=s.createContext(r);function i(e){const t=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),s.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/dabdf990.2836a489.js b/assets/js/dabdf990.47a863fa.js similarity index 97% rename from assets/js/dabdf990.2836a489.js rename to assets/js/dabdf990.47a863fa.js index 7b3459b4e8..4776547232 100644 --- a/assets/js/dabdf990.2836a489.js +++ b/assets/js/dabdf990.47a863fa.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3808],{5504:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>c,contentTitle:()=>l,default:()=>a,frontMatter:()=>r,metadata:()=>n,toc:()=>p});const n=JSON.parse('{"id":"getting-started/options/compiler","title":"Compiler option","description":"The compiler option allows you to define the compiler to be used. It\'ll be used to load the NodeJS module holding the TypeScript compiler.","source":"@site/versioned_docs/version-28.0/getting-started/options/compiler.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/compiler","permalink":"/ts-jest/docs/28.0/getting-started/options/compiler","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/options/compiler.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Compiler option"}}');var s=o(4848),i=o(8453);const r={title:"Compiler option"},l=void 0,c={},p=[{value:"Example",id:"example",level:3}];function d(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["The ",(0,s.jsx)(t.code,{children:"compiler"})," option allows you to define the compiler to be used. It'll be used to load the NodeJS module holding the TypeScript compiler."]}),"\n",(0,s.jsxs)(t.p,{children:["The default value is ",(0,s.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,s.jsx)(t.a,{href:"https://www.npmjs.com/package/typescript",children:"TypeScript compiler module"}),".\nThe loaded version will depend on the one installed in your project."]}),"\n",(0,s.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,s.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,s.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n compiler: 'ttypescript',\n },\n },\n}\n"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "compiler": "ttypescript"\n }\n }\n }\n}\n'})})]})}function a(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}},8453:(e,t,o)=>{o.d(t,{R:()=>r,x:()=>l});var n=o(6540);const s={},i=n.createContext(s);function r(e){const t=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:r(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3808],{5504:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>c,contentTitle:()=>l,default:()=>a,frontMatter:()=>r,metadata:()=>n,toc:()=>p});const n=JSON.parse('{"id":"getting-started/options/compiler","title":"Compiler option","description":"The compiler option allows you to define the compiler to be used. It\'ll be used to load the NodeJS module holding the TypeScript compiler.","source":"@site/versioned_docs/version-28.0/getting-started/options/compiler.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/compiler","permalink":"/ts-jest/docs/28.0/getting-started/options/compiler","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/options/compiler.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Compiler option"}}');var s=o(4848),i=o(8453);const r={title:"Compiler option"},l=void 0,c={},p=[{value:"Example",id:"example",level:3}];function d(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["The ",(0,s.jsx)(t.code,{children:"compiler"})," option allows you to define the compiler to be used. It'll be used to load the NodeJS module holding the TypeScript compiler."]}),"\n",(0,s.jsxs)(t.p,{children:["The default value is ",(0,s.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,s.jsx)(t.a,{href:"https://www.npmjs.com/package/typescript",children:"TypeScript compiler module"}),".\nThe loaded version will depend on the one installed in your project."]}),"\n",(0,s.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,s.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,s.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n compiler: 'ttypescript',\n },\n },\n}\n"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "compiler": "ttypescript"\n }\n }\n }\n}\n'})})]})}function a(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}},8453:(e,t,o)=>{o.d(t,{R:()=>r,x:()=>l});var n=o(6540);const s={},i=n.createContext(s);function r(e){const t=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:r(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/db49ae54.98f92ebe.js b/assets/js/db49ae54.6c64bd98.js similarity index 98% rename from assets/js/db49ae54.98f92ebe.js rename to assets/js/db49ae54.6c64bd98.js index fc90984e66..f349dfb889 100644 --- a/assets/js/db49ae54.98f92ebe.js +++ b/assets/js/db49ae54.6c64bd98.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9197],{6340:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>a,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>t,toc:()=>l});const t=JSON.parse('{"id":"guides/mock-es6-class","title":"Mock ES6 class","description":"TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.","source":"@site/versioned_docs/version-26.5/guides/mock-es6-class.md","sourceDirName":"guides","slug":"/guides/mock-es6-class","permalink":"/ts-jest/docs/26.5/guides/mock-es6-class","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/guides/mock-es6-class.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"mock-es6-class","title":"Mock ES6 class"},"sidebar":"version-26.5-docs","previous":{"title":"ESM Support","permalink":"/ts-jest/docs/26.5/guides/esm-support"},"next":{"title":"Using with React Native","permalink":"/ts-jest/docs/26.5/guides/react-native"}}');var o=n(4848),r=n(8453);const i={id:"mock-es6-class",title:"Mock ES6 class"},c=void 0,a={},l=[];function d(e){const s={code:"code",p:"p",pre:"pre",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(s.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,o.jsx)(s.code,{children:"const soundPlayer = require('./sound-player')"}),". Therefore creating an instance of the class that was exported as\na default will look like this: ",(0,o.jsx)(s.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"jest.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\n })\n})\n"})}),"\n",(0,o.jsx)(s.p,{children:"You will get the error"}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,o.jsxs)(s.p,{children:["because ",(0,o.jsx)(s.code,{children:"soundPlayer.default"})," does not point to a function. Your mock has to return an object which has a property default\nthat points to a function."]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"jest.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\n }\n }),\n }\n})\n"})}),"\n",(0,o.jsxs)(s.p,{children:["For named imports, like ",(0,o.jsx)(s.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,o.jsx)(s.code,{children:"default"})," with imported module name, ",(0,o.jsx)(s.code,{children:"OAuth2"})," in this example:"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"jest.mock('./oauth', () => {\n return {\n OAuth2: ... // mock here\n }\n})\n"})})]})}function u(e={}){const{wrapper:s}={...(0,r.R)(),...e.components};return s?(0,o.jsx)(s,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>i,x:()=>c});var t=n(6540);const o={},r=t.createContext(o);function i(e){const s=t.useContext(r);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function c(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),t.createElement(r.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9197],{6340:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>a,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>t,toc:()=>l});const t=JSON.parse('{"id":"guides/mock-es6-class","title":"Mock ES6 class","description":"TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.","source":"@site/versioned_docs/version-26.5/guides/mock-es6-class.md","sourceDirName":"guides","slug":"/guides/mock-es6-class","permalink":"/ts-jest/docs/26.5/guides/mock-es6-class","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/guides/mock-es6-class.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"mock-es6-class","title":"Mock ES6 class"},"sidebar":"version-26.5-docs","previous":{"title":"ESM Support","permalink":"/ts-jest/docs/26.5/guides/esm-support"},"next":{"title":"Using with React Native","permalink":"/ts-jest/docs/26.5/guides/react-native"}}');var o=n(4848),r=n(8453);const i={id:"mock-es6-class",title:"Mock ES6 class"},c=void 0,a={},l=[];function d(e){const s={code:"code",p:"p",pre:"pre",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(s.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,o.jsx)(s.code,{children:"const soundPlayer = require('./sound-player')"}),". Therefore creating an instance of the class that was exported as\na default will look like this: ",(0,o.jsx)(s.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"jest.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\n })\n})\n"})}),"\n",(0,o.jsx)(s.p,{children:"You will get the error"}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,o.jsxs)(s.p,{children:["because ",(0,o.jsx)(s.code,{children:"soundPlayer.default"})," does not point to a function. Your mock has to return an object which has a property default\nthat points to a function."]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"jest.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\n }\n }),\n }\n})\n"})}),"\n",(0,o.jsxs)(s.p,{children:["For named imports, like ",(0,o.jsx)(s.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,o.jsx)(s.code,{children:"default"})," with imported module name, ",(0,o.jsx)(s.code,{children:"OAuth2"})," in this example:"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-js",children:"jest.mock('./oauth', () => {\n return {\n OAuth2: ... // mock here\n }\n})\n"})})]})}function u(e={}){const{wrapper:s}={...(0,r.R)(),...e.components};return s?(0,o.jsx)(s,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>i,x:()=>c});var t=n(6540);const o={},r=t.createContext(o);function i(e){const s=t.useContext(r);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function c(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),t.createElement(r.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/db795cf2.039b2323.js b/assets/js/db795cf2.3fa12001.js similarity index 97% rename from assets/js/db795cf2.039b2323.js rename to assets/js/db795cf2.3fa12001.js index e3c1a6568e..ac54a19069 100644 --- a/assets/js/db795cf2.039b2323.js +++ b/assets/js/db795cf2.3fa12001.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5369],{1382:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>c,default:()=>u,frontMatter:()=>r,metadata:()=>s,toc:()=>g});const s=JSON.parse('{"id":"debugging","title":"Debugging ts-jest","description":"You can activate the debug logger by setting the environment variable TSJESTLOG before running tests.","source":"@site/versioned_docs/version-27.1/debugging.md","sourceDirName":".","slug":"/debugging","permalink":"/ts-jest/docs/27.1/debugging","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/debugging.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"debugging","title":"Debugging ts-jest"},"sidebar":"version-27.1-docs","previous":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/27.1/migration"}}');var o=n(4848),i=n(8453);const r={id:"debugging",title:"Debugging ts-jest"},c=void 0,d={},g=[];function l(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["You can activate the debug logger by setting the environment variable ",(0,o.jsx)(t.code,{children:"TS_JEST_LOG"})," before running tests.\nThe output of the logger will be in ",(0,o.jsx)(t.strong,{children:"ts-jest.log"})," in current working directory."]}),"\n",(0,o.jsxs)(t.p,{children:["The debug logger contains some useful information about how internal ",(0,o.jsx)(t.code,{children:"ts-jest"})," works, including which files are processed,\nwhich Jest config or TypeScript config is used etc."]}),"\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{children:"export TS_JEST_LOG=ts-jest.log\n"})}),"\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.strong,{children:"Windows"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{children:"set TS_JEST_LOG=ts-jest.log\n"})})]})}function u(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>c});var s=n(6540);const o={},i=s.createContext(o);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5369],{1382:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>c,default:()=>u,frontMatter:()=>r,metadata:()=>s,toc:()=>g});const s=JSON.parse('{"id":"debugging","title":"Debugging ts-jest","description":"You can activate the debug logger by setting the environment variable TSJESTLOG before running tests.","source":"@site/versioned_docs/version-27.1/debugging.md","sourceDirName":".","slug":"/debugging","permalink":"/ts-jest/docs/27.1/debugging","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/debugging.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"debugging","title":"Debugging ts-jest"},"sidebar":"version-27.1-docs","previous":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/27.1/migration"}}');var o=n(4848),i=n(8453);const r={id:"debugging",title:"Debugging ts-jest"},c=void 0,d={},g=[];function l(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["You can activate the debug logger by setting the environment variable ",(0,o.jsx)(t.code,{children:"TS_JEST_LOG"})," before running tests.\nThe output of the logger will be in ",(0,o.jsx)(t.strong,{children:"ts-jest.log"})," in current working directory."]}),"\n",(0,o.jsxs)(t.p,{children:["The debug logger contains some useful information about how internal ",(0,o.jsx)(t.code,{children:"ts-jest"})," works, including which files are processed,\nwhich Jest config or TypeScript config is used etc."]}),"\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{children:"export TS_JEST_LOG=ts-jest.log\n"})}),"\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.strong,{children:"Windows"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{children:"set TS_JEST_LOG=ts-jest.log\n"})})]})}function u(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>c});var s=n(6540);const o={},i=s.createContext(o);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/dcbdd84f.b89413b1.js b/assets/js/dcbdd84f.cd175312.js similarity index 97% rename from assets/js/dcbdd84f.b89413b1.js rename to assets/js/dcbdd84f.cd175312.js index 5115546564..331c92199c 100644 --- a/assets/js/dcbdd84f.b89413b1.js +++ b/assets/js/dcbdd84f.cd175312.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4716],{8885:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>c,default:()=>u,frontMatter:()=>r,metadata:()=>s,toc:()=>g});const s=JSON.parse('{"id":"debugging","title":"Debugging ts-jest","description":"You can activate the debug logger by setting the environment variable TSJESTLOG before running tests.","source":"@site/versioned_docs/version-26.5/debugging.md","sourceDirName":".","slug":"/debugging","permalink":"/ts-jest/docs/26.5/debugging","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/debugging.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"debugging","title":"Debugging ts-jest"},"sidebar":"version-26.5-docs","previous":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/26.5/migration"}}');var o=n(4848),i=n(8453);const r={id:"debugging",title:"Debugging ts-jest"},c=void 0,d={},g=[];function l(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["You can activate the debug logger by setting the environment variable ",(0,o.jsx)(t.code,{children:"TS_JEST_LOG"})," before running tests.\nThe output of the logger will be in ",(0,o.jsx)(t.strong,{children:"ts-jest.log"})," in current working directory."]}),"\n",(0,o.jsxs)(t.p,{children:["The debug logger contains some useful information about how internal ",(0,o.jsx)(t.code,{children:"ts-jest"})," works, including which files are processed,\nwhich Jest config or TypeScript config is used etc."]}),"\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{children:"export TS_JEST_LOG=ts-jest.log\n"})}),"\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.strong,{children:"Windows"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{children:"set TS_JEST_LOG=ts-jest.log\n"})})]})}function u(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>c});var s=n(6540);const o={},i=s.createContext(o);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4716],{8885:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>c,default:()=>u,frontMatter:()=>r,metadata:()=>s,toc:()=>g});const s=JSON.parse('{"id":"debugging","title":"Debugging ts-jest","description":"You can activate the debug logger by setting the environment variable TSJESTLOG before running tests.","source":"@site/versioned_docs/version-26.5/debugging.md","sourceDirName":".","slug":"/debugging","permalink":"/ts-jest/docs/26.5/debugging","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/debugging.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"debugging","title":"Debugging ts-jest"},"sidebar":"version-26.5-docs","previous":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/26.5/migration"}}');var o=n(4848),i=n(8453);const r={id:"debugging",title:"Debugging ts-jest"},c=void 0,d={},g=[];function l(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["You can activate the debug logger by setting the environment variable ",(0,o.jsx)(t.code,{children:"TS_JEST_LOG"})," before running tests.\nThe output of the logger will be in ",(0,o.jsx)(t.strong,{children:"ts-jest.log"})," in current working directory."]}),"\n",(0,o.jsxs)(t.p,{children:["The debug logger contains some useful information about how internal ",(0,o.jsx)(t.code,{children:"ts-jest"})," works, including which files are processed,\nwhich Jest config or TypeScript config is used etc."]}),"\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{children:"export TS_JEST_LOG=ts-jest.log\n"})}),"\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.strong,{children:"Windows"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{children:"set TS_JEST_LOG=ts-jest.log\n"})})]})}function u(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>c});var s=n(6540);const o={},i=s.createContext(o);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/e3a856ae.e046cbac.js b/assets/js/e3a856ae.f4179db3.js similarity index 98% rename from assets/js/e3a856ae.e046cbac.js rename to assets/js/e3a856ae.f4179db3.js index 4c805142b4..e494aa02a0 100644 --- a/assets/js/e3a856ae.e046cbac.js +++ b/assets/js/e3a856ae.f4179db3.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6771],{6807:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>p,frontMatter:()=>c,metadata:()=>n,toc:()=>l});const n=JSON.parse('{"id":"guides/react-native","title":"Using with React Native","description":"To use ts-jest with React Native + TypeScript and Babel 7, you\'ll first need to follow this tutorial.","source":"@site/versioned_docs/version-27.1/guides/react-native.md","sourceDirName":"guides","slug":"/guides/react-native","permalink":"/ts-jest/docs/27.1/guides/react-native","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/guides/react-native.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"react-native","title":"Using with React Native"},"sidebar":"version-27.1-docs","previous":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/27.1/guides/mock-es6-class"},"next":{"title":"Test helpers","permalink":"/ts-jest/docs/27.1/guides/test-helpers"}}');var i=s(4848),o=s(8453);const c={id:"react-native",title:"Using with React Native"},r=void 0,a={},l=[{value:"Babel config",id:"babel-config",level:3},{value:"TypeScript Configuration",id:"typescript-configuration",level:3},{value:"Jest config",id:"jest-config",level:3}];function d(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["To use ",(0,i.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,i.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,i.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,i.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,i.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,i.jsx)(t.code,{children:".babelrc"})," to ",(0,i.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"// babel.config.js\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n"})}),"\n",(0,i.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,i.jsxs)(t.p,{children:["Create a new ",(0,i.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-json",children:'// tsconfig.spec.json\n{\n "extends": "./tsconfig.json",\n "compilerOptions": {\n "jsx": "react"\n }\n}\n'})}),"\n",(0,i.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,i.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,i.jsx)(t.code,{children:"jest"})," key of ",(0,i.jsx)(t.code,{children:"package.json"})," to ",(0,i.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n\nmodule.exports = {\n preset: 'react-native',\n globals: {\n 'ts-jest': {\n tsconfig: 'tsconfig.spec.json',\n },\n },\n transform: {\n '^.+\\\\.jsx$': 'babel-jest',\n '^.+\\\\.tsx?$': 'ts-jest',\n },\n moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],\n}\n"})})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>c,x:()=>r});var n=s(6540);const i={},o=n.createContext(i);function c(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:c(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6771],{6807:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>p,frontMatter:()=>c,metadata:()=>n,toc:()=>l});const n=JSON.parse('{"id":"guides/react-native","title":"Using with React Native","description":"To use ts-jest with React Native + TypeScript and Babel 7, you\'ll first need to follow this tutorial.","source":"@site/versioned_docs/version-27.1/guides/react-native.md","sourceDirName":"guides","slug":"/guides/react-native","permalink":"/ts-jest/docs/27.1/guides/react-native","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/guides/react-native.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"react-native","title":"Using with React Native"},"sidebar":"version-27.1-docs","previous":{"title":"Mock ES6 class","permalink":"/ts-jest/docs/27.1/guides/mock-es6-class"},"next":{"title":"Test helpers","permalink":"/ts-jest/docs/27.1/guides/test-helpers"}}');var i=s(4848),o=s(8453);const c={id:"react-native",title:"Using with React Native"},r=void 0,a={},l=[{value:"Babel config",id:"babel-config",level:3},{value:"TypeScript Configuration",id:"typescript-configuration",level:3},{value:"Jest config",id:"jest-config",level:3}];function d(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["To use ",(0,i.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,i.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,i.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,i.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,i.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,i.jsx)(t.code,{children:".babelrc"})," to ",(0,i.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"// babel.config.js\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n"})}),"\n",(0,i.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,i.jsxs)(t.p,{children:["Create a new ",(0,i.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-json",children:'// tsconfig.spec.json\n{\n "extends": "./tsconfig.json",\n "compilerOptions": {\n "jsx": "react"\n }\n}\n'})}),"\n",(0,i.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,i.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,i.jsx)(t.code,{children:"jest"})," key of ",(0,i.jsx)(t.code,{children:"package.json"})," to ",(0,i.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n\nmodule.exports = {\n preset: 'react-native',\n globals: {\n 'ts-jest': {\n tsconfig: 'tsconfig.spec.json',\n },\n },\n transform: {\n '^.+\\\\.jsx$': 'babel-jest',\n '^.+\\\\.tsx?$': 'ts-jest',\n },\n moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],\n}\n"})})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>c,x:()=>r});var n=s(6540);const i={},o=n.createContext(i);function c(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:c(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/e5e34c6b.34d2aa10.js b/assets/js/e5e34c6b.83cffe15.js similarity index 97% rename from assets/js/e5e34c6b.34d2aa10.js rename to assets/js/e5e34c6b.83cffe15.js index 00bb274601..c92e6da787 100644 --- a/assets/js/e5e34c6b.34d2aa10.js +++ b/assets/js/e5e34c6b.83cffe15.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4218],{4437:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/version-checking","title":"Version checking","description":"By default, ts-jest supports a range of versions for jest/typescript. One uses incompatible versions will receive a warning","source":"@site/docs/getting-started/version-checking.md","sourceDirName":"getting-started","slug":"/getting-started/version-checking","permalink":"/ts-jest/docs/next/getting-started/version-checking","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/version-checking.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"version-checking","title":"Version checking"},"sidebar":"docs","previous":{"title":"Paths mapping","permalink":"/ts-jest/docs/next/getting-started/paths-mapping"},"next":{"title":"ESM Support","permalink":"/ts-jest/docs/next/guides/esm-support"}}');var i=n(4848),r=n(8453);const o={id:"version-checking",title:"Version checking"},c=void 0,a={},d=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["By default, ",(0,i.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,i.jsx)(t.code,{children:"jest"}),"/",(0,i.jsx)(t.code,{children:"typescript"}),". One uses incompatible versions will receive a warning\nmessage while running tests. This warning message can be opt-out by setting environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"export TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Windows"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,i.jsxs)(t.p,{children:["As long as the environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"})," stays, the warning message will no longer show.\nThis can lead to unexpected errors due to the usage of incompatible versions' dependencies. Use this environment variable with precautions."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>c});var s=n(6540);const i={},r=s.createContext(i);function o(e){const t=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4218],{4437:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/version-checking","title":"Version checking","description":"By default, ts-jest supports a range of versions for jest/typescript. One uses incompatible versions will receive a warning","source":"@site/docs/getting-started/version-checking.md","sourceDirName":"getting-started","slug":"/getting-started/version-checking","permalink":"/ts-jest/docs/next/getting-started/version-checking","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/version-checking.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"version-checking","title":"Version checking"},"sidebar":"docs","previous":{"title":"Paths mapping","permalink":"/ts-jest/docs/next/getting-started/paths-mapping"},"next":{"title":"ESM Support","permalink":"/ts-jest/docs/next/guides/esm-support"}}');var i=n(4848),r=n(8453);const o={id:"version-checking",title:"Version checking"},c=void 0,a={},d=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["By default, ",(0,i.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,i.jsx)(t.code,{children:"jest"}),"/",(0,i.jsx)(t.code,{children:"typescript"}),". One uses incompatible versions will receive a warning\nmessage while running tests. This warning message can be opt-out by setting environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"export TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Windows"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,i.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,i.jsxs)(t.p,{children:["As long as the environment variable ",(0,i.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"})," stays, the warning message will no longer show.\nThis can lead to unexpected errors due to the usage of incompatible versions' dependencies. Use this environment variable with precautions."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>c});var s=n(6540);const i={},r=s.createContext(i);function o(e){const t=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/e8085380.1ce58536.js b/assets/js/e8085380.3c65ab32.js similarity index 99% rename from assets/js/e8085380.1ce58536.js rename to assets/js/e8085380.3c65ab32.js index 954be29d8b..e1677083b9 100644 --- a/assets/js/e8085380.1ce58536.js +++ b/assets/js/e8085380.3c65ab32.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3284],{3330:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>l,metadata:()=>i,toc:()=>d});const i=JSON.parse('{"id":"getting-started/options/diagnostics","title":"Diagnostics option","description":"The diagnostics option configures error reporting.","source":"@site/versioned_docs/version-28.0/getting-started/options/diagnostics.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/diagnostics","permalink":"/ts-jest/docs/28.0/getting-started/options/diagnostics","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/options/diagnostics.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Diagnostics option"}}');var o=s(4848),t=s(8453);const l={title:"Diagnostics option"},r=void 0,c={},d=[{value:"Disabling/enabling",id:"disablingenabling",level:3},{value:"Advanced configuration",id:"advanced-configuration",level:3},{value:"Examples",id:"examples",level:3},{value:"Disabling diagnostics",id:"disabling-diagnostics",level:4},{value:"Advanced options",id:"advanced-options",level:4},{value:"Enabling diagnostics for test files only",id:"enabling-diagnostics-for-test-files-only",level:5},{value:"Do not fail on first error",id:"do-not-fail-on-first-error",level:5},{value:"Ignoring some error codes",id:"ignoring-some-error-codes",level:5}];function a(e){const n={a:"a",code:"code",em:"em",h3:"h3",h4:"h4",h5:"h5",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,t.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:["The ",(0,o.jsx)(n.code,{children:"diagnostics"})," option configures error reporting.\nIt can both be enabled/disabled entirely or limited to a specific type of errors and/or files."]}),"\n",(0,o.jsxs)(n.p,{children:["If a diagnostic is not filtered out, ",(0,o.jsx)(n.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,o.jsx)(n.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,o.jsxs)(n.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,o.jsx)(n.code,{children:"diagnostics"})," option to ",(0,o.jsx)(n.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,o.jsx)(n.code,{children:"diagnostics"})," to ",(0,o.jsx)(n.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,o.jsx)(n.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,o.jsxs)(n.p,{children:["The ",(0,o.jsx)(n.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"warnOnly"})}),": If specified and ",(0,o.jsx)(n.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,o.jsx)(n.em,{children:"disabled"}),")."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,o.jsx)(n.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". By default here are the ones ignored:","\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"6059"}),": ",(0,o.jsx)(n.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"18002"}),": ",(0,o.jsx)(n.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"18003"}),": ",(0,o.jsx)(n.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,o.jsx)(n.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,o.jsx)(n.code,{children:"tsconfig"})," option ",(0,o.jsx)(n.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,o.jsx)(n.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,o.jsx)(n.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,o.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsx)(n.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: false,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": false\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,o.jsx)(n.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,o.jsxs)(n.p,{children:["Assuming all your test files ends with ",(0,o.jsx)(n.code,{children:".spec.ts"})," or ",(0,o.jsx)(n.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: {\n exclude: ['!**/*.(spec|test).ts'],\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": {\n "exclude": ["!**/*.(spec|test).ts"]\n }\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,o.jsxs)(n.p,{children:["While some diagnostics are stop-blockers for the compilation, most of them are not. If you want the compilation (and so your tests) to continue when encountering those, set the ",(0,o.jsx)(n.code,{children:"warnOnly"})," to ",(0,o.jsx)(n.code,{children:"true"}),":"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: {\n warnOnly: true,\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": {\n "warnOnly": true\n }\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,o.jsxs)(n.p,{children:["All TypeScript error codes can be found ",(0,o.jsx)(n.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,o.jsx)(n.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,o.jsxs)(n.ol,{children:["\n",(0,o.jsxs)(n.li,{children:["A single ",(0,o.jsx)(n.code,{children:"number"})," (example: ",(0,o.jsx)(n.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,o.jsxs)(n.li,{children:["A ",(0,o.jsx)(n.code,{children:"string"})," with a code (example ",(0,o.jsx)(n.code,{children:'"1009"'}),", ",(0,o.jsx)(n.code,{children:'"TS1009"'})," or ",(0,o.jsx)(n.code,{children:'"TS1009"'}),")"]}),"\n",(0,o.jsxs)(n.li,{children:["A ",(0,o.jsx)(n.code,{children:"string"})," with a list of the above (example: ",(0,o.jsx)(n.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,o.jsxs)(n.li,{children:["An ",(0,o.jsx)(n.code,{children:"array"})," of one or more from ",(0,o.jsx)(n.code,{children:"1"})," or ",(0,o.jsx)(n.code,{children:"3"})," (example: ",(0,o.jsx)(n.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: {\n ignoreCodes: [2571, 6031, 18003],\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": {\n "ignoreCodes": [2571, 6031, 18003]\n }\n }\n }\n }\n}\n'})})]})}function h(e={}){const{wrapper:n}={...(0,t.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(a,{...e})}):a(e)}},8453:(e,n,s)=>{s.d(n,{R:()=>l,x:()=>r});var i=s(6540);const o={},t=i.createContext(o);function l(e){const n=i.useContext(t);return i.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function r(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:l(e.components),i.createElement(t.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3284],{3330:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>l,metadata:()=>i,toc:()=>d});const i=JSON.parse('{"id":"getting-started/options/diagnostics","title":"Diagnostics option","description":"The diagnostics option configures error reporting.","source":"@site/versioned_docs/version-28.0/getting-started/options/diagnostics.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/diagnostics","permalink":"/ts-jest/docs/28.0/getting-started/options/diagnostics","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/options/diagnostics.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Diagnostics option"}}');var o=s(4848),t=s(8453);const l={title:"Diagnostics option"},r=void 0,c={},d=[{value:"Disabling/enabling",id:"disablingenabling",level:3},{value:"Advanced configuration",id:"advanced-configuration",level:3},{value:"Examples",id:"examples",level:3},{value:"Disabling diagnostics",id:"disabling-diagnostics",level:4},{value:"Advanced options",id:"advanced-options",level:4},{value:"Enabling diagnostics for test files only",id:"enabling-diagnostics-for-test-files-only",level:5},{value:"Do not fail on first error",id:"do-not-fail-on-first-error",level:5},{value:"Ignoring some error codes",id:"ignoring-some-error-codes",level:5}];function a(e){const n={a:"a",code:"code",em:"em",h3:"h3",h4:"h4",h5:"h5",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,t.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:["The ",(0,o.jsx)(n.code,{children:"diagnostics"})," option configures error reporting.\nIt can both be enabled/disabled entirely or limited to a specific type of errors and/or files."]}),"\n",(0,o.jsxs)(n.p,{children:["If a diagnostic is not filtered out, ",(0,o.jsx)(n.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,o.jsx)(n.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,o.jsxs)(n.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,o.jsx)(n.code,{children:"diagnostics"})," option to ",(0,o.jsx)(n.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,o.jsx)(n.code,{children:"diagnostics"})," to ",(0,o.jsx)(n.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,o.jsx)(n.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,o.jsxs)(n.p,{children:["The ",(0,o.jsx)(n.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"warnOnly"})}),": If specified and ",(0,o.jsx)(n.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,o.jsx)(n.em,{children:"disabled"}),")."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,o.jsx)(n.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". By default here are the ones ignored:","\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"6059"}),": ",(0,o.jsx)(n.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"18002"}),": ",(0,o.jsx)(n.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"18003"}),": ",(0,o.jsx)(n.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,o.jsx)(n.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,o.jsx)(n.code,{children:"tsconfig"})," option ",(0,o.jsx)(n.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,o.jsx)(n.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:(0,o.jsx)(n.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,o.jsx)(n.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,o.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsx)(n.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: false,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": false\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,o.jsx)(n.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,o.jsxs)(n.p,{children:["Assuming all your test files ends with ",(0,o.jsx)(n.code,{children:".spec.ts"})," or ",(0,o.jsx)(n.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: {\n exclude: ['!**/*.(spec|test).ts'],\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": {\n "exclude": ["!**/*.(spec|test).ts"]\n }\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,o.jsxs)(n.p,{children:["While some diagnostics are stop-blockers for the compilation, most of them are not. If you want the compilation (and so your tests) to continue when encountering those, set the ",(0,o.jsx)(n.code,{children:"warnOnly"})," to ",(0,o.jsx)(n.code,{children:"true"}),":"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: {\n warnOnly: true,\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": {\n "warnOnly": true\n }\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,o.jsxs)(n.p,{children:["All TypeScript error codes can be found ",(0,o.jsx)(n.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,o.jsx)(n.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,o.jsxs)(n.ol,{children:["\n",(0,o.jsxs)(n.li,{children:["A single ",(0,o.jsx)(n.code,{children:"number"})," (example: ",(0,o.jsx)(n.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,o.jsxs)(n.li,{children:["A ",(0,o.jsx)(n.code,{children:"string"})," with a code (example ",(0,o.jsx)(n.code,{children:'"1009"'}),", ",(0,o.jsx)(n.code,{children:'"TS1009"'})," or ",(0,o.jsx)(n.code,{children:'"TS1009"'}),")"]}),"\n",(0,o.jsxs)(n.li,{children:["A ",(0,o.jsx)(n.code,{children:"string"})," with a list of the above (example: ",(0,o.jsx)(n.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,o.jsxs)(n.li,{children:["An ",(0,o.jsx)(n.code,{children:"array"})," of one or more from ",(0,o.jsx)(n.code,{children:"1"})," or ",(0,o.jsx)(n.code,{children:"3"})," (example: ",(0,o.jsx)(n.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n diagnostics: {\n ignoreCodes: [2571, 6031, 18003],\n },\n },\n },\n}\n"})}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "diagnostics": {\n "ignoreCodes": [2571, 6031, 18003]\n }\n }\n }\n }\n}\n'})})]})}function h(e={}){const{wrapper:n}={...(0,t.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(a,{...e})}):a(e)}},8453:(e,n,s)=>{s.d(n,{R:()=>l,x:()=>r});var i=s(6540);const o={},t=i.createContext(o);function l(e){const n=i.useContext(t);return i.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function r(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:l(e.components),i.createElement(t.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/e87a3571.9597891d.js b/assets/js/e87a3571.0c980777.js similarity index 98% rename from assets/js/e87a3571.9597891d.js rename to assets/js/e87a3571.0c980777.js index 7f9c034cbc..de200e172a 100644 --- a/assets/js/e87a3571.9597891d.js +++ b/assets/js/e87a3571.0c980777.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7252],{6505:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>r,metadata:()=>s,toc:()=>l});const s=JSON.parse('{"id":"babel7-or-ts","title":"Babel7 or TypeScript","description":"In Sept. 2018 Babel7 got released with an interesting preset: @babel/preset-typescript.","source":"@site/versioned_docs/version-29.0/babel7-or-ts.md","sourceDirName":".","slug":"/babel7-or-ts","permalink":"/ts-jest/docs/29.0/babel7-or-ts","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/babel7-or-ts.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"babel7-or-ts","title":"Babel7 or TypeScript"},"sidebar":"version-29.0-docs","previous":{"title":"Using with monorepo","permalink":"/ts-jest/docs/29.0/guides/using-with-monorepo"},"next":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/29.0/migration"}}');var i=n(4848),o=n(8453);const r={id:"babel7-or-ts",title:"Babel7 or TypeScript"},c=void 0,a={},l=[{value:"Limitations",id:"limitations",level:2},{value:"No type-checking",id:"no-type-checking",level:4},{value:"No namespace",id:"no-namespace",level:4},{value:"No const enum",id:"no-const-enum",level:4},{value:"No declaration merging (enum, namespace, ...)",id:"no-declaration-merging-enum-namespace-",level:4},{value:"No legacy import/export",id:"no-legacy-importexport",level:4},{value:"No caret type-casting with JSX enabled",id:"no-caret-type-casting-with-jsx-enabled",level:4}];function d(e){const t={a:"a",code:"code",h2:"h2",h4:"h4",hr:"hr",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,i.jsxs)(t.p,{children:["The goal is to make it easy for users using Babel to try TypeScript without moving out from Babel, just by adding a preset in their Babel config (here is the ",(0,i.jsx)(t.a,{href:"https://blogs.msdn.microsoft.com/typescript/2018/08/27/typescript-and-babel-7/",children:"MSDN blog post"})," about TypeScript and Babel 7)."]}),"\n",(0,i.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,i.jsxs)(t.p,{children:["While ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"})," is a great preset, you must know the limitation of it. Here is what is possible with TypeScript (and ",(0,i.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,i.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,i.jsxs)(t.p,{children:["This is the big ",(0,i.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,i.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,i.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,i.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,i.jsx)(t.p,{children:'With Babel, files are transpiled as isolated modules, there is no notion of "project". With TypeScript, files are part of a project and are compiled in that scope.'}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,i.jsx)(t.code,{children:"namespace"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"namespace app {\n export const VERSION = '1.0.0'\n export class App {\n /* ... */\n }\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,i.jsx)(t.code,{children:"const enum"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,i.jsx)(t.code,{children:"enum"}),", ",(0,i.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,i.jsxs)(t.p,{children:["You won't be able to do ",(0,i.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,i.jsx)(t.code,{children:"import"}),"/",(0,i.jsx)(t.code,{children:"export"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>c});var s=n(6540);const i={},o=s.createContext(i);function r(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7252],{6505:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>r,metadata:()=>s,toc:()=>l});const s=JSON.parse('{"id":"babel7-or-ts","title":"Babel7 or TypeScript","description":"In Sept. 2018 Babel7 got released with an interesting preset: @babel/preset-typescript.","source":"@site/versioned_docs/version-29.0/babel7-or-ts.md","sourceDirName":".","slug":"/babel7-or-ts","permalink":"/ts-jest/docs/29.0/babel7-or-ts","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/babel7-or-ts.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"babel7-or-ts","title":"Babel7 or TypeScript"},"sidebar":"version-29.0-docs","previous":{"title":"Using with monorepo","permalink":"/ts-jest/docs/29.0/guides/using-with-monorepo"},"next":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/29.0/migration"}}');var i=n(4848),o=n(8453);const r={id:"babel7-or-ts",title:"Babel7 or TypeScript"},c=void 0,a={},l=[{value:"Limitations",id:"limitations",level:2},{value:"No type-checking",id:"no-type-checking",level:4},{value:"No namespace",id:"no-namespace",level:4},{value:"No const enum",id:"no-const-enum",level:4},{value:"No declaration merging (enum, namespace, ...)",id:"no-declaration-merging-enum-namespace-",level:4},{value:"No legacy import/export",id:"no-legacy-importexport",level:4},{value:"No caret type-casting with JSX enabled",id:"no-caret-type-casting-with-jsx-enabled",level:4}];function d(e){const t={a:"a",code:"code",h2:"h2",h4:"h4",hr:"hr",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,i.jsxs)(t.p,{children:["The goal is to make it easy for users using Babel to try TypeScript without moving out from Babel, just by adding a preset in their Babel config (here is the ",(0,i.jsx)(t.a,{href:"https://blogs.msdn.microsoft.com/typescript/2018/08/27/typescript-and-babel-7/",children:"MSDN blog post"})," about TypeScript and Babel 7)."]}),"\n",(0,i.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,i.jsxs)(t.p,{children:["While ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"})," is a great preset, you must know the limitation of it. Here is what is possible with TypeScript (and ",(0,i.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,i.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,i.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,i.jsxs)(t.p,{children:["This is the big ",(0,i.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,i.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,i.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,i.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,i.jsx)(t.p,{children:'With Babel, files are transpiled as isolated modules, there is no notion of "project". With TypeScript, files are part of a project and are compiled in that scope.'}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,i.jsx)(t.code,{children:"namespace"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"namespace app {\n export const VERSION = '1.0.0'\n export class App {\n /* ... */\n }\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,i.jsx)(t.code,{children:"const enum"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,i.jsx)(t.code,{children:"enum"}),", ",(0,i.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,i.jsxs)(t.p,{children:["You won't be able to do ",(0,i.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,i.jsx)(t.code,{children:"import"}),"/",(0,i.jsx)(t.code,{children:"export"})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>c});var s=n(6540);const i={},o=s.createContext(i);function r(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/e8b13364.c13e2b25.js b/assets/js/e8b13364.71f5c781.js similarity index 99% rename from assets/js/e8b13364.c13e2b25.js rename to assets/js/e8b13364.71f5c781.js index 352f2a9af0..fa42eb86eb 100644 --- a/assets/js/e8b13364.c13e2b25.js +++ b/assets/js/e8b13364.71f5c781.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4523],{9480:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>i,default:()=>p,frontMatter:()=>a,metadata:()=>r,toc:()=>l});const r=JSON.parse('{"id":"getting-started/options/astTransformers","title":"AST transformers option","description":"ts-jest by default does hoisting for a few jest methods via a TypeScript AST transformer. One can also create custom","source":"@site/versioned_docs/version-26.5/getting-started/options/astTransformers.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/astTransformers","permalink":"/ts-jest/docs/26.5/getting-started/options/astTransformers","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/getting-started/options/astTransformers.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"AST transformers option"}}');var t=n(4848),o=n(8453);const a={title:"AST transformers option"},i=void 0,c={},l=[{value:"Examples",id:"examples",level:3},{value:"Basic Transformers",id:"basic-transformers",level:4},{value:"Configuring transformers with options",id:"configuring-transformers-with-options",level:4},{value:"Public transformers",id:"public-transformers",level:3},{value:"Example of opt-in transformers",id:"example-of-opt-in-transformers",level:4},{value:"Writing custom TypeScript AST transformers",id:"writing-custom-typescript-ast-transformers",level:3}];function d(e){const s={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(s.p,{children:[(0,t.jsx)(s.code,{children:"ts-jest"})," by default does hoisting for a few ",(0,t.jsx)(s.code,{children:"jest"})," methods via a TypeScript AST transformer. One can also create custom\nTypeScript AST transformers and provide them to ",(0,t.jsx)(s.code,{children:"ts-jest"})," to include into compilation process."]}),"\n",(0,t.jsxs)(s.p,{children:["The option is ",(0,t.jsx)(s.code,{children:"astTransformers"})," and it allows ones to specify which 3 types of TypeScript AST transformers to use with ",(0,t.jsx)(s.code,{children:"ts-jest"}),":"]}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"before"})," means your transformers get run before TS ones, which means your transformers will get raw TS syntax\ninstead of transpiled syntax (e.g ",(0,t.jsx)(s.code,{children:"import"})," instead of ",(0,t.jsx)(s.code,{children:"require"})," or ",(0,t.jsx)(s.code,{children:"define"})," )."]}),"\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"after"})," means your transformers get run after TS ones, which gets transpiled syntax."]}),"\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"afterDeclarations"})," means your transformers get run during ",(0,t.jsx)(s.code,{children:"d.ts"})," generation phase, allowing you to transform output type declarations."]}),"\n"]}),"\n",(0,t.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,t.jsx)(s.h4,{id:"basic-transformers",children:"Basic Transformers"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n astTransformers: {\n before: ['my-custom-transformer'],\n },\n },\n },\n}\n"})}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "astTransformers": {\n "before": ["my-custom-transformer"]\n }\n }\n }\n }\n}\n'})}),"\n",(0,t.jsx)(s.h4,{id:"configuring-transformers-with-options",children:"Configuring transformers with options"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n astTransformers: {\n before: [\n {\n path: 'my-custom-transformer-that-needs-extra-opts',\n options: {}, // extra options to pass to transformers here\n },\n ],\n },\n },\n },\n}\n"})}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "astTransformers": {\n "before": [\n {\n "path": "my-custom-transformer-that-needs-extra-opts",\n "options": {} // extra options to pass to transformers here\n }\n ]\n }\n }\n }\n }\n}\n'})}),"\n",(0,t.jsx)(s.h3,{id:"public-transformers",children:"Public transformers"}),"\n",(0,t.jsxs)(s.p,{children:[(0,t.jsx)(s.code,{children:"ts-jest"})," is able to expose transformers for public usage to provide the possibility to opt-in/out for users. Currently\nthe exposed transformers are:"]}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"path-mapping"})," convert alias import/export to relative import/export path base on ",(0,t.jsx)(s.code,{children:"paths"})," in ",(0,t.jsx)(s.code,{children:"tsconfig"}),".\nThis transformer works similar to ",(0,t.jsx)(s.code,{children:"moduleNameMapper"})," in ",(0,t.jsx)(s.code,{children:"jest.config.js"}),". When using this transformer, one might not need\n",(0,t.jsx)(s.code,{children:"moduleNameMapper"})," anymore."]}),"\n"]}),"\n",(0,t.jsx)(s.h4,{id:"example-of-opt-in-transformers",children:"Example of opt-in transformers"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n astTransformers: {\n before: ['ts-jest/dist/transformers/path-mapping'],\n },\n },\n },\n}\n"})}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "astTransformers": {\n "before": ["ts-jest/dist/transformers/path-mapping"]\n }\n }\n }\n }\n}\n'})}),"\n",(0,t.jsx)(s.h3,{id:"writing-custom-typescript-ast-transformers",children:"Writing custom TypeScript AST transformers"}),"\n",(0,t.jsxs)(s.p,{children:["To write a custom TypeScript AST transformers, one can take a look at ",(0,t.jsx)(s.a,{href:"https://github.com/kulshekhar/ts-jest/tree/v26.5.0/src/transformers",children:"the one"})," that ",(0,t.jsx)(s.code,{children:"ts-jest"})," is using."]})]})}function p(e={}){const{wrapper:s}={...(0,o.R)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.jsx)(d,{...e})}):d(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>a,x:()=>i});var r=n(6540);const t={},o=r.createContext(t);function a(e){const s=r.useContext(o);return r.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function i(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:a(e.components),r.createElement(o.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4523],{9480:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>i,default:()=>p,frontMatter:()=>a,metadata:()=>r,toc:()=>l});const r=JSON.parse('{"id":"getting-started/options/astTransformers","title":"AST transformers option","description":"ts-jest by default does hoisting for a few jest methods via a TypeScript AST transformer. One can also create custom","source":"@site/versioned_docs/version-26.5/getting-started/options/astTransformers.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/astTransformers","permalink":"/ts-jest/docs/26.5/getting-started/options/astTransformers","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/getting-started/options/astTransformers.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"AST transformers option"}}');var t=n(4848),o=n(8453);const a={title:"AST transformers option"},i=void 0,c={},l=[{value:"Examples",id:"examples",level:3},{value:"Basic Transformers",id:"basic-transformers",level:4},{value:"Configuring transformers with options",id:"configuring-transformers-with-options",level:4},{value:"Public transformers",id:"public-transformers",level:3},{value:"Example of opt-in transformers",id:"example-of-opt-in-transformers",level:4},{value:"Writing custom TypeScript AST transformers",id:"writing-custom-typescript-ast-transformers",level:3}];function d(e){const s={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(s.p,{children:[(0,t.jsx)(s.code,{children:"ts-jest"})," by default does hoisting for a few ",(0,t.jsx)(s.code,{children:"jest"})," methods via a TypeScript AST transformer. One can also create custom\nTypeScript AST transformers and provide them to ",(0,t.jsx)(s.code,{children:"ts-jest"})," to include into compilation process."]}),"\n",(0,t.jsxs)(s.p,{children:["The option is ",(0,t.jsx)(s.code,{children:"astTransformers"})," and it allows ones to specify which 3 types of TypeScript AST transformers to use with ",(0,t.jsx)(s.code,{children:"ts-jest"}),":"]}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"before"})," means your transformers get run before TS ones, which means your transformers will get raw TS syntax\ninstead of transpiled syntax (e.g ",(0,t.jsx)(s.code,{children:"import"})," instead of ",(0,t.jsx)(s.code,{children:"require"})," or ",(0,t.jsx)(s.code,{children:"define"})," )."]}),"\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"after"})," means your transformers get run after TS ones, which gets transpiled syntax."]}),"\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"afterDeclarations"})," means your transformers get run during ",(0,t.jsx)(s.code,{children:"d.ts"})," generation phase, allowing you to transform output type declarations."]}),"\n"]}),"\n",(0,t.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,t.jsx)(s.h4,{id:"basic-transformers",children:"Basic Transformers"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n astTransformers: {\n before: ['my-custom-transformer'],\n },\n },\n },\n}\n"})}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "astTransformers": {\n "before": ["my-custom-transformer"]\n }\n }\n }\n }\n}\n'})}),"\n",(0,t.jsx)(s.h4,{id:"configuring-transformers-with-options",children:"Configuring transformers with options"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n astTransformers: {\n before: [\n {\n path: 'my-custom-transformer-that-needs-extra-opts',\n options: {}, // extra options to pass to transformers here\n },\n ],\n },\n },\n },\n}\n"})}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "astTransformers": {\n "before": [\n {\n "path": "my-custom-transformer-that-needs-extra-opts",\n "options": {} // extra options to pass to transformers here\n }\n ]\n }\n }\n }\n }\n}\n'})}),"\n",(0,t.jsx)(s.h3,{id:"public-transformers",children:"Public transformers"}),"\n",(0,t.jsxs)(s.p,{children:[(0,t.jsx)(s.code,{children:"ts-jest"})," is able to expose transformers for public usage to provide the possibility to opt-in/out for users. Currently\nthe exposed transformers are:"]}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"path-mapping"})," convert alias import/export to relative import/export path base on ",(0,t.jsx)(s.code,{children:"paths"})," in ",(0,t.jsx)(s.code,{children:"tsconfig"}),".\nThis transformer works similar to ",(0,t.jsx)(s.code,{children:"moduleNameMapper"})," in ",(0,t.jsx)(s.code,{children:"jest.config.js"}),". When using this transformer, one might not need\n",(0,t.jsx)(s.code,{children:"moduleNameMapper"})," anymore."]}),"\n"]}),"\n",(0,t.jsx)(s.h4,{id:"example-of-opt-in-transformers",children:"Example of opt-in transformers"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n astTransformers: {\n before: ['ts-jest/dist/transformers/path-mapping'],\n },\n },\n },\n}\n"})}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "astTransformers": {\n "before": ["ts-jest/dist/transformers/path-mapping"]\n }\n }\n }\n }\n}\n'})}),"\n",(0,t.jsx)(s.h3,{id:"writing-custom-typescript-ast-transformers",children:"Writing custom TypeScript AST transformers"}),"\n",(0,t.jsxs)(s.p,{children:["To write a custom TypeScript AST transformers, one can take a look at ",(0,t.jsx)(s.a,{href:"https://github.com/kulshekhar/ts-jest/tree/v26.5.0/src/transformers",children:"the one"})," that ",(0,t.jsx)(s.code,{children:"ts-jest"})," is using."]})]})}function p(e={}){const{wrapper:s}={...(0,o.R)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.jsx)(d,{...e})}):d(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>a,x:()=>i});var r=n(6540);const t={},o=r.createContext(t);function a(e){const s=r.useContext(o);return r.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function i(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:a(e.components),r.createElement(o.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/eabdbf07.22b244a5.js b/assets/js/eabdbf07.5410c020.js similarity index 98% rename from assets/js/eabdbf07.22b244a5.js rename to assets/js/eabdbf07.5410c020.js index 85e96c7862..f8022c0b78 100644 --- a/assets/js/eabdbf07.22b244a5.js +++ b/assets/js/eabdbf07.5410c020.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5100],{5990:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>c,default:()=>d,frontMatter:()=>i,metadata:()=>n,toc:()=>u});const n=JSON.parse('{"id":"processing","title":"Processing flow","description":"These are internal technical documents. If you\'re not a contributor to ts-jest, but simply trying to use the library you\'ll find nothing of value here","source":"@site/docs/processing.md","sourceDirName":".","slug":"/processing","permalink":"/ts-jest/docs/next/processing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/processing.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"processing","title":"Processing flow"},"sidebar":"docs","previous":{"title":"Introduction","permalink":"/ts-jest/docs/next/"},"next":{"title":"Contributing","permalink":"/ts-jest/docs/next/contributing"}}');var o=s(4848),r=s(8453);const i={id:"processing",title:"Processing flow"},c=void 0,l={},u=[{value:"Jest process",id:"jest-process",level:2},{value:"ts-jest process",id:"ts-jest-process",level:2}];function a(e){const t={code:"code",em:"em",h2:"h2",img:"img",p:"p",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.p,{children:(0,o.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,o.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,o.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,o.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,o.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLJRRjim37tNLn3Omn9WwGUaG8Uz3YWmOFq1nQ9YjJ8PY7Iz0lduGHV7YHjWyvDruI7FuH7FfyGTYd0w6r6Rr9YzoayKVMWd6-4nTRXzD2Pus4ZFOtGWcW8TW__ulWNjaM3pWR8r-rTXMWuVpUu9nfEpYgR2F1g3KH0sn5k3v8Ali3v493iW83c1AMWF3-v1vHPz2YU46OXO4L8uzcg8WH0TA4F7mob4D0vzeA212JAsv6IGGwuBCESlBtqGZNXkSGasdUrwTDjpgIi8HwleO60tHfHRkWlIlaje5S6IWm9WL21QEe9WUW-vtiPsztHXK3CGd31944NI6hlIj0e80muDsYSUFWNTAFllqlUDSD7QQB8aUVbSxZPn8terHJsOGenmm5bUPwp0Ei6Ln000IpLGljkCTUyYJbqkMQ5zWtr360M1VQv-3hYSLzaTs0E_Nwdlp88momP1CfA3gKUw72UqBj2ncQJkhNZKlbKAeoWFyEFtIraNsJod0PDK3ci6FQQIU2e_FGVHd8rzEt_DBstWxYrVSapu3Qp0X362dSiP1TEk-3bRV4vfixVdAmURYJ51n-J3qNnciNkwz6xnN-7amv-s0uCzDHwVJ7UxVSzyHQRprJov-_YN9zycIMxkmHumhlnPzkuFeaNapiOeDNoNfJINz8iP_tS4zLR0UiNqgs90p_osVZGsDsPzwTwOMseCrRdv8YJKCP4OuG6rpqu8-hMyB5EiQGK8fzQEwv5LozmlXhlg8fBx2m00"})]})}function d(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(a,{...e})}):a(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5100],{5990:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>c,default:()=>d,frontMatter:()=>i,metadata:()=>n,toc:()=>u});const n=JSON.parse('{"id":"processing","title":"Processing flow","description":"These are internal technical documents. If you\'re not a contributor to ts-jest, but simply trying to use the library you\'ll find nothing of value here","source":"@site/docs/processing.md","sourceDirName":".","slug":"/processing","permalink":"/ts-jest/docs/next/processing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/processing.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"processing","title":"Processing flow"},"sidebar":"docs","previous":{"title":"Introduction","permalink":"/ts-jest/docs/next/"},"next":{"title":"Contributing","permalink":"/ts-jest/docs/next/contributing"}}');var o=s(4848),r=s(8453);const i={id:"processing",title:"Processing flow"},c=void 0,l={},u=[{value:"Jest process",id:"jest-process",level:2},{value:"ts-jest process",id:"ts-jest-process",level:2}];function a(e){const t={code:"code",em:"em",h2:"h2",img:"img",p:"p",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.p,{children:(0,o.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,o.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,o.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,o.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,o.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLJRRjim37tNLn3Omn9WwGUaG8Uz3YWmOFq1nQ9YjJ8PY7Iz0lduGHV7YHjWyvDruI7FuH7FfyGTYd0w6r6Rr9YzoayKVMWd6-4nTRXzD2Pus4ZFOtGWcW8TW__ulWNjaM3pWR8r-rTXMWuVpUu9nfEpYgR2F1g3KH0sn5k3v8Ali3v493iW83c1AMWF3-v1vHPz2YU46OXO4L8uzcg8WH0TA4F7mob4D0vzeA212JAsv6IGGwuBCESlBtqGZNXkSGasdUrwTDjpgIi8HwleO60tHfHRkWlIlaje5S6IWm9WL21QEe9WUW-vtiPsztHXK3CGd31944NI6hlIj0e80muDsYSUFWNTAFllqlUDSD7QQB8aUVbSxZPn8terHJsOGenmm5bUPwp0Ei6Ln000IpLGljkCTUyYJbqkMQ5zWtr360M1VQv-3hYSLzaTs0E_Nwdlp88momP1CfA3gKUw72UqBj2ncQJkhNZKlbKAeoWFyEFtIraNsJod0PDK3ci6FQQIU2e_FGVHd8rzEt_DBstWxYrVSapu3Qp0X362dSiP1TEk-3bRV4vfixVdAmURYJ51n-J3qNnciNkwz6xnN-7amv-s0uCzDHwVJ7UxVSzyHQRprJov-_YN9zycIMxkmHumhlnPzkuFeaNapiOeDNoNfJINz8iP_tS4zLR0UiNqgs90p_osVZGsDsPzwTwOMseCrRdv8YJKCP4OuG6rpqu8-hMyB5EiQGK8fzQEwv5LozmlXhlg8fBx2m00"})]})}function d(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(a,{...e})}):a(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/ec6c7123.93ae7b87.js b/assets/js/ec6c7123.8810b94a.js similarity index 98% rename from assets/js/ec6c7123.93ae7b87.js rename to assets/js/ec6c7123.8810b94a.js index 97d2792d57..0267ac87f0 100644 --- a/assets/js/ec6c7123.93ae7b87.js +++ b/assets/js/ec6c7123.8810b94a.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2091],{1561:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>d,contentTitle:()=>l,default:()=>u,frontMatter:()=>r,metadata:()=>t,toc:()=>a});const t=JSON.parse('{"id":"guides/troubleshooting","title":"Troubleshooting","description":"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them.","source":"@site/versioned_docs/version-26.5/guides/troubleshooting.md","sourceDirName":"guides","slug":"/guides/troubleshooting","permalink":"/ts-jest/docs/26.5/guides/troubleshooting","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/guides/troubleshooting.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"troubleshooting","title":"Troubleshooting"},"sidebar":"version-26.5-docs","previous":{"title":"Test helpers","permalink":"/ts-jest/docs/26.5/guides/test-helpers"},"next":{"title":"Using with monorepo","permalink":"/ts-jest/docs/26.5/guides/using-with-monorepo"}}');var o=n(4848),i=n(8453);const r={id:"troubleshooting",title:"Troubleshooting"},l=void 0,d={},a=[{value:"Running ts-jest on CI tools",id:"running-ts-jest-on-ci-tools",level:2},{value:"PROBLEM",id:"problem",level:3},{value:"SOLUTION",id:"solution",level:3},{value:"Transform (node)-module explicitly",id:"transform-node-module-explicitly",level:2},{value:"PROBLEM",id:"problem-1",level:3},{value:"SOLUTION",id:"solution-1",level:3},{value:"Tests gets stuck when importing a dependency",id:"tests-gets-stuck-when-importing-a-dependency",level:2},{value:"PROBLEM",id:"problem-2",level:3},{value:"SOLUTION",id:"solution-2",level:3}];function c(e){const s={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(s.p,{children:"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them."}),"\n",(0,o.jsxs)(s.p,{children:["Please also check Jest ",(0,o.jsx)(s.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," if your issue is related to jest."]}),"\n",(0,o.jsx)(s.h2,{id:"running-ts-jest-on-ci-tools",children:"Running ts-jest on CI tools"}),"\n",(0,o.jsx)(s.h3,{id:"problem",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:'Cannot find module "" from ""'}),"\n",(0,o.jsx)(s.h3,{id:"solution",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check if ",(0,o.jsx)(s.code,{children:"rootDir"})," is referenced correctly. If not add this on your existing jest configuration."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n roots: [""]\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module directories are included on your jest configuration. If not add this on your existing jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleDirectories: ["node_modules",""],\n modulePaths: [""],\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module name is properly mapped and can be referenced by jest. If not, you can define moduleNameMapper for your jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleNameMapper: {\n "": "/",\n },\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check github folder names if its identical to you local folder names. Sometimes github never updates your folder names even if you rename it locally. If this happens rename your folders via github or use this command ",(0,o.jsx)(s.code,{children:"git mv "})," and commit changes."]}),"\n"]}),"\n",(0,o.jsx)(s.h2,{id:"transform-node-module-explicitly",children:"Transform (node)-module explicitly"}),"\n",(0,o.jsx)(s.h3,{id:"problem-1",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"SyntaxError: Cannot use import statement outside a module"}),"\n",(0,o.jsx)(s.h3,{id:"solution-1",children:"SOLUTION"}),"\n",(0,o.jsx)(s.p,{children:"One of the node modules hasn't the correct syntax for Jests execution step. It needs to\nbe transformed first."}),"\n",(0,o.jsx)(s.p,{children:"There is a good chance that the error message shows which module is affected:"}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-shell",children:' SyntaxError: Cannot use import statement outside a module\n > 22 | import Component from "../../node_modules/some-module/lib";\n | ^\n'})}),"\n",(0,o.jsxs)(s.p,{children:["In this case ",(0,o.jsx)(s.strong,{children:"some-module"})," is the problem and needs to be transformed.\nBy adding the following line to the configuration file it will tell Jest which modules\nshouldnt be ignored during the transformation step:"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n transformIgnorePatterns: ["node_modules/(?!(some-module|another-module))"]\n};\n'})}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.strong,{children:"some-module"})," and ",(0,o.jsx)(s.strong,{children:"another-module"})," will be transformed."]}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/63389757/jest-unit-test-syntaxerror-cannot-use-import-statement-outside-a-module",children:"here"})," and ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/52035066/how-to-write-jest-transformignorepatterns",children:"here"}),"."]}),"\n",(0,o.jsx)(s.h2,{id:"tests-gets-stuck-when-importing-a-dependency",children:"Tests gets stuck when importing a dependency"}),"\n",(0,o.jsx)(s.h3,{id:"problem-2",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"Without cache, jest takes an extremely long time to process files and appears to be stuck."}),"\n",(0,o.jsx)(s.h3,{id:"solution-2",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.code,{children:"ts-jest"})," internally uses TypeScript compiler API to transform ts/js file into js file. The recommendation is to only transform what is needed."]}),"\n",(0,o.jsxs)(s.p,{children:["A possible cause for that issue is that you may have enabled ",(0,o.jsx)(s.code,{children:"ts-jest"})," to process javascript files in addition to TypeScript files. This leads to the result that more files are loaded which can, in some cases, blow up the machine."]}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your tsconfig file, check if ",(0,o.jsx)(s.code,{children:"compilerOptions.allowJs"})," is unset or set to false."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'{\n "compilerOptions": {\n "allowJs": false,\n }\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your jest configuration, check if the transform property includes only ",(0,o.jsx)(s.code,{children:".ts"})," files for ts-jest. If not, change the regular expression to exclude js files. You can also add the attribute ",(0,o.jsx)(s.code,{children:"isolatedModules: true"})," for ts-jest to disable type checking for tests."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-diff",children:"module.exports = {\n ...\n 'transform': {\n- '^.+\\\\.(t|j)s$': ['ts-jest', {}],\n+ '^.+\\\\.ts$': ['ts-jest', { isolatedModules: true }],\n },\n};\n"})}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://github.com/kulshekhar/ts-jest/issues/4294",children:"here"})]})]})}function u(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,o.jsx)(s,{...e,children:(0,o.jsx)(c,{...e})}):c(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>r,x:()=>l});var t=n(6540);const o={},i=t.createContext(o);function r(e){const s=t.useContext(i);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function l(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),t.createElement(i.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2091],{1561:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>d,contentTitle:()=>l,default:()=>u,frontMatter:()=>r,metadata:()=>t,toc:()=>a});const t=JSON.parse('{"id":"guides/troubleshooting","title":"Troubleshooting","description":"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them.","source":"@site/versioned_docs/version-26.5/guides/troubleshooting.md","sourceDirName":"guides","slug":"/guides/troubleshooting","permalink":"/ts-jest/docs/26.5/guides/troubleshooting","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/guides/troubleshooting.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"troubleshooting","title":"Troubleshooting"},"sidebar":"version-26.5-docs","previous":{"title":"Test helpers","permalink":"/ts-jest/docs/26.5/guides/test-helpers"},"next":{"title":"Using with monorepo","permalink":"/ts-jest/docs/26.5/guides/using-with-monorepo"}}');var o=n(4848),i=n(8453);const r={id:"troubleshooting",title:"Troubleshooting"},l=void 0,d={},a=[{value:"Running ts-jest on CI tools",id:"running-ts-jest-on-ci-tools",level:2},{value:"PROBLEM",id:"problem",level:3},{value:"SOLUTION",id:"solution",level:3},{value:"Transform (node)-module explicitly",id:"transform-node-module-explicitly",level:2},{value:"PROBLEM",id:"problem-1",level:3},{value:"SOLUTION",id:"solution-1",level:3},{value:"Tests gets stuck when importing a dependency",id:"tests-gets-stuck-when-importing-a-dependency",level:2},{value:"PROBLEM",id:"problem-2",level:3},{value:"SOLUTION",id:"solution-2",level:3}];function c(e){const s={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(s.p,{children:"During your development with ts-jest, you may encounter various issues. Use this guide to resolve them."}),"\n",(0,o.jsxs)(s.p,{children:["Please also check Jest ",(0,o.jsx)(s.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," if your issue is related to jest."]}),"\n",(0,o.jsx)(s.h2,{id:"running-ts-jest-on-ci-tools",children:"Running ts-jest on CI tools"}),"\n",(0,o.jsx)(s.h3,{id:"problem",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:'Cannot find module "" from ""'}),"\n",(0,o.jsx)(s.h3,{id:"solution",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check if ",(0,o.jsx)(s.code,{children:"rootDir"})," is referenced correctly. If not add this on your existing jest configuration."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n roots: [""]\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module directories are included on your jest configuration. If not add this on your existing jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleDirectories: ["node_modules",""],\n modulePaths: [""],\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"Check if module name is properly mapped and can be referenced by jest. If not, you can define moduleNameMapper for your jest configuration."}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n moduleNameMapper: {\n "": "/",\n },\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["Check github folder names if its identical to you local folder names. Sometimes github never updates your folder names even if you rename it locally. If this happens rename your folders via github or use this command ",(0,o.jsx)(s.code,{children:"git mv "})," and commit changes."]}),"\n"]}),"\n",(0,o.jsx)(s.h2,{id:"transform-node-module-explicitly",children:"Transform (node)-module explicitly"}),"\n",(0,o.jsx)(s.h3,{id:"problem-1",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"SyntaxError: Cannot use import statement outside a module"}),"\n",(0,o.jsx)(s.h3,{id:"solution-1",children:"SOLUTION"}),"\n",(0,o.jsx)(s.p,{children:"One of the node modules hasn't the correct syntax for Jests execution step. It needs to\nbe transformed first."}),"\n",(0,o.jsx)(s.p,{children:"There is a good chance that the error message shows which module is affected:"}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-shell",children:' SyntaxError: Cannot use import statement outside a module\n > 22 | import Component from "../../node_modules/some-module/lib";\n | ^\n'})}),"\n",(0,o.jsxs)(s.p,{children:["In this case ",(0,o.jsx)(s.strong,{children:"some-module"})," is the problem and needs to be transformed.\nBy adding the following line to the configuration file it will tell Jest which modules\nshouldnt be ignored during the transformation step:"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'module.exports = {\n ...\n transformIgnorePatterns: ["node_modules/(?!(some-module|another-module))"]\n};\n'})}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.strong,{children:"some-module"})," and ",(0,o.jsx)(s.strong,{children:"another-module"})," will be transformed."]}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/63389757/jest-unit-test-syntaxerror-cannot-use-import-statement-outside-a-module",children:"here"})," and ",(0,o.jsx)(s.a,{href:"https://stackoverflow.com/questions/52035066/how-to-write-jest-transformignorepatterns",children:"here"}),"."]}),"\n",(0,o.jsx)(s.h2,{id:"tests-gets-stuck-when-importing-a-dependency",children:"Tests gets stuck when importing a dependency"}),"\n",(0,o.jsx)(s.h3,{id:"problem-2",children:"PROBLEM"}),"\n",(0,o.jsx)(s.p,{children:"Without cache, jest takes an extremely long time to process files and appears to be stuck."}),"\n",(0,o.jsx)(s.h3,{id:"solution-2",children:"SOLUTION"}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.code,{children:"ts-jest"})," internally uses TypeScript compiler API to transform ts/js file into js file. The recommendation is to only transform what is needed."]}),"\n",(0,o.jsxs)(s.p,{children:["A possible cause for that issue is that you may have enabled ",(0,o.jsx)(s.code,{children:"ts-jest"})," to process javascript files in addition to TypeScript files. This leads to the result that more files are loaded which can, in some cases, blow up the machine."]}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your tsconfig file, check if ",(0,o.jsx)(s.code,{children:"compilerOptions.allowJs"})," is unset or set to false."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-javascript",children:'{\n "compilerOptions": {\n "allowJs": false,\n }\n}\n'})}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["In your jest configuration, check if the transform property includes only ",(0,o.jsx)(s.code,{children:".ts"})," files for ts-jest. If not, change the regular expression to exclude js files. You can also add the attribute ",(0,o.jsx)(s.code,{children:"isolatedModules: true"})," for ts-jest to disable type checking for tests."]}),"\n"]}),"\n",(0,o.jsx)(s.pre,{children:(0,o.jsx)(s.code,{className:"language-diff",children:"module.exports = {\n ...\n 'transform': {\n- '^.+\\\\.(t|j)s$': ['ts-jest', {}],\n+ '^.+\\\\.ts$': ['ts-jest', { isolatedModules: true }],\n },\n};\n"})}),"\n",(0,o.jsxs)(s.p,{children:["For more information see ",(0,o.jsx)(s.a,{href:"https://github.com/kulshekhar/ts-jest/issues/4294",children:"here"})]})]})}function u(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,o.jsx)(s,{...e,children:(0,o.jsx)(c,{...e})}):c(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>r,x:()=>l});var t=n(6540);const o={},i=t.createContext(o);function r(e){const s=t.useContext(i);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function l(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),t.createElement(i.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/f01607c0.a408f628.js b/assets/js/f01607c0.cdf147cf.js similarity index 98% rename from assets/js/f01607c0.a408f628.js rename to assets/js/f01607c0.cdf147cf.js index 93568504e3..db320068cf 100644 --- a/assets/js/f01607c0.a408f628.js +++ b/assets/js/f01607c0.cdf147cf.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6714],{4200:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>l,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/installation","title":"Installation","description":"Dependencies","source":"@site/versioned_docs/version-28.0/getting-started/installation.md","sourceDirName":"getting-started","slug":"/getting-started/installation","permalink":"/ts-jest/docs/28.0/getting-started/installation","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/installation.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"installation","title":"Installation"},"sidebar":"version-28.0-docs","previous":{"title":"Contributing","permalink":"/ts-jest/docs/28.0/contributing"},"next":{"title":"Presets","permalink":"/ts-jest/docs/28.0/getting-started/presets"}}');var i=n(4848),o=n(8453);const l={id:"installation",title:"Installation"},r=void 0,c={},d=[{value:"Dependencies",id:"dependencies",level:3},{value:"NPM",id:"npm",level:4},{value:"Yarn",id:"yarn",level:4},{value:"Jest config file",id:"jest-config-file",level:3},{value:"Creating",id:"creating",level:4},{value:"NPM",id:"npm-1",level:4},{value:"Yarn",id:"yarn-1",level:4},{value:"Customizing",id:"customizing",level:4}];function a(e){const t={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,i.jsxs)(t.p,{children:["You can install ",(0,i.jsx)(t.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,i.jsx)(t.h4,{id:"npm",children:"NPM"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(t.h4,{id:"yarn",children:"Yarn"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(t.admonition,{type:"tip",children:(0,i.jsxs)(t.p,{children:["Tip: If you get an error with the following ",(0,i.jsx)(t.code,{children:"npm"})," commands such as ",(0,i.jsx)(t.code,{children:"npx: command not found"}),", you can replace ",(0,i.jsx)(t.code,{children:"npx XXX"})," with ",(0,i.jsx)(t.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,i.jsx)(t.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,i.jsx)(t.h4,{id:"creating",children:"Creating"}),"\n",(0,i.jsxs)(t.p,{children:["By default, Jest can run without any config files, but it will not compile ",(0,i.jsx)(t.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,i.jsx)(t.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,i.jsx)(t.code,{children:"ts-jest"})," preset."]}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,i.jsx)(t.h4,{id:"npm-1",children:"NPM"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"npx ts-jest config:init\n"})}),"\n",(0,i.jsx)(t.h4,{id:"yarn-1",children:"Yarn"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"yarn ts-jest config:init\n"})}),"\n",(0,i.jsxs)(t.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,i.jsx)(t.code,{children:".ts"})," files correctly."]}),"\n",(0,i.jsxs)(t.p,{children:["You can also use the ",(0,i.jsx)(t.code,{children:"jest --init"})," command (prefixed with either ",(0,i.jsx)(t.code,{children:"npx"})," or ",(0,i.jsx)(t.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,i.jsx)(t.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,i.jsx)(t.code,{children:'preset: "ts-jest"'})," to the ",(0,i.jsx)(t.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,i.jsx)(t.h4,{id:"customizing",children:"Customizing"}),"\n",(0,i.jsxs)(t.p,{children:["For customizing jest, please follow their ",(0,i.jsx)(t.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"ts-jest"})," specific options can be found ",(0,i.jsx)(t.a,{href:"/ts-jest/docs/28.0/getting-started/options",children:"here"}),"."]})]})}function h(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(a,{...e})}):a(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>l,x:()=>r});var s=n(6540);const i={},o=s.createContext(i);function l(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:l(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6714],{4200:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>l,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"getting-started/installation","title":"Installation","description":"Dependencies","source":"@site/versioned_docs/version-28.0/getting-started/installation.md","sourceDirName":"getting-started","slug":"/getting-started/installation","permalink":"/ts-jest/docs/28.0/getting-started/installation","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/installation.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"installation","title":"Installation"},"sidebar":"version-28.0-docs","previous":{"title":"Contributing","permalink":"/ts-jest/docs/28.0/contributing"},"next":{"title":"Presets","permalink":"/ts-jest/docs/28.0/getting-started/presets"}}');var i=n(4848),o=n(8453);const l={id:"installation",title:"Installation"},r=void 0,c={},d=[{value:"Dependencies",id:"dependencies",level:3},{value:"NPM",id:"npm",level:4},{value:"Yarn",id:"yarn",level:4},{value:"Jest config file",id:"jest-config-file",level:3},{value:"Creating",id:"creating",level:4},{value:"NPM",id:"npm-1",level:4},{value:"Yarn",id:"yarn-1",level:4},{value:"Customizing",id:"customizing",level:4}];function a(e){const t={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,i.jsxs)(t.p,{children:["You can install ",(0,i.jsx)(t.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,i.jsx)(t.h4,{id:"npm",children:"NPM"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(t.h4,{id:"yarn",children:"Yarn"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(t.admonition,{type:"tip",children:(0,i.jsxs)(t.p,{children:["Tip: If you get an error with the following ",(0,i.jsx)(t.code,{children:"npm"})," commands such as ",(0,i.jsx)(t.code,{children:"npx: command not found"}),", you can replace ",(0,i.jsx)(t.code,{children:"npx XXX"})," with ",(0,i.jsx)(t.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,i.jsx)(t.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,i.jsx)(t.h4,{id:"creating",children:"Creating"}),"\n",(0,i.jsxs)(t.p,{children:["By default, Jest can run without any config files, but it will not compile ",(0,i.jsx)(t.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,i.jsx)(t.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,i.jsx)(t.code,{children:"ts-jest"})," preset."]}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,i.jsx)(t.h4,{id:"npm-1",children:"NPM"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"npx ts-jest config:init\n"})}),"\n",(0,i.jsx)(t.h4,{id:"yarn-1",children:"Yarn"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-sh",children:"yarn ts-jest config:init\n"})}),"\n",(0,i.jsxs)(t.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,i.jsx)(t.code,{children:".ts"})," files correctly."]}),"\n",(0,i.jsxs)(t.p,{children:["You can also use the ",(0,i.jsx)(t.code,{children:"jest --init"})," command (prefixed with either ",(0,i.jsx)(t.code,{children:"npx"})," or ",(0,i.jsx)(t.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,i.jsx)(t.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,i.jsx)(t.code,{children:'preset: "ts-jest"'})," to the ",(0,i.jsx)(t.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,i.jsx)(t.h4,{id:"customizing",children:"Customizing"}),"\n",(0,i.jsxs)(t.p,{children:["For customizing jest, please follow their ",(0,i.jsx)(t.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"ts-jest"})," specific options can be found ",(0,i.jsx)(t.a,{href:"/ts-jest/docs/28.0/getting-started/options",children:"here"}),"."]})]})}function h(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(a,{...e})}):a(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>l,x:()=>r});var s=n(6540);const i={},o=s.createContext(i);function l(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:l(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/f0683fd0.2befdc34.js b/assets/js/f0683fd0.043633fc.js similarity index 97% rename from assets/js/f0683fd0.2befdc34.js rename to assets/js/f0683fd0.043633fc.js index 3e48e5ac0e..1372a62f46 100644 --- a/assets/js/f0683fd0.2befdc34.js +++ b/assets/js/f0683fd0.043633fc.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6672],{8059:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>r,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"guides/using-with-monorepo","title":"Using with monorepo","description":"To use ts-jest in a project with monorepo structure, you\'ll need to use Jest projects configuration.","source":"@site/docs/guides/using-with-monorepo.md","sourceDirName":"guides","slug":"/guides/using-with-monorepo","permalink":"/ts-jest/docs/next/guides/using-with-monorepo","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/guides/using-with-monorepo.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"using-with-monorepo","title":"Using with monorepo"},"sidebar":"docs","previous":{"title":"Troubleshooting","permalink":"/ts-jest/docs/next/guides/troubleshooting"},"next":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/next/babel7-or-ts"}}');var n=o(4848),i=o(8453);const r={id:"using-with-monorepo",title:"Using with monorepo"},c=void 0,u={},d=[];function a(e){const t={a:"a",code:"code",p:"p",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["To use ",(0,n.jsx)(t.code,{children:"ts-jest"})," in a project with monorepo structure, you'll need to use ",(0,n.jsx)(t.a,{href:"https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig",children:"Jest projects configuration"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["When using Jest ",(0,n.jsx)(t.code,{children:"projects"})," configuration, Jest will run ",(0,n.jsx)(t.code,{children:"ts-jest"})," against each project which is defined in the configuration."]})]})}function p(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(a,{...e})}):a(e)}},8453:(e,t,o)=>{o.d(t,{R:()=>r,x:()=>c});var s=o(6540);const n={},i=s.createContext(n);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6672],{8059:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>r,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"guides/using-with-monorepo","title":"Using with monorepo","description":"To use ts-jest in a project with monorepo structure, you\'ll need to use Jest projects configuration.","source":"@site/docs/guides/using-with-monorepo.md","sourceDirName":"guides","slug":"/guides/using-with-monorepo","permalink":"/ts-jest/docs/next/guides/using-with-monorepo","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/guides/using-with-monorepo.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"using-with-monorepo","title":"Using with monorepo"},"sidebar":"docs","previous":{"title":"Troubleshooting","permalink":"/ts-jest/docs/next/guides/troubleshooting"},"next":{"title":"Babel7 or TypeScript","permalink":"/ts-jest/docs/next/babel7-or-ts"}}');var n=o(4848),i=o(8453);const r={id:"using-with-monorepo",title:"Using with monorepo"},c=void 0,u={},d=[];function a(e){const t={a:"a",code:"code",p:"p",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["To use ",(0,n.jsx)(t.code,{children:"ts-jest"})," in a project with monorepo structure, you'll need to use ",(0,n.jsx)(t.a,{href:"https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig",children:"Jest projects configuration"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["When using Jest ",(0,n.jsx)(t.code,{children:"projects"})," configuration, Jest will run ",(0,n.jsx)(t.code,{children:"ts-jest"})," against each project which is defined in the configuration."]})]})}function p(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(a,{...e})}):a(e)}},8453:(e,t,o)=>{o.d(t,{R:()=>r,x:()=>c});var s=o(6540);const n={},i=s.createContext(n);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/f154e663.b0212b7d.js b/assets/js/f154e663.fff8a972.js similarity index 99% rename from assets/js/f154e663.b0212b7d.js rename to assets/js/f154e663.fff8a972.js index 01598e5d2c..24165b113a 100644 --- a/assets/js/f154e663.b0212b7d.js +++ b/assets/js/f154e663.fff8a972.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9643],{4788:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>d,contentTitle:()=>c,default:()=>h,frontMatter:()=>l,metadata:()=>n,toc:()=>j});const n=JSON.parse('{"id":"getting-started/options/diagnostics","title":"Diagnostics option","description":"The diagnostics option configures error reporting.","source":"@site/versioned_docs/version-29.0/getting-started/options/diagnostics.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/diagnostics","permalink":"/ts-jest/docs/29.0/getting-started/options/diagnostics","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/options/diagnostics.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Diagnostics option"}}');var i=t(4848),r=t(8453),o=t(9489),a=t(7227);const l={title:"Diagnostics option"},c=void 0,d={},j=[{value:"Disabling/enabling",id:"disablingenabling",level:3},{value:"Advanced configuration",id:"advanced-configuration",level:3},{value:"Examples",id:"examples",level:3},{value:"Disabling diagnostics",id:"disabling-diagnostics",level:4},{value:"Advanced options",id:"advanced-options",level:4},{value:"Enabling diagnostics for test files only",id:"enabling-diagnostics-for-test-files-only",level:5},{value:"Do not fail on first error",id:"do-not-fail-on-first-error",level:5},{value:"Ignoring some error codes",id:"ignoring-some-error-codes",level:5}];function u(e){const s={a:"a",code:"code",em:"em",h3:"h3",h4:"h4",h5:"h5",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(s.p,{children:["The ",(0,i.jsx)(s.code,{children:"diagnostics"})," option configures error reporting.\nIt can both be enabled/disabled entirely or limited to a specific type of errors and/or files."]}),"\n",(0,i.jsxs)(s.p,{children:["If a diagnostic is not filtered out, ",(0,i.jsx)(s.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,i.jsx)(s.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,i.jsxs)(s.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,i.jsx)(s.code,{children:"diagnostics"})," option to ",(0,i.jsx)(s.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,i.jsx)(s.code,{children:"diagnostics"})," to ",(0,i.jsx)(s.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,i.jsx)(s.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,i.jsxs)(s.p,{children:["The ",(0,i.jsx)(s.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,i.jsxs)(s.ul,{children:["\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"warnOnly"})}),": If specified and ",(0,i.jsx)(s.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,i.jsx)(s.em,{children:"disabled"}),")."]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,i.jsx)(s.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". By default here are the ones ignored:","\n",(0,i.jsxs)(s.ul,{children:["\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.code,{children:"6059"}),": ",(0,i.jsx)(s.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.code,{children:"18002"}),": ",(0,i.jsx)(s.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.code,{children:"18003"}),": ",(0,i.jsx)(s.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,i.jsx)(s.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,i.jsx)(s.code,{children:"tsconfig"})," option ",(0,i.jsx)(s.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,i.jsx)(s.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,i.jsx)(s.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,i.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,i.jsx)(s.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,i.jsxs)(o.A,{groupId:"code-examples",children:[(0,i.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: false,\n },\n ],\n },\n}\n"})})}),(0,i.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: false,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,i.jsx)(a.A,{value:"JSON",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "diagnostics": false\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,i.jsx)(s.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,i.jsx)(s.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,i.jsxs)(s.p,{children:["Assuming all your test files ends with ",(0,i.jsx)(s.code,{children:".spec.ts"})," or ",(0,i.jsx)(s.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,i.jsxs)(o.A,{groupId:"code-examples",children:[(0,i.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n exclude: ['!**/*.(spec|test).ts'],\n },\n },\n ],\n },\n}\n"})})}),(0,i.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n exclude: ['!**/*.(spec|test).ts'],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,i.jsx)(a.A,{value:"JSON",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "diagnostics": {\n "exclude": ["!**/*.(spec|test).ts"]\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,i.jsx)(s.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,i.jsxs)(s.p,{children:["While some diagnostics are stop-blockers for the compilation, most of them are not. If you want the compilation (and so your tests) to continue when encountering those, set the ",(0,i.jsx)(s.code,{children:"warnOnly"})," to ",(0,i.jsx)(s.code,{children:"true"}),":"]}),"\n",(0,i.jsxs)(o.A,{groupId:"code-examples",children:[(0,i.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n warnOnly: true,\n },\n },\n ],\n },\n}\n"})})}),(0,i.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n warnOnly: true,\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,i.jsx)(a.A,{value:"JSON",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "diagnostics": {\n "warnOnly": true\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,i.jsx)(s.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,i.jsxs)(s.p,{children:["All TypeScript error codes can be found ",(0,i.jsx)(s.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,i.jsx)(s.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,i.jsxs)(s.ol,{children:["\n",(0,i.jsxs)(s.li,{children:["A single ",(0,i.jsx)(s.code,{children:"number"})," (example: ",(0,i.jsx)(s.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,i.jsxs)(s.li,{children:["A ",(0,i.jsx)(s.code,{children:"string"})," with a code (example ",(0,i.jsx)(s.code,{children:'"1009"'}),", ",(0,i.jsx)(s.code,{children:'"TS1009"'})," or ",(0,i.jsx)(s.code,{children:'"TS1009"'}),")"]}),"\n",(0,i.jsxs)(s.li,{children:["A ",(0,i.jsx)(s.code,{children:"string"})," with a list of the above (example: ",(0,i.jsx)(s.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,i.jsxs)(s.li,{children:["An ",(0,i.jsx)(s.code,{children:"array"})," of one or more from ",(0,i.jsx)(s.code,{children:"1"})," or ",(0,i.jsx)(s.code,{children:"3"})," (example: ",(0,i.jsx)(s.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,i.jsxs)(o.A,{groupId:"code-examples",children:[(0,i.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n ignoreCodes: [2571, 6031, 18003],\n },\n },\n ],\n },\n}\n"})})}),(0,i.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n ignoreCodes: [2571, 6031, 18003],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,i.jsx)(a.A,{value:"JSON",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "diagnostics": {\n "ignoreCodes": [2571, 6031, 18003]\n }\n }\n ]\n }\n }\n}\n'})})})]})]})}function h(e={}){const{wrapper:s}={...(0,r.R)(),...e.components};return s?(0,i.jsx)(s,{...e,children:(0,i.jsx)(u,{...e})}):u(e)}},7227:(e,s,t)=>{t.d(s,{A:()=>o});t(6540);var n=t(4164);const i={tabItem:"tabItem_Ymn6"};var r=t(4848);function o(e){let{children:s,hidden:t,className:o}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,n.A)(i.tabItem,o),hidden:t,children:s})}},9489:(e,s,t)=>{t.d(s,{A:()=>w});var n=t(6540),i=t(4164),r=t(4245),o=t(6347),a=t(6494),l=t(2814),c=t(5167),d=t(9900);function j(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:s}=e;return!!s&&"object"==typeof s&&"value"in s}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function u(e){const{values:s,children:t}=e;return(0,n.useMemo)((()=>{const e=s??function(e){return j(e).map((e=>{let{props:{value:s,label:t,attributes:n,default:i}}=e;return{value:s,label:t,attributes:n,default:i}}))}(t);return function(e){const s=(0,c.XI)(e,((e,s)=>e.value===s.value));if(s.length>0)throw new Error(`Docusaurus error: Duplicate values "${s.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[s,t])}function h(e){let{value:s,tabValues:t}=e;return t.some((e=>e.value===s))}function x(e){let{queryString:s=!1,groupId:t}=e;const i=(0,o.W6)(),r=function(e){let{queryString:s=!1,groupId:t}=e;if("string"==typeof s)return s;if(!1===s)return null;if(!0===s&&!t)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return t??null}({queryString:s,groupId:t});return[(0,l.aZ)(r),(0,n.useCallback)((e=>{if(!r)return;const s=new URLSearchParams(i.location.search);s.set(r,e),i.replace({...i.location,search:s.toString()})}),[r,i])]}function p(e){const{defaultValue:s,queryString:t=!1,groupId:i}=e,r=u(e),[o,l]=(0,n.useState)((()=>function(e){let{defaultValue:s,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(s){if(!h({value:s,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${s}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return s}const n=t.find((e=>e.default))??t[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:s,tabValues:r}))),[c,j]=x({queryString:t,groupId:i}),[p,g]=function(e){let{groupId:s}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(s),[i,r]=(0,d.Dv)(t);return[i,(0,n.useCallback)((e=>{t&&r.set(e)}),[t,r])]}({groupId:i}),m=(()=>{const e=c??p;return h({value:e,tabValues:r})?e:null})();(0,a.A)((()=>{m&&l(m)}),[m]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!h({value:e,tabValues:r}))throw new Error(`Can't select invalid tab value=${e}`);l(e),j(e),g(e)}),[j,g,r]),tabValues:r}}var g=t(1062);const m={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var f=t(4848);function b(e){let{className:s,block:t,selectedValue:n,selectValue:o,tabValues:a}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),d=e=>{const s=e.currentTarget,t=l.indexOf(s),i=a[t].value;i!==n&&(c(s),o(i))},j=e=>{let s=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const t=l.indexOf(e.currentTarget)+1;s=l[t]??l[0];break}case"ArrowLeft":{const t=l.indexOf(e.currentTarget)-1;s=l[t]??l[l.length-1];break}}s?.focus()};return(0,f.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,i.A)("tabs",{"tabs--block":t},s),children:a.map((e=>{let{value:s,label:t,attributes:r}=e;return(0,f.jsx)("li",{role:"tab",tabIndex:n===s?0:-1,"aria-selected":n===s,ref:e=>l.push(e),onKeyDown:j,onClick:d,...r,className:(0,i.A)("tabs__item",m.tabItem,r?.className,{"tabs__item--active":n===s}),children:t??s},s)}))})}function v(e){let{lazy:s,children:t,selectedValue:r}=e;const o=(Array.isArray(t)?t:[t]).filter(Boolean);if(s){const e=o.find((e=>e.props.value===r));return e?(0,n.cloneElement)(e,{className:(0,i.A)("margin-top--md",e.props.className)}):null}return(0,f.jsx)("div",{className:"margin-top--md",children:o.map(((e,s)=>(0,n.cloneElement)(e,{key:s,hidden:e.props.value!==r})))})}function y(e){const s=p(e);return(0,f.jsxs)("div",{className:(0,i.A)("tabs-container",m.tabList),children:[(0,f.jsx)(b,{...s,...e}),(0,f.jsx)(v,{...s,...e})]})}function w(e){const s=(0,g.A)();return(0,f.jsx)(y,{...e,children:j(e.children)},String(s))}},8453:(e,s,t)=>{t.d(s,{R:()=>o,x:()=>a});var n=t(6540);const i={},r=n.createContext(i);function o(e){const s=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function a(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),n.createElement(r.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9643],{4788:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>d,contentTitle:()=>c,default:()=>h,frontMatter:()=>l,metadata:()=>n,toc:()=>j});const n=JSON.parse('{"id":"getting-started/options/diagnostics","title":"Diagnostics option","description":"The diagnostics option configures error reporting.","source":"@site/versioned_docs/version-29.0/getting-started/options/diagnostics.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/diagnostics","permalink":"/ts-jest/docs/29.0/getting-started/options/diagnostics","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/options/diagnostics.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Diagnostics option"}}');var i=t(4848),r=t(8453),o=t(9489),a=t(7227);const l={title:"Diagnostics option"},c=void 0,d={},j=[{value:"Disabling/enabling",id:"disablingenabling",level:3},{value:"Advanced configuration",id:"advanced-configuration",level:3},{value:"Examples",id:"examples",level:3},{value:"Disabling diagnostics",id:"disabling-diagnostics",level:4},{value:"Advanced options",id:"advanced-options",level:4},{value:"Enabling diagnostics for test files only",id:"enabling-diagnostics-for-test-files-only",level:5},{value:"Do not fail on first error",id:"do-not-fail-on-first-error",level:5},{value:"Ignoring some error codes",id:"ignoring-some-error-codes",level:5}];function u(e){const s={a:"a",code:"code",em:"em",h3:"h3",h4:"h4",h5:"h5",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(s.p,{children:["The ",(0,i.jsx)(s.code,{children:"diagnostics"})," option configures error reporting.\nIt can both be enabled/disabled entirely or limited to a specific type of errors and/or files."]}),"\n",(0,i.jsxs)(s.p,{children:["If a diagnostic is not filtered out, ",(0,i.jsx)(s.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,i.jsx)(s.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,i.jsxs)(s.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,i.jsx)(s.code,{children:"diagnostics"})," option to ",(0,i.jsx)(s.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,i.jsx)(s.code,{children:"diagnostics"})," to ",(0,i.jsx)(s.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,i.jsx)(s.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,i.jsxs)(s.p,{children:["The ",(0,i.jsx)(s.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,i.jsxs)(s.ul,{children:["\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"warnOnly"})}),": If specified and ",(0,i.jsx)(s.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,i.jsx)(s.em,{children:"disabled"}),")."]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,i.jsx)(s.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". By default here are the ones ignored:","\n",(0,i.jsxs)(s.ul,{children:["\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.code,{children:"6059"}),": ",(0,i.jsx)(s.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.code,{children:"18002"}),": ",(0,i.jsx)(s.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.code,{children:"18003"}),": ",(0,i.jsx)(s.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,i.jsx)(s.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,i.jsx)(s.code,{children:"tsconfig"})," option ",(0,i.jsx)(s.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,i.jsx)(s.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,i.jsx)(s.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,i.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,i.jsx)(s.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,i.jsxs)(o.A,{groupId:"code-examples",children:[(0,i.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: false,\n },\n ],\n },\n}\n"})})}),(0,i.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: false,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,i.jsx)(a.A,{value:"JSON",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "diagnostics": false\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,i.jsx)(s.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,i.jsx)(s.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,i.jsxs)(s.p,{children:["Assuming all your test files ends with ",(0,i.jsx)(s.code,{children:".spec.ts"})," or ",(0,i.jsx)(s.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,i.jsxs)(o.A,{groupId:"code-examples",children:[(0,i.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n exclude: ['!**/*.(spec|test).ts'],\n },\n },\n ],\n },\n}\n"})})}),(0,i.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n exclude: ['!**/*.(spec|test).ts'],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,i.jsx)(a.A,{value:"JSON",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "diagnostics": {\n "exclude": ["!**/*.(spec|test).ts"]\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,i.jsx)(s.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,i.jsxs)(s.p,{children:["While some diagnostics are stop-blockers for the compilation, most of them are not. If you want the compilation (and so your tests) to continue when encountering those, set the ",(0,i.jsx)(s.code,{children:"warnOnly"})," to ",(0,i.jsx)(s.code,{children:"true"}),":"]}),"\n",(0,i.jsxs)(o.A,{groupId:"code-examples",children:[(0,i.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n warnOnly: true,\n },\n },\n ],\n },\n}\n"})})}),(0,i.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n warnOnly: true,\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,i.jsx)(a.A,{value:"JSON",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "diagnostics": {\n "warnOnly": true\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,i.jsx)(s.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,i.jsxs)(s.p,{children:["All TypeScript error codes can be found ",(0,i.jsx)(s.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,i.jsx)(s.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,i.jsxs)(s.ol,{children:["\n",(0,i.jsxs)(s.li,{children:["A single ",(0,i.jsx)(s.code,{children:"number"})," (example: ",(0,i.jsx)(s.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,i.jsxs)(s.li,{children:["A ",(0,i.jsx)(s.code,{children:"string"})," with a code (example ",(0,i.jsx)(s.code,{children:'"1009"'}),", ",(0,i.jsx)(s.code,{children:'"TS1009"'})," or ",(0,i.jsx)(s.code,{children:'"TS1009"'}),")"]}),"\n",(0,i.jsxs)(s.li,{children:["A ",(0,i.jsx)(s.code,{children:"string"})," with a list of the above (example: ",(0,i.jsx)(s.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,i.jsxs)(s.li,{children:["An ",(0,i.jsx)(s.code,{children:"array"})," of one or more from ",(0,i.jsx)(s.code,{children:"1"})," or ",(0,i.jsx)(s.code,{children:"3"})," (example: ",(0,i.jsx)(s.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,i.jsxs)(o.A,{groupId:"code-examples",children:[(0,i.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n ignoreCodes: [2571, 6031, 18003],\n },\n },\n ],\n },\n}\n"})})}),(0,i.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n ignoreCodes: [2571, 6031, 18003],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,i.jsx)(a.A,{value:"JSON",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "diagnostics": {\n "ignoreCodes": [2571, 6031, 18003]\n }\n }\n ]\n }\n }\n}\n'})})})]})]})}function h(e={}){const{wrapper:s}={...(0,r.R)(),...e.components};return s?(0,i.jsx)(s,{...e,children:(0,i.jsx)(u,{...e})}):u(e)}},7227:(e,s,t)=>{t.d(s,{A:()=>o});t(6540);var n=t(4164);const i={tabItem:"tabItem_Ymn6"};var r=t(4848);function o(e){let{children:s,hidden:t,className:o}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,n.A)(i.tabItem,o),hidden:t,children:s})}},9489:(e,s,t)=>{t.d(s,{A:()=>w});var n=t(6540),i=t(4164),r=t(4245),o=t(6347),a=t(6494),l=t(2814),c=t(5167),d=t(9900);function j(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:s}=e;return!!s&&"object"==typeof s&&"value"in s}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function u(e){const{values:s,children:t}=e;return(0,n.useMemo)((()=>{const e=s??function(e){return j(e).map((e=>{let{props:{value:s,label:t,attributes:n,default:i}}=e;return{value:s,label:t,attributes:n,default:i}}))}(t);return function(e){const s=(0,c.XI)(e,((e,s)=>e.value===s.value));if(s.length>0)throw new Error(`Docusaurus error: Duplicate values "${s.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[s,t])}function h(e){let{value:s,tabValues:t}=e;return t.some((e=>e.value===s))}function x(e){let{queryString:s=!1,groupId:t}=e;const i=(0,o.W6)(),r=function(e){let{queryString:s=!1,groupId:t}=e;if("string"==typeof s)return s;if(!1===s)return null;if(!0===s&&!t)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return t??null}({queryString:s,groupId:t});return[(0,l.aZ)(r),(0,n.useCallback)((e=>{if(!r)return;const s=new URLSearchParams(i.location.search);s.set(r,e),i.replace({...i.location,search:s.toString()})}),[r,i])]}function p(e){const{defaultValue:s,queryString:t=!1,groupId:i}=e,r=u(e),[o,l]=(0,n.useState)((()=>function(e){let{defaultValue:s,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(s){if(!h({value:s,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${s}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return s}const n=t.find((e=>e.default))??t[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:s,tabValues:r}))),[c,j]=x({queryString:t,groupId:i}),[p,g]=function(e){let{groupId:s}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(s),[i,r]=(0,d.Dv)(t);return[i,(0,n.useCallback)((e=>{t&&r.set(e)}),[t,r])]}({groupId:i}),m=(()=>{const e=c??p;return h({value:e,tabValues:r})?e:null})();(0,a.A)((()=>{m&&l(m)}),[m]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!h({value:e,tabValues:r}))throw new Error(`Can't select invalid tab value=${e}`);l(e),j(e),g(e)}),[j,g,r]),tabValues:r}}var g=t(1062);const m={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var f=t(4848);function b(e){let{className:s,block:t,selectedValue:n,selectValue:o,tabValues:a}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),d=e=>{const s=e.currentTarget,t=l.indexOf(s),i=a[t].value;i!==n&&(c(s),o(i))},j=e=>{let s=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const t=l.indexOf(e.currentTarget)+1;s=l[t]??l[0];break}case"ArrowLeft":{const t=l.indexOf(e.currentTarget)-1;s=l[t]??l[l.length-1];break}}s?.focus()};return(0,f.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,i.A)("tabs",{"tabs--block":t},s),children:a.map((e=>{let{value:s,label:t,attributes:r}=e;return(0,f.jsx)("li",{role:"tab",tabIndex:n===s?0:-1,"aria-selected":n===s,ref:e=>l.push(e),onKeyDown:j,onClick:d,...r,className:(0,i.A)("tabs__item",m.tabItem,r?.className,{"tabs__item--active":n===s}),children:t??s},s)}))})}function v(e){let{lazy:s,children:t,selectedValue:r}=e;const o=(Array.isArray(t)?t:[t]).filter(Boolean);if(s){const e=o.find((e=>e.props.value===r));return e?(0,n.cloneElement)(e,{className:(0,i.A)("margin-top--md",e.props.className)}):null}return(0,f.jsx)("div",{className:"margin-top--md",children:o.map(((e,s)=>(0,n.cloneElement)(e,{key:s,hidden:e.props.value!==r})))})}function y(e){const s=p(e);return(0,f.jsxs)("div",{className:(0,i.A)("tabs-container",m.tabList),children:[(0,f.jsx)(b,{...s,...e}),(0,f.jsx)(v,{...s,...e})]})}function w(e){const s=(0,g.A)();return(0,f.jsx)(y,{...e,children:j(e.children)},String(s))}},8453:(e,s,t)=>{t.d(s,{R:()=>o,x:()=>a});var n=t(6540);const i={},r=n.createContext(i);function o(e){const s=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function a(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),n.createElement(r.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/f298e69b.70fafe25.js b/assets/js/f298e69b.4ecb8a66.js similarity index 99% rename from assets/js/f298e69b.70fafe25.js rename to assets/js/f298e69b.4ecb8a66.js index c89e175203..9d317c97eb 100644 --- a/assets/js/f298e69b.70fafe25.js +++ b/assets/js/f298e69b.4ecb8a66.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2804],{7834:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>i,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/isolatedModules","title":"Isolated Modules option","description":"By default ts-jest uses TypeScript compiler in the context of a project (yours), with full type-checking and features.","source":"@site/versioned_docs/version-29.0/getting-started/options/isolatedModules.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/isolatedModules","permalink":"/ts-jest/docs/29.0/getting-started/options/isolatedModules","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/options/isolatedModules.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Isolated Modules option"}}');var a=s(4848),r=s(8453),o=s(9489),l=s(7227);const i={title:"Isolated Modules option"},c=void 0,u={},d=[{value:"Example",id:"example",level:3},{value:"Performance",id:"performance",level:2},{value:"Example",id:"example-1",level:3},{value:"Caveats",id:"caveats",level:2}];function h(e){const t={code:"code",h2:"h2",h3:"h3",p:"p",pre:"pre",...(0,r.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(t.p,{children:["By default ",(0,a.jsx)(t.code,{children:"ts-jest"})," uses TypeScript compiler in the context of a project (yours), with full type-checking and features.\nBut it can also be used to compile each file separately, what TypeScript calls an 'isolated module'.\nThat's what the ",(0,a.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,a.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,a.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,a.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,a.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,a.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\n",(0,a.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,a.jsxs)(o.A,{groupId:"code-examples",children:[(0,a.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n isolatedModules: true,\n },\n ],\n },\n}\n"})})}),(0,a.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process js/ts with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process js/ts/mjs/mts with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n isolatedModules: true,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,a.jsx)(l.A,{value:"JSON",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process js/ts with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process js/ts/mjs/mts with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "isolatedModules": true\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,a.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,a.jsxs)(t.p,{children:["Using ",(0,a.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,a.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,a.jsx)(t.code,{children:"include"})," in ",(0,a.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,a.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,a.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,a.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,a.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,a.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,a.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,a.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,a.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,a.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,a.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(h,{...e})}):h(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>o});s(6540);var n=s(4164);const a={tabItem:"tabItem_Ymn6"};var r=s(4848);function o(e){let{children:t,hidden:s,className:o}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,n.A)(a.tabItem,o),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>w});var n=s(6540),a=s(4164),r=s(4245),o=s(6347),l=s(6494),i=s(2814),c=s(5167),u=s(9900);function d(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:a}}=e;return{value:t,label:s,attributes:n,default:a}}))}(s);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function p(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:s}=e;const a=(0,o.W6)(),r=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,i.aZ)(r),(0,n.useCallback)((e=>{if(!r)return;const t=new URLSearchParams(a.location.search);t.set(r,e),a.replace({...a.location,search:t.toString()})}),[r,a])]}function f(e){const{defaultValue:t,queryString:s=!1,groupId:a}=e,r=h(e),[o,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:r}))),[c,d]=m({queryString:s,groupId:a}),[f,j]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,r]=(0,u.Dv)(s);return[a,(0,n.useCallback)((e=>{s&&r.set(e)}),[s,r])]}({groupId:a}),g=(()=>{const e=c??f;return p({value:e,tabValues:r})?e:null})();(0,l.A)((()=>{g&&i(g)}),[g]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!p({value:e,tabValues:r}))throw new Error(`Can't select invalid tab value=${e}`);i(e),d(e),j(e)}),[d,j,r]),tabValues:r}}var j=s(1062);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=s(4848);function x(e){let{className:t,block:s,selectedValue:n,selectValue:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),u=e=>{const t=e.currentTarget,s=i.indexOf(t),a=l[s].value;a!==n&&(c(t),o(a))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const s=i.indexOf(e.currentTarget)+1;t=i[s]??i[0];break}case"ArrowLeft":{const s=i.indexOf(e.currentTarget)-1;t=i[s]??i[i.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.A)("tabs",{"tabs--block":s},t),children:l.map((e=>{let{value:t,label:s,attributes:r}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:d,onClick:u,...r,className:(0,a.A)("tabs__item",g.tabItem,r?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:r}=e;const o=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===r));return e?(0,n.cloneElement)(e,{className:(0,a.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==r})))})}function y(e){const t=f(e);return(0,b.jsxs)("div",{className:(0,a.A)("tabs-container",g.tabList),children:[(0,b.jsx)(x,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function w(e){const t=(0,j.A)();return(0,b.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>o,x:()=>l});var n=s(6540);const a={},r=n.createContext(a);function o(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2804],{7834:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>i,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/isolatedModules","title":"Isolated Modules option","description":"By default ts-jest uses TypeScript compiler in the context of a project (yours), with full type-checking and features.","source":"@site/versioned_docs/version-29.0/getting-started/options/isolatedModules.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/isolatedModules","permalink":"/ts-jest/docs/29.0/getting-started/options/isolatedModules","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/options/isolatedModules.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Isolated Modules option"}}');var a=s(4848),r=s(8453),o=s(9489),l=s(7227);const i={title:"Isolated Modules option"},c=void 0,u={},d=[{value:"Example",id:"example",level:3},{value:"Performance",id:"performance",level:2},{value:"Example",id:"example-1",level:3},{value:"Caveats",id:"caveats",level:2}];function h(e){const t={code:"code",h2:"h2",h3:"h3",p:"p",pre:"pre",...(0,r.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(t.p,{children:["By default ",(0,a.jsx)(t.code,{children:"ts-jest"})," uses TypeScript compiler in the context of a project (yours), with full type-checking and features.\nBut it can also be used to compile each file separately, what TypeScript calls an 'isolated module'.\nThat's what the ",(0,a.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,a.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,a.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,a.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,a.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,a.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\n",(0,a.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,a.jsxs)(o.A,{groupId:"code-examples",children:[(0,a.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n isolatedModules: true,\n },\n ],\n },\n}\n"})})}),(0,a.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process js/ts with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process js/ts/mjs/mts with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n isolatedModules: true,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,a.jsx)(l.A,{value:"JSON",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process js/ts with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process js/ts/mjs/mts with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "isolatedModules": true\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,a.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,a.jsxs)(t.p,{children:["Using ",(0,a.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,a.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,a.jsx)(t.code,{children:"include"})," in ",(0,a.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,a.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,a.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,a.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,a.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,a.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,a.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,a.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,a.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,a.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,a.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(h,{...e})}):h(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>o});s(6540);var n=s(4164);const a={tabItem:"tabItem_Ymn6"};var r=s(4848);function o(e){let{children:t,hidden:s,className:o}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,n.A)(a.tabItem,o),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>w});var n=s(6540),a=s(4164),r=s(4245),o=s(6347),l=s(6494),i=s(2814),c=s(5167),u=s(9900);function d(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:a}}=e;return{value:t,label:s,attributes:n,default:a}}))}(s);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function p(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:s}=e;const a=(0,o.W6)(),r=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,i.aZ)(r),(0,n.useCallback)((e=>{if(!r)return;const t=new URLSearchParams(a.location.search);t.set(r,e),a.replace({...a.location,search:t.toString()})}),[r,a])]}function f(e){const{defaultValue:t,queryString:s=!1,groupId:a}=e,r=h(e),[o,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:r}))),[c,d]=m({queryString:s,groupId:a}),[f,j]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,r]=(0,u.Dv)(s);return[a,(0,n.useCallback)((e=>{s&&r.set(e)}),[s,r])]}({groupId:a}),g=(()=>{const e=c??f;return p({value:e,tabValues:r})?e:null})();(0,l.A)((()=>{g&&i(g)}),[g]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!p({value:e,tabValues:r}))throw new Error(`Can't select invalid tab value=${e}`);i(e),d(e),j(e)}),[d,j,r]),tabValues:r}}var j=s(1062);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=s(4848);function x(e){let{className:t,block:s,selectedValue:n,selectValue:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),u=e=>{const t=e.currentTarget,s=i.indexOf(t),a=l[s].value;a!==n&&(c(t),o(a))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const s=i.indexOf(e.currentTarget)+1;t=i[s]??i[0];break}case"ArrowLeft":{const s=i.indexOf(e.currentTarget)-1;t=i[s]??i[i.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.A)("tabs",{"tabs--block":s},t),children:l.map((e=>{let{value:t,label:s,attributes:r}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:d,onClick:u,...r,className:(0,a.A)("tabs__item",g.tabItem,r?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:r}=e;const o=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===r));return e?(0,n.cloneElement)(e,{className:(0,a.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==r})))})}function y(e){const t=f(e);return(0,b.jsxs)("div",{className:(0,a.A)("tabs-container",g.tabList),children:[(0,b.jsx)(x,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function w(e){const t=(0,j.A)();return(0,b.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>o,x:()=>l});var n=s(6540);const a={},r=n.createContext(a);function o(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/f371827f.04a303bd.js b/assets/js/f371827f.8009cbda.js similarity index 99% rename from assets/js/f371827f.04a303bd.js rename to assets/js/f371827f.8009cbda.js index 496e3e4658..90a1616cdc 100644 --- a/assets/js/f371827f.04a303bd.js +++ b/assets/js/f371827f.8009cbda.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4811],{541:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>j,frontMatter:()=>c,metadata:()=>s,toc:()=>u});const s=JSON.parse('{"id":"getting-started/options","title":"Options","description":"Introduction","source":"@site/versioned_docs/version-29.2/getting-started/options.md","sourceDirName":"getting-started","slug":"/getting-started/options","permalink":"/ts-jest/docs/getting-started/options","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/options.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"options","title":"Options"},"sidebar":"version-29.1-docs","previous":{"title":"Presets","permalink":"/ts-jest/docs/getting-started/presets"},"next":{"title":"Paths mapping","permalink":"/ts-jest/docs/getting-started/paths-mapping"}}');var r=n(4848),i=n(8453),o=n(9489),l=n(7227);const c={id:"options",title:"Options"},a=void 0,d={},u=[{value:"Introduction",id:"introduction",level:3},{value:"Options",id:"options",level:3}];function h(e){const t={a:"a",admonition:"admonition",code:"code",em:"em",h3:"h3",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,i.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.h3,{id:"introduction",children:"Introduction"}),"\n",(0,r.jsx)(t.admonition,{type:"caution",children:(0,r.jsxs)(t.p,{children:["If you are using custom ",(0,r.jsx)(t.code,{children:"transform"})," config, please remove ",(0,r.jsx)(t.code,{children:"preset"})," from your Jest config to avoid issues that Jest doesn't transform files correctly."]})}),"\n",(0,r.jsxs)(t.p,{children:["All ",(0,r.jsx)(t.code,{children:"ts-jest"})," specific options can be defined in Jest ",(0,r.jsx)(t.code,{children:"transform"})," config object in the ",(0,r.jsx)(t.code,{children:"package.json"})," file of your project,\nor through a ",(0,r.jsx)(t.code,{children:"jest.config.js"}),", or ",(0,r.jsx)(t.code,{children:"jest.config.ts"})," file."]}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\nconst { createDefaultPreset } = require('ts-jest')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n ...createDefaultPreset(),\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport { createDefaultPreset, JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n ...createDefaultPreset(),\n}\n"})})})]}),"\n",(0,r.jsx)(t.admonition,{type:"important",children:(0,r.jsxs)(t.p,{children:["When using TypeScript Jest config file, Jest will use ",(0,r.jsx)(t.code,{children:"ts-node"})," to compile the config file. ",(0,r.jsx)(t.code,{children:"ts-jest"})," doesn't take part in\nthat process."]})}),"\n",(0,r.jsx)(t.h3,{id:"options",children:"Options"}),"\n",(0,r.jsx)(t.p,{children:"All options have default values which should fit most of the projects. Click on the option's name to see details and example(s)."}),"\n",(0,r.jsxs)(t.table,{children:[(0,r.jsx)(t.thead,{children:(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.th,{children:"Option"}),(0,r.jsx)(t.th,{children:"Description"}),(0,r.jsx)(t.th,{children:"Type"}),(0,r.jsx)(t.th,{children:"Default"})]})}),(0,r.jsxs)(t.tbody,{children:[(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/compiler",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"compiler"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"string"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:'"typescript"'})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/tsconfig",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"tsconfig"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"string"}),"|",(0,r.jsx)(t.code,{children:"object"}),"|",(0,r.jsx)(t.code,{children:"boolean"})]}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"auto"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/isolatedModules",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"isolatedModules"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"boolean"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"disabled"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/astTransformers",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"astTransformers"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"object"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"auto"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/diagnostics",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"diagnostics"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"boolean"}),"|",(0,r.jsx)(t.code,{children:"object"})]}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"enabled"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/babelConfig",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"babelConfig"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"boolean"}),"|",(0,r.jsx)(t.code,{children:"string"}),"|",(0,r.jsx)(t.code,{children:"object"})]}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"disabled"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/stringifyContentPathRegex",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"stringifyContentPathRegex"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"string"}),"|",(0,r.jsx)(t.code,{children:"RegExp"})]}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"disabled"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/useESM",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"useESM"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/useESM",children:"Enable ESM support"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"boolean"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"auto"})})]})]})]})]})}function j(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var s=n(4164);const r={tabItem:"tabItem_Ymn6"};var i=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,i.jsx)("div",{role:"tabpanel",className:(0,s.A)(r.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),r=n(4164),i=n(4245),o=n(6347),l=n(6494),c=n(2814),a=n(5167),d=n(9900);function u(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return u(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:r}}=e;return{value:t,label:n,attributes:s,default:r}}))}(n);return function(e){const t=(0,a.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function j(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function p(e){let{queryString:t=!1,groupId:n}=e;const r=(0,o.W6)(),i=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,c.aZ)(i),(0,s.useCallback)((e=>{if(!i)return;const t=new URLSearchParams(r.location.search);t.set(i,e),r.replace({...r.location,search:t.toString()})}),[i,r])]}function x(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,i=h(e),[o,c]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!j({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:i}))),[a,u]=p({queryString:n,groupId:r}),[x,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,i]=(0,d.Dv)(n);return[r,(0,s.useCallback)((e=>{n&&i.set(e)}),[n,i])]}({groupId:r}),m=(()=>{const e=a??x;return j({value:e,tabValues:i})?e:null})();(0,l.A)((()=>{m&&c(m)}),[m]);return{selectedValue:o,selectValue:(0,s.useCallback)((e=>{if(!j({value:e,tabValues:i}))throw new Error(`Can't select invalid tab value=${e}`);c(e),u(e),f(e)}),[u,f,i]),tabValues:i}}var f=n(1062);const m={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=n(4848);function b(e){let{className:t,block:n,selectedValue:s,selectValue:o,tabValues:l}=e;const c=[],{blockElementScrollPositionUntilNextRender:a}=(0,i.a_)(),d=e=>{const t=e.currentTarget,n=c.indexOf(t),r=l[n].value;r!==s&&(a(t),o(r))},u=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const n=c.indexOf(e.currentTarget)+1;t=c[n]??c[0];break}case"ArrowLeft":{const n=c.indexOf(e.currentTarget)-1;t=c[n]??c[c.length-1];break}}t?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:i}=e;return(0,g.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>c.push(e),onKeyDown:u,onClick:d,...i,className:(0,r.A)("tabs__item",m.tabItem,i?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:i}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===i));return e?(0,s.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==i})))})}function y(e){const t=x(e);return(0,g.jsxs)("div",{className:(0,r.A)("tabs-container",m.tabList),children:[(0,g.jsx)(b,{...t,...e}),(0,g.jsx)(v,{...t,...e})]})}function w(e){const t=(0,f.A)();return(0,g.jsx)(y,{...e,children:u(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>l});var s=n(6540);const r={},i=s.createContext(r);function o(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4811],{541:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>j,frontMatter:()=>c,metadata:()=>s,toc:()=>u});const s=JSON.parse('{"id":"getting-started/options","title":"Options","description":"Introduction","source":"@site/versioned_docs/version-29.2/getting-started/options.md","sourceDirName":"getting-started","slug":"/getting-started/options","permalink":"/ts-jest/docs/getting-started/options","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/options.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"options","title":"Options"},"sidebar":"version-29.1-docs","previous":{"title":"Presets","permalink":"/ts-jest/docs/getting-started/presets"},"next":{"title":"Paths mapping","permalink":"/ts-jest/docs/getting-started/paths-mapping"}}');var r=n(4848),i=n(8453),o=n(9489),l=n(7227);const c={id:"options",title:"Options"},a=void 0,d={},u=[{value:"Introduction",id:"introduction",level:3},{value:"Options",id:"options",level:3}];function h(e){const t={a:"a",admonition:"admonition",code:"code",em:"em",h3:"h3",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,i.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.h3,{id:"introduction",children:"Introduction"}),"\n",(0,r.jsx)(t.admonition,{type:"caution",children:(0,r.jsxs)(t.p,{children:["If you are using custom ",(0,r.jsx)(t.code,{children:"transform"})," config, please remove ",(0,r.jsx)(t.code,{children:"preset"})," from your Jest config to avoid issues that Jest doesn't transform files correctly."]})}),"\n",(0,r.jsxs)(t.p,{children:["All ",(0,r.jsx)(t.code,{children:"ts-jest"})," specific options can be defined in Jest ",(0,r.jsx)(t.code,{children:"transform"})," config object in the ",(0,r.jsx)(t.code,{children:"package.json"})," file of your project,\nor through a ",(0,r.jsx)(t.code,{children:"jest.config.js"}),", or ",(0,r.jsx)(t.code,{children:"jest.config.ts"})," file."]}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\nconst { createDefaultPreset } = require('ts-jest')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n ...createDefaultPreset(),\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport { createDefaultPreset, JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n ...createDefaultPreset(),\n}\n"})})})]}),"\n",(0,r.jsx)(t.admonition,{type:"important",children:(0,r.jsxs)(t.p,{children:["When using TypeScript Jest config file, Jest will use ",(0,r.jsx)(t.code,{children:"ts-node"})," to compile the config file. ",(0,r.jsx)(t.code,{children:"ts-jest"})," doesn't take part in\nthat process."]})}),"\n",(0,r.jsx)(t.h3,{id:"options",children:"Options"}),"\n",(0,r.jsx)(t.p,{children:"All options have default values which should fit most of the projects. Click on the option's name to see details and example(s)."}),"\n",(0,r.jsxs)(t.table,{children:[(0,r.jsx)(t.thead,{children:(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.th,{children:"Option"}),(0,r.jsx)(t.th,{children:"Description"}),(0,r.jsx)(t.th,{children:"Type"}),(0,r.jsx)(t.th,{children:"Default"})]})}),(0,r.jsxs)(t.tbody,{children:[(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/compiler",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"compiler"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"string"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:'"typescript"'})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/tsconfig",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"tsconfig"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"string"}),"|",(0,r.jsx)(t.code,{children:"object"}),"|",(0,r.jsx)(t.code,{children:"boolean"})]}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"auto"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/isolatedModules",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"isolatedModules"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"boolean"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"disabled"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/astTransformers",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"astTransformers"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"object"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"auto"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/diagnostics",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"diagnostics"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"boolean"}),"|",(0,r.jsx)(t.code,{children:"object"})]}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"enabled"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/babelConfig",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"babelConfig"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"boolean"}),"|",(0,r.jsx)(t.code,{children:"string"}),"|",(0,r.jsx)(t.code,{children:"object"})]}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"disabled"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/stringifyContentPathRegex",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"stringifyContentPathRegex"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"string"}),"|",(0,r.jsx)(t.code,{children:"RegExp"})]}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"disabled"})})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/useESM",children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"useESM"})})})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"options/useESM",children:"Enable ESM support"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"boolean"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.em,{children:"auto"})})]})]})]})]})}function j(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var s=n(4164);const r={tabItem:"tabItem_Ymn6"};var i=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,i.jsx)("div",{role:"tabpanel",className:(0,s.A)(r.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),r=n(4164),i=n(4245),o=n(6347),l=n(6494),c=n(2814),a=n(5167),d=n(9900);function u(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return u(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:r}}=e;return{value:t,label:n,attributes:s,default:r}}))}(n);return function(e){const t=(0,a.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function j(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function p(e){let{queryString:t=!1,groupId:n}=e;const r=(0,o.W6)(),i=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,c.aZ)(i),(0,s.useCallback)((e=>{if(!i)return;const t=new URLSearchParams(r.location.search);t.set(i,e),r.replace({...r.location,search:t.toString()})}),[i,r])]}function x(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,i=h(e),[o,c]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!j({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:i}))),[a,u]=p({queryString:n,groupId:r}),[x,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,i]=(0,d.Dv)(n);return[r,(0,s.useCallback)((e=>{n&&i.set(e)}),[n,i])]}({groupId:r}),m=(()=>{const e=a??x;return j({value:e,tabValues:i})?e:null})();(0,l.A)((()=>{m&&c(m)}),[m]);return{selectedValue:o,selectValue:(0,s.useCallback)((e=>{if(!j({value:e,tabValues:i}))throw new Error(`Can't select invalid tab value=${e}`);c(e),u(e),f(e)}),[u,f,i]),tabValues:i}}var f=n(1062);const m={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=n(4848);function b(e){let{className:t,block:n,selectedValue:s,selectValue:o,tabValues:l}=e;const c=[],{blockElementScrollPositionUntilNextRender:a}=(0,i.a_)(),d=e=>{const t=e.currentTarget,n=c.indexOf(t),r=l[n].value;r!==s&&(a(t),o(r))},u=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const n=c.indexOf(e.currentTarget)+1;t=c[n]??c[0];break}case"ArrowLeft":{const n=c.indexOf(e.currentTarget)-1;t=c[n]??c[c.length-1];break}}t?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:i}=e;return(0,g.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>c.push(e),onKeyDown:u,onClick:d,...i,className:(0,r.A)("tabs__item",m.tabItem,i?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:i}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===i));return e?(0,s.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==i})))})}function y(e){const t=x(e);return(0,g.jsxs)("div",{className:(0,r.A)("tabs-container",m.tabList),children:[(0,g.jsx)(b,{...t,...e}),(0,g.jsx)(v,{...t,...e})]})}function w(e){const t=(0,f.A)();return(0,g.jsx)(y,{...e,children:u(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>l});var s=n(6540);const r={},i=s.createContext(r);function o(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/f4dd4a52.bbf579b7.js b/assets/js/f4dd4a52.b13354ac.js similarity index 99% rename from assets/js/f4dd4a52.bbf579b7.js rename to assets/js/f4dd4a52.b13354ac.js index bdf1074864..8b233e5969 100644 --- a/assets/js/f4dd4a52.bbf579b7.js +++ b/assets/js/f4dd4a52.b13354ac.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[397],{2421:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>i,metadata:()=>n,toc:()=>j});const n=JSON.parse('{"id":"getting-started/options/babelConfig","title":"Babel Config option","description":"ts-jest by default does NOT use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ts-jest can call the BabelJest processor once TypeScript has transformed the source into JavaScript.","source":"@site/versioned_docs/version-29.2/getting-started/options/babelConfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/babelConfig","permalink":"/ts-jest/docs/getting-started/options/babelConfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/options/babelConfig.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Babel Config option"}}');var r=s(4848),o=s(8453),a=s(9489),l=s(7227);const i={title:"Babel Config option"},c=void 0,u={},j=[{value:"Examples",id:"examples",level:3},{value:"Use default babelrc file",id:"use-default-babelrc-file",level:4},{value:"Path to a babelrc file",id:"path-to-a-babelrc-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4}];function d(e){const t={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"ts-jest"})," by default does ",(0,r.jsx)(t.strong,{children:"NOT"})," use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ",(0,r.jsx)(t.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,r.jsxs)(t.p,{children:["The option is ",(0,r.jsx)(t.code,{children:"babelConfig"})," and it works pretty much as the ",(0,r.jsx)(t.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"true"}),": enables Babel processing. ",(0,r.jsx)(t.code,{children:"ts-jest"})," will try to find a ",(0,r.jsx)(t.code,{children:".babelrc"}),", ",(0,r.jsx)(t.code,{children:".babelrc.js"}),", ",(0,r.jsx)(t.code,{children:"babel.config.js"})," file or a ",(0,r.jsx)(t.code,{children:"babel"})," section in the ",(0,r.jsx)(t.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,r.jsx)(t.code,{children:"babel-jest"})," processor."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"{ ... }"}),": inline ",(0,r.jsx)(t.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,r.jsx)(t.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,r.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,r.jsxs)(t.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,r.jsx)(t.code,{children:"babelrc"})," file"]}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: true,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: true,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "babelConfig": true\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsxs)(t.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,r.jsx)(t.code,{children:"babelrc"})," file"]}),"\n",(0,r.jsxs)(t.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,r.jsx)(t.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: 'babelrc.test.js',\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: 'babelrc.test.js',\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "babelConfig": "babelrc.test.js"\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsx)(t.p,{children:"or importing directly the config file:"}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: require('./babelrc.test.js'),\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\nimport babelConfig from './babelrc.test.js'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})})]}),"\n",(0,r.jsx)(t.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,r.jsxs)(t.p,{children:["Refer to the ",(0,r.jsx)(t.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: {\n comments: false,\n plugins: ['@babel/plugin-transform-for-of'],\n },\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: {\n comments: false,\n plugins: ['@babel/plugin-transform-for-of'],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "babelConfig": {\n "comments": false,\n "plugins": ["@babel/plugin-transform-for-of"]\n }\n }\n ]\n }\n }\n}\n'})})})]})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(d,{...e})}):d(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>a});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var o=s(4848);function a(e){let{children:t,hidden:s,className:a}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,a),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>w});var n=s(6540),r=s(4164),o=s(4245),a=s(6347),l=s(6494),i=s(2814),c=s(5167),u=s(9900);function j(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function d(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return j(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:r}}=e;return{value:t,label:s,attributes:n,default:r}}))}(s);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function p(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:s}=e;const r=(0,a.W6)(),o=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,i.aZ)(o),(0,n.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(r.location.search);t.set(o,e),r.replace({...r.location,search:t.toString()})}),[o,r])]}function x(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,o=d(e),[a,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:o}))),[c,j]=h({queryString:s,groupId:r}),[x,m]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,o]=(0,u.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&o.set(e)}),[s,o])]}({groupId:r}),f=(()=>{const e=c??x;return p({value:e,tabValues:o})?e:null})();(0,l.A)((()=>{f&&i(f)}),[f]);return{selectedValue:a,selectValue:(0,n.useCallback)((e=>{if(!p({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);i(e),j(e),m(e)}),[j,m,o]),tabValues:o}}var m=s(1062);const f={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=s(4848);function g(e){let{className:t,block:s,selectedValue:n,selectValue:a,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.a_)(),u=e=>{const t=e.currentTarget,s=i.indexOf(t),r=l[s].value;r!==n&&(c(t),a(r))},j=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const s=i.indexOf(e.currentTarget)+1;t=i[s]??i[0];break}case"ArrowLeft":{const s=i.indexOf(e.currentTarget)-1;t=i[s]??i[i.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":s},t),children:l.map((e=>{let{value:t,label:s,attributes:o}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:j,onClick:u,...o,className:(0,r.A)("tabs__item",f.tabItem,o?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:o}=e;const a=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=a.find((e=>e.props.value===o));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:a.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==o})))})}function y(e){const t=x(e);return(0,b.jsxs)("div",{className:(0,r.A)("tabs-container",f.tabList),children:[(0,b.jsx)(g,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function w(e){const t=(0,m.A)();return(0,b.jsx)(y,{...e,children:j(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>a,x:()=>l});var n=s(6540);const r={},o=n.createContext(r);function a(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[397],{2421:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>i,metadata:()=>n,toc:()=>j});const n=JSON.parse('{"id":"getting-started/options/babelConfig","title":"Babel Config option","description":"ts-jest by default does NOT use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ts-jest can call the BabelJest processor once TypeScript has transformed the source into JavaScript.","source":"@site/versioned_docs/version-29.2/getting-started/options/babelConfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/babelConfig","permalink":"/ts-jest/docs/getting-started/options/babelConfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/options/babelConfig.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Babel Config option"}}');var r=s(4848),o=s(8453),a=s(9489),l=s(7227);const i={title:"Babel Config option"},c=void 0,u={},j=[{value:"Examples",id:"examples",level:3},{value:"Use default babelrc file",id:"use-default-babelrc-file",level:4},{value:"Path to a babelrc file",id:"path-to-a-babelrc-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4}];function d(e){const t={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"ts-jest"})," by default does ",(0,r.jsx)(t.strong,{children:"NOT"})," use Babel. But you may want to use it, especially if your code rely on Babel plugins to make some transformations. ",(0,r.jsx)(t.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,r.jsxs)(t.p,{children:["The option is ",(0,r.jsx)(t.code,{children:"babelConfig"})," and it works pretty much as the ",(0,r.jsx)(t.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"true"}),": enables Babel processing. ",(0,r.jsx)(t.code,{children:"ts-jest"})," will try to find a ",(0,r.jsx)(t.code,{children:".babelrc"}),", ",(0,r.jsx)(t.code,{children:".babelrc.js"}),", ",(0,r.jsx)(t.code,{children:"babel.config.js"})," file or a ",(0,r.jsx)(t.code,{children:"babel"})," section in the ",(0,r.jsx)(t.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,r.jsx)(t.code,{children:"babel-jest"})," processor."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"{ ... }"}),": inline ",(0,r.jsx)(t.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,r.jsx)(t.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,r.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,r.jsxs)(t.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,r.jsx)(t.code,{children:"babelrc"})," file"]}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: true,\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: true,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "babelConfig": true\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsxs)(t.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,r.jsx)(t.code,{children:"babelrc"})," file"]}),"\n",(0,r.jsxs)(t.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,r.jsx)(t.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: 'babelrc.test.js',\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: 'babelrc.test.js',\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "babelConfig": "babelrc.test.js"\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsx)(t.p,{children:"or importing directly the config file:"}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: require('./babelrc.test.js'),\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\nimport babelConfig from './babelrc.test.js'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})})]}),"\n",(0,r.jsx)(t.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,r.jsxs)(t.p,{children:["Refer to the ",(0,r.jsx)(t.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(l.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: {\n comments: false,\n plugins: ['@babel/plugin-transform-for-of'],\n },\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(l.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n babelConfig: {\n comments: false,\n plugins: ['@babel/plugin-transform-for-of'],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(l.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "babelConfig": {\n "comments": false,\n "plugins": ["@babel/plugin-transform-for-of"]\n }\n }\n ]\n }\n }\n}\n'})})})]})]})}function p(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(d,{...e})}):d(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>a});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var o=s(4848);function a(e){let{children:t,hidden:s,className:a}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,a),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>w});var n=s(6540),r=s(4164),o=s(4245),a=s(6347),l=s(6494),i=s(2814),c=s(5167),u=s(9900);function j(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function d(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return j(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:r}}=e;return{value:t,label:s,attributes:n,default:r}}))}(s);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function p(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:s}=e;const r=(0,a.W6)(),o=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,i.aZ)(o),(0,n.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(r.location.search);t.set(o,e),r.replace({...r.location,search:t.toString()})}),[o,r])]}function x(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,o=d(e),[a,i]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:o}))),[c,j]=h({queryString:s,groupId:r}),[x,m]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,o]=(0,u.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&o.set(e)}),[s,o])]}({groupId:r}),f=(()=>{const e=c??x;return p({value:e,tabValues:o})?e:null})();(0,l.A)((()=>{f&&i(f)}),[f]);return{selectedValue:a,selectValue:(0,n.useCallback)((e=>{if(!p({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);i(e),j(e),m(e)}),[j,m,o]),tabValues:o}}var m=s(1062);const f={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=s(4848);function g(e){let{className:t,block:s,selectedValue:n,selectValue:a,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.a_)(),u=e=>{const t=e.currentTarget,s=i.indexOf(t),r=l[s].value;r!==n&&(c(t),a(r))},j=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const s=i.indexOf(e.currentTarget)+1;t=i[s]??i[0];break}case"ArrowLeft":{const s=i.indexOf(e.currentTarget)-1;t=i[s]??i[i.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":s},t),children:l.map((e=>{let{value:t,label:s,attributes:o}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:j,onClick:u,...o,className:(0,r.A)("tabs__item",f.tabItem,o?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:o}=e;const a=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=a.find((e=>e.props.value===o));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:a.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==o})))})}function y(e){const t=x(e);return(0,b.jsxs)("div",{className:(0,r.A)("tabs-container",f.tabList),children:[(0,b.jsx)(g,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function w(e){const t=(0,m.A)();return(0,b.jsx)(y,{...e,children:j(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>a,x:()=>l});var n=s(6540);const r={},o=n.createContext(r);function a(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/f6605416.f4cc3ff6.js b/assets/js/f6605416.777896e5.js similarity index 99% rename from assets/js/f6605416.f4cc3ff6.js rename to assets/js/f6605416.777896e5.js index d295235e3c..edc2199973 100644 --- a/assets/js/f6605416.f4cc3ff6.js +++ b/assets/js/f6605416.777896e5.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4343],{373:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>h,frontMatter:()=>l,metadata:()=>s,toc:()=>p});const s=JSON.parse('{"id":"getting-started/paths-mapping","title":"Paths mapping","description":"If you use \\"baseUrl\\" and \\"paths\\" options in your tsconfig file, you should make sure the \\"moduleNameMapper\\" option in your Jest config is setup accordingly.","source":"@site/versioned_docs/version-29.0/getting-started/paths-mapping.md","sourceDirName":"getting-started","slug":"/getting-started/paths-mapping","permalink":"/ts-jest/docs/29.0/getting-started/paths-mapping","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/paths-mapping.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"paths-mapping","title":"Paths mapping"},"sidebar":"version-29.0-docs","previous":{"title":"Options","permalink":"/ts-jest/docs/29.0/getting-started/options"},"next":{"title":"Version checking","permalink":"/ts-jest/docs/29.0/getting-started/version-checking"}}');var r=n(4848),o=n(8453),i=n(9489),a=n(7227);const l={id:"paths-mapping",title:"Paths mapping"},c=void 0,u={},p=[{value:"Example",id:"example",level:3},{value:"TypeScript config",id:"typescript-config",level:4},{value:"Jest config (without helper)",id:"jest-config-without-helper",level:4},{value:"Jest config (with helper)",id:"jest-config-with-helper",level:4}];function d(e){const t={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["If you use ",(0,r.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,r.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,r.jsx)(t.a,{href:"https://jestjs.io/docs/configuration#modulenamemapper-objectstring-string--arraystring",children:'"moduleNameMapper"'})," option in your Jest config is setup accordingly."]}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,r.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,r.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,r.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,r.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,r.jsxs)(t.p,{children:["With the below config in your ",(0,r.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n "compilerOptions": {\n "baseUrl": ".",\n "paths": {\n "@App/*": ["src/*"],\n "lib/*": ["common/*"]\n }\n }\n}\n'})}),"\n",(0,r.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,r.jsxs)(i.A,{groupId:"code-examples",children:[(0,r.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n moduleNameMapper: {\n '^@App/(.*)$': '/src/$1',\n '^lib/(.*)$': '/common/$1',\n },\n}\n"})})}),(0,r.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n moduleNameMapper: {\n '^@App/(.*)$': '/src/$1',\n '^lib/(.*)$': '/common/$1',\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(a.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleNameMapper": {\n "^@App/(.*)$": "/src/$1",\n "^lib/(.*)$": "/common/$1"\n }\n }\n}\n'})})})]}),"\n",(0,r.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,r.jsxs)(i.A,{groupId:"code-examples",children:[(0,r.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\nconst { pathsToModuleNameMapper } = require('ts-jest')\n// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file\n// which contains the path mapping (ie the `compilerOptions.paths` option):\nconst { compilerOptions } = require('./tsconfig')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n roots: [''],\n modulePaths: [compilerOptions.baseUrl], // <-- This will be set to 'baseUrl' value\n moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths /*, { prefix: '/' } */),\n}\n"})})}),(0,r.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport { pathsToModuleNameMapper } from 'ts-jest'\n// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file\n// which contains the path mapping (ie the `compilerOptions.paths` option):\nimport { compilerOptions } from './tsconfig'\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n roots: [''],\n modulePaths: [compilerOptions.baseUrl], // <-- This will be set to 'baseUrl' value\n moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths /*, { prefix: '/' } */),\n}\n\nexport default jestConfig\n"})})})]}),"\n",(0,r.jsx)(t.p,{children:"With extra options as 2nd argument:"}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"prefix"}),": append prefix to each of mapped config in the result"]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"useESM"}),": when using ",(0,r.jsx)(t.code,{children:"type: module"})," in ",(0,r.jsx)(t.code,{children:"package.json"}),", TypeScript enforces users to have explicit ",(0,r.jsx)(t.code,{children:"js"})," extension when importing\na ",(0,r.jsx)(t.code,{children:"ts"})," file. This option is to help ",(0,r.jsx)(t.code,{children:"pathsToModuleNameMapper"})," to create a config to suit with this scenario."]}),"\n"]})]})}function h(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(d,{...e})}):d(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>i});n(6540);var s=n(4164);const r={tabItem:"tabItem_Ymn6"};var o=n(4848);function i(e){let{children:t,hidden:n,className:i}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,s.A)(r.tabItem,i),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),r=n(4164),o=n(4245),i=n(6347),a=n(6494),l=n(2814),c=n(5167),u=n(9900);function p(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function d(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return p(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:r}}=e;return{value:t,label:n,attributes:s,default:r}}))}(n);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:n}=e;const r=(0,i.W6)(),o=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(o),(0,s.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(r.location.search);t.set(o,e),r.replace({...r.location,search:t.toString()})}),[o,r])]}function f(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,o=d(e),[i,l]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!h({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:o}))),[c,p]=m({queryString:n,groupId:r}),[f,g]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,o]=(0,u.Dv)(n);return[r,(0,s.useCallback)((e=>{n&&o.set(e)}),[n,o])]}({groupId:r}),j=(()=>{const e=c??f;return h({value:e,tabValues:o})?e:null})();(0,a.A)((()=>{j&&l(j)}),[j]);return{selectedValue:i,selectValue:(0,s.useCallback)((e=>{if(!h({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);l(e),p(e),g(e)}),[p,g,o]),tabValues:o}}var g=n(1062);const j={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=n(4848);function x(e){let{className:t,block:n,selectedValue:s,selectValue:i,tabValues:a}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.a_)(),u=e=>{const t=e.currentTarget,n=l.indexOf(t),r=a[n].value;r!==s&&(c(t),i(r))},p=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":n},t),children:a.map((e=>{let{value:t,label:n,attributes:o}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>l.push(e),onKeyDown:p,onClick:u,...o,className:(0,r.A)("tabs__item",j.tabItem,o?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:o}=e;const i=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=i.find((e=>e.props.value===o));return e?(0,s.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:i.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==o})))})}function y(e){const t=f(e);return(0,b.jsxs)("div",{className:(0,r.A)("tabs-container",j.tabList),children:[(0,b.jsx)(x,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function w(e){const t=(0,g.A)();return(0,b.jsx)(y,{...e,children:p(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>i,x:()=>a});var s=n(6540);const r={},o=s.createContext(r);function i(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4343],{373:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>h,frontMatter:()=>l,metadata:()=>s,toc:()=>p});const s=JSON.parse('{"id":"getting-started/paths-mapping","title":"Paths mapping","description":"If you use \\"baseUrl\\" and \\"paths\\" options in your tsconfig file, you should make sure the \\"moduleNameMapper\\" option in your Jest config is setup accordingly.","source":"@site/versioned_docs/version-29.0/getting-started/paths-mapping.md","sourceDirName":"getting-started","slug":"/getting-started/paths-mapping","permalink":"/ts-jest/docs/29.0/getting-started/paths-mapping","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/paths-mapping.md","tags":[],"version":"29.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"paths-mapping","title":"Paths mapping"},"sidebar":"version-29.0-docs","previous":{"title":"Options","permalink":"/ts-jest/docs/29.0/getting-started/options"},"next":{"title":"Version checking","permalink":"/ts-jest/docs/29.0/getting-started/version-checking"}}');var r=n(4848),o=n(8453),i=n(9489),a=n(7227);const l={id:"paths-mapping",title:"Paths mapping"},c=void 0,u={},p=[{value:"Example",id:"example",level:3},{value:"TypeScript config",id:"typescript-config",level:4},{value:"Jest config (without helper)",id:"jest-config-without-helper",level:4},{value:"Jest config (with helper)",id:"jest-config-with-helper",level:4}];function d(e){const t={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["If you use ",(0,r.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,r.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,r.jsx)(t.a,{href:"https://jestjs.io/docs/configuration#modulenamemapper-objectstring-string--arraystring",children:'"moduleNameMapper"'})," option in your Jest config is setup accordingly."]}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,r.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,r.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,r.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,r.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,r.jsxs)(t.p,{children:["With the below config in your ",(0,r.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n "compilerOptions": {\n "baseUrl": ".",\n "paths": {\n "@App/*": ["src/*"],\n "lib/*": ["common/*"]\n }\n }\n}\n'})}),"\n",(0,r.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,r.jsxs)(i.A,{groupId:"code-examples",children:[(0,r.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n moduleNameMapper: {\n '^@App/(.*)$': '/src/$1',\n '^lib/(.*)$': '/common/$1',\n },\n}\n"})})}),(0,r.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n moduleNameMapper: {\n '^@App/(.*)$': '/src/$1',\n '^lib/(.*)$': '/common/$1',\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(a.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleNameMapper": {\n "^@App/(.*)$": "/src/$1",\n "^lib/(.*)$": "/common/$1"\n }\n }\n}\n'})})})]}),"\n",(0,r.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,r.jsxs)(i.A,{groupId:"code-examples",children:[(0,r.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\nconst { pathsToModuleNameMapper } = require('ts-jest')\n// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file\n// which contains the path mapping (ie the `compilerOptions.paths` option):\nconst { compilerOptions } = require('./tsconfig')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n roots: [''],\n modulePaths: [compilerOptions.baseUrl], // <-- This will be set to 'baseUrl' value\n moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths /*, { prefix: '/' } */),\n}\n"})})}),(0,r.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport { pathsToModuleNameMapper } from 'ts-jest'\n// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file\n// which contains the path mapping (ie the `compilerOptions.paths` option):\nimport { compilerOptions } from './tsconfig'\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n roots: [''],\n modulePaths: [compilerOptions.baseUrl], // <-- This will be set to 'baseUrl' value\n moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths /*, { prefix: '/' } */),\n}\n\nexport default jestConfig\n"})})})]}),"\n",(0,r.jsx)(t.p,{children:"With extra options as 2nd argument:"}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"prefix"}),": append prefix to each of mapped config in the result"]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"useESM"}),": when using ",(0,r.jsx)(t.code,{children:"type: module"})," in ",(0,r.jsx)(t.code,{children:"package.json"}),", TypeScript enforces users to have explicit ",(0,r.jsx)(t.code,{children:"js"})," extension when importing\na ",(0,r.jsx)(t.code,{children:"ts"})," file. This option is to help ",(0,r.jsx)(t.code,{children:"pathsToModuleNameMapper"})," to create a config to suit with this scenario."]}),"\n"]})]})}function h(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(d,{...e})}):d(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>i});n(6540);var s=n(4164);const r={tabItem:"tabItem_Ymn6"};var o=n(4848);function i(e){let{children:t,hidden:n,className:i}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,s.A)(r.tabItem,i),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),r=n(4164),o=n(4245),i=n(6347),a=n(6494),l=n(2814),c=n(5167),u=n(9900);function p(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function d(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return p(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:r}}=e;return{value:t,label:n,attributes:s,default:r}}))}(n);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:n}=e;const r=(0,i.W6)(),o=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(o),(0,s.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(r.location.search);t.set(o,e),r.replace({...r.location,search:t.toString()})}),[o,r])]}function f(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,o=d(e),[i,l]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!h({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:o}))),[c,p]=m({queryString:n,groupId:r}),[f,g]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,o]=(0,u.Dv)(n);return[r,(0,s.useCallback)((e=>{n&&o.set(e)}),[n,o])]}({groupId:r}),j=(()=>{const e=c??f;return h({value:e,tabValues:o})?e:null})();(0,a.A)((()=>{j&&l(j)}),[j]);return{selectedValue:i,selectValue:(0,s.useCallback)((e=>{if(!h({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);l(e),p(e),g(e)}),[p,g,o]),tabValues:o}}var g=n(1062);const j={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=n(4848);function x(e){let{className:t,block:n,selectedValue:s,selectValue:i,tabValues:a}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.a_)(),u=e=>{const t=e.currentTarget,n=l.indexOf(t),r=a[n].value;r!==s&&(c(t),i(r))},p=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":n},t),children:a.map((e=>{let{value:t,label:n,attributes:o}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>l.push(e),onKeyDown:p,onClick:u,...o,className:(0,r.A)("tabs__item",j.tabItem,o?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:o}=e;const i=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=i.find((e=>e.props.value===o));return e?(0,s.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:i.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==o})))})}function y(e){const t=f(e);return(0,b.jsxs)("div",{className:(0,r.A)("tabs-container",j.tabList),children:[(0,b.jsx)(x,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function w(e){const t=(0,g.A)();return(0,b.jsx)(y,{...e,children:p(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>i,x:()=>a});var s=n(6540);const r={},o=s.createContext(r);function i(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/f6aab920.88ecf1a3.js b/assets/js/f6aab920.23d6e4b0.js similarity index 98% rename from assets/js/f6aab920.88ecf1a3.js rename to assets/js/f6aab920.23d6e4b0.js index d2dc9cf9c2..8b9bfc6b00 100644 --- a/assets/js/f6aab920.88ecf1a3.js +++ b/assets/js/f6aab920.23d6e4b0.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7320],{4100:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>r,contentTitle:()=>l,default:()=>p,frontMatter:()=>c,metadata:()=>o,toc:()=>a});const o=JSON.parse('{"id":"getting-started/options/tsconfig","title":"TypeScript Config option","description":"The tsconfig option allows you to define which tsconfig JSON file to use. An inline compiler options object can also be specified instead of a file path.","source":"@site/versioned_docs/version-26.5/getting-started/options/tsconfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/tsconfig","permalink":"/ts-jest/docs/26.5/getting-started/options/tsconfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/getting-started/options/tsconfig.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"TypeScript Config option"}}');var s=t(4848),i=t(8453);const c={title:"TypeScript Config option"},l=void 0,r={},a=[{value:"Examples",id:"examples",level:3},{value:"Path to a tsconfig file",id:"path-to-a-tsconfig-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4},{value:"Disable auto-lookup",id:"disable-auto-lookup",level:4}];function d(e){const n={a:"a",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"tsconfig"})," option allows you to define which ",(0,s.jsx)(n.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,s.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," object can also be specified instead of a file path."]}),"\n",(0,s.jsxs)(n.p,{children:["By default ",(0,s.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,s.jsx)(n.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,s.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,s.jsx)(n.code,{children:"ES2015"})," is used as ",(0,s.jsx)(n.code,{children:"target"})," instead of ",(0,s.jsx)(n.code,{children:"ES5"}),"."]}),"\n",(0,s.jsxs)(n.p,{children:["If you need to use defaults and force ",(0,s.jsx)(n.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,s.jsx)(n.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,s.jsx)(n.code,{children:"false"}),"."]}),"\n",(0,s.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,s.jsxs)(n.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,s.jsx)(n.code,{children:"tsconfig"})," file"]}),"\n",(0,s.jsxs)(n.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,s.jsx)(n.code,{children:""})," in the path to start from the project root dir."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n tsconfig: 'tsconfig.test.json',\n },\n },\n}\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "tsconfig": "tsconfig.test.json"\n }\n }\n }\n}\n'})}),"\n",(0,s.jsx)(n.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,s.jsxs)(n.p,{children:["Refer to the TypeScript ",(0,s.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," for reference.\nIt's basically the same object you'd put in your ",(0,s.jsx)(n.code,{children:"tsconfig.json"}),"'s ",(0,s.jsx)(n.code,{children:"compilerOptions"}),"."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n tsconfig: {\n importHelpers: true,\n },\n },\n },\n}\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "tsconfig": {\n "importHelpers": true\n }\n }\n }\n }\n}\n'})}),"\n",(0,s.jsx)(n.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,s.jsxs)(n.p,{children:["By default ",(0,s.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,s.jsx)(n.code,{children:"tsconfig.json"})," in your project. But you may not want to use it at all and keep TypeScript default options. You can achieve this by setting ",(0,s.jsx)(n.code,{children:"tsconfig"})," to ",(0,s.jsx)(n.code,{children:"false"}),"."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n tsconfig: false,\n },\n },\n}\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "tsconfig": false\n }\n }\n }\n}\n'})})]})}function p(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>c,x:()=>l});var o=t(6540);const s={},i=o.createContext(s);function c(e){const n=o.useContext(i);return o.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:c(e.components),o.createElement(i.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7320],{4100:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>r,contentTitle:()=>l,default:()=>p,frontMatter:()=>c,metadata:()=>o,toc:()=>a});const o=JSON.parse('{"id":"getting-started/options/tsconfig","title":"TypeScript Config option","description":"The tsconfig option allows you to define which tsconfig JSON file to use. An inline compiler options object can also be specified instead of a file path.","source":"@site/versioned_docs/version-26.5/getting-started/options/tsconfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/tsconfig","permalink":"/ts-jest/docs/26.5/getting-started/options/tsconfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/getting-started/options/tsconfig.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"TypeScript Config option"}}');var s=t(4848),i=t(8453);const c={title:"TypeScript Config option"},l=void 0,r={},a=[{value:"Examples",id:"examples",level:3},{value:"Path to a tsconfig file",id:"path-to-a-tsconfig-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4},{value:"Disable auto-lookup",id:"disable-auto-lookup",level:4}];function d(e){const n={a:"a",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"tsconfig"})," option allows you to define which ",(0,s.jsx)(n.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,s.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," object can also be specified instead of a file path."]}),"\n",(0,s.jsxs)(n.p,{children:["By default ",(0,s.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,s.jsx)(n.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,s.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,s.jsx)(n.code,{children:"ES2015"})," is used as ",(0,s.jsx)(n.code,{children:"target"})," instead of ",(0,s.jsx)(n.code,{children:"ES5"}),"."]}),"\n",(0,s.jsxs)(n.p,{children:["If you need to use defaults and force ",(0,s.jsx)(n.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,s.jsx)(n.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,s.jsx)(n.code,{children:"false"}),"."]}),"\n",(0,s.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,s.jsxs)(n.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,s.jsx)(n.code,{children:"tsconfig"})," file"]}),"\n",(0,s.jsxs)(n.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,s.jsx)(n.code,{children:""})," in the path to start from the project root dir."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n tsconfig: 'tsconfig.test.json',\n },\n },\n}\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "tsconfig": "tsconfig.test.json"\n }\n }\n }\n}\n'})}),"\n",(0,s.jsx)(n.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,s.jsxs)(n.p,{children:["Refer to the TypeScript ",(0,s.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," for reference.\nIt's basically the same object you'd put in your ",(0,s.jsx)(n.code,{children:"tsconfig.json"}),"'s ",(0,s.jsx)(n.code,{children:"compilerOptions"}),"."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n tsconfig: {\n importHelpers: true,\n },\n },\n },\n}\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "tsconfig": {\n "importHelpers": true\n }\n }\n }\n }\n}\n'})}),"\n",(0,s.jsx)(n.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,s.jsxs)(n.p,{children:["By default ",(0,s.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,s.jsx)(n.code,{children:"tsconfig.json"})," in your project. But you may not want to use it at all and keep TypeScript default options. You can achieve this by setting ",(0,s.jsx)(n.code,{children:"tsconfig"})," to ",(0,s.jsx)(n.code,{children:"false"}),"."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n tsconfig: false,\n },\n },\n}\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "tsconfig": false\n }\n }\n }\n}\n'})})]})}function p(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>c,x:()=>l});var o=t(6540);const s={},i=o.createContext(s);function c(e){const n=o.useContext(i);return o.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:c(e.components),o.createElement(i.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/f6f550ec.c49076a5.js b/assets/js/f6f550ec.6ebd70e3.js similarity index 99% rename from assets/js/f6f550ec.c49076a5.js rename to assets/js/f6f550ec.6ebd70e3.js index 9633ab17ed..6969a01a91 100644 --- a/assets/js/f6f550ec.c49076a5.js +++ b/assets/js/f6f550ec.6ebd70e3.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[983],{4914:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>p,contentTitle:()=>c,default:()=>h,frontMatter:()=>l,metadata:()=>s,toc:()=>u});const s=JSON.parse('{"id":"getting-started/paths-mapping","title":"Paths mapping","description":"If you use \\"baseUrl\\" and \\"paths\\" options in your tsconfig file, you should make sure the \\"moduleNameMapper\\" option in your Jest config is setup accordingly.","source":"@site/versioned_docs/version-29.2/getting-started/paths-mapping.md","sourceDirName":"getting-started","slug":"/getting-started/paths-mapping","permalink":"/ts-jest/docs/getting-started/paths-mapping","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/paths-mapping.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"paths-mapping","title":"Paths mapping"},"sidebar":"version-29.1-docs","previous":{"title":"Options","permalink":"/ts-jest/docs/getting-started/options"},"next":{"title":"Version checking","permalink":"/ts-jest/docs/getting-started/version-checking"}}');var o=n(4848),r=n(8453),a=n(9489),i=n(7227);const l={id:"paths-mapping",title:"Paths mapping"},c=void 0,p={},u=[{value:"Example",id:"example",level:3},{value:"TypeScript config",id:"typescript-config",level:4},{value:"Jest config (without helper)",id:"jest-config-without-helper",level:4},{value:"Jest config (with helper)",id:"jest-config-with-helper",level:4},{value:"If using globalSetup or globalTeardown",id:"if-using-globalsetup-or-globalteardown",level:4},{value:"Global setup file with tsconfig-paths",id:"global-setup-file-with-tsconfig-paths",level:5}];function d(e){const t={a:"a",code:"code",h3:"h3",h4:"h4",h5:"h5",li:"li",p:"p",pre:"pre",ul:"ul",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["If you use ",(0,o.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,o.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,o.jsx)(t.a,{href:"https://jestjs.io/docs/configuration#modulenamemapper-objectstring-string--arraystring",children:'"moduleNameMapper"'})," option in your Jest config is setup accordingly."]}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,o.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,o.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,o.jsxs)(t.p,{children:["With the below config in your ",(0,o.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n "compilerOptions": {\n "baseUrl": ".",\n "paths": {\n "@App/*": ["src/*"],\n "lib/*": ["common/*"]\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,o.jsxs)(a.A,{groupId:"code-examples",children:[(0,o.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n moduleNameMapper: {\n '^@App/(.*)$': '/src/$1',\n '^lib/(.*)$': '/common/$1',\n },\n}\n"})})}),(0,o.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n moduleNameMapper: {\n '^@App/(.*)$': '/src/$1',\n '^lib/(.*)$': '/common/$1',\n },\n}\n\nexport default jestConfig\n"})})}),(0,o.jsx)(i.A,{value:"JSON",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleNameMapper": {\n "^@App/(.*)$": "/src/$1",\n "^lib/(.*)$": "/common/$1"\n }\n }\n}\n'})})})]}),"\n",(0,o.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,o.jsxs)(a.A,{groupId:"code-examples",children:[(0,o.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\nconst { pathsToModuleNameMapper } = require('ts-jest')\n// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file\n// which contains the path mapping (ie the `compilerOptions.paths` option):\nconst { compilerOptions } = require('./tsconfig')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n roots: [''],\n modulePaths: [compilerOptions.baseUrl], // <-- This will be set to 'baseUrl' value\n moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths /*, { prefix: '/' } */),\n}\n"})})}),(0,o.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport { pathsToModuleNameMapper } from 'ts-jest'\n// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file\n// which contains the path mapping (ie the `compilerOptions.paths` option):\nimport { compilerOptions } from './tsconfig'\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n roots: [''],\n modulePaths: [compilerOptions.baseUrl], // <-- This will be set to 'baseUrl' value\n moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths /*, { prefix: '/' } */),\n}\n\nexport default jestConfig\n"})})})]}),"\n",(0,o.jsx)(t.p,{children:"With extra options as 2nd argument:"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsxs)(t.li,{children:[(0,o.jsx)(t.code,{children:"prefix"}),": append prefix to each of mapped config in the result"]}),"\n",(0,o.jsxs)(t.li,{children:[(0,o.jsx)(t.code,{children:"useESM"}),": when using ",(0,o.jsx)(t.code,{children:"type: module"})," in ",(0,o.jsx)(t.code,{children:"package.json"}),", TypeScript enforces users to have explicit ",(0,o.jsx)(t.code,{children:"js"})," extension when importing\na ",(0,o.jsx)(t.code,{children:"ts"})," file. This option is to help ",(0,o.jsx)(t.code,{children:"pathsToModuleNameMapper"})," to create a config to suit with this scenario."]}),"\n"]}),"\n",(0,o.jsxs)(t.h4,{id:"if-using-globalsetup-or-globalteardown",children:["If using ",(0,o.jsx)(t.code,{children:"globalSetup"})," or ",(0,o.jsx)(t.code,{children:"globalTeardown"})]}),"\n",(0,o.jsxs)(t.p,{children:["Files used for ",(0,o.jsx)(t.a,{href:"https://jestjs.io/docs/configuration#globalsetup-string",children:(0,o.jsx)(t.code,{children:"globalSetup"})})," or ",(0,o.jsx)(t.a,{href:"https://jestjs.io/docs/configuration#globalteardown-string",children:(0,o.jsx)(t.code,{children:"globalTeardown"})})," are not directly processes by ",(0,o.jsx)(t.code,{children:"jest"}),", so those do not use the ",(0,o.jsx)(t.a,{href:"https://jestjs.io/docs/configuration#modulenamemapper-objectstring-string--arraystring",children:'"moduleNameMapper"'})," mapping. So you have to make sure those are able to map the paths themselves."]}),"\n",(0,o.jsxs)(t.h5,{id:"global-setup-file-with-tsconfig-paths",children:["Global setup file with ",(0,o.jsx)(t.code,{children:"tsconfig-paths"})]}),"\n",(0,o.jsxs)(t.p,{children:["For those files to be able to use ",(0,o.jsx)(t.a,{href:"https://www.npmjs.com/package/tsconfig-paths",children:(0,o.jsx)(t.code,{children:"tsconfig-paths"})}),", you have to import it directly"]}),"\n",(0,o.jsxs)(a.A,{groupId:"code-examples",children:[(0,o.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// ./path/to/globalSetup.js\nrequire('tsconfig-paths/register')\n\n/**\n * Your global setup\n */\n\n// ./path/to/globalTeardown.js\nrequire('tsconfig-paths/register')\n\n/**\n * Your global teardown\n */\n"})})}),(0,o.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// ./path/to/globalSetup.ts\nimport 'tsconfig-paths/register'\n\n/**\n * Your global setup\n */\n\n// ./path/to/globalTeardown.ts\nimport 'tsconfig-paths/register'\n\n/**\n * Your global teardown\n */\n"})})})]})]})}function h(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>a});n(6540);var s=n(4164);const o={tabItem:"tabItem_Ymn6"};var r=n(4848);function a(e){let{children:t,hidden:n,className:a}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,s.A)(o.tabItem,a),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>y});var s=n(6540),o=n(4164),r=n(4245),a=n(6347),i=n(6494),l=n(2814),c=n(5167),p=n(9900);function u(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function d(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return u(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:o}}=e;return{value:t,label:n,attributes:s,default:o}}))}(n);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function g(e){let{queryString:t=!1,groupId:n}=e;const o=(0,a.W6)(),r=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(r),(0,s.useCallback)((e=>{if(!r)return;const t=new URLSearchParams(o.location.search);t.set(r,e),o.replace({...o.location,search:t.toString()})}),[r,o])]}function m(e){const{defaultValue:t,queryString:n=!1,groupId:o}=e,r=d(e),[a,l]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!h({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:r}))),[c,u]=g({queryString:n,groupId:o}),[m,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[o,r]=(0,p.Dv)(n);return[o,(0,s.useCallback)((e=>{n&&r.set(e)}),[n,r])]}({groupId:o}),j=(()=>{const e=c??m;return h({value:e,tabValues:r})?e:null})();(0,i.A)((()=>{j&&l(j)}),[j]);return{selectedValue:a,selectValue:(0,s.useCallback)((e=>{if(!h({value:e,tabValues:r}))throw new Error(`Can't select invalid tab value=${e}`);l(e),u(e),f(e)}),[u,f,r]),tabValues:r}}var f=n(1062);const j={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=n(4848);function x(e){let{className:t,block:n,selectedValue:s,selectValue:a,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),p=e=>{const t=e.currentTarget,n=l.indexOf(t),o=i[n].value;o!==s&&(c(t),a(o))},u=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.A)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:r}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>l.push(e),onKeyDown:u,onClick:p,...r,className:(0,o.A)("tabs__item",j.tabItem,r?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:r}=e;const a=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=a.find((e=>e.props.value===r));return e?(0,s.cloneElement)(e,{className:(0,o.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:a.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==r})))})}function w(e){const t=m(e);return(0,b.jsxs)("div",{className:(0,o.A)("tabs-container",j.tabList),children:[(0,b.jsx)(x,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function y(e){const t=(0,f.A)();return(0,b.jsx)(w,{...e,children:u(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>a,x:()=>i});var s=n(6540);const o={},r=s.createContext(o);function a(e){const t=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[983],{4914:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>p,contentTitle:()=>c,default:()=>h,frontMatter:()=>l,metadata:()=>s,toc:()=>u});const s=JSON.parse('{"id":"getting-started/paths-mapping","title":"Paths mapping","description":"If you use \\"baseUrl\\" and \\"paths\\" options in your tsconfig file, you should make sure the \\"moduleNameMapper\\" option in your Jest config is setup accordingly.","source":"@site/versioned_docs/version-29.2/getting-started/paths-mapping.md","sourceDirName":"getting-started","slug":"/getting-started/paths-mapping","permalink":"/ts-jest/docs/getting-started/paths-mapping","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/paths-mapping.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"paths-mapping","title":"Paths mapping"},"sidebar":"version-29.1-docs","previous":{"title":"Options","permalink":"/ts-jest/docs/getting-started/options"},"next":{"title":"Version checking","permalink":"/ts-jest/docs/getting-started/version-checking"}}');var o=n(4848),r=n(8453),a=n(9489),i=n(7227);const l={id:"paths-mapping",title:"Paths mapping"},c=void 0,p={},u=[{value:"Example",id:"example",level:3},{value:"TypeScript config",id:"typescript-config",level:4},{value:"Jest config (without helper)",id:"jest-config-without-helper",level:4},{value:"Jest config (with helper)",id:"jest-config-with-helper",level:4},{value:"If using globalSetup or globalTeardown",id:"if-using-globalsetup-or-globalteardown",level:4},{value:"Global setup file with tsconfig-paths",id:"global-setup-file-with-tsconfig-paths",level:5}];function d(e){const t={a:"a",code:"code",h3:"h3",h4:"h4",h5:"h5",li:"li",p:"p",pre:"pre",ul:"ul",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["If you use ",(0,o.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,o.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,o.jsx)(t.a,{href:"https://jestjs.io/docs/configuration#modulenamemapper-objectstring-string--arraystring",children:'"moduleNameMapper"'})," option in your Jest config is setup accordingly."]}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,o.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,o.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,o.jsxs)(t.p,{children:["With the below config in your ",(0,o.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n "compilerOptions": {\n "baseUrl": ".",\n "paths": {\n "@App/*": ["src/*"],\n "lib/*": ["common/*"]\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,o.jsxs)(a.A,{groupId:"code-examples",children:[(0,o.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n moduleNameMapper: {\n '^@App/(.*)$': '/src/$1',\n '^lib/(.*)$': '/common/$1',\n },\n}\n"})})}),(0,o.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n moduleNameMapper: {\n '^@App/(.*)$': '/src/$1',\n '^lib/(.*)$': '/common/$1',\n },\n}\n\nexport default jestConfig\n"})})}),(0,o.jsx)(i.A,{value:"JSON",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleNameMapper": {\n "^@App/(.*)$": "/src/$1",\n "^lib/(.*)$": "/common/$1"\n }\n }\n}\n'})})})]}),"\n",(0,o.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,o.jsxs)(a.A,{groupId:"code-examples",children:[(0,o.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\nconst { pathsToModuleNameMapper } = require('ts-jest')\n// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file\n// which contains the path mapping (ie the `compilerOptions.paths` option):\nconst { compilerOptions } = require('./tsconfig')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n roots: [''],\n modulePaths: [compilerOptions.baseUrl], // <-- This will be set to 'baseUrl' value\n moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths /*, { prefix: '/' } */),\n}\n"})})}),(0,o.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport { pathsToModuleNameMapper } from 'ts-jest'\n// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file\n// which contains the path mapping (ie the `compilerOptions.paths` option):\nimport { compilerOptions } from './tsconfig'\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n roots: [''],\n modulePaths: [compilerOptions.baseUrl], // <-- This will be set to 'baseUrl' value\n moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths /*, { prefix: '/' } */),\n}\n\nexport default jestConfig\n"})})})]}),"\n",(0,o.jsx)(t.p,{children:"With extra options as 2nd argument:"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsxs)(t.li,{children:[(0,o.jsx)(t.code,{children:"prefix"}),": append prefix to each of mapped config in the result"]}),"\n",(0,o.jsxs)(t.li,{children:[(0,o.jsx)(t.code,{children:"useESM"}),": when using ",(0,o.jsx)(t.code,{children:"type: module"})," in ",(0,o.jsx)(t.code,{children:"package.json"}),", TypeScript enforces users to have explicit ",(0,o.jsx)(t.code,{children:"js"})," extension when importing\na ",(0,o.jsx)(t.code,{children:"ts"})," file. This option is to help ",(0,o.jsx)(t.code,{children:"pathsToModuleNameMapper"})," to create a config to suit with this scenario."]}),"\n"]}),"\n",(0,o.jsxs)(t.h4,{id:"if-using-globalsetup-or-globalteardown",children:["If using ",(0,o.jsx)(t.code,{children:"globalSetup"})," or ",(0,o.jsx)(t.code,{children:"globalTeardown"})]}),"\n",(0,o.jsxs)(t.p,{children:["Files used for ",(0,o.jsx)(t.a,{href:"https://jestjs.io/docs/configuration#globalsetup-string",children:(0,o.jsx)(t.code,{children:"globalSetup"})})," or ",(0,o.jsx)(t.a,{href:"https://jestjs.io/docs/configuration#globalteardown-string",children:(0,o.jsx)(t.code,{children:"globalTeardown"})})," are not directly processes by ",(0,o.jsx)(t.code,{children:"jest"}),", so those do not use the ",(0,o.jsx)(t.a,{href:"https://jestjs.io/docs/configuration#modulenamemapper-objectstring-string--arraystring",children:'"moduleNameMapper"'})," mapping. So you have to make sure those are able to map the paths themselves."]}),"\n",(0,o.jsxs)(t.h5,{id:"global-setup-file-with-tsconfig-paths",children:["Global setup file with ",(0,o.jsx)(t.code,{children:"tsconfig-paths"})]}),"\n",(0,o.jsxs)(t.p,{children:["For those files to be able to use ",(0,o.jsx)(t.a,{href:"https://www.npmjs.com/package/tsconfig-paths",children:(0,o.jsx)(t.code,{children:"tsconfig-paths"})}),", you have to import it directly"]}),"\n",(0,o.jsxs)(a.A,{groupId:"code-examples",children:[(0,o.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// ./path/to/globalSetup.js\nrequire('tsconfig-paths/register')\n\n/**\n * Your global setup\n */\n\n// ./path/to/globalTeardown.js\nrequire('tsconfig-paths/register')\n\n/**\n * Your global teardown\n */\n"})})}),(0,o.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// ./path/to/globalSetup.ts\nimport 'tsconfig-paths/register'\n\n/**\n * Your global setup\n */\n\n// ./path/to/globalTeardown.ts\nimport 'tsconfig-paths/register'\n\n/**\n * Your global teardown\n */\n"})})})]})]})}function h(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>a});n(6540);var s=n(4164);const o={tabItem:"tabItem_Ymn6"};var r=n(4848);function a(e){let{children:t,hidden:n,className:a}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,s.A)(o.tabItem,a),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>y});var s=n(6540),o=n(4164),r=n(4245),a=n(6347),i=n(6494),l=n(2814),c=n(5167),p=n(9900);function u(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function d(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return u(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:o}}=e;return{value:t,label:n,attributes:s,default:o}}))}(n);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function g(e){let{queryString:t=!1,groupId:n}=e;const o=(0,a.W6)(),r=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(r),(0,s.useCallback)((e=>{if(!r)return;const t=new URLSearchParams(o.location.search);t.set(r,e),o.replace({...o.location,search:t.toString()})}),[r,o])]}function m(e){const{defaultValue:t,queryString:n=!1,groupId:o}=e,r=d(e),[a,l]=(0,s.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!h({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:r}))),[c,u]=g({queryString:n,groupId:o}),[m,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[o,r]=(0,p.Dv)(n);return[o,(0,s.useCallback)((e=>{n&&r.set(e)}),[n,r])]}({groupId:o}),j=(()=>{const e=c??m;return h({value:e,tabValues:r})?e:null})();(0,i.A)((()=>{j&&l(j)}),[j]);return{selectedValue:a,selectValue:(0,s.useCallback)((e=>{if(!h({value:e,tabValues:r}))throw new Error(`Can't select invalid tab value=${e}`);l(e),u(e),f(e)}),[u,f,r]),tabValues:r}}var f=n(1062);const j={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=n(4848);function x(e){let{className:t,block:n,selectedValue:s,selectValue:a,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),p=e=>{const t=e.currentTarget,n=l.indexOf(t),o=i[n].value;o!==s&&(c(t),a(o))},u=e=>{let t=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.A)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:r}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>l.push(e),onKeyDown:u,onClick:p,...r,className:(0,o.A)("tabs__item",j.tabItem,r?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:r}=e;const a=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=a.find((e=>e.props.value===r));return e?(0,s.cloneElement)(e,{className:(0,o.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:a.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==r})))})}function w(e){const t=m(e);return(0,b.jsxs)("div",{className:(0,o.A)("tabs-container",j.tabList),children:[(0,b.jsx)(x,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function y(e){const t=(0,f.A)();return(0,b.jsx)(w,{...e,children:u(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>a,x:()=>i});var s=n(6540);const o={},r=s.createContext(o);function a(e){const t=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/f7416098.6d7831a2.js b/assets/js/f7416098.99e20882.js similarity index 98% rename from assets/js/f7416098.6d7831a2.js rename to assets/js/f7416098.99e20882.js index a2192bc2b7..7743cebc31 100644 --- a/assets/js/f7416098.6d7831a2.js +++ b/assets/js/f7416098.99e20882.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2186],{4281:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>p,default:()=>d,frontMatter:()=>r,metadata:()=>s,toc:()=>c});const s=JSON.parse('{"id":"getting-started/paths-mapping","title":"Paths mapping","description":"If you use \\"baseUrl\\" and \\"paths\\" options in your tsconfig file, you should make sure the \\"moduleNameMapper\\" option in your Jest config is setup accordingly.","source":"@site/versioned_docs/version-27.0/getting-started/paths-mapping.md","sourceDirName":"getting-started","slug":"/getting-started/paths-mapping","permalink":"/ts-jest/docs/27.0/getting-started/paths-mapping","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/paths-mapping.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"paths-mapping","title":"Paths mapping"},"sidebar":"version-27.0-docs","previous":{"title":"Options","permalink":"/ts-jest/docs/27.0/getting-started/options"},"next":{"title":"Version checking","permalink":"/ts-jest/docs/27.0/getting-started/version-checking"}}');var o=n(4848),i=n(8453);const r={id:"paths-mapping",title:"Paths mapping"},p=void 0,a={},c=[{value:"Example",id:"example",level:3},{value:"TypeScript config",id:"typescript-config",level:4},{value:"Jest config (without helper)",id:"jest-config-without-helper",level:4},{value:"Jest config (with helper)",id:"jest-config-with-helper",level:4}];function l(e){const t={a:"a",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["If you use ",(0,o.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,o.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,o.jsx)(t.a,{href:"https://jestjs.io/docs/configuration#modulenamemapper-objectstring-string--arraystring",children:'"moduleNameMapper"'})," option in your Jest config is setup accordingly."]}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,o.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,o.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,o.jsxs)(t.p,{children:["With the below config in your ",(0,o.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n "compilerOptions": {\n "baseUrl": ".",\n "paths": {\n "@App/*": ["src/*"],\n "lib/*": ["common/*"]\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n moduleNameMapper: {\n '^@App/(.*)$': '/src/$1',\n '^lib/(.*)$': '/common/$1',\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleNameMapper": {\n "^@App/(.*)$": "/src/$1",\n "^lib/(.*)$": "/common/$1"\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nconst { pathsToModuleNameMapper } = require('ts-jest/utils')\n// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file\n// which contains the path mapping (ie the `compilerOptions.paths` option):\nconst { compilerOptions } = require('./tsconfig')\n\nmodule.exports = {\n // [...]\n roots: [''],\n modulePaths: [compilerOptions.baseUrl], // <-- This will be set to 'baseUrl' value\n moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths /*, { prefix: '/' } */),\n}\n"})})]})}function d(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>p});var s=n(6540);const o={},i=s.createContext(o);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function p(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2186],{4281:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>p,default:()=>d,frontMatter:()=>r,metadata:()=>s,toc:()=>c});const s=JSON.parse('{"id":"getting-started/paths-mapping","title":"Paths mapping","description":"If you use \\"baseUrl\\" and \\"paths\\" options in your tsconfig file, you should make sure the \\"moduleNameMapper\\" option in your Jest config is setup accordingly.","source":"@site/versioned_docs/version-27.0/getting-started/paths-mapping.md","sourceDirName":"getting-started","slug":"/getting-started/paths-mapping","permalink":"/ts-jest/docs/27.0/getting-started/paths-mapping","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/paths-mapping.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"paths-mapping","title":"Paths mapping"},"sidebar":"version-27.0-docs","previous":{"title":"Options","permalink":"/ts-jest/docs/27.0/getting-started/options"},"next":{"title":"Version checking","permalink":"/ts-jest/docs/27.0/getting-started/version-checking"}}');var o=n(4848),i=n(8453);const r={id:"paths-mapping",title:"Paths mapping"},p=void 0,a={},c=[{value:"Example",id:"example",level:3},{value:"TypeScript config",id:"typescript-config",level:4},{value:"Jest config (without helper)",id:"jest-config-without-helper",level:4},{value:"Jest config (with helper)",id:"jest-config-with-helper",level:4}];function l(e){const t={a:"a",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["If you use ",(0,o.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,o.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,o.jsx)(t.a,{href:"https://jestjs.io/docs/configuration#modulenamemapper-objectstring-string--arraystring",children:'"moduleNameMapper"'})," option in your Jest config is setup accordingly."]}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,o.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,o.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,o.jsxs)(t.p,{children:["With the below config in your ",(0,o.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n "compilerOptions": {\n "baseUrl": ".",\n "paths": {\n "@App/*": ["src/*"],\n "lib/*": ["common/*"]\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n moduleNameMapper: {\n '^@App/(.*)$': '/src/$1',\n '^lib/(.*)$': '/common/$1',\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleNameMapper": {\n "^@App/(.*)$": "/src/$1",\n "^lib/(.*)$": "/common/$1"\n }\n }\n}\n'})}),"\n",(0,o.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nconst { pathsToModuleNameMapper } = require('ts-jest/utils')\n// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file\n// which contains the path mapping (ie the `compilerOptions.paths` option):\nconst { compilerOptions } = require('./tsconfig')\n\nmodule.exports = {\n // [...]\n roots: [''],\n modulePaths: [compilerOptions.baseUrl], // <-- This will be set to 'baseUrl' value\n moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths /*, { prefix: '/' } */),\n}\n"})})]})}function d(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>p});var s=n(6540);const o={},i=s.createContext(o);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function p(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/f7862b07.8de16ae5.js b/assets/js/f7862b07.88c0d675.js similarity index 98% rename from assets/js/f7862b07.8de16ae5.js rename to assets/js/f7862b07.88c0d675.js index 9a97a6da80..3b118bf5e1 100644 --- a/assets/js/f7862b07.8de16ae5.js +++ b/assets/js/f7862b07.88c0d675.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8539],{6830:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>d,frontMatter:()=>r,metadata:()=>n,toc:()=>h});const n=JSON.parse('{"id":"contributing","title":"Contributing","description":"When contributing to this repository, please first discuss the change you wish to make via ts-jest GitHub discussion or issue with the owners of this repository before making a change.","source":"@site/versioned_docs/version-26.5/contributing.md","sourceDirName":".","slug":"/contributing","permalink":"/ts-jest/docs/26.5/contributing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/contributing.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"contributing","title":"Contributing"},"sidebar":"version-26.5-docs","previous":{"title":"Processing flow","permalink":"/ts-jest/docs/26.5/processing"},"next":{"title":"Installation","permalink":"/ts-jest/docs/26.5/getting-started/installation"}}');var i=s(4848),o=s(8453);const r={id:"contributing",title:"Contributing"},c=void 0,a={},h=[{value:"Pull Request Process",id:"pull-request-process",level:2},{value:"E2E Testing",id:"e2e-testing",level:2},{value:"Preparing",id:"preparing",level:3},{value:"Running",id:"running",level:3}];function l(e){const t={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,i.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,i.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,i.jsx)(t.a,{href:"https://github.com/kulshekhar/ts-jest/issues",children:"issue"})," with the owners of this repository before making a change."]}),"\n",(0,i.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,i.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,i.jsxs)(t.ol,{children:["\n",(0,i.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,i.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,i.jsxs)(t.li,{children:["Update the ",(0,i.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,i.jsx)(t.li,{children:"If possible, squash your commits. There must be only one commit in your PR (until a review). Then after each review requesting changes, DO NOT squash your commits with the one before the review, so that we can see intermediate modifications."}),"\n",(0,i.jsx)(t.li,{children:"You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you."}),"\n"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,i.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,i.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,i.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,i.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,i.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLBBRgGm4BpxA-eMEAmYxH6EEUrNW0StG--ODh9xGkQotnxP32D6YQ8z8L5TZovtKXlLcEPq5US9cdxzfQIjaQ24oET9pShUutHbxtOO9nf390oHhBASeHDXKp0a3fbiJ5DWWjAyO0tn0iVnIRcdt_Jwh-iow3XswJPxbalNzSZV10rWDVGnqA88WhS_87dd66GcqNGmMoVsX6eC4MI7gPXwgrGV_VQV2JOIMB07U01TzzeVL7b4jMClwLw2uqY3XdYhyzw2YZuuQQfDi_AIUr3q4XnrSt1NJwdVzYQV29K4nMD-AwZDXZpcmi9omyYU4iOOPXoi7SUjZKEATWkusE5YpmGVXajXVyaLoJhCfDPPjQqn0F0ZSx89msJbJAukqq0JQGxlzErg-uWiCrYIMkzHXOY1w-_1nnsLcxdFb89Auq_eJvd-JpDJvKMVsLldHMMDh8JhugpIKqzVd-p-KYJkVd0k2DN6D2N1uxnouRVMcAHX-GG0"}),"\n",(0,i.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,i.jsxs)(t.p,{children:["When a test-case needs to be run with a given template within tests, here is what's happening (in ",(0,i.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/hLHDRzim3BthLn3OOGcsfC2E3R2TUzfFI1I9ZjN8f23IJOAX--s3PBknksAdtGoQ7-yzFahKPZNcqMMqYd3XV0OVyiuGAq8EfrRDatwE4Ou8FZGDPYI5X1aKHJVE2XfBVenqAPOsHoj1jWR9G-bZDjy1l-73x_s-3F0Xx-NMnK3d_VxXrrJrMZx7bgyxOq83gzOAM23skE_Ozn6beFkn1csHO7L3MPl7iTSYRIGGiL5ZNpXuoBZ9FL6W4r3g892eZT4qd06jQoiTABEXq9b0xUuaC0h2YdXTGg4fed6wGHCAgYPpDokQgMTZ77C2tHNo8OFDQ1odW1wKP_Ed9HYyEamAXpcnGu5d3icwiptX9h8xRv-5wN07QYvjY0YhDsfb_31z6k53NbU1Wu2GJTAork27mjuDKVMS2kekq2ddW5BOm5Y0tYm82VVP3Po5GLkhfa_UQjc5jjZ1XVleeSO6e2sQiQZXw37FoDKrZD2VKNJhc9fmsZxB0dp9MFw68D3qv3GmlNEGAqkw16qXsUflnwH8kd1HZ7mHQBZiHOi5wFGFSmm1rXPpdS3fzYzRBAKoeprWPe_sFnXZm8RagqFkPoy9NR0Ze0LCuUxTxm5NhQjhRYtvYD0odwiwW5VRfLZFo9ooFS8XPNOeibeVuEbdpIatK6WaT6hBGcI6yd4qmaYbibY2GWKBhXVb3ewzGXEkw85iDxn5BvWbC1LbvptANRYssA0IQe8RXJLt_R-ydUWCq2VbpYe_vdvObUp-lh7fADQb_weB8iNTyzr-v8AXosLsESjkOgOJktq5makyJTBFKW81CG5UWzIJAkQvX1Y1i7h77D-Cn2-O8P2o6T_Z0ao6LtXwUcUclXibe_QP8AFqiV8NvVG7"})]})}function d(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>r,x:()=>c});var n=s(6540);const i={},o=n.createContext(i);function r(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8539],{6830:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>d,frontMatter:()=>r,metadata:()=>n,toc:()=>h});const n=JSON.parse('{"id":"contributing","title":"Contributing","description":"When contributing to this repository, please first discuss the change you wish to make via ts-jest GitHub discussion or issue with the owners of this repository before making a change.","source":"@site/versioned_docs/version-26.5/contributing.md","sourceDirName":".","slug":"/contributing","permalink":"/ts-jest/docs/26.5/contributing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/contributing.md","tags":[],"version":"26.5","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"contributing","title":"Contributing"},"sidebar":"version-26.5-docs","previous":{"title":"Processing flow","permalink":"/ts-jest/docs/26.5/processing"},"next":{"title":"Installation","permalink":"/ts-jest/docs/26.5/getting-started/installation"}}');var i=s(4848),o=s(8453);const r={id:"contributing",title:"Contributing"},c=void 0,a={},h=[{value:"Pull Request Process",id:"pull-request-process",level:2},{value:"E2E Testing",id:"e2e-testing",level:2},{value:"Preparing",id:"preparing",level:3},{value:"Running",id:"running",level:3}];function l(e){const t={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,i.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,i.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,i.jsx)(t.a,{href:"https://github.com/kulshekhar/ts-jest/issues",children:"issue"})," with the owners of this repository before making a change."]}),"\n",(0,i.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,i.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,i.jsxs)(t.ol,{children:["\n",(0,i.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,i.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,i.jsxs)(t.li,{children:["Update the ",(0,i.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,i.jsx)(t.li,{children:"If possible, squash your commits. There must be only one commit in your PR (until a review). Then after each review requesting changes, DO NOT squash your commits with the one before the review, so that we can see intermediate modifications."}),"\n",(0,i.jsx)(t.li,{children:"You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you."}),"\n"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,i.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,i.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,i.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,i.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,i.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLBBRgGm4BpxA-eMEAmYxH6EEUrNW0StG--ODh9xGkQotnxP32D6YQ8z8L5TZovtKXlLcEPq5US9cdxzfQIjaQ24oET9pShUutHbxtOO9nf390oHhBASeHDXKp0a3fbiJ5DWWjAyO0tn0iVnIRcdt_Jwh-iow3XswJPxbalNzSZV10rWDVGnqA88WhS_87dd66GcqNGmMoVsX6eC4MI7gPXwgrGV_VQV2JOIMB07U01TzzeVL7b4jMClwLw2uqY3XdYhyzw2YZuuQQfDi_AIUr3q4XnrSt1NJwdVzYQV29K4nMD-AwZDXZpcmi9omyYU4iOOPXoi7SUjZKEATWkusE5YpmGVXajXVyaLoJhCfDPPjQqn0F0ZSx89msJbJAukqq0JQGxlzErg-uWiCrYIMkzHXOY1w-_1nnsLcxdFb89Auq_eJvd-JpDJvKMVsLldHMMDh8JhugpIKqzVd-p-KYJkVd0k2DN6D2N1uxnouRVMcAHX-GG0"}),"\n",(0,i.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,i.jsxs)(t.p,{children:["When a test-case needs to be run with a given template within tests, here is what's happening (in ",(0,i.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,i.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/hLHDRzim3BthLn3OOGcsfC2E3R2TUzfFI1I9ZjN8f23IJOAX--s3PBknksAdtGoQ7-yzFahKPZNcqMMqYd3XV0OVyiuGAq8EfrRDatwE4Ou8FZGDPYI5X1aKHJVE2XfBVenqAPOsHoj1jWR9G-bZDjy1l-73x_s-3F0Xx-NMnK3d_VxXrrJrMZx7bgyxOq83gzOAM23skE_Ozn6beFkn1csHO7L3MPl7iTSYRIGGiL5ZNpXuoBZ9FL6W4r3g892eZT4qd06jQoiTABEXq9b0xUuaC0h2YdXTGg4fed6wGHCAgYPpDokQgMTZ77C2tHNo8OFDQ1odW1wKP_Ed9HYyEamAXpcnGu5d3icwiptX9h8xRv-5wN07QYvjY0YhDsfb_31z6k53NbU1Wu2GJTAork27mjuDKVMS2kekq2ddW5BOm5Y0tYm82VVP3Po5GLkhfa_UQjc5jjZ1XVleeSO6e2sQiQZXw37FoDKrZD2VKNJhc9fmsZxB0dp9MFw68D3qv3GmlNEGAqkw16qXsUflnwH8kd1HZ7mHQBZiHOi5wFGFSmm1rXPpdS3fzYzRBAKoeprWPe_sFnXZm8RagqFkPoy9NR0Ze0LCuUxTxm5NhQjhRYtvYD0odwiwW5VRfLZFo9ooFS8XPNOeibeVuEbdpIatK6WaT6hBGcI6yd4qmaYbibY2GWKBhXVb3ewzGXEkw85iDxn5BvWbC1LbvptANRYssA0IQe8RXJLt_R-ydUWCq2VbpYe_vdvObUp-lh7fADQb_weB8iNTyzr-v8AXosLsESjkOgOJktq5makyJTBFKW81CG5UWzIJAkQvX1Y1i7h77D-Cn2-O8P2o6T_Z0ao6LtXwUcUclXibe_QP8AFqiV8NvVG7"})]})}function d(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>r,x:()=>c});var n=s(6540);const i={},o=n.createContext(i);function r(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/f7b7430f.c4d24c44.js b/assets/js/f7b7430f.0b7a9f59.js similarity index 98% rename from assets/js/f7b7430f.c4d24c44.js rename to assets/js/f7b7430f.0b7a9f59.js index 1f5991d0d4..458f588ad1 100644 --- a/assets/js/f7b7430f.c4d24c44.js +++ b/assets/js/f7b7430f.0b7a9f59.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1678],{9637:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>r,contentTitle:()=>l,default:()=>p,frontMatter:()=>c,metadata:()=>o,toc:()=>a});const o=JSON.parse('{"id":"getting-started/options/tsconfig","title":"TypeScript Config option","description":"The tsconfig option allows you to define which tsconfig JSON file to use. An inline compiler options object can also be specified instead of a file path.","source":"@site/versioned_docs/version-27.0/getting-started/options/tsconfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/tsconfig","permalink":"/ts-jest/docs/27.0/getting-started/options/tsconfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/options/tsconfig.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"TypeScript Config option"}}');var s=t(4848),i=t(8453);const c={title:"TypeScript Config option"},l=void 0,r={},a=[{value:"Examples",id:"examples",level:3},{value:"Path to a tsconfig file",id:"path-to-a-tsconfig-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4},{value:"Disable auto-lookup",id:"disable-auto-lookup",level:4}];function d(e){const n={a:"a",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"tsconfig"})," option allows you to define which ",(0,s.jsx)(n.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,s.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," object can also be specified instead of a file path."]}),"\n",(0,s.jsxs)(n.p,{children:["By default ",(0,s.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,s.jsx)(n.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,s.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,s.jsx)(n.code,{children:"ES2015"})," is used as ",(0,s.jsx)(n.code,{children:"target"})," instead of ",(0,s.jsx)(n.code,{children:"ES5"}),"."]}),"\n",(0,s.jsxs)(n.p,{children:["If you need to use defaults and force ",(0,s.jsx)(n.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,s.jsx)(n.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,s.jsx)(n.code,{children:"false"}),"."]}),"\n",(0,s.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,s.jsxs)(n.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,s.jsx)(n.code,{children:"tsconfig"})," file"]}),"\n",(0,s.jsxs)(n.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,s.jsx)(n.code,{children:""})," in the path to start from the project root dir."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n tsconfig: 'tsconfig.test.json',\n },\n },\n}\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "tsconfig": "tsconfig.test.json"\n }\n }\n }\n}\n'})}),"\n",(0,s.jsx)(n.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,s.jsxs)(n.p,{children:["Refer to the TypeScript ",(0,s.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," for reference.\nIt's basically the same object you'd put in your ",(0,s.jsx)(n.code,{children:"tsconfig.json"}),"'s ",(0,s.jsx)(n.code,{children:"compilerOptions"}),"."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n tsconfig: {\n importHelpers: true,\n },\n },\n },\n}\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "tsconfig": {\n "importHelpers": true\n }\n }\n }\n }\n}\n'})}),"\n",(0,s.jsx)(n.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,s.jsxs)(n.p,{children:["By default ",(0,s.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,s.jsx)(n.code,{children:"tsconfig.json"})," in your project. But you may not want to use it at all and keep TypeScript default options. You can achieve this by setting ",(0,s.jsx)(n.code,{children:"tsconfig"})," to ",(0,s.jsx)(n.code,{children:"false"}),"."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n tsconfig: false,\n },\n },\n}\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "tsconfig": false\n }\n }\n }\n}\n'})})]})}function p(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>c,x:()=>l});var o=t(6540);const s={},i=o.createContext(s);function c(e){const n=o.useContext(i);return o.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:c(e.components),o.createElement(i.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1678],{9637:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>r,contentTitle:()=>l,default:()=>p,frontMatter:()=>c,metadata:()=>o,toc:()=>a});const o=JSON.parse('{"id":"getting-started/options/tsconfig","title":"TypeScript Config option","description":"The tsconfig option allows you to define which tsconfig JSON file to use. An inline compiler options object can also be specified instead of a file path.","source":"@site/versioned_docs/version-27.0/getting-started/options/tsconfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/tsconfig","permalink":"/ts-jest/docs/27.0/getting-started/options/tsconfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/options/tsconfig.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"TypeScript Config option"}}');var s=t(4848),i=t(8453);const c={title:"TypeScript Config option"},l=void 0,r={},a=[{value:"Examples",id:"examples",level:3},{value:"Path to a tsconfig file",id:"path-to-a-tsconfig-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4},{value:"Disable auto-lookup",id:"disable-auto-lookup",level:4}];function d(e){const n={a:"a",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"tsconfig"})," option allows you to define which ",(0,s.jsx)(n.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,s.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," object can also be specified instead of a file path."]}),"\n",(0,s.jsxs)(n.p,{children:["By default ",(0,s.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,s.jsx)(n.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,s.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,s.jsx)(n.code,{children:"ES2015"})," is used as ",(0,s.jsx)(n.code,{children:"target"})," instead of ",(0,s.jsx)(n.code,{children:"ES5"}),"."]}),"\n",(0,s.jsxs)(n.p,{children:["If you need to use defaults and force ",(0,s.jsx)(n.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,s.jsx)(n.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,s.jsx)(n.code,{children:"false"}),"."]}),"\n",(0,s.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,s.jsxs)(n.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,s.jsx)(n.code,{children:"tsconfig"})," file"]}),"\n",(0,s.jsxs)(n.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,s.jsx)(n.code,{children:""})," in the path to start from the project root dir."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n tsconfig: 'tsconfig.test.json',\n },\n },\n}\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "tsconfig": "tsconfig.test.json"\n }\n }\n }\n}\n'})}),"\n",(0,s.jsx)(n.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,s.jsxs)(n.p,{children:["Refer to the TypeScript ",(0,s.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," for reference.\nIt's basically the same object you'd put in your ",(0,s.jsx)(n.code,{children:"tsconfig.json"}),"'s ",(0,s.jsx)(n.code,{children:"compilerOptions"}),"."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n tsconfig: {\n importHelpers: true,\n },\n },\n },\n}\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "tsconfig": {\n "importHelpers": true\n }\n }\n }\n }\n}\n'})}),"\n",(0,s.jsx)(n.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,s.jsxs)(n.p,{children:["By default ",(0,s.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,s.jsx)(n.code,{children:"tsconfig.json"})," in your project. But you may not want to use it at all and keep TypeScript default options. You can achieve this by setting ",(0,s.jsx)(n.code,{children:"tsconfig"})," to ",(0,s.jsx)(n.code,{children:"false"}),"."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n tsconfig: false,\n },\n },\n}\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "tsconfig": false\n }\n }\n }\n}\n'})})]})}function p(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>c,x:()=>l});var o=t(6540);const s={},i=o.createContext(s);function c(e){const n=o.useContext(i);return o.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:c(e.components),o.createElement(i.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/f7cb2af4.4584226e.js b/assets/js/f7cb2af4.99a450db.js similarity index 99% rename from assets/js/f7cb2af4.4584226e.js rename to assets/js/f7cb2af4.99a450db.js index 259e869550..00870421d7 100644 --- a/assets/js/f7cb2af4.4584226e.js +++ b/assets/js/f7cb2af4.99a450db.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7036],{7322:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>u,contentTitle:()=>c,default:()=>j,frontMatter:()=>l,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/tsconfig","title":"TypeScript Config option","description":"The tsconfig option allows you to define which tsconfig JSON file to use. An inline compiler options object can also be specified instead of a file path.","source":"@site/docs/getting-started/options/tsconfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/tsconfig","permalink":"/ts-jest/docs/next/getting-started/options/tsconfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/tsconfig.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"TypeScript Config option"}}');var o=s(4848),r=s(8453),i=s(9489),a=s(7227);const l={title:"TypeScript Config option"},c=void 0,u={},d=[{value:"Examples",id:"examples",level:3},{value:"Path to a tsconfig file",id:"path-to-a-tsconfig-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4},{value:"Disable auto-lookup",id:"disable-auto-lookup",level:4}];function p(t){const e={a:"a",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,r.R)(),...t.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(e.p,{children:["The ",(0,o.jsx)(e.code,{children:"tsconfig"})," option allows you to define which ",(0,o.jsx)(e.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,o.jsx)(e.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," object can also be specified instead of a file path."]}),"\n",(0,o.jsxs)(e.p,{children:["By default ",(0,o.jsx)(e.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(e.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,o.jsx)(e.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,o.jsx)(e.code,{children:"ES2015"})," is used as ",(0,o.jsx)(e.code,{children:"target"})," instead of ",(0,o.jsx)(e.code,{children:"ES5"}),"."]}),"\n",(0,o.jsxs)(e.p,{children:["If you need to use defaults and force ",(0,o.jsx)(e.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,o.jsx)(e.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,o.jsx)(e.code,{children:"false"}),"."]}),"\n",(0,o.jsx)(e.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsxs)(e.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,o.jsx)(e.code,{children:"tsconfig"})," file"]}),"\n",(0,o.jsxs)(e.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,o.jsx)(e.code,{children:""})," in the path to start from the project root dir."]}),"\n",(0,o.jsxs)(i.A,{groupId:"code-examples",children:[(0,o.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: 'tsconfig.test.json',\n },\n ],\n },\n}\n"})})}),(0,o.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: 'tsconfig.test.json',\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,o.jsx)(a.A,{value:"JSON",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "tsconfig": "tsconfig.test.json"\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,o.jsx)(e.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,o.jsxs)(e.p,{children:["Refer to the TypeScript ",(0,o.jsx)(e.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," for reference.\nIt's basically the same object you'd put in your ",(0,o.jsx)(e.code,{children:"tsconfig.json"}),"'s ",(0,o.jsx)(e.code,{children:"compilerOptions"}),"."]}),"\n",(0,o.jsxs)(i.A,{groupId:"code-examples",children:[(0,o.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: {\n importHelpers: true,\n },\n },\n ],\n },\n}\n"})})}),(0,o.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: {\n importHelpers: true,\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,o.jsx)(a.A,{value:"JSON",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "tsconfig": {\n "importHelpers": true\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,o.jsx)(e.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,o.jsxs)(e.p,{children:["By default ",(0,o.jsx)(e.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(e.code,{children:"tsconfig.json"})," in your project. But you may not want to use it at all and keep TypeScript default options. You can achieve this by setting ",(0,o.jsx)(e.code,{children:"tsconfig"})," to ",(0,o.jsx)(e.code,{children:"false"}),"."]}),"\n",(0,o.jsxs)(i.A,{groupId:"code-examples",children:[(0,o.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: false,\n },\n ],\n },\n}\n"})})}),(0,o.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: false,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,o.jsx)(a.A,{value:"JSON",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "tsconfig": {\n "tsconfig": false\n }\n }\n ]\n }\n }\n}\n'})})})]})]})}function j(t={}){const{wrapper:e}={...(0,r.R)(),...t.components};return e?(0,o.jsx)(e,{...t,children:(0,o.jsx)(p,{...t})}):p(t)}},7227:(t,e,s)=>{s.d(e,{A:()=>i});s(6540);var n=s(4164);const o={tabItem:"tabItem_Ymn6"};var r=s(4848);function i(t){let{children:e,hidden:s,className:i}=t;return(0,r.jsx)("div",{role:"tabpanel",className:(0,n.A)(o.tabItem,i),hidden:s,children:e})}},9489:(t,e,s)=>{s.d(e,{A:()=>w});var n=s(6540),o=s(4164),r=s(4245),i=s(6347),a=s(6494),l=s(2814),c=s(5167),u=s(9900);function d(t){return n.Children.toArray(t).filter((t=>"\n"!==t)).map((t=>{if(!t||(0,n.isValidElement)(t)&&function(t){const{props:e}=t;return!!e&&"object"==typeof e&&"value"in e}(t))return t;throw new Error(`Docusaurus error: Bad child <${"string"==typeof t.type?t.type:t.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(t){const{values:e,children:s}=t;return(0,n.useMemo)((()=>{const t=e??function(t){return d(t).map((t=>{let{props:{value:e,label:s,attributes:n,default:o}}=t;return{value:e,label:s,attributes:n,default:o}}))}(s);return function(t){const e=(0,c.XI)(t,((t,e)=>t.value===e.value));if(e.length>0)throw new Error(`Docusaurus error: Duplicate values "${e.map((t=>t.value)).join(", ")}" found in . Every value needs to be unique.`)}(t),t}),[e,s])}function j(t){let{value:e,tabValues:s}=t;return s.some((t=>t.value===e))}function h(t){let{queryString:e=!1,groupId:s}=t;const o=(0,i.W6)(),r=function(t){let{queryString:e=!1,groupId:s}=t;if("string"==typeof e)return e;if(!1===e)return null;if(!0===e&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:e,groupId:s});return[(0,l.aZ)(r),(0,n.useCallback)((t=>{if(!r)return;const e=new URLSearchParams(o.location.search);e.set(r,t),o.replace({...o.location,search:e.toString()})}),[r,o])]}function f(t){const{defaultValue:e,queryString:s=!1,groupId:o}=t,r=p(t),[i,l]=(0,n.useState)((()=>function(t){let{defaultValue:e,tabValues:s}=t;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(e){if(!j({value:e,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${e}" but none of its children has the corresponding value. Available values are: ${s.map((t=>t.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return e}const n=s.find((t=>t.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:e,tabValues:r}))),[c,d]=h({queryString:s,groupId:o}),[f,m]=function(t){let{groupId:e}=t;const s=function(t){return t?`docusaurus.tab.${t}`:null}(e),[o,r]=(0,u.Dv)(s);return[o,(0,n.useCallback)((t=>{s&&r.set(t)}),[s,r])]}({groupId:o}),x=(()=>{const t=c??f;return j({value:t,tabValues:r})?t:null})();(0,a.A)((()=>{x&&l(x)}),[x]);return{selectedValue:i,selectValue:(0,n.useCallback)((t=>{if(!j({value:t,tabValues:r}))throw new Error(`Can't select invalid tab value=${t}`);l(t),d(t),m(t)}),[d,m,r]),tabValues:r}}var m=s(1062);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=s(4848);function b(t){let{className:e,block:s,selectedValue:n,selectValue:i,tabValues:a}=t;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),u=t=>{const e=t.currentTarget,s=l.indexOf(e),o=a[s].value;o!==n&&(c(e),i(o))},d=t=>{let e=null;switch(t.key){case"Enter":u(t);break;case"ArrowRight":{const s=l.indexOf(t.currentTarget)+1;e=l[s]??l[0];break}case"ArrowLeft":{const s=l.indexOf(t.currentTarget)-1;e=l[s]??l[l.length-1];break}}e?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.A)("tabs",{"tabs--block":s},e),children:a.map((t=>{let{value:e,label:s,attributes:r}=t;return(0,g.jsx)("li",{role:"tab",tabIndex:n===e?0:-1,"aria-selected":n===e,ref:t=>l.push(t),onKeyDown:d,onClick:u,...r,className:(0,o.A)("tabs__item",x.tabItem,r?.className,{"tabs__item--active":n===e}),children:s??e},e)}))})}function v(t){let{lazy:e,children:s,selectedValue:r}=t;const i=(Array.isArray(s)?s:[s]).filter(Boolean);if(e){const t=i.find((t=>t.props.value===r));return t?(0,n.cloneElement)(t,{className:(0,o.A)("margin-top--md",t.props.className)}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:i.map(((t,e)=>(0,n.cloneElement)(t,{key:e,hidden:t.props.value!==r})))})}function y(t){const e=f(t);return(0,g.jsxs)("div",{className:(0,o.A)("tabs-container",x.tabList),children:[(0,g.jsx)(b,{...e,...t}),(0,g.jsx)(v,{...e,...t})]})}function w(t){const e=(0,m.A)();return(0,g.jsx)(y,{...t,children:d(t.children)},String(e))}},8453:(t,e,s)=>{s.d(e,{R:()=>i,x:()=>a});var n=s(6540);const o={},r=n.createContext(o);function i(t){const e=n.useContext(r);return n.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function a(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:i(t.components),n.createElement(r.Provider,{value:e},t.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7036],{7322:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>u,contentTitle:()=>c,default:()=>j,frontMatter:()=>l,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/tsconfig","title":"TypeScript Config option","description":"The tsconfig option allows you to define which tsconfig JSON file to use. An inline compiler options object can also be specified instead of a file path.","source":"@site/docs/getting-started/options/tsconfig.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/tsconfig","permalink":"/ts-jest/docs/next/getting-started/options/tsconfig","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/tsconfig.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"TypeScript Config option"}}');var o=s(4848),r=s(8453),i=s(9489),a=s(7227);const l={title:"TypeScript Config option"},c=void 0,u={},d=[{value:"Examples",id:"examples",level:3},{value:"Path to a tsconfig file",id:"path-to-a-tsconfig-file",level:4},{value:"Inline compiler options",id:"inline-compiler-options",level:4},{value:"Disable auto-lookup",id:"disable-auto-lookup",level:4}];function p(t){const e={a:"a",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,r.R)(),...t.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(e.p,{children:["The ",(0,o.jsx)(e.code,{children:"tsconfig"})," option allows you to define which ",(0,o.jsx)(e.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,o.jsx)(e.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," object can also be specified instead of a file path."]}),"\n",(0,o.jsxs)(e.p,{children:["By default ",(0,o.jsx)(e.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(e.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,o.jsx)(e.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,o.jsx)(e.code,{children:"ES2015"})," is used as ",(0,o.jsx)(e.code,{children:"target"})," instead of ",(0,o.jsx)(e.code,{children:"ES5"}),"."]}),"\n",(0,o.jsxs)(e.p,{children:["If you need to use defaults and force ",(0,o.jsx)(e.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,o.jsx)(e.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,o.jsx)(e.code,{children:"false"}),"."]}),"\n",(0,o.jsx)(e.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsxs)(e.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,o.jsx)(e.code,{children:"tsconfig"})," file"]}),"\n",(0,o.jsxs)(e.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,o.jsx)(e.code,{children:""})," in the path to start from the project root dir."]}),"\n",(0,o.jsxs)(i.A,{groupId:"code-examples",children:[(0,o.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: 'tsconfig.test.json',\n },\n ],\n },\n}\n"})})}),(0,o.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: 'tsconfig.test.json',\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,o.jsx)(a.A,{value:"JSON",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "tsconfig": "tsconfig.test.json"\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,o.jsx)(e.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,o.jsxs)(e.p,{children:["Refer to the TypeScript ",(0,o.jsx)(e.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"})," for reference.\nIt's basically the same object you'd put in your ",(0,o.jsx)(e.code,{children:"tsconfig.json"}),"'s ",(0,o.jsx)(e.code,{children:"compilerOptions"}),"."]}),"\n",(0,o.jsxs)(i.A,{groupId:"code-examples",children:[(0,o.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: {\n importHelpers: true,\n },\n },\n ],\n },\n}\n"})})}),(0,o.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: {\n importHelpers: true,\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,o.jsx)(a.A,{value:"JSON",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "tsconfig": {\n "importHelpers": true\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,o.jsx)(e.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,o.jsxs)(e.p,{children:["By default ",(0,o.jsx)(e.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(e.code,{children:"tsconfig.json"})," in your project. But you may not want to use it at all and keep TypeScript default options. You can achieve this by setting ",(0,o.jsx)(e.code,{children:"tsconfig"})," to ",(0,o.jsx)(e.code,{children:"false"}),"."]}),"\n",(0,o.jsxs)(i.A,{groupId:"code-examples",children:[(0,o.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: false,\n },\n ],\n },\n}\n"})})}),(0,o.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n tsconfig: false,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,o.jsx)(a.A,{value:"JSON",children:(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "tsconfig": {\n "tsconfig": false\n }\n }\n ]\n }\n }\n}\n'})})})]})]})}function j(t={}){const{wrapper:e}={...(0,r.R)(),...t.components};return e?(0,o.jsx)(e,{...t,children:(0,o.jsx)(p,{...t})}):p(t)}},7227:(t,e,s)=>{s.d(e,{A:()=>i});s(6540);var n=s(4164);const o={tabItem:"tabItem_Ymn6"};var r=s(4848);function i(t){let{children:e,hidden:s,className:i}=t;return(0,r.jsx)("div",{role:"tabpanel",className:(0,n.A)(o.tabItem,i),hidden:s,children:e})}},9489:(t,e,s)=>{s.d(e,{A:()=>w});var n=s(6540),o=s(4164),r=s(4245),i=s(6347),a=s(6494),l=s(2814),c=s(5167),u=s(9900);function d(t){return n.Children.toArray(t).filter((t=>"\n"!==t)).map((t=>{if(!t||(0,n.isValidElement)(t)&&function(t){const{props:e}=t;return!!e&&"object"==typeof e&&"value"in e}(t))return t;throw new Error(`Docusaurus error: Bad child <${"string"==typeof t.type?t.type:t.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(t){const{values:e,children:s}=t;return(0,n.useMemo)((()=>{const t=e??function(t){return d(t).map((t=>{let{props:{value:e,label:s,attributes:n,default:o}}=t;return{value:e,label:s,attributes:n,default:o}}))}(s);return function(t){const e=(0,c.XI)(t,((t,e)=>t.value===e.value));if(e.length>0)throw new Error(`Docusaurus error: Duplicate values "${e.map((t=>t.value)).join(", ")}" found in . Every value needs to be unique.`)}(t),t}),[e,s])}function j(t){let{value:e,tabValues:s}=t;return s.some((t=>t.value===e))}function h(t){let{queryString:e=!1,groupId:s}=t;const o=(0,i.W6)(),r=function(t){let{queryString:e=!1,groupId:s}=t;if("string"==typeof e)return e;if(!1===e)return null;if(!0===e&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:e,groupId:s});return[(0,l.aZ)(r),(0,n.useCallback)((t=>{if(!r)return;const e=new URLSearchParams(o.location.search);e.set(r,t),o.replace({...o.location,search:e.toString()})}),[r,o])]}function f(t){const{defaultValue:e,queryString:s=!1,groupId:o}=t,r=p(t),[i,l]=(0,n.useState)((()=>function(t){let{defaultValue:e,tabValues:s}=t;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(e){if(!j({value:e,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${e}" but none of its children has the corresponding value. Available values are: ${s.map((t=>t.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return e}const n=s.find((t=>t.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:e,tabValues:r}))),[c,d]=h({queryString:s,groupId:o}),[f,m]=function(t){let{groupId:e}=t;const s=function(t){return t?`docusaurus.tab.${t}`:null}(e),[o,r]=(0,u.Dv)(s);return[o,(0,n.useCallback)((t=>{s&&r.set(t)}),[s,r])]}({groupId:o}),x=(()=>{const t=c??f;return j({value:t,tabValues:r})?t:null})();(0,a.A)((()=>{x&&l(x)}),[x]);return{selectedValue:i,selectValue:(0,n.useCallback)((t=>{if(!j({value:t,tabValues:r}))throw new Error(`Can't select invalid tab value=${t}`);l(t),d(t),m(t)}),[d,m,r]),tabValues:r}}var m=s(1062);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=s(4848);function b(t){let{className:e,block:s,selectedValue:n,selectValue:i,tabValues:a}=t;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),u=t=>{const e=t.currentTarget,s=l.indexOf(e),o=a[s].value;o!==n&&(c(e),i(o))},d=t=>{let e=null;switch(t.key){case"Enter":u(t);break;case"ArrowRight":{const s=l.indexOf(t.currentTarget)+1;e=l[s]??l[0];break}case"ArrowLeft":{const s=l.indexOf(t.currentTarget)-1;e=l[s]??l[l.length-1];break}}e?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.A)("tabs",{"tabs--block":s},e),children:a.map((t=>{let{value:e,label:s,attributes:r}=t;return(0,g.jsx)("li",{role:"tab",tabIndex:n===e?0:-1,"aria-selected":n===e,ref:t=>l.push(t),onKeyDown:d,onClick:u,...r,className:(0,o.A)("tabs__item",x.tabItem,r?.className,{"tabs__item--active":n===e}),children:s??e},e)}))})}function v(t){let{lazy:e,children:s,selectedValue:r}=t;const i=(Array.isArray(s)?s:[s]).filter(Boolean);if(e){const t=i.find((t=>t.props.value===r));return t?(0,n.cloneElement)(t,{className:(0,o.A)("margin-top--md",t.props.className)}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:i.map(((t,e)=>(0,n.cloneElement)(t,{key:e,hidden:t.props.value!==r})))})}function y(t){const e=f(t);return(0,g.jsxs)("div",{className:(0,o.A)("tabs-container",x.tabList),children:[(0,g.jsx)(b,{...e,...t}),(0,g.jsx)(v,{...e,...t})]})}function w(t){const e=(0,m.A)();return(0,g.jsx)(y,{...t,children:d(t.children)},String(e))}},8453:(t,e,s)=>{s.d(e,{R:()=>i,x:()=>a});var n=s(6540);const o={},r=n.createContext(o);function i(t){const e=n.useContext(r);return n.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function a(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:i(t.components),n.createElement(r.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/f8fb2427.a69eb55c.js b/assets/js/f8fb2427.6a6c567e.js similarity index 99% rename from assets/js/f8fb2427.a69eb55c.js rename to assets/js/f8fb2427.6a6c567e.js index 5acda86b37..46430c01c8 100644 --- a/assets/js/f8fb2427.a69eb55c.js +++ b/assets/js/f8fb2427.6a6c567e.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6734],{1687:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>d,contentTitle:()=>c,default:()=>h,frontMatter:()=>l,metadata:()=>n,toc:()=>j});const n=JSON.parse('{"id":"getting-started/options/diagnostics","title":"Diagnostics option","description":"The diagnostics option configures error reporting.","source":"@site/versioned_docs/version-29.2/getting-started/options/diagnostics.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/diagnostics","permalink":"/ts-jest/docs/getting-started/options/diagnostics","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/options/diagnostics.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Diagnostics option"}}');var i=t(4848),r=t(8453),o=t(9489),a=t(7227);const l={title:"Diagnostics option"},c=void 0,d={},j=[{value:"Disabling/enabling",id:"disablingenabling",level:3},{value:"Advanced configuration",id:"advanced-configuration",level:3},{value:"Examples",id:"examples",level:3},{value:"Disabling diagnostics",id:"disabling-diagnostics",level:4},{value:"Advanced options",id:"advanced-options",level:4},{value:"Enabling diagnostics for test files only",id:"enabling-diagnostics-for-test-files-only",level:5},{value:"Do not fail on first error",id:"do-not-fail-on-first-error",level:5},{value:"Ignoring some error codes",id:"ignoring-some-error-codes",level:5}];function u(e){const s={a:"a",code:"code",em:"em",h3:"h3",h4:"h4",h5:"h5",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(s.p,{children:["The ",(0,i.jsx)(s.code,{children:"diagnostics"})," option configures error reporting.\nIt can both be enabled/disabled entirely or limited to a specific type of errors and/or files."]}),"\n",(0,i.jsxs)(s.p,{children:["If a diagnostic is not filtered out, ",(0,i.jsx)(s.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,i.jsx)(s.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,i.jsxs)(s.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,i.jsx)(s.code,{children:"diagnostics"})," option to ",(0,i.jsx)(s.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,i.jsx)(s.code,{children:"diagnostics"})," to ",(0,i.jsx)(s.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,i.jsx)(s.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,i.jsxs)(s.p,{children:["The ",(0,i.jsx)(s.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,i.jsxs)(s.ul,{children:["\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"warnOnly"})}),": If specified and ",(0,i.jsx)(s.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,i.jsx)(s.em,{children:"disabled"}),")."]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,i.jsx)(s.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". By default here are the ones ignored:","\n",(0,i.jsxs)(s.ul,{children:["\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.code,{children:"6059"}),": ",(0,i.jsx)(s.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.code,{children:"18002"}),": ",(0,i.jsx)(s.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.code,{children:"18003"}),": ",(0,i.jsx)(s.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,i.jsx)(s.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,i.jsx)(s.code,{children:"tsconfig"})," option ",(0,i.jsx)(s.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,i.jsx)(s.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,i.jsx)(s.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,i.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,i.jsx)(s.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,i.jsxs)(o.A,{groupId:"code-examples",children:[(0,i.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: false,\n },\n ],\n },\n}\n"})})}),(0,i.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: false,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,i.jsx)(a.A,{value:"JSON",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "diagnostics": false\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,i.jsx)(s.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,i.jsx)(s.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,i.jsxs)(s.p,{children:["Assuming all your test files ends with ",(0,i.jsx)(s.code,{children:".spec.ts"})," or ",(0,i.jsx)(s.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,i.jsxs)(o.A,{groupId:"code-examples",children:[(0,i.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n exclude: ['!**/*.(spec|test).ts'],\n },\n },\n ],\n },\n}\n"})})}),(0,i.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n exclude: ['!**/*.(spec|test).ts'],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,i.jsx)(a.A,{value:"JSON",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "diagnostics": {\n "exclude": ["!**/*.(spec|test).ts"]\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,i.jsx)(s.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,i.jsxs)(s.p,{children:["While some diagnostics are stop-blockers for the compilation, most of them are not. If you want the compilation (and so your tests) to continue when encountering those, set the ",(0,i.jsx)(s.code,{children:"warnOnly"})," to ",(0,i.jsx)(s.code,{children:"true"}),":"]}),"\n",(0,i.jsxs)(o.A,{groupId:"code-examples",children:[(0,i.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n warnOnly: true,\n },\n },\n ],\n },\n}\n"})})}),(0,i.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n warnOnly: true,\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,i.jsx)(a.A,{value:"JSON",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "diagnostics": {\n "warnOnly": true\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,i.jsx)(s.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,i.jsxs)(s.p,{children:["All TypeScript error codes can be found ",(0,i.jsx)(s.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,i.jsx)(s.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,i.jsxs)(s.ol,{children:["\n",(0,i.jsxs)(s.li,{children:["A single ",(0,i.jsx)(s.code,{children:"number"})," (example: ",(0,i.jsx)(s.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,i.jsxs)(s.li,{children:["A ",(0,i.jsx)(s.code,{children:"string"})," with a code (example ",(0,i.jsx)(s.code,{children:'"1009"'}),", ",(0,i.jsx)(s.code,{children:'"TS1009"'})," or ",(0,i.jsx)(s.code,{children:'"TS1009"'}),")"]}),"\n",(0,i.jsxs)(s.li,{children:["A ",(0,i.jsx)(s.code,{children:"string"})," with a list of the above (example: ",(0,i.jsx)(s.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,i.jsxs)(s.li,{children:["An ",(0,i.jsx)(s.code,{children:"array"})," of one or more from ",(0,i.jsx)(s.code,{children:"1"})," or ",(0,i.jsx)(s.code,{children:"3"})," (example: ",(0,i.jsx)(s.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,i.jsxs)(o.A,{groupId:"code-examples",children:[(0,i.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n ignoreCodes: [2571, 6031, 18003],\n },\n },\n ],\n },\n}\n"})})}),(0,i.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n ignoreCodes: [2571, 6031, 18003],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,i.jsx)(a.A,{value:"JSON",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "diagnostics": {\n "ignoreCodes": [2571, 6031, 18003]\n }\n }\n ]\n }\n }\n}\n'})})})]})]})}function h(e={}){const{wrapper:s}={...(0,r.R)(),...e.components};return s?(0,i.jsx)(s,{...e,children:(0,i.jsx)(u,{...e})}):u(e)}},7227:(e,s,t)=>{t.d(s,{A:()=>o});t(6540);var n=t(4164);const i={tabItem:"tabItem_Ymn6"};var r=t(4848);function o(e){let{children:s,hidden:t,className:o}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,n.A)(i.tabItem,o),hidden:t,children:s})}},9489:(e,s,t)=>{t.d(s,{A:()=>w});var n=t(6540),i=t(4164),r=t(4245),o=t(6347),a=t(6494),l=t(2814),c=t(5167),d=t(9900);function j(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:s}=e;return!!s&&"object"==typeof s&&"value"in s}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function u(e){const{values:s,children:t}=e;return(0,n.useMemo)((()=>{const e=s??function(e){return j(e).map((e=>{let{props:{value:s,label:t,attributes:n,default:i}}=e;return{value:s,label:t,attributes:n,default:i}}))}(t);return function(e){const s=(0,c.XI)(e,((e,s)=>e.value===s.value));if(s.length>0)throw new Error(`Docusaurus error: Duplicate values "${s.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[s,t])}function h(e){let{value:s,tabValues:t}=e;return t.some((e=>e.value===s))}function x(e){let{queryString:s=!1,groupId:t}=e;const i=(0,o.W6)(),r=function(e){let{queryString:s=!1,groupId:t}=e;if("string"==typeof s)return s;if(!1===s)return null;if(!0===s&&!t)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return t??null}({queryString:s,groupId:t});return[(0,l.aZ)(r),(0,n.useCallback)((e=>{if(!r)return;const s=new URLSearchParams(i.location.search);s.set(r,e),i.replace({...i.location,search:s.toString()})}),[r,i])]}function p(e){const{defaultValue:s,queryString:t=!1,groupId:i}=e,r=u(e),[o,l]=(0,n.useState)((()=>function(e){let{defaultValue:s,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(s){if(!h({value:s,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${s}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return s}const n=t.find((e=>e.default))??t[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:s,tabValues:r}))),[c,j]=x({queryString:t,groupId:i}),[p,g]=function(e){let{groupId:s}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(s),[i,r]=(0,d.Dv)(t);return[i,(0,n.useCallback)((e=>{t&&r.set(e)}),[t,r])]}({groupId:i}),m=(()=>{const e=c??p;return h({value:e,tabValues:r})?e:null})();(0,a.A)((()=>{m&&l(m)}),[m]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!h({value:e,tabValues:r}))throw new Error(`Can't select invalid tab value=${e}`);l(e),j(e),g(e)}),[j,g,r]),tabValues:r}}var g=t(1062);const m={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var f=t(4848);function b(e){let{className:s,block:t,selectedValue:n,selectValue:o,tabValues:a}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),d=e=>{const s=e.currentTarget,t=l.indexOf(s),i=a[t].value;i!==n&&(c(s),o(i))},j=e=>{let s=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const t=l.indexOf(e.currentTarget)+1;s=l[t]??l[0];break}case"ArrowLeft":{const t=l.indexOf(e.currentTarget)-1;s=l[t]??l[l.length-1];break}}s?.focus()};return(0,f.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,i.A)("tabs",{"tabs--block":t},s),children:a.map((e=>{let{value:s,label:t,attributes:r}=e;return(0,f.jsx)("li",{role:"tab",tabIndex:n===s?0:-1,"aria-selected":n===s,ref:e=>l.push(e),onKeyDown:j,onClick:d,...r,className:(0,i.A)("tabs__item",m.tabItem,r?.className,{"tabs__item--active":n===s}),children:t??s},s)}))})}function v(e){let{lazy:s,children:t,selectedValue:r}=e;const o=(Array.isArray(t)?t:[t]).filter(Boolean);if(s){const e=o.find((e=>e.props.value===r));return e?(0,n.cloneElement)(e,{className:(0,i.A)("margin-top--md",e.props.className)}):null}return(0,f.jsx)("div",{className:"margin-top--md",children:o.map(((e,s)=>(0,n.cloneElement)(e,{key:s,hidden:e.props.value!==r})))})}function y(e){const s=p(e);return(0,f.jsxs)("div",{className:(0,i.A)("tabs-container",m.tabList),children:[(0,f.jsx)(b,{...s,...e}),(0,f.jsx)(v,{...s,...e})]})}function w(e){const s=(0,g.A)();return(0,f.jsx)(y,{...e,children:j(e.children)},String(s))}},8453:(e,s,t)=>{t.d(s,{R:()=>o,x:()=>a});var n=t(6540);const i={},r=n.createContext(i);function o(e){const s=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function a(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),n.createElement(r.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6734],{1687:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>d,contentTitle:()=>c,default:()=>h,frontMatter:()=>l,metadata:()=>n,toc:()=>j});const n=JSON.parse('{"id":"getting-started/options/diagnostics","title":"Diagnostics option","description":"The diagnostics option configures error reporting.","source":"@site/versioned_docs/version-29.2/getting-started/options/diagnostics.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/diagnostics","permalink":"/ts-jest/docs/getting-started/options/diagnostics","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/options/diagnostics.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Diagnostics option"}}');var i=t(4848),r=t(8453),o=t(9489),a=t(7227);const l={title:"Diagnostics option"},c=void 0,d={},j=[{value:"Disabling/enabling",id:"disablingenabling",level:3},{value:"Advanced configuration",id:"advanced-configuration",level:3},{value:"Examples",id:"examples",level:3},{value:"Disabling diagnostics",id:"disabling-diagnostics",level:4},{value:"Advanced options",id:"advanced-options",level:4},{value:"Enabling diagnostics for test files only",id:"enabling-diagnostics-for-test-files-only",level:5},{value:"Do not fail on first error",id:"do-not-fail-on-first-error",level:5},{value:"Ignoring some error codes",id:"ignoring-some-error-codes",level:5}];function u(e){const s={a:"a",code:"code",em:"em",h3:"h3",h4:"h4",h5:"h5",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(s.p,{children:["The ",(0,i.jsx)(s.code,{children:"diagnostics"})," option configures error reporting.\nIt can both be enabled/disabled entirely or limited to a specific type of errors and/or files."]}),"\n",(0,i.jsxs)(s.p,{children:["If a diagnostic is not filtered out, ",(0,i.jsx)(s.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,i.jsx)(s.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,i.jsxs)(s.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,i.jsx)(s.code,{children:"diagnostics"})," option to ",(0,i.jsx)(s.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,i.jsx)(s.code,{children:"diagnostics"})," to ",(0,i.jsx)(s.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,i.jsx)(s.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,i.jsxs)(s.p,{children:["The ",(0,i.jsx)(s.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,i.jsxs)(s.ul,{children:["\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"warnOnly"})}),": If specified and ",(0,i.jsx)(s.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,i.jsx)(s.em,{children:"disabled"}),")."]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,i.jsx)(s.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". By default here are the ones ignored:","\n",(0,i.jsxs)(s.ul,{children:["\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.code,{children:"6059"}),": ",(0,i.jsx)(s.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.code,{children:"18002"}),": ",(0,i.jsx)(s.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.code,{children:"18003"}),": ",(0,i.jsx)(s.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,i.jsx)(s.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,i.jsx)(s.code,{children:"tsconfig"})," option ",(0,i.jsx)(s.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,i.jsx)(s.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,i.jsxs)(s.li,{children:[(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,i.jsx)(s.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,i.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,i.jsx)(s.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,i.jsxs)(o.A,{groupId:"code-examples",children:[(0,i.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: false,\n },\n ],\n },\n}\n"})})}),(0,i.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: false,\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,i.jsx)(a.A,{value:"JSON",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "diagnostics": false\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,i.jsx)(s.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,i.jsx)(s.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,i.jsxs)(s.p,{children:["Assuming all your test files ends with ",(0,i.jsx)(s.code,{children:".spec.ts"})," or ",(0,i.jsx)(s.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,i.jsxs)(o.A,{groupId:"code-examples",children:[(0,i.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n exclude: ['!**/*.(spec|test).ts'],\n },\n },\n ],\n },\n}\n"})})}),(0,i.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n exclude: ['!**/*.(spec|test).ts'],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,i.jsx)(a.A,{value:"JSON",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "diagnostics": {\n "exclude": ["!**/*.(spec|test).ts"]\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,i.jsx)(s.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,i.jsxs)(s.p,{children:["While some diagnostics are stop-blockers for the compilation, most of them are not. If you want the compilation (and so your tests) to continue when encountering those, set the ",(0,i.jsx)(s.code,{children:"warnOnly"})," to ",(0,i.jsx)(s.code,{children:"true"}),":"]}),"\n",(0,i.jsxs)(o.A,{groupId:"code-examples",children:[(0,i.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n warnOnly: true,\n },\n },\n ],\n },\n}\n"})})}),(0,i.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n warnOnly: true,\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,i.jsx)(a.A,{value:"JSON",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "diagnostics": {\n "warnOnly": true\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,i.jsx)(s.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,i.jsxs)(s.p,{children:["All TypeScript error codes can be found ",(0,i.jsx)(s.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,i.jsx)(s.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,i.jsxs)(s.ol,{children:["\n",(0,i.jsxs)(s.li,{children:["A single ",(0,i.jsx)(s.code,{children:"number"})," (example: ",(0,i.jsx)(s.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,i.jsxs)(s.li,{children:["A ",(0,i.jsx)(s.code,{children:"string"})," with a code (example ",(0,i.jsx)(s.code,{children:'"1009"'}),", ",(0,i.jsx)(s.code,{children:'"TS1009"'})," or ",(0,i.jsx)(s.code,{children:'"TS1009"'}),")"]}),"\n",(0,i.jsxs)(s.li,{children:["A ",(0,i.jsx)(s.code,{children:"string"})," with a list of the above (example: ",(0,i.jsx)(s.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,i.jsxs)(s.li,{children:["An ",(0,i.jsx)(s.code,{children:"array"})," of one or more from ",(0,i.jsx)(s.code,{children:"1"})," or ",(0,i.jsx)(s.code,{children:"3"})," (example: ",(0,i.jsx)(s.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,i.jsxs)(o.A,{groupId:"code-examples",children:[(0,i.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n ignoreCodes: [2571, 6031, 18003],\n },\n },\n ],\n },\n}\n"})})}),(0,i.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n diagnostics: {\n ignoreCodes: [2571, 6031, 18003],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,i.jsx)(a.A,{value:"JSON",children:(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "diagnostics": {\n "ignoreCodes": [2571, 6031, 18003]\n }\n }\n ]\n }\n }\n}\n'})})})]})]})}function h(e={}){const{wrapper:s}={...(0,r.R)(),...e.components};return s?(0,i.jsx)(s,{...e,children:(0,i.jsx)(u,{...e})}):u(e)}},7227:(e,s,t)=>{t.d(s,{A:()=>o});t(6540);var n=t(4164);const i={tabItem:"tabItem_Ymn6"};var r=t(4848);function o(e){let{children:s,hidden:t,className:o}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,n.A)(i.tabItem,o),hidden:t,children:s})}},9489:(e,s,t)=>{t.d(s,{A:()=>w});var n=t(6540),i=t(4164),r=t(4245),o=t(6347),a=t(6494),l=t(2814),c=t(5167),d=t(9900);function j(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:s}=e;return!!s&&"object"==typeof s&&"value"in s}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function u(e){const{values:s,children:t}=e;return(0,n.useMemo)((()=>{const e=s??function(e){return j(e).map((e=>{let{props:{value:s,label:t,attributes:n,default:i}}=e;return{value:s,label:t,attributes:n,default:i}}))}(t);return function(e){const s=(0,c.XI)(e,((e,s)=>e.value===s.value));if(s.length>0)throw new Error(`Docusaurus error: Duplicate values "${s.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[s,t])}function h(e){let{value:s,tabValues:t}=e;return t.some((e=>e.value===s))}function x(e){let{queryString:s=!1,groupId:t}=e;const i=(0,o.W6)(),r=function(e){let{queryString:s=!1,groupId:t}=e;if("string"==typeof s)return s;if(!1===s)return null;if(!0===s&&!t)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return t??null}({queryString:s,groupId:t});return[(0,l.aZ)(r),(0,n.useCallback)((e=>{if(!r)return;const s=new URLSearchParams(i.location.search);s.set(r,e),i.replace({...i.location,search:s.toString()})}),[r,i])]}function p(e){const{defaultValue:s,queryString:t=!1,groupId:i}=e,r=u(e),[o,l]=(0,n.useState)((()=>function(e){let{defaultValue:s,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(s){if(!h({value:s,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${s}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return s}const n=t.find((e=>e.default))??t[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:s,tabValues:r}))),[c,j]=x({queryString:t,groupId:i}),[p,g]=function(e){let{groupId:s}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(s),[i,r]=(0,d.Dv)(t);return[i,(0,n.useCallback)((e=>{t&&r.set(e)}),[t,r])]}({groupId:i}),m=(()=>{const e=c??p;return h({value:e,tabValues:r})?e:null})();(0,a.A)((()=>{m&&l(m)}),[m]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!h({value:e,tabValues:r}))throw new Error(`Can't select invalid tab value=${e}`);l(e),j(e),g(e)}),[j,g,r]),tabValues:r}}var g=t(1062);const m={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var f=t(4848);function b(e){let{className:s,block:t,selectedValue:n,selectValue:o,tabValues:a}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),d=e=>{const s=e.currentTarget,t=l.indexOf(s),i=a[t].value;i!==n&&(c(s),o(i))},j=e=>{let s=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const t=l.indexOf(e.currentTarget)+1;s=l[t]??l[0];break}case"ArrowLeft":{const t=l.indexOf(e.currentTarget)-1;s=l[t]??l[l.length-1];break}}s?.focus()};return(0,f.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,i.A)("tabs",{"tabs--block":t},s),children:a.map((e=>{let{value:s,label:t,attributes:r}=e;return(0,f.jsx)("li",{role:"tab",tabIndex:n===s?0:-1,"aria-selected":n===s,ref:e=>l.push(e),onKeyDown:j,onClick:d,...r,className:(0,i.A)("tabs__item",m.tabItem,r?.className,{"tabs__item--active":n===s}),children:t??s},s)}))})}function v(e){let{lazy:s,children:t,selectedValue:r}=e;const o=(Array.isArray(t)?t:[t]).filter(Boolean);if(s){const e=o.find((e=>e.props.value===r));return e?(0,n.cloneElement)(e,{className:(0,i.A)("margin-top--md",e.props.className)}):null}return(0,f.jsx)("div",{className:"margin-top--md",children:o.map(((e,s)=>(0,n.cloneElement)(e,{key:s,hidden:e.props.value!==r})))})}function y(e){const s=p(e);return(0,f.jsxs)("div",{className:(0,i.A)("tabs-container",m.tabList),children:[(0,f.jsx)(b,{...s,...e}),(0,f.jsx)(v,{...s,...e})]})}function w(e){const s=(0,g.A)();return(0,f.jsx)(y,{...e,children:j(e.children)},String(s))}},8453:(e,s,t)=>{t.d(s,{R:()=>o,x:()=>a});var n=t(6540);const i={},r=n.createContext(i);function o(e){const s=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function a(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),n.createElement(r.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/fa061f97.c83784db.js b/assets/js/fa061f97.1355d829.js similarity index 99% rename from assets/js/fa061f97.c83784db.js rename to assets/js/fa061f97.1355d829.js index 2275736d78..685db8bc59 100644 --- a/assets/js/fa061f97.c83784db.js +++ b/assets/js/fa061f97.1355d829.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9547],{1121:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>l,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/astTransformers","title":"AST transformers option","description":"ts-jest by default does hoisting for a few jest methods via a TypeScript AST transformer. One can also create custom","source":"@site/versioned_docs/version-29.2/getting-started/options/astTransformers.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/astTransformers","permalink":"/ts-jest/docs/getting-started/options/astTransformers","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/options/astTransformers.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"AST transformers option"}}');var r=s(4848),a=s(8453),o=s(9489),i=s(7227);const l={title:"AST transformers option"},c=void 0,u={},d=[{value:"Examples",id:"examples",level:3},{value:"Basic Transformers",id:"basic-transformers",level:4},{value:"Configuring transformers with options",id:"configuring-transformers-with-options",level:4},{value:"Writing custom TypeScript AST transformers",id:"writing-custom-typescript-ast-transformers",level:3}];function m(e){const t={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"ts-jest"})," by default does hoisting for a few ",(0,r.jsx)(t.code,{children:"jest"})," methods via a TypeScript AST transformer. One can also create custom\nTypeScript AST transformers and provide them to ",(0,r.jsx)(t.code,{children:"ts-jest"})," to include into compilation process."]}),"\n",(0,r.jsxs)(t.p,{children:["The option is ",(0,r.jsx)(t.code,{children:"astTransformers"})," and it allows ones to specify which 3 types of TypeScript AST transformers to use with ",(0,r.jsx)(t.code,{children:"ts-jest"}),":"]}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"before"})," means your transformers get run before TS ones, which means your transformers will get raw TS syntax\ninstead of transpiled syntax (e.g ",(0,r.jsx)(t.code,{children:"import"})," instead of ",(0,r.jsx)(t.code,{children:"require"})," or ",(0,r.jsx)(t.code,{children:"define"})," )."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"after"})," means your transformers get run after TS ones, which gets transpiled syntax."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"afterDeclarations"})," means your transformers get run during ",(0,r.jsx)(t.code,{children:"d.ts"})," generation phase, allowing you to transform output type declarations."]}),"\n"]}),"\n",(0,r.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,r.jsx)(t.h4,{id:"basic-transformers",children:"Basic Transformers"}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n astTransformers: {\n before: ['my-custom-transformer'],\n },\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n astTransformers: {\n before: ['my-custom-transformer'],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(i.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "astTransformers": {\n "before": ["my-custom-transformer"]\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsx)(t.h4,{id:"configuring-transformers-with-options",children:"Configuring transformers with options"}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n astTransformers: {\n before: [\n {\n path: 'my-custom-transformer-that-needs-extra-opts',\n options: {}, // extra options to pass to transformers here\n },\n ],\n },\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n astTransformers: {\n before: [\n {\n path: 'my-custom-transformer-that-needs-extra-opts',\n options: {}, // extra options to pass to transformers here\n },\n ],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(i.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "astTransformers": {\n "before": [\n {\n "path": "my-custom-transformer-that-needs-extra-opts",\n "options": {} // extra options to pass to transformers here\n }\n ]\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsx)(t.h3,{id:"writing-custom-typescript-ast-transformers",children:"Writing custom TypeScript AST transformers"}),"\n",(0,r.jsxs)(t.p,{children:["To write a custom TypeScript AST transformers, one can take a look at ",(0,r.jsx)(t.a,{href:"https://github.com/kulshekhar/ts-jest/tree/main/src/transformers",children:"the one"})," that ",(0,r.jsx)(t.code,{children:"ts-jest"})," is using."]})]})}function p(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(m,{...e})}):m(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>o});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var a=s(4848);function o(e){let{children:t,hidden:s,className:o}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,o),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>T});var n=s(6540),r=s(4164),a=s(4245),o=s(6347),i=s(6494),l=s(2814),c=s(5167),u=s(9900);function d(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function m(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:r}}=e;return{value:t,label:s,attributes:n,default:r}}))}(s);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function p(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:s}=e;const r=(0,o.W6)(),a=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,l.aZ)(a),(0,n.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function h(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,a=m(e),[o,l]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:a}))),[c,d]=f({queryString:s,groupId:r}),[h,j]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,u.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&a.set(e)}),[s,a])]}({groupId:r}),x=(()=>{const e=c??h;return p({value:e,tabValues:a})?e:null})();(0,i.A)((()=>{x&&l(x)}),[x]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!p({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),j(e)}),[d,j,a]),tabValues:a}}var j=s(1062);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=s(4848);function b(e){let{className:t,block:s,selectedValue:n,selectValue:o,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,a.a_)(),u=e=>{const t=e.currentTarget,s=l.indexOf(t),r=i[s].value;r!==n&&(c(t),o(r))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const s=l.indexOf(e.currentTarget)+1;t=l[s]??l[0];break}case"ArrowLeft":{const s=l.indexOf(e.currentTarget)-1;t=l[s]??l[l.length-1];break}}t?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":s},t),children:i.map((e=>{let{value:t,label:s,attributes:a}=e;return(0,g.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>l.push(e),onKeyDown:d,onClick:u,...a,className:(0,r.A)("tabs__item",x.tabItem,a?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:a}=e;const o=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=h(e);return(0,g.jsxs)("div",{className:(0,r.A)("tabs-container",x.tabList),children:[(0,g.jsx)(b,{...t,...e}),(0,g.jsx)(v,{...t,...e})]})}function T(e){const t=(0,j.A)();return(0,g.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>o,x:()=>i});var n=s(6540);const r={},a=n.createContext(r);function o(e){const t=n.useContext(a);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),n.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9547],{1121:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>l,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"getting-started/options/astTransformers","title":"AST transformers option","description":"ts-jest by default does hoisting for a few jest methods via a TypeScript AST transformer. One can also create custom","source":"@site/versioned_docs/version-29.2/getting-started/options/astTransformers.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/astTransformers","permalink":"/ts-jest/docs/getting-started/options/astTransformers","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/options/astTransformers.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"AST transformers option"}}');var r=s(4848),a=s(8453),o=s(9489),i=s(7227);const l={title:"AST transformers option"},c=void 0,u={},d=[{value:"Examples",id:"examples",level:3},{value:"Basic Transformers",id:"basic-transformers",level:4},{value:"Configuring transformers with options",id:"configuring-transformers-with-options",level:4},{value:"Writing custom TypeScript AST transformers",id:"writing-custom-typescript-ast-transformers",level:3}];function m(e){const t={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"ts-jest"})," by default does hoisting for a few ",(0,r.jsx)(t.code,{children:"jest"})," methods via a TypeScript AST transformer. One can also create custom\nTypeScript AST transformers and provide them to ",(0,r.jsx)(t.code,{children:"ts-jest"})," to include into compilation process."]}),"\n",(0,r.jsxs)(t.p,{children:["The option is ",(0,r.jsx)(t.code,{children:"astTransformers"})," and it allows ones to specify which 3 types of TypeScript AST transformers to use with ",(0,r.jsx)(t.code,{children:"ts-jest"}),":"]}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"before"})," means your transformers get run before TS ones, which means your transformers will get raw TS syntax\ninstead of transpiled syntax (e.g ",(0,r.jsx)(t.code,{children:"import"})," instead of ",(0,r.jsx)(t.code,{children:"require"})," or ",(0,r.jsx)(t.code,{children:"define"})," )."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"after"})," means your transformers get run after TS ones, which gets transpiled syntax."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"afterDeclarations"})," means your transformers get run during ",(0,r.jsx)(t.code,{children:"d.ts"})," generation phase, allowing you to transform output type declarations."]}),"\n"]}),"\n",(0,r.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,r.jsx)(t.h4,{id:"basic-transformers",children:"Basic Transformers"}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n astTransformers: {\n before: ['my-custom-transformer'],\n },\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n astTransformers: {\n before: ['my-custom-transformer'],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(i.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "astTransformers": {\n "before": ["my-custom-transformer"]\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsx)(t.h4,{id:"configuring-transformers-with-options",children:"Configuring transformers with options"}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n astTransformers: {\n before: [\n {\n path: 'my-custom-transformer-that-needs-extra-opts',\n options: {}, // extra options to pass to transformers here\n },\n ],\n },\n },\n ],\n },\n}\n"})})}),(0,r.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\n // '^.+\\\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n '^.+\\\\.tsx?$': [\n 'ts-jest',\n {\n astTransformers: {\n before: [\n {\n path: 'my-custom-transformer-that-needs-extra-opts',\n options: {}, // extra options to pass to transformers here\n },\n ],\n },\n },\n ],\n },\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(i.A,{value:"JSON",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-JSON",metastring:"tab",children:'// package.json\n{\n // [...]\n "jest": {\n "transform": {\n // \'^.+\\\\.[tj]sx?$\' to process ts,js,tsx,jsx with `ts-jest`\n // \'^.+\\\\.m?[tj]sx?$\' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`\n "^.+\\\\.tsx?$": [\n "ts-jest",\n {\n "astTransformers": {\n "before": [\n {\n "path": "my-custom-transformer-that-needs-extra-opts",\n "options": {} // extra options to pass to transformers here\n }\n ]\n }\n }\n ]\n }\n }\n}\n'})})})]}),"\n",(0,r.jsx)(t.h3,{id:"writing-custom-typescript-ast-transformers",children:"Writing custom TypeScript AST transformers"}),"\n",(0,r.jsxs)(t.p,{children:["To write a custom TypeScript AST transformers, one can take a look at ",(0,r.jsx)(t.a,{href:"https://github.com/kulshekhar/ts-jest/tree/main/src/transformers",children:"the one"})," that ",(0,r.jsx)(t.code,{children:"ts-jest"})," is using."]})]})}function p(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(m,{...e})}):m(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>o});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var a=s(4848);function o(e){let{children:t,hidden:s,className:o}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,n.A)(r.tabItem,o),hidden:s,children:t})}},9489:(e,t,s)=>{s.d(t,{A:()=>T});var n=s(6540),r=s(4164),a=s(4245),o=s(6347),i=s(6494),l=s(2814),c=s(5167),u=s(9900);function d(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function m(e){const{values:t,children:s}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:s,attributes:n,default:r}}=e;return{value:t,label:s,attributes:n,default:r}}))}(s);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,s])}function p(e){let{value:t,tabValues:s}=e;return s.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:s}=e;const r=(0,o.W6)(),a=function(e){let{queryString:t=!1,groupId:s}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:t,groupId:s});return[(0,l.aZ)(a),(0,n.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function h(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,a=m(e),[o,l]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=s.find((e=>e.default))??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:a}))),[c,d]=f({queryString:s,groupId:r}),[h,j]=function(e){let{groupId:t}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,u.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&a.set(e)}),[s,a])]}({groupId:r}),x=(()=>{const e=c??h;return p({value:e,tabValues:a})?e:null})();(0,i.A)((()=>{x&&l(x)}),[x]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!p({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),j(e)}),[d,j,a]),tabValues:a}}var j=s(1062);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=s(4848);function b(e){let{className:t,block:s,selectedValue:n,selectValue:o,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,a.a_)(),u=e=>{const t=e.currentTarget,s=l.indexOf(t),r=i[s].value;r!==n&&(c(t),o(r))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const s=l.indexOf(e.currentTarget)+1;t=l[s]??l[0];break}case"ArrowLeft":{const s=l.indexOf(e.currentTarget)-1;t=l[s]??l[l.length-1];break}}t?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":s},t),children:i.map((e=>{let{value:t,label:s,attributes:a}=e;return(0,g.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>l.push(e),onKeyDown:d,onClick:u,...a,className:(0,r.A)("tabs__item",x.tabItem,a?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:a}=e;const o=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=h(e);return(0,g.jsxs)("div",{className:(0,r.A)("tabs-container",x.tabList),children:[(0,g.jsx)(b,{...t,...e}),(0,g.jsx)(v,{...t,...e})]})}function T(e){const t=(0,j.A)();return(0,g.jsx)(y,{...e,children:d(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>o,x:()=>i});var n=s(6540);const r={},a=n.createContext(r);function o(e){const t=n.useContext(a);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),n.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/fb1b7a48.74274200.js b/assets/js/fb1b7a48.b5e4f6ba.js similarity index 98% rename from assets/js/fb1b7a48.74274200.js rename to assets/js/fb1b7a48.b5e4f6ba.js index f96d9a0e6a..2eb90b42a2 100644 --- a/assets/js/fb1b7a48.74274200.js +++ b/assets/js/fb1b7a48.b5e4f6ba.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9566],{2649:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>h,frontMatter:()=>r,metadata:()=>s,toc:()=>l});const s=JSON.parse('{"id":"getting-started/options/stringifyContentPathRegex","title":"Stringify content option","description":"The stringifyContentPathRegex option has been kept for backward compatibility of HTML_TRANSFORM","source":"@site/versioned_docs/version-28.0/getting-started/options/stringifyContentPathRegex.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/stringifyContentPathRegex","permalink":"/ts-jest/docs/28.0/getting-started/options/stringifyContentPathRegex","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/options/stringifyContentPathRegex.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Stringify content option"}}');var o=n(4848),i=n(8453);const r={title:"Stringify content option"},a=void 0,c={},l=[{value:"Example",id:"example",level:3}];function d(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["The ",(0,o.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,o.jsx)(t.code,{children:"__HTML_TRANSFORM__"}),"\nIt's a regular expression pattern used to match the path of file to be transformed.\nIf it matches, the file will be exported as a module exporting its content."]}),"\n",(0,o.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,o.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,o.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,o.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,o.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,o.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,o.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,o.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,o.jsx)(t.code,{children:"transform"})," option pointing to ",(0,o.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,o.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsxs)(t.p,{children:["In the ",(0,o.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,o.jsx)(t.code,{children:"package.json"})," version of the config, but extending from the preset will ensure more compatibility without any changes when updating."]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\n// Here `defaults` can be replaced with any other preset\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n\nmodule.exports = {\n // [...]\n moduleFileExtensions: [...tsjPreset.moduleFileExtensions, 'html'],\n transform: {\n ...tsjPreset.transform,\n '\\\\.html$': 'ts-jest',\n },\n globals: {\n 'ts-jest': {\n stringifyContentPathRegex: /\\.html$/,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleFileExtensions": ["js", "ts", "html"],\n "transform": {\n "\\\\.(html|ts|js)$": "ts-jest"\n },\n "globals": {\n "ts-jest": {\n "stringifyContentPathRegex": "\\\\.html$"\n }\n }\n }\n}\n'})})]})}function h(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>a});var s=n(6540);const o={},i=s.createContext(o);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9566],{2649:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>h,frontMatter:()=>r,metadata:()=>s,toc:()=>l});const s=JSON.parse('{"id":"getting-started/options/stringifyContentPathRegex","title":"Stringify content option","description":"The stringifyContentPathRegex option has been kept for backward compatibility of HTML_TRANSFORM","source":"@site/versioned_docs/version-28.0/getting-started/options/stringifyContentPathRegex.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/stringifyContentPathRegex","permalink":"/ts-jest/docs/28.0/getting-started/options/stringifyContentPathRegex","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/options/stringifyContentPathRegex.md","tags":[],"version":"28.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Stringify content option"}}');var o=n(4848),i=n(8453);const r={title:"Stringify content option"},a=void 0,c={},l=[{value:"Example",id:"example",level:3}];function d(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.p,{children:["The ",(0,o.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,o.jsx)(t.code,{children:"__HTML_TRANSFORM__"}),"\nIt's a regular expression pattern used to match the path of file to be transformed.\nIf it matches, the file will be exported as a module exporting its content."]}),"\n",(0,o.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,o.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,o.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,o.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,o.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,o.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,o.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,o.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,o.jsx)(t.code,{children:"transform"})," option pointing to ",(0,o.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,o.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,o.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,o.jsxs)(t.p,{children:["In the ",(0,o.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,o.jsx)(t.code,{children:"package.json"})," version of the config, but extending from the preset will ensure more compatibility without any changes when updating."]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",children:"// jest.config.js\n// Here `defaults` can be replaced with any other preset\nconst { defaults: tsjPreset } = require('ts-jest/presets')\n\nmodule.exports = {\n // [...]\n moduleFileExtensions: [...tsjPreset.moduleFileExtensions, 'html'],\n transform: {\n ...tsjPreset.transform,\n '\\\\.html$': 'ts-jest',\n },\n globals: {\n 'ts-jest': {\n stringifyContentPathRegex: /\\.html$/,\n },\n },\n}\n"})}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "moduleFileExtensions": ["js", "ts", "html"],\n "transform": {\n "\\\\.(html|ts|js)$": "ts-jest"\n },\n "globals": {\n "ts-jest": {\n "stringifyContentPathRegex": "\\\\.html$"\n }\n }\n }\n}\n'})})]})}function h(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>a});var s=n(6540);const o={},i=s.createContext(o);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/fc43d853.45796344.js b/assets/js/fc43d853.cb9c3261.js similarity index 98% rename from assets/js/fc43d853.45796344.js rename to assets/js/fc43d853.cb9c3261.js index bf970ad30a..d990a3e0ed 100644 --- a/assets/js/fc43d853.45796344.js +++ b/assets/js/fc43d853.cb9c3261.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5609],{5709:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>c,default:()=>a,frontMatter:()=>i,metadata:()=>n,toc:()=>u});const n=JSON.parse('{"id":"processing","title":"Processing flow","description":"These are internal technical documents. If you\'re not a contributor to ts-jest, but simply trying to use the library you\'ll find nothing of value here","source":"@site/versioned_docs/version-29.2/processing.md","sourceDirName":".","slug":"/processing","permalink":"/ts-jest/docs/processing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/processing.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"processing","title":"Processing flow"},"sidebar":"version-29.1-docs","previous":{"title":"Introduction","permalink":"/ts-jest/docs/"},"next":{"title":"Contributing","permalink":"/ts-jest/docs/contributing"}}');var o=s(4848),r=s(8453);const i={id:"processing",title:"Processing flow"},c=void 0,l={},u=[{value:"Jest process",id:"jest-process",level:2},{value:"ts-jest process",id:"ts-jest-process",level:2}];function d(e){const t={code:"code",em:"em",h2:"h2",img:"img",p:"p",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.p,{children:(0,o.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,o.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,o.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,o.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,o.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLJRRjim37tNLn3Omn9WwGUaG8Uz3YWmOFq1nQ9YjJ8PY7Iz0lduGHV7YHjWyvDruI7FuH7FfyGTYd0w6r6Rr9YzoayKVMWd6-4nTRXzD2Pus4ZFOtGWcW8TW__ulWNjaM3pWR8r-rTXMWuVpUu9nfEpYgR2F1g3KH0sn5k3v8Ali3v493iW83c1AMWF3-v1vHPz2YU46OXO4L8uzcg8WH0TA4F7mob4D0vzeA212JAsv6IGGwuBCESlBtqGZNXkSGasdUrwTDjpgIi8HwleO60tHfHRkWlIlaje5S6IWm9WL21QEe9WUW-vtiPsztHXK3CGd31944NI6hlIj0e80muDsYSUFWNTAFllqlUDSD7QQB8aUVbSxZPn8terHJsOGenmm5bUPwp0Ei6Ln000IpLGljkCTUyYJbqkMQ5zWtr360M1VQv-3hYSLzaTs0E_Nwdlp88momP1CfA3gKUw72UqBj2ncQJkhNZKlbKAeoWFyEFtIraNsJod0PDK3ci6FQQIU2e_FGVHd8rzEt_DBstWxYrVSapu3Qp0X362dSiP1TEk-3bRV4vfixVdAmURYJ51n-J3qNnciNkwz6xnN-7amv-s0uCzDHwVJ7UxVSzyHQRprJov-_YN9zycIMxkmHumhlnPzkuFeaNapiOeDNoNfJINz8iP_tS4zLR0UiNqgs90p_osVZGsDsPzwTwOMseCrRdv8YJKCP4OuG6rpqu8-hMyB5EiQGK8fzQEwv5LozmlXhlg8fBx2m00"})]})}function a(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5609],{5709:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>c,default:()=>a,frontMatter:()=>i,metadata:()=>n,toc:()=>u});const n=JSON.parse('{"id":"processing","title":"Processing flow","description":"These are internal technical documents. If you\'re not a contributor to ts-jest, but simply trying to use the library you\'ll find nothing of value here","source":"@site/versioned_docs/version-29.2/processing.md","sourceDirName":".","slug":"/processing","permalink":"/ts-jest/docs/processing","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/processing.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"processing","title":"Processing flow"},"sidebar":"version-29.1-docs","previous":{"title":"Introduction","permalink":"/ts-jest/docs/"},"next":{"title":"Contributing","permalink":"/ts-jest/docs/contributing"}}');var o=s(4848),r=s(8453);const i={id:"processing",title:"Processing flow"},c=void 0,l={},u=[{value:"Jest process",id:"jest-process",level:2},{value:"ts-jest process",id:"ts-jest-process",level:2}];function d(e){const t={code:"code",em:"em",h2:"h2",img:"img",p:"p",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.p,{children:(0,o.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,o.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,o.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,o.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,o.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,o.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/ZLJRRjim37tNLn3Omn9WwGUaG8Uz3YWmOFq1nQ9YjJ8PY7Iz0lduGHV7YHjWyvDruI7FuH7FfyGTYd0w6r6Rr9YzoayKVMWd6-4nTRXzD2Pus4ZFOtGWcW8TW__ulWNjaM3pWR8r-rTXMWuVpUu9nfEpYgR2F1g3KH0sn5k3v8Ali3v493iW83c1AMWF3-v1vHPz2YU46OXO4L8uzcg8WH0TA4F7mob4D0vzeA212JAsv6IGGwuBCESlBtqGZNXkSGasdUrwTDjpgIi8HwleO60tHfHRkWlIlaje5S6IWm9WL21QEe9WUW-vtiPsztHXK3CGd31944NI6hlIj0e80muDsYSUFWNTAFllqlUDSD7QQB8aUVbSxZPn8terHJsOGenmm5bUPwp0Ei6Ln000IpLGljkCTUyYJbqkMQ5zWtr360M1VQv-3hYSLzaTs0E_Nwdlp88momP1CfA3gKUw72UqBj2ncQJkhNZKlbKAeoWFyEFtIraNsJod0PDK3ci6FQQIU2e_FGVHd8rzEt_DBstWxYrVSapu3Qp0X362dSiP1TEk-3bRV4vfixVdAmURYJ51n-J3qNnciNkwz6xnN-7amv-s0uCzDHwVJ7UxVSzyHQRprJov-_YN9zycIMxkmHumhlnPzkuFeaNapiOeDNoNfJINz8iP_tS4zLR0UiNqgs90p_osVZGsDsPzwTwOMseCrRdv8YJKCP4OuG6rpqu8-hMyB5EiQGK8fzQEwv5LozmlXhlg8fBx2m00"})]})}function a(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},8453:(e,t,s)=>{s.d(t,{R:()=>i,x:()=>c});var n=s(6540);const o={},r=n.createContext(o);function i(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/fc80686b.b18b0112.js b/assets/js/fc80686b.d9f583eb.js similarity index 99% rename from assets/js/fc80686b.b18b0112.js rename to assets/js/fc80686b.d9f583eb.js index 2a442572a6..d3e63c84cf 100644 --- a/assets/js/fc80686b.b18b0112.js +++ b/assets/js/fc80686b.d9f583eb.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2440],{6105:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>x,contentTitle:()=>a,default:()=>p,frontMatter:()=>l,metadata:()=>t,toc:()=>h});const t=JSON.parse('{"id":"getting-started/presets","title":"Presets","description":"In Jest, presets are pre-defined configurations that help streamline and standardize the process of setting up testing environments.","source":"@site/docs/getting-started/presets.md","sourceDirName":"getting-started","slug":"/getting-started/presets","permalink":"/ts-jest/docs/next/getting-started/presets","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/presets.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"presets","title":"Presets"},"sidebar":"docs","previous":{"title":"Installation","permalink":"/ts-jest/docs/next/getting-started/installation"},"next":{"title":"Options","permalink":"/ts-jest/docs/next/getting-started/options"}}');var r=n(4848),i=n(8453),o=n(9489),c=n(7227),d=n(1574);const l={id:"presets",title:"Presets"},a=void 0,x={},h=[{value:"Functions",id:"functions",level:2},{value:"createDefaultPreset(options)",id:"createdefaultpresetoptions",level:3},{value:"Parameters",id:"parameters",level:4},{value:"Returns",id:"returns",level:4},{value:"Example:",id:"example",level:4},{value:"createDefaultLegacyPreset(options)",id:"createdefaultlegacypresetoptions",level:3},{value:"Parameters",id:"parameters-1",level:4},{value:"Returns",id:"returns-1",level:4},{value:"Example:",id:"example-1",level:4},{value:"createDefaultEsmPreset(options)",id:"createdefaultesmpresetoptions",level:3},{value:"Parameters",id:"parameters-2",level:4},{value:"Returns",id:"returns-2",level:4},{value:"Example:",id:"example-2",level:4},{value:"createDefaultLegacyEsmPreset(options)",id:"createdefaultlegacyesmpresetoptions",level:3},{value:"Parameters",id:"parameters-3",level:4},{value:"Returns",id:"returns-3",level:4},{value:"Example:",id:"example-3",level:4},{value:"createJsWithTsPreset(options)",id:"createjswithtspresetoptions",level:3},{value:"Parameters",id:"parameters-4",level:4},{value:"Returns",id:"returns-4",level:4},{value:"Example:",id:"example-4",level:4},{value:"createJsWithTsLegacyPreset(options)",id:"createjswithtslegacypresetoptions",level:3},{value:"Parameters",id:"parameters-5",level:4},{value:"Returns",id:"returns-5",level:4},{value:"Example:",id:"example-5",level:4},{value:"createJsWithTsEsmPreset(options)",id:"createjswithtsesmpresetoptions",level:3},{value:"Parameters",id:"parameters-6",level:4},{value:"Returns",id:"returns-6",level:4},{value:"Example:",id:"example-6",level:4},{value:"createJsWithTsEsmLegacyPreset(options)",id:"createjswithtsesmlegacypresetoptions",level:3},{value:"Parameters",id:"parameters-7",level:4},{value:"Returns",id:"returns-7",level:4},{value:"Example:",id:"example-7",level:4},{value:"createJsWithBabelPreset(options)",id:"createjswithbabelpresetoptions",level:3},{value:"Parameters",id:"parameters-8",level:4},{value:"Returns",id:"returns-8",level:4},{value:"Example:",id:"example-8",level:4},{value:"createJsWithBabelLegacyPreset(options)",id:"createjswithbabellegacypresetoptions",level:3},{value:"Parameters",id:"parameters-9",level:4},{value:"Returns",id:"returns-9",level:4},{value:"Example:",id:"example-9",level:4},{value:"createJsWithBabelEsmPreset(options)",id:"createjswithbabelesmpresetoptions",level:3},{value:"Parameters",id:"parameters-10",level:4},{value:"Returns",id:"returns-10",level:4},{value:"Example:",id:"example-10",level:4},{value:"createJsWithBabelEsmLegacyPreset(options)",id:"createjswithbabelesmlegacypresetoptions",level:3},{value:"Parameters",id:"parameters-11",level:4},{value:"Returns",id:"returns-11",level:4},{value:"Example:",id:"example-11",level:4},{value:"Legacy presets",id:"legacy-presets",level:3},{value:"Example",id:"example-12",level:4}];function j(e){const s={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",h4:"h4",hr:"hr",li:"li",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,i.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(s.p,{children:["In Jest, ",(0,r.jsx)(s.strong,{children:"presets"})," are pre-defined configurations that help streamline and standardize the process of setting up testing environments.\nThey allow developers to quickly configure Jest with specific transformers, file extensions, and other options."]}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.code,{children:"ts-jest"})," provides very opinionated presets and based on what we found to be useful."]}),"\n",(0,r.jsx)(s.admonition,{type:"important",children:(0,r.jsx)(s.p,{children:"The current best practice for using presets is to call one of the utility functions below to create (and optionally extend) presets. Legacy presets are listed at the bottom of the page."})}),"\n",(0,r.jsx)(s.h2,{id:"functions",children:"Functions"}),"\n","\n",(0,r.jsx)(d.A,{toc:h.slice(1)}),"\n",(0,r.jsx)(s.hr,{}),"\n",(0,r.jsx)(s.h3,{id:"createdefaultpresetoptions",children:(0,r.jsx)(s.code,{children:"createDefaultPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a configuration to process TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type DefaultPreset = {\n transform: {\n '^.+.tsx?$': ['ts-jest', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport { createDefaultPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createDefaultPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createdefaultlegacypresetoptions",children:(0,r.jsx)(s.code,{children:"createDefaultLegacyPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ",(0,r.jsx)(s.strong,{children:"LEGACY"})," configuration to process TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-1",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-1",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type DefaultPreset = {\n transform: {\n '^.+.tsx?$': ['ts-jest/legacy', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-1",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport { createDefaultLegacyPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createDefaultPreset({\n //...optionsa\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createdefaultesmpresetoptions",children:(0,r.jsx)(s.code,{children:"createDefaultEsmPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create an ESM configuration to process TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".mts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),"/",(0,r.jsx)(s.code,{children:".mtsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-2",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-2",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type DefaultEsmPreset = {\n extensionsToTreatAsEsm: string[]\n transform: {\n '^.+\\\\.m?tsx?$': ['ts-jest', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-2",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createDefaultEsmPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createDefaultEsmPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createdefaultlegacyesmpresetoptions",children:(0,r.jsx)(s.code,{children:"createDefaultLegacyEsmPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ",(0,r.jsx)(s.strong,{children:"LEGACY"})," ESM configuration to process TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".mts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),"/",(0,r.jsx)(s.code,{children:".mtsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-3",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-3",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type DefaultEsmPreset = {\n extensionsToTreatAsEsm: string[]\n transform: {\n '^.+\\\\.m?tsx?$': ['ts-jest/legacy', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-3",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createDefaultLegacyEsmPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createDefaultLegacyEsmPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithtspresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithTsPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-4",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-4",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithTsPreset = {\n transform: {\n '^.+.[tj]sx?$': ['ts-jest', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-4",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport { createJsWithTsPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithTsPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithtslegacypresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithTsLegacyPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ",(0,r.jsx)(s.strong,{children:"LEGACY"})," configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-5",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-5",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithTsPreset = {\n transform: {\n '^.+.[tj]sx?$': ['ts-jest/legacy', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-5",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport { createJsWithTsLegacyPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithTsLegacyPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithtsesmpresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithTsEsmPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ESM configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".mjs"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".mjsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".mts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),"/",(0,r.jsx)(s.code,{children:".mtsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-6",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-6",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithTsPreset = {\n transform: {\n '^.+\\\\.m?[tj]sx?$': ['ts-jest', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-6",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createJsWithTsEsmPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithTsEsmPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithtsesmlegacypresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithTsEsmLegacyPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ",(0,r.jsx)(s.strong,{children:"LEGACY"})," ESM configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".mjs"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".mjsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".mts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),"/",(0,r.jsx)(s.code,{children:".mtsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-7",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-7",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithTsPreset = {\n transform: {\n '^.+\\\\.m?[tj]sx?$': ['ts-jest/legacy', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-7",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createJsWithTsEsmLegacyPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithTsEsmLegacyPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithbabelpresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithBabelPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),") which uses ",(0,r.jsx)(s.code,{children:"babel-jest"})," to perform additional transformation."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-8",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),"):","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"babelConfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/babelConfig",children:"babelConfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-8",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n babelConfig?: boolean | string | BabelConfig\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithBabelPreset = {\n transform: {\n '^.+.[tj]sx?$': ['ts-jest', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-8",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport { createJsWithBabelPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithBabelPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithbabellegacypresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithBabelLegacyPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ",(0,r.jsx)(s.strong,{children:"LEGACY"})," configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),") which uses ",(0,r.jsx)(s.code,{children:"babel-jest"})," to perform additional transformation."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-9",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),"):","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"babelConfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/babelConfig",children:"babelConfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-9",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n babelConfig?: boolean | string | BabelConfig\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithBabelPreset = {\n transform: {\n '^.+.[tj]sx?$': ['ts-jest/legacy', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-9",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport { createJsWithBabelLegacyPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithBabelLegacyPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithbabelesmpresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithBabelEsmPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ESM configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".mjs"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".mjsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".mts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),"/",(0,r.jsx)(s.code,{children:".mtsx"}),") which uses ",(0,r.jsx)(s.code,{children:"babel-jest"})," to perform additional transformation."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-10",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),"):","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"babelConfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/babelConfig",children:"babelConfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-10",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n babelConfig?: boolean | string | BabelConfig\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithBabelPreset = {\n transform: {\n '^.+.[tj]sx?$': ['ts-jest', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-10",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createJsWithBabelEsmPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithBabelEsmPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithbabelesmlegacypresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithBabelEsmLegacyPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ",(0,r.jsx)(s.strong,{children:"LEGACY"})," ESM configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".mjs"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".mjsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".mts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),"/",(0,r.jsx)(s.code,{children:".mtsx"}),") which uses ",(0,r.jsx)(s.code,{children:"babel-jest"})," to perform additional transformation."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-11",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),"):","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"babelConfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/babelConfig",children:"babelConfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-11",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n babelConfig?: boolean | string | BabelConfig\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithBabelPreset = {\n transform: {\n '^.+.[tj]sx?$': ['ts-jest/legacy', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-11",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createJsWithBabelEsmLegacyPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithBabelEsmLegacyPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"legacy-presets",children:"Legacy presets"}),"\n",(0,r.jsx)(s.admonition,{type:"warning",children:(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.code,{children:"ts-jest"})," ",(0,r.jsx)(s.strong,{children:"DON'T RECOMMEND"})," to use legacy presets because this approach is not flexible to configure Jest configuration.\nThese legacy presets will be removed in the next major release and users are ",(0,r.jsx)(s.strong,{children:"HIGHLY RECOMMENDED"})," to migrate to use the above utility functions."]})}),"\n",(0,r.jsxs)(s.table,{children:[(0,r.jsx)(s.thead,{children:(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.th,{children:"Preset name"}),(0,r.jsx)(s.th,{children:"Description"})]})}),(0,r.jsxs)(s.tbody,{children:[(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default"}),(0,r.jsx)("br",{}),"or ",(0,r.jsx)(s.code,{children:"ts-jest"})]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default-legacy"}),(0,r.jsx)("br",{}),"or ",(0,r.jsx)(s.code,{children:"ts-jest/legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default-esm"}),(0,r.jsx)("br",{})]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default-esm-legacy"}),(0,r.jsx)("br",{})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts"})}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-esm"})}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-esm-legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel"})}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-esm"})}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-esm-legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]})]})]}),"\n",(0,r.jsx)(s.h4,{id:"example-12",children:"Example"}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(c.A,{value:"typescript-cjs",label:"TypeScript CJS",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",metastring:'tab={"label": "TypeScript CJS"}',children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // Replace `` with the one of the preset names from the table above\n preset: '',\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(c.A,{value:"typescript-esm",label:"TypeScript ESM",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",metastring:'tab={"label": "TypeScript ESM"}',children:"// jest.config.mts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // Replace `` with the one of the preset names from the table above\n preset: '',\n}\n\nexport default jestConfig\n"})})})]})]})}function p(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(j,{...e})}):j(e)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2440],{6105:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>x,contentTitle:()=>a,default:()=>p,frontMatter:()=>l,metadata:()=>t,toc:()=>h});const t=JSON.parse('{"id":"getting-started/presets","title":"Presets","description":"In Jest, presets are pre-defined configurations that help streamline and standardize the process of setting up testing environments.","source":"@site/docs/getting-started/presets.md","sourceDirName":"getting-started","slug":"/getting-started/presets","permalink":"/ts-jest/docs/next/getting-started/presets","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/presets.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"presets","title":"Presets"},"sidebar":"docs","previous":{"title":"Installation","permalink":"/ts-jest/docs/next/getting-started/installation"},"next":{"title":"Options","permalink":"/ts-jest/docs/next/getting-started/options"}}');var r=n(4848),i=n(8453),o=n(9489),c=n(7227),d=n(1574);const l={id:"presets",title:"Presets"},a=void 0,x={},h=[{value:"Functions",id:"functions",level:2},{value:"createDefaultPreset(options)",id:"createdefaultpresetoptions",level:3},{value:"Parameters",id:"parameters",level:4},{value:"Returns",id:"returns",level:4},{value:"Example:",id:"example",level:4},{value:"createDefaultLegacyPreset(options)",id:"createdefaultlegacypresetoptions",level:3},{value:"Parameters",id:"parameters-1",level:4},{value:"Returns",id:"returns-1",level:4},{value:"Example:",id:"example-1",level:4},{value:"createDefaultEsmPreset(options)",id:"createdefaultesmpresetoptions",level:3},{value:"Parameters",id:"parameters-2",level:4},{value:"Returns",id:"returns-2",level:4},{value:"Example:",id:"example-2",level:4},{value:"createDefaultLegacyEsmPreset(options)",id:"createdefaultlegacyesmpresetoptions",level:3},{value:"Parameters",id:"parameters-3",level:4},{value:"Returns",id:"returns-3",level:4},{value:"Example:",id:"example-3",level:4},{value:"createJsWithTsPreset(options)",id:"createjswithtspresetoptions",level:3},{value:"Parameters",id:"parameters-4",level:4},{value:"Returns",id:"returns-4",level:4},{value:"Example:",id:"example-4",level:4},{value:"createJsWithTsLegacyPreset(options)",id:"createjswithtslegacypresetoptions",level:3},{value:"Parameters",id:"parameters-5",level:4},{value:"Returns",id:"returns-5",level:4},{value:"Example:",id:"example-5",level:4},{value:"createJsWithTsEsmPreset(options)",id:"createjswithtsesmpresetoptions",level:3},{value:"Parameters",id:"parameters-6",level:4},{value:"Returns",id:"returns-6",level:4},{value:"Example:",id:"example-6",level:4},{value:"createJsWithTsEsmLegacyPreset(options)",id:"createjswithtsesmlegacypresetoptions",level:3},{value:"Parameters",id:"parameters-7",level:4},{value:"Returns",id:"returns-7",level:4},{value:"Example:",id:"example-7",level:4},{value:"createJsWithBabelPreset(options)",id:"createjswithbabelpresetoptions",level:3},{value:"Parameters",id:"parameters-8",level:4},{value:"Returns",id:"returns-8",level:4},{value:"Example:",id:"example-8",level:4},{value:"createJsWithBabelLegacyPreset(options)",id:"createjswithbabellegacypresetoptions",level:3},{value:"Parameters",id:"parameters-9",level:4},{value:"Returns",id:"returns-9",level:4},{value:"Example:",id:"example-9",level:4},{value:"createJsWithBabelEsmPreset(options)",id:"createjswithbabelesmpresetoptions",level:3},{value:"Parameters",id:"parameters-10",level:4},{value:"Returns",id:"returns-10",level:4},{value:"Example:",id:"example-10",level:4},{value:"createJsWithBabelEsmLegacyPreset(options)",id:"createjswithbabelesmlegacypresetoptions",level:3},{value:"Parameters",id:"parameters-11",level:4},{value:"Returns",id:"returns-11",level:4},{value:"Example:",id:"example-11",level:4},{value:"Legacy presets",id:"legacy-presets",level:3},{value:"Example",id:"example-12",level:4}];function j(e){const s={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",h4:"h4",hr:"hr",li:"li",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,i.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(s.p,{children:["In Jest, ",(0,r.jsx)(s.strong,{children:"presets"})," are pre-defined configurations that help streamline and standardize the process of setting up testing environments.\nThey allow developers to quickly configure Jest with specific transformers, file extensions, and other options."]}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.code,{children:"ts-jest"})," provides very opinionated presets and based on what we found to be useful."]}),"\n",(0,r.jsx)(s.admonition,{type:"important",children:(0,r.jsx)(s.p,{children:"The current best practice for using presets is to call one of the utility functions below to create (and optionally extend) presets. Legacy presets are listed at the bottom of the page."})}),"\n",(0,r.jsx)(s.h2,{id:"functions",children:"Functions"}),"\n","\n",(0,r.jsx)(d.A,{toc:h.slice(1)}),"\n",(0,r.jsx)(s.hr,{}),"\n",(0,r.jsx)(s.h3,{id:"createdefaultpresetoptions",children:(0,r.jsx)(s.code,{children:"createDefaultPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a configuration to process TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type DefaultPreset = {\n transform: {\n '^.+.tsx?$': ['ts-jest', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport { createDefaultPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createDefaultPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createdefaultlegacypresetoptions",children:(0,r.jsx)(s.code,{children:"createDefaultLegacyPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ",(0,r.jsx)(s.strong,{children:"LEGACY"})," configuration to process TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-1",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-1",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type DefaultPreset = {\n transform: {\n '^.+.tsx?$': ['ts-jest/legacy', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-1",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport { createDefaultLegacyPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createDefaultPreset({\n //...optionsa\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createdefaultesmpresetoptions",children:(0,r.jsx)(s.code,{children:"createDefaultEsmPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create an ESM configuration to process TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".mts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),"/",(0,r.jsx)(s.code,{children:".mtsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-2",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-2",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type DefaultEsmPreset = {\n extensionsToTreatAsEsm: string[]\n transform: {\n '^.+\\\\.m?tsx?$': ['ts-jest', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-2",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createDefaultEsmPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createDefaultEsmPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createdefaultlegacyesmpresetoptions",children:(0,r.jsx)(s.code,{children:"createDefaultLegacyEsmPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ",(0,r.jsx)(s.strong,{children:"LEGACY"})," ESM configuration to process TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".mts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),"/",(0,r.jsx)(s.code,{children:".mtsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-3",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-3",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type DefaultEsmPreset = {\n extensionsToTreatAsEsm: string[]\n transform: {\n '^.+\\\\.m?tsx?$': ['ts-jest/legacy', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-3",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createDefaultLegacyEsmPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createDefaultLegacyEsmPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithtspresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithTsPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-4",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-4",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithTsPreset = {\n transform: {\n '^.+.[tj]sx?$': ['ts-jest', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-4",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport { createJsWithTsPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithTsPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithtslegacypresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithTsLegacyPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ",(0,r.jsx)(s.strong,{children:"LEGACY"})," configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-5",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-5",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithTsPreset = {\n transform: {\n '^.+.[tj]sx?$': ['ts-jest/legacy', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-5",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport { createJsWithTsLegacyPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithTsLegacyPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithtsesmpresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithTsEsmPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ESM configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".mjs"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".mjsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".mts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),"/",(0,r.jsx)(s.code,{children:".mtsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-6",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-6",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithTsPreset = {\n transform: {\n '^.+\\\\.m?[tj]sx?$': ['ts-jest', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-6",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createJsWithTsEsmPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithTsEsmPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithtsesmlegacypresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithTsEsmLegacyPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ",(0,r.jsx)(s.strong,{children:"LEGACY"})," ESM configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".mjs"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".mjsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".mts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),"/",(0,r.jsx)(s.code,{children:".mtsx"}),")."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-7",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),")","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-7",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithTsPreset = {\n transform: {\n '^.+\\\\.m?[tj]sx?$': ['ts-jest/legacy', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-7",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createJsWithTsEsmLegacyPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithTsEsmLegacyPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithbabelpresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithBabelPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),") which uses ",(0,r.jsx)(s.code,{children:"babel-jest"})," to perform additional transformation."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-8",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),"):","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"babelConfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/babelConfig",children:"babelConfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-8",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n babelConfig?: boolean | string | BabelConfig\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithBabelPreset = {\n transform: {\n '^.+.[tj]sx?$': ['ts-jest', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-8",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport { createJsWithBabelPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithBabelPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithbabellegacypresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithBabelLegacyPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ",(0,r.jsx)(s.strong,{children:"LEGACY"})," configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),") which uses ",(0,r.jsx)(s.code,{children:"babel-jest"})," to perform additional transformation."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-9",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),"):","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"babelConfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/babelConfig",children:"babelConfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-9",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n babelConfig?: boolean | string | BabelConfig\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithBabelPreset = {\n transform: {\n '^.+.[tj]sx?$': ['ts-jest/legacy', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-9",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport { createJsWithBabelLegacyPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithBabelLegacyPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithbabelesmpresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithBabelEsmPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ESM configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".mjs"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".mjsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".mts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),"/",(0,r.jsx)(s.code,{children:".mtsx"}),") which uses ",(0,r.jsx)(s.code,{children:"babel-jest"})," to perform additional transformation."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-10",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),"):","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"babelConfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/babelConfig",children:"babelConfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-10",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n babelConfig?: boolean | string | BabelConfig\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithBabelPreset = {\n transform: {\n '^.+.[tj]sx?$': ['ts-jest', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-10",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createJsWithBabelEsmPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithBabelEsmPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"createjswithbabelesmlegacypresetoptions",children:(0,r.jsx)(s.code,{children:"createJsWithBabelEsmLegacyPreset(options)"})}),"\n",(0,r.jsxs)(s.p,{children:["Create a ",(0,r.jsx)(s.strong,{children:"LEGACY"})," ESM configuration to process JavaScript/TypeScript files (",(0,r.jsx)(s.code,{children:".js"}),"/",(0,r.jsx)(s.code,{children:".mjs"}),"/",(0,r.jsx)(s.code,{children:".jsx"}),"/",(0,r.jsx)(s.code,{children:".mjsx"}),"/",(0,r.jsx)(s.code,{children:".ts"}),"/",(0,r.jsx)(s.code,{children:".mts"}),"/",(0,r.jsx)(s.code,{children:".tsx"}),"/",(0,r.jsx)(s.code,{children:".mtsx"}),") which uses ",(0,r.jsx)(s.code,{children:"babel-jest"})," to perform additional transformation."]}),"\n",(0,r.jsx)(s.h4,{id:"parameters-11",children:"Parameters"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"options"})," (",(0,r.jsx)(s.strong,{children:"OPTIONAL"}),"):","\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"tsconfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/tsconfig",children:"tsconfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"isolatedModules"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/isolatedModules",children:"isolatedModules options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"compiler"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/compiler",children:"compiler options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"astTransformers"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/astTransformers",children:"astTransformers options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"diagnostics"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/diagnostics",children:"diagnostics options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"babelConfig"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/babelConfig",children:"babelConfig options page"})]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"stringifyContentPathRegex"}),": see more at ",(0,r.jsx)(s.a,{href:"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex",children:"stringifyContentPathRegex options page"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"returns-11",children:"Returns"}),"\n",(0,r.jsxs)(s.p,{children:["An object contains Jest's ",(0,r.jsx)(s.code,{children:"transform"})," property:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"interface TsJestTransformerOptions {\n tsconfig?: boolean | string | RawCompilerOptions\n isolatedModules?: boolean\n astTransformers?: ConfigCustomTransformer\n diagnostics?:\n | boolean\n | {\n pretty?: boolean\n ignoreCodes?: number | string | Array\n exclude?: string[]\n warnOnly?: boolean\n }\n babelConfig?: boolean | string | BabelConfig\n stringifyContentPathRegex?: string | RegExp\n}\n\nexport type JsWithBabelPreset = {\n transform: {\n '^.+.[tj]sx?$': ['ts-jest/legacy', TsJestTransformerOptions]\n }\n}\n"})}),"\n",(0,r.jsx)(s.h4,{id:"example-11",children:"Example:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"// jest.config.mts\nimport { createJsWithBabelEsmLegacyPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst presetConfig = createJsWithBabelEsmLegacyPreset({\n //...options\n})\n\nconst jestConfig: JestConfigWithTsJest = {\n ...presetConfig,\n}\n\nexport default jestConfig\n"})}),"\n",(0,r.jsx)(s.h3,{id:"legacy-presets",children:"Legacy presets"}),"\n",(0,r.jsx)(s.admonition,{type:"warning",children:(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.code,{children:"ts-jest"})," ",(0,r.jsx)(s.strong,{children:"DON'T RECOMMEND"})," to use legacy presets because this approach is not flexible to configure Jest configuration.\nThese legacy presets will be removed in the next major release and users are ",(0,r.jsx)(s.strong,{children:"HIGHLY RECOMMENDED"})," to migrate to use the above utility functions."]})}),"\n",(0,r.jsxs)(s.table,{children:[(0,r.jsx)(s.thead,{children:(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.th,{children:"Preset name"}),(0,r.jsx)(s.th,{children:"Description"})]})}),(0,r.jsxs)(s.tbody,{children:[(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default"}),(0,r.jsx)("br",{}),"or ",(0,r.jsx)(s.code,{children:"ts-jest"})]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default-legacy"}),(0,r.jsx)("br",{}),"or ",(0,r.jsx)(s.code,{children:"ts-jest/legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default-esm"}),(0,r.jsx)("br",{})]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/default-esm-legacy"}),(0,r.jsx)("br",{})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, leaving JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") as-is."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts"})}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-esm"})}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-ts-esm-legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript and JavaScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),", ",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:".jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax.",(0,r.jsx)("br",{}),"You'll need to set ",(0,r.jsx)(s.code,{children:"allowJs"})," to ",(0,r.jsx)(s.code,{children:"true"})," in your ",(0,r.jsx)(s.code,{children:"tsconfig.json"})," file."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel"})}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"CommonJS"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-esm"})}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"ts-jest/presets/js-with-babel-esm-legacy"})," (",(0,r.jsx)(s.strong,{children:"LEGACY"}),")"]}),(0,r.jsxs)(s.td,{children:["TypeScript files (",(0,r.jsx)(s.code,{children:".ts"}),", ",(0,r.jsx)(s.code,{children:".tsx"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"ts-jest"})," to ",(0,r.jsx)(s.strong,{children:"ESM"})," syntax, and JavaScript files (",(0,r.jsx)(s.code,{children:".js"}),", ",(0,r.jsx)(s.code,{children:"jsx"}),", ",(0,r.jsx)(s.code,{children:".mjs"}),") will be transformed by ",(0,r.jsx)(s.code,{children:"babel-jest"}),"."]})]})]})]}),"\n",(0,r.jsx)(s.h4,{id:"example-12",children:"Example"}),"\n",(0,r.jsxs)(o.A,{groupId:"code-examples",children:[(0,r.jsx)(c.A,{value:"typescript-cjs",label:"TypeScript CJS",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",metastring:'tab={"label": "TypeScript CJS"}',children:"// jest.config.ts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // Replace `` with the one of the preset names from the table above\n preset: '',\n}\n\nexport default jestConfig\n"})})}),(0,r.jsx)(c.A,{value:"typescript-esm",label:"TypeScript ESM",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",metastring:'tab={"label": "TypeScript ESM"}',children:"// jest.config.mts\nimport type { JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // Replace `` with the one of the preset names from the table above\n preset: '',\n}\n\nexport default jestConfig\n"})})})]})]})}function p(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(j,{...e})}):j(e)}}}]); \ No newline at end of file diff --git a/assets/js/fdcb7476.feb6962b.js b/assets/js/fdcb7476.0782afd3.js similarity index 99% rename from assets/js/fdcb7476.feb6962b.js rename to assets/js/fdcb7476.0782afd3.js index 89ac4ade46..12702f828b 100644 --- a/assets/js/fdcb7476.feb6962b.js +++ b/assets/js/fdcb7476.0782afd3.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9660],{7603:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>d,default:()=>j,frontMatter:()=>r,metadata:()=>t,toc:()=>l});const t=JSON.parse('{"id":"getting-started/options","title":"Options","description":"Introduction","source":"@site/versioned_docs/version-27.1/getting-started/options.md","sourceDirName":"getting-started","slug":"/getting-started/options","permalink":"/ts-jest/docs/27.1/getting-started/options","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/options.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"options","title":"Options"},"sidebar":"version-27.1-docs","previous":{"title":"Presets","permalink":"/ts-jest/docs/27.1/getting-started/presets"},"next":{"title":"Paths mapping","permalink":"/ts-jest/docs/27.1/getting-started/paths-mapping"}}');var i=n(4848),o=n(8453);const r={id:"options",title:"Options"},d=void 0,c={},l=[{value:"Introduction",id:"introduction",level:3},{value:"Options",id:"options",level:3}];function h(e){const s={a:"a",admonition:"admonition",code:"code",em:"em",h3:"h3",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(s.h3,{id:"introduction",children:"Introduction"}),"\n",(0,i.jsxs)(s.p,{children:["All ",(0,i.jsx)(s.code,{children:"ts-jest"})," specific options are located under the ",(0,i.jsx)(s.code,{children:"globals"})," of Jest config object in the ",(0,i.jsx)(s.code,{children:"package.json"})," file of your project,\nor through a ",(0,i.jsx)(s.code,{children:"jest.config.js"}),", or ",(0,i.jsx)(s.code,{children:"jest.config.ts"})," file."]}),"\n",(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n // ts-jest configuration goes here\n }\n }\n }\n}\n'})}),"\n",(0,i.jsx)(s.p,{children:"Or through JavaScript:"}),"\n",(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n // ts-jest configuration goes here\n },\n },\n}\n"})}),"\n",(0,i.jsxs)(s.admonition,{type:"tip",children:[(0,i.jsxs)(s.p,{children:["To utilize IDE suggestions, you can use ",(0,i.jsx)(s.code,{children:"JSDoc"})," comments to provide suggested ",(0,i.jsx)(s.code,{children:"ts-jest"})," configs for your Jest config:"]}),(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",children:"// jest.config.js\n/** @type {import('ts-jest').InitialOptionsTsJest} */\nmodule.exports = config = {\n // [...]\n globals: {\n 'ts-jest': {\n // ts-jest configuration goes here and your IDE will suggest which configs when typing\n },\n },\n}\n"})})]}),"\n",(0,i.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,i.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport type { InitialOptionsTsJest } from 'ts-jest'\n\nconst config: InitialOptionsTsJest = {\n globals: {\n 'ts-jest': {\n // ts-jest configuration goes here\n },\n },\n}\nexport default config\n"})}),"\n",(0,i.jsx)(s.admonition,{type:"important",children:(0,i.jsxs)(s.p,{children:["When using TypeScript Jest config file, Jest will use ",(0,i.jsx)(s.code,{children:"ts-node"})," to compile the config file. ",(0,i.jsx)(s.code,{children:"ts-jest"})," doesn't take part in\nthat process."]})}),"\n",(0,i.jsx)(s.h3,{id:"options",children:"Options"}),"\n",(0,i.jsx)(s.p,{children:"All options have default values which should fit most of the projects. Click on the option's name to see details and example(s)."}),"\n",(0,i.jsxs)(s.table,{children:[(0,i.jsx)(s.thead,{children:(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.th,{children:"Option"}),(0,i.jsx)(s.th,{children:"Description"}),(0,i.jsx)(s.th,{children:"Type"}),(0,i.jsx)(s.th,{children:"Default"})]})}),(0,i.jsxs)(s.tbody,{children:[(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/compiler",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"compiler"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"string"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:'"typescript"'})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/tsconfig",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"tsconfig"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"string"}),"|",(0,i.jsx)(s.code,{children:"object"}),"|",(0,i.jsx)(s.code,{children:"boolean"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"auto"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/isolatedModules",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"isolatedModules"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"boolean"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"disabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/astTransformers",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"astTransformers"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"object"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"auto"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/diagnostics",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"diagnostics"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"boolean"}),"|",(0,i.jsx)(s.code,{children:"object"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"enabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/babelConfig",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"babelConfig"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"boolean"}),"|",(0,i.jsx)(s.code,{children:"string"}),"|",(0,i.jsx)(s.code,{children:"object"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"disabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"stringifyContentPathRegex"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"string"}),"|",(0,i.jsx)(s.code,{children:"RegExp"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"disabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/useESM",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"useESM"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/useESM",children:"Enable ESM support"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"boolean"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"auto"})})]})]})]})]})}function j(e={}){const{wrapper:s}={...(0,o.R)(),...e.components};return s?(0,i.jsx)(s,{...e,children:(0,i.jsx)(h,{...e})}):h(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>r,x:()=>d});var t=n(6540);const i={},o=t.createContext(i);function r(e){const s=t.useContext(o);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function d(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),t.createElement(o.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9660],{7603:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>d,default:()=>j,frontMatter:()=>r,metadata:()=>t,toc:()=>l});const t=JSON.parse('{"id":"getting-started/options","title":"Options","description":"Introduction","source":"@site/versioned_docs/version-27.1/getting-started/options.md","sourceDirName":"getting-started","slug":"/getting-started/options","permalink":"/ts-jest/docs/27.1/getting-started/options","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/options.md","tags":[],"version":"27.1","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"options","title":"Options"},"sidebar":"version-27.1-docs","previous":{"title":"Presets","permalink":"/ts-jest/docs/27.1/getting-started/presets"},"next":{"title":"Paths mapping","permalink":"/ts-jest/docs/27.1/getting-started/paths-mapping"}}');var i=n(4848),o=n(8453);const r={id:"options",title:"Options"},d=void 0,c={},l=[{value:"Introduction",id:"introduction",level:3},{value:"Options",id:"options",level:3}];function h(e){const s={a:"a",admonition:"admonition",code:"code",em:"em",h3:"h3",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(s.h3,{id:"introduction",children:"Introduction"}),"\n",(0,i.jsxs)(s.p,{children:["All ",(0,i.jsx)(s.code,{children:"ts-jest"})," specific options are located under the ",(0,i.jsx)(s.code,{children:"globals"})," of Jest config object in the ",(0,i.jsx)(s.code,{children:"package.json"})," file of your project,\nor through a ",(0,i.jsx)(s.code,{children:"jest.config.js"}),", or ",(0,i.jsx)(s.code,{children:"jest.config.ts"})," file."]}),"\n",(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n // ts-jest configuration goes here\n }\n }\n }\n}\n'})}),"\n",(0,i.jsx)(s.p,{children:"Or through JavaScript:"}),"\n",(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n // ts-jest configuration goes here\n },\n },\n}\n"})}),"\n",(0,i.jsxs)(s.admonition,{type:"tip",children:[(0,i.jsxs)(s.p,{children:["To utilize IDE suggestions, you can use ",(0,i.jsx)(s.code,{children:"JSDoc"})," comments to provide suggested ",(0,i.jsx)(s.code,{children:"ts-jest"})," configs for your Jest config:"]}),(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-js",children:"// jest.config.js\n/** @type {import('ts-jest').InitialOptionsTsJest} */\nmodule.exports = config = {\n // [...]\n globals: {\n 'ts-jest': {\n // ts-jest configuration goes here and your IDE will suggest which configs when typing\n },\n },\n}\n"})})]}),"\n",(0,i.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,i.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-ts",children:"// jest.config.ts\nimport type { InitialOptionsTsJest } from 'ts-jest'\n\nconst config: InitialOptionsTsJest = {\n globals: {\n 'ts-jest': {\n // ts-jest configuration goes here\n },\n },\n}\nexport default config\n"})}),"\n",(0,i.jsx)(s.admonition,{type:"important",children:(0,i.jsxs)(s.p,{children:["When using TypeScript Jest config file, Jest will use ",(0,i.jsx)(s.code,{children:"ts-node"})," to compile the config file. ",(0,i.jsx)(s.code,{children:"ts-jest"})," doesn't take part in\nthat process."]})}),"\n",(0,i.jsx)(s.h3,{id:"options",children:"Options"}),"\n",(0,i.jsx)(s.p,{children:"All options have default values which should fit most of the projects. Click on the option's name to see details and example(s)."}),"\n",(0,i.jsxs)(s.table,{children:[(0,i.jsx)(s.thead,{children:(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.th,{children:"Option"}),(0,i.jsx)(s.th,{children:"Description"}),(0,i.jsx)(s.th,{children:"Type"}),(0,i.jsx)(s.th,{children:"Default"})]})}),(0,i.jsxs)(s.tbody,{children:[(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/compiler",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"compiler"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"string"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:'"typescript"'})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/tsconfig",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"tsconfig"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"string"}),"|",(0,i.jsx)(s.code,{children:"object"}),"|",(0,i.jsx)(s.code,{children:"boolean"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"auto"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/isolatedModules",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"isolatedModules"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"boolean"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"disabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/astTransformers",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"astTransformers"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"object"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"auto"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/diagnostics",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"diagnostics"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"boolean"}),"|",(0,i.jsx)(s.code,{children:"object"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"enabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/babelConfig",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"babelConfig"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"boolean"}),"|",(0,i.jsx)(s.code,{children:"string"}),"|",(0,i.jsx)(s.code,{children:"object"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"disabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"stringifyContentPathRegex"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"string"}),"|",(0,i.jsx)(s.code,{children:"RegExp"})]}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"disabled"})})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/useESM",children:(0,i.jsx)(s.strong,{children:(0,i.jsx)(s.code,{children:"useESM"})})})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.a,{href:"options/useESM",children:"Enable ESM support"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"boolean"})}),(0,i.jsx)(s.td,{children:(0,i.jsx)(s.em,{children:"auto"})})]})]})]})]})}function j(e={}){const{wrapper:s}={...(0,o.R)(),...e.components};return s?(0,i.jsx)(s,{...e,children:(0,i.jsx)(h,{...e})}):h(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>r,x:()=>d});var t=n(6540);const i={},o=t.createContext(i);function r(e){const s=t.useContext(o);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function d(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),t.createElement(o.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/fe39109b.92f315a0.js b/assets/js/fe39109b.2dd4360a.js similarity index 99% rename from assets/js/fe39109b.92f315a0.js rename to assets/js/fe39109b.2dd4360a.js index 2b6779b9d7..e4225eeb92 100644 --- a/assets/js/fe39109b.92f315a0.js +++ b/assets/js/fe39109b.2dd4360a.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8718],{4188:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>h,frontMatter:()=>i,metadata:()=>r,toc:()=>d});const r=JSON.parse('{"id":"debugging","title":"Debugging ts-jest","description":"You can activate the debug logger by setting the environment variable TSJESTLOG before running tests.","source":"@site/versioned_docs/version-29.2/debugging.md","sourceDirName":".","slug":"/debugging","permalink":"/ts-jest/docs/debugging","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/debugging.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"id":"debugging","title":"Debugging ts-jest"},"sidebar":"version-29.1-docs","previous":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/migration"}}');var s=n(4848),a=n(8453),o=n(9489),l=n(7227);const i={id:"debugging",title:"Debugging ts-jest"},u=void 0,c={},d=[];function g(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,a.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["You can activate the debug logger by setting the environment variable ",(0,s.jsx)(t.code,{children:"TS_JEST_LOG"})," before running tests.\nThe output of the logger will be in ",(0,s.jsx)(t.strong,{children:"ts-jest.log"})," in current working directory."]}),"\n",(0,s.jsxs)(t.p,{children:["The debug logger contains some useful information about how internal ",(0,s.jsx)(t.code,{children:"ts-jest"})," works, including which files are processed,\nwhich Jest config or TypeScript config is used etc."]}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"export TS_JEST_LOG=ts-jest.log\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Windows"})}),"\n",(0,s.jsxs)(o.A,{groupId:"code-examples",children:[(0,s.jsx)(l.A,{value:"Command",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-Command",metastring:"Prompt tab",children:"set TS_JEST_LOG=ts-jest.log\n"})})}),(0,s.jsx)(l.A,{value:"PowerShell",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-PowerShell",metastring:"tab",children:"$env:TS_JEST_LOG = 'ts-jest.log'\n"})})})]})]})}function h(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(g,{...e})}):g(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var r=n(4164);const s={tabItem:"tabItem_Ymn6"};var a=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,r.A)(s.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>y});var r=n(6540),s=n(4164),a=n(4245),o=n(6347),l=n(6494),i=n(2814),u=n(5167),c=n(9900);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function g(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:s}}=e;return{value:t,label:n,attributes:r,default:s}}))}(n);return function(e){const t=(0,u.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function b(e){let{queryString:t=!1,groupId:n}=e;const s=(0,o.W6)(),a=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,i.aZ)(a),(0,r.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(s.location.search);t.set(a,e),s.replace({...s.location,search:t.toString()})}),[a,s])]}function p(e){const{defaultValue:t,queryString:n=!1,groupId:s}=e,a=g(e),[o,i]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!h({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:a}))),[u,d]=b({queryString:n,groupId:s}),[p,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[s,a]=(0,c.Dv)(n);return[s,(0,r.useCallback)((e=>{n&&a.set(e)}),[n,a])]}({groupId:s}),m=(()=>{const e=u??p;return h({value:e,tabValues:a})?e:null})();(0,l.A)((()=>{m&&i(m)}),[m]);return{selectedValue:o,selectValue:(0,r.useCallback)((e=>{if(!h({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);i(e),d(e),f(e)}),[d,f,a]),tabValues:a}}var f=n(1062);const m={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=n(4848);function j(e){let{className:t,block:n,selectedValue:r,selectValue:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:u}=(0,a.a_)(),c=e=>{const t=e.currentTarget,n=i.indexOf(t),s=l[n].value;s!==r&&(u(t),o(s))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=i.indexOf(e.currentTarget)+1;t=i[n]??i[0];break}case"ArrowLeft":{const n=i.indexOf(e.currentTarget)-1;t=i[n]??i[i.length-1];break}}t?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.A)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:a}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>i.push(e),onKeyDown:d,onClick:c,...a,className:(0,s.A)("tabs__item",m.tabItem,a?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:a}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:(0,s.A)("margin-top--md",e.props.className)}):null}return(0,v.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function w(e){const t=p(e);return(0,v.jsxs)("div",{className:(0,s.A)("tabs-container",m.tabList),children:[(0,v.jsx)(j,{...t,...e}),(0,v.jsx)(x,{...t,...e})]})}function y(e){const t=(0,f.A)();return(0,v.jsx)(w,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>l});var r=n(6540);const s={},a=r.createContext(s);function o(e){const t=r.useContext(a);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:o(e.components),r.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8718],{4188:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>h,frontMatter:()=>i,metadata:()=>r,toc:()=>d});const r=JSON.parse('{"id":"debugging","title":"Debugging ts-jest","description":"You can activate the debug logger by setting the environment variable TSJESTLOG before running tests.","source":"@site/versioned_docs/version-29.2/debugging.md","sourceDirName":".","slug":"/debugging","permalink":"/ts-jest/docs/debugging","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/debugging.md","tags":[],"version":"29.2","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"id":"debugging","title":"Debugging ts-jest"},"sidebar":"version-29.1-docs","previous":{"title":"Migration from <=23.10","permalink":"/ts-jest/docs/migration"}}');var s=n(4848),a=n(8453),o=n(9489),l=n(7227);const i={id:"debugging",title:"Debugging ts-jest"},u=void 0,c={},d=[];function g(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,a.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["You can activate the debug logger by setting the environment variable ",(0,s.jsx)(t.code,{children:"TS_JEST_LOG"})," before running tests.\nThe output of the logger will be in ",(0,s.jsx)(t.strong,{children:"ts-jest.log"})," in current working directory."]}),"\n",(0,s.jsxs)(t.p,{children:["The debug logger contains some useful information about how internal ",(0,s.jsx)(t.code,{children:"ts-jest"})," works, including which files are processed,\nwhich Jest config or TypeScript config is used etc."]}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"export TS_JEST_LOG=ts-jest.log\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Windows"})}),"\n",(0,s.jsxs)(o.A,{groupId:"code-examples",children:[(0,s.jsx)(l.A,{value:"Command",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-Command",metastring:"Prompt tab",children:"set TS_JEST_LOG=ts-jest.log\n"})})}),(0,s.jsx)(l.A,{value:"PowerShell",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-PowerShell",metastring:"tab",children:"$env:TS_JEST_LOG = 'ts-jest.log'\n"})})})]})]})}function h(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(g,{...e})}):g(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var r=n(4164);const s={tabItem:"tabItem_Ymn6"};var a=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,r.A)(s.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>y});var r=n(6540),s=n(4164),a=n(4245),o=n(6347),l=n(6494),i=n(2814),u=n(5167),c=n(9900);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function g(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:s}}=e;return{value:t,label:n,attributes:r,default:s}}))}(n);return function(e){const t=(0,u.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function b(e){let{queryString:t=!1,groupId:n}=e;const s=(0,o.W6)(),a=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,i.aZ)(a),(0,r.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(s.location.search);t.set(a,e),s.replace({...s.location,search:t.toString()})}),[a,s])]}function p(e){const{defaultValue:t,queryString:n=!1,groupId:s}=e,a=g(e),[o,i]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!h({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:a}))),[u,d]=b({queryString:n,groupId:s}),[p,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[s,a]=(0,c.Dv)(n);return[s,(0,r.useCallback)((e=>{n&&a.set(e)}),[n,a])]}({groupId:s}),m=(()=>{const e=u??p;return h({value:e,tabValues:a})?e:null})();(0,l.A)((()=>{m&&i(m)}),[m]);return{selectedValue:o,selectValue:(0,r.useCallback)((e=>{if(!h({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);i(e),d(e),f(e)}),[d,f,a]),tabValues:a}}var f=n(1062);const m={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=n(4848);function j(e){let{className:t,block:n,selectedValue:r,selectValue:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:u}=(0,a.a_)(),c=e=>{const t=e.currentTarget,n=i.indexOf(t),s=l[n].value;s!==r&&(u(t),o(s))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=i.indexOf(e.currentTarget)+1;t=i[n]??i[0];break}case"ArrowLeft":{const n=i.indexOf(e.currentTarget)-1;t=i[n]??i[i.length-1];break}}t?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.A)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:a}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>i.push(e),onKeyDown:d,onClick:c,...a,className:(0,s.A)("tabs__item",m.tabItem,a?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:a}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:(0,s.A)("margin-top--md",e.props.className)}):null}return(0,v.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function w(e){const t=p(e);return(0,v.jsxs)("div",{className:(0,s.A)("tabs-container",m.tabList),children:[(0,v.jsx)(j,{...t,...e}),(0,v.jsx)(x,{...t,...e})]})}function y(e){const t=(0,f.A)();return(0,v.jsx)(w,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>o,x:()=>l});var r=n(6540);const s={},a=r.createContext(s);function o(e){const t=r.useContext(a);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:o(e.components),r.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/fe3b9d2d.b2989998.js b/assets/js/fe3b9d2d.91ae64e8.js similarity index 97% rename from assets/js/fe3b9d2d.b2989998.js rename to assets/js/fe3b9d2d.91ae64e8.js index 4e55797bc7..7b59e0cf31 100644 --- a/assets/js/fe3b9d2d.b2989998.js +++ b/assets/js/fe3b9d2d.91ae64e8.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8418],{3638:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>c,contentTitle:()=>l,default:()=>a,frontMatter:()=>r,metadata:()=>n,toc:()=>p});const n=JSON.parse('{"id":"getting-started/options/compiler","title":"Compiler option","description":"The compiler option allows you to define the compiler to be used. It\'ll be used to load the NodeJS module holding the TypeScript compiler.","source":"@site/versioned_docs/version-27.0/getting-started/options/compiler.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/compiler","permalink":"/ts-jest/docs/27.0/getting-started/options/compiler","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/options/compiler.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733832425000,"frontMatter":{"title":"Compiler option"}}');var s=o(4848),i=o(8453);const r={title:"Compiler option"},l=void 0,c={},p=[{value:"Example",id:"example",level:3}];function d(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["The ",(0,s.jsx)(t.code,{children:"compiler"})," option allows you to define the compiler to be used. It'll be used to load the NodeJS module holding the TypeScript compiler."]}),"\n",(0,s.jsxs)(t.p,{children:["The default value is ",(0,s.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,s.jsx)(t.a,{href:"https://www.npmjs.com/package/typescript",children:"TypeScript compiler module"}),".\nThe loaded version will depend on the one installed in your project."]}),"\n",(0,s.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,s.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,s.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n compiler: 'ttypescript',\n },\n },\n}\n"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "compiler": "ttypescript"\n }\n }\n }\n}\n'})})]})}function a(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}},8453:(e,t,o)=>{o.d(t,{R:()=>r,x:()=>l});var n=o(6540);const s={},i=n.createContext(s);function r(e){const t=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:r(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8418],{3638:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>c,contentTitle:()=>l,default:()=>a,frontMatter:()=>r,metadata:()=>n,toc:()=>p});const n=JSON.parse('{"id":"getting-started/options/compiler","title":"Compiler option","description":"The compiler option allows you to define the compiler to be used. It\'ll be used to load the NodeJS module holding the TypeScript compiler.","source":"@site/versioned_docs/version-27.0/getting-started/options/compiler.md","sourceDirName":"getting-started/options","slug":"/getting-started/options/compiler","permalink":"/ts-jest/docs/27.0/getting-started/options/compiler","draft":false,"unlisted":false,"editUrl":"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/options/compiler.md","tags":[],"version":"27.0","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1733918568000,"frontMatter":{"title":"Compiler option"}}');var s=o(4848),i=o(8453);const r={title:"Compiler option"},l=void 0,c={},p=[{value:"Example",id:"example",level:3}];function d(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["The ",(0,s.jsx)(t.code,{children:"compiler"})," option allows you to define the compiler to be used. It'll be used to load the NodeJS module holding the TypeScript compiler."]}),"\n",(0,s.jsxs)(t.p,{children:["The default value is ",(0,s.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,s.jsx)(t.a,{href:"https://www.npmjs.com/package/typescript",children:"TypeScript compiler module"}),".\nThe loaded version will depend on the one installed in your project."]}),"\n",(0,s.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,s.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,s.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",children:"// jest.config.js\nmodule.exports = {\n // [...]\n globals: {\n 'ts-jest': {\n compiler: 'ttypescript',\n },\n },\n}\n"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-json",children:'// package.json\n{\n // [...]\n "jest": {\n "globals": {\n "ts-jest": {\n "compiler": "ttypescript"\n }\n }\n }\n}\n'})})]})}function a(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}},8453:(e,t,o)=>{o.d(t,{R:()=>r,x:()=>l});var n=o(6540);const s={},i=n.createContext(s);function r(e){const t=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:r(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/main.80f7cbc5.js b/assets/js/main.1a623312.js similarity index 94% rename from assets/js/main.80f7cbc5.js rename to assets/js/main.1a623312.js index ef73e99862..fecd87c3ab 100644 --- a/assets/js/main.80f7cbc5.js +++ b/assets/js/main.1a623312.js @@ -1,2 +1,2 @@ -/*! For license information please see main.80f7cbc5.js.LICENSE.txt */ -(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8792],{2413:(e,t,n)=>{"use strict";n.d(t,{A:()=>p});n(6540);var r=n(3259),o=n.n(r),s=n(4054);const a={"00e7239c":[()=>Promise.all([n.e(1869),n.e(8970)]).then(n.bind(n,1611)),"@site/docs/getting-started/options/astTransformers.md",1611],"0259e2f2":[()=>n.e(378).then(n.bind(n,30)),"@site/versioned_docs/version-28.0/getting-started/options/astTransformers.md",30],"03be7dae":[()=>n.e(4768).then(n.bind(n,2699)),"@site/docs/guides/troubleshooting.md",2699],"045c3af2":[()=>n.e(1983).then(n.t.bind(n,7361,19)),"@generated/docusaurus-plugin-content-docs/default/p/ts-jest-docs-29-0-0b4.json",7361],"057d33b8":[()=>n.e(8683).then(n.bind(n,7282)),"@site/versioned_docs/version-28.0/guides/mock-es6-class.md",7282],"06fbaa8e":[()=>n.e(942).then(n.bind(n,7568)),"@site/versioned_docs/version-27.0/debugging.md",7568],"07a7640f":[()=>n.e(7796).then(n.bind(n,5340)),"@site/versioned_docs/version-27.0/guides/troubleshooting.md",5340],"0833143f":[()=>n.e(2625).then(n.bind(n,6464)),"@site/versioned_docs/version-27.0/guides/using-with-monorepo.md",6464],"093c23a0":[()=>Promise.all([n.e(1869),n.e(5258)]).then(n.bind(n,5003)),"@site/versioned_docs/version-29.0/getting-started/options.md",5003],"0a51ecf3":[()=>Promise.all([n.e(1869),n.e(4441)]).then(n.bind(n,9638)),"@site/versioned_docs/version-29.0/guides/react-native.md",9638],"0b2fcab7":[()=>n.e(3004).then(n.bind(n,2639)),"@site/versioned_docs/version-27.0/migration.md",2639],"0d0f47fc":[()=>Promise.all([n.e(1869),n.e(4263)]).then(n.bind(n,6868)),"@site/versioned_docs/version-29.0/getting-started/presets.md",6868],"10aeaaf3":[()=>n.e(2957).then(n.bind(n,4006)),"@site/versioned_docs/version-26.5/guides/esm-support.md",4006],"1165ba55":[()=>n.e(8431).then(n.bind(n,687)),"@site/versioned_docs/version-26.5/getting-started/installation.md",687],12292045:[()=>n.e(610).then(n.bind(n,5141)),"@site/versioned_docs/version-29.2/introduction.md",5141],"15c7296a":[()=>Promise.all([n.e(1869),n.e(551)]).then(n.bind(n,6396)),"@site/versioned_docs/version-29.2/guides/mock-es6-class.md",6396],"16ada0e2":[()=>n.e(5623).then(n.bind(n,283)),"@site/versioned_docs/version-28.0/guides/using-with-monorepo.md",283],"16bac89a":[()=>n.e(5046).then(n.bind(n,6186)),"@site/versioned_docs/version-27.1/babel7-or-ts.md",6186],17896441:[()=>Promise.all([n.e(1869),n.e(8401)]).then(n.bind(n,8973)),"@theme/DocItem",8973],"1854c3e7":[()=>n.e(1797).then(n.bind(n,8357)),"@site/versioned_docs/version-26.5/babel7-or-ts.md",8357],"1917a510":[()=>Promise.all([n.e(1869),n.e(4076)]).then(n.bind(n,3644)),"@site/versioned_docs/version-29.2/getting-started/options/stringifyContentPathRegex.md",3644],"19f0fee7":[()=>n.e(8888).then(n.bind(n,5283)),"@site/versioned_docs/version-27.1/getting-started/options/diagnostics.md",5283],"1ca5b1f2":[()=>n.e(1682).then(n.bind(n,1063)),"@site/versioned_docs/version-29.2/getting-started/version-checking.md",1063],"1d7bf7da":[()=>n.e(6171).then(n.t.bind(n,8097,19)),"@generated/docusaurus-plugin-content-docs/default/p/ts-jest-docs-28-0-4b5.json",8097],"1df93b7f":[()=>Promise.all([n.e(1869),n.e(4583)]).then(n.bind(n,7521)),"@site/src/pages/index.tsx",7521],"2145bebc":[()=>n.e(8703).then(n.bind(n,2522)),"@site/versioned_docs/version-27.1/getting-started/installation.md",2522],"22e01789":[()=>n.e(2365).then(n.bind(n,9790)),"@site/versioned_docs/version-28.0/getting-started/options/tsconfig.md",9790],"22f8c605":[()=>n.e(6475).then(n.bind(n,4624)),"@site/versioned_docs/version-27.1/introduction.md",4624],"2331e073":[()=>n.e(1455).then(n.bind(n,6716)),"@site/versioned_docs/version-27.1/guides/test-helpers.md",6716],"2338618e":[()=>Promise.all([n.e(1869),n.e(8529)]).then(n.bind(n,1349)),"@site/versioned_docs/version-29.0/migration.md",1349],"24991caa":[()=>n.e(8317).then(n.bind(n,6348)),"@site/versioned_docs/version-29.0/processing.md",6348],"265d7427":[()=>n.e(7556).then(n.bind(n,1317)),"@site/versioned_docs/version-27.0/getting-started/options/stringifyContentPathRegex.md",1317],"270520cb":[()=>Promise.all([n.e(1869),n.e(3110)]).then(n.bind(n,4)),"@site/versioned_docs/version-29.0/getting-started/options/tsconfig.md",4],"295b567d":[()=>Promise.all([n.e(1869),n.e(3549)]).then(n.bind(n,462)),"@site/docs/migration.md",462],"2a3bd03a":[()=>n.e(6399).then(n.bind(n,4493)),"@site/versioned_docs/version-27.1/guides/troubleshooting.md",4493],"2b68f68f":[()=>n.e(4519).then(n.bind(n,5885)),"@site/versioned_docs/version-27.0/getting-started/installation.md",5885],"2b77ff19":[()=>n.e(3951).then(n.bind(n,789)),"@site/versioned_docs/version-29.2/guides/troubleshooting.md",789],"2b94ed59":[()=>n.e(6797).then(n.bind(n,3077)),"@site/versioned_docs/version-26.5/getting-started/options/compiler.md",3077],"2bccb399":[()=>Promise.all([n.e(1869),n.e(5154)]).then(n.bind(n,8010)),"@site/docs/debugging.md",8010],"2c53b5e4":[()=>n.e(8282).then(n.bind(n,7033)),"@site/versioned_docs/version-27.0/guides/test-helpers.md",7033],"2d143bed":[()=>n.e(1154).then(n.bind(n,1953)),"@site/versioned_docs/version-29.2/babel7-or-ts.md",1953],"2e89f3c4":[()=>n.e(4937).then(n.bind(n,7383)),"@site/versioned_docs/version-28.0/getting-started/options/isolatedModules.md",7383],"304054d0":[()=>Promise.all([n.e(1869),n.e(5501)]).then(n.bind(n,2148)),"@site/versioned_docs/version-29.2/getting-started/options/tsconfig.md",2148],"334e0bf3":[()=>n.e(3723).then(n.bind(n,2807)),"@site/versioned_docs/version-26.5/guides/using-with-monorepo.md",2807],"3432663a":[()=>n.e(9345).then(n.bind(n,7994)),"@site/versioned_docs/version-27.1/migration.md",7994],"35779d9e":[()=>Promise.all([n.e(1869),n.e(3152)]).then(n.bind(n,9372)),"@site/versioned_docs/version-29.0/getting-started/options/babelConfig.md",9372],"35ce71d5":[()=>n.e(9014).then(n.bind(n,7796)),"@site/versioned_docs/version-29.0/guides/using-with-monorepo.md",7796],"3787ba46":[()=>n.e(775).then(n.bind(n,9985)),"@site/versioned_docs/version-27.1/guides/esm-support.md",9985],"3bfdd655":[()=>n.e(4798).then(n.bind(n,2805)),"@site/versioned_docs/version-26.5/getting-started/presets.md",2805],"3e930f87":[()=>Promise.all([n.e(1869),n.e(2078)]).then(n.bind(n,3439)),"@site/docs/getting-started/options/compiler.md",3439],"4040fa6b":[()=>n.e(9032).then(n.bind(n,9182)),"@site/versioned_docs/version-26.5/introduction.md",9182],44207808:[()=>n.e(8120).then(n.bind(n,4407)),"@site/versioned_docs/version-26.5/getting-started/options/babelConfig.md",4407],"44d840ac":[()=>n.e(5775).then(n.bind(n,9353)),"@site/versioned_docs/version-26.5/getting-started/options/diagnostics.md",9353],"4aabdf82":[()=>n.e(8639).then(n.bind(n,9023)),"@site/docs/babel7-or-ts.md",9023],"4c23203f":[()=>n.e(8468).then(n.bind(n,8592)),"@site/versioned_docs/version-26.5/guides/react-native.md",8592],"4c757249":[()=>n.e(10).then(n.bind(n,4442)),"@site/versioned_docs/version-27.0/contributing.md",4442],"4d54d076":[()=>n.e(1459).then(n.bind(n,4776)),"@site/docs/contributing.md",4776],"4dd3fb5c":[()=>Promise.all([n.e(1869),n.e(2636)]).then(n.bind(n,2481)),"@site/versioned_docs/version-29.0/guides/mock-es6-class.md",2481],"4e0c07c5":[()=>Promise.all([n.e(1869),n.e(5250)]).then(n.bind(n,4422)),"@site/docs/getting-started/options.md",4422],"5316ff60":[()=>n.e(5520).then(n.bind(n,6874)),"@site/versioned_docs/version-27.0/getting-started/options/astTransformers.md",6874],"544d8072":[()=>n.e(9979).then(n.bind(n,9058)),"@site/versioned_docs/version-26.5/migration.md",9058],"54ceb25f":[()=>Promise.all([n.e(1869),n.e(6368),n.e(4317)]).then(n.bind(n,9717)),"@site/versioned_docs/version-29.2/guides/esm-support.md",9717],"54f44165":[()=>Promise.all([n.e(1869),n.e(7924)]).then(n.bind(n,1226)),"@site/docs/getting-started/installation.md",1226],"5bf3837a":[()=>n.e(2276).then(n.bind(n,128)),"@site/versioned_docs/version-26.5/processing.md",128],"5d7f6371":[()=>n.e(5834).then(n.t.bind(n,2331,19)),"@generated/docusaurus-plugin-content-docs/default/p/ts-jest-docs-next-fd5.json",2331],"5e95c892":[()=>n.e(9647).then(n.bind(n,3124)),"@theme/DocsRoot",3124],"5e9f5e1a":[()=>Promise.resolve().then(n.bind(n,4784)),"@generated/docusaurus.config",4784],"61b42bb5":[()=>n.e(346).then(n.bind(n,3049)),"@site/versioned_docs/version-26.5/getting-started/paths-mapping.md",3049],"629085c0":[()=>Promise.all([n.e(1869),n.e(2452)]).then(n.bind(n,3088)),"@site/versioned_docs/version-29.2/getting-started/options/compiler.md",3088],"6625be2a":[()=>Promise.all([n.e(1869),n.e(4136)]).then(n.bind(n,6195)),"@site/docs/guides/mock-es6-class.md",6195],"673550c0":[()=>n.e(6460).then(n.bind(n,3732)),"@site/versioned_docs/version-28.0/guides/esm-support.md",3732],"6789ef91":[()=>n.e(3960).then(n.bind(n,7195)),"@site/versioned_docs/version-26.5/getting-started/options.md",7195],"684ec830":[()=>Promise.all([n.e(1869),n.e(5584)]).then(n.bind(n,6563)),"@site/versioned_docs/version-29.0/getting-started/options/compiler.md",6563],"6bc4332d":[()=>n.e(7350).then(n.bind(n,5671)),"@site/versioned_docs/version-27.1/processing.md",5671],"6cdc57e1":[()=>n.e(9995).then(n.bind(n,8544)),"@site/versioned_docs/version-27.0/processing.md",8544],"6f04af8d":[()=>Promise.all([n.e(1869),n.e(6018)]).then(n.bind(n,4358)),"@site/docs/getting-started/options/isolatedModules.md",4358],"6f4d8994":[()=>n.e(3021).then(n.bind(n,6973)),"@site/versioned_docs/version-27.1/getting-started/version-checking.md",6973],"6f82a5f4":[()=>n.e(3429).then(n.bind(n,6164)),"@site/versioned_docs/version-26.5/guides/test-helpers.md",6164],"7335c74d":[()=>Promise.all([n.e(1869),n.e(7983)]).then(n.bind(n,5379)),"@site/versioned_docs/version-29.0/debugging.md",5379],"73f5a02c":[()=>Promise.all([n.e(1869),n.e(8080)]).then(n.bind(n,6248)),"@site/docs/getting-started/options/stringifyContentPathRegex.md",6248],"75ab14ad":[()=>n.e(6506).then(n.bind(n,59)),"@site/versioned_docs/version-26.5/getting-started/options/stringifyContentPathRegex.md",59],"78f0a226":[()=>n.e(8313).then(n.bind(n,7329)),"@site/versioned_docs/version-27.1/getting-started/options/babelConfig.md",7329],"7aac82f3":[()=>Promise.all([n.e(1869),n.e(6576)]).then(n.bind(n,9271)),"@site/versioned_docs/version-29.0/guides/esm-support.md",9271],"7b562fc7":[()=>n.e(8647).then(n.bind(n,7662)),"@site/versioned_docs/version-29.2/contributing.md",7662],"7d1a64ae":[()=>n.e(7352).then(n.bind(n,1946)),"@site/versioned_docs/version-27.1/contributing.md",1946],"7dafce35":[()=>Promise.all([n.e(1869),n.e(7083)]).then(n.bind(n,8366)),"@site/versioned_docs/version-29.0/getting-started/options/astTransformers.md",8366],"7ec61308":[()=>Promise.all([n.e(1869),n.e(992)]).then(n.bind(n,6723)),"@site/docs/getting-started/paths-mapping.md",6723],"801c4327":[()=>n.e(2817).then(n.bind(n,1369)),"@site/versioned_docs/version-27.1/getting-started/presets.md",1369],"850a2979":[()=>n.e(6964).then(n.bind(n,6113)),"@site/versioned_docs/version-27.0/getting-started/presets.md",6113],"86b5844b":[()=>Promise.all([n.e(1869),n.e(988)]).then(n.bind(n,1471)),"@site/docs/guides/react-native.md",1471],"8b2f9623":[()=>n.e(8629).then(n.bind(n,5035)),"@site/versioned_docs/version-29.0/guides/troubleshooting.md",5035],"8b622911":[()=>n.e(1268).then(n.bind(n,8119)),"@site/versioned_docs/version-27.1/getting-started/options/tsconfig.md",8119],"8cf61ec4":[()=>n.e(5799).then(n.bind(n,3977)),"@site/versioned_docs/version-27.0/getting-started/options/isolatedModules.md",3977],"8d536cde":[()=>n.e(8979).then(n.bind(n,102)),"@site/versioned_docs/version-28.0/contributing.md",102],"8e5d45d9":[()=>n.e(7425).then(n.bind(n,2261)),"@site/versioned_docs/version-29.0/introduction.md",2261],"8e81f9bb":[()=>n.e(8192).then(n.bind(n,1172)),"@site/versioned_docs/version-28.0/getting-started/options.md",1172],"902acc05":[()=>n.e(8632).then(n.bind(n,2373)),"@site/versioned_docs/version-27.0/guides/esm-support.md",2373],90645308:[()=>Promise.all([n.e(1869),n.e(1626)]).then(n.bind(n,6747)),"@site/versioned_docs/version-29.2/getting-started/options/useESM.md",6747],"91ac5286":[()=>n.e(6614).then(n.t.bind(n,7218,19)),"@generated/docusaurus-plugin-content-docs/default/p/ts-jest-docs-808.json",7218],"9226f379":[()=>n.e(5567).then(n.bind(n,7204)),"@site/versioned_docs/version-28.0/getting-started/presets.md",7204],"96f7df01":[()=>n.e(4316).then(n.bind(n,7827)),"@site/versioned_docs/version-27.0/babel7-or-ts.md",7827],"9762b2e9":[()=>n.e(6553).then(n.bind(n,5862)),"@site/versioned_docs/version-27.1/getting-started/paths-mapping.md",5862],"981dc414":[()=>Promise.all([n.e(1869),n.e(2777)]).then(n.bind(n,1263)),"@site/versioned_docs/version-29.0/getting-started/options/useESM.md",1263],"9920b385":[()=>Promise.all([n.e(1869),n.e(4571)]).then(n.bind(n,9482)),"@site/docs/getting-started/options/babelConfig.md",9482],"9d036230":[()=>n.e(8810).then(n.bind(n,1592)),"@site/versioned_docs/version-29.0/contributing.md",1592],"9ed06f50":[()=>n.e(5174).then(n.bind(n,1128)),"@site/versioned_docs/version-28.0/migration.md",1128],a09c2993:[()=>n.e(5899).then(n.bind(n,4778)),"@site/docs/introduction.md",4778],a132b5de:[()=>n.e(7132).then(n.bind(n,6376)),"@site/versioned_docs/version-27.0/getting-started/options/diagnostics.md",6376],a21658d9:[()=>n.e(1173).then(n.bind(n,1297)),"@site/versioned_docs/version-28.0/guides/react-native.md",1297],a5ea8355:[()=>n.e(3762).then(n.bind(n,9687)),"@site/versioned_docs/version-27.1/getting-started/options/isolatedModules.md",9687],a6267c3c:[()=>n.e(6586).then(n.bind(n,4967)),"@site/versioned_docs/version-28.0/introduction.md",4967],a7423e3b:[()=>Promise.all([n.e(1869),n.e(3322)]).then(n.bind(n,4374)),"@site/versioned_docs/version-29.2/getting-started/installation.md",4374],a7456010:[()=>n.e(1235).then(n.t.bind(n,8552,19)),"@generated/docusaurus-plugin-content-pages/default/__plugin.json",8552],a7bc29db:[()=>Promise.all([n.e(1869),n.e(6368),n.e(9123)]).then(n.bind(n,8486)),"@site/versioned_docs/version-29.2/getting-started/presets.md",8486],a7bd4aaa:[()=>n.e(7098).then(n.bind(n,9011)),"@theme/DocVersionRoot",9011],a8c654d7:[()=>n.e(2587).then(n.bind(n,4149)),"@site/versioned_docs/version-28.0/debugging.md",4149],a8e3f14e:[()=>Promise.all([n.e(1869),n.e(2234)]).then(n.bind(n,2257)),"@site/versioned_docs/version-29.0/getting-started/options/stringifyContentPathRegex.md",2257],a94703ab:[()=>Promise.all([n.e(1869),n.e(9048)]).then(n.bind(n,8001)),"@theme/DocRoot",8001],aaf1bd4c:[()=>n.e(863).then(n.bind(n,706)),"@site/versioned_docs/version-26.5/getting-started/options/isolatedModules.md",706],aba21aa0:[()=>n.e(5742).then(n.t.bind(n,7093,19)),"@generated/docusaurus-plugin-content-docs/default/__plugin.json",7093],ae1ffb77:[()=>n.e(698).then(n.bind(n,4369)),"@site/versioned_docs/version-28.0/getting-started/version-checking.md",4369],aeb5491d:[()=>n.e(4572).then(n.bind(n,3497)),"@site/versioned_docs/version-28.0/babel7-or-ts.md",3497],aeb823d8:[()=>Promise.all([n.e(1869),n.e(3790)]).then(n.bind(n,1286)),"@site/versioned_docs/version-29.2/getting-started/options/isolatedModules.md",1286],afb030c9:[()=>n.e(4746).then(n.bind(n,7833)),"@site/versioned_docs/version-28.0/processing.md",7833],b317f538:[()=>n.e(8392).then(n.bind(n,9211)),"@site/versioned_docs/version-29.0/getting-started/version-checking.md",9211],b519512b:[()=>n.e(8116).then(n.bind(n,6468)),"@site/versioned_docs/version-27.0/guides/react-native.md",6468],b72fc7f8:[()=>Promise.all([n.e(1869),n.e(9610)]).then(n.bind(n,831)),"@site/versioned_docs/version-29.2/migration.md",831],b809b403:[()=>n.e(7693).then(n.bind(n,8982)),"@site/versioned_docs/version-27.0/getting-started/options/useESM.md",8982],b96776d9:[()=>Promise.all([n.e(1869),n.e(4623)]).then(n.bind(n,2845)),"@site/versioned_docs/version-29.2/guides/react-native.md",2845],b97f260e:[()=>n.e(742).then(n.t.bind(n,3738,19)),"@generated/docusaurus-plugin-content-docs/default/p/ts-jest-docs-27-1-008.json",3738],ba1cda66:[()=>n.e(4009).then(n.t.bind(n,2402,19)),"@generated/docusaurus-plugin-content-docs/default/p/ts-jest-docs-26-5-67f.json",2402],bdf18d96:[()=>n.e(7555).then(n.bind(n,4078)),"@site/versioned_docs/version-27.0/guides/mock-es6-class.md",4078],bdfec613:[()=>n.e(4733).then(n.bind(n,2219)),"@site/versioned_docs/version-27.0/getting-started/options.md",2219],bf341476:[()=>n.e(2402).then(n.bind(n,4306)),"@site/versioned_docs/version-27.0/introduction.md",4306],c010a830:[()=>n.e(7015).then(n.bind(n,8945)),"@site/versioned_docs/version-27.1/getting-started/options/useESM.md",8945],c1932cab:[()=>n.e(8719).then(n.bind(n,1386)),"@site/versioned_docs/version-28.0/getting-started/options/babelConfig.md",1386],c1a7450f:[()=>Promise.all([n.e(1869),n.e(6120)]).then(n.bind(n,9156)),"@site/docs/getting-started/options/useESM.md",9156],c6326909:[()=>n.e(6121).then(n.bind(n,4616)),"@site/versioned_docs/version-27.0/getting-started/version-checking.md",4616],c8c88a41:[()=>n.e(1907).then(n.bind(n,5937)),"@site/versioned_docs/version-28.0/getting-started/paths-mapping.md",5937],c8eced56:[()=>n.e(1344).then(n.bind(n,6329)),"@site/versioned_docs/version-28.0/getting-started/options/useESM.md",6329],ceaad8ca:[()=>Promise.all([n.e(1869),n.e(4681)]).then(n.bind(n,7705)),"@site/docs/getting-started/options/diagnostics.md",7705],cf5c42a2:[()=>n.e(2659).then(n.bind(n,4920)),"@site/versioned_docs/version-27.1/getting-started/options/stringifyContentPathRegex.md",4920],cffdf1e5:[()=>n.e(4631).then(n.bind(n,92)),"@site/versioned_docs/version-28.0/guides/troubleshooting.md",92],d0e697d4:[()=>n.e(6842).then(n.bind(n,4061)),"@site/versioned_docs/version-27.1/guides/using-with-monorepo.md",4061],d296dded:[()=>n.e(8563).then(n.bind(n,3791)),"@site/versioned_docs/version-29.2/guides/using-with-monorepo.md",3791],d3b43630:[()=>n.e(9592).then(n.bind(n,5216)),"@site/versioned_docs/version-27.1/guides/mock-es6-class.md",5216],d4836a8e:[()=>Promise.all([n.e(1869),n.e(6368),n.e(106)]).then(n.bind(n,3191)),"@site/docs/guides/esm-support.md",3191],d4a6dd78:[()=>n.e(1163).then(n.bind(n,1435)),"@site/versioned_docs/version-27.0/getting-started/options/babelConfig.md",1435],d6f9473b:[()=>n.e(9314).then(n.bind(n,4904)),"@site/versioned_docs/version-27.1/getting-started/options/astTransformers.md",4904],d8357ecf:[()=>n.e(5580).then(n.bind(n,5145)),"@site/versioned_docs/version-27.1/getting-started/options/compiler.md",5145],d9f7da4b:[()=>n.e(6556).then(n.bind(n,7332)),"@site/versioned_docs/version-26.5/getting-started/version-checking.md",7332],da431c38:[()=>Promise.all([n.e(1869),n.e(1952)]).then(n.bind(n,9319)),"@site/versioned_docs/version-29.0/getting-started/installation.md",9319],dabdf990:[()=>n.e(3808).then(n.bind(n,5504)),"@site/versioned_docs/version-28.0/getting-started/options/compiler.md",5504],db49ae54:[()=>n.e(9197).then(n.bind(n,6340)),"@site/versioned_docs/version-26.5/guides/mock-es6-class.md",6340],db795cf2:[()=>n.e(5369).then(n.bind(n,1382)),"@site/versioned_docs/version-27.1/debugging.md",1382],dcbdd84f:[()=>n.e(4716).then(n.bind(n,8885)),"@site/versioned_docs/version-26.5/debugging.md",8885],e3a856ae:[()=>n.e(6771).then(n.bind(n,6807)),"@site/versioned_docs/version-27.1/guides/react-native.md",6807],e5e34c6b:[()=>n.e(4218).then(n.bind(n,4437)),"@site/docs/getting-started/version-checking.md",4437],e8085380:[()=>n.e(3284).then(n.bind(n,3330)),"@site/versioned_docs/version-28.0/getting-started/options/diagnostics.md",3330],e87a3571:[()=>n.e(7252).then(n.bind(n,6505)),"@site/versioned_docs/version-29.0/babel7-or-ts.md",6505],e8b13364:[()=>n.e(4523).then(n.bind(n,9480)),"@site/versioned_docs/version-26.5/getting-started/options/astTransformers.md",9480],eabdbf07:[()=>n.e(5100).then(n.bind(n,5990)),"@site/docs/processing.md",5990],ec6c7123:[()=>n.e(2091).then(n.bind(n,1561)),"@site/versioned_docs/version-26.5/guides/troubleshooting.md",1561],f01607c0:[()=>n.e(6714).then(n.bind(n,4200)),"@site/versioned_docs/version-28.0/getting-started/installation.md",4200],f0683fd0:[()=>n.e(6672).then(n.bind(n,8059)),"@site/docs/guides/using-with-monorepo.md",8059],f154e663:[()=>Promise.all([n.e(1869),n.e(9643)]).then(n.bind(n,4788)),"@site/versioned_docs/version-29.0/getting-started/options/diagnostics.md",4788],f298e69b:[()=>Promise.all([n.e(1869),n.e(2804)]).then(n.bind(n,7834)),"@site/versioned_docs/version-29.0/getting-started/options/isolatedModules.md",7834],f371827f:[()=>Promise.all([n.e(1869),n.e(4811)]).then(n.bind(n,541)),"@site/versioned_docs/version-29.2/getting-started/options.md",541],f4dd4a52:[()=>Promise.all([n.e(1869),n.e(397)]).then(n.bind(n,2421)),"@site/versioned_docs/version-29.2/getting-started/options/babelConfig.md",2421],f6605416:[()=>Promise.all([n.e(1869),n.e(4343)]).then(n.bind(n,373)),"@site/versioned_docs/version-29.0/getting-started/paths-mapping.md",373],f6aab920:[()=>n.e(7320).then(n.bind(n,4100)),"@site/versioned_docs/version-26.5/getting-started/options/tsconfig.md",4100],f6f550ec:[()=>Promise.all([n.e(1869),n.e(983)]).then(n.bind(n,4914)),"@site/versioned_docs/version-29.2/getting-started/paths-mapping.md",4914],f7416098:[()=>n.e(2186).then(n.bind(n,4281)),"@site/versioned_docs/version-27.0/getting-started/paths-mapping.md",4281],f7862b07:[()=>n.e(8539).then(n.bind(n,6830)),"@site/versioned_docs/version-26.5/contributing.md",6830],f7b7430f:[()=>n.e(1678).then(n.bind(n,9637)),"@site/versioned_docs/version-27.0/getting-started/options/tsconfig.md",9637],f7cb2af4:[()=>Promise.all([n.e(1869),n.e(7036)]).then(n.bind(n,7322)),"@site/docs/getting-started/options/tsconfig.md",7322],f8fb2427:[()=>Promise.all([n.e(1869),n.e(6734)]).then(n.bind(n,1687)),"@site/versioned_docs/version-29.2/getting-started/options/diagnostics.md",1687],fa061f97:[()=>Promise.all([n.e(1869),n.e(9547)]).then(n.bind(n,1121)),"@site/versioned_docs/version-29.2/getting-started/options/astTransformers.md",1121],fa17a3e5:[()=>n.e(8054).then(n.bind(n,8350)),"@site/src/pages/versions.tsx",8350],fb1b7a48:[()=>n.e(9566).then(n.bind(n,2649)),"@site/versioned_docs/version-28.0/getting-started/options/stringifyContentPathRegex.md",2649],fc43d853:[()=>n.e(5609).then(n.bind(n,5709)),"@site/versioned_docs/version-29.2/processing.md",5709],fc80686b:[()=>Promise.all([n.e(1869),n.e(6368),n.e(2440)]).then(n.bind(n,6105)),"@site/docs/getting-started/presets.md",6105],fcfccc02:[()=>n.e(4103).then(n.t.bind(n,3105,19)),"@generated/docusaurus-plugin-content-docs/default/p/ts-jest-docs-27-0-721.json",3105],fdcb7476:[()=>n.e(9660).then(n.bind(n,7603)),"@site/versioned_docs/version-27.1/getting-started/options.md",7603],fe39109b:[()=>Promise.all([n.e(1869),n.e(8718)]).then(n.bind(n,4188)),"@site/versioned_docs/version-29.2/debugging.md",4188],fe3b9d2d:[()=>n.e(8418).then(n.bind(n,3638)),"@site/versioned_docs/version-27.0/getting-started/options/compiler.md",3638]};var i=n(4848);function l(e){let{error:t,retry:n,pastDelay:r}=e;return t?(0,i.jsxs)("div",{style:{textAlign:"center",color:"#fff",backgroundColor:"#fa383e",borderColor:"#fa383e",borderStyle:"solid",borderRadius:"0.25rem",borderWidth:"1px",boxSizing:"border-box",display:"block",padding:"1rem",flex:"0 0 50%",marginLeft:"25%",marginRight:"25%",marginTop:"5rem",maxWidth:"50%",width:"100%"},children:[(0,i.jsx)("p",{children:String(t)}),(0,i.jsx)("div",{children:(0,i.jsx)("button",{type:"button",onClick:n,children:"Retry"})})]}):r?(0,i.jsx)("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh"},children:(0,i.jsx)("svg",{id:"loader",style:{width:128,height:110,position:"absolute",top:"calc(100vh - 64%)"},viewBox:"0 0 45 45",xmlns:"http://www.w3.org/2000/svg",stroke:"#61dafb",children:(0,i.jsxs)("g",{fill:"none",fillRule:"evenodd",transform:"translate(1 1)",strokeWidth:"2",children:[(0,i.jsxs)("circle",{cx:"22",cy:"22",r:"6",strokeOpacity:"0",children:[(0,i.jsx)("animate",{attributeName:"r",begin:"1.5s",dur:"3s",values:"6;22",calcMode:"linear",repeatCount:"indefinite"}),(0,i.jsx)("animate",{attributeName:"stroke-opacity",begin:"1.5s",dur:"3s",values:"1;0",calcMode:"linear",repeatCount:"indefinite"}),(0,i.jsx)("animate",{attributeName:"stroke-width",begin:"1.5s",dur:"3s",values:"2;0",calcMode:"linear",repeatCount:"indefinite"})]}),(0,i.jsxs)("circle",{cx:"22",cy:"22",r:"6",strokeOpacity:"0",children:[(0,i.jsx)("animate",{attributeName:"r",begin:"3s",dur:"3s",values:"6;22",calcMode:"linear",repeatCount:"indefinite"}),(0,i.jsx)("animate",{attributeName:"stroke-opacity",begin:"3s",dur:"3s",values:"1;0",calcMode:"linear",repeatCount:"indefinite"}),(0,i.jsx)("animate",{attributeName:"stroke-width",begin:"3s",dur:"3s",values:"2;0",calcMode:"linear",repeatCount:"indefinite"})]}),(0,i.jsx)("circle",{cx:"22",cy:"22",r:"8",children:(0,i.jsx)("animate",{attributeName:"r",begin:"0s",dur:"1.5s",values:"6;1;2;3;4;5;6",calcMode:"linear",repeatCount:"indefinite"})})]})})}):null}var c=n(1604),u=n(3363);function d(e,t){if("*"===e)return o()({loading:l,loader:()=>n.e(2560).then(n.bind(n,2560)),modules:["@theme/NotFound"],webpack:()=>[2560],render(e,t){const n=e.default;return(0,i.jsx)(u.W,{value:{plugin:{name:"native",id:"default"}},children:(0,i.jsx)(n,{...t})})}});const r=s[`${e}-${t}`],d={},p=[],f=[],g=(0,c.A)(r);return Object.entries(g).forEach((e=>{let[t,n]=e;const r=a[n];r&&(d[t]=r[0],p.push(r[1]),f.push(r[2]))})),o().Map({loading:l,loader:d,modules:p,webpack:()=>f,render(t,n){const o=JSON.parse(JSON.stringify(r));Object.entries(t).forEach((t=>{let[n,r]=t;const s=r.default;if(!s)throw new Error(`The page component at ${e} doesn't have a default export. This makes it impossible to render anything. Consider default-exporting a React component.`);"object"!=typeof s&&"function"!=typeof s||Object.keys(r).filter((e=>"default"!==e)).forEach((e=>{s[e]=r[e]}));let a=o;const i=n.split(".");i.slice(0,-1).forEach((e=>{a=a[e]})),a[i[i.length-1]]=s}));const s=o.__comp;delete o.__comp;const a=o.__context;delete o.__context;const l=o.__props;return delete o.__props,(0,i.jsx)(u.W,{value:a,children:(0,i.jsx)(s,{...o,...l,...n})})}})}const p=[{path:"/ts-jest/versions",component:d("/ts-jest/versions","aad"),exact:!0},{path:"/ts-jest/docs",component:d("/ts-jest/docs","a0b"),routes:[{path:"/ts-jest/docs/26.5",component:d("/ts-jest/docs/26.5","aa8"),routes:[{path:"/ts-jest/docs/26.5",component:d("/ts-jest/docs/26.5","93c"),routes:[{path:"/ts-jest/docs/26.5/",component:d("/ts-jest/docs/26.5/","103"),exact:!0,sidebar:"version-26.5-docs"},{path:"/ts-jest/docs/26.5/babel7-or-ts",component:d("/ts-jest/docs/26.5/babel7-or-ts","821"),exact:!0,sidebar:"version-26.5-docs"},{path:"/ts-jest/docs/26.5/contributing",component:d("/ts-jest/docs/26.5/contributing","8d2"),exact:!0,sidebar:"version-26.5-docs"},{path:"/ts-jest/docs/26.5/debugging",component:d("/ts-jest/docs/26.5/debugging","a80"),exact:!0,sidebar:"version-26.5-docs"},{path:"/ts-jest/docs/26.5/getting-started/installation",component:d("/ts-jest/docs/26.5/getting-started/installation","c42"),exact:!0,sidebar:"version-26.5-docs"},{path:"/ts-jest/docs/26.5/getting-started/options",component:d("/ts-jest/docs/26.5/getting-started/options","972"),exact:!0,sidebar:"version-26.5-docs"},{path:"/ts-jest/docs/26.5/getting-started/options/astTransformers",component:d("/ts-jest/docs/26.5/getting-started/options/astTransformers","8bc"),exact:!0},{path:"/ts-jest/docs/26.5/getting-started/options/babelConfig",component:d("/ts-jest/docs/26.5/getting-started/options/babelConfig","814"),exact:!0},{path:"/ts-jest/docs/26.5/getting-started/options/compiler",component:d("/ts-jest/docs/26.5/getting-started/options/compiler","afb"),exact:!0},{path:"/ts-jest/docs/26.5/getting-started/options/diagnostics",component:d("/ts-jest/docs/26.5/getting-started/options/diagnostics","8c4"),exact:!0},{path:"/ts-jest/docs/26.5/getting-started/options/isolatedModules",component:d("/ts-jest/docs/26.5/getting-started/options/isolatedModules","bac"),exact:!0},{path:"/ts-jest/docs/26.5/getting-started/options/stringifyContentPathRegex",component:d("/ts-jest/docs/26.5/getting-started/options/stringifyContentPathRegex","17b"),exact:!0},{path:"/ts-jest/docs/26.5/getting-started/options/tsconfig",component:d("/ts-jest/docs/26.5/getting-started/options/tsconfig","d69"),exact:!0},{path:"/ts-jest/docs/26.5/getting-started/paths-mapping",component:d("/ts-jest/docs/26.5/getting-started/paths-mapping","4ff"),exact:!0,sidebar:"version-26.5-docs"},{path:"/ts-jest/docs/26.5/getting-started/presets",component:d("/ts-jest/docs/26.5/getting-started/presets","0db"),exact:!0,sidebar:"version-26.5-docs"},{path:"/ts-jest/docs/26.5/getting-started/version-checking",component:d("/ts-jest/docs/26.5/getting-started/version-checking","39d"),exact:!0,sidebar:"version-26.5-docs"},{path:"/ts-jest/docs/26.5/guides/esm-support",component:d("/ts-jest/docs/26.5/guides/esm-support","2da"),exact:!0,sidebar:"version-26.5-docs"},{path:"/ts-jest/docs/26.5/guides/mock-es6-class",component:d("/ts-jest/docs/26.5/guides/mock-es6-class","784"),exact:!0,sidebar:"version-26.5-docs"},{path:"/ts-jest/docs/26.5/guides/react-native",component:d("/ts-jest/docs/26.5/guides/react-native","042"),exact:!0,sidebar:"version-26.5-docs"},{path:"/ts-jest/docs/26.5/guides/test-helpers",component:d("/ts-jest/docs/26.5/guides/test-helpers","cad"),exact:!0,sidebar:"version-26.5-docs"},{path:"/ts-jest/docs/26.5/guides/troubleshooting",component:d("/ts-jest/docs/26.5/guides/troubleshooting","a80"),exact:!0,sidebar:"version-26.5-docs"},{path:"/ts-jest/docs/26.5/guides/using-with-monorepo",component:d("/ts-jest/docs/26.5/guides/using-with-monorepo","a54"),exact:!0,sidebar:"version-26.5-docs"},{path:"/ts-jest/docs/26.5/migration",component:d("/ts-jest/docs/26.5/migration","108"),exact:!0,sidebar:"version-26.5-docs"},{path:"/ts-jest/docs/26.5/processing",component:d("/ts-jest/docs/26.5/processing","82e"),exact:!0,sidebar:"version-26.5-docs"}]}]},{path:"/ts-jest/docs/27.0",component:d("/ts-jest/docs/27.0","7ba"),routes:[{path:"/ts-jest/docs/27.0",component:d("/ts-jest/docs/27.0","546"),routes:[{path:"/ts-jest/docs/27.0/",component:d("/ts-jest/docs/27.0/","9b8"),exact:!0,sidebar:"version-27.0-docs"},{path:"/ts-jest/docs/27.0/babel7-or-ts",component:d("/ts-jest/docs/27.0/babel7-or-ts","dd2"),exact:!0,sidebar:"version-27.0-docs"},{path:"/ts-jest/docs/27.0/contributing",component:d("/ts-jest/docs/27.0/contributing","bd5"),exact:!0,sidebar:"version-27.0-docs"},{path:"/ts-jest/docs/27.0/debugging",component:d("/ts-jest/docs/27.0/debugging","657"),exact:!0,sidebar:"version-27.0-docs"},{path:"/ts-jest/docs/27.0/getting-started/installation",component:d("/ts-jest/docs/27.0/getting-started/installation","d8e"),exact:!0,sidebar:"version-27.0-docs"},{path:"/ts-jest/docs/27.0/getting-started/options",component:d("/ts-jest/docs/27.0/getting-started/options","93a"),exact:!0,sidebar:"version-27.0-docs"},{path:"/ts-jest/docs/27.0/getting-started/options/astTransformers",component:d("/ts-jest/docs/27.0/getting-started/options/astTransformers","01b"),exact:!0},{path:"/ts-jest/docs/27.0/getting-started/options/babelConfig",component:d("/ts-jest/docs/27.0/getting-started/options/babelConfig","afa"),exact:!0},{path:"/ts-jest/docs/27.0/getting-started/options/compiler",component:d("/ts-jest/docs/27.0/getting-started/options/compiler","d47"),exact:!0},{path:"/ts-jest/docs/27.0/getting-started/options/diagnostics",component:d("/ts-jest/docs/27.0/getting-started/options/diagnostics","fec"),exact:!0},{path:"/ts-jest/docs/27.0/getting-started/options/isolatedModules",component:d("/ts-jest/docs/27.0/getting-started/options/isolatedModules","76c"),exact:!0},{path:"/ts-jest/docs/27.0/getting-started/options/stringifyContentPathRegex",component:d("/ts-jest/docs/27.0/getting-started/options/stringifyContentPathRegex","a40"),exact:!0},{path:"/ts-jest/docs/27.0/getting-started/options/tsconfig",component:d("/ts-jest/docs/27.0/getting-started/options/tsconfig","588"),exact:!0},{path:"/ts-jest/docs/27.0/getting-started/options/useESM",component:d("/ts-jest/docs/27.0/getting-started/options/useESM","6fb"),exact:!0},{path:"/ts-jest/docs/27.0/getting-started/paths-mapping",component:d("/ts-jest/docs/27.0/getting-started/paths-mapping","307"),exact:!0,sidebar:"version-27.0-docs"},{path:"/ts-jest/docs/27.0/getting-started/presets",component:d("/ts-jest/docs/27.0/getting-started/presets","b0b"),exact:!0,sidebar:"version-27.0-docs"},{path:"/ts-jest/docs/27.0/getting-started/version-checking",component:d("/ts-jest/docs/27.0/getting-started/version-checking","cae"),exact:!0,sidebar:"version-27.0-docs"},{path:"/ts-jest/docs/27.0/guides/esm-support",component:d("/ts-jest/docs/27.0/guides/esm-support","726"),exact:!0,sidebar:"version-27.0-docs"},{path:"/ts-jest/docs/27.0/guides/mock-es6-class",component:d("/ts-jest/docs/27.0/guides/mock-es6-class","a01"),exact:!0,sidebar:"version-27.0-docs"},{path:"/ts-jest/docs/27.0/guides/react-native",component:d("/ts-jest/docs/27.0/guides/react-native","b31"),exact:!0,sidebar:"version-27.0-docs"},{path:"/ts-jest/docs/27.0/guides/test-helpers",component:d("/ts-jest/docs/27.0/guides/test-helpers","7d7"),exact:!0,sidebar:"version-27.0-docs"},{path:"/ts-jest/docs/27.0/guides/troubleshooting",component:d("/ts-jest/docs/27.0/guides/troubleshooting","224"),exact:!0,sidebar:"version-27.0-docs"},{path:"/ts-jest/docs/27.0/guides/using-with-monorepo",component:d("/ts-jest/docs/27.0/guides/using-with-monorepo","629"),exact:!0,sidebar:"version-27.0-docs"},{path:"/ts-jest/docs/27.0/migration",component:d("/ts-jest/docs/27.0/migration","2cd"),exact:!0,sidebar:"version-27.0-docs"},{path:"/ts-jest/docs/27.0/processing",component:d("/ts-jest/docs/27.0/processing","f2a"),exact:!0,sidebar:"version-27.0-docs"}]}]},{path:"/ts-jest/docs/27.1",component:d("/ts-jest/docs/27.1","407"),routes:[{path:"/ts-jest/docs/27.1",component:d("/ts-jest/docs/27.1","1ac"),routes:[{path:"/ts-jest/docs/27.1/",component:d("/ts-jest/docs/27.1/","99b"),exact:!0,sidebar:"version-27.1-docs"},{path:"/ts-jest/docs/27.1/babel7-or-ts",component:d("/ts-jest/docs/27.1/babel7-or-ts","03d"),exact:!0,sidebar:"version-27.1-docs"},{path:"/ts-jest/docs/27.1/contributing",component:d("/ts-jest/docs/27.1/contributing","696"),exact:!0,sidebar:"version-27.1-docs"},{path:"/ts-jest/docs/27.1/debugging",component:d("/ts-jest/docs/27.1/debugging","b00"),exact:!0,sidebar:"version-27.1-docs"},{path:"/ts-jest/docs/27.1/getting-started/installation",component:d("/ts-jest/docs/27.1/getting-started/installation","026"),exact:!0,sidebar:"version-27.1-docs"},{path:"/ts-jest/docs/27.1/getting-started/options",component:d("/ts-jest/docs/27.1/getting-started/options","540"),exact:!0,sidebar:"version-27.1-docs"},{path:"/ts-jest/docs/27.1/getting-started/options/astTransformers",component:d("/ts-jest/docs/27.1/getting-started/options/astTransformers","adc"),exact:!0},{path:"/ts-jest/docs/27.1/getting-started/options/babelConfig",component:d("/ts-jest/docs/27.1/getting-started/options/babelConfig","b2a"),exact:!0},{path:"/ts-jest/docs/27.1/getting-started/options/compiler",component:d("/ts-jest/docs/27.1/getting-started/options/compiler","a3d"),exact:!0},{path:"/ts-jest/docs/27.1/getting-started/options/diagnostics",component:d("/ts-jest/docs/27.1/getting-started/options/diagnostics","da6"),exact:!0},{path:"/ts-jest/docs/27.1/getting-started/options/isolatedModules",component:d("/ts-jest/docs/27.1/getting-started/options/isolatedModules","8ef"),exact:!0},{path:"/ts-jest/docs/27.1/getting-started/options/stringifyContentPathRegex",component:d("/ts-jest/docs/27.1/getting-started/options/stringifyContentPathRegex","0db"),exact:!0},{path:"/ts-jest/docs/27.1/getting-started/options/tsconfig",component:d("/ts-jest/docs/27.1/getting-started/options/tsconfig","20d"),exact:!0},{path:"/ts-jest/docs/27.1/getting-started/options/useESM",component:d("/ts-jest/docs/27.1/getting-started/options/useESM","21e"),exact:!0},{path:"/ts-jest/docs/27.1/getting-started/paths-mapping",component:d("/ts-jest/docs/27.1/getting-started/paths-mapping","3a9"),exact:!0,sidebar:"version-27.1-docs"},{path:"/ts-jest/docs/27.1/getting-started/presets",component:d("/ts-jest/docs/27.1/getting-started/presets","6dd"),exact:!0,sidebar:"version-27.1-docs"},{path:"/ts-jest/docs/27.1/getting-started/version-checking",component:d("/ts-jest/docs/27.1/getting-started/version-checking","90d"),exact:!0,sidebar:"version-27.1-docs"},{path:"/ts-jest/docs/27.1/guides/esm-support",component:d("/ts-jest/docs/27.1/guides/esm-support","1ba"),exact:!0,sidebar:"version-27.1-docs"},{path:"/ts-jest/docs/27.1/guides/mock-es6-class",component:d("/ts-jest/docs/27.1/guides/mock-es6-class","c23"),exact:!0,sidebar:"version-27.1-docs"},{path:"/ts-jest/docs/27.1/guides/react-native",component:d("/ts-jest/docs/27.1/guides/react-native","e45"),exact:!0,sidebar:"version-27.1-docs"},{path:"/ts-jest/docs/27.1/guides/test-helpers",component:d("/ts-jest/docs/27.1/guides/test-helpers","7f0"),exact:!0,sidebar:"version-27.1-docs"},{path:"/ts-jest/docs/27.1/guides/troubleshooting",component:d("/ts-jest/docs/27.1/guides/troubleshooting","eeb"),exact:!0,sidebar:"version-27.1-docs"},{path:"/ts-jest/docs/27.1/guides/using-with-monorepo",component:d("/ts-jest/docs/27.1/guides/using-with-monorepo","1f6"),exact:!0,sidebar:"version-27.1-docs"},{path:"/ts-jest/docs/27.1/migration",component:d("/ts-jest/docs/27.1/migration","4f8"),exact:!0,sidebar:"version-27.1-docs"},{path:"/ts-jest/docs/27.1/processing",component:d("/ts-jest/docs/27.1/processing","24a"),exact:!0,sidebar:"version-27.1-docs"}]}]},{path:"/ts-jest/docs/28.0",component:d("/ts-jest/docs/28.0","822"),routes:[{path:"/ts-jest/docs/28.0",component:d("/ts-jest/docs/28.0","4f0"),routes:[{path:"/ts-jest/docs/28.0/",component:d("/ts-jest/docs/28.0/","ab8"),exact:!0,sidebar:"version-28.0-docs"},{path:"/ts-jest/docs/28.0/babel7-or-ts",component:d("/ts-jest/docs/28.0/babel7-or-ts","b6d"),exact:!0,sidebar:"version-28.0-docs"},{path:"/ts-jest/docs/28.0/contributing",component:d("/ts-jest/docs/28.0/contributing","38b"),exact:!0,sidebar:"version-28.0-docs"},{path:"/ts-jest/docs/28.0/debugging",component:d("/ts-jest/docs/28.0/debugging","73e"),exact:!0,sidebar:"version-28.0-docs"},{path:"/ts-jest/docs/28.0/getting-started/installation",component:d("/ts-jest/docs/28.0/getting-started/installation","633"),exact:!0,sidebar:"version-28.0-docs"},{path:"/ts-jest/docs/28.0/getting-started/options",component:d("/ts-jest/docs/28.0/getting-started/options","12f"),exact:!0,sidebar:"version-28.0-docs"},{path:"/ts-jest/docs/28.0/getting-started/options/astTransformers",component:d("/ts-jest/docs/28.0/getting-started/options/astTransformers","69b"),exact:!0},{path:"/ts-jest/docs/28.0/getting-started/options/babelConfig",component:d("/ts-jest/docs/28.0/getting-started/options/babelConfig","60b"),exact:!0},{path:"/ts-jest/docs/28.0/getting-started/options/compiler",component:d("/ts-jest/docs/28.0/getting-started/options/compiler","cb5"),exact:!0},{path:"/ts-jest/docs/28.0/getting-started/options/diagnostics",component:d("/ts-jest/docs/28.0/getting-started/options/diagnostics","f27"),exact:!0},{path:"/ts-jest/docs/28.0/getting-started/options/isolatedModules",component:d("/ts-jest/docs/28.0/getting-started/options/isolatedModules","a6c"),exact:!0},{path:"/ts-jest/docs/28.0/getting-started/options/stringifyContentPathRegex",component:d("/ts-jest/docs/28.0/getting-started/options/stringifyContentPathRegex","663"),exact:!0},{path:"/ts-jest/docs/28.0/getting-started/options/tsconfig",component:d("/ts-jest/docs/28.0/getting-started/options/tsconfig","39b"),exact:!0},{path:"/ts-jest/docs/28.0/getting-started/options/useESM",component:d("/ts-jest/docs/28.0/getting-started/options/useESM","8c8"),exact:!0},{path:"/ts-jest/docs/28.0/getting-started/paths-mapping",component:d("/ts-jest/docs/28.0/getting-started/paths-mapping","284"),exact:!0,sidebar:"version-28.0-docs"},{path:"/ts-jest/docs/28.0/getting-started/presets",component:d("/ts-jest/docs/28.0/getting-started/presets","8d5"),exact:!0,sidebar:"version-28.0-docs"},{path:"/ts-jest/docs/28.0/getting-started/version-checking",component:d("/ts-jest/docs/28.0/getting-started/version-checking","097"),exact:!0,sidebar:"version-28.0-docs"},{path:"/ts-jest/docs/28.0/guides/esm-support",component:d("/ts-jest/docs/28.0/guides/esm-support","963"),exact:!0,sidebar:"version-28.0-docs"},{path:"/ts-jest/docs/28.0/guides/mock-es6-class",component:d("/ts-jest/docs/28.0/guides/mock-es6-class","3ec"),exact:!0,sidebar:"version-28.0-docs"},{path:"/ts-jest/docs/28.0/guides/react-native",component:d("/ts-jest/docs/28.0/guides/react-native","218"),exact:!0,sidebar:"version-28.0-docs"},{path:"/ts-jest/docs/28.0/guides/troubleshooting",component:d("/ts-jest/docs/28.0/guides/troubleshooting","265"),exact:!0,sidebar:"version-28.0-docs"},{path:"/ts-jest/docs/28.0/guides/using-with-monorepo",component:d("/ts-jest/docs/28.0/guides/using-with-monorepo","ee1"),exact:!0,sidebar:"version-28.0-docs"},{path:"/ts-jest/docs/28.0/migration",component:d("/ts-jest/docs/28.0/migration","be2"),exact:!0,sidebar:"version-28.0-docs"},{path:"/ts-jest/docs/28.0/processing",component:d("/ts-jest/docs/28.0/processing","f3a"),exact:!0,sidebar:"version-28.0-docs"}]}]},{path:"/ts-jest/docs/29.0",component:d("/ts-jest/docs/29.0","3d2"),routes:[{path:"/ts-jest/docs/29.0",component:d("/ts-jest/docs/29.0","32e"),routes:[{path:"/ts-jest/docs/29.0/",component:d("/ts-jest/docs/29.0/","610"),exact:!0,sidebar:"version-29.0-docs"},{path:"/ts-jest/docs/29.0/babel7-or-ts",component:d("/ts-jest/docs/29.0/babel7-or-ts","9a7"),exact:!0,sidebar:"version-29.0-docs"},{path:"/ts-jest/docs/29.0/contributing",component:d("/ts-jest/docs/29.0/contributing","6fe"),exact:!0,sidebar:"version-29.0-docs"},{path:"/ts-jest/docs/29.0/debugging",component:d("/ts-jest/docs/29.0/debugging","03b"),exact:!0,sidebar:"version-29.0-docs"},{path:"/ts-jest/docs/29.0/getting-started/installation",component:d("/ts-jest/docs/29.0/getting-started/installation","b65"),exact:!0,sidebar:"version-29.0-docs"},{path:"/ts-jest/docs/29.0/getting-started/options",component:d("/ts-jest/docs/29.0/getting-started/options","d68"),exact:!0,sidebar:"version-29.0-docs"},{path:"/ts-jest/docs/29.0/getting-started/options/astTransformers",component:d("/ts-jest/docs/29.0/getting-started/options/astTransformers","8b6"),exact:!0},{path:"/ts-jest/docs/29.0/getting-started/options/babelConfig",component:d("/ts-jest/docs/29.0/getting-started/options/babelConfig","2b2"),exact:!0},{path:"/ts-jest/docs/29.0/getting-started/options/compiler",component:d("/ts-jest/docs/29.0/getting-started/options/compiler","112"),exact:!0},{path:"/ts-jest/docs/29.0/getting-started/options/diagnostics",component:d("/ts-jest/docs/29.0/getting-started/options/diagnostics","571"),exact:!0},{path:"/ts-jest/docs/29.0/getting-started/options/isolatedModules",component:d("/ts-jest/docs/29.0/getting-started/options/isolatedModules","bf1"),exact:!0},{path:"/ts-jest/docs/29.0/getting-started/options/stringifyContentPathRegex",component:d("/ts-jest/docs/29.0/getting-started/options/stringifyContentPathRegex","4a1"),exact:!0},{path:"/ts-jest/docs/29.0/getting-started/options/tsconfig",component:d("/ts-jest/docs/29.0/getting-started/options/tsconfig","db3"),exact:!0},{path:"/ts-jest/docs/29.0/getting-started/options/useESM",component:d("/ts-jest/docs/29.0/getting-started/options/useESM","8ea"),exact:!0},{path:"/ts-jest/docs/29.0/getting-started/paths-mapping",component:d("/ts-jest/docs/29.0/getting-started/paths-mapping","638"),exact:!0,sidebar:"version-29.0-docs"},{path:"/ts-jest/docs/29.0/getting-started/presets",component:d("/ts-jest/docs/29.0/getting-started/presets","721"),exact:!0,sidebar:"version-29.0-docs"},{path:"/ts-jest/docs/29.0/getting-started/version-checking",component:d("/ts-jest/docs/29.0/getting-started/version-checking","67a"),exact:!0,sidebar:"version-29.0-docs"},{path:"/ts-jest/docs/29.0/guides/esm-support",component:d("/ts-jest/docs/29.0/guides/esm-support","ce5"),exact:!0,sidebar:"version-29.0-docs"},{path:"/ts-jest/docs/29.0/guides/mock-es6-class",component:d("/ts-jest/docs/29.0/guides/mock-es6-class","5e6"),exact:!0,sidebar:"version-29.0-docs"},{path:"/ts-jest/docs/29.0/guides/react-native",component:d("/ts-jest/docs/29.0/guides/react-native","816"),exact:!0,sidebar:"version-29.0-docs"},{path:"/ts-jest/docs/29.0/guides/troubleshooting",component:d("/ts-jest/docs/29.0/guides/troubleshooting","77e"),exact:!0,sidebar:"version-29.0-docs"},{path:"/ts-jest/docs/29.0/guides/using-with-monorepo",component:d("/ts-jest/docs/29.0/guides/using-with-monorepo","d3d"),exact:!0,sidebar:"version-29.0-docs"},{path:"/ts-jest/docs/29.0/migration",component:d("/ts-jest/docs/29.0/migration","abf"),exact:!0,sidebar:"version-29.0-docs"},{path:"/ts-jest/docs/29.0/processing",component:d("/ts-jest/docs/29.0/processing","596"),exact:!0,sidebar:"version-29.0-docs"}]}]},{path:"/ts-jest/docs/next",component:d("/ts-jest/docs/next","d6b"),routes:[{path:"/ts-jest/docs/next",component:d("/ts-jest/docs/next","434"),routes:[{path:"/ts-jest/docs/next/",component:d("/ts-jest/docs/next/","681"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/babel7-or-ts",component:d("/ts-jest/docs/next/babel7-or-ts","57d"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/contributing",component:d("/ts-jest/docs/next/contributing","bd3"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/debugging",component:d("/ts-jest/docs/next/debugging","23d"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/getting-started/installation",component:d("/ts-jest/docs/next/getting-started/installation","c3f"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/getting-started/options",component:d("/ts-jest/docs/next/getting-started/options","94f"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/getting-started/options/astTransformers",component:d("/ts-jest/docs/next/getting-started/options/astTransformers","e4a"),exact:!0},{path:"/ts-jest/docs/next/getting-started/options/babelConfig",component:d("/ts-jest/docs/next/getting-started/options/babelConfig","b8a"),exact:!0},{path:"/ts-jest/docs/next/getting-started/options/compiler",component:d("/ts-jest/docs/next/getting-started/options/compiler","1ea"),exact:!0},{path:"/ts-jest/docs/next/getting-started/options/diagnostics",component:d("/ts-jest/docs/next/getting-started/options/diagnostics","7fb"),exact:!0},{path:"/ts-jest/docs/next/getting-started/options/isolatedModules",component:d("/ts-jest/docs/next/getting-started/options/isolatedModules","c98"),exact:!0},{path:"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex",component:d("/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex","478"),exact:!0},{path:"/ts-jest/docs/next/getting-started/options/tsconfig",component:d("/ts-jest/docs/next/getting-started/options/tsconfig","b74"),exact:!0},{path:"/ts-jest/docs/next/getting-started/options/useESM",component:d("/ts-jest/docs/next/getting-started/options/useESM","2cd"),exact:!0},{path:"/ts-jest/docs/next/getting-started/paths-mapping",component:d("/ts-jest/docs/next/getting-started/paths-mapping","8ab"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/getting-started/presets",component:d("/ts-jest/docs/next/getting-started/presets","63e"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/getting-started/version-checking",component:d("/ts-jest/docs/next/getting-started/version-checking","010"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/guides/esm-support",component:d("/ts-jest/docs/next/guides/esm-support","a47"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/guides/mock-es6-class",component:d("/ts-jest/docs/next/guides/mock-es6-class","c79"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/guides/react-native",component:d("/ts-jest/docs/next/guides/react-native","c0f"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/guides/troubleshooting",component:d("/ts-jest/docs/next/guides/troubleshooting","55f"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/guides/using-with-monorepo",component:d("/ts-jest/docs/next/guides/using-with-monorepo","fb5"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/migration",component:d("/ts-jest/docs/next/migration","4a3"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/processing",component:d("/ts-jest/docs/next/processing","046"),exact:!0,sidebar:"docs"}]}]},{path:"/ts-jest/docs",component:d("/ts-jest/docs","78e"),routes:[{path:"/ts-jest/docs",component:d("/ts-jest/docs","c5e"),routes:[{path:"/ts-jest/docs/",component:d("/ts-jest/docs/","8d2"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/babel7-or-ts",component:d("/ts-jest/docs/babel7-or-ts","3d3"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/contributing",component:d("/ts-jest/docs/contributing","d38"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/debugging",component:d("/ts-jest/docs/debugging","724"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/getting-started/installation",component:d("/ts-jest/docs/getting-started/installation","cc2"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/getting-started/options",component:d("/ts-jest/docs/getting-started/options","907"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/getting-started/options/astTransformers",component:d("/ts-jest/docs/getting-started/options/astTransformers","e80"),exact:!0},{path:"/ts-jest/docs/getting-started/options/babelConfig",component:d("/ts-jest/docs/getting-started/options/babelConfig","079"),exact:!0},{path:"/ts-jest/docs/getting-started/options/compiler",component:d("/ts-jest/docs/getting-started/options/compiler","a0a"),exact:!0},{path:"/ts-jest/docs/getting-started/options/diagnostics",component:d("/ts-jest/docs/getting-started/options/diagnostics","866"),exact:!0},{path:"/ts-jest/docs/getting-started/options/isolatedModules",component:d("/ts-jest/docs/getting-started/options/isolatedModules","e8f"),exact:!0},{path:"/ts-jest/docs/getting-started/options/stringifyContentPathRegex",component:d("/ts-jest/docs/getting-started/options/stringifyContentPathRegex","393"),exact:!0},{path:"/ts-jest/docs/getting-started/options/tsconfig",component:d("/ts-jest/docs/getting-started/options/tsconfig","c4e"),exact:!0},{path:"/ts-jest/docs/getting-started/options/useESM",component:d("/ts-jest/docs/getting-started/options/useESM","545"),exact:!0},{path:"/ts-jest/docs/getting-started/paths-mapping",component:d("/ts-jest/docs/getting-started/paths-mapping","c75"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/getting-started/presets",component:d("/ts-jest/docs/getting-started/presets","13c"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/getting-started/version-checking",component:d("/ts-jest/docs/getting-started/version-checking","9ad"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/guides/esm-support",component:d("/ts-jest/docs/guides/esm-support","692"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/guides/mock-es6-class",component:d("/ts-jest/docs/guides/mock-es6-class","f93"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/guides/react-native",component:d("/ts-jest/docs/guides/react-native","852"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/guides/troubleshooting",component:d("/ts-jest/docs/guides/troubleshooting","345"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/guides/using-with-monorepo",component:d("/ts-jest/docs/guides/using-with-monorepo","bc8"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/migration",component:d("/ts-jest/docs/migration","c7a"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/processing",component:d("/ts-jest/docs/processing","35e"),exact:!0,sidebar:"version-29.1-docs"}]}]}]},{path:"/ts-jest/",component:d("/ts-jest/","5db"),exact:!0},{path:"*",component:d("*")}]},8848:(e,t,n)=>{"use strict";n.d(t,{o:()=>s,x:()=>a});var r=n(6540),o=n(4848);const s=r.createContext(!1);function a(e){let{children:t}=e;const[n,a]=(0,r.useState)(!1);return(0,r.useEffect)((()=>{a(!0)}),[]),(0,o.jsx)(s.Provider,{value:n,children:t})}},7522:(e,t,n)=>{"use strict";var r=n(6540),o=n(5338),s=n(545),a=n(4625),i=n(4784),l=n(1712);const c=[n(5300),n(4753),n(5729),n(8252),n(8155)];var u=n(2413),d=n(6347),p=n(2831),f=n(4848);function g(e){let{children:t}=e;return(0,f.jsx)(f.Fragment,{children:t})}var m=n(1141),h=n(7639),b=n(8180),v=n(6957),y=n(9817),w=n(2098),k=n(9503);const x="default";var j=n(4609),_=n(1210);function S(){const{i18n:{currentLocale:e,defaultLocale:t,localeConfigs:n}}=(0,h.A)(),r=(0,w.o)(),o=n[e].htmlLang,s=e=>e.replace("-","_");return(0,f.jsxs)(m.A,{children:[Object.entries(n).map((e=>{let[t,{htmlLang:n}]=e;return(0,f.jsx)("link",{rel:"alternate",href:r.createUrl({locale:t,fullyQualified:!0}),hrefLang:n},t)})),(0,f.jsx)("link",{rel:"alternate",href:r.createUrl({locale:t,fullyQualified:!0}),hrefLang:"x-default"}),(0,f.jsx)("meta",{property:"og:locale",content:s(o)}),Object.values(n).filter((e=>o!==e.htmlLang)).map((e=>(0,f.jsx)("meta",{property:"og:locale:alternate",content:s(e.htmlLang)},`meta-og-${e.htmlLang}`)))]})}function E(e){let{permalink:t}=e;const{siteConfig:{url:n}}=(0,h.A)(),r=function(){const{siteConfig:{url:e,baseUrl:t,trailingSlash:n}}=(0,h.A)(),{pathname:r}=(0,d.zy)();return e+(0,j.Ks)((0,b.Ay)(r),{trailingSlash:n,baseUrl:t})}(),o=t?`${n}${t}`:r;return(0,f.jsxs)(m.A,{children:[(0,f.jsx)("meta",{property:"og:url",content:o}),(0,f.jsx)("link",{rel:"canonical",href:o})]})}function C(){const{i18n:{currentLocale:e}}=(0,h.A)(),{metadata:t,image:n}=(0,v.p)();return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsxs)(m.A,{children:[(0,f.jsx)("meta",{name:"twitter:card",content:"summary_large_image"}),(0,f.jsx)("body",{className:k.w})]}),n&&(0,f.jsx)(y.be,{image:n}),(0,f.jsx)(E,{}),(0,f.jsx)(S,{}),(0,f.jsx)(_.A,{tag:x,locale:e}),(0,f.jsx)(m.A,{children:t.map(((e,t)=>(0,f.jsx)("meta",{...e},t)))})]})}const T=new Map;var A=n(8848),P=n(3366),R=n(6494);function N(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r{const r=t.default?.[e]??t[e];return r?.(...n)}));return()=>o.forEach((e=>e?.()))}const L=function(e){let{children:t,location:n,previousLocation:r}=e;return(0,R.A)((()=>{r!==n&&(!function(e){let{location:t,previousLocation:n}=e;if(!n)return;const r=t.pathname===n.pathname,o=t.hash===n.hash,s=t.search===n.search;if(r&&o&&!s)return;const{hash:a}=t;if(a){const e=decodeURIComponent(a.substring(1)),t=document.getElementById(e);t?.scrollIntoView()}else window.scrollTo(0,0)}({location:n,previousLocation:r}),N("onRouteDidUpdate",{previousLocation:r,location:n}))}),[r,n]),t};function O(e){const t=Array.from(new Set([e,decodeURI(e)])).map((e=>(0,p.u)(u.A,e))).flat();return Promise.all(t.map((e=>e.route.component.preload?.())))}class M extends r.Component{previousLocation;routeUpdateCleanupCb;constructor(e){super(e),this.previousLocation=null,this.routeUpdateCleanupCb=l.A.canUseDOM?N("onRouteUpdate",{previousLocation:null,location:this.props.location}):()=>{},this.state={nextRouteHasLoaded:!0}}shouldComponentUpdate(e,t){if(e.location===this.props.location)return t.nextRouteHasLoaded;const n=e.location;return this.previousLocation=this.props.location,this.setState({nextRouteHasLoaded:!1}),this.routeUpdateCleanupCb=N("onRouteUpdate",{previousLocation:this.previousLocation,location:n}),O(n.pathname).then((()=>{this.routeUpdateCleanupCb(),this.setState({nextRouteHasLoaded:!0})})).catch((e=>{console.warn(e),window.location.reload()})),!1}render(){const{children:e,location:t}=this.props;return(0,f.jsx)(L,{previousLocation:this.previousLocation,location:t,children:(0,f.jsx)(d.qh,{location:t,render:()=>e})})}}const D=M,I="__docusaurus-base-url-issue-banner-container",F="__docusaurus-base-url-issue-banner",z="__docusaurus-base-url-issue-banner-suggestion-container";function B(e){return`\ndocument.addEventListener('DOMContentLoaded', function maybeInsertBanner() {\n var shouldInsert = typeof window['docusaurus'] === 'undefined';\n shouldInsert && insertBanner();\n});\n\nfunction insertBanner() {\n var bannerContainer = document.createElement('div');\n bannerContainer.id = '${I}';\n var bannerHtml = ${JSON.stringify(function(e){return`\n
\n

Your Docusaurus site did not load properly.

\n

A very common reason is a wrong site baseUrl configuration.

\n

Current configured baseUrl = ${e} ${"/"===e?" (default value)":""}

\n

We suggest trying baseUrl =

\n
\n`}(e)).replace(/{let{route:t}=e;return!0===t.exact})))return T.set(e.pathname,e.pathname),e;const t=e.pathname.trim().replace(/(?:\/index)?\.html$/,"")||"/";return T.set(e.pathname,t),{...e,pathname:t}}((0,d.zy)());return(0,f.jsx)(D,{location:e,children:V})}function K(){return(0,f.jsx)(H.A,{children:(0,f.jsx)(P.l,{children:(0,f.jsxs)(A.x,{children:[(0,f.jsxs)(g,{children:[(0,f.jsx)(q,{}),(0,f.jsx)(C,{}),(0,f.jsx)(U,{}),(0,f.jsx)(Q,{})]}),(0,f.jsx)(W,{})]})})})}var Y=n(4054);const Z=function(e){try{return document.createElement("link").relList.supports(e)}catch{return!1}}("prefetch")?function(e){return new Promise(((t,n)=>{if("undefined"==typeof document)return void n();const r=document.createElement("link");r.setAttribute("rel","prefetch"),r.setAttribute("href",e),r.onload=()=>t(),r.onerror=()=>n();const o=document.getElementsByTagName("head")[0]??document.getElementsByName("script")[0]?.parentNode;o?.appendChild(r)}))}:function(e){return new Promise(((t,n)=>{const r=new XMLHttpRequest;r.open("GET",e,!0),r.withCredentials=!0,r.onload=()=>{200===r.status?t():n()},r.send(null)}))};var X=n(1604);const J=new Set,ee=new Set,te=()=>navigator.connection?.effectiveType.includes("2g")||navigator.connection?.saveData,ne={prefetch:e=>{if(!(e=>!te()&&!ee.has(e)&&!J.has(e))(e))return!1;J.add(e);const t=(0,p.u)(u.A,e).flatMap((e=>{return t=e.route.path,Object.entries(Y).filter((e=>{let[n]=e;return n.replace(/-[^-]+$/,"")===t})).flatMap((e=>{let[,t]=e;return Object.values((0,X.A)(t))}));var t}));return Promise.all(t.map((e=>{const t=n.gca(e);return t&&!t.includes("undefined")?Z(t).catch((()=>{})):Promise.resolve()})))},preload:e=>!!(e=>!te()&&!ee.has(e))(e)&&(ee.add(e),O(e))},re=Object.freeze(ne);function oe(e){let{children:t}=e;return"hash"===i.default.future.experimental_router?(0,f.jsx)(a.I9,{children:t}):(0,f.jsx)(a.Kd,{children:t})}const se=Boolean(!0);if(l.A.canUseDOM){window.docusaurus=re;const e=document.getElementById("__docusaurus"),t=(0,f.jsx)(s.vd,{children:(0,f.jsx)(oe,{children:(0,f.jsx)(K,{})})}),n=(e,t)=>{console.error("Docusaurus React Root onRecoverableError:",e,t)},a=()=>{if(window.docusaurusRoot)window.docusaurusRoot.render(t);else if(se)window.docusaurusRoot=o.hydrateRoot(e,t,{onRecoverableError:n});else{const r=o.createRoot(e,{onRecoverableError:n});r.render(t),window.docusaurusRoot=r}};O(window.location.pathname).then((()=>{(0,r.startTransition)(a)}))}},3366:(e,t,n)=>{"use strict";n.d(t,{o:()=>d,l:()=>p});var r=n(6540),o=n(4784);const s=JSON.parse('{"docusaurus-plugin-content-docs":{"default":{"path":"/ts-jest/docs","versions":[{"name":"current","label":"Next","isLast":false,"path":"/ts-jest/docs/next","mainDocId":"introduction","docs":[{"id":"babel7-or-ts","path":"/ts-jest/docs/next/babel7-or-ts","sidebar":"docs"},{"id":"contributing","path":"/ts-jest/docs/next/contributing","sidebar":"docs"},{"id":"debugging","path":"/ts-jest/docs/next/debugging","sidebar":"docs"},{"id":"getting-started/installation","path":"/ts-jest/docs/next/getting-started/installation","sidebar":"docs"},{"id":"getting-started/options","path":"/ts-jest/docs/next/getting-started/options","sidebar":"docs"},{"id":"getting-started/options/astTransformers","path":"/ts-jest/docs/next/getting-started/options/astTransformers"},{"id":"getting-started/options/babelConfig","path":"/ts-jest/docs/next/getting-started/options/babelConfig"},{"id":"getting-started/options/compiler","path":"/ts-jest/docs/next/getting-started/options/compiler"},{"id":"getting-started/options/diagnostics","path":"/ts-jest/docs/next/getting-started/options/diagnostics"},{"id":"getting-started/options/isolatedModules","path":"/ts-jest/docs/next/getting-started/options/isolatedModules"},{"id":"getting-started/options/stringifyContentPathRegex","path":"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex"},{"id":"getting-started/options/tsconfig","path":"/ts-jest/docs/next/getting-started/options/tsconfig"},{"id":"getting-started/options/useESM","path":"/ts-jest/docs/next/getting-started/options/useESM"},{"id":"getting-started/paths-mapping","path":"/ts-jest/docs/next/getting-started/paths-mapping","sidebar":"docs"},{"id":"getting-started/presets","path":"/ts-jest/docs/next/getting-started/presets","sidebar":"docs"},{"id":"getting-started/version-checking","path":"/ts-jest/docs/next/getting-started/version-checking","sidebar":"docs"},{"id":"guides/esm-support","path":"/ts-jest/docs/next/guides/esm-support","sidebar":"docs"},{"id":"guides/mock-es6-class","path":"/ts-jest/docs/next/guides/mock-es6-class","sidebar":"docs"},{"id":"guides/react-native","path":"/ts-jest/docs/next/guides/react-native","sidebar":"docs"},{"id":"guides/troubleshooting","path":"/ts-jest/docs/next/guides/troubleshooting","sidebar":"docs"},{"id":"guides/using-with-monorepo","path":"/ts-jest/docs/next/guides/using-with-monorepo","sidebar":"docs"},{"id":"introduction","path":"/ts-jest/docs/next/","sidebar":"docs"},{"id":"migration","path":"/ts-jest/docs/next/migration","sidebar":"docs"},{"id":"processing","path":"/ts-jest/docs/next/processing","sidebar":"docs"}],"draftIds":[],"sidebars":{"docs":{"link":{"path":"/ts-jest/docs/next/","label":"introduction"}}}},{"name":"29.2","label":"29.2","isLast":true,"path":"/ts-jest/docs","mainDocId":"introduction","docs":[{"id":"babel7-or-ts","path":"/ts-jest/docs/babel7-or-ts","sidebar":"version-29.1-docs"},{"id":"contributing","path":"/ts-jest/docs/contributing","sidebar":"version-29.1-docs"},{"id":"debugging","path":"/ts-jest/docs/debugging","sidebar":"version-29.1-docs"},{"id":"getting-started/installation","path":"/ts-jest/docs/getting-started/installation","sidebar":"version-29.1-docs"},{"id":"getting-started/options","path":"/ts-jest/docs/getting-started/options","sidebar":"version-29.1-docs"},{"id":"getting-started/options/astTransformers","path":"/ts-jest/docs/getting-started/options/astTransformers"},{"id":"getting-started/options/babelConfig","path":"/ts-jest/docs/getting-started/options/babelConfig"},{"id":"getting-started/options/compiler","path":"/ts-jest/docs/getting-started/options/compiler"},{"id":"getting-started/options/diagnostics","path":"/ts-jest/docs/getting-started/options/diagnostics"},{"id":"getting-started/options/isolatedModules","path":"/ts-jest/docs/getting-started/options/isolatedModules"},{"id":"getting-started/options/stringifyContentPathRegex","path":"/ts-jest/docs/getting-started/options/stringifyContentPathRegex"},{"id":"getting-started/options/tsconfig","path":"/ts-jest/docs/getting-started/options/tsconfig"},{"id":"getting-started/options/useESM","path":"/ts-jest/docs/getting-started/options/useESM"},{"id":"getting-started/paths-mapping","path":"/ts-jest/docs/getting-started/paths-mapping","sidebar":"version-29.1-docs"},{"id":"getting-started/presets","path":"/ts-jest/docs/getting-started/presets","sidebar":"version-29.1-docs"},{"id":"getting-started/version-checking","path":"/ts-jest/docs/getting-started/version-checking","sidebar":"version-29.1-docs"},{"id":"guides/esm-support","path":"/ts-jest/docs/guides/esm-support","sidebar":"version-29.1-docs"},{"id":"guides/mock-es6-class","path":"/ts-jest/docs/guides/mock-es6-class","sidebar":"version-29.1-docs"},{"id":"guides/react-native","path":"/ts-jest/docs/guides/react-native","sidebar":"version-29.1-docs"},{"id":"guides/troubleshooting","path":"/ts-jest/docs/guides/troubleshooting","sidebar":"version-29.1-docs"},{"id":"guides/using-with-monorepo","path":"/ts-jest/docs/guides/using-with-monorepo","sidebar":"version-29.1-docs"},{"id":"introduction","path":"/ts-jest/docs/","sidebar":"version-29.1-docs"},{"id":"migration","path":"/ts-jest/docs/migration","sidebar":"version-29.1-docs"},{"id":"processing","path":"/ts-jest/docs/processing","sidebar":"version-29.1-docs"}],"draftIds":[],"sidebars":{"version-29.1-docs":{"link":{"path":"/ts-jest/docs/","label":"introduction"}}}},{"name":"29.0","label":"29.0","isLast":false,"path":"/ts-jest/docs/29.0","mainDocId":"introduction","docs":[{"id":"babel7-or-ts","path":"/ts-jest/docs/29.0/babel7-or-ts","sidebar":"version-29.0-docs"},{"id":"contributing","path":"/ts-jest/docs/29.0/contributing","sidebar":"version-29.0-docs"},{"id":"debugging","path":"/ts-jest/docs/29.0/debugging","sidebar":"version-29.0-docs"},{"id":"getting-started/installation","path":"/ts-jest/docs/29.0/getting-started/installation","sidebar":"version-29.0-docs"},{"id":"getting-started/options","path":"/ts-jest/docs/29.0/getting-started/options","sidebar":"version-29.0-docs"},{"id":"getting-started/options/astTransformers","path":"/ts-jest/docs/29.0/getting-started/options/astTransformers"},{"id":"getting-started/options/babelConfig","path":"/ts-jest/docs/29.0/getting-started/options/babelConfig"},{"id":"getting-started/options/compiler","path":"/ts-jest/docs/29.0/getting-started/options/compiler"},{"id":"getting-started/options/diagnostics","path":"/ts-jest/docs/29.0/getting-started/options/diagnostics"},{"id":"getting-started/options/isolatedModules","path":"/ts-jest/docs/29.0/getting-started/options/isolatedModules"},{"id":"getting-started/options/stringifyContentPathRegex","path":"/ts-jest/docs/29.0/getting-started/options/stringifyContentPathRegex"},{"id":"getting-started/options/tsconfig","path":"/ts-jest/docs/29.0/getting-started/options/tsconfig"},{"id":"getting-started/options/useESM","path":"/ts-jest/docs/29.0/getting-started/options/useESM"},{"id":"getting-started/paths-mapping","path":"/ts-jest/docs/29.0/getting-started/paths-mapping","sidebar":"version-29.0-docs"},{"id":"getting-started/presets","path":"/ts-jest/docs/29.0/getting-started/presets","sidebar":"version-29.0-docs"},{"id":"getting-started/version-checking","path":"/ts-jest/docs/29.0/getting-started/version-checking","sidebar":"version-29.0-docs"},{"id":"guides/esm-support","path":"/ts-jest/docs/29.0/guides/esm-support","sidebar":"version-29.0-docs"},{"id":"guides/mock-es6-class","path":"/ts-jest/docs/29.0/guides/mock-es6-class","sidebar":"version-29.0-docs"},{"id":"guides/react-native","path":"/ts-jest/docs/29.0/guides/react-native","sidebar":"version-29.0-docs"},{"id":"guides/troubleshooting","path":"/ts-jest/docs/29.0/guides/troubleshooting","sidebar":"version-29.0-docs"},{"id":"guides/using-with-monorepo","path":"/ts-jest/docs/29.0/guides/using-with-monorepo","sidebar":"version-29.0-docs"},{"id":"introduction","path":"/ts-jest/docs/29.0/","sidebar":"version-29.0-docs"},{"id":"migration","path":"/ts-jest/docs/29.0/migration","sidebar":"version-29.0-docs"},{"id":"processing","path":"/ts-jest/docs/29.0/processing","sidebar":"version-29.0-docs"}],"draftIds":[],"sidebars":{"version-29.0-docs":{"link":{"path":"/ts-jest/docs/29.0/","label":"introduction"}}}},{"name":"28.0","label":"28.0","isLast":false,"path":"/ts-jest/docs/28.0","mainDocId":"introduction","docs":[{"id":"babel7-or-ts","path":"/ts-jest/docs/28.0/babel7-or-ts","sidebar":"version-28.0-docs"},{"id":"contributing","path":"/ts-jest/docs/28.0/contributing","sidebar":"version-28.0-docs"},{"id":"debugging","path":"/ts-jest/docs/28.0/debugging","sidebar":"version-28.0-docs"},{"id":"getting-started/installation","path":"/ts-jest/docs/28.0/getting-started/installation","sidebar":"version-28.0-docs"},{"id":"getting-started/options","path":"/ts-jest/docs/28.0/getting-started/options","sidebar":"version-28.0-docs"},{"id":"getting-started/options/astTransformers","path":"/ts-jest/docs/28.0/getting-started/options/astTransformers"},{"id":"getting-started/options/babelConfig","path":"/ts-jest/docs/28.0/getting-started/options/babelConfig"},{"id":"getting-started/options/compiler","path":"/ts-jest/docs/28.0/getting-started/options/compiler"},{"id":"getting-started/options/diagnostics","path":"/ts-jest/docs/28.0/getting-started/options/diagnostics"},{"id":"getting-started/options/isolatedModules","path":"/ts-jest/docs/28.0/getting-started/options/isolatedModules"},{"id":"getting-started/options/stringifyContentPathRegex","path":"/ts-jest/docs/28.0/getting-started/options/stringifyContentPathRegex"},{"id":"getting-started/options/tsconfig","path":"/ts-jest/docs/28.0/getting-started/options/tsconfig"},{"id":"getting-started/options/useESM","path":"/ts-jest/docs/28.0/getting-started/options/useESM"},{"id":"getting-started/paths-mapping","path":"/ts-jest/docs/28.0/getting-started/paths-mapping","sidebar":"version-28.0-docs"},{"id":"getting-started/presets","path":"/ts-jest/docs/28.0/getting-started/presets","sidebar":"version-28.0-docs"},{"id":"getting-started/version-checking","path":"/ts-jest/docs/28.0/getting-started/version-checking","sidebar":"version-28.0-docs"},{"id":"guides/esm-support","path":"/ts-jest/docs/28.0/guides/esm-support","sidebar":"version-28.0-docs"},{"id":"guides/mock-es6-class","path":"/ts-jest/docs/28.0/guides/mock-es6-class","sidebar":"version-28.0-docs"},{"id":"guides/react-native","path":"/ts-jest/docs/28.0/guides/react-native","sidebar":"version-28.0-docs"},{"id":"guides/troubleshooting","path":"/ts-jest/docs/28.0/guides/troubleshooting","sidebar":"version-28.0-docs"},{"id":"guides/using-with-monorepo","path":"/ts-jest/docs/28.0/guides/using-with-monorepo","sidebar":"version-28.0-docs"},{"id":"introduction","path":"/ts-jest/docs/28.0/","sidebar":"version-28.0-docs"},{"id":"migration","path":"/ts-jest/docs/28.0/migration","sidebar":"version-28.0-docs"},{"id":"processing","path":"/ts-jest/docs/28.0/processing","sidebar":"version-28.0-docs"}],"draftIds":[],"sidebars":{"version-28.0-docs":{"link":{"path":"/ts-jest/docs/28.0/","label":"introduction"}}}},{"name":"27.1","label":"27.1","isLast":false,"path":"/ts-jest/docs/27.1","mainDocId":"introduction","docs":[{"id":"babel7-or-ts","path":"/ts-jest/docs/27.1/babel7-or-ts","sidebar":"version-27.1-docs"},{"id":"contributing","path":"/ts-jest/docs/27.1/contributing","sidebar":"version-27.1-docs"},{"id":"debugging","path":"/ts-jest/docs/27.1/debugging","sidebar":"version-27.1-docs"},{"id":"getting-started/installation","path":"/ts-jest/docs/27.1/getting-started/installation","sidebar":"version-27.1-docs"},{"id":"getting-started/options","path":"/ts-jest/docs/27.1/getting-started/options","sidebar":"version-27.1-docs"},{"id":"getting-started/options/astTransformers","path":"/ts-jest/docs/27.1/getting-started/options/astTransformers"},{"id":"getting-started/options/babelConfig","path":"/ts-jest/docs/27.1/getting-started/options/babelConfig"},{"id":"getting-started/options/compiler","path":"/ts-jest/docs/27.1/getting-started/options/compiler"},{"id":"getting-started/options/diagnostics","path":"/ts-jest/docs/27.1/getting-started/options/diagnostics"},{"id":"getting-started/options/isolatedModules","path":"/ts-jest/docs/27.1/getting-started/options/isolatedModules"},{"id":"getting-started/options/stringifyContentPathRegex","path":"/ts-jest/docs/27.1/getting-started/options/stringifyContentPathRegex"},{"id":"getting-started/options/tsconfig","path":"/ts-jest/docs/27.1/getting-started/options/tsconfig"},{"id":"getting-started/options/useESM","path":"/ts-jest/docs/27.1/getting-started/options/useESM"},{"id":"getting-started/paths-mapping","path":"/ts-jest/docs/27.1/getting-started/paths-mapping","sidebar":"version-27.1-docs"},{"id":"getting-started/presets","path":"/ts-jest/docs/27.1/getting-started/presets","sidebar":"version-27.1-docs"},{"id":"getting-started/version-checking","path":"/ts-jest/docs/27.1/getting-started/version-checking","sidebar":"version-27.1-docs"},{"id":"guides/esm-support","path":"/ts-jest/docs/27.1/guides/esm-support","sidebar":"version-27.1-docs"},{"id":"guides/mock-es6-class","path":"/ts-jest/docs/27.1/guides/mock-es6-class","sidebar":"version-27.1-docs"},{"id":"guides/react-native","path":"/ts-jest/docs/27.1/guides/react-native","sidebar":"version-27.1-docs"},{"id":"guides/test-helpers","path":"/ts-jest/docs/27.1/guides/test-helpers","sidebar":"version-27.1-docs"},{"id":"guides/troubleshooting","path":"/ts-jest/docs/27.1/guides/troubleshooting","sidebar":"version-27.1-docs"},{"id":"guides/using-with-monorepo","path":"/ts-jest/docs/27.1/guides/using-with-monorepo","sidebar":"version-27.1-docs"},{"id":"introduction","path":"/ts-jest/docs/27.1/","sidebar":"version-27.1-docs"},{"id":"migration","path":"/ts-jest/docs/27.1/migration","sidebar":"version-27.1-docs"},{"id":"processing","path":"/ts-jest/docs/27.1/processing","sidebar":"version-27.1-docs"}],"draftIds":[],"sidebars":{"version-27.1-docs":{"link":{"path":"/ts-jest/docs/27.1/","label":"introduction"}}}},{"name":"27.0","label":"27.0","isLast":false,"path":"/ts-jest/docs/27.0","mainDocId":"introduction","docs":[{"id":"babel7-or-ts","path":"/ts-jest/docs/27.0/babel7-or-ts","sidebar":"version-27.0-docs"},{"id":"contributing","path":"/ts-jest/docs/27.0/contributing","sidebar":"version-27.0-docs"},{"id":"debugging","path":"/ts-jest/docs/27.0/debugging","sidebar":"version-27.0-docs"},{"id":"getting-started/installation","path":"/ts-jest/docs/27.0/getting-started/installation","sidebar":"version-27.0-docs"},{"id":"getting-started/options","path":"/ts-jest/docs/27.0/getting-started/options","sidebar":"version-27.0-docs"},{"id":"getting-started/options/astTransformers","path":"/ts-jest/docs/27.0/getting-started/options/astTransformers"},{"id":"getting-started/options/babelConfig","path":"/ts-jest/docs/27.0/getting-started/options/babelConfig"},{"id":"getting-started/options/compiler","path":"/ts-jest/docs/27.0/getting-started/options/compiler"},{"id":"getting-started/options/diagnostics","path":"/ts-jest/docs/27.0/getting-started/options/diagnostics"},{"id":"getting-started/options/isolatedModules","path":"/ts-jest/docs/27.0/getting-started/options/isolatedModules"},{"id":"getting-started/options/stringifyContentPathRegex","path":"/ts-jest/docs/27.0/getting-started/options/stringifyContentPathRegex"},{"id":"getting-started/options/tsconfig","path":"/ts-jest/docs/27.0/getting-started/options/tsconfig"},{"id":"getting-started/options/useESM","path":"/ts-jest/docs/27.0/getting-started/options/useESM"},{"id":"getting-started/paths-mapping","path":"/ts-jest/docs/27.0/getting-started/paths-mapping","sidebar":"version-27.0-docs"},{"id":"getting-started/presets","path":"/ts-jest/docs/27.0/getting-started/presets","sidebar":"version-27.0-docs"},{"id":"getting-started/version-checking","path":"/ts-jest/docs/27.0/getting-started/version-checking","sidebar":"version-27.0-docs"},{"id":"guides/esm-support","path":"/ts-jest/docs/27.0/guides/esm-support","sidebar":"version-27.0-docs"},{"id":"guides/mock-es6-class","path":"/ts-jest/docs/27.0/guides/mock-es6-class","sidebar":"version-27.0-docs"},{"id":"guides/react-native","path":"/ts-jest/docs/27.0/guides/react-native","sidebar":"version-27.0-docs"},{"id":"guides/test-helpers","path":"/ts-jest/docs/27.0/guides/test-helpers","sidebar":"version-27.0-docs"},{"id":"guides/troubleshooting","path":"/ts-jest/docs/27.0/guides/troubleshooting","sidebar":"version-27.0-docs"},{"id":"guides/using-with-monorepo","path":"/ts-jest/docs/27.0/guides/using-with-monorepo","sidebar":"version-27.0-docs"},{"id":"introduction","path":"/ts-jest/docs/27.0/","sidebar":"version-27.0-docs"},{"id":"migration","path":"/ts-jest/docs/27.0/migration","sidebar":"version-27.0-docs"},{"id":"processing","path":"/ts-jest/docs/27.0/processing","sidebar":"version-27.0-docs"}],"draftIds":[],"sidebars":{"version-27.0-docs":{"link":{"path":"/ts-jest/docs/27.0/","label":"introduction"}}}},{"name":"26.5","label":"26.5","isLast":false,"path":"/ts-jest/docs/26.5","mainDocId":"introduction","docs":[{"id":"babel7-or-ts","path":"/ts-jest/docs/26.5/babel7-or-ts","sidebar":"version-26.5-docs"},{"id":"contributing","path":"/ts-jest/docs/26.5/contributing","sidebar":"version-26.5-docs"},{"id":"debugging","path":"/ts-jest/docs/26.5/debugging","sidebar":"version-26.5-docs"},{"id":"getting-started/installation","path":"/ts-jest/docs/26.5/getting-started/installation","sidebar":"version-26.5-docs"},{"id":"getting-started/options","path":"/ts-jest/docs/26.5/getting-started/options","sidebar":"version-26.5-docs"},{"id":"getting-started/options/astTransformers","path":"/ts-jest/docs/26.5/getting-started/options/astTransformers"},{"id":"getting-started/options/babelConfig","path":"/ts-jest/docs/26.5/getting-started/options/babelConfig"},{"id":"getting-started/options/compiler","path":"/ts-jest/docs/26.5/getting-started/options/compiler"},{"id":"getting-started/options/diagnostics","path":"/ts-jest/docs/26.5/getting-started/options/diagnostics"},{"id":"getting-started/options/isolatedModules","path":"/ts-jest/docs/26.5/getting-started/options/isolatedModules"},{"id":"getting-started/options/stringifyContentPathRegex","path":"/ts-jest/docs/26.5/getting-started/options/stringifyContentPathRegex"},{"id":"getting-started/options/tsconfig","path":"/ts-jest/docs/26.5/getting-started/options/tsconfig"},{"id":"getting-started/paths-mapping","path":"/ts-jest/docs/26.5/getting-started/paths-mapping","sidebar":"version-26.5-docs"},{"id":"getting-started/presets","path":"/ts-jest/docs/26.5/getting-started/presets","sidebar":"version-26.5-docs"},{"id":"getting-started/version-checking","path":"/ts-jest/docs/26.5/getting-started/version-checking","sidebar":"version-26.5-docs"},{"id":"guides/esm-support","path":"/ts-jest/docs/26.5/guides/esm-support","sidebar":"version-26.5-docs"},{"id":"guides/mock-es6-class","path":"/ts-jest/docs/26.5/guides/mock-es6-class","sidebar":"version-26.5-docs"},{"id":"guides/react-native","path":"/ts-jest/docs/26.5/guides/react-native","sidebar":"version-26.5-docs"},{"id":"guides/test-helpers","path":"/ts-jest/docs/26.5/guides/test-helpers","sidebar":"version-26.5-docs"},{"id":"guides/troubleshooting","path":"/ts-jest/docs/26.5/guides/troubleshooting","sidebar":"version-26.5-docs"},{"id":"guides/using-with-monorepo","path":"/ts-jest/docs/26.5/guides/using-with-monorepo","sidebar":"version-26.5-docs"},{"id":"introduction","path":"/ts-jest/docs/26.5/","sidebar":"version-26.5-docs"},{"id":"migration","path":"/ts-jest/docs/26.5/migration","sidebar":"version-26.5-docs"},{"id":"processing","path":"/ts-jest/docs/26.5/processing","sidebar":"version-26.5-docs"}],"draftIds":[],"sidebars":{"version-26.5-docs":{"link":{"path":"/ts-jest/docs/26.5/","label":"introduction"}}}}],"breadcrumbs":true}}}'),a=JSON.parse('{"defaultLocale":"en","locales":["en"],"path":"i18n","currentLocale":"en","localeConfigs":{"en":{"label":"English","direction":"ltr","htmlLang":"en","calendar":"gregory","path":"en"}}}');var i=n(2654);const l=JSON.parse('{"docusaurusVersion":"3.6.3","siteVersion":"0.0.0","pluginVersions":{"docusaurus-plugin-content-docs":{"type":"package","name":"@docusaurus/plugin-content-docs","version":"3.6.3"},"docusaurus-plugin-content-blog":{"type":"package","name":"@docusaurus/plugin-content-blog","version":"3.6.3"},"docusaurus-plugin-content-pages":{"type":"package","name":"@docusaurus/plugin-content-pages","version":"3.6.3"},"docusaurus-plugin-sitemap":{"type":"package","name":"@docusaurus/plugin-sitemap","version":"3.6.3"},"docusaurus-theme-classic":{"type":"package","name":"@docusaurus/theme-classic","version":"3.6.3"},"docusaurus-plugin-ideal-image":{"type":"package","name":"@docusaurus/plugin-ideal-image","version":"3.6.3"},"docusaurus-plugin-pwa":{"type":"package","name":"@docusaurus/plugin-pwa","version":"3.6.3"}}}');var c=n(4848);const u={siteConfig:o.default,siteMetadata:l,globalData:s,i18n:a,codeTranslations:i},d=r.createContext(u);function p(e){let{children:t}=e;return(0,c.jsx)(d.Provider,{value:u,children:t})}},3832:(e,t,n)=>{"use strict";n.d(t,{A:()=>m});var r=n(6540),o=n(1712),s=n(1141),a=n(4609),i=n(3844),l=n(3363),c=n(4848);function u(e){let{error:t,tryAgain:n}=e;return(0,c.jsxs)("div",{style:{display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"flex-start",minHeight:"100vh",width:"100%",maxWidth:"80ch",fontSize:"20px",margin:"0 auto",padding:"1rem"},children:[(0,c.jsx)("h1",{style:{fontSize:"3rem"},children:"This page crashed"}),(0,c.jsx)("button",{type:"button",onClick:n,style:{margin:"1rem 0",fontSize:"2rem",cursor:"pointer",borderRadius:20,padding:"1rem"},children:"Try again"}),(0,c.jsx)(d,{error:t})]})}function d(e){let{error:t}=e;const n=(0,a.rA)(t).map((e=>e.message)).join("\n\nCause:\n");return(0,c.jsx)("p",{style:{whiteSpace:"pre-wrap"},children:n})}function p(e){let{children:t}=e;return(0,c.jsx)(l.W,{value:{plugin:{name:"docusaurus-core-error-boundary",id:"default"}},children:t})}function f(e){let{error:t,tryAgain:n}=e;return(0,c.jsx)(p,{children:(0,c.jsxs)(m,{fallback:()=>(0,c.jsx)(u,{error:t,tryAgain:n}),children:[(0,c.jsx)(s.A,{children:(0,c.jsx)("title",{children:"Page Error"})}),(0,c.jsx)(i.A,{children:(0,c.jsx)(u,{error:t,tryAgain:n})})]})})}const g=e=>(0,c.jsx)(f,{...e});class m extends r.Component{constructor(e){super(e),this.state={error:null}}componentDidCatch(e){o.A.canUseDOM&&this.setState({error:e})}render(){const{children:e}=this.props,{error:t}=this.state;if(t){const e={error:t,tryAgain:()=>this.setState({error:null})};return(this.props.fallback??g)(e)}return e??null}}},1712:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});const r="undefined"!=typeof window&&"document"in window&&"createElement"in window.document,o={canUseDOM:r,canUseEventListeners:r&&("addEventListener"in window||"attachEvent"in window),canUseIntersectionObserver:r&&"IntersectionObserver"in window,canUseViewport:r&&"screen"in window}},1141:(e,t,n)=>{"use strict";n.d(t,{A:()=>s});n(6540);var r=n(545),o=n(4848);function s(e){return(0,o.jsx)(r.mg,{...e})}},4783:(e,t,n)=>{"use strict";n.d(t,{A:()=>f});var r=n(6540),o=n(4625),s=n(4609),a=n(7639),i=n(877),l=n(1712),c=n(7344),u=n(8180),d=n(4848);function p(e,t){let{isNavLink:n,to:p,href:f,activeClassName:g,isActive:m,"data-noBrokenLinkCheck":h,autoAddBaseUrl:b=!0,...v}=e;const{siteConfig:y}=(0,a.A)(),{trailingSlash:w,baseUrl:k}=y,x=y.future.experimental_router,{withBaseUrl:j}=(0,u.hH)(),_=(0,c.A)(),S=(0,r.useRef)(null);(0,r.useImperativeHandle)(t,(()=>S.current));const E=p||f;const C=(0,i.A)(E),T=E?.replace("pathname://","");let A=void 0!==T?(P=T,b&&(e=>e.startsWith("/"))(P)?j(P):P):void 0;var P;"hash"===x&&A?.startsWith("./")&&(A=A?.slice(1)),A&&C&&(A=(0,s.Ks)(A,{trailingSlash:w,baseUrl:k}));const R=(0,r.useRef)(!1),N=n?o.k2:o.N_,L=l.A.canUseIntersectionObserver,O=(0,r.useRef)(),M=()=>{R.current||null==A||(window.docusaurus.preload(A),R.current=!0)};(0,r.useEffect)((()=>(!L&&C&&l.A.canUseDOM&&null!=A&&window.docusaurus.prefetch(A),()=>{L&&O.current&&O.current.disconnect()})),[O,A,L,C]);const D=A?.startsWith("#")??!1,I=!v.target||"_self"===v.target,F=!A||!C||!I||D&&"hash"!==x;h||!D&&F||_.collectLink(A),v.id&&_.collectAnchor(v.id);const z={};return F?(0,d.jsx)("a",{ref:S,href:A,...E&&!C&&{target:"_blank",rel:"noopener noreferrer"},...v,...z}):(0,d.jsx)(N,{...v,onMouseEnter:M,onTouchStart:M,innerRef:e=>{S.current=e,L&&e&&C&&(O.current=new window.IntersectionObserver((t=>{t.forEach((t=>{e===t.target&&(t.isIntersecting||t.intersectionRatio>0)&&(O.current.unobserve(e),O.current.disconnect(),null!=A&&window.docusaurus.prefetch(A))}))})),O.current.observe(e))},to:A,...n&&{isActive:m,activeClassName:g},...z})}const f=r.forwardRef(p)},9175:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});const r=()=>null},3230:(e,t,n)=>{"use strict";n.d(t,{A:()=>c,T:()=>l});var r=n(6540),o=n(4848);function s(e,t){const n=e.split(/(\{\w+\})/).map(((e,n)=>{if(n%2==1){const n=t?.[e.slice(1,-1)];if(void 0!==n)return n}return e}));return n.some((e=>(0,r.isValidElement)(e)))?n.map(((e,t)=>(0,r.isValidElement)(e)?r.cloneElement(e,{key:t}):e)).filter((e=>""!==e)):n.join("")}var a=n(2654);function i(e){let{id:t,message:n}=e;if(void 0===t&&void 0===n)throw new Error("Docusaurus translation declarations must have at least a translation id or a default translation message");return a[t??n]??n??t}function l(e,t){let{message:n,id:r}=e;return s(i({message:n,id:r}),t)}function c(e){let{children:t,id:n,values:r}=e;if(t&&"string"!=typeof t)throw console.warn("Illegal children",t),new Error("The Docusaurus component only accept simple string values");const a=i({message:t,id:n});return(0,o.jsx)(o.Fragment,{children:s(a,r)})}},4598:(e,t,n)=>{"use strict";n.d(t,{W:()=>r});const r="default"},877:(e,t,n)=>{"use strict";function r(e){return/^(?:\w*:|\/\/)/.test(e)}function o(e){return void 0!==e&&!r(e)}n.d(t,{A:()=>o,z:()=>r})},8180:(e,t,n)=>{"use strict";n.d(t,{Ay:()=>i,hH:()=>a});var r=n(6540),o=n(7639),s=n(877);function a(){const{siteConfig:e}=(0,o.A)(),{baseUrl:t,url:n}=e,a=e.future.experimental_router,i=(0,r.useCallback)(((e,r)=>function(e){let{siteUrl:t,baseUrl:n,url:r,options:{forcePrependBaseUrl:o=!1,absolute:a=!1}={},router:i}=e;if(!r||r.startsWith("#")||(0,s.z)(r))return r;if("hash"===i)return r.startsWith("/")?`.${r}`:`./${r}`;if(o)return n+r.replace(/^\//,"");if(r===n.replace(/\/$/,""))return n;const l=r.startsWith(n)?r:n+r.replace(/^\//,"");return a?t+l:l}({siteUrl:n,baseUrl:t,url:e,options:r,router:a})),[n,t,a]);return{withBaseUrl:i}}function i(e,t){void 0===t&&(t={});const{withBaseUrl:n}=a();return n(e,t)}},7344:(e,t,n)=>{"use strict";n.d(t,{A:()=>a});var r=n(6540);n(4848);const o=r.createContext({collectAnchor:()=>{},collectLink:()=>{}}),s=()=>(0,r.useContext)(o);function a(){return s()}},7639:(e,t,n)=>{"use strict";n.d(t,{A:()=>s});var r=n(6540),o=n(3366);function s(){return(0,r.useContext)(o.o)}},1062:(e,t,n)=>{"use strict";n.d(t,{A:()=>s});var r=n(6540),o=n(8848);function s(){return(0,r.useContext)(o.o)}},6494:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});var r=n(6540);const o=n(1712).A.canUseDOM?r.useLayoutEffect:r.useEffect},1604:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});const r=e=>"object"==typeof e&&!!e&&Object.keys(e).length>0;function o(e){const t={};return function e(n,o){Object.entries(n).forEach((n=>{let[s,a]=n;const i=o?`${o}.${s}`:s;r(a)?e(a,i):t[i]=a}))}(e),t}},3363:(e,t,n)=>{"use strict";n.d(t,{W:()=>a,o:()=>s});var r=n(6540),o=n(4848);const s=r.createContext(null);function a(e){let{children:t,value:n}=e;const a=r.useContext(s),i=(0,r.useMemo)((()=>function(e){let{parent:t,value:n}=e;if(!t){if(!n)throw new Error("Unexpected: no Docusaurus route context found");if(!("plugin"in n))throw new Error("Unexpected: Docusaurus topmost route context has no `plugin` attribute");return n}const r={...t.data,...n?.data};return{plugin:t.plugin,data:r}}({parent:a,value:n})),[a,n]);return(0,o.jsx)(s.Provider,{value:i,children:t})}},6457:(e,t,n)=>{"use strict";n.d(t,{VQ:()=>h,g1:()=>v});var r=n(6540),o=n(4721),s=n(4598),a=n(6957),i=n(9900),l=n(4799),c=n(4848);const u=e=>`docs-preferred-version-${e}`,d={save:(e,t,n)=>{(0,i.Wf)(u(e),{persistence:t}).set(n)},read:(e,t)=>(0,i.Wf)(u(e),{persistence:t}).get(),clear:(e,t)=>{(0,i.Wf)(u(e),{persistence:t}).del()}},p=e=>Object.fromEntries(e.map((e=>[e,{preferredVersionName:null}])));const f=r.createContext(null);function g(){const e=(0,o.Gy)(),t=(0,a.p)().docs.versionPersistence,n=(0,r.useMemo)((()=>Object.keys(e)),[e]),[s,i]=(0,r.useState)((()=>p(n)));(0,r.useEffect)((()=>{i(function(e){let{pluginIds:t,versionPersistence:n,allDocsData:r}=e;function o(e){const t=d.read(e,n);return r[e].versions.some((e=>e.name===t))?{preferredVersionName:t}:(d.clear(e,n),{preferredVersionName:null})}return Object.fromEntries(t.map((e=>[e,o(e)])))}({allDocsData:e,versionPersistence:t,pluginIds:n}))}),[e,t,n]);return[s,(0,r.useMemo)((()=>({savePreferredVersion:function(e,n){d.save(e,t,n),i((t=>({...t,[e]:{preferredVersionName:n}})))}})),[t])]}function m(e){let{children:t}=e;const n=g();return(0,c.jsx)(f.Provider,{value:n,children:t})}function h(e){let{children:t}=e;return(0,c.jsx)(m,{children:t})}function b(){const e=(0,r.useContext)(f);if(!e)throw new l.dV("DocsPreferredVersionContextProvider");return e}function v(e){void 0===e&&(e=s.W);const t=(0,o.ht)(e),[n,a]=b(),{preferredVersionName:i}=n[e];return{preferredVersion:t.versions.find((e=>e.name===i))??null,savePreferredVersionName:(0,r.useCallback)((t=>{a.savePreferredVersion(e,t)}),[a,e])}}},40:(e,t,n)=>{"use strict";n.d(t,{V:()=>l,t:()=>c});var r=n(6540),o=n(4799),s=n(4848);const a=Symbol("EmptyContext"),i=r.createContext(a);function l(e){let{children:t,name:n,items:o}=e;const a=(0,r.useMemo)((()=>n&&o?{name:n,items:o}:null),[n,o]);return(0,s.jsx)(i.Provider,{value:a,children:t})}function c(){const e=(0,r.useContext)(i);if(e===a)throw new o.dV("DocsSidebarProvider");return e}},5357:(e,t,n)=>{"use strict";n.d(t,{B5:()=>j,Nr:()=>p,OF:()=>y,QB:()=>x,Vd:()=>w,Y:()=>b,fW:()=>k,w8:()=>m});var r=n(6540),o=n(6347),s=n(2831),a=n(4721),i=n(260),l=n(5167),c=n(6457),u=n(1704),d=n(40);function p(e){return"link"!==e.type||e.unlisted?"category"===e.type?function(e){if(e.href&&!e.linkUnlisted)return e.href;for(const t of e.items){const e=p(t);if(e)return e}}(e):void 0:e.href}const f=(e,t)=>void 0!==e&&(0,i.ys)(e,t),g=(e,t)=>e.some((e=>m(e,t)));function m(e,t){return"link"===e.type?f(e.href,t):"category"===e.type&&(f(e.href,t)||g(e.items,t))}function h(e,t){switch(e.type){case"category":return m(e,t)||e.items.some((e=>h(e,t)));case"link":return!e.unlisted||m(e,t);default:return!0}}function b(e,t){return(0,r.useMemo)((()=>e.filter((e=>h(e,t)))),[e,t])}function v(e){let{sidebarItems:t,pathname:n,onlyCategories:r=!1}=e;const o=[];return function e(t){for(const s of t)if("category"===s.type&&((0,i.ys)(s.href,n)||e(s.items))||"link"===s.type&&(0,i.ys)(s.href,n)){return r&&"category"!==s.type||o.unshift(s),!0}return!1}(t),o}function y(){const e=(0,d.t)(),{pathname:t}=(0,o.zy)(),n=(0,a.vT)()?.pluginData.breadcrumbs;return!1!==n&&e?v({sidebarItems:e.items,pathname:t}):null}function w(e){const{activeVersion:t}=(0,a.zK)(e),{preferredVersion:n}=(0,c.g1)(e),o=(0,a.r7)(e);return(0,r.useMemo)((()=>(0,l.sb)([t,n,o].filter(Boolean))),[t,n,o])}function k(e,t){const n=w(t);return(0,r.useMemo)((()=>{const t=n.flatMap((e=>e.sidebars?Object.entries(e.sidebars):[])),r=t.find((t=>t[0]===e));if(!r)throw new Error(`Can't find any sidebar with id "${e}" in version${n.length>1?"s":""} ${n.map((e=>e.name)).join(", ")}".\nAvailable sidebar ids are:\n- ${t.map((e=>e[0])).join("\n- ")}`);return r[1]}),[e,n])}function x(e,t){const n=w(t);return(0,r.useMemo)((()=>{const t=n.flatMap((e=>e.docs)),r=t.find((t=>t.id===e));if(!r){if(n.flatMap((e=>e.draftIds)).includes(e))return null;throw new Error(`Couldn't find any doc with id "${e}" in version${n.length>1?"s":""} "${n.map((e=>e.name)).join(", ")}".\nAvailable doc ids are:\n- ${(0,l.sb)(t.map((e=>e.id))).join("\n- ")}`)}return r}),[e,n])}function j(e){let{route:t}=e;const n=(0,o.zy)(),r=(0,u.r)(),a=t.routes,i=a.find((e=>(0,o.B6)(n.pathname,e)));if(!i)return null;const l=i.sidebar,c=l?r.docsSidebars[l]:void 0;return{docElement:(0,s.v)(a),sidebarName:l,sidebarItems:c}}},1704:(e,t,n)=>{"use strict";n.d(t,{n:()=>i,r:()=>l});var r=n(6540),o=n(4799),s=n(4848);const a=r.createContext(null);function i(e){let{children:t,version:n}=e;return(0,s.jsx)(a.Provider,{value:n,children:t})}function l(){const e=(0,r.useContext)(a);if(null===e)throw new o.dV("DocsVersionProvider");return e}},4721:(e,t,n)=>{"use strict";n.d(t,{zK:()=>m,vT:()=>p,Gy:()=>u,HW:()=>h,ht:()=>d,r7:()=>g,jh:()=>f});var r=n(6347),o=n(7639),s=n(4598);function a(e,t){void 0===t&&(t={});const n=function(){const{globalData:e}=(0,o.A)();return e}()[e];if(!n&&t.failfast)throw new Error(`Docusaurus plugin global data not found for "${e}" plugin.`);return n}const i=e=>e.versions.find((e=>e.isLast));function l(e,t){const n=function(e,t){return[...e.versions].sort(((e,t)=>e.path===t.path?0:e.path.includes(t.path)?-1:t.path.includes(e.path)?1:0)).find((e=>!!(0,r.B6)(t,{path:e.path,exact:!1,strict:!1})))}(e,t),o=n?.docs.find((e=>!!(0,r.B6)(t,{path:e.path,exact:!0,strict:!1})));return{activeVersion:n,activeDoc:o,alternateDocVersions:o?function(t){const n={};return e.versions.forEach((e=>{e.docs.forEach((r=>{r.id===t&&(n[e.name]=r)}))})),n}(o.id):{}}}const c={},u=()=>a("docusaurus-plugin-content-docs")??c,d=e=>{try{return function(e,t,n){void 0===t&&(t=s.W),void 0===n&&(n={});const r=a(e),o=r?.[t];if(!o&&n.failfast)throw new Error(`Docusaurus plugin global data not found for "${e}" plugin with id "${t}".`);return o}("docusaurus-plugin-content-docs",e,{failfast:!0})}catch(t){throw new Error("You are using a feature of the Docusaurus docs plugin, but this plugin does not seem to be enabled"+("Default"===e?"":` (pluginId=${e}`),{cause:t})}};function p(e){void 0===e&&(e={});const t=u(),{pathname:n}=(0,r.zy)();return function(e,t,n){void 0===n&&(n={});const o=Object.entries(e).sort(((e,t)=>t[1].path.localeCompare(e[1].path))).find((e=>{let[,n]=e;return!!(0,r.B6)(t,{path:n.path,exact:!1,strict:!1})})),s=o?{pluginId:o[0],pluginData:o[1]}:void 0;if(!s&&n.failfast)throw new Error(`Can't find active docs plugin for "${t}" pathname, while it was expected to be found. Maybe you tried to use a docs feature that can only be used on a docs-related page? Existing docs plugin paths are: ${Object.values(e).map((e=>e.path)).join(", ")}`);return s}(t,n,e)}function f(e){return d(e).versions}function g(e){const t=d(e);return i(t)}function m(e){const t=d(e),{pathname:n}=(0,r.zy)();return l(t,n)}function h(e){const t=d(e),{pathname:n}=(0,r.zy)();return function(e,t){const n=i(e);return{latestDocSuggestion:l(e,t).alternateDocVersions[n.name],latestVersionSuggestion:n}}(t,n)}},8155:(e,t,n)=>{"use strict";n.r(t);var r=n(1712),o=n(9900);const s="/ts-jest/sw.js",a=["appInstalled","queryString"],i=!1,l=(0,o.Wf)("docusaurus.pwa.event.appInstalled.fired");function c(e,t){i&&(void 0===t?console.log(`[Docusaurus-PWA][registerSw]: ${e}`):console.log(`[Docusaurus-PWA][registerSw]: ${e}`,t))}async function u(){const e=await navigator.serviceWorker.getRegistrations();c("will unregister all service workers",{registrations:e}),await Promise.all(e.map((e=>e.unregister().then((t=>c("unregister service worker",{registration:e,result:t})))))),c("unregistered all service workers",{registrations:e}),window.location.reload()}const d={always:()=>!0,mobile:()=>window.innerWidth<=996,saveData:()=>!!navigator.connection?.saveData,appInstalled:()=>"true"===l.get()||async function(){if(!("getInstalledRelatedApps"in window.navigator))return!1;try{return(await navigator.getInstalledRelatedApps()).some((e=>"webapp"===e.platform))}catch(e){return!1}}(),standalone:()=>window.matchMedia("(display-mode: standalone)").matches,queryString:()=>"true"===new URLSearchParams(window.location.search).get("offlineMode")};async function p(){const e=await async function(){return(await Promise.all(a.map((e=>Promise.resolve(d[e]()).then((t=>t?e:void 0)))))).filter(Boolean)}(),t=e.length>0;return c(t?"offline mode enabled, because of activation strategies":"offline mode disabled, because none of the offlineModeActivationStrategies could be used",{activeStrategies:e,availableStrategies:a}),t}r.A.canUseDOM&&(c("debug mode enabled"),"serviceWorker"in navigator&&(c("addLegacyAppInstalledEventsListeners"),window.addEventListener("appinstalled",(e=>{c("event appinstalled",{event:e}),l.set("true"),c("AppInstalledEventFiredStorage.set('true')"),u()})),window.addEventListener("beforeinstallprompt",(e=>{c("event beforeinstallprompt",{event:e});const t=l.get();c("AppInstalledEventFiredStorage.get()",{appInstalledEventFired:t}),t&&(l.del(),c("AppInstalledEventFiredStorage.del()"),u())})),c("legacy appinstalled and beforeinstallprompt event listeners installed"),async function(){const[{Workbox:e},t]=await Promise.all([n.e(9730).then(n.bind(n,9730)),p()]),r=new e(function(e){const t=JSON.stringify(e),n=`${s}?params=${encodeURIComponent(t)}`;return c("service worker url",{url:n,params:e}),n}({offlineMode:t,debug:i})),o=()=>r.messageSW({type:"SKIP_WAITING"}),a=()=>(c("handleServiceWorkerWaiting"),t?n.e(5691).then(n.bind(n,5691)).then((e=>{let{renderReloadPopup:t}=e;return t({onReload(){r.addEventListener("controlling",(()=>{window.location.reload()})),o()}})})):o());r.addEventListener("waiting",(e=>{c("event waiting",{event:e}),a()})),r.addEventListener("externalwaiting",(e=>{c("event externalwaiting",{event:e}),a()}));const l=await r.register();l&&(l.active&&c("registration.active",{registration:l}),l.installing&&c("registration.installing",{registration:l}),l.waiting&&(c("registration.waiting",{registration:l}),await a()))}().catch((e=>console.error("registerSW failed",e)))))},5729:(e,t,n)=>{"use strict";n.r(t),n.d(t,{default:()=>s});var r=n(5947),o=n.n(r);o().configure({showSpinner:!1});const s={onRouteUpdate(e){let{location:t,previousLocation:n}=e;if(n&&t.pathname!==n.pathname){const e=window.setTimeout((()=>{o().start()}),200);return()=>window.clearTimeout(e)}},onRouteDidUpdate(){o().done()}}},4753:(e,t,n)=>{"use strict";var r=n(1765),o=n(4784);!function(e){const{themeConfig:{prism:t}}=o.default,{additionalLanguages:r}=t,s=globalThis.Prism;globalThis.Prism=e,r.forEach((e=>{"php"===e&&n(9700),n(8692)(`./prism-${e}`)})),delete globalThis.Prism,void 0!==s&&(globalThis.Prism=e)}(r.My)},5225:(e,t,n)=>{"use strict";n.d(t,{A:()=>u});n(6540);var r=n(4164),o=n(3230),s=n(6957),a=n(4783),i=n(7344);const l={anchorWithStickyNavbar:"anchorWithStickyNavbar_LWe7",anchorWithHideOnScrollNavbar:"anchorWithHideOnScrollNavbar_WYt5"};var c=n(4848);function u(e){let{as:t,id:n,...u}=e;const d=(0,i.A)(),{navbar:{hideOnScroll:p}}=(0,s.p)();if("h1"===t||!n)return(0,c.jsx)(t,{...u,id:void 0});d.collectAnchor(n);const f=(0,o.T)({id:"theme.common.headingLinkTitle",message:"Direct link to {heading}",description:"Title for link to heading"},{heading:"string"==typeof u.children?u.children:n});return(0,c.jsxs)(t,{...u,className:(0,r.A)("anchor",p?l.anchorWithHideOnScrollNavbar:l.anchorWithStickyNavbar,u.className),id:n,children:[u.children,(0,c.jsx)(a.A,{className:"hash-link",to:`#${n}`,"aria-label":f,title:f,children:"\u200b"})]})}},716:(e,t,n)=>{"use strict";n.d(t,{A:()=>s});n(6540);const r={iconExternalLink:"iconExternalLink_nPIU"};var o=n(4848);function s(e){let{width:t=13.5,height:n=13.5}=e;return(0,o.jsx)("svg",{width:t,height:n,"aria-hidden":"true",viewBox:"0 0 24 24",className:r.iconExternalLink,children:(0,o.jsx)("path",{fill:"currentColor",d:"M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"})})}},3844:(e,t,n)=>{"use strict";n.d(t,{A:()=>ft});var r=n(6540),o=n(4164),s=n(3832),a=n(9817),i=n(6347),l=n(3230),c=n(4067),u=n(4848);const d="__docusaurus_skipToContent_fallback";function p(e){e.setAttribute("tabindex","-1"),e.focus(),e.removeAttribute("tabindex")}function f(){const e=(0,r.useRef)(null),{action:t}=(0,i.W6)(),n=(0,r.useCallback)((e=>{e.preventDefault();const t=document.querySelector("main:first-of-type")??document.getElementById(d);t&&p(t)}),[]);return(0,c.$)((n=>{let{location:r}=n;e.current&&!r.hash&&"PUSH"===t&&p(e.current)})),{containerRef:e,onClick:n}}const g=(0,l.T)({id:"theme.common.skipToMainContent",description:"The skip to content label used for accessibility, allowing to rapidly navigate to main content with keyboard tab/enter navigation",message:"Skip to main content"});function m(e){const t=e.children??g,{containerRef:n,onClick:r}=f();return(0,u.jsx)("div",{ref:n,role:"region","aria-label":g,children:(0,u.jsx)("a",{...e,href:`#${d}`,onClick:r,children:t})})}var h=n(8630),b=n(9503);const v={skipToContent:"skipToContent_fXgn"};function y(){return(0,u.jsx)(m,{className:v.skipToContent})}var w=n(6957),k=n(2);function x(e){let{width:t=21,height:n=21,color:r="currentColor",strokeWidth:o=1.2,className:s,...a}=e;return(0,u.jsx)("svg",{viewBox:"0 0 15 15",width:t,height:n,...a,children:(0,u.jsx)("g",{stroke:r,strokeWidth:o,children:(0,u.jsx)("path",{d:"M.75.75l13.5 13.5M14.25.75L.75 14.25"})})})}const j={closeButton:"closeButton_CVFx"};function _(e){return(0,u.jsx)("button",{type:"button","aria-label":(0,l.T)({id:"theme.AnnouncementBar.closeButtonAriaLabel",message:"Close",description:"The ARIA label for close button of announcement bar"}),...e,className:(0,o.A)("clean-btn close",j.closeButton,e.className),children:(0,u.jsx)(x,{width:14,height:14,strokeWidth:3.1})})}const S={content:"content_knG7"};function E(e){const{announcementBar:t}=(0,w.p)(),{content:n}=t;return(0,u.jsx)("div",{...e,className:(0,o.A)(S.content,e.className),dangerouslySetInnerHTML:{__html:n}})}const C={announcementBar:"announcementBar_mb4j",announcementBarPlaceholder:"announcementBarPlaceholder_vyr4",announcementBarClose:"announcementBarClose_gvF7",announcementBarContent:"announcementBarContent_xLdY"};function T(){const{announcementBar:e}=(0,w.p)(),{isActive:t,close:n}=(0,k.M)();if(!t)return null;const{backgroundColor:r,textColor:o,isCloseable:s}=e;return(0,u.jsxs)("div",{className:C.announcementBar,style:{backgroundColor:r,color:o},role:"banner",children:[s&&(0,u.jsx)("div",{className:C.announcementBarPlaceholder}),(0,u.jsx)(E,{className:C.announcementBarContent}),s&&(0,u.jsx)(_,{onClick:n,className:C.announcementBarClose})]})}var A=n(1938),P=n(4245);var R=n(4799),N=n(763);const L=r.createContext(null);function O(e){let{children:t}=e;const n=function(){const e=(0,A.M)(),t=(0,N.YL)(),[n,o]=(0,r.useState)(!1),s=null!==t.component,a=(0,R.ZC)(s);return(0,r.useEffect)((()=>{s&&!a&&o(!0)}),[s,a]),(0,r.useEffect)((()=>{s?e.shown||o(!0):o(!1)}),[e.shown,s]),(0,r.useMemo)((()=>[n,o]),[n])}();return(0,u.jsx)(L.Provider,{value:n,children:t})}function M(e){if(e.component){const t=e.component;return(0,u.jsx)(t,{...e.props})}}function D(){const e=(0,r.useContext)(L);if(!e)throw new R.dV("NavbarSecondaryMenuDisplayProvider");const[t,n]=e,o=(0,r.useCallback)((()=>n(!1)),[n]),s=(0,N.YL)();return(0,r.useMemo)((()=>({shown:t,hide:o,content:M(s)})),[o,s,t])}function I(e){let{header:t,primaryMenu:n,secondaryMenu:r}=e;const{shown:s}=D();return(0,u.jsxs)("div",{className:"navbar-sidebar",children:[t,(0,u.jsxs)("div",{className:(0,o.A)("navbar-sidebar__items",{"navbar-sidebar__items--show-secondary":s}),children:[(0,u.jsx)("div",{className:"navbar-sidebar__item menu",children:n}),(0,u.jsx)("div",{className:"navbar-sidebar__item menu",children:r})]})]})}var F=n(7710),z=n(1062);function B(e){return(0,u.jsx)("svg",{viewBox:"0 0 24 24",width:24,height:24,...e,children:(0,u.jsx)("path",{fill:"currentColor",d:"M12,9c1.65,0,3,1.35,3,3s-1.35,3-3,3s-3-1.35-3-3S10.35,9,12,9 M12,7c-2.76,0-5,2.24-5,5s2.24,5,5,5s5-2.24,5-5 S14.76,7,12,7L12,7z M2,13l2,0c0.55,0,1-0.45,1-1s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S1.45,13,2,13z M20,13l2,0c0.55,0,1-0.45,1-1 s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S19.45,13,20,13z M11,2v2c0,0.55,0.45,1,1,1s1-0.45,1-1V2c0-0.55-0.45-1-1-1S11,1.45,11,2z M11,20v2c0,0.55,0.45,1,1,1s1-0.45,1-1v-2c0-0.55-0.45-1-1-1C11.45,19,11,19.45,11,20z M5.99,4.58c-0.39-0.39-1.03-0.39-1.41,0 c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0s0.39-1.03,0-1.41L5.99,4.58z M18.36,16.95 c-0.39-0.39-1.03-0.39-1.41,0c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0c0.39-0.39,0.39-1.03,0-1.41 L18.36,16.95z M19.42,5.99c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06c-0.39,0.39-0.39,1.03,0,1.41 s1.03,0.39,1.41,0L19.42,5.99z M7.05,18.36c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06 c-0.39,0.39-0.39,1.03,0,1.41s1.03,0.39,1.41,0L7.05,18.36z"})})}function $(e){return(0,u.jsx)("svg",{viewBox:"0 0 24 24",width:24,height:24,...e,children:(0,u.jsx)("path",{fill:"currentColor",d:"M9.37,5.51C9.19,6.15,9.1,6.82,9.1,7.5c0,4.08,3.32,7.4,7.4,7.4c0.68,0,1.35-0.09,1.99-0.27C17.45,17.19,14.93,19,12,19 c-3.86,0-7-3.14-7-7C5,9.07,6.81,6.55,9.37,5.51z M12,3c-4.97,0-9,4.03-9,9s4.03,9,9,9s9-4.03,9-9c0-0.46-0.04-0.92-0.1-1.36 c-0.98,1.37-2.58,2.26-4.4,2.26c-2.98,0-5.4-2.42-5.4-5.4c0-1.81,0.89-3.42,2.26-4.4C12.92,3.04,12.46,3,12,3L12,3z"})})}const U={toggle:"toggle_vylO",toggleButton:"toggleButton_gllP",darkToggleIcon:"darkToggleIcon_wfgR",lightToggleIcon:"lightToggleIcon_pyhR",toggleButtonDisabled:"toggleButtonDisabled_aARS"};function q(e){let{className:t,buttonClassName:n,value:r,onChange:s}=e;const a=(0,z.A)(),i=(0,l.T)({message:"Switch between dark and light mode (currently {mode})",id:"theme.colorToggle.ariaLabel",description:"The ARIA label for the navbar color mode toggle"},{mode:"dark"===r?(0,l.T)({message:"dark mode",id:"theme.colorToggle.ariaLabel.mode.dark",description:"The name for the dark color mode"}):(0,l.T)({message:"light mode",id:"theme.colorToggle.ariaLabel.mode.light",description:"The name for the light color mode"})});return(0,u.jsx)("div",{className:(0,o.A)(U.toggle,t),children:(0,u.jsxs)("button",{className:(0,o.A)("clean-btn",U.toggleButton,!a&&U.toggleButtonDisabled,n),type:"button",onClick:()=>s("dark"===r?"light":"dark"),disabled:!a,title:i,"aria-label":i,"aria-live":"polite","aria-pressed":"dark"===r?"true":"false",children:[(0,u.jsx)(B,{className:(0,o.A)(U.toggleIcon,U.lightToggleIcon)}),(0,u.jsx)($,{className:(0,o.A)(U.toggleIcon,U.darkToggleIcon)})]})})}const H=r.memo(q),G={darkNavbarColorModeToggle:"darkNavbarColorModeToggle_X3D1"};function W(e){let{className:t}=e;const n=(0,w.p)().navbar.style,r=(0,w.p)().colorMode.disableSwitch,{colorMode:o,setColorMode:s}=(0,F.G)();return r?null:(0,u.jsx)(H,{className:t,buttonClassName:"dark"===n?G.darkNavbarColorModeToggle:void 0,value:o,onChange:s})}var V=n(20);function Q(){return(0,u.jsx)(V.A,{className:"navbar__brand",imageClassName:"navbar__logo",titleClassName:"navbar__title text--truncate"})}function K(){const e=(0,A.M)();return(0,u.jsx)("button",{type:"button","aria-label":(0,l.T)({id:"theme.docs.sidebar.closeSidebarButtonAriaLabel",message:"Close navigation bar",description:"The ARIA label for close button of mobile sidebar"}),className:"clean-btn navbar-sidebar__close",onClick:()=>e.toggle(),children:(0,u.jsx)(x,{color:"var(--ifm-color-emphasis-600)"})})}function Y(){return(0,u.jsxs)("div",{className:"navbar-sidebar__brand",children:[(0,u.jsx)(Q,{}),(0,u.jsx)(W,{className:"margin-right--md"}),(0,u.jsx)(K,{})]})}var Z=n(4783),X=n(8180),J=n(877);function ee(e,t){return void 0!==e&&void 0!==t&&new RegExp(e,"gi").test(t)}var te=n(716);function ne(e){let{activeBasePath:t,activeBaseRegex:n,to:r,href:o,label:s,html:a,isDropdownLink:i,prependBaseUrlToHref:l,...c}=e;const d=(0,X.Ay)(r),p=(0,X.Ay)(t),f=(0,X.Ay)(o,{forcePrependBaseUrl:!0}),g=s&&o&&!(0,J.A)(o),m=a?{dangerouslySetInnerHTML:{__html:a}}:{children:(0,u.jsxs)(u.Fragment,{children:[s,g&&(0,u.jsx)(te.A,{...i&&{width:12,height:12}})]})};return o?(0,u.jsx)(Z.A,{href:l?f:o,...c,...m}):(0,u.jsx)(Z.A,{to:d,isNavLink:!0,...(t||n)&&{isActive:(e,t)=>n?ee(n,t.pathname):t.pathname.startsWith(p)},...c,...m})}function re(e){let{className:t,isDropdownItem:n=!1,...r}=e;const s=(0,u.jsx)(ne,{className:(0,o.A)(n?"dropdown__link":"navbar__item navbar__link",t),isDropdownLink:n,...r});return n?(0,u.jsx)("li",{children:s}):s}function oe(e){let{className:t,isDropdownItem:n,...r}=e;return(0,u.jsx)("li",{className:"menu__list-item",children:(0,u.jsx)(ne,{className:(0,o.A)("menu__link",t),...r})})}function se(e){let{mobile:t=!1,position:n,...r}=e;const o=t?oe:re;return(0,u.jsx)(o,{...r,activeClassName:r.activeClassName??(t?"menu__link--active":"navbar__link--active")})}var ae=n(4549),ie=n(260),le=n(7639);const ce={dropdownNavbarItemMobile:"dropdownNavbarItemMobile_S0Fm"};function ue(e,t){return e.some((e=>function(e,t){return!!(0,ie.ys)(e.to,t)||!!ee(e.activeBaseRegex,t)||!(!e.activeBasePath||!t.startsWith(e.activeBasePath))}(e,t)))}function de(e){let{items:t,position:n,className:s,onClick:a,...i}=e;const l=(0,r.useRef)(null),[c,d]=(0,r.useState)(!1);return(0,r.useEffect)((()=>{const e=e=>{l.current&&!l.current.contains(e.target)&&d(!1)};return document.addEventListener("mousedown",e),document.addEventListener("touchstart",e),document.addEventListener("focusin",e),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e),document.removeEventListener("focusin",e)}}),[l]),(0,u.jsxs)("div",{ref:l,className:(0,o.A)("navbar__item","dropdown","dropdown--hoverable",{"dropdown--right":"right"===n,"dropdown--show":c}),children:[(0,u.jsx)(ne,{"aria-haspopup":"true","aria-expanded":c,role:"button",href:i.to?void 0:"#",className:(0,o.A)("navbar__link",s),...i,onClick:i.to?void 0:e=>e.preventDefault(),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),d(!c))},children:i.children??i.label}),(0,u.jsx)("ul",{className:"dropdown__menu",children:t.map(((e,t)=>(0,r.createElement)(Se,{isDropdownItem:!0,activeClassName:"dropdown__link--active",...e,key:t})))})]})}function pe(e){let{items:t,className:n,position:s,onClick:a,...l}=e;const c=function(){const{siteConfig:{baseUrl:e}}=(0,le.A)(),{pathname:t}=(0,i.zy)();return t.replace(e,"/")}(),d=ue(t,c),{collapsed:p,toggleCollapsed:f,setCollapsed:g}=(0,ae.u)({initialState:()=>!d});return(0,r.useEffect)((()=>{d&&g(!d)}),[c,d,g]),(0,u.jsxs)("li",{className:(0,o.A)("menu__list-item",{"menu__list-item--collapsed":p}),children:[(0,u.jsx)(ne,{role:"button",className:(0,o.A)(ce.dropdownNavbarItemMobile,"menu__link menu__link--sublist menu__link--sublist-caret",n),...l,onClick:e=>{e.preventDefault(),f()},children:l.children??l.label}),(0,u.jsx)(ae.N,{lazy:!0,as:"ul",className:"menu__list",collapsed:p,children:t.map(((e,t)=>(0,r.createElement)(Se,{mobile:!0,isDropdownItem:!0,onClick:a,activeClassName:"menu__link--active",...e,key:t})))})]})}function fe(e){let{mobile:t=!1,...n}=e;const r=t?pe:de;return(0,u.jsx)(r,{...n})}var ge=n(2098);function me(e){let{width:t=20,height:n=20,...r}=e;return(0,u.jsx)("svg",{viewBox:"0 0 24 24",width:t,height:n,"aria-hidden":!0,...r,children:(0,u.jsx)("path",{fill:"currentColor",d:"M12.87 15.07l-2.54-2.51.03-.03c1.74-1.94 2.98-4.17 3.71-6.53H17V4h-7V2H8v2H1v1.99h11.17C11.5 7.92 10.44 9.75 9 11.35 8.07 10.32 7.3 9.19 6.69 8h-2c.73 1.63 1.73 3.17 2.98 4.56l-5.09 5.02L4 19l5-5 3.11 3.11.76-2.04zM18.5 10h-2L12 22h2l1.12-3h4.75L21 22h2l-4.5-12zm-2.62 7l1.62-4.33L19.12 17h-3.24z"})})}const he="iconLanguage_nlXk";var be=n(9175);const ve={navbarSearchContainer:"navbarSearchContainer_Bca1"};function ye(e){let{children:t,className:n}=e;return(0,u.jsx)("div",{className:(0,o.A)(n,ve.navbarSearchContainer),children:t})}var we=n(4721),ke=n(5357);var xe=n(6457);function je(e,t){return t.alternateDocVersions[e.name]??function(e){return e.docs.find((t=>t.id===e.mainDocId))}(e)}const _e={default:se,localeDropdown:function(e){let{mobile:t,dropdownItemsBefore:n,dropdownItemsAfter:r,queryString:o="",...s}=e;const{i18n:{currentLocale:a,locales:c,localeConfigs:d}}=(0,le.A)(),p=(0,ge.o)(),{search:f,hash:g}=(0,i.zy)(),m=[...n,...c.map((e=>{const n=`${`pathname://${p.createUrl({locale:e,fullyQualified:!1})}`}${f}${g}${o}`;return{label:d[e].label,lang:d[e].htmlLang,to:n,target:"_self",autoAddBaseUrl:!1,className:e===a?t?"menu__link--active":"dropdown__link--active":""}})),...r],h=t?(0,l.T)({message:"Languages",id:"theme.navbar.mobileLanguageDropdown.label",description:"The label for the mobile language switcher dropdown"}):d[a].label;return(0,u.jsx)(fe,{...s,mobile:t,label:(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(me,{className:he}),h]}),items:m})},search:function(e){let{mobile:t,className:n}=e;return t?null:(0,u.jsx)(ye,{className:n,children:(0,u.jsx)(be.A,{})})},dropdown:fe,html:function(e){let{value:t,className:n,mobile:r=!1,isDropdownItem:s=!1}=e;const a=s?"li":"div";return(0,u.jsx)(a,{className:(0,o.A)({navbar__item:!r&&!s,"menu__list-item":r},n),dangerouslySetInnerHTML:{__html:t}})},doc:function(e){let{docId:t,label:n,docsPluginId:r,...o}=e;const{activeDoc:s}=(0,we.zK)(r),a=(0,ke.QB)(t,r),i=s?.path===a?.path;return null===a||a.unlisted&&!i?null:(0,u.jsx)(se,{exact:!0,...o,isActive:()=>i||!!s?.sidebar&&s.sidebar===a.sidebar,label:n??a.id,to:a.path})},docSidebar:function(e){let{sidebarId:t,label:n,docsPluginId:r,...o}=e;const{activeDoc:s}=(0,we.zK)(r),a=(0,ke.fW)(t,r).link;if(!a)throw new Error(`DocSidebarNavbarItem: Sidebar with ID "${t}" doesn't have anything to be linked to.`);return(0,u.jsx)(se,{exact:!0,...o,isActive:()=>s?.sidebar===t,label:n??a.label,to:a.path})},docsVersion:function(e){let{label:t,to:n,docsPluginId:r,...o}=e;const s=(0,ke.Vd)(r)[0],a=t??s.label,i=n??(e=>e.docs.find((t=>t.id===e.mainDocId)))(s).path;return(0,u.jsx)(se,{...o,label:a,to:i})},docsVersionDropdown:function(e){let{mobile:t,docsPluginId:n,dropdownActiveClassDisabled:r,dropdownItemsBefore:o,dropdownItemsAfter:s,...a}=e;const{search:c,hash:d}=(0,i.zy)(),p=(0,we.zK)(n),f=(0,we.jh)(n),{savePreferredVersionName:g}=(0,xe.g1)(n),m=[...o,...f.map((function(e){const t=je(e,p);return{label:e.label,to:`${t.path}${c}${d}`,isActive:()=>e===p.activeVersion,onClick:()=>g(e.name)}})),...s],h=(0,ke.Vd)(n)[0],b=t&&m.length>1?(0,l.T)({id:"theme.navbar.mobileVersionsDropdown.label",message:"Versions",description:"The label for the navbar versions dropdown on mobile view"}):h.label,v=t&&m.length>1?void 0:je(h,p).path;return m.length<=1?(0,u.jsx)(se,{...a,mobile:t,label:b,to:v,isActive:r?()=>!1:void 0}):(0,u.jsx)(fe,{...a,mobile:t,label:b,to:v,items:m,isActive:r?()=>!1:void 0})}};function Se(e){let{type:t,...n}=e;const r=function(e,t){return e&&"default"!==e?e:"items"in t?"dropdown":"default"}(t,n),o=_e[r];if(!o)throw new Error(`No NavbarItem component found for type "${t}".`);return(0,u.jsx)(o,{...n})}function Ee(){const e=(0,A.M)(),t=(0,w.p)().navbar.items;return(0,u.jsx)("ul",{className:"menu__list",children:t.map(((t,n)=>(0,r.createElement)(Se,{mobile:!0,...t,onClick:()=>e.toggle(),key:n})))})}function Ce(e){return(0,u.jsx)("button",{...e,type:"button",className:"clean-btn navbar-sidebar__back",children:(0,u.jsx)(l.A,{id:"theme.navbar.mobileSidebarSecondaryMenu.backButtonLabel",description:"The label of the back button to return to main menu, inside the mobile navbar sidebar secondary menu (notably used to display the docs sidebar)",children:"\u2190 Back to main menu"})})}function Te(){const e=0===(0,w.p)().navbar.items.length,t=D();return(0,u.jsxs)(u.Fragment,{children:[!e&&(0,u.jsx)(Ce,{onClick:()=>t.hide()}),t.content]})}function Ae(){const e=(0,A.M)();var t;return void 0===(t=e.shown)&&(t=!0),(0,r.useEffect)((()=>(document.body.style.overflow=t?"hidden":"visible",()=>{document.body.style.overflow="visible"})),[t]),e.shouldRender?(0,u.jsx)(I,{header:(0,u.jsx)(Y,{}),primaryMenu:(0,u.jsx)(Ee,{}),secondaryMenu:(0,u.jsx)(Te,{})}):null}const Pe={navbarHideable:"navbarHideable_m1mJ",navbarHidden:"navbarHidden_jGov"};function Re(e){return(0,u.jsx)("div",{role:"presentation",...e,className:(0,o.A)("navbar-sidebar__backdrop",e.className)})}function Ne(e){let{children:t}=e;const{navbar:{hideOnScroll:n,style:s}}=(0,w.p)(),a=(0,A.M)(),{navbarRef:i,isNavbarVisible:d}=function(e){const[t,n]=(0,r.useState)(e),o=(0,r.useRef)(!1),s=(0,r.useRef)(0),a=(0,r.useCallback)((e=>{null!==e&&(s.current=e.getBoundingClientRect().height)}),[]);return(0,P.Mq)(((t,r)=>{let{scrollY:a}=t;if(!e)return;if(a=i?n(!1):a+c{if(!e)return;const r=t.location.hash;if(r?document.getElementById(r.substring(1)):void 0)return o.current=!0,void n(!1);n(!0)})),{navbarRef:a,isNavbarVisible:t}}(n);return(0,u.jsxs)("nav",{ref:i,"aria-label":(0,l.T)({id:"theme.NavBar.navAriaLabel",message:"Main",description:"The ARIA label for the main navigation"}),className:(0,o.A)("navbar","navbar--fixed-top",n&&[Pe.navbarHideable,!d&&Pe.navbarHidden],{"navbar--dark":"dark"===s,"navbar--primary":"primary"===s,"navbar-sidebar--show":a.shown}),children:[t,(0,u.jsx)(Re,{onClick:a.toggle}),(0,u.jsx)(Ae,{})]})}var Le=n(4609);const Oe={errorBoundaryError:"errorBoundaryError_a6uf",errorBoundaryFallback:"errorBoundaryFallback_VBag"};function Me(e){return(0,u.jsx)("button",{type:"button",...e,children:(0,u.jsx)(l.A,{id:"theme.ErrorPageContent.tryAgain",description:"The label of the button to try again rendering when the React error boundary captures an error",children:"Try again"})})}function De(e){let{error:t}=e;const n=(0,Le.rA)(t).map((e=>e.message)).join("\n\nCause:\n");return(0,u.jsx)("p",{className:Oe.errorBoundaryError,children:n})}class Ie extends r.Component{componentDidCatch(e,t){throw this.props.onError(e,t)}render(){return this.props.children}}const Fe="right";function ze(e){let{width:t=30,height:n=30,className:r,...o}=e;return(0,u.jsx)("svg",{className:r,width:t,height:n,viewBox:"0 0 30 30","aria-hidden":"true",...o,children:(0,u.jsx)("path",{stroke:"currentColor",strokeLinecap:"round",strokeMiterlimit:"10",strokeWidth:"2",d:"M4 7h22M4 15h22M4 23h22"})})}function Be(){const{toggle:e,shown:t}=(0,A.M)();return(0,u.jsx)("button",{onClick:e,"aria-label":(0,l.T)({id:"theme.docs.sidebar.toggleSidebarButtonAriaLabel",message:"Toggle navigation bar",description:"The ARIA label for hamburger menu button of mobile navigation"}),"aria-expanded":t,className:"navbar__toggle clean-btn",type:"button",children:(0,u.jsx)(ze,{})})}const $e={colorModeToggle:"colorModeToggle_DEke"};function Ue(e){let{items:t}=e;return(0,u.jsx)(u.Fragment,{children:t.map(((e,t)=>(0,u.jsx)(Ie,{onError:t=>new Error(`A theme navbar item failed to render.\nPlease double-check the following navbar item (themeConfig.navbar.items) of your Docusaurus config:\n${JSON.stringify(e,null,2)}`,{cause:t}),children:(0,u.jsx)(Se,{...e})},t)))})}function qe(e){let{left:t,right:n}=e;return(0,u.jsxs)("div",{className:"navbar__inner",children:[(0,u.jsx)("div",{className:"navbar__items",children:t}),(0,u.jsx)("div",{className:"navbar__items navbar__items--right",children:n})]})}function He(){const e=(0,A.M)(),t=(0,w.p)().navbar.items,[n,r]=function(e){function t(e){return"left"===(e.position??Fe)}return[e.filter(t),e.filter((e=>!t(e)))]}(t),o=t.find((e=>"search"===e.type));return(0,u.jsx)(qe,{left:(0,u.jsxs)(u.Fragment,{children:[!e.disabled&&(0,u.jsx)(Be,{}),(0,u.jsx)(Q,{}),(0,u.jsx)(Ue,{items:n})]}),right:(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(Ue,{items:r}),(0,u.jsx)(W,{className:$e.colorModeToggle}),!o&&(0,u.jsx)(ye,{children:(0,u.jsx)(be.A,{})})]})})}function Ge(){return(0,u.jsx)(Ne,{children:(0,u.jsx)(He,{})})}function We(e){let{item:t}=e;const{to:n,href:r,label:o,prependBaseUrlToHref:s,...a}=t,i=(0,X.Ay)(n),l=(0,X.Ay)(r,{forcePrependBaseUrl:!0});return(0,u.jsxs)(Z.A,{className:"footer__link-item",...r?{href:s?l:r}:{to:i},...a,children:[o,r&&!(0,J.A)(r)&&(0,u.jsx)(te.A,{})]})}function Ve(e){let{item:t}=e;return t.html?(0,u.jsx)("li",{className:"footer__item",dangerouslySetInnerHTML:{__html:t.html}}):(0,u.jsx)("li",{className:"footer__item",children:(0,u.jsx)(We,{item:t})},t.href??t.to)}function Qe(e){let{column:t}=e;return(0,u.jsxs)("div",{className:"col footer__col",children:[(0,u.jsx)("div",{className:"footer__title",children:t.title}),(0,u.jsx)("ul",{className:"footer__items clean-list",children:t.items.map(((e,t)=>(0,u.jsx)(Ve,{item:e},t)))})]})}function Ke(e){let{columns:t}=e;return(0,u.jsx)("div",{className:"row footer__links",children:t.map(((e,t)=>(0,u.jsx)(Qe,{column:e},t)))})}function Ye(){return(0,u.jsx)("span",{className:"footer__link-separator",children:"\xb7"})}function Ze(e){let{item:t}=e;return t.html?(0,u.jsx)("span",{className:"footer__link-item",dangerouslySetInnerHTML:{__html:t.html}}):(0,u.jsx)(We,{item:t})}function Xe(e){let{links:t}=e;return(0,u.jsx)("div",{className:"footer__links text--center",children:(0,u.jsx)("div",{className:"footer__links",children:t.map(((e,n)=>(0,u.jsxs)(r.Fragment,{children:[(0,u.jsx)(Ze,{item:e}),t.length!==n+1&&(0,u.jsx)(Ye,{})]},n)))})})}function Je(e){let{links:t}=e;return function(e){return"title"in e[0]}(t)?(0,u.jsx)(Ke,{columns:t}):(0,u.jsx)(Xe,{links:t})}var et=n(975);const tt={footerLogoLink:"footerLogoLink_BH7S"};function nt(e){let{logo:t}=e;const{withBaseUrl:n}=(0,X.hH)(),r={light:n(t.src),dark:n(t.srcDark??t.src)};return(0,u.jsx)(et.A,{className:(0,o.A)("footer__logo",t.className),alt:t.alt,sources:r,width:t.width,height:t.height,style:t.style})}function rt(e){let{logo:t}=e;return t.href?(0,u.jsx)(Z.A,{href:t.href,className:tt.footerLogoLink,target:t.target,children:(0,u.jsx)(nt,{logo:t})}):(0,u.jsx)(nt,{logo:t})}function ot(e){let{copyright:t}=e;return(0,u.jsx)("div",{className:"footer__copyright",dangerouslySetInnerHTML:{__html:t}})}function st(e){let{style:t,links:n,logo:r,copyright:s}=e;return(0,u.jsx)("footer",{className:(0,o.A)("footer",{"footer--dark":"dark"===t}),children:(0,u.jsxs)("div",{className:"container container-fluid",children:[n,(r||s)&&(0,u.jsxs)("div",{className:"footer__bottom text--center",children:[r&&(0,u.jsx)("div",{className:"margin-bottom--sm",children:r}),s]})]})})}function at(){const{footer:e}=(0,w.p)();if(!e)return null;const{copyright:t,links:n,logo:r,style:o}=e;return(0,u.jsx)(st,{style:o,links:n&&n.length>0&&(0,u.jsx)(Je,{links:n}),logo:r&&(0,u.jsx)(rt,{logo:r}),copyright:t&&(0,u.jsx)(ot,{copyright:t})})}const it=r.memo(at),lt=(0,R.fM)([F.a,k.o,P.Tv,xe.VQ,a.Jx,function(e){let{children:t}=e;return(0,u.jsx)(N.y_,{children:(0,u.jsx)(A.e,{children:(0,u.jsx)(O,{children:t})})})}]);function ct(e){let{children:t}=e;return(0,u.jsx)(lt,{children:t})}var ut=n(5225);function dt(e){let{error:t,tryAgain:n}=e;return(0,u.jsx)("main",{className:"container margin-vert--xl",children:(0,u.jsx)("div",{className:"row",children:(0,u.jsxs)("div",{className:"col col--6 col--offset-3",children:[(0,u.jsx)(ut.A,{as:"h1",className:"hero__title",children:(0,u.jsx)(l.A,{id:"theme.ErrorPageContent.title",description:"The title of the fallback page when the page crashed",children:"This page crashed."})}),(0,u.jsx)("div",{className:"margin-vert--lg",children:(0,u.jsx)(Me,{onClick:n,className:"button button--primary shadow--lw"})}),(0,u.jsx)("hr",{}),(0,u.jsx)("div",{className:"margin-vert--md",children:(0,u.jsx)(De,{error:t})})]})})})}const pt={mainWrapper:"mainWrapper_z2l0"};function ft(e){const{children:t,noFooter:n,wrapperClassName:r,title:i,description:l}=e;return(0,b.J)(),(0,u.jsxs)(ct,{children:[(0,u.jsx)(a.be,{title:i,description:l}),(0,u.jsx)(y,{}),(0,u.jsx)(T,{}),(0,u.jsx)(Ge,{}),(0,u.jsx)("div",{id:d,className:(0,o.A)(h.G.wrapper.main,pt.mainWrapper,r),children:(0,u.jsx)(s.A,{fallback:e=>(0,u.jsx)(dt,{...e}),children:t})}),!n&&(0,u.jsx)(it,{})]})}},20:(e,t,n)=>{"use strict";n.d(t,{A:()=>u});n(6540);var r=n(4783),o=n(8180),s=n(7639),a=n(6957),i=n(975),l=n(4848);function c(e){let{logo:t,alt:n,imageClassName:r}=e;const s={light:(0,o.Ay)(t.src),dark:(0,o.Ay)(t.srcDark||t.src)},a=(0,l.jsx)(i.A,{className:t.className,sources:s,height:t.height,width:t.width,alt:n,style:t.style});return r?(0,l.jsx)("div",{className:r,children:a}):a}function u(e){const{siteConfig:{title:t}}=(0,s.A)(),{navbar:{title:n,logo:i}}=(0,a.p)(),{imageClassName:u,titleClassName:d,...p}=e,f=(0,o.Ay)(i?.href||"/"),g=n?"":t,m=i?.alt??g;return(0,l.jsxs)(r.A,{to:f,...p,...i?.target&&{target:i.target},children:[i&&(0,l.jsx)(c,{logo:i,alt:m,imageClassName:u}),null!=n&&(0,l.jsx)("b",{className:d,children:n})]})}},1210:(e,t,n)=>{"use strict";n.d(t,{A:()=>s});n(6540);var r=n(1141),o=n(4848);function s(e){let{locale:t,version:n,tag:s}=e;const a=t;return(0,o.jsxs)(r.A,{children:[t&&(0,o.jsx)("meta",{name:"docusaurus_locale",content:t}),n&&(0,o.jsx)("meta",{name:"docusaurus_version",content:n}),s&&(0,o.jsx)("meta",{name:"docusaurus_tag",content:s}),a&&(0,o.jsx)("meta",{name:"docsearch:language",content:a}),n&&(0,o.jsx)("meta",{name:"docsearch:version",content:n}),s&&(0,o.jsx)("meta",{name:"docsearch:docusaurus_tag",content:s})]})}},975:(e,t,n)=>{"use strict";n.d(t,{A:()=>u});var r=n(6540),o=n(4164),s=n(1062),a=n(7710);const i={themedComponent:"themedComponent_mlkZ","themedComponent--light":"themedComponent--light_NVdE","themedComponent--dark":"themedComponent--dark_xIcU"};var l=n(4848);function c(e){let{className:t,children:n}=e;const c=(0,s.A)(),{colorMode:u}=(0,a.G)();return(0,l.jsx)(l.Fragment,{children:(c?"dark"===u?["dark"]:["light"]:["light","dark"]).map((e=>{const s=n({theme:e,className:(0,o.A)(t,i.themedComponent,i[`themedComponent--${e}`])});return(0,l.jsx)(r.Fragment,{children:s},e)}))})}function u(e){const{sources:t,className:n,alt:r,...o}=e;return(0,l.jsx)(c,{className:n,children:e=>{let{theme:n,className:s}=e;return(0,l.jsx)("img",{src:t[n],alt:r,className:s,...o})}})}},4549:(e,t,n)=>{"use strict";n.d(t,{N:()=>b,u:()=>c});var r=n(6540),o=n(1712),s=n(6494),a=n(6350),i=n(4848);const l="ease-in-out";function c(e){let{initialState:t}=e;const[n,o]=(0,r.useState)(t??!1),s=(0,r.useCallback)((()=>{o((e=>!e))}),[]);return{collapsed:n,setCollapsed:o,toggleCollapsed:s}}const u={display:"none",overflow:"hidden",height:"0px"},d={display:"block",overflow:"visible",height:"auto"};function p(e,t){const n=t?u:d;e.style.display=n.display,e.style.overflow=n.overflow,e.style.height=n.height}function f(e){let{collapsibleRef:t,collapsed:n,animation:o}=e;const s=(0,r.useRef)(!1);(0,r.useEffect)((()=>{const e=t.current;function r(){const t=e.scrollHeight,n=o?.duration??function(e){if((0,a.O)())return 1;const t=e/36;return Math.round(10*(4+15*t**.25+t/5))}(t);return{transition:`height ${n}ms ${o?.easing??l}`,height:`${t}px`}}function i(){const t=r();e.style.transition=t.transition,e.style.height=t.height}if(!s.current)return p(e,n),void(s.current=!0);return e.style.willChange="height",function(){const t=requestAnimationFrame((()=>{n?(i(),requestAnimationFrame((()=>{e.style.height=u.height,e.style.overflow=u.overflow}))):(e.style.display="block",requestAnimationFrame((()=>{i()})))}));return()=>cancelAnimationFrame(t)}()}),[t,n,o])}function g(e){if(!o.A.canUseDOM)return e?u:d}function m(e){let{as:t="div",collapsed:n,children:o,animation:s,onCollapseTransitionEnd:a,className:l,disableSSRStyle:c}=e;const u=(0,r.useRef)(null);return f({collapsibleRef:u,collapsed:n,animation:s}),(0,i.jsx)(t,{ref:u,style:c?void 0:g(n),onTransitionEnd:e=>{"height"===e.propertyName&&(p(u.current,n),a?.(n))},className:l,children:o})}function h(e){let{collapsed:t,...n}=e;const[o,a]=(0,r.useState)(!t),[l,c]=(0,r.useState)(t);return(0,s.A)((()=>{t||a(!0)}),[t]),(0,s.A)((()=>{o&&c(t)}),[o,t]),o?(0,i.jsx)(m,{...n,collapsed:l}):null}function b(e){let{lazy:t,...n}=e;const r=t?h:m;return(0,i.jsx)(r,{...n})}},2:(e,t,n)=>{"use strict";n.d(t,{M:()=>m,o:()=>g});var r=n(6540),o=n(1062),s=n(9900),a=n(4799),i=n(6957),l=n(4848);const c=(0,s.Wf)("docusaurus.announcement.dismiss"),u=(0,s.Wf)("docusaurus.announcement.id"),d=()=>"true"===c.get(),p=e=>c.set(String(e)),f=r.createContext(null);function g(e){let{children:t}=e;const n=function(){const{announcementBar:e}=(0,i.p)(),t=(0,o.A)(),[n,s]=(0,r.useState)((()=>!!t&&d()));(0,r.useEffect)((()=>{s(d())}),[]);const a=(0,r.useCallback)((()=>{p(!0),s(!0)}),[]);return(0,r.useEffect)((()=>{if(!e)return;const{id:t}=e;let n=u.get();"annoucement-bar"===n&&(n="announcement-bar");const r=t!==n;u.set(t),r&&p(!1),!r&&d()||s(!1)}),[e]),(0,r.useMemo)((()=>({isActive:!!e&&!n,close:a})),[e,n,a])}();return(0,l.jsx)(f.Provider,{value:n,children:t})}function m(){const e=(0,r.useContext)(f);if(!e)throw new a.dV("AnnouncementBarProvider");return e}},7710:(e,t,n)=>{"use strict";n.d(t,{G:()=>b,a:()=>h});var r=n(6540),o=n(1712),s=n(4799),a=n(9900),i=n(6957),l=n(4848);const c=r.createContext(void 0),u="theme",d=(0,a.Wf)(u),p={light:"light",dark:"dark"},f=e=>e===p.dark?p.dark:p.light,g=e=>o.A.canUseDOM?f(document.documentElement.getAttribute("data-theme")):f(e),m=e=>{d.set(f(e))};function h(e){let{children:t}=e;const n=function(){const{colorMode:{defaultMode:e,disableSwitch:t,respectPrefersColorScheme:n}}=(0,i.p)(),[o,s]=(0,r.useState)(g(e));(0,r.useEffect)((()=>{t&&d.del()}),[t]);const a=(0,r.useCallback)((function(t,r){void 0===r&&(r={});const{persist:o=!0}=r;t?(s(t),o&&m(t)):(s(n?window.matchMedia("(prefers-color-scheme: dark)").matches?p.dark:p.light:e),d.del())}),[n,e]);(0,r.useEffect)((()=>{document.documentElement.setAttribute("data-theme",f(o))}),[o]),(0,r.useEffect)((()=>{if(t)return;const e=e=>{if(e.key!==u)return;const t=d.get();null!==t&&a(f(t))};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)}),[t,a]);const l=(0,r.useRef)(!1);return(0,r.useEffect)((()=>{if(t&&!n)return;const e=window.matchMedia("(prefers-color-scheme: dark)"),r=()=>{window.matchMedia("print").matches||l.current?l.current=window.matchMedia("print").matches:a(null)};return e.addListener(r),()=>e.removeListener(r)}),[a,t,n]),(0,r.useMemo)((()=>({colorMode:o,setColorMode:a,get isDarkTheme(){return o===p.dark},setLightTheme(){a(p.light)},setDarkTheme(){a(p.dark)}})),[o,a])}();return(0,l.jsx)(c.Provider,{value:n,children:t})}function b(){const e=(0,r.useContext)(c);if(null==e)throw new s.dV("ColorModeProvider","Please see https://docusaurus.io/docs/api/themes/configuration#use-color-mode.");return e}},1938:(e,t,n)=>{"use strict";n.d(t,{M:()=>f,e:()=>p});var r=n(6540),o=n(763),s=n(2216),a=n(2814),i=n(6957),l=n(4799),c=n(4848);const u=r.createContext(void 0);function d(){const e=function(){const e=(0,o.YL)(),{items:t}=(0,i.p)().navbar;return 0===t.length&&!e.component}(),t=(0,s.l)(),n=!e&&"mobile"===t,[l,c]=(0,r.useState)(!1);(0,a.$Z)((()=>{if(l)return c(!1),!1}));const u=(0,r.useCallback)((()=>{c((e=>!e))}),[]);return(0,r.useEffect)((()=>{"desktop"===t&&c(!1)}),[t]),(0,r.useMemo)((()=>({disabled:e,shouldRender:n,toggle:u,shown:l})),[e,n,u,l])}function p(e){let{children:t}=e;const n=d();return(0,c.jsx)(u.Provider,{value:n,children:t})}function f(){const e=r.useContext(u);if(void 0===e)throw new l.dV("NavbarMobileSidebarProvider");return e}},763:(e,t,n)=>{"use strict";n.d(t,{GX:()=>c,YL:()=>l,y_:()=>i});var r=n(6540),o=n(4799),s=n(4848);const a=r.createContext(null);function i(e){let{children:t}=e;const n=(0,r.useState)({component:null,props:null});return(0,s.jsx)(a.Provider,{value:n,children:t})}function l(){const e=(0,r.useContext)(a);if(!e)throw new o.dV("NavbarSecondaryMenuContentProvider");return e[0]}function c(e){let{component:t,props:n}=e;const s=(0,r.useContext)(a);if(!s)throw new o.dV("NavbarSecondaryMenuContentProvider");const[,i]=s,l=(0,o.Be)(n);return(0,r.useEffect)((()=>{i({component:t,props:l})}),[i,t,l]),(0,r.useEffect)((()=>()=>i({component:null,props:null})),[i]),null}},9503:(e,t,n)=>{"use strict";n.d(t,{w:()=>o,J:()=>s});var r=n(6540);const o="navigation-with-keyboard";function s(){(0,r.useEffect)((()=>{function e(e){"keydown"===e.type&&"Tab"===e.key&&document.body.classList.add(o),"mousedown"===e.type&&document.body.classList.remove(o)}return document.addEventListener("keydown",e),document.addEventListener("mousedown",e),()=>{document.body.classList.remove(o),document.removeEventListener("keydown",e),document.removeEventListener("mousedown",e)}}),[])}},2216:(e,t,n)=>{"use strict";n.d(t,{l:()=>i});var r=n(6540),o=n(1712);const s={desktop:"desktop",mobile:"mobile",ssr:"ssr"},a=996;function i(e){let{desktopBreakpoint:t=a}=void 0===e?{}:e;const[n,i]=(0,r.useState)((()=>"ssr"));return(0,r.useEffect)((()=>{function e(){i(function(e){if(!o.A.canUseDOM)throw new Error("getWindowSize() should only be called after React hydration");return window.innerWidth>e?s.desktop:s.mobile}(t))}return e(),window.addEventListener("resize",e),()=>{window.removeEventListener("resize",e)}}),[t]),n}},8630:(e,t,n)=>{"use strict";n.d(t,{G:()=>r});const r={page:{blogListPage:"blog-list-page",blogPostPage:"blog-post-page",blogTagsListPage:"blog-tags-list-page",blogTagPostListPage:"blog-tags-post-list-page",blogAuthorsListPage:"blog-authors-list-page",blogAuthorsPostsPage:"blog-authors-posts-page",docsDocPage:"docs-doc-page",docsTagsListPage:"docs-tags-list-page",docsTagDocListPage:"docs-tags-doc-list-page",mdxPage:"mdx-page"},wrapper:{main:"main-wrapper",blogPages:"blog-wrapper",docsPages:"docs-wrapper",mdxPages:"mdx-wrapper"},common:{editThisPage:"theme-edit-this-page",lastUpdated:"theme-last-updated",backToTopButton:"theme-back-to-top-button",codeBlock:"theme-code-block",admonition:"theme-admonition",unlistedBanner:"theme-unlisted-banner",draftBanner:"theme-draft-banner",admonitionType:e=>`theme-admonition-${e}`},layout:{},docs:{docVersionBanner:"theme-doc-version-banner",docVersionBadge:"theme-doc-version-badge",docBreadcrumbs:"theme-doc-breadcrumbs",docMarkdown:"theme-doc-markdown",docTocMobile:"theme-doc-toc-mobile",docTocDesktop:"theme-doc-toc-desktop",docFooter:"theme-doc-footer",docFooterTagsRow:"theme-doc-footer-tags-row",docFooterEditMetaRow:"theme-doc-footer-edit-meta-row",docSidebarContainer:"theme-doc-sidebar-container",docSidebarMenu:"theme-doc-sidebar-menu",docSidebarItemCategory:"theme-doc-sidebar-item-category",docSidebarItemLink:"theme-doc-sidebar-item-link",docSidebarItemCategoryLevel:e=>`theme-doc-sidebar-item-category-level-${e}`,docSidebarItemLinkLevel:e=>`theme-doc-sidebar-item-link-level-${e}`},blog:{blogFooterTagsRow:"theme-blog-footer-tags-row",blogFooterEditMetaRow:"theme-blog-footer-edit-meta-row"},pages:{pageFooterEditMetaRow:"theme-pages-footer-edit-meta-row"}}},6350:(e,t,n)=>{"use strict";function r(){return window.matchMedia("(prefers-reduced-motion: reduce)").matches}n.d(t,{O:()=>r})},2814:(e,t,n)=>{"use strict";n.d(t,{$Z:()=>a,aZ:()=>l});var r=n(6540),o=n(6347),s=n(4799);function a(e){!function(e){const t=(0,o.W6)(),n=(0,s._q)(e);(0,r.useEffect)((()=>t.block(((e,t)=>n(e,t)))),[t,n])}(((t,n)=>{if("POP"===n)return e(t,n)}))}function i(e){const t=(0,o.W6)();return(0,r.useSyncExternalStore)(t.listen,(()=>e(t)),(()=>e(t)))}function l(e){return i((t=>null===e?null:new URLSearchParams(t.location.search).get(e)))}},5167:(e,t,n)=>{"use strict";function r(e,t){return void 0===t&&(t=(e,t)=>e===t),e.filter(((n,r)=>e.findIndex((e=>t(e,n)))!==r))}function o(e){return Array.from(new Set(e))}n.d(t,{XI:()=>r,sb:()=>o})},9817:(e,t,n)=>{"use strict";n.d(t,{e3:()=>f,be:()=>d,Jx:()=>g});var r=n(6540),o=n(4164),s=n(1141),a=n(3363);function i(){const e=r.useContext(a.o);if(!e)throw new Error("Unexpected: no Docusaurus route context found");return e}var l=n(8180),c=n(7639);var u=n(4848);function d(e){let{title:t,description:n,keywords:r,image:o,children:a}=e;const i=function(e){const{siteConfig:t}=(0,c.A)(),{title:n,titleDelimiter:r}=t;return e?.trim().length?`${e.trim()} ${r} ${n}`:n}(t),{withBaseUrl:d}=(0,l.hH)(),p=o?d(o,{absolute:!0}):void 0;return(0,u.jsxs)(s.A,{children:[t&&(0,u.jsx)("title",{children:i}),t&&(0,u.jsx)("meta",{property:"og:title",content:i}),n&&(0,u.jsx)("meta",{name:"description",content:n}),n&&(0,u.jsx)("meta",{property:"og:description",content:n}),r&&(0,u.jsx)("meta",{name:"keywords",content:Array.isArray(r)?r.join(","):r}),p&&(0,u.jsx)("meta",{property:"og:image",content:p}),p&&(0,u.jsx)("meta",{name:"twitter:image",content:p}),a]})}const p=r.createContext(void 0);function f(e){let{className:t,children:n}=e;const a=r.useContext(p),i=(0,o.A)(a,t);return(0,u.jsxs)(p.Provider,{value:i,children:[(0,u.jsx)(s.A,{children:(0,u.jsx)("html",{className:i})}),n]})}function g(e){let{children:t}=e;const n=i(),r=`plugin-${n.plugin.name.replace(/docusaurus-(?:plugin|theme)-(?:content-)?/gi,"")}`;const s=`plugin-id-${n.plugin.id}`;return(0,u.jsx)(f,{className:(0,o.A)(r,s),children:t})}},4799:(e,t,n)=>{"use strict";n.d(t,{Be:()=>c,ZC:()=>i,_q:()=>a,dV:()=>l,fM:()=>u});var r=n(6540),o=n(6494),s=n(4848);function a(e){const t=(0,r.useRef)(e);return(0,o.A)((()=>{t.current=e}),[e]),(0,r.useCallback)((function(){return t.current(...arguments)}),[])}function i(e){const t=(0,r.useRef)();return(0,o.A)((()=>{t.current=e})),t.current}class l extends Error{constructor(e,t){super(),this.name="ReactContextError",this.message=`Hook ${this.stack?.split("\n")[1]?.match(/at (?:\w+\.)?(?\w+)/)?.groups.name??""} is called outside the <${e}>. ${t??""}`}}function c(e){const t=Object.entries(e);return t.sort(((e,t)=>e[0].localeCompare(t[0]))),(0,r.useMemo)((()=>e),t.flat())}function u(e){return t=>{let{children:n}=t;return(0,s.jsx)(s.Fragment,{children:e.reduceRight(((e,t)=>(0,s.jsx)(t,{children:e})),n)})}}},260:(e,t,n)=>{"use strict";n.d(t,{Dt:()=>i,ys:()=>a});var r=n(6540),o=n(2413),s=n(7639);function a(e,t){const n=e=>(!e||e.endsWith("/")?e:`${e}/`)?.toLowerCase();return n(e)===n(t)}function i(){const{baseUrl:e}=(0,s.A)().siteConfig;return(0,r.useMemo)((()=>function(e){let{baseUrl:t,routes:n}=e;function r(e){return e.path===t&&!0===e.exact}function o(e){return e.path===t&&!e.exact}return function e(t){if(0===t.length)return;return t.find(r)||e(t.filter(o).flatMap((e=>e.routes??[])))}(n)}({routes:o.A,baseUrl:e})),[e])}},4245:(e,t,n)=>{"use strict";n.d(t,{Mq:()=>f,Tv:()=>u,a_:()=>g,gk:()=>m});var r=n(6540),o=n(1712),s=n(1062),a=n(6494),i=n(4799),l=n(4848);const c=r.createContext(void 0);function u(e){let{children:t}=e;const n=function(){const e=(0,r.useRef)(!0);return(0,r.useMemo)((()=>({scrollEventsEnabledRef:e,enableScrollEvents:()=>{e.current=!0},disableScrollEvents:()=>{e.current=!1}})),[])}();return(0,l.jsx)(c.Provider,{value:n,children:t})}function d(){const e=(0,r.useContext)(c);if(null==e)throw new i.dV("ScrollControllerProvider");return e}const p=()=>o.A.canUseDOM?{scrollX:window.pageXOffset,scrollY:window.pageYOffset}:null;function f(e,t){void 0===t&&(t=[]);const{scrollEventsEnabledRef:n}=d(),o=(0,r.useRef)(p()),s=(0,i._q)(e);(0,r.useEffect)((()=>{const e=()=>{if(!n.current)return;const e=p();s(e,o.current),o.current=e},t={passive:!0};return e(),window.addEventListener("scroll",e,t),()=>window.removeEventListener("scroll",e,t)}),[s,n,...t])}function g(){const e=d(),t=function(){const e=(0,r.useRef)({elem:null,top:0}),t=(0,r.useCallback)((t=>{e.current={elem:t,top:t.getBoundingClientRect().top}}),[]),n=(0,r.useCallback)((()=>{const{current:{elem:t,top:n}}=e;if(!t)return{restored:!1};const r=t.getBoundingClientRect().top-n;return r&&window.scrollBy({left:0,top:r}),e.current={elem:null,top:0},{restored:0!==r}}),[]);return(0,r.useMemo)((()=>({save:t,restore:n})),[n,t])}(),n=(0,r.useRef)(void 0),o=(0,r.useCallback)((r=>{t.save(r),e.disableScrollEvents(),n.current=()=>{const{restored:r}=t.restore();if(n.current=void 0,r){const t=()=>{e.enableScrollEvents(),window.removeEventListener("scroll",t)};window.addEventListener("scroll",t)}else e.enableScrollEvents()}}),[e,t]);return(0,a.A)((()=>{queueMicrotask((()=>n.current?.()))})),{blockElementScrollPositionUntilNextRender:o}}function m(){const e=(0,r.useRef)(null),t=(0,s.A)()&&"smooth"===getComputedStyle(document.documentElement).scrollBehavior;return{startScroll:n=>{e.current=t?function(e){return window.scrollTo({top:e,behavior:"smooth"}),()=>{}}(n):function(e){let t=null;const n=document.documentElement.scrollTop>e;return function r(){const o=document.documentElement.scrollTop;(n&&o>e||!n&&ot&&cancelAnimationFrame(t)}(n)},cancelScroll:()=>e.current?.()}}},9900:(e,t,n)=>{"use strict";n.d(t,{Wf:()=>u,Dv:()=>d});var r=n(6540);const o=JSON.parse('{"N":"localStorage","M":""}'),s=o.N;function a(e){let{key:t,oldValue:n,newValue:r,storage:o}=e;if(n===r)return;const s=document.createEvent("StorageEvent");s.initStorageEvent("storage",!1,!1,t,n,r,window.location.href,o),window.dispatchEvent(s)}function i(e){if(void 0===e&&(e=s),"undefined"==typeof window)throw new Error("Browser storage is not available on Node.js/Docusaurus SSR process.");if("none"===e)return null;try{return window[e]}catch(n){return t=n,l||(console.warn("Docusaurus browser storage is not available.\nPossible reasons: running Docusaurus in an iframe, in an incognito browser session, or using too strict browser privacy settings.",t),l=!0),null}var t}let l=!1;const c={get:()=>null,set:()=>{},del:()=>{},listen:()=>()=>{}};function u(e,t){const n=`${e}${o.M}`;if("undefined"==typeof window)return function(e){function t(){throw new Error(`Illegal storage API usage for storage key "${e}".\nDocusaurus storage APIs are not supposed to be called on the server-rendering process.\nPlease only call storage APIs in effects and event handlers.`)}return{get:t,set:t,del:t,listen:t}}(n);const r=i(t?.persistence);return null===r?c:{get:()=>{try{return r.getItem(n)}catch(e){return console.error(`Docusaurus storage error, can't get key=${n}`,e),null}},set:e=>{try{const t=r.getItem(n);r.setItem(n,e),a({key:n,oldValue:t,newValue:e,storage:r})}catch(t){console.error(`Docusaurus storage error, can't set ${n}=${e}`,t)}},del:()=>{try{const e=r.getItem(n);r.removeItem(n),a({key:n,oldValue:e,newValue:null,storage:r})}catch(e){console.error(`Docusaurus storage error, can't delete key=${n}`,e)}},listen:e=>{try{const t=t=>{t.storageArea===r&&t.key===n&&e(t)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)}catch(t){return console.error(`Docusaurus storage error, can't listen for changes of key=${n}`,t),()=>{}}}}}function d(e,t){const n=(0,r.useRef)((()=>null===e?c:u(e,t))).current(),o=(0,r.useCallback)((e=>"undefined"==typeof window?()=>{}:n.listen(e)),[n]);return[(0,r.useSyncExternalStore)(o,(()=>"undefined"==typeof window?null:n.get()),(()=>null)),n]}},2098:(e,t,n)=>{"use strict";n.d(t,{o:()=>a});var r=n(7639),o=n(6347),s=n(4609);function a(){const{siteConfig:{baseUrl:e,url:t,trailingSlash:n},i18n:{defaultLocale:a,currentLocale:i}}=(0,r.A)(),{pathname:l}=(0,o.zy)(),c=(0,s.Ks)(l,{trailingSlash:n,baseUrl:e}),u=i===a?e:e.replace(`/${i}/`,"/"),d=c.replace(e,"");return{createUrl:function(e){let{locale:n,fullyQualified:r}=e;return`${r?t:""}${function(e){return e===a?`${u}`:`${u}${e}/`}(n)}${d}`}}}},4067:(e,t,n)=>{"use strict";n.d(t,{$:()=>a});var r=n(6540),o=n(6347),s=n(4799);function a(e){const t=(0,o.zy)(),n=(0,s.ZC)(t),a=(0,s._q)(e);(0,r.useEffect)((()=>{n&&t!==n&&a({location:t,previousLocation:n})}),[a,t,n])}},6957:(e,t,n)=>{"use strict";n.d(t,{p:()=>o});var r=n(7639);function o(){return(0,r.A)().siteConfig.themeConfig}},4356:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.addTrailingSlash=o,t.default=function(e,t){const{trailingSlash:n,baseUrl:r}=t;if(e.startsWith("#"))return e;if(void 0===n)return e;const[a]=e.split(/[#?]/),i="/"===a||a===r?a:(l=a,c=n,c?o(l):s(l));var l,c;return e.replace(a,i)},t.addLeadingSlash=function(e){return(0,r.addPrefix)(e,"/")},t.removeTrailingSlash=s;const r=n(835);function o(e){return e.endsWith("/")?e:`${e}/`}function s(e){return(0,r.removeSuffix)(e,"/")}},8274:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getErrorCausalChain=function e(t){if(t.cause)return[t,...e(t.cause)];return[t]}},4609:(e,t,n)=>{"use strict";t.rA=t.Ks=void 0;const r=n(1635);var o=n(4356);Object.defineProperty(t,"Ks",{enumerable:!0,get:function(){return r.__importDefault(o).default}});var s=n(835);var a=n(8274);Object.defineProperty(t,"rA",{enumerable:!0,get:function(){return a.getErrorCausalChain}})},835:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.addPrefix=function(e,t){return e.startsWith(t)?e:`${t}${e}`},t.removeSuffix=function(e,t){if(""===t)return e;return e.endsWith(t)?e.slice(0,-t.length):e},t.addSuffix=function(e,t){return e.endsWith(t)?e:`${e}${t}`},t.removePrefix=function(e,t){return e.startsWith(t)?e.slice(t.length):e}},1513:(e,t,n)=>{"use strict";n.d(t,{zR:()=>w,TM:()=>E,yJ:()=>f,sC:()=>T,AO:()=>p});var r=n(8168);function o(e){return"/"===e.charAt(0)}function s(e,t){for(var n=t,r=n+1,o=e.length;r=0;p--){var f=a[p];"."===f?s(a,p):".."===f?(s(a,p),d++):d&&(s(a,p),d--)}if(!c)for(;d--;d)a.unshift("..");!c||""===a[0]||a[0]&&o(a[0])||a.unshift("");var g=a.join("/");return n&&"/"!==g.substr(-1)&&(g+="/"),g};var i=n(8997);function l(e){return"/"===e.charAt(0)?e:"/"+e}function c(e){return"/"===e.charAt(0)?e.substr(1):e}function u(e,t){return function(e,t){return 0===e.toLowerCase().indexOf(t.toLowerCase())&&-1!=="/?#".indexOf(e.charAt(t.length))}(e,t)?e.substr(t.length):e}function d(e){return"/"===e.charAt(e.length-1)?e.slice(0,-1):e}function p(e){var t=e.pathname,n=e.search,r=e.hash,o=t||"/";return n&&"?"!==n&&(o+="?"===n.charAt(0)?n:"?"+n),r&&"#"!==r&&(o+="#"===r.charAt(0)?r:"#"+r),o}function f(e,t,n,o){var s;"string"==typeof e?(s=function(e){var t=e||"/",n="",r="",o=t.indexOf("#");-1!==o&&(r=t.substr(o),t=t.substr(0,o));var s=t.indexOf("?");return-1!==s&&(n=t.substr(s),t=t.substr(0,s)),{pathname:t,search:"?"===n?"":n,hash:"#"===r?"":r}}(e),s.state=t):(void 0===(s=(0,r.A)({},e)).pathname&&(s.pathname=""),s.search?"?"!==s.search.charAt(0)&&(s.search="?"+s.search):s.search="",s.hash?"#"!==s.hash.charAt(0)&&(s.hash="#"+s.hash):s.hash="",void 0!==t&&void 0===s.state&&(s.state=t));try{s.pathname=decodeURI(s.pathname)}catch(i){throw i instanceof URIError?new URIError('Pathname "'+s.pathname+'" could not be decoded. This is likely caused by an invalid percent-encoding.'):i}return n&&(s.key=n),o?s.pathname?"/"!==s.pathname.charAt(0)&&(s.pathname=a(s.pathname,o.pathname)):s.pathname=o.pathname:s.pathname||(s.pathname="/"),s}function g(){var e=null;var t=[];return{setPrompt:function(t){return e=t,function(){e===t&&(e=null)}},confirmTransitionTo:function(t,n,r,o){if(null!=e){var s="function"==typeof e?e(t,n):e;"string"==typeof s?"function"==typeof r?r(s,o):o(!0):o(!1!==s)}else o(!0)},appendListener:function(e){var n=!0;function r(){n&&e.apply(void 0,arguments)}return t.push(r),function(){n=!1,t=t.filter((function(e){return e!==r}))}},notifyListeners:function(){for(var e=arguments.length,n=new Array(e),r=0;rt?n.splice(t,n.length-t,o):n.push(o),d({action:r,location:o,index:t,entries:n})}}))},replace:function(e,t){var r="REPLACE",o=f(e,t,m(),w.location);u.confirmTransitionTo(o,r,n,(function(e){e&&(w.entries[w.index]=o,d({action:r,location:o}))}))},go:y,goBack:function(){y(-1)},goForward:function(){y(1)},canGo:function(e){var t=w.index+e;return t>=0&&t{"use strict";var r=n(4363),o={childContextTypes:!0,contextType:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,getDerivedStateFromError:!0,getDerivedStateFromProps:!0,mixins:!0,propTypes:!0,type:!0},s={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},a={$$typeof:!0,compare:!0,defaultProps:!0,displayName:!0,propTypes:!0,type:!0},i={};function l(e){return r.isMemo(e)?a:i[e.$$typeof]||o}i[r.ForwardRef]={$$typeof:!0,render:!0,defaultProps:!0,displayName:!0,propTypes:!0},i[r.Memo]=a;var c=Object.defineProperty,u=Object.getOwnPropertyNames,d=Object.getOwnPropertySymbols,p=Object.getOwnPropertyDescriptor,f=Object.getPrototypeOf,g=Object.prototype;e.exports=function e(t,n,r){if("string"!=typeof n){if(g){var o=f(n);o&&o!==g&&e(t,o,r)}var a=u(n);d&&(a=a.concat(d(n)));for(var i=l(t),m=l(n),h=0;h{"use strict";e.exports=function(e,t,n,r,o,s,a,i){if(!e){var l;if(void 0===t)l=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[n,r,o,s,a,i],u=0;(l=new Error(t.replace(/%s/g,(function(){return c[u++]})))).name="Invariant Violation"}throw l.framesToPop=1,l}}},4634:e=>{e.exports=Array.isArray||function(e){return"[object Array]"==Object.prototype.toString.call(e)}},5300:(e,t,n)=>{"use strict";n.r(t)},8252:(e,t,n)=>{"use strict";n.r(t)},5947:function(e,t,n){var r,o;r=function(){var e,t,n={version:"0.2.0"},r=n.settings={minimum:.08,easing:"ease",positionUsing:"",speed:200,trickle:!0,trickleRate:.02,trickleSpeed:800,showSpinner:!0,barSelector:'[role="bar"]',spinnerSelector:'[role="spinner"]',parent:"body",template:'
'};function o(e,t,n){return en?n:e}function s(e){return 100*(-1+e)}function a(e,t,n){var o;return(o="translate3d"===r.positionUsing?{transform:"translate3d("+s(e)+"%,0,0)"}:"translate"===r.positionUsing?{transform:"translate("+s(e)+"%,0)"}:{"margin-left":s(e)+"%"}).transition="all "+t+"ms "+n,o}n.configure=function(e){var t,n;for(t in e)void 0!==(n=e[t])&&e.hasOwnProperty(t)&&(r[t]=n);return this},n.status=null,n.set=function(e){var t=n.isStarted();e=o(e,r.minimum,1),n.status=1===e?null:e;var s=n.render(!t),c=s.querySelector(r.barSelector),u=r.speed,d=r.easing;return s.offsetWidth,i((function(t){""===r.positionUsing&&(r.positionUsing=n.getPositioningCSS()),l(c,a(e,u,d)),1===e?(l(s,{transition:"none",opacity:1}),s.offsetWidth,setTimeout((function(){l(s,{transition:"all "+u+"ms linear",opacity:0}),setTimeout((function(){n.remove(),t()}),u)}),u)):setTimeout(t,u)})),this},n.isStarted=function(){return"number"==typeof n.status},n.start=function(){n.status||n.set(0);var e=function(){setTimeout((function(){n.status&&(n.trickle(),e())}),r.trickleSpeed)};return r.trickle&&e(),this},n.done=function(e){return e||n.status?n.inc(.3+.5*Math.random()).set(1):this},n.inc=function(e){var t=n.status;return t?("number"!=typeof e&&(e=(1-t)*o(Math.random()*t,.1,.95)),t=o(t+e,0,.994),n.set(t)):n.start()},n.trickle=function(){return n.inc(Math.random()*r.trickleRate)},e=0,t=0,n.promise=function(r){return r&&"resolved"!==r.state()?(0===t&&n.start(),e++,t++,r.always((function(){0==--t?(e=0,n.done()):n.set((e-t)/e)})),this):this},n.render=function(e){if(n.isRendered())return document.getElementById("nprogress");u(document.documentElement,"nprogress-busy");var t=document.createElement("div");t.id="nprogress",t.innerHTML=r.template;var o,a=t.querySelector(r.barSelector),i=e?"-100":s(n.status||0),c=document.querySelector(r.parent);return l(a,{transition:"all 0 linear",transform:"translate3d("+i+"%,0,0)"}),r.showSpinner||(o=t.querySelector(r.spinnerSelector))&&f(o),c!=document.body&&u(c,"nprogress-custom-parent"),c.appendChild(t),t},n.remove=function(){d(document.documentElement,"nprogress-busy"),d(document.querySelector(r.parent),"nprogress-custom-parent");var e=document.getElementById("nprogress");e&&f(e)},n.isRendered=function(){return!!document.getElementById("nprogress")},n.getPositioningCSS=function(){var e=document.body.style,t="WebkitTransform"in e?"Webkit":"MozTransform"in e?"Moz":"msTransform"in e?"ms":"OTransform"in e?"O":"";return t+"Perspective"in e?"translate3d":t+"Transform"in e?"translate":"margin"};var i=function(){var e=[];function t(){var n=e.shift();n&&n(t)}return function(n){e.push(n),1==e.length&&t()}}(),l=function(){var e=["Webkit","O","Moz","ms"],t={};function n(e){return e.replace(/^-ms-/,"ms-").replace(/-([\da-z])/gi,(function(e,t){return t.toUpperCase()}))}function r(t){var n=document.body.style;if(t in n)return t;for(var r,o=e.length,s=t.charAt(0).toUpperCase()+t.slice(1);o--;)if((r=e[o]+s)in n)return r;return t}function o(e){return e=n(e),t[e]||(t[e]=r(e))}function s(e,t,n){t=o(t),e.style[t]=n}return function(e,t){var n,r,o=arguments;if(2==o.length)for(n in t)void 0!==(r=t[n])&&t.hasOwnProperty(n)&&s(e,n,r);else s(e,o[1],o[2])}}();function c(e,t){return("string"==typeof e?e:p(e)).indexOf(" "+t+" ")>=0}function u(e,t){var n=p(e),r=n+t;c(n,t)||(e.className=r.substring(1))}function d(e,t){var n,r=p(e);c(e,t)&&(n=r.replace(" "+t+" "," "),e.className=n.substring(1,n.length-1))}function p(e){return(" "+(e.className||"")+" ").replace(/\s+/gi," ")}function f(e){e&&e.parentNode&&e.parentNode.removeChild(e)}return n},void 0===(o="function"==typeof r?r.call(t,n,t,e):r)||(e.exports=o)},5302:(e,t,n)=>{var r=n(4634);e.exports=g,e.exports.parse=s,e.exports.compile=function(e,t){return l(s(e,t),t)},e.exports.tokensToFunction=l,e.exports.tokensToRegExp=f;var o=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g");function s(e,t){for(var n,r=[],s=0,i=0,l="",c=t&&t.delimiter||"/";null!=(n=o.exec(e));){var d=n[0],p=n[1],f=n.index;if(l+=e.slice(i,f),i=f+d.length,p)l+=p[1];else{var g=e[i],m=n[2],h=n[3],b=n[4],v=n[5],y=n[6],w=n[7];l&&(r.push(l),l="");var k=null!=m&&null!=g&&g!==m,x="+"===y||"*"===y,j="?"===y||"*"===y,_=m||c,S=b||v,E=m||("string"==typeof r[r.length-1]?r[r.length-1]:"");r.push({name:h||s++,prefix:m||"",delimiter:_,optional:j,repeat:x,partial:k,asterisk:!!w,pattern:S?u(S):w?".*":a(_,E)})}}return i-1?"[^"+c(e)+"]+?":c(t)+"|(?:(?!"+c(t)+")[^"+c(e)+"])+?"}function i(e){return encodeURI(e).replace(/[\/?#]/g,(function(e){return"%"+e.charCodeAt(0).toString(16).toUpperCase()}))}function l(e,t){for(var n=new Array(e.length),o=0;o{e.exports&&(e.exports={core:{meta:{path:"components/prism-core.js",option:"mandatory"},core:"Core"},themes:{meta:{path:"themes/{id}.css",link:"index.html?theme={id}",exclusive:!0},prism:{title:"Default",option:"default"},"prism-dark":"Dark","prism-funky":"Funky","prism-okaidia":{title:"Okaidia",owner:"ocodia"},"prism-twilight":{title:"Twilight",owner:"remybach"},"prism-coy":{title:"Coy",owner:"tshedor"},"prism-solarizedlight":{title:"Solarized Light",owner:"hectormatos2011 "},"prism-tomorrow":{title:"Tomorrow Night",owner:"Rosey"}},languages:{meta:{path:"components/prism-{id}",noCSS:!0,examplesPath:"examples/prism-{id}",addCheckAll:!0},markup:{title:"Markup",alias:["html","xml","svg","mathml","ssml","atom","rss"],aliasTitles:{html:"HTML",xml:"XML",svg:"SVG",mathml:"MathML",ssml:"SSML",atom:"Atom",rss:"RSS"},option:"default"},css:{title:"CSS",option:"default",modify:"markup"},clike:{title:"C-like",option:"default"},javascript:{title:"JavaScript",require:"clike",modify:"markup",optional:"regex",alias:"js",option:"default"},abap:{title:"ABAP",owner:"dellagustin"},abnf:{title:"ABNF",owner:"RunDevelopment"},actionscript:{title:"ActionScript",require:"javascript",modify:"markup",owner:"Golmote"},ada:{title:"Ada",owner:"Lucretia"},agda:{title:"Agda",owner:"xy-ren"},al:{title:"AL",owner:"RunDevelopment"},antlr4:{title:"ANTLR4",alias:"g4",owner:"RunDevelopment"},apacheconf:{title:"Apache Configuration",owner:"GuiTeK"},apex:{title:"Apex",require:["clike","sql"],owner:"RunDevelopment"},apl:{title:"APL",owner:"ngn"},applescript:{title:"AppleScript",owner:"Golmote"},aql:{title:"AQL",owner:"RunDevelopment"},arduino:{title:"Arduino",require:"cpp",alias:"ino",owner:"dkern"},arff:{title:"ARFF",owner:"Golmote"},armasm:{title:"ARM Assembly",alias:"arm-asm",owner:"RunDevelopment"},arturo:{title:"Arturo",alias:"art",optional:["bash","css","javascript","markup","markdown","sql"],owner:"drkameleon"},asciidoc:{alias:"adoc",title:"AsciiDoc",owner:"Golmote"},aspnet:{title:"ASP.NET (C#)",require:["markup","csharp"],owner:"nauzilus"},asm6502:{title:"6502 Assembly",owner:"kzurawel"},asmatmel:{title:"Atmel AVR Assembly",owner:"cerkit"},autohotkey:{title:"AutoHotkey",owner:"aviaryan"},autoit:{title:"AutoIt",owner:"Golmote"},avisynth:{title:"AviSynth",alias:"avs",owner:"Zinfidel"},"avro-idl":{title:"Avro IDL",alias:"avdl",owner:"RunDevelopment"},awk:{title:"AWK",alias:"gawk",aliasTitles:{gawk:"GAWK"},owner:"RunDevelopment"},bash:{title:"Bash",alias:["sh","shell"],aliasTitles:{sh:"Shell",shell:"Shell"},owner:"zeitgeist87"},basic:{title:"BASIC",owner:"Golmote"},batch:{title:"Batch",owner:"Golmote"},bbcode:{title:"BBcode",alias:"shortcode",aliasTitles:{shortcode:"Shortcode"},owner:"RunDevelopment"},bbj:{title:"BBj",owner:"hyyan"},bicep:{title:"Bicep",owner:"johnnyreilly"},birb:{title:"Birb",require:"clike",owner:"Calamity210"},bison:{title:"Bison",require:"c",owner:"Golmote"},bnf:{title:"BNF",alias:"rbnf",aliasTitles:{rbnf:"RBNF"},owner:"RunDevelopment"},bqn:{title:"BQN",owner:"yewscion"},brainfuck:{title:"Brainfuck",owner:"Golmote"},brightscript:{title:"BrightScript",owner:"RunDevelopment"},bro:{title:"Bro",owner:"wayward710"},bsl:{title:"BSL (1C:Enterprise)",alias:"oscript",aliasTitles:{oscript:"OneScript"},owner:"Diversus23"},c:{title:"C",require:"clike",owner:"zeitgeist87"},csharp:{title:"C#",require:"clike",alias:["cs","dotnet"],owner:"mvalipour"},cpp:{title:"C++",require:"c",owner:"zeitgeist87"},cfscript:{title:"CFScript",require:"clike",alias:"cfc",owner:"mjclemente"},chaiscript:{title:"ChaiScript",require:["clike","cpp"],owner:"RunDevelopment"},cil:{title:"CIL",owner:"sbrl"},cilkc:{title:"Cilk/C",require:"c",alias:"cilk-c",owner:"OpenCilk"},cilkcpp:{title:"Cilk/C++",require:"cpp",alias:["cilk-cpp","cilk"],owner:"OpenCilk"},clojure:{title:"Clojure",owner:"troglotit"},cmake:{title:"CMake",owner:"mjrogozinski"},cobol:{title:"COBOL",owner:"RunDevelopment"},coffeescript:{title:"CoffeeScript",require:"javascript",alias:"coffee",owner:"R-osey"},concurnas:{title:"Concurnas",alias:"conc",owner:"jasontatton"},csp:{title:"Content-Security-Policy",owner:"ScottHelme"},cooklang:{title:"Cooklang",owner:"ahue"},coq:{title:"Coq",owner:"RunDevelopment"},crystal:{title:"Crystal",require:"ruby",owner:"MakeNowJust"},"css-extras":{title:"CSS Extras",require:"css",modify:"css",owner:"milesj"},csv:{title:"CSV",owner:"RunDevelopment"},cue:{title:"CUE",owner:"RunDevelopment"},cypher:{title:"Cypher",owner:"RunDevelopment"},d:{title:"D",require:"clike",owner:"Golmote"},dart:{title:"Dart",require:"clike",owner:"Golmote"},dataweave:{title:"DataWeave",owner:"machaval"},dax:{title:"DAX",owner:"peterbud"},dhall:{title:"Dhall",owner:"RunDevelopment"},diff:{title:"Diff",owner:"uranusjr"},django:{title:"Django/Jinja2",require:"markup-templating",alias:"jinja2",owner:"romanvm"},"dns-zone-file":{title:"DNS zone file",owner:"RunDevelopment",alias:"dns-zone"},docker:{title:"Docker",alias:"dockerfile",owner:"JustinBeckwith"},dot:{title:"DOT (Graphviz)",alias:"gv",optional:"markup",owner:"RunDevelopment"},ebnf:{title:"EBNF",owner:"RunDevelopment"},editorconfig:{title:"EditorConfig",owner:"osipxd"},eiffel:{title:"Eiffel",owner:"Conaclos"},ejs:{title:"EJS",require:["javascript","markup-templating"],owner:"RunDevelopment",alias:"eta",aliasTitles:{eta:"Eta"}},elixir:{title:"Elixir",owner:"Golmote"},elm:{title:"Elm",owner:"zwilias"},etlua:{title:"Embedded Lua templating",require:["lua","markup-templating"],owner:"RunDevelopment"},erb:{title:"ERB",require:["ruby","markup-templating"],owner:"Golmote"},erlang:{title:"Erlang",owner:"Golmote"},"excel-formula":{title:"Excel Formula",alias:["xlsx","xls"],owner:"RunDevelopment"},fsharp:{title:"F#",require:"clike",owner:"simonreynolds7"},factor:{title:"Factor",owner:"catb0t"},false:{title:"False",owner:"edukisto"},"firestore-security-rules":{title:"Firestore security rules",require:"clike",owner:"RunDevelopment"},flow:{title:"Flow",require:"javascript",owner:"Golmote"},fortran:{title:"Fortran",owner:"Golmote"},ftl:{title:"FreeMarker Template Language",require:"markup-templating",owner:"RunDevelopment"},gml:{title:"GameMaker Language",alias:"gamemakerlanguage",require:"clike",owner:"LiarOnce"},gap:{title:"GAP (CAS)",owner:"RunDevelopment"},gcode:{title:"G-code",owner:"RunDevelopment"},gdscript:{title:"GDScript",owner:"RunDevelopment"},gedcom:{title:"GEDCOM",owner:"Golmote"},gettext:{title:"gettext",alias:"po",owner:"RunDevelopment"},gherkin:{title:"Gherkin",owner:"hason"},git:{title:"Git",owner:"lgiraudel"},glsl:{title:"GLSL",require:"c",owner:"Golmote"},gn:{title:"GN",alias:"gni",owner:"RunDevelopment"},"linker-script":{title:"GNU Linker Script",alias:"ld",owner:"RunDevelopment"},go:{title:"Go",require:"clike",owner:"arnehormann"},"go-module":{title:"Go module",alias:"go-mod",owner:"RunDevelopment"},gradle:{title:"Gradle",require:"clike",owner:"zeabdelkhalek-badido18"},graphql:{title:"GraphQL",optional:"markdown",owner:"Golmote"},groovy:{title:"Groovy",require:"clike",owner:"robfletcher"},haml:{title:"Haml",require:"ruby",optional:["css","css-extras","coffeescript","erb","javascript","less","markdown","scss","textile"],owner:"Golmote"},handlebars:{title:"Handlebars",require:"markup-templating",alias:["hbs","mustache"],aliasTitles:{mustache:"Mustache"},owner:"Golmote"},haskell:{title:"Haskell",alias:"hs",owner:"bholst"},haxe:{title:"Haxe",require:"clike",optional:"regex",owner:"Golmote"},hcl:{title:"HCL",owner:"outsideris"},hlsl:{title:"HLSL",require:"c",owner:"RunDevelopment"},hoon:{title:"Hoon",owner:"matildepark"},http:{title:"HTTP",optional:["csp","css","hpkp","hsts","javascript","json","markup","uri"],owner:"danielgtaylor"},hpkp:{title:"HTTP Public-Key-Pins",owner:"ScottHelme"},hsts:{title:"HTTP Strict-Transport-Security",owner:"ScottHelme"},ichigojam:{title:"IchigoJam",owner:"BlueCocoa"},icon:{title:"Icon",owner:"Golmote"},"icu-message-format":{title:"ICU Message Format",owner:"RunDevelopment"},idris:{title:"Idris",alias:"idr",owner:"KeenS",require:"haskell"},ignore:{title:".ignore",owner:"osipxd",alias:["gitignore","hgignore","npmignore"],aliasTitles:{gitignore:".gitignore",hgignore:".hgignore",npmignore:".npmignore"}},inform7:{title:"Inform 7",owner:"Golmote"},ini:{title:"Ini",owner:"aviaryan"},io:{title:"Io",owner:"AlesTsurko"},j:{title:"J",owner:"Golmote"},java:{title:"Java",require:"clike",owner:"sherblot"},javadoc:{title:"JavaDoc",require:["markup","java","javadoclike"],modify:"java",optional:"scala",owner:"RunDevelopment"},javadoclike:{title:"JavaDoc-like",modify:["java","javascript","php"],owner:"RunDevelopment"},javastacktrace:{title:"Java stack trace",owner:"RunDevelopment"},jexl:{title:"Jexl",owner:"czosel"},jolie:{title:"Jolie",require:"clike",owner:"thesave"},jq:{title:"JQ",owner:"RunDevelopment"},jsdoc:{title:"JSDoc",require:["javascript","javadoclike","typescript"],modify:"javascript",optional:["actionscript","coffeescript"],owner:"RunDevelopment"},"js-extras":{title:"JS Extras",require:"javascript",modify:"javascript",optional:["actionscript","coffeescript","flow","n4js","typescript"],owner:"RunDevelopment"},json:{title:"JSON",alias:"webmanifest",aliasTitles:{webmanifest:"Web App Manifest"},owner:"CupOfTea696"},json5:{title:"JSON5",require:"json",owner:"RunDevelopment"},jsonp:{title:"JSONP",require:"json",owner:"RunDevelopment"},jsstacktrace:{title:"JS stack trace",owner:"sbrl"},"js-templates":{title:"JS Templates",require:"javascript",modify:"javascript",optional:["css","css-extras","graphql","markdown","markup","sql"],owner:"RunDevelopment"},julia:{title:"Julia",owner:"cdagnino"},keepalived:{title:"Keepalived Configure",owner:"dev-itsheng"},keyman:{title:"Keyman",owner:"mcdurdin"},kotlin:{title:"Kotlin",alias:["kt","kts"],aliasTitles:{kts:"Kotlin Script"},require:"clike",owner:"Golmote"},kumir:{title:"KuMir (\u041a\u0443\u041c\u0438\u0440)",alias:"kum",owner:"edukisto"},kusto:{title:"Kusto",owner:"RunDevelopment"},latex:{title:"LaTeX",alias:["tex","context"],aliasTitles:{tex:"TeX",context:"ConTeXt"},owner:"japborst"},latte:{title:"Latte",require:["clike","markup-templating","php"],owner:"nette"},less:{title:"Less",require:"css",optional:"css-extras",owner:"Golmote"},lilypond:{title:"LilyPond",require:"scheme",alias:"ly",owner:"RunDevelopment"},liquid:{title:"Liquid",require:"markup-templating",owner:"cinhtau"},lisp:{title:"Lisp",alias:["emacs","elisp","emacs-lisp"],owner:"JuanCaicedo"},livescript:{title:"LiveScript",owner:"Golmote"},llvm:{title:"LLVM IR",owner:"porglezomp"},log:{title:"Log file",optional:"javastacktrace",owner:"RunDevelopment"},lolcode:{title:"LOLCODE",owner:"Golmote"},lua:{title:"Lua",owner:"Golmote"},magma:{title:"Magma (CAS)",owner:"RunDevelopment"},makefile:{title:"Makefile",owner:"Golmote"},markdown:{title:"Markdown",require:"markup",optional:"yaml",alias:"md",owner:"Golmote"},"markup-templating":{title:"Markup templating",require:"markup",owner:"Golmote"},mata:{title:"Mata",owner:"RunDevelopment"},matlab:{title:"MATLAB",owner:"Golmote"},maxscript:{title:"MAXScript",owner:"RunDevelopment"},mel:{title:"MEL",owner:"Golmote"},mermaid:{title:"Mermaid",owner:"RunDevelopment"},metafont:{title:"METAFONT",owner:"LaeriExNihilo"},mizar:{title:"Mizar",owner:"Golmote"},mongodb:{title:"MongoDB",owner:"airs0urce",require:"javascript"},monkey:{title:"Monkey",owner:"Golmote"},moonscript:{title:"MoonScript",alias:"moon",owner:"RunDevelopment"},n1ql:{title:"N1QL",owner:"TMWilds"},n4js:{title:"N4JS",require:"javascript",optional:"jsdoc",alias:"n4jsd",owner:"bsmith-n4"},"nand2tetris-hdl":{title:"Nand To Tetris HDL",owner:"stephanmax"},naniscript:{title:"Naninovel Script",owner:"Elringus",alias:"nani"},nasm:{title:"NASM",owner:"rbmj"},neon:{title:"NEON",owner:"nette"},nevod:{title:"Nevod",owner:"nezaboodka"},nginx:{title:"nginx",owner:"volado"},nim:{title:"Nim",owner:"Golmote"},nix:{title:"Nix",owner:"Golmote"},nsis:{title:"NSIS",owner:"idleberg"},objectivec:{title:"Objective-C",require:"c",alias:"objc",owner:"uranusjr"},ocaml:{title:"OCaml",owner:"Golmote"},odin:{title:"Odin",owner:"edukisto"},opencl:{title:"OpenCL",require:"c",modify:["c","cpp"],owner:"Milania1"},openqasm:{title:"OpenQasm",alias:"qasm",owner:"RunDevelopment"},oz:{title:"Oz",owner:"Golmote"},parigp:{title:"PARI/GP",owner:"Golmote"},parser:{title:"Parser",require:"markup",owner:"Golmote"},pascal:{title:"Pascal",alias:"objectpascal",aliasTitles:{objectpascal:"Object Pascal"},owner:"Golmote"},pascaligo:{title:"Pascaligo",owner:"DefinitelyNotAGoat"},psl:{title:"PATROL Scripting Language",owner:"bertysentry"},pcaxis:{title:"PC-Axis",alias:"px",owner:"RunDevelopment"},peoplecode:{title:"PeopleCode",alias:"pcode",owner:"RunDevelopment"},perl:{title:"Perl",owner:"Golmote"},php:{title:"PHP",require:"markup-templating",owner:"milesj"},phpdoc:{title:"PHPDoc",require:["php","javadoclike"],modify:"php",owner:"RunDevelopment"},"php-extras":{title:"PHP Extras",require:"php",modify:"php",owner:"milesj"},"plant-uml":{title:"PlantUML",alias:"plantuml",owner:"RunDevelopment"},plsql:{title:"PL/SQL",require:"sql",owner:"Golmote"},powerquery:{title:"PowerQuery",alias:["pq","mscript"],owner:"peterbud"},powershell:{title:"PowerShell",owner:"nauzilus"},processing:{title:"Processing",require:"clike",owner:"Golmote"},prolog:{title:"Prolog",owner:"Golmote"},promql:{title:"PromQL",owner:"arendjr"},properties:{title:".properties",owner:"Golmote"},protobuf:{title:"Protocol Buffers",require:"clike",owner:"just-boris"},pug:{title:"Pug",require:["markup","javascript"],optional:["coffeescript","ejs","handlebars","less","livescript","markdown","scss","stylus","twig"],owner:"Golmote"},puppet:{title:"Puppet",owner:"Golmote"},pure:{title:"Pure",optional:["c","cpp","fortran"],owner:"Golmote"},purebasic:{title:"PureBasic",require:"clike",alias:"pbfasm",owner:"HeX0R101"},purescript:{title:"PureScript",require:"haskell",alias:"purs",owner:"sriharshachilakapati"},python:{title:"Python",alias:"py",owner:"multipetros"},qsharp:{title:"Q#",require:"clike",alias:"qs",owner:"fedonman"},q:{title:"Q (kdb+ database)",owner:"Golmote"},qml:{title:"QML",require:"javascript",owner:"RunDevelopment"},qore:{title:"Qore",require:"clike",owner:"temnroegg"},r:{title:"R",owner:"Golmote"},racket:{title:"Racket",require:"scheme",alias:"rkt",owner:"RunDevelopment"},cshtml:{title:"Razor C#",alias:"razor",require:["markup","csharp"],optional:["css","css-extras","javascript","js-extras"],owner:"RunDevelopment"},jsx:{title:"React JSX",require:["markup","javascript"],optional:["jsdoc","js-extras","js-templates"],owner:"vkbansal"},tsx:{title:"React TSX",require:["jsx","typescript"]},reason:{title:"Reason",require:"clike",owner:"Golmote"},regex:{title:"Regex",owner:"RunDevelopment"},rego:{title:"Rego",owner:"JordanSh"},renpy:{title:"Ren'py",alias:"rpy",owner:"HyuchiaDiego"},rescript:{title:"ReScript",alias:"res",owner:"vmarcosp"},rest:{title:"reST (reStructuredText)",owner:"Golmote"},rip:{title:"Rip",owner:"ravinggenius"},roboconf:{title:"Roboconf",owner:"Golmote"},robotframework:{title:"Robot Framework",alias:"robot",owner:"RunDevelopment"},ruby:{title:"Ruby",require:"clike",alias:"rb",owner:"samflores"},rust:{title:"Rust",owner:"Golmote"},sas:{title:"SAS",optional:["groovy","lua","sql"],owner:"Golmote"},sass:{title:"Sass (Sass)",require:"css",optional:"css-extras",owner:"Golmote"},scss:{title:"Sass (SCSS)",require:"css",optional:"css-extras",owner:"MoOx"},scala:{title:"Scala",require:"java",owner:"jozic"},scheme:{title:"Scheme",owner:"bacchus123"},"shell-session":{title:"Shell session",require:"bash",alias:["sh-session","shellsession"],owner:"RunDevelopment"},smali:{title:"Smali",owner:"RunDevelopment"},smalltalk:{title:"Smalltalk",owner:"Golmote"},smarty:{title:"Smarty",require:"markup-templating",optional:"php",owner:"Golmote"},sml:{title:"SML",alias:"smlnj",aliasTitles:{smlnj:"SML/NJ"},owner:"RunDevelopment"},solidity:{title:"Solidity (Ethereum)",alias:"sol",require:"clike",owner:"glachaud"},"solution-file":{title:"Solution file",alias:"sln",owner:"RunDevelopment"},soy:{title:"Soy (Closure Template)",require:"markup-templating",owner:"Golmote"},sparql:{title:"SPARQL",require:"turtle",owner:"Triply-Dev",alias:"rq"},"splunk-spl":{title:"Splunk SPL",owner:"RunDevelopment"},sqf:{title:"SQF: Status Quo Function (Arma 3)",require:"clike",owner:"RunDevelopment"},sql:{title:"SQL",owner:"multipetros"},squirrel:{title:"Squirrel",require:"clike",owner:"RunDevelopment"},stan:{title:"Stan",owner:"RunDevelopment"},stata:{title:"Stata Ado",require:["mata","java","python"],owner:"RunDevelopment"},iecst:{title:"Structured Text (IEC 61131-3)",owner:"serhioromano"},stylus:{title:"Stylus",owner:"vkbansal"},supercollider:{title:"SuperCollider",alias:"sclang",owner:"RunDevelopment"},swift:{title:"Swift",owner:"chrischares"},systemd:{title:"Systemd configuration file",owner:"RunDevelopment"},"t4-templating":{title:"T4 templating",owner:"RunDevelopment"},"t4-cs":{title:"T4 Text Templates (C#)",require:["t4-templating","csharp"],alias:"t4",owner:"RunDevelopment"},"t4-vb":{title:"T4 Text Templates (VB)",require:["t4-templating","vbnet"],owner:"RunDevelopment"},tap:{title:"TAP",owner:"isaacs",require:"yaml"},tcl:{title:"Tcl",owner:"PeterChaplin"},tt2:{title:"Template Toolkit 2",require:["clike","markup-templating"],owner:"gflohr"},textile:{title:"Textile",require:"markup",optional:"css",owner:"Golmote"},toml:{title:"TOML",owner:"RunDevelopment"},tremor:{title:"Tremor",alias:["trickle","troy"],owner:"darach",aliasTitles:{trickle:"trickle",troy:"troy"}},turtle:{title:"Turtle",alias:"trig",aliasTitles:{trig:"TriG"},owner:"jakubklimek"},twig:{title:"Twig",require:"markup-templating",owner:"brandonkelly"},typescript:{title:"TypeScript",require:"javascript",optional:"js-templates",alias:"ts",owner:"vkbansal"},typoscript:{title:"TypoScript",alias:"tsconfig",aliasTitles:{tsconfig:"TSConfig"},owner:"dkern"},unrealscript:{title:"UnrealScript",alias:["uscript","uc"],owner:"RunDevelopment"},uorazor:{title:"UO Razor Script",owner:"jaseowns"},uri:{title:"URI",alias:"url",aliasTitles:{url:"URL"},owner:"RunDevelopment"},v:{title:"V",require:"clike",owner:"taggon"},vala:{title:"Vala",require:"clike",optional:"regex",owner:"TemplarVolk"},vbnet:{title:"VB.Net",require:"basic",owner:"Bigsby"},velocity:{title:"Velocity",require:"markup",owner:"Golmote"},verilog:{title:"Verilog",owner:"a-rey"},vhdl:{title:"VHDL",owner:"a-rey"},vim:{title:"vim",owner:"westonganger"},"visual-basic":{title:"Visual Basic",alias:["vb","vba"],aliasTitles:{vba:"VBA"},owner:"Golmote"},warpscript:{title:"WarpScript",owner:"RunDevelopment"},wasm:{title:"WebAssembly",owner:"Golmote"},"web-idl":{title:"Web IDL",alias:"webidl",owner:"RunDevelopment"},wgsl:{title:"WGSL",owner:"Dr4gonthree"},wiki:{title:"Wiki markup",require:"markup",owner:"Golmote"},wolfram:{title:"Wolfram language",alias:["mathematica","nb","wl"],aliasTitles:{mathematica:"Mathematica",nb:"Mathematica Notebook"},owner:"msollami"},wren:{title:"Wren",owner:"clsource"},xeora:{title:"Xeora",require:"markup",alias:"xeoracube",aliasTitles:{xeoracube:"XeoraCube"},owner:"freakmaxi"},"xml-doc":{title:"XML doc (.net)",require:"markup",modify:["csharp","fsharp","vbnet"],owner:"RunDevelopment"},xojo:{title:"Xojo (REALbasic)",owner:"Golmote"},xquery:{title:"XQuery",require:"markup",owner:"Golmote"},yaml:{title:"YAML",alias:"yml",owner:"hason"},yang:{title:"YANG",owner:"RunDevelopment"},zig:{title:"Zig",owner:"RunDevelopment"}},plugins:{meta:{path:"plugins/{id}/prism-{id}",link:"plugins/{id}/"},"line-highlight":{title:"Line Highlight",description:"Highlights specific lines and/or line ranges."},"line-numbers":{title:"Line Numbers",description:"Line number at the beginning of code lines.",owner:"kuba-kubula"},"show-invisibles":{title:"Show Invisibles",description:"Show hidden characters such as tabs and line breaks.",optional:["autolinker","data-uri-highlight"]},autolinker:{title:"Autolinker",description:"Converts URLs and emails in code to clickable links. Parses Markdown links in comments."},wpd:{title:"WebPlatform Docs",description:'Makes tokens link to WebPlatform.org documentation. The links open in a new tab.'},"custom-class":{title:"Custom Class",description:"This plugin allows you to prefix Prism's default classes (.comment can become .namespace--comment) or replace them with your defined ones (like .editor__comment). You can even add new classes.",owner:"dvkndn",noCSS:!0},"file-highlight":{title:"File Highlight",description:"Fetch external files and highlight them with Prism. Used on the Prism website itself.",noCSS:!0},"show-language":{title:"Show Language",description:"Display the highlighted language in code blocks (inline code does not show the label).",owner:"nauzilus",noCSS:!0,require:"toolbar"},"jsonp-highlight":{title:"JSONP Highlight",description:"Fetch content with JSONP and highlight some interesting content (e.g. GitHub/Gists or Bitbucket API).",noCSS:!0,owner:"nauzilus"},"highlight-keywords":{title:"Highlight Keywords",description:"Adds special CSS classes for each keyword for fine-grained highlighting.",owner:"vkbansal",noCSS:!0},"remove-initial-line-feed":{title:"Remove initial line feed",description:"Removes the initial line feed in code blocks.",owner:"Golmote",noCSS:!0},"inline-color":{title:"Inline color",description:"Adds a small inline preview for colors in style sheets.",require:"css-extras",owner:"RunDevelopment"},previewers:{title:"Previewers",description:"Previewers for angles, colors, gradients, easing and time.",require:"css-extras",owner:"Golmote"},autoloader:{title:"Autoloader",description:"Automatically loads the needed languages to highlight the code blocks.",owner:"Golmote",noCSS:!0},"keep-markup":{title:"Keep Markup",description:"Prevents custom markup from being dropped out during highlighting.",owner:"Golmote",optional:"normalize-whitespace",noCSS:!0},"command-line":{title:"Command Line",description:"Display a command line with a prompt and, optionally, the output/response from the commands.",owner:"chriswells0"},"unescaped-markup":{title:"Unescaped Markup",description:"Write markup without having to escape anything."},"normalize-whitespace":{title:"Normalize Whitespace",description:"Supports multiple operations to normalize whitespace in code blocks.",owner:"zeitgeist87",optional:"unescaped-markup",noCSS:!0},"data-uri-highlight":{title:"Data-URI Highlight",description:"Highlights data-URI contents.",owner:"Golmote",noCSS:!0},toolbar:{title:"Toolbar",description:"Attach a toolbar for plugins to easily register buttons on the top of a code block.",owner:"mAAdhaTTah"},"copy-to-clipboard":{title:"Copy to Clipboard Button",description:"Add a button that copies the code block to the clipboard when clicked.",owner:"mAAdhaTTah",require:"toolbar",noCSS:!0},"download-button":{title:"Download Button",description:"A button in the toolbar of a code block adding a convenient way to download a code file.",owner:"Golmote",require:"toolbar",noCSS:!0},"match-braces":{title:"Match braces",description:"Highlights matching braces.",owner:"RunDevelopment"},"diff-highlight":{title:"Diff Highlight",description:"Highlights the code inside diff blocks.",owner:"RunDevelopment",require:"diff"},"filter-highlight-all":{title:"Filter highlightAll",description:"Filters the elements the highlightAll and highlightAllUnder methods actually highlight.",owner:"RunDevelopment",noCSS:!0},treeview:{title:"Treeview",description:"A language with special styles to highlight file system tree structures.",owner:"Golmote"}}})},8722:(e,t,n)=>{const r=n(6969),o=n(8380),s=new Set;function a(e){void 0===e?e=Object.keys(r.languages).filter((e=>"meta"!=e)):Array.isArray(e)||(e=[e]);const t=[...s,...Object.keys(Prism.languages)];o(r,e,t).load((e=>{if(!(e in r.languages))return void(a.silent||console.warn("Language does not exist: "+e));const t="./prism-"+e;delete n.c[n(3157).resolve(t)],delete Prism.languages[e],n(3157)(t),s.add(e)}))}a.silent=!1,e.exports=a},9700:()=>{!function(e){function t(e,t){return"___"+e.toUpperCase()+t+"___"}Object.defineProperties(e.languages["markup-templating"]={},{buildPlaceholders:{value:function(n,r,o,s){if(n.language===r){var a=n.tokenStack=[];n.code=n.code.replace(o,(function(e){if("function"==typeof s&&!s(e))return e;for(var o,i=a.length;-1!==n.code.indexOf(o=t(r,i));)++i;return a[i]=e,o})),n.grammar=e.languages.markup}}},tokenizePlaceholders:{value:function(n,r){if(n.language===r&&n.tokenStack){n.grammar=e.languages[r];var o=0,s=Object.keys(n.tokenStack);!function a(i){for(var l=0;l=s.length);l++){var c=i[l];if("string"==typeof c||c.content&&"string"==typeof c.content){var u=s[o],d=n.tokenStack[u],p="string"==typeof c?c:c.content,f=t(r,u),g=p.indexOf(f);if(g>-1){++o;var m=p.substring(0,g),h=new e.Token(r,e.tokenize(d,n.grammar),"language-"+r,d),b=p.substring(g+f.length),v=[];m&&v.push.apply(v,a([m])),v.push(h),b&&v.push.apply(v,a([b])),"string"==typeof c?i.splice.apply(i,[l,1].concat(v)):c.content=v}}else c.content&&a(c.content)}return i}(n.tokens)}}}})}(Prism)},8692:(e,t,n)=>{var r={"./":8722};function o(e){var t=s(e);return n(t)}function s(e){if(!n.o(r,e)){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}return r[e]}o.keys=function(){return Object.keys(r)},o.resolve=s,e.exports=o,o.id=8692},3157:(e,t,n)=>{var r={"./":8722};function o(e){var t=s(e);return n(t)}function s(e){if(!n.o(r,e)){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}return r[e]}o.keys=function(){return Object.keys(r)},o.resolve=s,e.exports=o,o.id=3157},8380:e=>{"use strict";var t=function(){var e=function(){};function t(e,t){Array.isArray(e)?e.forEach(t):null!=e&&t(e,0)}function n(e){for(var t={},n=0,r=e.length;n "));var i={},l=e[r];if(l){function c(t){if(!(t in e))throw new Error(r+" depends on an unknown component "+t);if(!(t in i))for(var a in o(t,s),i[t]=!0,n[t])i[a]=!0}t(l.require,c),t(l.optional,c),t(l.modify,c)}n[r]=i,s.pop()}}return function(e){var t=n[e];return t||(o(e,r),t=n[e]),t}}function o(e){for(var t in e)return!0;return!1}return function(s,a,i){var l=function(e){var t={};for(var n in e){var r=e[n];for(var o in r)if("meta"!=o){var s=r[o];t[o]="string"==typeof s?{title:s}:s}}return t}(s),c=function(e){var n;return function(r){if(r in e)return r;if(!n)for(var o in n={},e){var s=e[o];t(s&&s.alias,(function(t){if(t in n)throw new Error(t+" cannot be alias for both "+o+" and "+n[t]);if(t in e)throw new Error(t+" cannot be alias of "+o+" because it is a component.");n[t]=o}))}return n[r]||r}}(l);a=a.map(c),i=(i||[]).map(c);var u=n(a),d=n(i);a.forEach((function e(n){var r=l[n];t(r&&r.require,(function(t){t in d||(u[t]=!0,e(t))}))}));for(var p,f=r(l),g=u;o(g);){for(var m in p={},g){var h=l[m];t(h&&h.modify,(function(e){e in d&&(p[e]=!0)}))}for(var b in d)if(!(b in u))for(var v in f(b))if(v in u){p[b]=!0;break}for(var y in g=p)u[y]=!0}var w={getIds:function(){var e=[];return w.load((function(t){e.push(t)})),e},load:function(t,n){return function(t,n,r,o){var s=o?o.series:void 0,a=o?o.parallel:e,i={},l={};function c(e){if(e in i)return i[e];l[e]=!0;var o,u=[];for(var d in t(e))d in n&&u.push(d);if(0===u.length)o=r(e);else{var p=a(u.map((function(e){var t=c(e);return delete l[e],t})));s?o=s(p,(function(){return r(e)})):r(e)}return i[e]=o}for(var u in n)c(u);var d=[];for(var p in l)d.push(i[p]);return a(d)}(f,u,t,n)}};return w}}();e.exports=t},2694:(e,t,n)=>{"use strict";var r=n(6925);function o(){}function s(){}s.resetWarningCache=o,e.exports=function(){function e(e,t,n,o,s,a){if(a!==r){var i=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw i.name="Invariant Violation",i}}function t(){return e}e.isRequired=e;var n={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:s,resetWarningCache:o};return n.PropTypes=n,n}},5556:(e,t,n)=>{e.exports=n(2694)()},6925:e=>{"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},2551:(e,t,n)=>{"use strict";var r=n(6540),o=n(9982);function s(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,n=1;n