diff --git a/404.html b/404.html index 8324c883b8..3d900c1d07 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.236d0ad9.js b/assets/js/00e7239c.236d0ad9.js deleted file mode 100644 index cd7f63d38a..0000000000 --- a/assets/js/00e7239c.236d0ad9.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8970],{7074:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>l,default:()=>p,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var n=s(4848),r=s(8453),a=s(9489),o=s(7227);const i={title:"AST transformers option"},l=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/astTransformers.md",tags:[],version:"current",lastUpdatedBy:"renovate[bot]",lastUpdatedAt:1726058855e3,frontMatter:{title:"AST transformers option"}},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,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:[(0,n.jsx)(t.code,{children:"ts-jest"})," by default does hoisting for a few ",(0,n.jsx)(t.code,{children:"jest"})," methods via a TypeScript AST transformer. One can also create custom\nTypeScript AST transformers and provide them to ",(0,n.jsx)(t.code,{children:"ts-jest"})," to include into compilation process."]}),"\n",(0,n.jsxs)(t.p,{children:["The option is ",(0,n.jsx)(t.code,{children:"astTransformers"})," and it allows ones to specify which 3 types of TypeScript AST transformers to use with ",(0,n.jsx)(t.code,{children:"ts-jest"}),":"]}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.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,n.jsx)(t.code,{children:"import"})," instead of ",(0,n.jsx)(t.code,{children:"require"})," or ",(0,n.jsx)(t.code,{children:"define"})," )."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"after"})," means your transformers get run after TS ones, which gets transpiled syntax."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"afterDeclarations"})," means your transformers get run during ",(0,n.jsx)(t.code,{children:"d.ts"})," generation phase, allowing you to transform output type declarations."]}),"\n"]}),"\n",(0,n.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsx)(t.h4,{id:"basic-transformers",children:"Basic Transformers"}),"\n",(0,n.jsxs)(a.A,{groupId:"code-examples",children:[(0,n.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.h4,{id:"configuring-transformers-with-options",children:"Configuring transformers with options"}),"\n",(0,n.jsxs)(a.A,{groupId:"code-examples",children:[(0,n.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.h3,{id:"writing-custom-typescript-ast-transformers",children:"Writing custom TypeScript AST transformers"}),"\n",(0,n.jsxs)(t.p,{children:["To write a custom TypeScript AST transformers, one can take a look at ",(0,n.jsx)(t.a,{href:"https://github.com/kulshekhar/ts-jest/tree/main/src/transformers",children:"the one"})," that ",(0,n.jsx)(t.code,{children:"ts-jest"})," is using."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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/00e7239c.4486d478.js b/assets/js/00e7239c.4486d478.js new file mode 100644 index 0000000000..06e67d57bb --- /dev/null +++ b/assets/js/00e7239c.4486d478.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8970],{7074:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>l,default:()=>p,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var n=s(4848),r=s(8453),a=s(9489),o=s(7227);const i={title:"AST transformers option"},l=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/astTransformers.md",tags:[],version:"current",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"AST transformers option"}},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,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:[(0,n.jsx)(t.code,{children:"ts-jest"})," by default does hoisting for a few ",(0,n.jsx)(t.code,{children:"jest"})," methods via a TypeScript AST transformer. One can also create custom\nTypeScript AST transformers and provide them to ",(0,n.jsx)(t.code,{children:"ts-jest"})," to include into compilation process."]}),"\n",(0,n.jsxs)(t.p,{children:["The option is ",(0,n.jsx)(t.code,{children:"astTransformers"})," and it allows ones to specify which 3 types of TypeScript AST transformers to use with ",(0,n.jsx)(t.code,{children:"ts-jest"}),":"]}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.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,n.jsx)(t.code,{children:"import"})," instead of ",(0,n.jsx)(t.code,{children:"require"})," or ",(0,n.jsx)(t.code,{children:"define"})," )."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"after"})," means your transformers get run after TS ones, which gets transpiled syntax."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"afterDeclarations"})," means your transformers get run during ",(0,n.jsx)(t.code,{children:"d.ts"})," generation phase, allowing you to transform output type declarations."]}),"\n"]}),"\n",(0,n.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsx)(t.h4,{id:"basic-transformers",children:"Basic Transformers"}),"\n",(0,n.jsxs)(a.A,{groupId:"code-examples",children:[(0,n.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.h4,{id:"configuring-transformers-with-options",children:"Configuring transformers with options"}),"\n",(0,n.jsxs)(a.A,{groupId:"code-examples",children:[(0,n.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.h3,{id:"writing-custom-typescript-ast-transformers",children:"Writing custom TypeScript AST transformers"}),"\n",(0,n.jsxs)(t.p,{children:["To write a custom TypeScript AST transformers, one can take a look at ",(0,n.jsx)(t.a,{href:"https://github.com/kulshekhar/ts-jest/tree/main/src/transformers",children:"the one"})," that ",(0,n.jsx)(t.code,{children:"ts-jest"})," is using."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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.384b6fd1.js b/assets/js/0259e2f2.384b6fd1.js new file mode 100644 index 0000000000..3e39dc83dd --- /dev/null +++ b/assets/js/0259e2f2.384b6fd1.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[378],{278:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>a,default:()=>m,frontMatter:()=>o,metadata:()=>i,toc:()=>d});var t=n(4848),r=n(8453);const o={title:"AST transformers option"},a=void 0,i={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"AST transformers option"}},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,r.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:"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 m(e={}){const{wrapper:s}={...(0,r.R)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.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/0259e2f2.54f0908c.js b/assets/js/0259e2f2.54f0908c.js deleted file mode 100644 index 3a7698b661..0000000000 --- a/assets/js/0259e2f2.54f0908c.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[378],{278:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>a,default:()=>m,frontMatter:()=>o,metadata:()=>i,toc:()=>d});var t=n(4848),r=n(8453);const o={title:"AST transformers option"},a=void 0,i={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"AST transformers option"}},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,r.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:"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 m(e={}){const{wrapper:s}={...(0,r.R)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.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.164e8dfa.js b/assets/js/03be7dae.164e8dfa.js new file mode 100644 index 0000000000..75eacac827 --- /dev/null +++ b/assets/js/03be7dae.164e8dfa.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4768],{6262:(t,e,o)=>{o.r(e),o.d(e,{assets:()=>c,contentTitle:()=>r,default:()=>a,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var s=o(4848),n=o(8453);const i={id:"troubleshooting",title:"Troubleshooting"},r=void 0,u={id:"guides/troubleshooting",title:"Troubleshooting",description:"You can check Jest troubleshooting guide or visit ts-jest [troubleshooting",source:"@site/docs/guides/troubleshooting.md",sourceDirName:"guides",slug:"/guides/troubleshooting",permalink:"/ts-jest/docs/next/guides/troubleshooting",draft:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/guides/troubleshooting.md",tags:[],version:"current",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},c={},d=[];function l(t){const e={a:"a",code:"code",p:"p",...(0,n.R)(),...t.components};return(0,s.jsxs)(e.p,{children:["You can check Jest ",(0,s.jsx)(e.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," or visit ",(0,s.jsx)(e.code,{children:"ts-jest"})," ",(0,s.jsx)(e.a,{href:"https://github.com/kulshekhar/ts-jest/blob/main/TROUBLESHOOTING.md",children:"troubleshooting\nguide"})]})}function a(t={}){const{wrapper:e}={...(0,n.R)(),...t.components};return e?(0,s.jsx)(e,{...t,children:(0,s.jsx)(l,{...t})}):l(t)}},8453:(t,e,o)=>{o.d(e,{R:()=>r,x:()=>u});var s=o(6540);const n={},i=s.createContext(n);function r(t){const e=s.useContext(i);return s.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function u(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(n):t.components||n:r(t.components),s.createElement(i.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/03be7dae.2d4a2848.js b/assets/js/03be7dae.2d4a2848.js deleted file mode 100644 index adfced62e7..0000000000 --- a/assets/js/03be7dae.2d4a2848.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4768],{6262:(t,e,o)=>{o.r(e),o.d(e,{assets:()=>c,contentTitle:()=>r,default:()=>a,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var s=o(4848),n=o(8453);const i={id:"troubleshooting",title:"Troubleshooting"},r=void 0,u={id:"guides/troubleshooting",title:"Troubleshooting",description:"You can check Jest troubleshooting guide or visit ts-jest [troubleshooting",source:"@site/docs/guides/troubleshooting.md",sourceDirName:"guides",slug:"/guides/troubleshooting",permalink:"/ts-jest/docs/next/guides/troubleshooting",draft:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/guides/troubleshooting.md",tags:[],version:"current",lastUpdatedBy:"renovate[bot]",lastUpdatedAt:1726058855e3,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"}},c={},d=[];function l(t){const e={a:"a",code:"code",p:"p",...(0,n.R)(),...t.components};return(0,s.jsxs)(e.p,{children:["You can check Jest ",(0,s.jsx)(e.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," or visit ",(0,s.jsx)(e.code,{children:"ts-jest"})," ",(0,s.jsx)(e.a,{href:"https://github.com/kulshekhar/ts-jest/blob/main/TROUBLESHOOTING.md",children:"troubleshooting\nguide"})]})}function a(t={}){const{wrapper:e}={...(0,n.R)(),...t.components};return e?(0,s.jsx)(e,{...t,children:(0,s.jsx)(l,{...t})}):l(t)}},8453:(t,e,o)=>{o.d(e,{R:()=>r,x:()=>u});var s=o(6540);const n={},i=s.createContext(n);function r(t){const e=s.useContext(i);return s.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function u(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(n):t.components||n:r(t.components),s.createElement(i.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/057d33b8.11edeb56.js b/assets/js/057d33b8.11edeb56.js deleted file mode 100644 index f824be3c18..0000000000 --- a/assets/js/057d33b8.11edeb56.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8683],{5698:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>a,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>l});var t=n(4848),o=n(8453);const r={id:"mock-es6-class",title:"Mock ES6 class"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},a={},l=[];function d(e){const s={code:"code",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(s.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,t.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,t.jsx)(s.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.p,{children:"You will get the error"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,t.jsxs)(s.p,{children:["because ",(0,t.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,t.jsx)(s.pre,{children:(0,t.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,t.jsxs)(s.p,{children:["For named imports, like ",(0,t.jsx)(s.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,t.jsx)(s.code,{children:"default"})," with imported module name, ",(0,t.jsx)(s.code,{children:"OAuth2"})," in this example:"]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,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:()=>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/057d33b8.1f177264.js b/assets/js/057d33b8.1f177264.js new file mode 100644 index 0000000000..6d4443d445 --- /dev/null +++ b/assets/js/057d33b8.1f177264.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8683],{5698:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>a,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>d});var t=n(4848),o=n(8453);const r={id:"mock-es6-class",title:"Mock ES6 class"},i=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},a={},d=[];function l(e){const s={code:"code",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(s.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,t.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,t.jsx)(s.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.p,{children:"You will get the error"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,t.jsxs)(s.p,{children:["because ",(0,t.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,t.jsx)(s.pre,{children:(0,t.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,t.jsxs)(s.p,{children:["For named imports, like ",(0,t.jsx)(s.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,t.jsx)(s.code,{children:"default"})," with imported module name, ",(0,t.jsx)(s.code,{children:"OAuth2"})," in this example:"]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,o.R)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.jsx)(l,{...e})}):l(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.a4e69be2.js b/assets/js/06fbaa8e.a4e69be2.js deleted file mode 100644 index df71d95ce9..0000000000 --- a/assets/js/06fbaa8e.a4e69be2.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[942],{5429:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>l,frontMatter:()=>i,metadata:()=>c,toc:()=>g});var s=n(4848),o=n(8453);const i={id:"debugging",title:"Debugging ts-jest"},r=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},d={},g=[];function u(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,o.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.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"set TS_JEST_LOG=ts-jest.log\n"})})]})}function l(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(u,{...e})}):u(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/06fbaa8e.f8b2109a.js b/assets/js/06fbaa8e.f8b2109a.js new file mode 100644 index 0000000000..614c74af1e --- /dev/null +++ b/assets/js/06fbaa8e.f8b2109a.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[942],{5429:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>l,frontMatter:()=>i,metadata:()=>c,toc:()=>g});var s=n(4848),o=n(8453);const i={id:"debugging",title:"Debugging ts-jest"},r=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/debugging.md",tags:[],version:"27.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},g=[];function u(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,o.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.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"set TS_JEST_LOG=ts-jest.log\n"})})]})}function l(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(u,{...e})}):u(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.26808025.js b/assets/js/07a7640f.26808025.js deleted file mode 100644 index 368563319b..0000000000 --- a/assets/js/07a7640f.26808025.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7796],{5657:(t,e,o)=>{o.r(e),o.d(e,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var s=o(4848),n=o(8453);const i={id:"troubleshooting",title:"Troubleshooting"},r=void 0,u={id:"guides/troubleshooting",title:"Troubleshooting",description:"You can check Jest troubleshooting guide or visit ts-jest [troubleshooting",source:"@site/versioned_docs/version-27.0/guides/troubleshooting.md",sourceDirName:"guides",slug:"/guides/troubleshooting",permalink:"/ts-jest/docs/27.0/guides/troubleshooting",draft:!1,unlisted:!1,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:1726058855e3,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"}},c={},d=[];function l(t){const e={a:"a",code:"code",p:"p",...(0,n.R)(),...t.components};return(0,s.jsxs)(e.p,{children:["You can check Jest ",(0,s.jsx)(e.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," or visit ",(0,s.jsx)(e.code,{children:"ts-jest"})," ",(0,s.jsx)(e.a,{href:"https://github.com/kulshekhar/ts-jest/blob/main/TROUBLESHOOTING.md",children:"troubleshooting\nguide"})]})}function h(t={}){const{wrapper:e}={...(0,n.R)(),...t.components};return e?(0,s.jsx)(e,{...t,children:(0,s.jsx)(l,{...t})}):l(t)}},8453:(t,e,o)=>{o.d(e,{R:()=>r,x:()=>u});var s=o(6540);const n={},i=s.createContext(n);function r(t){const e=s.useContext(i);return s.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function u(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(n):t.components||n:r(t.components),s.createElement(i.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/07a7640f.79e5d19f.js b/assets/js/07a7640f.79e5d19f.js new file mode 100644 index 0000000000..ae6d4cacc6 --- /dev/null +++ b/assets/js/07a7640f.79e5d19f.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7796],{5657:(t,e,o)=>{o.r(e),o.d(e,{assets:()=>d,contentTitle:()=>r,default:()=>h,frontMatter:()=>i,metadata:()=>u,toc:()=>c});var s=o(4848),n=o(8453);const i={id:"troubleshooting",title:"Troubleshooting"},r=void 0,u={id:"guides/troubleshooting",title:"Troubleshooting",description:"You can check Jest troubleshooting guide or visit ts-jest [troubleshooting",source:"@site/versioned_docs/version-27.0/guides/troubleshooting.md",sourceDirName:"guides",slug:"/guides/troubleshooting",permalink:"/ts-jest/docs/27.0/guides/troubleshooting",draft:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/guides/troubleshooting.md",tags:[],version:"27.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},c=[];function l(t){const e={a:"a",code:"code",p:"p",...(0,n.R)(),...t.components};return(0,s.jsxs)(e.p,{children:["You can check Jest ",(0,s.jsx)(e.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," or visit ",(0,s.jsx)(e.code,{children:"ts-jest"})," ",(0,s.jsx)(e.a,{href:"https://github.com/kulshekhar/ts-jest/blob/main/TROUBLESHOOTING.md",children:"troubleshooting\nguide"})]})}function h(t={}){const{wrapper:e}={...(0,n.R)(),...t.components};return e?(0,s.jsx)(e,{...t,children:(0,s.jsx)(l,{...t})}):l(t)}},8453:(t,e,o)=>{o.d(e,{R:()=>r,x:()=>u});var s=o(6540);const n={},i=s.createContext(n);function r(t){const e=s.useContext(i);return s.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function u(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(n):t.components||n:r(t.components),s.createElement(i.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/0833143f.66c92b72.js b/assets/js/0833143f.66c92b72.js new file mode 100644 index 0000000000..7e6c9fe45f --- /dev/null +++ b/assets/js/0833143f.66c92b72.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2625],{1146:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>p,frontMatter:()=>i,metadata:()=>c,toc:()=>u});var s=o(4848),n=o(8453);const i={id:"using-with-monorepo",title:"Using with monorepo"},r=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},u=[];function a(e){const t={a:"a",code:"code",p:"p",...(0,n.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["To use ",(0,s.jsx)(t.code,{children:"ts-jest"})," in a project with monorepo structure, you'll need to use ",(0,s.jsx)(t.a,{href:"https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig",children:"Jest projects configuration"}),"."]}),"\n",(0,s.jsxs)(t.p,{children:["When using Jest ",(0,s.jsx)(t.code,{children:"projects"})," configuration, Jest will run ",(0,s.jsx)(t.code,{children:"ts-jest"})," against each project which is defined in the configuration."]})]})}function p(e={}){const{wrapper:t}={...(0,n.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/0833143f.c5b47fbd.js b/assets/js/0833143f.c5b47fbd.js deleted file mode 100644 index 94f6f88be4..0000000000 --- a/assets/js/0833143f.c5b47fbd.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2625],{1146:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>u,contentTitle:()=>r,default:()=>p,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var s=o(4848),n=o(8453);const i={id:"using-with-monorepo",title:"Using with monorepo"},r=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},u={},d=[];function a(e){const t={a:"a",code:"code",p:"p",...(0,n.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["To use ",(0,s.jsx)(t.code,{children:"ts-jest"})," in a project with monorepo structure, you'll need to use ",(0,s.jsx)(t.a,{href:"https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig",children:"Jest projects configuration"}),"."]}),"\n",(0,s.jsxs)(t.p,{children:["When using Jest ",(0,s.jsx)(t.code,{children:"projects"})," configuration, Jest will run ",(0,s.jsx)(t.code,{children:"ts-jest"})," against each project which is defined in the configuration."]})]})}function p(e={}){const{wrapper:t}={...(0,n.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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.7650d01c.js b/assets/js/093c23a0.7650d01c.js new file mode 100644 index 0000000000..990c418183 --- /dev/null +++ b/assets/js/093c23a0.7650d01c.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5258],{6570:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>d,contentTitle:()=>c,default:()=>j,frontMatter:()=>l,metadata:()=>a,toc:()=>h});var n=s(4848),r=s(8453),i=s(9489),o=s(7227);const l={id:"options",title:"Options"},c=void 0,a={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/options.md",tags:[],version:"29.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.h3,{id:"introduction",children:"Introduction"}),"\n",(0,n.jsx)(t.admonition,{type:"caution",children:(0,n.jsxs)(t.p,{children:["If you are using custom ",(0,n.jsx)(t.code,{children:"transform"})," config, please remove ",(0,n.jsx)(t.code,{children:"preset"})," from your Jest config to avoid issues that Jest doesn't transform files correctly."]})}),"\n",(0,n.jsxs)(t.p,{children:["All ",(0,n.jsx)(t.code,{children:"ts-jest"})," specific options can be defined in Jest ",(0,n.jsx)(t.code,{children:"transform"})," config object in the ",(0,n.jsx)(t.code,{children:"package.json"})," file of your project,\nor through a ",(0,n.jsx)(t.code,{children:"jest.config.js"}),", or ",(0,n.jsx)(t.code,{children:"jest.config.ts"})," file."]}),"\n",(0,n.jsxs)(i.A,{groupId:"code-examples",children:[(0,n.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.admonition,{type:"important",children:(0,n.jsxs)(t.p,{children:["When using TypeScript Jest config file, Jest will use ",(0,n.jsx)(t.code,{children:"ts-node"})," to compile the config file. ",(0,n.jsx)(t.code,{children:"ts-jest"})," doesn't take part in\nthat process."]})}),"\n",(0,n.jsx)(t.h3,{id:"options",children:"Options"}),"\n",(0,n.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,n.jsxs)(t.table,{children:[(0,n.jsx)(t.thead,{children:(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.th,{children:"Option"}),(0,n.jsx)(t.th,{children:"Description"}),(0,n.jsx)(t.th,{children:"Type"}),(0,n.jsx)(t.th,{children:"Default"})]})}),(0,n.jsxs)(t.tbody,{children:[(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/compiler",children:(0,n.jsx)(t.strong,{children:(0,n.jsx)(t.code,{children:"compiler"})})})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.code,{children:"string"})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.code,{children:'"typescript"'})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/tsconfig",children:(0,n.jsx)(t.strong,{children:(0,n.jsx)(t.code,{children:"tsconfig"})})})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,n.jsxs)(t.td,{children:[(0,n.jsx)(t.code,{children:"string"}),"|",(0,n.jsx)(t.code,{children:"object"}),"|",(0,n.jsx)(t.code,{children:"boolean"})]}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.em,{children:"auto"})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/isolatedModules",children:(0,n.jsx)(t.strong,{children:(0,n.jsx)(t.code,{children:"isolatedModules"})})})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.code,{children:"boolean"})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.em,{children:"disabled"})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/astTransformers",children:(0,n.jsx)(t.strong,{children:(0,n.jsx)(t.code,{children:"astTransformers"})})})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.code,{children:"object"})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.em,{children:"auto"})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/diagnostics",children:(0,n.jsx)(t.strong,{children:(0,n.jsx)(t.code,{children:"diagnostics"})})})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,n.jsxs)(t.td,{children:[(0,n.jsx)(t.code,{children:"boolean"}),"|",(0,n.jsx)(t.code,{children:"object"})]}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.em,{children:"enabled"})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/babelConfig",children:(0,n.jsx)(t.strong,{children:(0,n.jsx)(t.code,{children:"babelConfig"})})})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,n.jsxs)(t.td,{children:[(0,n.jsx)(t.code,{children:"boolean"}),"|",(0,n.jsx)(t.code,{children:"string"}),"|",(0,n.jsx)(t.code,{children:"object"})]}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.em,{children:"disabled"})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/stringifyContentPathRegex",children:(0,n.jsx)(t.strong,{children:(0,n.jsx)(t.code,{children:"stringifyContentPathRegex"})})})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,n.jsxs)(t.td,{children:[(0,n.jsx)(t.code,{children:"string"}),"|",(0,n.jsx)(t.code,{children:"RegExp"})]}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.em,{children:"disabled"})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/useESM",children:(0,n.jsx)(t.strong,{children:(0,n.jsx)(t.code,{children:"useESM"})})})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/useESM",children:"Enable ESM support"})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.code,{children:"boolean"})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.em,{children:"auto"})})]})]})]})]})}function j(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(u,{...e})}):u(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>o});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var i=s(4848);function o(e){let{children:t,hidden:s,className:o}=e;return(0,i.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),i=s(4245),o=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,o.W6)(),i=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)(i),(0,n.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 p(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,i=u(e),[o,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:i}))),[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,i]=(0,d.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&i.set(e)}),[s,i])]}({groupId:r}),m=(()=>{const e=a??p;return j({value:e,tabValues:i})?e:null})();(0,l.A)((()=>{m&&c(m)}),[m]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!j({value:e,tabValues:i}))throw new Error(`Can't select invalid tab value=${e}`);c(e),h(e),f(e)}),[h,f,i]),tabValues:i}}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:o,tabValues:l}=e;const c=[],{blockElementScrollPositionUntilNextRender:a}=(0,i.a_)(),d=e=>{const t=e.currentTarget,s=c.indexOf(t),r=l[s].value;r!==n&&(a(t),o(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:i}=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,...i,className:(0,r.A)("tabs__item",m.tabItem,i?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:i}=e;const o=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===i));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!==i})))})}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:()=>o,x:()=>l});var n=s(6540);const r={},i=n.createContext(r);function o(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(r):e.components||r:o(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/093c23a0.818d5f5a.js b/assets/js/093c23a0.818d5f5a.js deleted file mode 100644 index 94489ac467..0000000000 --- a/assets/js/093c23a0.818d5f5a.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5258],{6570:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>d,contentTitle:()=>c,default:()=>j,frontMatter:()=>l,metadata:()=>a,toc:()=>h});var n=s(4848),r=s(8453),i=s(9489),o=s(7227);const l={id:"options",title:"Options"},c=void 0,a={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:!1,unlisted:!1,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:1726058855e3,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"}},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,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.h3,{id:"introduction",children:"Introduction"}),"\n",(0,n.jsx)(t.admonition,{type:"caution",children:(0,n.jsxs)(t.p,{children:["If you are using custom ",(0,n.jsx)(t.code,{children:"transform"})," config, please remove ",(0,n.jsx)(t.code,{children:"preset"})," from your Jest config to avoid issues that Jest doesn't transform files correctly."]})}),"\n",(0,n.jsxs)(t.p,{children:["All ",(0,n.jsx)(t.code,{children:"ts-jest"})," specific options can be defined in Jest ",(0,n.jsx)(t.code,{children:"transform"})," config object in the ",(0,n.jsx)(t.code,{children:"package.json"})," file of your project,\nor through a ",(0,n.jsx)(t.code,{children:"jest.config.js"}),", or ",(0,n.jsx)(t.code,{children:"jest.config.ts"})," file."]}),"\n",(0,n.jsxs)(i.A,{groupId:"code-examples",children:[(0,n.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.admonition,{type:"important",children:(0,n.jsxs)(t.p,{children:["When using TypeScript Jest config file, Jest will use ",(0,n.jsx)(t.code,{children:"ts-node"})," to compile the config file. ",(0,n.jsx)(t.code,{children:"ts-jest"})," doesn't take part in\nthat process."]})}),"\n",(0,n.jsx)(t.h3,{id:"options",children:"Options"}),"\n",(0,n.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,n.jsxs)(t.table,{children:[(0,n.jsx)(t.thead,{children:(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.th,{children:"Option"}),(0,n.jsx)(t.th,{children:"Description"}),(0,n.jsx)(t.th,{children:"Type"}),(0,n.jsx)(t.th,{children:"Default"})]})}),(0,n.jsxs)(t.tbody,{children:[(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/compiler",children:(0,n.jsx)(t.strong,{children:(0,n.jsx)(t.code,{children:"compiler"})})})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.code,{children:"string"})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.code,{children:'"typescript"'})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/tsconfig",children:(0,n.jsx)(t.strong,{children:(0,n.jsx)(t.code,{children:"tsconfig"})})})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,n.jsxs)(t.td,{children:[(0,n.jsx)(t.code,{children:"string"}),"|",(0,n.jsx)(t.code,{children:"object"}),"|",(0,n.jsx)(t.code,{children:"boolean"})]}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.em,{children:"auto"})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/isolatedModules",children:(0,n.jsx)(t.strong,{children:(0,n.jsx)(t.code,{children:"isolatedModules"})})})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.code,{children:"boolean"})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.em,{children:"disabled"})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/astTransformers",children:(0,n.jsx)(t.strong,{children:(0,n.jsx)(t.code,{children:"astTransformers"})})})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.code,{children:"object"})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.em,{children:"auto"})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/diagnostics",children:(0,n.jsx)(t.strong,{children:(0,n.jsx)(t.code,{children:"diagnostics"})})})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,n.jsxs)(t.td,{children:[(0,n.jsx)(t.code,{children:"boolean"}),"|",(0,n.jsx)(t.code,{children:"object"})]}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.em,{children:"enabled"})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/babelConfig",children:(0,n.jsx)(t.strong,{children:(0,n.jsx)(t.code,{children:"babelConfig"})})})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,n.jsxs)(t.td,{children:[(0,n.jsx)(t.code,{children:"boolean"}),"|",(0,n.jsx)(t.code,{children:"string"}),"|",(0,n.jsx)(t.code,{children:"object"})]}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.em,{children:"disabled"})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/stringifyContentPathRegex",children:(0,n.jsx)(t.strong,{children:(0,n.jsx)(t.code,{children:"stringifyContentPathRegex"})})})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,n.jsxs)(t.td,{children:[(0,n.jsx)(t.code,{children:"string"}),"|",(0,n.jsx)(t.code,{children:"RegExp"})]}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.em,{children:"disabled"})})]}),(0,n.jsxs)(t.tr,{children:[(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/useESM",children:(0,n.jsx)(t.strong,{children:(0,n.jsx)(t.code,{children:"useESM"})})})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.a,{href:"options/useESM",children:"Enable ESM support"})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.code,{children:"boolean"})}),(0,n.jsx)(t.td,{children:(0,n.jsx)(t.em,{children:"auto"})})]})]})]})]})}function j(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(u,{...e})}):u(e)}},7227:(e,t,s)=>{s.d(t,{A:()=>o});s(6540);var n=s(4164);const r={tabItem:"tabItem_Ymn6"};var i=s(4848);function o(e){let{children:t,hidden:s,className:o}=e;return(0,i.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),i=s(4245),o=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,o.W6)(),i=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)(i),(0,n.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 p(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,i=u(e),[o,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:i}))),[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,i]=(0,d.Dv)(s);return[r,(0,n.useCallback)((e=>{s&&i.set(e)}),[s,i])]}({groupId:r}),m=(()=>{const e=a??p;return j({value:e,tabValues:i})?e:null})();(0,l.A)((()=>{m&&c(m)}),[m]);return{selectedValue:o,selectValue:(0,n.useCallback)((e=>{if(!j({value:e,tabValues:i}))throw new Error(`Can't select invalid tab value=${e}`);c(e),h(e),f(e)}),[h,f,i]),tabValues:i}}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:o,tabValues:l}=e;const c=[],{blockElementScrollPositionUntilNextRender:a}=(0,i.a_)(),d=e=>{const t=e.currentTarget,s=c.indexOf(t),r=l[s].value;r!==n&&(a(t),o(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:i}=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,...i,className:(0,r.A)("tabs__item",m.tabItem,i?.className,{"tabs__item--active":n===t}),children:s??t},t)}))})}function v(e){let{lazy:t,children:s,selectedValue:i}=e;const o=(Array.isArray(s)?s:[s]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===i));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!==i})))})}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:()=>o,x:()=>l});var n=s(6540);const r={},i=n.createContext(r);function o(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(r):e.components||r:o(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/0a51ecf3.589506da.js b/assets/js/0a51ecf3.589506da.js deleted file mode 100644 index df5e5ea876..0000000000 --- a/assets/js/0a51ecf3.589506da.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4441],{8004:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>l,default:()=>f,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var s=n(4848),r=n(8453),a=n(9489),o=n(7227);const i={id:"react-native",title:"Using with React Native"},l=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},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,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["To use ",(0,s.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,s.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,s.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,s.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,s.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,s.jsx)(t.code,{children:".babelrc"})," to ",(0,s.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,s.jsxs)(a.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.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\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.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,s.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,s.jsxs)(t.p,{children:["Create a new ",(0,s.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,s.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,s.jsx)(t.code,{children:"jest"})," key of ",(0,s.jsx)(t.code,{children:"package.json"})," to ",(0,s.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,s.jsxs)(a.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.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,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.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,r.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:()=>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/0a51ecf3.8b2406b3.js b/assets/js/0a51ecf3.8b2406b3.js new file mode 100644 index 0000000000..68fac4351b --- /dev/null +++ b/assets/js/0a51ecf3.8b2406b3.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4441],{8004:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>l,default:()=>f,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var s=n(4848),r=n(8453),a=n(9489),o=n(7227);const i={id:"react-native",title:"Using with React Native"},l=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/guides/react-native.md",tags:[],version:"29.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["To use ",(0,s.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,s.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,s.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,s.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,s.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,s.jsx)(t.code,{children:".babelrc"})," to ",(0,s.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,s.jsxs)(a.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.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\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.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,s.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,s.jsxs)(t.p,{children:["Create a new ",(0,s.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,s.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,s.jsx)(t.code,{children:"jest"})," key of ",(0,s.jsx)(t.code,{children:"package.json"})," to ",(0,s.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,s.jsxs)(a.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.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,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.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,r.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:()=>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.0c2b5ed8.js b/assets/js/0b2fcab7.0c2b5ed8.js deleted file mode 100644 index 58183e457b..0000000000 --- a/assets/js/0b2fcab7.0c2b5ed8.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3004],{9881:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>a,contentTitle:()=>r,default:()=>g,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var s=t(4848),o=t(8453);const i={id:"migration",title:"Migration from <=23.10"},r=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},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,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(n.p,{children:["You can use the ",(0,s.jsx)(n.code,{children:"config:migrate"})," tool of ",(0,s.jsx)(n.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsxs)(n.em,{children:["If you're using ",(0,s.jsx)(n.code,{children:"jest.config.js"}),":"]})}),"\n",(0,s.jsx)(n.h3,{id:"npm",children:"NPM"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate jest.config.js\n"})}),"\n",(0,s.jsx)(n.h3,{id:"yarn",children:"Yarn"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate jest.config.js\n"})}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsxs)(n.em,{children:["If you're using ",(0,s.jsx)(n.code,{children:"jest"})," config property of ",(0,s.jsx)(n.code,{children:"package.json"}),":"]})}),"\n",(0,s.jsx)(n.h3,{id:"npm-1",children:"NPM"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate package.json\n"})}),"\n",(0,s.jsx)(n.h3,{id:"yarn-1",children:"Yarn"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate package.json\n"})})]})}function g(e={}){const{wrapper:n}={...(0,o.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.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/0b2fcab7.6c92b9dc.js b/assets/js/0b2fcab7.6c92b9dc.js new file mode 100644 index 0000000000..80b2013141 --- /dev/null +++ b/assets/js/0b2fcab7.6c92b9dc.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3004],{9881:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>a,contentTitle:()=>r,default:()=>g,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var s=t(4848),o=t(8453);const i={id:"migration",title:"Migration from <=23.10"},r=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/migration.md",tags:[],version:"27.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(n.p,{children:["You can use the ",(0,s.jsx)(n.code,{children:"config:migrate"})," tool of ",(0,s.jsx)(n.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsxs)(n.em,{children:["If you're using ",(0,s.jsx)(n.code,{children:"jest.config.js"}),":"]})}),"\n",(0,s.jsx)(n.h3,{id:"npm",children:"NPM"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate jest.config.js\n"})}),"\n",(0,s.jsx)(n.h3,{id:"yarn",children:"Yarn"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate jest.config.js\n"})}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsxs)(n.em,{children:["If you're using ",(0,s.jsx)(n.code,{children:"jest"})," config property of ",(0,s.jsx)(n.code,{children:"package.json"}),":"]})}),"\n",(0,s.jsx)(n.h3,{id:"npm-1",children:"NPM"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate package.json\n"})}),"\n",(0,s.jsx)(n.h3,{id:"yarn-1",children:"Yarn"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate package.json\n"})})]})}function g(e={}){const{wrapper:n}={...(0,o.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.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.44652755.js b/assets/js/0d0f47fc.44652755.js new file mode 100644 index 0000000000..7c74766239 --- /dev/null +++ b/assets/js/0d0f47fc.44652755.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4263],{3036:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>a,contentTitle:()=>l,default:()=>u,frontMatter:()=>o,metadata:()=>d,toc:()=>j});var r=t(4848),n=t(8453),i=t(9489),c=t(7227);const o={id:"presets",title:"Presets"},l=void 0,d={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/presets.md",tags:[],version:"29.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,n.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.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.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.jsxs)(i.A,{groupId:"code-examples",children:[(0,r.jsx)(c.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 // Replace `ts-jest` with the preset you want to use\n // from the above list\n preset: 'ts-jest',\n}\n"})})}),(0,r.jsx)(c.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 // 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,r.jsx)(c.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 // [...]\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.jsxs)(i.A,{groupId:"code-examples",children:[(0,r.jsx)(c.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\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,r.jsx)(c.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\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,n.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.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/0d0f47fc.eff61710.js b/assets/js/0d0f47fc.eff61710.js deleted file mode 100644 index 2bc8fd9211..0000000000 --- a/assets/js/0d0f47fc.eff61710.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4263],{3036:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>a,contentTitle:()=>l,default:()=>u,frontMatter:()=>o,metadata:()=>d,toc:()=>j});var r=t(4848),n=t(8453),i=t(9489),c=t(7227);const o={id:"presets",title:"Presets"},l=void 0,d={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:!1,unlisted:!1,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:1726058855e3,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"}},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,n.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.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.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.jsxs)(i.A,{groupId:"code-examples",children:[(0,r.jsx)(c.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 // Replace `ts-jest` with the preset you want to use\n // from the above list\n preset: 'ts-jest',\n}\n"})})}),(0,r.jsx)(c.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 // 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,r.jsx)(c.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 // [...]\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.jsxs)(i.A,{groupId:"code-examples",children:[(0,r.jsx)(c.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\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,r.jsx)(c.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\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,n.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.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.029e0bed.js b/assets/js/10aeaaf3.029e0bed.js new file mode 100644 index 0000000000..a69ca42206 --- /dev/null +++ b/assets/js/10aeaaf3.029e0bed.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2957],{8765:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>c,contentTitle:()=>r,default:()=>a,frontMatter:()=>i,metadata:()=>p,toc:()=>d});var n=s(4848),o=s(8453);const i={id:"esm-support",title:"ESM Support"},r=void 0,p={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/guides/esm-support.md",tags:[],version:"26.5",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},c={},d=[];function u(t){const e={admonition:"admonition",p:"p",strong:"strong",...(0,o.R)(),...t.components};return(0,n.jsx)(e.admonition,{type:"important",children:(0,n.jsxs)(e.p,{children:["ESM support is only available in ",(0,n.jsx)(e.strong,{children:"v27++"})]})})}function a(t={}){const{wrapper:e}={...(0,o.R)(),...t.components};return e?(0,n.jsx)(e,{...t,children:(0,n.jsx)(u,{...t})}):u(t)}},8453:(t,e,s)=>{s.d(e,{R:()=>r,x:()=>p});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 p(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/10aeaaf3.5b99ffe3.js b/assets/js/10aeaaf3.5b99ffe3.js deleted file mode 100644 index 02f4febe5e..0000000000 --- a/assets/js/10aeaaf3.5b99ffe3.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2957],{8765:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>p,contentTitle:()=>r,default:()=>a,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var n=s(4848),o=s(8453);const i={id:"esm-support",title:"ESM Support"},r=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},p={},d=[];function u(t){const e={admonition:"admonition",p:"p",strong:"strong",...(0,o.R)(),...t.components};return(0,n.jsx)(e.admonition,{type:"important",children:(0,n.jsxs)(e.p,{children:["ESM support is only available in ",(0,n.jsx)(e.strong,{children:"v27++"})]})})}function a(t={}){const{wrapper:e}={...(0,o.R)(),...t.components};return e?(0,n.jsx)(e,{...t,children:(0,n.jsx)(u,{...t})}):u(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.dd3d9e6e.js b/assets/js/1165ba55.dd3d9e6e.js deleted file mode 100644 index 89e7c6c2b1..0000000000 --- a/assets/js/1165ba55.dd3d9e6e.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8431],{4544:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>l,default:()=>h,frontMatter:()=>o,metadata:()=>r,toc:()=>d});var i=t(4848),s=t(8453);const o={id:"installation",title:"Installation"},l=void 0,r={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:!1,unlisted:!1,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:1726058855e3,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"}},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 n={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,i.jsxs)(n.p,{children:["You can install ",(0,i.jsx)(n.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,i.jsx)(n.h4,{id:"npm",children:"NPM"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(n.h4,{id:"yarn",children:"Yarn"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:["Tip: If you get an error with the following ",(0,i.jsx)(n.code,{children:"npm"})," commands such as ",(0,i.jsx)(n.code,{children:"npx: command not found"}),", you can replace ",(0,i.jsx)(n.code,{children:"npx XXX"})," with ",(0,i.jsx)(n.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,i.jsx)(n.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,i.jsx)(n.h4,{id:"creating",children:"Creating"}),"\n",(0,i.jsxs)(n.p,{children:["By default Jest can run without any config files, but it will not compile ",(0,i.jsx)(n.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,i.jsx)(n.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,i.jsx)(n.code,{children:"ts-jest"})," preset."]}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,i.jsx)(n.h4,{id:"npm-1",children:"NPM"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:init\n"})}),"\n",(0,i.jsx)(n.h4,{id:"yarn-1",children:"Yarn"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:init\n"})}),"\n",(0,i.jsxs)(n.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,i.jsx)(n.code,{children:".ts"})," files correctly."]}),"\n",(0,i.jsxs)(n.p,{children:["You can also use the ",(0,i.jsx)(n.code,{children:"jest --init"})," command (prefixed with either ",(0,i.jsx)(n.code,{children:"npx"})," or ",(0,i.jsx)(n.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,i.jsx)(n.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,i.jsx)(n.code,{children:'preset: "ts-jest"'})," to the ",(0,i.jsx)(n.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,i.jsx)(n.h4,{id:"customizing",children:"Customizing"}),"\n",(0,i.jsxs)(n.p,{children:["For customizing jest, please follow their ",(0,i.jsx)(n.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.code,{children:"ts-jest"})," specific options can be found ",(0,i.jsx)(n.a,{href:"options",children:"here"}),"."]})]})}function h(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(a,{...e})}):a(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>l,x:()=>r});var i=t(6540);const s={},o=i.createContext(s);function l(e){const n=i.useContext(o);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(s):e.components||s:l(e.components),i.createElement(o.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/1165ba55.f50235a3.js b/assets/js/1165ba55.f50235a3.js new file mode 100644 index 0000000000..7aa6a5d1d7 --- /dev/null +++ b/assets/js/1165ba55.f50235a3.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8431],{4544:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>l,default:()=>h,frontMatter:()=>o,metadata:()=>r,toc:()=>d});var i=t(4848),s=t(8453);const o={id:"installation",title:"Installation"},l=void 0,r={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/getting-started/installation.md",tags:[],version:"26.5",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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 n={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,i.jsxs)(n.p,{children:["You can install ",(0,i.jsx)(n.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,i.jsx)(n.h4,{id:"npm",children:"NPM"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(n.h4,{id:"yarn",children:"Yarn"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:["Tip: If you get an error with the following ",(0,i.jsx)(n.code,{children:"npm"})," commands such as ",(0,i.jsx)(n.code,{children:"npx: command not found"}),", you can replace ",(0,i.jsx)(n.code,{children:"npx XXX"})," with ",(0,i.jsx)(n.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,i.jsx)(n.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,i.jsx)(n.h4,{id:"creating",children:"Creating"}),"\n",(0,i.jsxs)(n.p,{children:["By default Jest can run without any config files, but it will not compile ",(0,i.jsx)(n.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,i.jsx)(n.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,i.jsx)(n.code,{children:"ts-jest"})," preset."]}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,i.jsx)(n.h4,{id:"npm-1",children:"NPM"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:init\n"})}),"\n",(0,i.jsx)(n.h4,{id:"yarn-1",children:"Yarn"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:init\n"})}),"\n",(0,i.jsxs)(n.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,i.jsx)(n.code,{children:".ts"})," files correctly."]}),"\n",(0,i.jsxs)(n.p,{children:["You can also use the ",(0,i.jsx)(n.code,{children:"jest --init"})," command (prefixed with either ",(0,i.jsx)(n.code,{children:"npx"})," or ",(0,i.jsx)(n.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,i.jsx)(n.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,i.jsx)(n.code,{children:'preset: "ts-jest"'})," to the ",(0,i.jsx)(n.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,i.jsx)(n.h4,{id:"customizing",children:"Customizing"}),"\n",(0,i.jsxs)(n.p,{children:["For customizing jest, please follow their ",(0,i.jsx)(n.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.code,{children:"ts-jest"})," specific options can be found ",(0,i.jsx)(n.a,{href:"options",children:"here"}),"."]})]})}function h(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(a,{...e})}):a(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>l,x:()=>r});var i=t(6540);const s={},o=i.createContext(s);function l(e){const n=i.useContext(o);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(s):e.components||s:l(e.components),i.createElement(o.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/12292045.1cb02d81.js b/assets/js/12292045.1cb02d81.js new file mode 100644 index 0000000000..7e8577248f --- /dev/null +++ b/assets/js/12292045.1cb02d81.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[610],{7613:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var n=s(4848),o=s(8453);const r={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},i=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/introduction.md",tags:[],version:"29.2",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,o.R)(),...t.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,n.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,n.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,n.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,n.jsx)(e.code,{children:"preset-typescript"})," ",(0,n.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,n.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,n.jsx)(e.admonition,{type:"important",children:(0,n.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,n.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,n.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,o.R)(),...t.components};return e?(0,n.jsx)(e,{...t,children:(0,n.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/12292045.d830fc8a.js b/assets/js/12292045.d830fc8a.js deleted file mode 100644 index d8a6685553..0000000000 --- a/assets/js/12292045.d830fc8a.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[610],{7613:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var n=s(4848),o=s(8453);const r={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,o.R)(),...t.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,n.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,n.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,n.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,n.jsx)(e.code,{children:"preset-typescript"})," ",(0,n.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,n.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,n.jsx)(e.admonition,{type:"important",children:(0,n.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,n.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,n.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,o.R)(),...t.components};return e?(0,n.jsx)(e,{...t,children:(0,n.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.419faa31.js b/assets/js/15c7296a.419faa31.js deleted file mode 100644 index 374a629d04..0000000000 --- a/assets/js/15c7296a.419faa31.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[551],{1307:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>m,frontMatter:()=>o,metadata:()=>i,toc:()=>d});var r=n(4848),s=n(8453),a=n(9489),l=n(7227);const o={id:"mock-es6-class",title:"Mock ES6 class"},u=void 0,i={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:!1,unlisted:!1,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:1726058855e3,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"}},c={},d=[];function p(e){const t={code:"code",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,r.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,r.jsx)(t.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\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.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\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.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\n })\n})\n"})})})]}),"\n",(0,r.jsx)(t.p,{children:"You will get the error"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,r.jsxs)(t.p,{children:["because ",(0,r.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,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.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\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.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\n }\n }),\n }\n})\n"})})})]}),"\n",(0,r.jsxs)(t.p,{children:["For named imports, like ",(0,r.jsx)(t.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,r.jsx)(t.code,{children:"default"})," with imported module name, ",(0,r.jsx)(t.code,{children:"OAuth2"})," in this 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.mock('./oauth', () => {\n return {\n OAuth2: ... // mock here\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.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,r.jsx)(t,{...e,children:(0,r.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/15c7296a.76ade3ac.js b/assets/js/15c7296a.76ade3ac.js new file mode 100644 index 0000000000..06eef07ee2 --- /dev/null +++ b/assets/js/15c7296a.76ade3ac.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[551],{1307:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>m,frontMatter:()=>o,metadata:()=>i,toc:()=>d});var r=n(4848),s=n(8453),a=n(9489),l=n(7227);const o={id:"mock-es6-class",title:"Mock ES6 class"},u=void 0,i={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},c={},d=[];function p(e){const t={code:"code",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,r.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,r.jsx)(t.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\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.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\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.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\n })\n})\n"})})})]}),"\n",(0,r.jsx)(t.p,{children:"You will get the error"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,r.jsxs)(t.p,{children:["because ",(0,r.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,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.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\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.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\n }\n }),\n }\n})\n"})})})]}),"\n",(0,r.jsxs)(t.p,{children:["For named imports, like ",(0,r.jsx)(t.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,r.jsx)(t.code,{children:"default"})," with imported module name, ",(0,r.jsx)(t.code,{children:"OAuth2"})," in this 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.mock('./oauth', () => {\n return {\n OAuth2: ... // mock here\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.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,r.jsx)(t,{...e,children:(0,r.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.9b9f8b09.js b/assets/js/16ada0e2.9b9f8b09.js new file mode 100644 index 0000000000..73680307a5 --- /dev/null +++ b/assets/js/16ada0e2.9b9f8b09.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5623],{7205:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>p,frontMatter:()=>i,metadata:()=>c,toc:()=>u});var s=o(4848),n=o(8453);const i={id:"using-with-monorepo",title:"Using with monorepo"},r=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},u=[];function a(e){const t={a:"a",code:"code",p:"p",...(0,n.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["To use ",(0,s.jsx)(t.code,{children:"ts-jest"})," in a project with monorepo structure, you'll need to use ",(0,s.jsx)(t.a,{href:"https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig",children:"Jest projects configuration"}),"."]}),"\n",(0,s.jsxs)(t.p,{children:["When using Jest ",(0,s.jsx)(t.code,{children:"projects"})," configuration, Jest will run ",(0,s.jsx)(t.code,{children:"ts-jest"})," against each project which is defined in the configuration."]})]})}function p(e={}){const{wrapper:t}={...(0,n.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/16ada0e2.c0e52a74.js b/assets/js/16ada0e2.c0e52a74.js deleted file mode 100644 index a4507ee2a2..0000000000 --- a/assets/js/16ada0e2.c0e52a74.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5623],{7205:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>u,contentTitle:()=>r,default:()=>p,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var s=o(4848),n=o(8453);const i={id:"using-with-monorepo",title:"Using with monorepo"},r=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},u={},d=[];function a(e){const t={a:"a",code:"code",p:"p",...(0,n.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["To use ",(0,s.jsx)(t.code,{children:"ts-jest"})," in a project with monorepo structure, you'll need to use ",(0,s.jsx)(t.a,{href:"https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig",children:"Jest projects configuration"}),"."]}),"\n",(0,s.jsxs)(t.p,{children:["When using Jest ",(0,s.jsx)(t.code,{children:"projects"})," configuration, Jest will run ",(0,s.jsx)(t.code,{children:"ts-jest"})," against each project which is defined in the configuration."]})]})}function p(e={}){const{wrapper:t}={...(0,n.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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.7df48aa7.js b/assets/js/16bac89a.7df48aa7.js new file mode 100644 index 0000000000..3147e098cd --- /dev/null +++ b/assets/js/16bac89a.7df48aa7.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5046],{8081:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>p,frontMatter:()=>o,metadata:()=>c,toc:()=>l});var s=n(4848),i=n(8453);const o={id:"babel7-or-ts",title:"Babel7 or TypeScript"},r=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/babel7-or-ts.md",tags:[],version:"27.1",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,s.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,s.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,s.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,s.jsxs)(t.p,{children:["While ",(0,s.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,s.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,s.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,s.jsxs)(t.p,{children:["This is the big ",(0,s.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,s.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,s.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,s.jsx)(t.code,{children:"namespace"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,s.jsx)(t.code,{children:"const enum"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,s.jsx)(t.code,{children:"enum"}),", ",(0,s.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,s.jsxs)(t.p,{children:["You won't be able to do ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,s.jsx)(t.code,{children:"import"}),"/",(0,s.jsx)(t.code,{children:"export"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(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,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/16bac89a.d567dcfa.js b/assets/js/16bac89a.d567dcfa.js deleted file mode 100644 index 57741451a9..0000000000 --- a/assets/js/16bac89a.d567dcfa.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5046],{8081:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>p,frontMatter:()=>o,metadata:()=>c,toc:()=>l});var s=n(4848),i=n(8453);const o={id:"babel7-or-ts",title:"Babel7 or TypeScript"},r=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},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,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,s.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,s.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,s.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,s.jsxs)(t.p,{children:["While ",(0,s.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,s.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,s.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,s.jsxs)(t.p,{children:["This is the big ",(0,s.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,s.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,s.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,s.jsx)(t.code,{children:"namespace"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,s.jsx)(t.code,{children:"const enum"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,s.jsx)(t.code,{children:"enum"}),", ",(0,s.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,s.jsxs)(t.p,{children:["You won't be able to do ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,s.jsx)(t.code,{children:"import"}),"/",(0,s.jsx)(t.code,{children:"export"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(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,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.99269201.js b/assets/js/1854c3e7.99269201.js new file mode 100644 index 0000000000..363e60ac02 --- /dev/null +++ b/assets/js/1854c3e7.99269201.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1797],{8152:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>p,frontMatter:()=>o,metadata:()=>c,toc:()=>l});var s=n(4848),i=n(8453);const o={id:"babel7-or-ts",title:"Babel7 or TypeScript"},r=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/babel7-or-ts.md",tags:[],version:"26.5",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,s.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,s.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,s.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,s.jsxs)(t.p,{children:["While ",(0,s.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,s.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,s.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,s.jsxs)(t.p,{children:["This is the big ",(0,s.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,s.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,s.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,s.jsx)(t.code,{children:"namespace"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,s.jsx)(t.code,{children:"const enum"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,s.jsx)(t.code,{children:"enum"}),", ",(0,s.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,s.jsxs)(t.p,{children:["You won't be able to do ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,s.jsx)(t.code,{children:"import"}),"/",(0,s.jsx)(t.code,{children:"export"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(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,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.ac860993.js b/assets/js/1854c3e7.ac860993.js deleted file mode 100644 index a601a82d40..0000000000 --- a/assets/js/1854c3e7.ac860993.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1797],{8152:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>p,frontMatter:()=>o,metadata:()=>c,toc:()=>l});var s=n(4848),i=n(8453);const o={id:"babel7-or-ts",title:"Babel7 or TypeScript"},r=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},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,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,s.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,s.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,s.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,s.jsxs)(t.p,{children:["While ",(0,s.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,s.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,s.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,s.jsxs)(t.p,{children:["This is the big ",(0,s.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,s.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,s.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,s.jsx)(t.code,{children:"namespace"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,s.jsx)(t.code,{children:"const enum"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,s.jsx)(t.code,{children:"enum"}),", ",(0,s.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,s.jsxs)(t.p,{children:["You won't be able to do ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,s.jsx)(t.code,{children:"import"}),"/",(0,s.jsx)(t.code,{children:"export"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(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,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.11abb5ac.js b/assets/js/1917a510.11abb5ac.js new file mode 100644 index 0000000000..2d8c499541 --- /dev/null +++ b/assets/js/1917a510.11abb5ac.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4076],{9295:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>l,default:()=>p,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var s=n(4848),r=n(8453),o=n(9489),a=n(7227);const i={title:"Stringify content option"},l=void 0,u={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Stringify content option"}},c={},d=[{value:"Example",id:"example",level:3}];function h(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["The ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,s.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,s.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,s.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,s.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,s.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,s.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,s.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,s.jsx)(t.code,{children:"transform"})," option pointing to ",(0,s.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,s.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsxs)(t.p,{children:["In the ",(0,s.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,s.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,s.jsxs)(o.A,{groupId:"code-examples",children:[(0,s.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(a.A,{value:"JSON",children:(0,s.jsx)(t.pre,{children:(0,s.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,r.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/1917a510.8f63b55f.js b/assets/js/1917a510.8f63b55f.js deleted file mode 100644 index 9957cbc5cc..0000000000 --- a/assets/js/1917a510.8f63b55f.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4076],{9295:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>l,default:()=>p,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var s=n(4848),r=n(8453),o=n(9489),a=n(7227);const i={title:"Stringify content option"},l=void 0,u={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Stringify content option"}},c={},d=[{value:"Example",id:"example",level:3}];function h(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["The ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,s.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,s.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,s.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,s.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,s.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,s.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,s.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,s.jsx)(t.code,{children:"transform"})," option pointing to ",(0,s.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,s.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsxs)(t.p,{children:["In the ",(0,s.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,s.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,s.jsxs)(o.A,{groupId:"code-examples",children:[(0,s.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(a.A,{value:"JSON",children:(0,s.jsx)(t.pre,{children:(0,s.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,r.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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.68a02422.js b/assets/js/19f0fee7.68a02422.js deleted file mode 100644 index a787eab8e7..0000000000 --- a/assets/js/19f0fee7.68a02422.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8888],{2332:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>c,contentTitle:()=>l,default:()=>h,frontMatter:()=>t,metadata:()=>r,toc:()=>d});var i=s(4848),o=s(8453);const t={title:"Diagnostics option"},l=void 0,r={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Diagnostics option"}},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,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(n.p,{children:["The ",(0,i.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,i.jsxs)(n.p,{children:["If a diagnostic is not filtered out, ",(0,i.jsx)(n.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,i.jsx)(n.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,i.jsxs)(n.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,i.jsx)(n.code,{children:"diagnostics"})," option to ",(0,i.jsx)(n.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,i.jsx)(n.code,{children:"diagnostics"})," to ",(0,i.jsx)(n.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,i.jsx)(n.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"warnOnly"})}),": If specified and ",(0,i.jsx)(n.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,i.jsx)(n.em,{children:"disabled"}),")."]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,i.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,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"6059"}),": ",(0,i.jsx)(n.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"18002"}),": ",(0,i.jsx)(n.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"18003"}),": ",(0,i.jsx)(n.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,i.jsx)(n.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,i.jsx)(n.code,{children:"tsconfig"})," option ",(0,i.jsx)(n.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,i.jsx)(n.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,i.jsx)(n.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,i.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,i.jsx)(n.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,i.jsx)(n.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,i.jsxs)(n.p,{children:["Assuming all your test files ends with ",(0,i.jsx)(n.code,{children:".spec.ts"})," or ",(0,i.jsx)(n.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,i.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,i.jsx)(n.code,{children:"warnOnly"})," to ",(0,i.jsx)(n.code,{children:"true"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,i.jsxs)(n.p,{children:["All TypeScript error codes can be found ",(0,i.jsx)(n.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,i.jsx)(n.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,i.jsxs)(n.ol,{children:["\n",(0,i.jsxs)(n.li,{children:["A single ",(0,i.jsx)(n.code,{children:"number"})," (example: ",(0,i.jsx)(n.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,i.jsxs)(n.li,{children:["A ",(0,i.jsx)(n.code,{children:"string"})," with a code (example ",(0,i.jsx)(n.code,{children:'"1009"'}),", ",(0,i.jsx)(n.code,{children:'"TS1009"'})," or ",(0,i.jsx)(n.code,{children:'"TS1009"'}),")"]}),"\n",(0,i.jsxs)(n.li,{children:["A ",(0,i.jsx)(n.code,{children:"string"})," with a list of the above (example: ",(0,i.jsx)(n.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,i.jsxs)(n.li,{children:["An ",(0,i.jsx)(n.code,{children:"array"})," of one or more from ",(0,i.jsx)(n.code,{children:"1"})," or ",(0,i.jsx)(n.code,{children:"3"})," (example: ",(0,i.jsx)(n.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,o.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.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/19f0fee7.bbb45e51.js b/assets/js/19f0fee7.bbb45e51.js new file mode 100644 index 0000000000..53c0e7491c --- /dev/null +++ b/assets/js/19f0fee7.bbb45e51.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8888],{2332:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>c,contentTitle:()=>l,default:()=>h,frontMatter:()=>t,metadata:()=>r,toc:()=>d});var i=s(4848),o=s(8453);const t={title:"Diagnostics option"},l=void 0,r={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Diagnostics option"}},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,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(n.p,{children:["The ",(0,i.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,i.jsxs)(n.p,{children:["If a diagnostic is not filtered out, ",(0,i.jsx)(n.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,i.jsx)(n.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,i.jsxs)(n.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,i.jsx)(n.code,{children:"diagnostics"})," option to ",(0,i.jsx)(n.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,i.jsx)(n.code,{children:"diagnostics"})," to ",(0,i.jsx)(n.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,i.jsx)(n.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"warnOnly"})}),": If specified and ",(0,i.jsx)(n.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,i.jsx)(n.em,{children:"disabled"}),")."]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,i.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,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"6059"}),": ",(0,i.jsx)(n.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"18002"}),": ",(0,i.jsx)(n.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"18003"}),": ",(0,i.jsx)(n.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,i.jsx)(n.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,i.jsx)(n.code,{children:"tsconfig"})," option ",(0,i.jsx)(n.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,i.jsx)(n.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,i.jsx)(n.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,i.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,i.jsx)(n.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,i.jsx)(n.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,i.jsxs)(n.p,{children:["Assuming all your test files ends with ",(0,i.jsx)(n.code,{children:".spec.ts"})," or ",(0,i.jsx)(n.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,i.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,i.jsx)(n.code,{children:"warnOnly"})," to ",(0,i.jsx)(n.code,{children:"true"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,i.jsxs)(n.p,{children:["All TypeScript error codes can be found ",(0,i.jsx)(n.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,i.jsx)(n.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,i.jsxs)(n.ol,{children:["\n",(0,i.jsxs)(n.li,{children:["A single ",(0,i.jsx)(n.code,{children:"number"})," (example: ",(0,i.jsx)(n.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,i.jsxs)(n.li,{children:["A ",(0,i.jsx)(n.code,{children:"string"})," with a code (example ",(0,i.jsx)(n.code,{children:'"1009"'}),", ",(0,i.jsx)(n.code,{children:'"TS1009"'})," or ",(0,i.jsx)(n.code,{children:'"TS1009"'}),")"]}),"\n",(0,i.jsxs)(n.li,{children:["A ",(0,i.jsx)(n.code,{children:"string"})," with a list of the above (example: ",(0,i.jsx)(n.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,i.jsxs)(n.li,{children:["An ",(0,i.jsx)(n.code,{children:"array"})," of one or more from ",(0,i.jsx)(n.code,{children:"1"})," or ",(0,i.jsx)(n.code,{children:"3"})," (example: ",(0,i.jsx)(n.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,o.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.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.0dfc81f2.js b/assets/js/1ca5b1f2.0dfc81f2.js new file mode 100644 index 0000000000..db667d3723 --- /dev/null +++ b/assets/js/1ca5b1f2.0dfc81f2.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1682],{2331:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>p,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var s=n(4848),i=n(8453);const r={id:"version-checking",title:"Version checking"},o=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},a=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default, ",(0,s.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,s.jsx)(t.code,{children:"jest"}),"/",(0,s.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,s.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\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_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Windows"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,s.jsxs)(t.p,{children:["As long as the environment variable ",(0,s.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,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/1ca5b1f2.723c5c46.js b/assets/js/1ca5b1f2.723c5c46.js deleted file mode 100644 index 642be753e8..0000000000 --- a/assets/js/1ca5b1f2.723c5c46.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1682],{2331:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>p,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var s=n(4848),i=n(8453);const r={id:"version-checking",title:"Version checking"},o=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},d={},a=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default, ",(0,s.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,s.jsx)(t.code,{children:"jest"}),"/",(0,s.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,s.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\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_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Windows"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,s.jsxs)(t.p,{children:["As long as the environment variable ",(0,s.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,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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.506c6889.js b/assets/js/2145bebc.506c6889.js new file mode 100644 index 0000000000..ace99275d3 --- /dev/null +++ b/assets/js/2145bebc.506c6889.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8703],{8001:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>l,default:()=>h,frontMatter:()=>o,metadata:()=>r,toc:()=>d});var i=t(4848),s=t(8453);const o={id:"installation",title:"Installation"},l=void 0,r={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/installation.md",tags:[],version:"27.1",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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 n={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,i.jsxs)(n.p,{children:["You can install ",(0,i.jsx)(n.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,i.jsx)(n.h4,{id:"npm",children:"NPM"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(n.h4,{id:"yarn",children:"Yarn"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:["Tip: If you get an error with the following ",(0,i.jsx)(n.code,{children:"npm"})," commands such as ",(0,i.jsx)(n.code,{children:"npx: command not found"}),", you can replace ",(0,i.jsx)(n.code,{children:"npx XXX"})," with ",(0,i.jsx)(n.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,i.jsx)(n.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,i.jsx)(n.h4,{id:"creating",children:"Creating"}),"\n",(0,i.jsxs)(n.p,{children:["By default, Jest can run without any config files, but it will not compile ",(0,i.jsx)(n.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,i.jsx)(n.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,i.jsx)(n.code,{children:"ts-jest"})," preset."]}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,i.jsx)(n.h4,{id:"npm-1",children:"NPM"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:init\n"})}),"\n",(0,i.jsx)(n.h4,{id:"yarn-1",children:"Yarn"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:init\n"})}),"\n",(0,i.jsxs)(n.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,i.jsx)(n.code,{children:".ts"})," files correctly."]}),"\n",(0,i.jsxs)(n.p,{children:["You can also use the ",(0,i.jsx)(n.code,{children:"jest --init"})," command (prefixed with either ",(0,i.jsx)(n.code,{children:"npx"})," or ",(0,i.jsx)(n.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,i.jsx)(n.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,i.jsx)(n.code,{children:'preset: "ts-jest"'})," to the ",(0,i.jsx)(n.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,i.jsx)(n.h4,{id:"customizing",children:"Customizing"}),"\n",(0,i.jsxs)(n.p,{children:["For customizing jest, please follow their ",(0,i.jsx)(n.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.code,{children:"ts-jest"})," specific options can be found ",(0,i.jsx)(n.a,{href:"options",children:"here"}),"."]})]})}function h(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(a,{...e})}):a(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>l,x:()=>r});var i=t(6540);const s={},o=i.createContext(s);function l(e){const n=i.useContext(o);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(s):e.components||s:l(e.components),i.createElement(o.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/2145bebc.dbfee05f.js b/assets/js/2145bebc.dbfee05f.js deleted file mode 100644 index 8a654cfd45..0000000000 --- a/assets/js/2145bebc.dbfee05f.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8703],{8001:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>l,default:()=>h,frontMatter:()=>o,metadata:()=>r,toc:()=>d});var i=t(4848),s=t(8453);const o={id:"installation",title:"Installation"},l=void 0,r={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:!1,unlisted:!1,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:1726058855e3,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"}},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 n={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,i.jsxs)(n.p,{children:["You can install ",(0,i.jsx)(n.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,i.jsx)(n.h4,{id:"npm",children:"NPM"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(n.h4,{id:"yarn",children:"Yarn"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:["Tip: If you get an error with the following ",(0,i.jsx)(n.code,{children:"npm"})," commands such as ",(0,i.jsx)(n.code,{children:"npx: command not found"}),", you can replace ",(0,i.jsx)(n.code,{children:"npx XXX"})," with ",(0,i.jsx)(n.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,i.jsx)(n.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,i.jsx)(n.h4,{id:"creating",children:"Creating"}),"\n",(0,i.jsxs)(n.p,{children:["By default, Jest can run without any config files, but it will not compile ",(0,i.jsx)(n.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,i.jsx)(n.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,i.jsx)(n.code,{children:"ts-jest"})," preset."]}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,i.jsx)(n.h4,{id:"npm-1",children:"NPM"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:init\n"})}),"\n",(0,i.jsx)(n.h4,{id:"yarn-1",children:"Yarn"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:init\n"})}),"\n",(0,i.jsxs)(n.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,i.jsx)(n.code,{children:".ts"})," files correctly."]}),"\n",(0,i.jsxs)(n.p,{children:["You can also use the ",(0,i.jsx)(n.code,{children:"jest --init"})," command (prefixed with either ",(0,i.jsx)(n.code,{children:"npx"})," or ",(0,i.jsx)(n.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,i.jsx)(n.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,i.jsx)(n.code,{children:'preset: "ts-jest"'})," to the ",(0,i.jsx)(n.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,i.jsx)(n.h4,{id:"customizing",children:"Customizing"}),"\n",(0,i.jsxs)(n.p,{children:["For customizing jest, please follow their ",(0,i.jsx)(n.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.code,{children:"ts-jest"})," specific options can be found ",(0,i.jsx)(n.a,{href:"options",children:"here"}),"."]})]})}function h(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(a,{...e})}):a(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>l,x:()=>r});var i=t(6540);const s={},o=i.createContext(s);function l(e){const n=i.useContext(o);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(s):e.components||s:l(e.components),i.createElement(o.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/22e01789.1fc9bd34.js b/assets/js/22e01789.1fc9bd34.js deleted file mode 100644 index e7b5239d70..0000000000 --- a/assets/js/22e01789.1fc9bd34.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2365],{9835:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>r,contentTitle:()=>c,default:()=>p,frontMatter:()=>i,metadata:()=>l,toc:()=>a});var o=t(4848),s=t(8453);const i={title:"TypeScript Config option"},c=void 0,l={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"TypeScript Config option"}},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,s.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:["The ",(0,o.jsx)(n.code,{children:"tsconfig"})," option allows you to define which ",(0,o.jsx)(n.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,o.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,o.jsxs)(n.p,{children:["By default ",(0,o.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(n.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,o.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,o.jsx)(n.code,{children:"ES2015"})," is used as ",(0,o.jsx)(n.code,{children:"target"})," instead of ",(0,o.jsx)(n.code,{children:"ES5"}),"."]}),"\n",(0,o.jsxs)(n.p,{children:["If you need to use defaults and force ",(0,o.jsx)(n.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,o.jsx)(n.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,o.jsx)(n.code,{children:"false"}),"."]}),"\n",(0,o.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsxs)(n.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,o.jsx)(n.code,{children:"tsconfig"})," 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 to start from the project root dir."]}),"\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 tsconfig: 'tsconfig.test.json',\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 "tsconfig": "tsconfig.test.json"\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 TypeScript ",(0,o.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,o.jsx)(n.code,{children:"tsconfig.json"}),"'s ",(0,o.jsx)(n.code,{children:"compilerOptions"}),"."]}),"\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 tsconfig: {\n importHelpers: 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 "tsconfig": {\n "importHelpers": true\n }\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,o.jsxs)(n.p,{children:["By default ",(0,o.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,o.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,o.jsx)(n.code,{children:"tsconfig"})," to ",(0,o.jsx)(n.code,{children:"false"}),"."]}),"\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 tsconfig: 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 "tsconfig": false\n }\n }\n }\n}\n'})})]})}function p(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.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/22e01789.f09c8603.js b/assets/js/22e01789.f09c8603.js new file mode 100644 index 0000000000..7501a23e60 --- /dev/null +++ b/assets/js/22e01789.f09c8603.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2365],{9835:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>r,contentTitle:()=>c,default:()=>p,frontMatter:()=>i,metadata:()=>l,toc:()=>a});var o=t(4848),s=t(8453);const i={title:"TypeScript Config option"},c=void 0,l={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"TypeScript Config option"}},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,s.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:["The ",(0,o.jsx)(n.code,{children:"tsconfig"})," option allows you to define which ",(0,o.jsx)(n.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,o.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,o.jsxs)(n.p,{children:["By default ",(0,o.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(n.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,o.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,o.jsx)(n.code,{children:"ES2015"})," is used as ",(0,o.jsx)(n.code,{children:"target"})," instead of ",(0,o.jsx)(n.code,{children:"ES5"}),"."]}),"\n",(0,o.jsxs)(n.p,{children:["If you need to use defaults and force ",(0,o.jsx)(n.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,o.jsx)(n.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,o.jsx)(n.code,{children:"false"}),"."]}),"\n",(0,o.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsxs)(n.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,o.jsx)(n.code,{children:"tsconfig"})," 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 to start from the project root dir."]}),"\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 tsconfig: 'tsconfig.test.json',\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 "tsconfig": "tsconfig.test.json"\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 TypeScript ",(0,o.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,o.jsx)(n.code,{children:"tsconfig.json"}),"'s ",(0,o.jsx)(n.code,{children:"compilerOptions"}),"."]}),"\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 tsconfig: {\n importHelpers: 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 "tsconfig": {\n "importHelpers": true\n }\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,o.jsxs)(n.p,{children:["By default ",(0,o.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,o.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,o.jsx)(n.code,{children:"tsconfig"})," to ",(0,o.jsx)(n.code,{children:"false"}),"."]}),"\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 tsconfig: 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 "tsconfig": false\n }\n }\n }\n}\n'})})]})}function p(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.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.5f2f5495.js b/assets/js/22f8c605.5f2f5495.js new file mode 100644 index 0000000000..3ad0a7f6fc --- /dev/null +++ b/assets/js/22f8c605.5f2f5495.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6475],{9308:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var n=s(4848),o=s(8453);const r={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},i=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/introduction.md",tags:[],version:"27.1",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,o.R)(),...t.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,n.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,n.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,n.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,n.jsx)(e.code,{children:"preset-typescript"})," ",(0,n.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,n.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,n.jsx)(e.admonition,{type:"important",children:(0,n.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,n.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,n.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,o.R)(),...t.components};return e?(0,n.jsx)(e,{...t,children:(0,n.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/22f8c605.90935336.js b/assets/js/22f8c605.90935336.js deleted file mode 100644 index f16e25891f..0000000000 --- a/assets/js/22f8c605.90935336.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6475],{9308:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var n=s(4848),o=s(8453);const r={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,o.R)(),...t.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,n.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,n.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,n.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,n.jsx)(e.code,{children:"preset-typescript"})," ",(0,n.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,n.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,n.jsx)(e.admonition,{type:"important",children:(0,n.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,n.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,n.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,o.R)(),...t.components};return e?(0,n.jsx)(e,{...t,children:(0,n.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.7b9af32a.js b/assets/js/2331e073.7b9af32a.js deleted file mode 100644 index cf3619056a..0000000000 --- a/assets/js/2331e073.7b9af32a.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1455],{9668:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>i,metadata:()=>d,toc:()=>l});var s=n(4848),o=n(8453);const i={id:"test-helpers",title:"Test helpers"},r=void 0,d={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:!1,unlisted:!1,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:1726058855e3,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"}},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={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.admonition,{type:"warning",children:(0,s.jsxs)(t.p,{children:["This function is now deprecated and will be removed in ",(0,s.jsx)(t.strong,{children:"28.0.0"}),". The function has been integrated into ",(0,s.jsx)(t.code,{children:"jest-mock"})," package\nas a part of Jest ",(0,s.jsx)(t.strong,{children:"27.4.0"}),", see ",(0,s.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,s.jsx)(t.code,{children:"jest-mock"})," instead."]})}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," provides some test utilities to be used in your test, related to TypeScript."]}),"\n",(0,s.jsx)(t.h2,{id:"mockedtitem-t-deep--false",children:(0,s.jsx)(t.code,{children:"mocked(item: T, deep = false)"})}),"\n",(0,s.jsxs)(t.p,{children:["The ",(0,s.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,s.jsx)(t.code,{children:"jest.MockInstance"}),")."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.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,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.pre,{children:(0,s.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,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(a,{...e})}):a(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>d});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 d(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/2331e073.8c1078c0.js b/assets/js/2331e073.8c1078c0.js new file mode 100644 index 0000000000..7bddffc934 --- /dev/null +++ b/assets/js/2331e073.8c1078c0.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1455],{9668:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>i,metadata:()=>d,toc:()=>l});var s=n(4848),o=n(8453);const i={id:"test-helpers",title:"Test helpers"},r=void 0,d={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/guides/test-helpers.md",tags:[],version:"27.1",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.admonition,{type:"warning",children:(0,s.jsxs)(t.p,{children:["This function is now deprecated and will be removed in ",(0,s.jsx)(t.strong,{children:"28.0.0"}),". The function has been integrated into ",(0,s.jsx)(t.code,{children:"jest-mock"})," package\nas a part of Jest ",(0,s.jsx)(t.strong,{children:"27.4.0"}),", see ",(0,s.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,s.jsx)(t.code,{children:"jest-mock"})," instead."]})}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," provides some test utilities to be used in your test, related to TypeScript."]}),"\n",(0,s.jsx)(t.h2,{id:"mockedtitem-t-deep--false",children:(0,s.jsx)(t.code,{children:"mocked(item: T, deep = false)"})}),"\n",(0,s.jsxs)(t.p,{children:["The ",(0,s.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,s.jsx)(t.code,{children:"jest.MockInstance"}),")."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.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,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.pre,{children:(0,s.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,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(a,{...e})}):a(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>d});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 d(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/2338618e.283b2c6f.js b/assets/js/2338618e.283b2c6f.js new file mode 100644 index 0000000000..1dd2eae511 --- /dev/null +++ b/assets/js/2338618e.283b2c6f.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8529],{6011:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>l,default:()=>p,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var r=n(4848),a=n(8453),s=n(9489),o=n(7227);const i={id:"migration",title:"Migration from <=23.10"},l=void 0,u={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/migration.md",tags:[],version:"29.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},c={},d=[];function m(e){const t={code:"code",em:"em",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["You can use the ",(0,r.jsx)(t.code,{children:"config:migrate"})," tool of ",(0,r.jsx)(t.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsxs)(t.em,{children:["If you're using ",(0,r.jsx)(t.code,{children:"jest.config.js"}),":"]})}),"\n",(0,r.jsxs)(s.A,{groupId:"code-examples",children:[(0,r.jsx)(o.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:migrate jest.config.js\n"})})}),(0,r.jsx)(o.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:migrate jest.config.js\n"})})})]}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsxs)(t.em,{children:["If you're using ",(0,r.jsx)(t.code,{children:"jest"})," config property of ",(0,r.jsx)(t.code,{children:"package.json"}),":"]})}),"\n",(0,r.jsxs)(s.A,{groupId:"code-examples",children:[(0,r.jsx)(o.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:migrate package.json\n"})})}),(0,r.jsx)(o.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:migrate package.json\n"})})})]})]})}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,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/2338618e.40d730c2.js b/assets/js/2338618e.40d730c2.js deleted file mode 100644 index c5a9210f10..0000000000 --- a/assets/js/2338618e.40d730c2.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8529],{6011:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>l,default:()=>p,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var r=n(4848),a=n(8453),s=n(9489),o=n(7227);const i={id:"migration",title:"Migration from <=23.10"},l=void 0,u={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:!1,unlisted:!1,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:1726058855e3,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"}},c={},d=[];function m(e){const t={code:"code",em:"em",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["You can use the ",(0,r.jsx)(t.code,{children:"config:migrate"})," tool of ",(0,r.jsx)(t.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsxs)(t.em,{children:["If you're using ",(0,r.jsx)(t.code,{children:"jest.config.js"}),":"]})}),"\n",(0,r.jsxs)(s.A,{groupId:"code-examples",children:[(0,r.jsx)(o.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:migrate jest.config.js\n"})})}),(0,r.jsx)(o.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:migrate jest.config.js\n"})})})]}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsxs)(t.em,{children:["If you're using ",(0,r.jsx)(t.code,{children:"jest"})," config property of ",(0,r.jsx)(t.code,{children:"package.json"}),":"]})}),"\n",(0,r.jsxs)(s.A,{groupId:"code-examples",children:[(0,r.jsx)(o.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:migrate package.json\n"})})}),(0,r.jsx)(o.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:migrate package.json\n"})})})]})]})}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,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.34fa946b.js b/assets/js/24991caa.34fa946b.js new file mode 100644 index 0000000000..315b81dbec --- /dev/null +++ b/assets/js/24991caa.34fa946b.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8317],{8224:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>a,frontMatter:()=>r,metadata:()=>c,toc:()=>d});var n=s(4848),o=s(8453);const r={id:"processing",title:"Processing flow"},i=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/processing.md",tags:[],version:"29.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},l={},d=[{value:"Jest process",id:"jest-process",level:2},{value:"ts-jest process",id:"ts-jest-process",level:2}];function u(e){const t={code:"code",em:"em",h2:"h2",img:"img",p:"p",...(0,o.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,n.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,n.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,n.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,o.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(u,{...e})}):u(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/24991caa.eca9bb37.js b/assets/js/24991caa.eca9bb37.js deleted file mode 100644 index 872bb6f6d7..0000000000 --- a/assets/js/24991caa.eca9bb37.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8317],{8224:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>a,frontMatter:()=>r,metadata:()=>c,toc:()=>u});var n=s(4848),o=s(8453);const r={id:"processing",title:"Processing flow"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},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,o.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,n.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,n.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,n.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,o.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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.ba29374b.js b/assets/js/265d7427.ba29374b.js deleted file mode 100644 index 147e3d7d3e..0000000000 --- a/assets/js/265d7427.ba29374b.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7556],{8307:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>i,metadata:()=>a,toc:()=>d});var s=n(4848),o=n(8453);const i={title:"Stringify content option"},r=void 0,a={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Stringify content option"}},c={},d=[{value:"Example",id:"example",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["The ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,s.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,s.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,s.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,s.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,s.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,s.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,s.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,s.jsx)(t.code,{children:"transform"})," option pointing to ",(0,s.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,s.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsxs)(t.p,{children:["In the ",(0,s.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,s.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,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.pre,{children:(0,s.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,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(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/265d7427.c3638c49.js b/assets/js/265d7427.c3638c49.js new file mode 100644 index 0000000000..814a2edbbf --- /dev/null +++ b/assets/js/265d7427.c3638c49.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7556],{8307:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>i,metadata:()=>a,toc:()=>d});var s=n(4848),o=n(8453);const i={title:"Stringify content option"},r=void 0,a={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Stringify content option"}},c={},d=[{value:"Example",id:"example",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["The ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,s.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,s.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,s.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,s.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,s.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,s.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,s.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,s.jsx)(t.code,{children:"transform"})," option pointing to ",(0,s.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,s.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsxs)(t.p,{children:["In the ",(0,s.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,s.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,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.pre,{children:(0,s.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,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(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.70df84d2.js b/assets/js/270520cb.70df84d2.js deleted file mode 100644 index 6483058e7c..0000000000 --- a/assets/js/270520cb.70df84d2.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3110],{1282:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>u,contentTitle:()=>l,default:()=>j,frontMatter:()=>a,metadata:()=>c,toc:()=>d});var n=s(4848),o=s(8453),r=s(9489),i=s(7227);const a={title:"TypeScript Config option"},l=void 0,c={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"TypeScript Config option"}},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,o.R)(),...t.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:["The ",(0,n.jsx)(e.code,{children:"tsconfig"})," option allows you to define which ",(0,n.jsx)(e.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,n.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,n.jsxs)(e.p,{children:["By default ",(0,n.jsx)(e.code,{children:"ts-jest"})," will try to find a ",(0,n.jsx)(e.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,n.jsx)(e.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,n.jsx)(e.code,{children:"ES2015"})," is used as ",(0,n.jsx)(e.code,{children:"target"})," instead of ",(0,n.jsx)(e.code,{children:"ES5"}),"."]}),"\n",(0,n.jsxs)(e.p,{children:["If you need to use defaults and force ",(0,n.jsx)(e.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,n.jsx)(e.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,n.jsx)(e.code,{children:"false"}),"."]}),"\n",(0,n.jsx)(e.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsxs)(e.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,n.jsx)(e.code,{children:"tsconfig"})," file"]}),"\n",(0,n.jsxs)(e.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,n.jsx)(e.code,{children:""})," in the path to start from the project root dir."]}),"\n",(0,n.jsxs)(r.A,{groupId:"code-examples",children:[(0,n.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"JSON",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(e.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,n.jsxs)(e.p,{children:["Refer to the TypeScript ",(0,n.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,n.jsx)(e.code,{children:"tsconfig.json"}),"'s ",(0,n.jsx)(e.code,{children:"compilerOptions"}),"."]}),"\n",(0,n.jsxs)(r.A,{groupId:"code-examples",children:[(0,n.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"JSON",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(e.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,n.jsxs)(e.p,{children:["By default ",(0,n.jsx)(e.code,{children:"ts-jest"})," will try to find a ",(0,n.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,n.jsx)(e.code,{children:"tsconfig"})," to ",(0,n.jsx)(e.code,{children:"false"}),"."]}),"\n",(0,n.jsxs)(r.A,{groupId:"code-examples",children:[(0,n.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"JSON",children:(0,n.jsx)(e.pre,{children:(0,n.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,o.R)(),...t.components};return e?(0,n.jsx)(e,{...t,children:(0,n.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/270520cb.d5b3460d.js b/assets/js/270520cb.d5b3460d.js new file mode 100644 index 0000000000..c6dc4e152f --- /dev/null +++ b/assets/js/270520cb.d5b3460d.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3110],{1282:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>u,contentTitle:()=>l,default:()=>j,frontMatter:()=>a,metadata:()=>c,toc:()=>d});var n=s(4848),o=s(8453),r=s(9489),i=s(7227);const a={title:"TypeScript Config option"},l=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"TypeScript Config option"}},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,o.R)(),...t.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:["The ",(0,n.jsx)(e.code,{children:"tsconfig"})," option allows you to define which ",(0,n.jsx)(e.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,n.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,n.jsxs)(e.p,{children:["By default ",(0,n.jsx)(e.code,{children:"ts-jest"})," will try to find a ",(0,n.jsx)(e.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,n.jsx)(e.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,n.jsx)(e.code,{children:"ES2015"})," is used as ",(0,n.jsx)(e.code,{children:"target"})," instead of ",(0,n.jsx)(e.code,{children:"ES5"}),"."]}),"\n",(0,n.jsxs)(e.p,{children:["If you need to use defaults and force ",(0,n.jsx)(e.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,n.jsx)(e.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,n.jsx)(e.code,{children:"false"}),"."]}),"\n",(0,n.jsx)(e.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsxs)(e.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,n.jsx)(e.code,{children:"tsconfig"})," file"]}),"\n",(0,n.jsxs)(e.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,n.jsx)(e.code,{children:""})," in the path to start from the project root dir."]}),"\n",(0,n.jsxs)(r.A,{groupId:"code-examples",children:[(0,n.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"JSON",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(e.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,n.jsxs)(e.p,{children:["Refer to the TypeScript ",(0,n.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,n.jsx)(e.code,{children:"tsconfig.json"}),"'s ",(0,n.jsx)(e.code,{children:"compilerOptions"}),"."]}),"\n",(0,n.jsxs)(r.A,{groupId:"code-examples",children:[(0,n.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"JSON",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(e.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,n.jsxs)(e.p,{children:["By default ",(0,n.jsx)(e.code,{children:"ts-jest"})," will try to find a ",(0,n.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,n.jsx)(e.code,{children:"tsconfig"})," to ",(0,n.jsx)(e.code,{children:"false"}),"."]}),"\n",(0,n.jsxs)(r.A,{groupId:"code-examples",children:[(0,n.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"JSON",children:(0,n.jsx)(e.pre,{children:(0,n.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,o.R)(),...t.components};return e?(0,n.jsx)(e,{...t,children:(0,n.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.d377a367.js b/assets/js/295b567d.d377a367.js new file mode 100644 index 0000000000..45708a28ce --- /dev/null +++ b/assets/js/295b567d.d377a367.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3549],{644:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>l,default:()=>p,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var r=n(4848),a=n(8453),s=n(9489),o=n(7227);const i={id:"migration",title:"Migration from <=23.10"},l=void 0,u={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/migration.md",tags:[],version:"current",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},c={},d=[];function m(e){const t={code:"code",em:"em",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["You can use the ",(0,r.jsx)(t.code,{children:"config:migrate"})," tool of ",(0,r.jsx)(t.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsxs)(t.em,{children:["If you're using ",(0,r.jsx)(t.code,{children:"jest.config.js"}),":"]})}),"\n",(0,r.jsxs)(s.A,{groupId:"code-examples",children:[(0,r.jsx)(o.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:migrate jest.config.js\n"})})}),(0,r.jsx)(o.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:migrate jest.config.js\n"})})})]}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsxs)(t.em,{children:["If you're using ",(0,r.jsx)(t.code,{children:"jest"})," config property of ",(0,r.jsx)(t.code,{children:"package.json"}),":"]})}),"\n",(0,r.jsxs)(s.A,{groupId:"code-examples",children:[(0,r.jsx)(o.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:migrate package.json\n"})})}),(0,r.jsx)(o.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:migrate package.json\n"})})})]})]})}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,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/295b567d.e093363a.js b/assets/js/295b567d.e093363a.js deleted file mode 100644 index 995492e9e5..0000000000 --- a/assets/js/295b567d.e093363a.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3549],{644:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>l,default:()=>p,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var r=n(4848),a=n(8453),s=n(9489),o=n(7227);const i={id:"migration",title:"Migration from <=23.10"},l=void 0,u={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/migration.md",tags:[],version:"current",lastUpdatedBy:"renovate[bot]",lastUpdatedAt:1726058855e3,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"}},c={},d=[];function m(e){const t={code:"code",em:"em",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["You can use the ",(0,r.jsx)(t.code,{children:"config:migrate"})," tool of ",(0,r.jsx)(t.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsxs)(t.em,{children:["If you're using ",(0,r.jsx)(t.code,{children:"jest.config.js"}),":"]})}),"\n",(0,r.jsxs)(s.A,{groupId:"code-examples",children:[(0,r.jsx)(o.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:migrate jest.config.js\n"})})}),(0,r.jsx)(o.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:migrate jest.config.js\n"})})})]}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsxs)(t.em,{children:["If you're using ",(0,r.jsx)(t.code,{children:"jest"})," config property of ",(0,r.jsx)(t.code,{children:"package.json"}),":"]})}),"\n",(0,r.jsxs)(s.A,{groupId:"code-examples",children:[(0,r.jsx)(o.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:migrate package.json\n"})})}),(0,r.jsx)(o.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:migrate package.json\n"})})})]})]})}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,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.3fdf1216.js b/assets/js/2a3bd03a.3fdf1216.js new file mode 100644 index 0000000000..769e9fd138 --- /dev/null +++ b/assets/js/2a3bd03a.3fdf1216.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6399],{7287:(t,e,o)=>{o.r(e),o.d(e,{assets:()=>d,contentTitle:()=>r,default:()=>h,frontMatter:()=>i,metadata:()=>u,toc:()=>c});var s=o(4848),n=o(8453);const i={id:"troubleshooting",title:"Troubleshooting"},r=void 0,u={id:"guides/troubleshooting",title:"Troubleshooting",description:"You can check Jest troubleshooting guide or visit ts-jest [troubleshooting",source:"@site/versioned_docs/version-27.1/guides/troubleshooting.md",sourceDirName:"guides",slug:"/guides/troubleshooting",permalink:"/ts-jest/docs/27.1/guides/troubleshooting",draft:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/guides/troubleshooting.md",tags:[],version:"27.1",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},c=[];function l(t){const e={a:"a",code:"code",p:"p",...(0,n.R)(),...t.components};return(0,s.jsxs)(e.p,{children:["You can check Jest ",(0,s.jsx)(e.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," or visit ",(0,s.jsx)(e.code,{children:"ts-jest"})," ",(0,s.jsx)(e.a,{href:"https://github.com/kulshekhar/ts-jest/blob/main/TROUBLESHOOTING.md",children:"troubleshooting\nguide"})]})}function h(t={}){const{wrapper:e}={...(0,n.R)(),...t.components};return e?(0,s.jsx)(e,{...t,children:(0,s.jsx)(l,{...t})}):l(t)}},8453:(t,e,o)=>{o.d(e,{R:()=>r,x:()=>u});var s=o(6540);const n={},i=s.createContext(n);function r(t){const e=s.useContext(i);return s.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function u(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(n):t.components||n:r(t.components),s.createElement(i.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/2a3bd03a.a2168a19.js b/assets/js/2a3bd03a.a2168a19.js deleted file mode 100644 index 40380bd442..0000000000 --- a/assets/js/2a3bd03a.a2168a19.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6399],{7287:(t,e,o)=>{o.r(e),o.d(e,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var s=o(4848),n=o(8453);const i={id:"troubleshooting",title:"Troubleshooting"},r=void 0,u={id:"guides/troubleshooting",title:"Troubleshooting",description:"You can check Jest troubleshooting guide or visit ts-jest [troubleshooting",source:"@site/versioned_docs/version-27.1/guides/troubleshooting.md",sourceDirName:"guides",slug:"/guides/troubleshooting",permalink:"/ts-jest/docs/27.1/guides/troubleshooting",draft:!1,unlisted:!1,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:1726058855e3,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"}},c={},d=[];function l(t){const e={a:"a",code:"code",p:"p",...(0,n.R)(),...t.components};return(0,s.jsxs)(e.p,{children:["You can check Jest ",(0,s.jsx)(e.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," or visit ",(0,s.jsx)(e.code,{children:"ts-jest"})," ",(0,s.jsx)(e.a,{href:"https://github.com/kulshekhar/ts-jest/blob/main/TROUBLESHOOTING.md",children:"troubleshooting\nguide"})]})}function h(t={}){const{wrapper:e}={...(0,n.R)(),...t.components};return e?(0,s.jsx)(e,{...t,children:(0,s.jsx)(l,{...t})}):l(t)}},8453:(t,e,o)=>{o.d(e,{R:()=>r,x:()=>u});var s=o(6540);const n={},i=s.createContext(n);function r(t){const e=s.useContext(i);return s.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function u(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(n):t.components||n:r(t.components),s.createElement(i.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/2b68f68f.8f4b837e.js b/assets/js/2b68f68f.8f4b837e.js deleted file mode 100644 index d4cde129ab..0000000000 --- a/assets/js/2b68f68f.8f4b837e.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4519],{912:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>l,default:()=>h,frontMatter:()=>o,metadata:()=>r,toc:()=>d});var i=t(4848),s=t(8453);const o={id:"installation",title:"Installation"},l=void 0,r={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:!1,unlisted:!1,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:1726058855e3,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"}},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 n={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,i.jsxs)(n.p,{children:["You can install ",(0,i.jsx)(n.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,i.jsx)(n.h4,{id:"npm",children:"NPM"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(n.h4,{id:"yarn",children:"Yarn"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:["Tip: If you get an error with the following ",(0,i.jsx)(n.code,{children:"npm"})," commands such as ",(0,i.jsx)(n.code,{children:"npx: command not found"}),", you can replace ",(0,i.jsx)(n.code,{children:"npx XXX"})," with ",(0,i.jsx)(n.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,i.jsx)(n.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,i.jsx)(n.h4,{id:"creating",children:"Creating"}),"\n",(0,i.jsxs)(n.p,{children:["By default, Jest can run without any config files, but it will not compile ",(0,i.jsx)(n.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,i.jsx)(n.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,i.jsx)(n.code,{children:"ts-jest"})," preset."]}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,i.jsx)(n.h4,{id:"npm-1",children:"NPM"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:init\n"})}),"\n",(0,i.jsx)(n.h4,{id:"yarn-1",children:"Yarn"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:init\n"})}),"\n",(0,i.jsxs)(n.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,i.jsx)(n.code,{children:".ts"})," files correctly."]}),"\n",(0,i.jsxs)(n.p,{children:["You can also use the ",(0,i.jsx)(n.code,{children:"jest --init"})," command (prefixed with either ",(0,i.jsx)(n.code,{children:"npx"})," or ",(0,i.jsx)(n.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,i.jsx)(n.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,i.jsx)(n.code,{children:'preset: "ts-jest"'})," to the ",(0,i.jsx)(n.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,i.jsx)(n.h4,{id:"customizing",children:"Customizing"}),"\n",(0,i.jsxs)(n.p,{children:["For customizing jest, please follow their ",(0,i.jsx)(n.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.code,{children:"ts-jest"})," specific options can be found ",(0,i.jsx)(n.a,{href:"options",children:"here"}),"."]})]})}function h(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(a,{...e})}):a(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>l,x:()=>r});var i=t(6540);const s={},o=i.createContext(s);function l(e){const n=i.useContext(o);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(s):e.components||s:l(e.components),i.createElement(o.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/2b68f68f.f6f3ff83.js b/assets/js/2b68f68f.f6f3ff83.js new file mode 100644 index 0000000000..8b6fb40d40 --- /dev/null +++ b/assets/js/2b68f68f.f6f3ff83.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4519],{912:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>l,default:()=>h,frontMatter:()=>o,metadata:()=>r,toc:()=>d});var i=t(4848),s=t(8453);const o={id:"installation",title:"Installation"},l=void 0,r={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/installation.md",tags:[],version:"27.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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 n={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,i.jsxs)(n.p,{children:["You can install ",(0,i.jsx)(n.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,i.jsx)(n.h4,{id:"npm",children:"NPM"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(n.h4,{id:"yarn",children:"Yarn"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:["Tip: If you get an error with the following ",(0,i.jsx)(n.code,{children:"npm"})," commands such as ",(0,i.jsx)(n.code,{children:"npx: command not found"}),", you can replace ",(0,i.jsx)(n.code,{children:"npx XXX"})," with ",(0,i.jsx)(n.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,i.jsx)(n.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,i.jsx)(n.h4,{id:"creating",children:"Creating"}),"\n",(0,i.jsxs)(n.p,{children:["By default, Jest can run without any config files, but it will not compile ",(0,i.jsx)(n.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,i.jsx)(n.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,i.jsx)(n.code,{children:"ts-jest"})," preset."]}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,i.jsx)(n.h4,{id:"npm-1",children:"NPM"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:init\n"})}),"\n",(0,i.jsx)(n.h4,{id:"yarn-1",children:"Yarn"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:init\n"})}),"\n",(0,i.jsxs)(n.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,i.jsx)(n.code,{children:".ts"})," files correctly."]}),"\n",(0,i.jsxs)(n.p,{children:["You can also use the ",(0,i.jsx)(n.code,{children:"jest --init"})," command (prefixed with either ",(0,i.jsx)(n.code,{children:"npx"})," or ",(0,i.jsx)(n.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,i.jsx)(n.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,i.jsx)(n.code,{children:'preset: "ts-jest"'})," to the ",(0,i.jsx)(n.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,i.jsx)(n.h4,{id:"customizing",children:"Customizing"}),"\n",(0,i.jsxs)(n.p,{children:["For customizing jest, please follow their ",(0,i.jsx)(n.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.code,{children:"ts-jest"})," specific options can be found ",(0,i.jsx)(n.a,{href:"options",children:"here"}),"."]})]})}function h(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(a,{...e})}):a(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>l,x:()=>r});var i=t(6540);const s={},o=i.createContext(s);function l(e){const n=i.useContext(o);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(s):e.components||s:l(e.components),i.createElement(o.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/2b77ff19.0d771dbc.js b/assets/js/2b77ff19.0d771dbc.js deleted file mode 100644 index c51224105b..0000000000 --- a/assets/js/2b77ff19.0d771dbc.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3951],{7597:(t,e,o)=>{o.r(e),o.d(e,{assets:()=>c,contentTitle:()=>r,default:()=>a,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var s=o(4848),n=o(8453);const i={id:"troubleshooting",title:"Troubleshooting"},r=void 0,u={id:"guides/troubleshooting",title:"Troubleshooting",description:"You can check Jest troubleshooting guide or visit ts-jest [troubleshooting",source:"@site/versioned_docs/version-29.2/guides/troubleshooting.md",sourceDirName:"guides",slug:"/guides/troubleshooting",permalink:"/ts-jest/docs/guides/troubleshooting",draft:!1,unlisted:!1,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:1726058855e3,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"}},c={},d=[];function l(t){const e={a:"a",code:"code",p:"p",...(0,n.R)(),...t.components};return(0,s.jsxs)(e.p,{children:["You can check Jest ",(0,s.jsx)(e.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," or visit ",(0,s.jsx)(e.code,{children:"ts-jest"})," ",(0,s.jsx)(e.a,{href:"https://github.com/kulshekhar/ts-jest/blob/main/TROUBLESHOOTING.md",children:"troubleshooting\nguide"})]})}function a(t={}){const{wrapper:e}={...(0,n.R)(),...t.components};return e?(0,s.jsx)(e,{...t,children:(0,s.jsx)(l,{...t})}):l(t)}},8453:(t,e,o)=>{o.d(e,{R:()=>r,x:()=>u});var s=o(6540);const n={},i=s.createContext(n);function r(t){const e=s.useContext(i);return s.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function u(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(n):t.components||n:r(t.components),s.createElement(i.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/2b77ff19.e9a83eba.js b/assets/js/2b77ff19.e9a83eba.js new file mode 100644 index 0000000000..ea52dbd33b --- /dev/null +++ b/assets/js/2b77ff19.e9a83eba.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3951],{7597:(t,e,o)=>{o.r(e),o.d(e,{assets:()=>c,contentTitle:()=>r,default:()=>a,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var s=o(4848),n=o(8453);const i={id:"troubleshooting",title:"Troubleshooting"},r=void 0,u={id:"guides/troubleshooting",title:"Troubleshooting",description:"You can check Jest troubleshooting guide or visit ts-jest [troubleshooting",source:"@site/versioned_docs/version-29.2/guides/troubleshooting.md",sourceDirName:"guides",slug:"/guides/troubleshooting",permalink:"/ts-jest/docs/guides/troubleshooting",draft:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/guides/troubleshooting.md",tags:[],version:"29.2",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},c={},d=[];function l(t){const e={a:"a",code:"code",p:"p",...(0,n.R)(),...t.components};return(0,s.jsxs)(e.p,{children:["You can check Jest ",(0,s.jsx)(e.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," or visit ",(0,s.jsx)(e.code,{children:"ts-jest"})," ",(0,s.jsx)(e.a,{href:"https://github.com/kulshekhar/ts-jest/blob/main/TROUBLESHOOTING.md",children:"troubleshooting\nguide"})]})}function a(t={}){const{wrapper:e}={...(0,n.R)(),...t.components};return e?(0,s.jsx)(e,{...t,children:(0,s.jsx)(l,{...t})}):l(t)}},8453:(t,e,o)=>{o.d(e,{R:()=>r,x:()=>u});var s=o(6540);const n={},i=s.createContext(n);function r(t){const e=s.useContext(i);return s.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function u(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(n):t.components||n:r(t.components),s.createElement(i.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/2b94ed59.4de22409.js b/assets/js/2b94ed59.4de22409.js new file mode 100644 index 0000000000..440e4cee7f --- /dev/null +++ b/assets/js/2b94ed59.4de22409.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6797],{4510:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>a,frontMatter:()=>i,metadata:()=>l,toc:()=>p});var n=o(4848),s=o(8453);const i={title:"Compiler option"},r=void 0,l={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Compiler option"}},c={},p=[{value:"Example",id:"example",level:3}];function d(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["The ",(0,n.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,n.jsxs)(t.p,{children:["The default value is ",(0,n.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,n.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,n.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,n.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,n.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,n.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.pre,{children:(0,n.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,s.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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/2b94ed59.be4d813b.js b/assets/js/2b94ed59.be4d813b.js deleted file mode 100644 index efec3fd24b..0000000000 --- a/assets/js/2b94ed59.be4d813b.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6797],{4510:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>a,frontMatter:()=>i,metadata:()=>l,toc:()=>p});var n=o(4848),s=o(8453);const i={title:"Compiler option"},r=void 0,l={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Compiler option"}},c={},p=[{value:"Example",id:"example",level:3}];function d(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["The ",(0,n.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,n.jsxs)(t.p,{children:["The default value is ",(0,n.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,n.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,n.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,n.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,n.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,n.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.pre,{children:(0,n.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,s.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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.6e515fbe.js b/assets/js/2bccb399.6e515fbe.js new file mode 100644 index 0000000000..48942aa3a6 --- /dev/null +++ b/assets/js/2bccb399.6e515fbe.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5154],{1416:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>h,frontMatter:()=>l,metadata:()=>i,toc:()=>d});var r=n(4848),a=n(8453),s=n(9489),o=n(7227);const l={id:"debugging",title:"Debugging ts-jest"},u=void 0,i={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/debugging.md",tags:[],version:"current",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{id:"debugging",title:"Debugging ts-jest"},sidebar:"docs",previous:{title:"Migration from <=23.10",permalink:"/ts-jest/docs/next/migration"}},c={},d=[];function g(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["You can activate the debug logger by setting the environment variable ",(0,r.jsx)(t.code,{children:"TS_JEST_LOG"})," before running tests.\nThe output of the logger will be in ",(0,r.jsx)(t.strong,{children:"ts-jest.log"})," in current working directory."]}),"\n",(0,r.jsxs)(t.p,{children:["The debug logger contains some useful information about how internal ",(0,r.jsx)(t.code,{children:"ts-jest"})," works, including which files are processed,\nwhich Jest config or TypeScript config is used etc."]}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{children:"export TS_JEST_LOG=ts-jest.log\n"})}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsx)(t.strong,{children:"Windows"})}),"\n",(0,r.jsxs)(s.A,{groupId:"code-examples",children:[(0,r.jsx)(o.A,{value:"Command",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-Command",metastring:"Prompt tab",children:"set TS_JEST_LOG=ts-jest.log\n"})})}),(0,r.jsx)(o.A,{value:"PowerShell",children:(0,r.jsx)(t.pre,{children:(0,r.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,r.jsx)(t,{...e,children:(0,r.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/2bccb399.e602fd63.js b/assets/js/2bccb399.e602fd63.js deleted file mode 100644 index 430fe262fb..0000000000 --- a/assets/js/2bccb399.e602fd63.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5154],{1416:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>h,frontMatter:()=>l,metadata:()=>i,toc:()=>d});var r=n(4848),a=n(8453),s=n(9489),o=n(7227);const l={id:"debugging",title:"Debugging ts-jest"},u=void 0,i={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/debugging.md",tags:[],version:"current",lastUpdatedBy:"renovate[bot]",lastUpdatedAt:1726058855e3,frontMatter:{id:"debugging",title:"Debugging ts-jest"},sidebar:"docs",previous:{title:"Migration from <=23.10",permalink:"/ts-jest/docs/next/migration"}},c={},d=[];function g(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["You can activate the debug logger by setting the environment variable ",(0,r.jsx)(t.code,{children:"TS_JEST_LOG"})," before running tests.\nThe output of the logger will be in ",(0,r.jsx)(t.strong,{children:"ts-jest.log"})," in current working directory."]}),"\n",(0,r.jsxs)(t.p,{children:["The debug logger contains some useful information about how internal ",(0,r.jsx)(t.code,{children:"ts-jest"})," works, including which files are processed,\nwhich Jest config or TypeScript config is used etc."]}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{children:"export TS_JEST_LOG=ts-jest.log\n"})}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsx)(t.strong,{children:"Windows"})}),"\n",(0,r.jsxs)(s.A,{groupId:"code-examples",children:[(0,r.jsx)(o.A,{value:"Command",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-Command",metastring:"Prompt tab",children:"set TS_JEST_LOG=ts-jest.log\n"})})}),(0,r.jsx)(o.A,{value:"PowerShell",children:(0,r.jsx)(t.pre,{children:(0,r.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,r.jsx)(t,{...e,children:(0,r.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/6f82a5f4.08d8ce41.js b/assets/js/2c53b5e4.66f0dfe2.js similarity index 74% rename from assets/js/6f82a5f4.08d8ce41.js rename to assets/js/2c53b5e4.66f0dfe2.js index 4f5c026bd3..c45593f96f 100644 --- a/assets/js/6f82a5f4.08d8ce41.js +++ b/assets/js/2c53b5e4.66f0dfe2.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3429],{9643:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>p,frontMatter:()=>i,metadata:()=>d,toc:()=>l});var o=s(4848),n=s(8453);const i={id:"test-helpers",title:"Test helpers"},r=void 0,d={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:!1,unlisted:!1,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:1726058855e3,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"}},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,n.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(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 p(e={}){const{wrapper:t}={...(0,n.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:()=>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],{59:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>p,frontMatter:()=>i,metadata:()=>d,toc:()=>l});var o=s(4848),n=s(8453);const i={id:"test-helpers",title:"Test helpers"},r=void 0,d={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/guides/test-helpers.md",tags:[],version:"27.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,n.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(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 p(e={}){const{wrapper:t}={...(0,n.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:()=>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/2c53b5e4.ab26183e.js b/assets/js/2c53b5e4.ab26183e.js deleted file mode 100644 index 1752802606..0000000000 --- a/assets/js/2c53b5e4.ab26183e.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8282],{59:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>p,frontMatter:()=>i,metadata:()=>d,toc:()=>l});var o=s(4848),n=s(8453);const i={id:"test-helpers",title:"Test helpers"},r=void 0,d={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:!1,unlisted:!1,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:1726058855e3,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"}},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,n.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(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 p(e={}){const{wrapper:t}={...(0,n.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:()=>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.0b66c0c6.js b/assets/js/2d143bed.0b66c0c6.js new file mode 100644 index 0000000000..ab278796f9 --- /dev/null +++ b/assets/js/2d143bed.0b66c0c6.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1154],{6956:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>p,frontMatter:()=>o,metadata:()=>c,toc:()=>l});var s=n(4848),i=n(8453);const o={id:"babel7-or-ts",title:"Babel7 or TypeScript"},r=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/babel7-or-ts.md",tags:[],version:"29.2",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,s.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,s.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,s.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,s.jsxs)(t.p,{children:["While ",(0,s.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,s.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,s.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,s.jsxs)(t.p,{children:["This is the big ",(0,s.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,s.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,s.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,s.jsx)(t.code,{children:"namespace"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,s.jsx)(t.code,{children:"const enum"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,s.jsx)(t.code,{children:"enum"}),", ",(0,s.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,s.jsxs)(t.p,{children:["You won't be able to do ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,s.jsx)(t.code,{children:"import"}),"/",(0,s.jsx)(t.code,{children:"export"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(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,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/2d143bed.587b1f02.js b/assets/js/2d143bed.587b1f02.js deleted file mode 100644 index f2e064605c..0000000000 --- a/assets/js/2d143bed.587b1f02.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1154],{6956:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>p,frontMatter:()=>o,metadata:()=>c,toc:()=>l});var s=n(4848),i=n(8453);const o={id:"babel7-or-ts",title:"Babel7 or TypeScript"},r=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},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,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,s.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,s.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,s.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,s.jsxs)(t.p,{children:["While ",(0,s.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,s.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,s.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,s.jsxs)(t.p,{children:["This is the big ",(0,s.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,s.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,s.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,s.jsx)(t.code,{children:"namespace"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,s.jsx)(t.code,{children:"const enum"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,s.jsx)(t.code,{children:"enum"}),", ",(0,s.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,s.jsxs)(t.p,{children:["You won't be able to do ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,s.jsx)(t.code,{children:"import"}),"/",(0,s.jsx)(t.code,{children:"export"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(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,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.5535d459.js b/assets/js/2e89f3c4.5535d459.js new file mode 100644 index 0000000000..94f61982e4 --- /dev/null +++ b/assets/js/2e89f3c4.5535d459.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4937],{5254:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>l,default:()=>h,frontMatter:()=>i,metadata:()=>d,toc:()=>c});var s=n(4848),o=n(8453);const i={title:"Isolated Modules option"},l=void 0,d={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Isolated Modules option"}},a={},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,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default ",(0,s.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,s.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,s.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,s.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,s.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,s.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\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 isolatedModules: true,\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 "isolatedModules": true\n }\n }\n }\n}\n'})}),"\n",(0,s.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,s.jsxs)(t.p,{children:["Using ",(0,s.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,s.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,s.jsx)(t.code,{children:"include"})," in ",(0,s.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,s.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,s.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,s.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,s.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,s.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,s.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,s.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,s.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,s.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,s.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function h(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(r,{...e})}):r(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>l,x:()=>d});var s=n(6540);const o={},i=s.createContext(o);function l(e){const t=s.useContext(i);return s.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(o):e.components||o:l(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/2e89f3c4.72f8aa45.js b/assets/js/2e89f3c4.72f8aa45.js deleted file mode 100644 index c085c3830e..0000000000 --- a/assets/js/2e89f3c4.72f8aa45.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4937],{5254:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>l,default:()=>h,frontMatter:()=>i,metadata:()=>a,toc:()=>c});var s=n(4848),o=n(8453);const i={title:"Isolated Modules option"},l=void 0,a={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Isolated Modules option"}},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,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default ",(0,s.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,s.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,s.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,s.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,s.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,s.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\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 isolatedModules: true,\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 "isolatedModules": true\n }\n }\n }\n}\n'})}),"\n",(0,s.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,s.jsxs)(t.p,{children:["Using ",(0,s.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,s.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,s.jsx)(t.code,{children:"include"})," in ",(0,s.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,s.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,s.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,s.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,s.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,s.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,s.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,s.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,s.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,s.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,s.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function h(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(r,{...e})}):r(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>l,x:()=>a});var s=n(6540);const o={},i=s.createContext(o);function l(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:l(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/304054d0.29aade62.js b/assets/js/304054d0.29aade62.js new file mode 100644 index 0000000000..9ffc87fe32 --- /dev/null +++ b/assets/js/304054d0.29aade62.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5501],{772:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>u,contentTitle:()=>l,default:()=>j,frontMatter:()=>a,metadata:()=>c,toc:()=>d});var n=s(4848),o=s(8453),r=s(9489),i=s(7227);const a={title:"TypeScript Config option"},l=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"TypeScript Config option"}},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,o.R)(),...t.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:["The ",(0,n.jsx)(e.code,{children:"tsconfig"})," option allows you to define which ",(0,n.jsx)(e.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,n.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,n.jsxs)(e.p,{children:["By default ",(0,n.jsx)(e.code,{children:"ts-jest"})," will try to find a ",(0,n.jsx)(e.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,n.jsx)(e.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,n.jsx)(e.code,{children:"ES2015"})," is used as ",(0,n.jsx)(e.code,{children:"target"})," instead of ",(0,n.jsx)(e.code,{children:"ES5"}),"."]}),"\n",(0,n.jsxs)(e.p,{children:["If you need to use defaults and force ",(0,n.jsx)(e.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,n.jsx)(e.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,n.jsx)(e.code,{children:"false"}),"."]}),"\n",(0,n.jsx)(e.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsxs)(e.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,n.jsx)(e.code,{children:"tsconfig"})," file"]}),"\n",(0,n.jsxs)(e.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,n.jsx)(e.code,{children:""})," in the path to start from the project root dir."]}),"\n",(0,n.jsxs)(r.A,{groupId:"code-examples",children:[(0,n.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"JSON",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(e.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,n.jsxs)(e.p,{children:["Refer to the TypeScript ",(0,n.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,n.jsx)(e.code,{children:"tsconfig.json"}),"'s ",(0,n.jsx)(e.code,{children:"compilerOptions"}),"."]}),"\n",(0,n.jsxs)(r.A,{groupId:"code-examples",children:[(0,n.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"JSON",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(e.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,n.jsxs)(e.p,{children:["By default ",(0,n.jsx)(e.code,{children:"ts-jest"})," will try to find a ",(0,n.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,n.jsx)(e.code,{children:"tsconfig"})," to ",(0,n.jsx)(e.code,{children:"false"}),"."]}),"\n",(0,n.jsxs)(r.A,{groupId:"code-examples",children:[(0,n.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"JSON",children:(0,n.jsx)(e.pre,{children:(0,n.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,o.R)(),...t.components};return e?(0,n.jsx)(e,{...t,children:(0,n.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/304054d0.ae6deb60.js b/assets/js/304054d0.ae6deb60.js deleted file mode 100644 index 3b54530655..0000000000 --- a/assets/js/304054d0.ae6deb60.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5501],{772:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>u,contentTitle:()=>l,default:()=>j,frontMatter:()=>a,metadata:()=>c,toc:()=>d});var n=s(4848),o=s(8453),r=s(9489),i=s(7227);const a={title:"TypeScript Config option"},l=void 0,c={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"TypeScript Config option"}},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,o.R)(),...t.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:["The ",(0,n.jsx)(e.code,{children:"tsconfig"})," option allows you to define which ",(0,n.jsx)(e.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,n.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,n.jsxs)(e.p,{children:["By default ",(0,n.jsx)(e.code,{children:"ts-jest"})," will try to find a ",(0,n.jsx)(e.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,n.jsx)(e.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,n.jsx)(e.code,{children:"ES2015"})," is used as ",(0,n.jsx)(e.code,{children:"target"})," instead of ",(0,n.jsx)(e.code,{children:"ES5"}),"."]}),"\n",(0,n.jsxs)(e.p,{children:["If you need to use defaults and force ",(0,n.jsx)(e.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,n.jsx)(e.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,n.jsx)(e.code,{children:"false"}),"."]}),"\n",(0,n.jsx)(e.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsxs)(e.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,n.jsx)(e.code,{children:"tsconfig"})," file"]}),"\n",(0,n.jsxs)(e.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,n.jsx)(e.code,{children:""})," in the path to start from the project root dir."]}),"\n",(0,n.jsxs)(r.A,{groupId:"code-examples",children:[(0,n.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"JSON",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(e.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,n.jsxs)(e.p,{children:["Refer to the TypeScript ",(0,n.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,n.jsx)(e.code,{children:"tsconfig.json"}),"'s ",(0,n.jsx)(e.code,{children:"compilerOptions"}),"."]}),"\n",(0,n.jsxs)(r.A,{groupId:"code-examples",children:[(0,n.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"JSON",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(e.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,n.jsxs)(e.p,{children:["By default ",(0,n.jsx)(e.code,{children:"ts-jest"})," will try to find a ",(0,n.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,n.jsx)(e.code,{children:"tsconfig"})," to ",(0,n.jsx)(e.code,{children:"false"}),"."]}),"\n",(0,n.jsxs)(r.A,{groupId:"code-examples",children:[(0,n.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"JSON",children:(0,n.jsx)(e.pre,{children:(0,n.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,o.R)(),...t.components};return e?(0,n.jsx)(e,{...t,children:(0,n.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.136b7aca.js b/assets/js/334e0bf3.136b7aca.js new file mode 100644 index 0000000000..200d83ff6a --- /dev/null +++ b/assets/js/334e0bf3.136b7aca.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3723],{2378:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>a,frontMatter:()=>i,metadata:()=>c,toc:()=>u});var s=o(4848),n=o(8453);const i={id:"using-with-monorepo",title:"Using with monorepo"},r=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},u=[];function p(e){const t={a:"a",code:"code",p:"p",strong:"strong",...(0,n.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["To use ",(0,s.jsx)(t.code,{children:"ts-jest"})," in a project with monorepo structure, you'll need to use ",(0,s.jsx)(t.a,{href:"https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig",children:"Jest projects configuration"}),"."]}),"\n",(0,s.jsxs)(t.p,{children:["When using Jest ",(0,s.jsx)(t.code,{children:"projects"})," configuration, Jest will run ",(0,s.jsx)(t.code,{children:"ts-jest"})," against each project which is defined in the configuration."]}),"\n",(0,s.jsxs)(t.p,{children:["One should not be confused between the term ",(0,s.jsx)(t.strong,{children:"monorepo"})," vs TypeScript ",(0,s.jsx)(t.strong,{children:"project references"}),". These are 2 different terms."]})]})}function a(e={}){const{wrapper:t}={...(0,n.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(p,{...e})}):p(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/334e0bf3.d1e13fc1.js b/assets/js/334e0bf3.d1e13fc1.js deleted file mode 100644 index 3f0d127883..0000000000 --- a/assets/js/334e0bf3.d1e13fc1.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3723],{2378:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>a,frontMatter:()=>i,metadata:()=>c,toc:()=>u});var s=o(4848),n=o(8453);const i={id:"using-with-monorepo",title:"Using with monorepo"},r=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},d={},u=[];function p(e){const t={a:"a",code:"code",p:"p",strong:"strong",...(0,n.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["To use ",(0,s.jsx)(t.code,{children:"ts-jest"})," in a project with monorepo structure, you'll need to use ",(0,s.jsx)(t.a,{href:"https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig",children:"Jest projects configuration"}),"."]}),"\n",(0,s.jsxs)(t.p,{children:["When using Jest ",(0,s.jsx)(t.code,{children:"projects"})," configuration, Jest will run ",(0,s.jsx)(t.code,{children:"ts-jest"})," against each project which is defined in the configuration."]}),"\n",(0,s.jsxs)(t.p,{children:["One should not be confused between the term ",(0,s.jsx)(t.strong,{children:"monorepo"})," vs TypeScript ",(0,s.jsx)(t.strong,{children:"project references"}),". These are 2 different terms."]})]})}function a(e={}){const{wrapper:t}={...(0,n.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(p,{...e})}):p(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/3432663a.15464016.js b/assets/js/3432663a.15464016.js deleted file mode 100644 index 435c0ed93c..0000000000 --- a/assets/js/3432663a.15464016.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9345],{5570:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>a,contentTitle:()=>r,default:()=>g,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var s=t(4848),o=t(8453);const i={id:"migration",title:"Migration from <=23.10"},r=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},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,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(n.p,{children:["You can use the ",(0,s.jsx)(n.code,{children:"config:migrate"})," tool of ",(0,s.jsx)(n.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsxs)(n.em,{children:["If you're using ",(0,s.jsx)(n.code,{children:"jest.config.js"}),":"]})}),"\n",(0,s.jsx)(n.h3,{id:"npm",children:"NPM"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate jest.config.js\n"})}),"\n",(0,s.jsx)(n.h3,{id:"yarn",children:"Yarn"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate jest.config.js\n"})}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsxs)(n.em,{children:["If you're using ",(0,s.jsx)(n.code,{children:"jest"})," config property of ",(0,s.jsx)(n.code,{children:"package.json"}),":"]})}),"\n",(0,s.jsx)(n.h3,{id:"npm-1",children:"NPM"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate package.json\n"})}),"\n",(0,s.jsx)(n.h3,{id:"yarn-1",children:"Yarn"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate package.json\n"})})]})}function g(e={}){const{wrapper:n}={...(0,o.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.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/3432663a.65873a50.js b/assets/js/3432663a.65873a50.js new file mode 100644 index 0000000000..5ea9ef0557 --- /dev/null +++ b/assets/js/3432663a.65873a50.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9345],{5570:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>a,contentTitle:()=>r,default:()=>g,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var s=t(4848),o=t(8453);const i={id:"migration",title:"Migration from <=23.10"},r=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/migration.md",tags:[],version:"27.1",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(n.p,{children:["You can use the ",(0,s.jsx)(n.code,{children:"config:migrate"})," tool of ",(0,s.jsx)(n.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsxs)(n.em,{children:["If you're using ",(0,s.jsx)(n.code,{children:"jest.config.js"}),":"]})}),"\n",(0,s.jsx)(n.h3,{id:"npm",children:"NPM"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate jest.config.js\n"})}),"\n",(0,s.jsx)(n.h3,{id:"yarn",children:"Yarn"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate jest.config.js\n"})}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsxs)(n.em,{children:["If you're using ",(0,s.jsx)(n.code,{children:"jest"})," config property of ",(0,s.jsx)(n.code,{children:"package.json"}),":"]})}),"\n",(0,s.jsx)(n.h3,{id:"npm-1",children:"NPM"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate package.json\n"})}),"\n",(0,s.jsx)(n.h3,{id:"yarn-1",children:"Yarn"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate package.json\n"})})]})}function g(e={}){const{wrapper:n}={...(0,o.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.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.d0f46e46.js b/assets/js/35779d9e.d0f46e46.js deleted file mode 100644 index ddd75b7428..0000000000 --- a/assets/js/35779d9e.d0f46e46.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3152],{3099:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>p,frontMatter:()=>l,metadata:()=>c,toc:()=>j});var n=s(4848),r=s(8453),o=s(9489),a=s(7227);const l={title:"Babel Config option"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Babel Config option"}},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,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:[(0,n.jsx)(t.code,{children:"ts-jest"})," by default does ",(0,n.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,n.jsx)(t.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,n.jsxs)(t.p,{children:["The option is ",(0,n.jsx)(t.code,{children:"babelConfig"})," and it works pretty much as the ",(0,n.jsx)(t.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"true"}),": enables Babel processing. ",(0,n.jsx)(t.code,{children:"ts-jest"})," will try to find a ",(0,n.jsx)(t.code,{children:".babelrc"}),", ",(0,n.jsx)(t.code,{children:".babelrc.js"}),", ",(0,n.jsx)(t.code,{children:"babel.config.js"})," file or a ",(0,n.jsx)(t.code,{children:"babel"})," section in the ",(0,n.jsx)(t.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,n.jsx)(t.code,{children:"babel-jest"})," processor."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"{ ... }"}),": inline ",(0,n.jsx)(t.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,n.jsx)(t.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,n.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsxs)(t.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,n.jsx)(t.code,{children:"babelrc"})," file"]}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsxs)(t.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,n.jsx)(t.code,{children:"babelrc"})," file"]}),"\n",(0,n.jsxs)(t.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,n.jsx)(t.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.p,{children:"or importing directly the config file:"}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,n.jsxs)(t.p,{children:["Refer to the ",(0,n.jsx)(t.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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/35779d9e.fd45dc2b.js b/assets/js/35779d9e.fd45dc2b.js new file mode 100644 index 0000000000..f4231ac334 --- /dev/null +++ b/assets/js/35779d9e.fd45dc2b.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3152],{3099:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>p,frontMatter:()=>l,metadata:()=>c,toc:()=>j});var n=s(4848),r=s(8453),o=s(9489),a=s(7227);const l={title:"Babel Config option"},i=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Babel Config option"}},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,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:[(0,n.jsx)(t.code,{children:"ts-jest"})," by default does ",(0,n.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,n.jsx)(t.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,n.jsxs)(t.p,{children:["The option is ",(0,n.jsx)(t.code,{children:"babelConfig"})," and it works pretty much as the ",(0,n.jsx)(t.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"true"}),": enables Babel processing. ",(0,n.jsx)(t.code,{children:"ts-jest"})," will try to find a ",(0,n.jsx)(t.code,{children:".babelrc"}),", ",(0,n.jsx)(t.code,{children:".babelrc.js"}),", ",(0,n.jsx)(t.code,{children:"babel.config.js"})," file or a ",(0,n.jsx)(t.code,{children:"babel"})," section in the ",(0,n.jsx)(t.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,n.jsx)(t.code,{children:"babel-jest"})," processor."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"{ ... }"}),": inline ",(0,n.jsx)(t.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,n.jsx)(t.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,n.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsxs)(t.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,n.jsx)(t.code,{children:"babelrc"})," file"]}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsxs)(t.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,n.jsx)(t.code,{children:"babelrc"})," file"]}),"\n",(0,n.jsxs)(t.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,n.jsx)(t.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.p,{children:"or importing directly the config file:"}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,n.jsxs)(t.p,{children:["Refer to the ",(0,n.jsx)(t.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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}),b=(()=>{const e=c??x;return p({value:e,tabValues:o})?e:null})();(0,l.A)((()=>{b&&i(b)}),[b]);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 b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var f=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,f.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,f.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",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,f.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,f.jsxs)("div",{className:(0,r.A)("tabs-container",b.tabList),children:[(0,f.jsx)(g,{...t,...e}),(0,f.jsx)(v,{...t,...e})]})}function w(e){const t=(0,m.A)();return(0,f.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.135fc666.js b/assets/js/35ce71d5.135fc666.js new file mode 100644 index 0000000000..e5d4e1118f --- /dev/null +++ b/assets/js/35ce71d5.135fc666.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9014],{2608:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>p,frontMatter:()=>i,metadata:()=>c,toc:()=>u});var s=o(4848),n=o(8453);const i={id:"using-with-monorepo",title:"Using with monorepo"},r=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},u=[];function a(e){const t={a:"a",code:"code",p:"p",...(0,n.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["To use ",(0,s.jsx)(t.code,{children:"ts-jest"})," in a project with monorepo structure, you'll need to use ",(0,s.jsx)(t.a,{href:"https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig",children:"Jest projects configuration"}),"."]}),"\n",(0,s.jsxs)(t.p,{children:["When using Jest ",(0,s.jsx)(t.code,{children:"projects"})," configuration, Jest will run ",(0,s.jsx)(t.code,{children:"ts-jest"})," against each project which is defined in the configuration."]})]})}function p(e={}){const{wrapper:t}={...(0,n.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/35ce71d5.f72098e4.js b/assets/js/35ce71d5.f72098e4.js deleted file mode 100644 index 1e527a6296..0000000000 --- a/assets/js/35ce71d5.f72098e4.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9014],{2608:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>u,contentTitle:()=>r,default:()=>p,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var s=o(4848),n=o(8453);const i={id:"using-with-monorepo",title:"Using with monorepo"},r=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},u={},d=[];function a(e){const t={a:"a",code:"code",p:"p",...(0,n.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["To use ",(0,s.jsx)(t.code,{children:"ts-jest"})," in a project with monorepo structure, you'll need to use ",(0,s.jsx)(t.a,{href:"https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig",children:"Jest projects configuration"}),"."]}),"\n",(0,s.jsxs)(t.p,{children:["When using Jest ",(0,s.jsx)(t.code,{children:"projects"})," configuration, Jest will run ",(0,s.jsx)(t.code,{children:"ts-jest"})," against each project which is defined in the configuration."]})]})}function p(e={}){const{wrapper:t}={...(0,n.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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.820cc301.js b/assets/js/3787ba46.820cc301.js deleted file mode 100644 index 417d97bf6b..0000000000 --- a/assets/js/3787ba46.820cc301.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[775],{3995:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>l,contentTitle:()=>i,default:()=>u,frontMatter:()=>o,metadata:()=>c,toc:()=>a});var t=n(4848),r=n(8453);const o={id:"esm-support",title:"ESM Support"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},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,r.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(s.p,{children:["To use ",(0,t.jsx)(s.code,{children:"ts-jest"})," with ESM support:"]}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:["Check ",(0,t.jsx)(s.a,{href:"https://jestjs.io/docs/en/ecmascript-modules",children:"ESM Jest documentation"}),"."]}),"\n",(0,t.jsxs)(s.li,{children:["Enable ",(0,t.jsx)(s.a,{href:"../getting-started/options/useESM",children:"useESM"})," ",(0,t.jsx)(s.code,{children:"true"})," for ",(0,t.jsx)(s.code,{children:"ts-jest"})," config."]}),"\n",(0,t.jsxs)(s.li,{children:["Include ",(0,t.jsx)(s.code,{children:".ts"})," in ",(0,t.jsx)(s.a,{href:"https://jestjs.io/docs/en/next/configuration#extensionstotreatasesm-arraystring",children:"extensionsToTreatAsEsm"})," Jest config option."]}),"\n",(0,t.jsxs)(s.li,{children:["Ensure that ",(0,t.jsx)(s.code,{children:"tsconfig"})," has ",(0,t.jsx)(s.code,{children:"module"})," with value for ESM, e.g. ",(0,t.jsx)(s.code,{children:"ES2015"})," or ",(0,t.jsx)(s.code,{children:"ES2020"})," etc..."]}),"\n"]}),"\n",(0,t.jsx)(s.h3,{id:"esm-presets",children:"ESM presets"}),"\n",(0,t.jsxs)(s.p,{children:["There are also ",(0,t.jsx)(s.a,{href:"/ts-jest/docs/27.1/getting-started/presets",children:"3 presets"})," to work with ESM."]}),"\n",(0,t.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,t.jsx)(s.h4,{id:"manual-configuration",children:"Manual configuration"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.h4,{id:"use-esm-presets",children:"Use ESM presets"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.pre,{children:(0,t.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,r.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:()=>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/3787ba46.dd93323a.js b/assets/js/3787ba46.dd93323a.js new file mode 100644 index 0000000000..9167590cba --- /dev/null +++ b/assets/js/3787ba46.dd93323a.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[775],{3995:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>l,contentTitle:()=>i,default:()=>u,frontMatter:()=>o,metadata:()=>c,toc:()=>d});var t=n(4848),r=n(8453);const o={id:"esm-support",title:"ESM Support"},i=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/guides/esm-support.md",tags:[],version:"27.1",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},l={},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}];function a(e){const s={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",ul:"ul",...(0,r.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(s.p,{children:["To use ",(0,t.jsx)(s.code,{children:"ts-jest"})," with ESM support:"]}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:["Check ",(0,t.jsx)(s.a,{href:"https://jestjs.io/docs/en/ecmascript-modules",children:"ESM Jest documentation"}),"."]}),"\n",(0,t.jsxs)(s.li,{children:["Enable ",(0,t.jsx)(s.a,{href:"../getting-started/options/useESM",children:"useESM"})," ",(0,t.jsx)(s.code,{children:"true"})," for ",(0,t.jsx)(s.code,{children:"ts-jest"})," config."]}),"\n",(0,t.jsxs)(s.li,{children:["Include ",(0,t.jsx)(s.code,{children:".ts"})," in ",(0,t.jsx)(s.a,{href:"https://jestjs.io/docs/en/next/configuration#extensionstotreatasesm-arraystring",children:"extensionsToTreatAsEsm"})," Jest config option."]}),"\n",(0,t.jsxs)(s.li,{children:["Ensure that ",(0,t.jsx)(s.code,{children:"tsconfig"})," has ",(0,t.jsx)(s.code,{children:"module"})," with value for ESM, e.g. ",(0,t.jsx)(s.code,{children:"ES2015"})," or ",(0,t.jsx)(s.code,{children:"ES2020"})," etc..."]}),"\n"]}),"\n",(0,t.jsx)(s.h3,{id:"esm-presets",children:"ESM presets"}),"\n",(0,t.jsxs)(s.p,{children:["There are also ",(0,t.jsx)(s.a,{href:"/ts-jest/docs/27.1/getting-started/presets",children:"3 presets"})," to work with ESM."]}),"\n",(0,t.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,t.jsx)(s.h4,{id:"manual-configuration",children:"Manual configuration"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.h4,{id:"use-esm-presets",children:"Use ESM presets"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.pre,{children:(0,t.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,r.R)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.jsx)(a,{...e})}):a(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.a0c14a87.js b/assets/js/3bfdd655.a0c14a87.js deleted file mode 100644 index ba78c33529..0000000000 --- a/assets/js/3bfdd655.a0c14a87.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4798],{8110:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>c,contentTitle:()=>o,default:()=>j,frontMatter:()=>i,metadata:()=>d,toc:()=>l});var n=t(4848),r=t(8453);const i={id:"presets",title:"Presets"},o=void 0,d={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:!1,unlisted:!1,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:1726058855e3,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"}},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,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(s.h3,{id:"the-presets",children:"The presets"}),"\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.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.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"}),"."]})]})]})]}),"\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 using TypeScript with Jest (assuming you added ",(0,n.jsx)(s.code,{children:"ts-jest"})," to your dev. dependencies of course):"]}),"\n",(0,n.jsx)(s.pre,{children:(0,n.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,n.jsx)(s.pre,{children:(0,n.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,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.jsx)(s.pre,{children:(0,n.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,n.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,n.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,n.jsx)(s.pre,{children:(0,n.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,r.R)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.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/3bfdd655.dc183ecc.js b/assets/js/3bfdd655.dc183ecc.js new file mode 100644 index 0000000000..c2d927d469 --- /dev/null +++ b/assets/js/3bfdd655.dc183ecc.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4798],{8110:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>c,contentTitle:()=>o,default:()=>j,frontMatter:()=>i,metadata:()=>d,toc:()=>l});var n=t(4848),r=t(8453);const i={id:"presets",title:"Presets"},o=void 0,d={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/getting-started/presets.md",tags:[],version:"26.5",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(s.h3,{id:"the-presets",children:"The presets"}),"\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.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.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"}),"."]})]})]})]}),"\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 using TypeScript with Jest (assuming you added ",(0,n.jsx)(s.code,{children:"ts-jest"})," to your dev. dependencies of course):"]}),"\n",(0,n.jsx)(s.pre,{children:(0,n.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,n.jsx)(s.pre,{children:(0,n.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,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.jsx)(s.pre,{children:(0,n.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,n.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,n.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,n.jsx)(s.pre,{children:(0,n.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,r.R)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.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.268242a0.js b/assets/js/3e930f87.268242a0.js new file mode 100644 index 0000000000..e01b70aeb8 --- /dev/null +++ b/assets/js/3e930f87.268242a0.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2078],{1921:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>m,frontMatter:()=>l,metadata:()=>c,toc:()=>d});var n=s(4848),r=s(8453),a=s(9489),o=s(7227);const l={title:"Compiler option"},i=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/compiler.md",tags:[],version:"current",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Compiler option"}},u={},d=[{value:"Example",id:"example",level:3}];function p(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["The ",(0,n.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,n.jsxs)(t.p,{children:["The default value is ",(0,n.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,n.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,n.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,n.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,n.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,n.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,n.jsxs)(a.A,{groupId:"code-examples",children:[(0,n.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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}),b=(()=>{const e=c??f;return m({value:e,tabValues:a})?e:null})();(0,l.A)((()=>{b&&i(b)}),[b]);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 b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=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,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:a}=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,...a,className:(0,r.A)("tabs__item",b.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,x.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,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:()=>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/3e930f87.802e8f90.js b/assets/js/3e930f87.802e8f90.js deleted file mode 100644 index efec8c85a9..0000000000 --- a/assets/js/3e930f87.802e8f90.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2078],{1921:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>m,frontMatter:()=>l,metadata:()=>c,toc:()=>d});var n=s(4848),r=s(8453),a=s(9489),o=s(7227);const l={title:"Compiler option"},i=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/compiler.md",tags:[],version:"current",lastUpdatedBy:"renovate[bot]",lastUpdatedAt:1726058855e3,frontMatter:{title:"Compiler option"}},u={},d=[{value:"Example",id:"example",level:3}];function p(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["The ",(0,n.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,n.jsxs)(t.p,{children:["The default value is ",(0,n.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,n.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,n.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,n.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,n.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,n.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,n.jsxs)(a.A,{groupId:"code-examples",children:[(0,n.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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.da85df0a.js b/assets/js/4040fa6b.da85df0a.js new file mode 100644 index 0000000000..003d9fcca1 --- /dev/null +++ b/assets/js/4040fa6b.da85df0a.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9032],{2513:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var n=s(4848),o=s(8453);const r={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},i=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/introduction.md",tags:[],version:"26.5",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,o.R)(),...t.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,n.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,n.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,n.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,n.jsx)(e.code,{children:"preset-typescript"})," ",(0,n.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,n.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,n.jsx)(e.admonition,{type:"important",children:(0,n.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,n.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,n.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,o.R)(),...t.components};return e?(0,n.jsx)(e,{...t,children:(0,n.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/4040fa6b.ded1ca75.js b/assets/js/4040fa6b.ded1ca75.js deleted file mode 100644 index 06eb3c5622..0000000000 --- a/assets/js/4040fa6b.ded1ca75.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9032],{2513:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var n=s(4848),o=s(8453);const r={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,o.R)(),...t.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,n.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,n.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,n.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,n.jsx)(e.code,{children:"preset-typescript"})," ",(0,n.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,n.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,n.jsx)(e.admonition,{type:"important",children:(0,n.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,n.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,n.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,o.R)(),...t.components};return e?(0,n.jsx)(e,{...t,children:(0,n.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.0bd72c36.js b/assets/js/44207808.0bd72c36.js new file mode 100644 index 0000000000..82784441cb --- /dev/null +++ b/assets/js/44207808.0bd72c36.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8120],{1417:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>r,contentTitle:()=>i,default:()=>b,frontMatter:()=>l,metadata:()=>a,toc:()=>c});var t=s(4848),o=s(8453);const l={title:"Babel Config option"},i=void 0,a={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Babel Config option"}},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,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.code,{children:"ts-jest"})," by default does ",(0,t.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,t.jsx)(n.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,t.jsxs)(n.p,{children:["The option is ",(0,t.jsx)(n.code,{children:"babelConfig"})," and it works pretty much as the ",(0,t.jsx)(n.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"true"}),": enables Babel processing. ",(0,t.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,t.jsx)(n.code,{children:".babelrc"}),", ",(0,t.jsx)(n.code,{children:".babelrc.js"}),", ",(0,t.jsx)(n.code,{children:"babel.config.js"})," file or a ",(0,t.jsx)(n.code,{children:"babel"})," section in the ",(0,t.jsx)(n.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,t.jsx)(n.code,{children:"babel-jest"})," processor."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"{ ... }"}),": inline ",(0,t.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,t.jsx)(n.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,t.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,t.jsxs)(n.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,t.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.pre,{children:(0,t.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,t.jsxs)(n.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,t.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,t.jsxs)(n.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,t.jsx)(n.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.p,{children:"or"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,t.jsxs)(n.p,{children:["Refer to the ",(0,t.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.pre,{children:(0,t.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,o.R)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(d,{...e})}):d(e)}},8453:(e,n,s)=>{s.d(n,{R:()=>i,x:()=>a});var t=s(6540);const o={},l=t.createContext(o);function i(e){const n=t.useContext(l);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),t.createElement(l.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/44207808.d1cbf46e.js b/assets/js/44207808.d1cbf46e.js deleted file mode 100644 index 9a0f66fe92..0000000000 --- a/assets/js/44207808.d1cbf46e.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8120],{1417:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>r,contentTitle:()=>i,default:()=>b,frontMatter:()=>l,metadata:()=>a,toc:()=>c});var t=s(4848),o=s(8453);const l={title:"Babel Config option"},i=void 0,a={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Babel Config option"}},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,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.code,{children:"ts-jest"})," by default does ",(0,t.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,t.jsx)(n.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,t.jsxs)(n.p,{children:["The option is ",(0,t.jsx)(n.code,{children:"babelConfig"})," and it works pretty much as the ",(0,t.jsx)(n.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"true"}),": enables Babel processing. ",(0,t.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,t.jsx)(n.code,{children:".babelrc"}),", ",(0,t.jsx)(n.code,{children:".babelrc.js"}),", ",(0,t.jsx)(n.code,{children:"babel.config.js"})," file or a ",(0,t.jsx)(n.code,{children:"babel"})," section in the ",(0,t.jsx)(n.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,t.jsx)(n.code,{children:"babel-jest"})," processor."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"{ ... }"}),": inline ",(0,t.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,t.jsx)(n.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,t.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,t.jsxs)(n.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,t.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.pre,{children:(0,t.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,t.jsxs)(n.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,t.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,t.jsxs)(n.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,t.jsx)(n.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.p,{children:"or"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,t.jsxs)(n.p,{children:["Refer to the ",(0,t.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.pre,{children:(0,t.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,o.R)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(d,{...e})}):d(e)}},8453:(e,n,s)=>{s.d(n,{R:()=>i,x:()=>a});var t=s(6540);const o={},l=t.createContext(o);function i(e){const n=t.useContext(l);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),t.createElement(l.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/44d840ac.7912f654.js b/assets/js/44d840ac.7912f654.js deleted file mode 100644 index 9b7f81a65c..0000000000 --- a/assets/js/44d840ac.7912f654.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5775],{8779:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>c,contentTitle:()=>l,default:()=>h,frontMatter:()=>t,metadata:()=>r,toc:()=>d});var i=s(4848),o=s(8453);const t={title:"Diagnostics option"},l=void 0,r={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Diagnostics option"}},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,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(n.p,{children:["The ",(0,i.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,i.jsxs)(n.p,{children:["If a diagnostic is not filtered out, ",(0,i.jsx)(n.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,i.jsx)(n.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,i.jsxs)(n.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,i.jsx)(n.code,{children:"diagnostics"})," option to ",(0,i.jsx)(n.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,i.jsx)(n.code,{children:"diagnostics"})," to ",(0,i.jsx)(n.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,i.jsx)(n.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"warnOnly"})}),": If specified and ",(0,i.jsx)(n.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,i.jsx)(n.em,{children:"disabled"}),")."]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,i.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,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"6059"}),": ",(0,i.jsx)(n.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"18002"}),": ",(0,i.jsx)(n.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"18003"}),": ",(0,i.jsx)(n.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"pathRegex"})})," (",(0,i.jsx)(n.strong,{children:"DEPRECATED"}),"): If specified, diagnostics of source files which path does ",(0,i.jsx)(n.strong,{children:"not"})," match will be ignored."]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,i.jsx)(n.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,i.jsx)(n.code,{children:"tsconfig"})," option ",(0,i.jsx)(n.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,i.jsx)(n.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,i.jsx)(n.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,i.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,i.jsx)(n.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,i.jsx)(n.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,i.jsxs)(n.p,{children:["Assuming all your test files ends with ",(0,i.jsx)(n.code,{children:".spec.ts"})," or ",(0,i.jsx)(n.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,i.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,i.jsx)(n.code,{children:"warnOnly"})," to ",(0,i.jsx)(n.code,{children:"true"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,i.jsxs)(n.p,{children:["All TypeScript error codes can be found ",(0,i.jsx)(n.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,i.jsx)(n.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,i.jsxs)(n.ol,{children:["\n",(0,i.jsxs)(n.li,{children:["A single ",(0,i.jsx)(n.code,{children:"number"})," (example: ",(0,i.jsx)(n.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,i.jsxs)(n.li,{children:["A ",(0,i.jsx)(n.code,{children:"string"})," with a code (example ",(0,i.jsx)(n.code,{children:'"1009"'}),", ",(0,i.jsx)(n.code,{children:'"TS1009"'})," or ",(0,i.jsx)(n.code,{children:'"TS1009"'}),")"]}),"\n",(0,i.jsxs)(n.li,{children:["A ",(0,i.jsx)(n.code,{children:"string"})," with a list of the above (example: ",(0,i.jsx)(n.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,i.jsxs)(n.li,{children:["An ",(0,i.jsx)(n.code,{children:"array"})," of one or more from ",(0,i.jsx)(n.code,{children:"1"})," or ",(0,i.jsx)(n.code,{children:"3"})," (example: ",(0,i.jsx)(n.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,o.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.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/44d840ac.d0be9717.js b/assets/js/44d840ac.d0be9717.js new file mode 100644 index 0000000000..2f3993ccac --- /dev/null +++ b/assets/js/44d840ac.d0be9717.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5775],{8779:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>c,contentTitle:()=>l,default:()=>h,frontMatter:()=>t,metadata:()=>r,toc:()=>d});var i=s(4848),o=s(8453);const t={title:"Diagnostics option"},l=void 0,r={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Diagnostics option"}},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,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(n.p,{children:["The ",(0,i.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,i.jsxs)(n.p,{children:["If a diagnostic is not filtered out, ",(0,i.jsx)(n.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,i.jsx)(n.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,i.jsxs)(n.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,i.jsx)(n.code,{children:"diagnostics"})," option to ",(0,i.jsx)(n.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,i.jsx)(n.code,{children:"diagnostics"})," to ",(0,i.jsx)(n.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,i.jsx)(n.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"warnOnly"})}),": If specified and ",(0,i.jsx)(n.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,i.jsx)(n.em,{children:"disabled"}),")."]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,i.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,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"6059"}),": ",(0,i.jsx)(n.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"18002"}),": ",(0,i.jsx)(n.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"18003"}),": ",(0,i.jsx)(n.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"pathRegex"})})," (",(0,i.jsx)(n.strong,{children:"DEPRECATED"}),"): If specified, diagnostics of source files which path does ",(0,i.jsx)(n.strong,{children:"not"})," match will be ignored."]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,i.jsx)(n.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,i.jsx)(n.code,{children:"tsconfig"})," option ",(0,i.jsx)(n.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,i.jsx)(n.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,i.jsx)(n.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,i.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,i.jsx)(n.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,i.jsx)(n.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,i.jsxs)(n.p,{children:["Assuming all your test files ends with ",(0,i.jsx)(n.code,{children:".spec.ts"})," or ",(0,i.jsx)(n.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,i.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,i.jsx)(n.code,{children:"warnOnly"})," to ",(0,i.jsx)(n.code,{children:"true"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,i.jsxs)(n.p,{children:["All TypeScript error codes can be found ",(0,i.jsx)(n.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,i.jsx)(n.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,i.jsxs)(n.ol,{children:["\n",(0,i.jsxs)(n.li,{children:["A single ",(0,i.jsx)(n.code,{children:"number"})," (example: ",(0,i.jsx)(n.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,i.jsxs)(n.li,{children:["A ",(0,i.jsx)(n.code,{children:"string"})," with a code (example ",(0,i.jsx)(n.code,{children:'"1009"'}),", ",(0,i.jsx)(n.code,{children:'"TS1009"'})," or ",(0,i.jsx)(n.code,{children:'"TS1009"'}),")"]}),"\n",(0,i.jsxs)(n.li,{children:["A ",(0,i.jsx)(n.code,{children:"string"})," with a list of the above (example: ",(0,i.jsx)(n.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,i.jsxs)(n.li,{children:["An ",(0,i.jsx)(n.code,{children:"array"})," of one or more from ",(0,i.jsx)(n.code,{children:"1"})," or ",(0,i.jsx)(n.code,{children:"3"})," (example: ",(0,i.jsx)(n.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,o.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.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.4ad7affe.js b/assets/js/4aabdf82.4ad7affe.js deleted file mode 100644 index ad12c87f31..0000000000 --- a/assets/js/4aabdf82.4ad7affe.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8639],{8431:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>p,frontMatter:()=>o,metadata:()=>c,toc:()=>l});var s=n(4848),i=n(8453);const o={id:"babel7-or-ts",title:"Babel7 or TypeScript"},r=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/babel7-or-ts.md",tags:[],version:"current",lastUpdatedBy:"renovate[bot]",lastUpdatedAt:1726058855e3,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"}},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,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,s.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,s.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,s.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,s.jsxs)(t.p,{children:["While ",(0,s.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,s.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,s.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,s.jsxs)(t.p,{children:["This is the big ",(0,s.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,s.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,s.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,s.jsx)(t.code,{children:"namespace"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,s.jsx)(t.code,{children:"const enum"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,s.jsx)(t.code,{children:"enum"}),", ",(0,s.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,s.jsxs)(t.p,{children:["You won't be able to do ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,s.jsx)(t.code,{children:"import"}),"/",(0,s.jsx)(t.code,{children:"export"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(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,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/4aabdf82.818d6e38.js b/assets/js/4aabdf82.818d6e38.js new file mode 100644 index 0000000000..8621d09bd9 --- /dev/null +++ b/assets/js/4aabdf82.818d6e38.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8639],{8431:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>p,frontMatter:()=>o,metadata:()=>c,toc:()=>l});var s=n(4848),i=n(8453);const o={id:"babel7-or-ts",title:"Babel7 or TypeScript"},r=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/babel7-or-ts.md",tags:[],version:"current",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,s.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,s.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,s.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,s.jsxs)(t.p,{children:["While ",(0,s.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,s.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,s.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,s.jsxs)(t.p,{children:["This is the big ",(0,s.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,s.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,s.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,s.jsx)(t.code,{children:"namespace"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,s.jsx)(t.code,{children:"const enum"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,s.jsx)(t.code,{children:"enum"}),", ",(0,s.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,s.jsxs)(t.p,{children:["You won't be able to do ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,s.jsx)(t.code,{children:"import"}),"/",(0,s.jsx)(t.code,{children:"export"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(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,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.06f14dac.js b/assets/js/4c23203f.06f14dac.js new file mode 100644 index 0000000000..3d8ad13bb4 --- /dev/null +++ b/assets/js/4c23203f.06f14dac.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8468],{6006:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>r,contentTitle:()=>c,default:()=>p,frontMatter:()=>o,metadata:()=>a,toc:()=>l});var s=n(4848),i=n(8453);const o={id:"react-native",title:"Using with React Native"},c=void 0,a={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/guides/react-native.md",tags:[],version:"26.5",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["To use ",(0,s.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,s.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,s.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,s.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,s.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,s.jsx)(t.code,{children:".babelrc"})," to ",(0,s.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",children:"// babel.config.js\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n"})}),"\n",(0,s.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,s.jsxs)(t.p,{children:["Create a new ",(0,s.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,s.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,s.jsx)(t.code,{children:"jest"})," key of ",(0,s.jsx)(t.code,{children:"package.json"})," to ",(0,s.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>c,x:()=>a});var s=n(6540);const i={},o=s.createContext(i);function c(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(i):e.components||i:c(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/4c23203f.cbd21640.js b/assets/js/4c23203f.cbd21640.js deleted file mode 100644 index d78d63a195..0000000000 --- a/assets/js/4c23203f.cbd21640.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8468],{6006:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>o,metadata:()=>r,toc:()=>l});var s=n(4848),i=n(8453);const o={id:"react-native",title:"Using with React Native"},c=void 0,r={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:!1,unlisted:!1,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:1726058855e3,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"}},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,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["To use ",(0,s.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,s.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,s.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,s.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,s.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,s.jsx)(t.code,{children:".babelrc"})," to ",(0,s.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",children:"// babel.config.js\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n"})}),"\n",(0,s.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,s.jsxs)(t.p,{children:["Create a new ",(0,s.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,s.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,s.jsx)(t.code,{children:"jest"})," key of ",(0,s.jsx)(t.code,{children:"package.json"})," to ",(0,s.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>c,x:()=>r});var s=n(6540);const i={},o=s.createContext(i);function c(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:c(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/f7862b07.10d09716.js b/assets/js/4c757249.71e59815.js similarity index 82% rename from assets/js/f7862b07.10d09716.js rename to assets/js/4c757249.71e59815.js index 90a30b33d0..d715d0ccfd 100644 --- a/assets/js/f7862b07.10d09716.js +++ b/assets/js/4c757249.71e59815.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8539],{5569:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>h,contentTitle:()=>r,default:()=>l,frontMatter:()=>o,metadata:()=>c,toc:()=>a});var n=s(4848),i=s(8453);const o={id:"contributing",title:"Contributing"},r=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},h={},a=[{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 d(e){const t={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,n.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,n.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,n.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,n.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,n.jsxs)(t.ol,{children:["\n",(0,n.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,n.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,n.jsxs)(t.li,{children:["Update the ",(0,n.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,n.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,n.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,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,n.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,n.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,n.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,n.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,n.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,n.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,n.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,n.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 l(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(d,{...e})}):d(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],{7905:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>h,contentTitle:()=>r,default:()=>l,frontMatter:()=>o,metadata:()=>c,toc:()=>a});var n=s(4848),i=s(8453);const o={id:"contributing",title:"Contributing"},r=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/contributing.md",tags:[],version:"27.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},h={},a=[{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 d(e){const t={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,n.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,n.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,n.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,n.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,n.jsxs)(t.ol,{children:["\n",(0,n.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,n.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,n.jsxs)(t.li,{children:["Update the ",(0,n.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,n.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,n.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,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,n.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,n.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,n.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,n.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,n.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,n.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,n.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,n.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 l(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(d,{...e})}):d(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/4c757249.89f05c49.js b/assets/js/4c757249.89f05c49.js deleted file mode 100644 index 7863e54e64..0000000000 --- a/assets/js/4c757249.89f05c49.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[10],{7905:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>h,contentTitle:()=>r,default:()=>l,frontMatter:()=>o,metadata:()=>c,toc:()=>a});var n=s(4848),i=s(8453);const o={id:"contributing",title:"Contributing"},r=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},h={},a=[{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 d(e){const t={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,n.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,n.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,n.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,n.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,n.jsxs)(t.ol,{children:["\n",(0,n.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,n.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,n.jsxs)(t.li,{children:["Update the ",(0,n.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,n.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,n.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,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,n.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,n.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,n.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,n.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,n.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,n.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,n.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,n.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 l(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(d,{...e})}):d(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.121a12aa.js b/assets/js/4d54d076.121a12aa.js new file mode 100644 index 0000000000..e63be96e1d --- /dev/null +++ b/assets/js/4d54d076.121a12aa.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1459],{8538:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>h,contentTitle:()=>r,default:()=>l,frontMatter:()=>o,metadata:()=>c,toc:()=>a});var n=s(4848),i=s(8453);const o={id:"contributing",title:"Contributing"},r=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/contributing.md",tags:[],version:"current",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},h={},a=[{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 d(e){const t={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,n.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,n.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,n.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,n.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,n.jsxs)(t.ol,{children:["\n",(0,n.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,n.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,n.jsxs)(t.li,{children:["Update the ",(0,n.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,n.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,n.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,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,n.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,n.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,n.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,n.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,n.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,n.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,n.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,n.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 l(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(d,{...e})}):d(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.74c8c3eb.js b/assets/js/4d54d076.74c8c3eb.js deleted file mode 100644 index a343a19ab0..0000000000 --- a/assets/js/4d54d076.74c8c3eb.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1459],{8538:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>h,contentTitle:()=>r,default:()=>d,frontMatter:()=>o,metadata:()=>c,toc:()=>a});var n=s(4848),i=s(8453);const o={id:"contributing",title:"Contributing"},r=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/contributing.md",tags:[],version:"current",lastUpdatedBy:"renovate[bot]",lastUpdatedAt:1726058855e3,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"}},h={},a=[{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,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,n.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,n.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,n.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,n.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,n.jsxs)(t.ol,{children:["\n",(0,n.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,n.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,n.jsxs)(t.li,{children:["Update the ",(0,n.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,n.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,n.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,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,n.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,n.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,n.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,n.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,n.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,n.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,n.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,n.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,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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.7486b19a.js b/assets/js/4dd3fb5c.7486b19a.js new file mode 100644 index 0000000000..73bd6a3ab6 --- /dev/null +++ b/assets/js/4dd3fb5c.7486b19a.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2636],{7301:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>m,frontMatter:()=>o,metadata:()=>i,toc:()=>d});var r=n(4848),s=n(8453),a=n(9489),l=n(7227);const o={id:"mock-es6-class",title:"Mock ES6 class"},u=void 0,i={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},c={},d=[];function p(e){const t={code:"code",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,r.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,r.jsx)(t.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\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.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\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.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\n })\n})\n"})})})]}),"\n",(0,r.jsx)(t.p,{children:"You will get the error"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,r.jsxs)(t.p,{children:["because ",(0,r.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,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.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\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.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\n }\n }),\n }\n})\n"})})})]}),"\n",(0,r.jsxs)(t.p,{children:["For named imports, like ",(0,r.jsx)(t.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,r.jsx)(t.code,{children:"default"})," with imported module name, ",(0,r.jsx)(t.code,{children:"OAuth2"})," in this 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.mock('./oauth', () => {\n return {\n OAuth2: ... // mock here\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.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,r.jsx)(t,{...e,children:(0,r.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/4dd3fb5c.7e5ff12d.js b/assets/js/4dd3fb5c.7e5ff12d.js deleted file mode 100644 index 8776811f84..0000000000 --- a/assets/js/4dd3fb5c.7e5ff12d.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2636],{7301:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>m,frontMatter:()=>o,metadata:()=>i,toc:()=>d});var r=n(4848),s=n(8453),a=n(9489),l=n(7227);const o={id:"mock-es6-class",title:"Mock ES6 class"},u=void 0,i={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:!1,unlisted:!1,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:1726058855e3,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"}},c={},d=[];function p(e){const t={code:"code",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,r.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,r.jsx)(t.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\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.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\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.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\n })\n})\n"})})})]}),"\n",(0,r.jsx)(t.p,{children:"You will get the error"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,r.jsxs)(t.p,{children:["because ",(0,r.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,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.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\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.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\n }\n }),\n }\n})\n"})})})]}),"\n",(0,r.jsxs)(t.p,{children:["For named imports, like ",(0,r.jsx)(t.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,r.jsx)(t.code,{children:"default"})," with imported module name, ",(0,r.jsx)(t.code,{children:"OAuth2"})," in this 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.mock('./oauth', () => {\n return {\n OAuth2: ... // mock here\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.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,r.jsx)(t,{...e,children:(0,r.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.8be95e36.js b/assets/js/4e0c07c5.8be95e36.js new file mode 100644 index 0000000000..b5b196f0a8 --- /dev/null +++ b/assets/js/4e0c07c5.8be95e36.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5250],{1101:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>c,default:()=>j,frontMatter:()=>l,metadata:()=>a,toc:()=>u});var s=n(4848),r=n(8453),i=n(9489),o=n(7227);const l={id:"options",title:"Options"},c=void 0,a={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options.md",tags:[],version:"current",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.h3,{id:"introduction",children:"Introduction"}),"\n",(0,s.jsx)(t.admonition,{type:"caution",children:(0,s.jsxs)(t.p,{children:["If you are using custom ",(0,s.jsx)(t.code,{children:"transform"})," config, please remove ",(0,s.jsx)(t.code,{children:"preset"})," from your Jest config to avoid issues that Jest doesn't transform files correctly."]})}),"\n",(0,s.jsxs)(t.p,{children:["All ",(0,s.jsx)(t.code,{children:"ts-jest"})," specific options can be defined in Jest ",(0,s.jsx)(t.code,{children:"transform"})," config object in the ",(0,s.jsx)(t.code,{children:"package.json"})," file of your project,\nor through a ",(0,s.jsx)(t.code,{children:"jest.config.js"}),", or ",(0,s.jsx)(t.code,{children:"jest.config.ts"})," file."]}),"\n",(0,s.jsxs)(i.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.config.js\nconst { createDefaultPreset } = require('ts-jest')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n ...createDefaultPreset(),\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.config.ts\nimport { createDefaultPreset, JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n ...createDefaultPreset(),\n}\n"})})})]}),"\n",(0,s.jsx)(t.admonition,{type:"important",children:(0,s.jsxs)(t.p,{children:["When using TypeScript Jest config file, Jest will use ",(0,s.jsx)(t.code,{children:"ts-node"})," to compile the config file. ",(0,s.jsx)(t.code,{children:"ts-jest"})," doesn't take part in\nthat process."]})}),"\n",(0,s.jsx)(t.h3,{id:"options",children:"Options"}),"\n",(0,s.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,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Option"}),(0,s.jsx)(t.th,{children:"Description"}),(0,s.jsx)(t.th,{children:"Type"}),(0,s.jsx)(t.th,{children:"Default"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/compiler",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"compiler"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"string"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:'"typescript"'})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/tsconfig",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"tsconfig"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,s.jsxs)(t.td,{children:[(0,s.jsx)(t.code,{children:"string"}),"|",(0,s.jsx)(t.code,{children:"object"}),"|",(0,s.jsx)(t.code,{children:"boolean"})]}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"auto"})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/isolatedModules",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"isolatedModules"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"boolean"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"disabled"})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/astTransformers",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"astTransformers"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"object"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"auto"})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/diagnostics",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"diagnostics"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,s.jsxs)(t.td,{children:[(0,s.jsx)(t.code,{children:"boolean"}),"|",(0,s.jsx)(t.code,{children:"object"})]}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"enabled"})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/babelConfig",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"babelConfig"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,s.jsxs)(t.td,{children:[(0,s.jsx)(t.code,{children:"boolean"}),"|",(0,s.jsx)(t.code,{children:"string"}),"|",(0,s.jsx)(t.code,{children:"object"})]}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"disabled"})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/stringifyContentPathRegex",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,s.jsxs)(t.td,{children:[(0,s.jsx)(t.code,{children:"string"}),"|",(0,s.jsx)(t.code,{children:"RegExp"})]}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"disabled"})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/useESM",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"useESM"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/useESM",children:"Enable ESM support"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"boolean"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"auto"})})]})]})]})]})}function j(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/4e0c07c5.b5e1d203.js b/assets/js/4e0c07c5.b5e1d203.js deleted file mode 100644 index ed4b9377f5..0000000000 --- a/assets/js/4e0c07c5.b5e1d203.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5250],{1101:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>c,default:()=>j,frontMatter:()=>l,metadata:()=>a,toc:()=>u});var s=n(4848),r=n(8453),i=n(9489),o=n(7227);const l={id:"options",title:"Options"},c=void 0,a={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options.md",tags:[],version:"current",lastUpdatedBy:"renovate[bot]",lastUpdatedAt:1726058855e3,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"}},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,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.h3,{id:"introduction",children:"Introduction"}),"\n",(0,s.jsx)(t.admonition,{type:"caution",children:(0,s.jsxs)(t.p,{children:["If you are using custom ",(0,s.jsx)(t.code,{children:"transform"})," config, please remove ",(0,s.jsx)(t.code,{children:"preset"})," from your Jest config to avoid issues that Jest doesn't transform files correctly."]})}),"\n",(0,s.jsxs)(t.p,{children:["All ",(0,s.jsx)(t.code,{children:"ts-jest"})," specific options can be defined in Jest ",(0,s.jsx)(t.code,{children:"transform"})," config object in the ",(0,s.jsx)(t.code,{children:"package.json"})," file of your project,\nor through a ",(0,s.jsx)(t.code,{children:"jest.config.js"}),", or ",(0,s.jsx)(t.code,{children:"jest.config.ts"})," file."]}),"\n",(0,s.jsxs)(i.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.config.js\nconst { createDefaultPreset } = require('ts-jest')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n ...createDefaultPreset(),\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.config.ts\nimport { createDefaultPreset, JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n ...createDefaultPreset(),\n}\n"})})})]}),"\n",(0,s.jsx)(t.admonition,{type:"important",children:(0,s.jsxs)(t.p,{children:["When using TypeScript Jest config file, Jest will use ",(0,s.jsx)(t.code,{children:"ts-node"})," to compile the config file. ",(0,s.jsx)(t.code,{children:"ts-jest"})," doesn't take part in\nthat process."]})}),"\n",(0,s.jsx)(t.h3,{id:"options",children:"Options"}),"\n",(0,s.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,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Option"}),(0,s.jsx)(t.th,{children:"Description"}),(0,s.jsx)(t.th,{children:"Type"}),(0,s.jsx)(t.th,{children:"Default"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/compiler",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"compiler"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"string"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:'"typescript"'})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/tsconfig",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"tsconfig"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,s.jsxs)(t.td,{children:[(0,s.jsx)(t.code,{children:"string"}),"|",(0,s.jsx)(t.code,{children:"object"}),"|",(0,s.jsx)(t.code,{children:"boolean"})]}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"auto"})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/isolatedModules",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"isolatedModules"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"boolean"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"disabled"})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/astTransformers",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"astTransformers"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"object"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"auto"})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/diagnostics",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"diagnostics"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,s.jsxs)(t.td,{children:[(0,s.jsx)(t.code,{children:"boolean"}),"|",(0,s.jsx)(t.code,{children:"object"})]}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"enabled"})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/babelConfig",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"babelConfig"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,s.jsxs)(t.td,{children:[(0,s.jsx)(t.code,{children:"boolean"}),"|",(0,s.jsx)(t.code,{children:"string"}),"|",(0,s.jsx)(t.code,{children:"object"})]}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"disabled"})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/stringifyContentPathRegex",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,s.jsxs)(t.td,{children:[(0,s.jsx)(t.code,{children:"string"}),"|",(0,s.jsx)(t.code,{children:"RegExp"})]}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"disabled"})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/useESM",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"useESM"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/useESM",children:"Enable ESM support"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"boolean"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"auto"})})]})]})]})]})}function j(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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.60342f65.js b/assets/js/5316ff60.60342f65.js new file mode 100644 index 0000000000..ab84f8a550 --- /dev/null +++ b/assets/js/5316ff60.60342f65.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5520],{8863:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>a,default:()=>p,frontMatter:()=>o,metadata:()=>i,toc:()=>l});var r=n(4848),t=n(8453);const o={title:"AST transformers option"},a=void 0,i={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"AST transformers option"}},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,t.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:"public-transformers",children:"Public transformers"}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.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,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"path-mapping"})," convert alias import/export to relative import/export path base on ",(0,r.jsx)(s.code,{children:"paths"})," in ",(0,r.jsx)(s.code,{children:"tsconfig"}),".\nThis transformer works similar to ",(0,r.jsx)(s.code,{children:"moduleNameMapper"})," in ",(0,r.jsx)(s.code,{children:"jest.config.js"}),". When using this transformer, one might not need\n",(0,r.jsx)(s.code,{children:"moduleNameMapper"})," anymore."]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"example-of-opt-in-transformers",children:"Example of opt-in 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: ['ts-jest/dist/transformers/path-mapping'],\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": ["ts-jest/dist/transformers/path-mapping"]\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 p(e={}){const{wrapper:s}={...(0,t.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:()=>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/5316ff60.cb45c428.js b/assets/js/5316ff60.cb45c428.js deleted file mode 100644 index fd3840c0b7..0000000000 --- a/assets/js/5316ff60.cb45c428.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5520],{8863:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>a,default:()=>p,frontMatter:()=>o,metadata:()=>i,toc:()=>l});var r=n(4848),t=n(8453);const o={title:"AST transformers option"},a=void 0,i={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"AST transformers option"}},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,t.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:"public-transformers",children:"Public transformers"}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.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,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"path-mapping"})," convert alias import/export to relative import/export path base on ",(0,r.jsx)(s.code,{children:"paths"})," in ",(0,r.jsx)(s.code,{children:"tsconfig"}),".\nThis transformer works similar to ",(0,r.jsx)(s.code,{children:"moduleNameMapper"})," in ",(0,r.jsx)(s.code,{children:"jest.config.js"}),". When using this transformer, one might not need\n",(0,r.jsx)(s.code,{children:"moduleNameMapper"})," anymore."]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"example-of-opt-in-transformers",children:"Example of opt-in 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: ['ts-jest/dist/transformers/path-mapping'],\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": ["ts-jest/dist/transformers/path-mapping"]\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 p(e={}){const{wrapper:s}={...(0,t.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:()=>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.63a233b5.js b/assets/js/544d8072.63a233b5.js new file mode 100644 index 0000000000..525f3a725c --- /dev/null +++ b/assets/js/544d8072.63a233b5.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9979],{6697:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>a,contentTitle:()=>r,default:()=>g,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var s=t(4848),o=t(8453);const i={id:"migration",title:"Migration from <=23.10"},r=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/migration.md",tags:[],version:"26.5",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(n.p,{children:["You can use the ",(0,s.jsx)(n.code,{children:"config:migrate"})," tool of ",(0,s.jsx)(n.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsxs)(n.em,{children:["If you're using ",(0,s.jsx)(n.code,{children:"jest.config.js"}),":"]})}),"\n",(0,s.jsx)(n.h3,{id:"npm",children:"NPM"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate jest.config.js\n"})}),"\n",(0,s.jsx)(n.h3,{id:"yarn",children:"Yarn"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate jest.config.js\n"})}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsxs)(n.em,{children:["If you're using ",(0,s.jsx)(n.code,{children:"jest"})," config property of ",(0,s.jsx)(n.code,{children:"package.json"}),":"]})}),"\n",(0,s.jsx)(n.h3,{id:"npm-1",children:"NPM"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate package.json\n"})}),"\n",(0,s.jsx)(n.h3,{id:"yarn-1",children:"Yarn"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate package.json\n"})})]})}function g(e={}){const{wrapper:n}={...(0,o.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.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/544d8072.e23570e8.js b/assets/js/544d8072.e23570e8.js deleted file mode 100644 index 7c73bd667c..0000000000 --- a/assets/js/544d8072.e23570e8.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9979],{6697:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>a,contentTitle:()=>r,default:()=>g,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var s=t(4848),o=t(8453);const i={id:"migration",title:"Migration from <=23.10"},r=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},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,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(n.p,{children:["You can use the ",(0,s.jsx)(n.code,{children:"config:migrate"})," tool of ",(0,s.jsx)(n.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsxs)(n.em,{children:["If you're using ",(0,s.jsx)(n.code,{children:"jest.config.js"}),":"]})}),"\n",(0,s.jsx)(n.h3,{id:"npm",children:"NPM"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate jest.config.js\n"})}),"\n",(0,s.jsx)(n.h3,{id:"yarn",children:"Yarn"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate jest.config.js\n"})}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsxs)(n.em,{children:["If you're using ",(0,s.jsx)(n.code,{children:"jest"})," config property of ",(0,s.jsx)(n.code,{children:"package.json"}),":"]})}),"\n",(0,s.jsx)(n.h3,{id:"npm-1",children:"NPM"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate package.json\n"})}),"\n",(0,s.jsx)(n.h3,{id:"yarn-1",children:"Yarn"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate package.json\n"})})]})}function g(e={}){const{wrapper:n}={...(0,o.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.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.3a165a4e.js b/assets/js/54ceb25f.3a165a4e.js new file mode 100644 index 0000000000..1c656c8e11 --- /dev/null +++ b/assets/js/54ceb25f.3a165a4e.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4317],{1662:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>u,contentTitle:()=>l,default:()=>h,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var n=t(4848),r=t(8453),o=t(9489),a=t(7227);const i={id:"esm-support",title:"ESM Support"},l=void 0,c={id:"guides/esm-support",title:"ESM Support",description:"To use ts-jest with ESM support:",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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/guides/esm-support.md",tags:[],version:"29.2",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(s.p,{children:["To use ",(0,n.jsx)(s.code,{children:"ts-jest"})," with ESM support:"]}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:["Check ",(0,n.jsx)(s.a,{href:"https://jestjs.io/docs/en/ecmascript-modules",children:"ESM Jest documentation"}),"."]}),"\n",(0,n.jsxs)(s.li,{children:["Enable ",(0,n.jsx)(s.a,{href:"../getting-started/options/useESM",children:"useESM"})," ",(0,n.jsx)(s.code,{children:"true"})," for ",(0,n.jsx)(s.code,{children:"ts-jest"})," config."]}),"\n",(0,n.jsxs)(s.li,{children:["Include ",(0,n.jsx)(s.code,{children:".ts"})," in ",(0,n.jsx)(s.a,{href:"https://jestjs.io/docs/en/next/configuration#extensionstotreatasesm-arraystring",children:"extensionsToTreatAsEsm"})," Jest config option."]}),"\n",(0,n.jsxs)(s.li,{children:["Ensure that ",(0,n.jsx)(s.code,{children:"tsconfig"})," has ",(0,n.jsx)(s.code,{children:"module"})," with value for ESM, e.g. ",(0,n.jsx)(s.code,{children:"ES2015"})," or ",(0,n.jsx)(s.code,{children:"ES2020"})," etc..."]}),"\n"]}),"\n",(0,n.jsx)(s.h3,{id:"esm-presets",children:"ESM presets"}),"\n",(0,n.jsxs)(s.p,{children:["There are also ",(0,n.jsx)(s.a,{href:"/ts-jest/docs/getting-started/presets",children:"3 presets"})," to work with ESM."]}),"\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.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsx)(s.h4,{id:"manual-configuration",children:"Manual configuration"}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.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 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,n.jsx)(a.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 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,n.jsx)(a.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 "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,n.jsx)(s.h4,{id:"use-esm-presets",children:"Use ESM 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 switch to ",(0,n.jsx)(s.code,{children:"esbuild"}),"/",(0,n.jsx)(s.code,{children:"swc"})," to transform ",(0,n.jsx)(s.code,{children:"ts"})," to ",(0,n.jsx)(s.code,{children:"js"}),". 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.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.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 { createDefaultEsmPreset } = require('ts-jest')\n\nconst defaultEsmPreset = createDefaultEsmPreset()\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n ...defaultEsmPreset,\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n}\n"})})}),(0,n.jsx)(a.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 { createDefaultEsmPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst defaultEsmPreset = createDefaultEsmPreset()\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n ...defaultEsmPreset,\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n}\n\nexport default jestConfig\n"})})})]}),"\n",(0,n.jsxs)(s.h4,{id:"support-mts-extension",children:["Support ",(0,n.jsx)(s.code,{children:".mts"})," extension"]}),"\n",(0,n.jsxs)(s.p,{children:["To work with ",(0,n.jsx)(s.code,{children:".mts"})," extension, besides the requirement to run Jest and ",(0,n.jsx)(s.code,{children:"ts-jest"})," in ESM mode, there are a few extra requirements to be met:"]}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.code,{children:"package.json"})," should contain ",(0,n.jsx)(s.code,{children:'"type": "module"'})]}),"\n",(0,n.jsxs)(s.li,{children:["A custom Jest resolver to resolve ",(0,n.jsx)(s.code,{children:".mjs"})," extension, see our simple one at ",(0,n.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,n.jsxs)(s.li,{children:[(0,n.jsx)(s.code,{children:"tsconfig.json"})," should at least contain these following options"]}),"\n"]}),"\n",(0,n.jsx)(s.pre,{children:(0,n.jsx)(s.code,{className:"language-json",children:'// tsconfig.spec.json\n{\n "compilerOptions": {\n "module": "ESNext", // or ES2015/ES2020/ES2022\n "target": "ESNext",\n "esModuleInterop": true\n }\n}\n'})})]})}function h(e={}){const{wrapper:s}={...(0,r.R)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.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:()=>S});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 h(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 j(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(!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:o}))),[c,d]=m({queryString:t,groupId:r}),[j,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??j;return h({value:e,tabValues:o})?e:null})();(0,i.A)((()=>{f&&l(f)}),[f]);return{selectedValue:a,selectValue:(0,n.useCallback)((e=>{if(!h({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 E(e){const s=j(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 S(e){const s=(0,x.A)();return(0,g.jsx)(E,{...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/54ceb25f.71cb31ae.js b/assets/js/54ceb25f.71cb31ae.js deleted file mode 100644 index 9f9f2e6cf0..0000000000 --- a/assets/js/54ceb25f.71cb31ae.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4317],{1662:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>u,contentTitle:()=>l,default:()=>h,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var n=t(4848),r=t(8453),o=t(9489),a=t(7227);const i={id:"esm-support",title:"ESM Support"},l=void 0,c={id:"guides/esm-support",title:"ESM Support",description:"To use ts-jest with ESM support:",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:!1,unlisted:!1,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:1726058855e3,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"}},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,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(s.p,{children:["To use ",(0,n.jsx)(s.code,{children:"ts-jest"})," with ESM support:"]}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:["Check ",(0,n.jsx)(s.a,{href:"https://jestjs.io/docs/en/ecmascript-modules",children:"ESM Jest documentation"}),"."]}),"\n",(0,n.jsxs)(s.li,{children:["Enable ",(0,n.jsx)(s.a,{href:"../getting-started/options/useESM",children:"useESM"})," ",(0,n.jsx)(s.code,{children:"true"})," for ",(0,n.jsx)(s.code,{children:"ts-jest"})," config."]}),"\n",(0,n.jsxs)(s.li,{children:["Include ",(0,n.jsx)(s.code,{children:".ts"})," in ",(0,n.jsx)(s.a,{href:"https://jestjs.io/docs/en/next/configuration#extensionstotreatasesm-arraystring",children:"extensionsToTreatAsEsm"})," Jest config option."]}),"\n",(0,n.jsxs)(s.li,{children:["Ensure that ",(0,n.jsx)(s.code,{children:"tsconfig"})," has ",(0,n.jsx)(s.code,{children:"module"})," with value for ESM, e.g. ",(0,n.jsx)(s.code,{children:"ES2015"})," or ",(0,n.jsx)(s.code,{children:"ES2020"})," etc..."]}),"\n"]}),"\n",(0,n.jsx)(s.h3,{id:"esm-presets",children:"ESM presets"}),"\n",(0,n.jsxs)(s.p,{children:["There are also ",(0,n.jsx)(s.a,{href:"/ts-jest/docs/getting-started/presets",children:"3 presets"})," to work with ESM."]}),"\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.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsx)(s.h4,{id:"manual-configuration",children:"Manual configuration"}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.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 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,n.jsx)(a.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 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,n.jsx)(a.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 "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,n.jsx)(s.h4,{id:"use-esm-presets",children:"Use ESM 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 switch to ",(0,n.jsx)(s.code,{children:"esbuild"}),"/",(0,n.jsx)(s.code,{children:"swc"})," to transform ",(0,n.jsx)(s.code,{children:"ts"})," to ",(0,n.jsx)(s.code,{children:"js"}),". 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.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.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 { createDefaultEsmPreset } = require('ts-jest')\n\nconst defaultEsmPreset = createDefaultEsmPreset()\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n ...defaultEsmPreset,\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n}\n"})})}),(0,n.jsx)(a.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 { createDefaultEsmPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst defaultEsmPreset = createDefaultEsmPreset()\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n ...defaultEsmPreset,\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n}\n\nexport default jestConfig\n"})})})]}),"\n",(0,n.jsxs)(s.h4,{id:"support-mts-extension",children:["Support ",(0,n.jsx)(s.code,{children:".mts"})," extension"]}),"\n",(0,n.jsxs)(s.p,{children:["To work with ",(0,n.jsx)(s.code,{children:".mts"})," extension, besides the requirement to run Jest and ",(0,n.jsx)(s.code,{children:"ts-jest"})," in ESM mode, there are a few extra requirements to be met:"]}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.code,{children:"package.json"})," should contain ",(0,n.jsx)(s.code,{children:'"type": "module"'})]}),"\n",(0,n.jsxs)(s.li,{children:["A custom Jest resolver to resolve ",(0,n.jsx)(s.code,{children:".mjs"})," extension, see our simple one at ",(0,n.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,n.jsxs)(s.li,{children:[(0,n.jsx)(s.code,{children:"tsconfig.json"})," should at least contain these following options"]}),"\n"]}),"\n",(0,n.jsx)(s.pre,{children:(0,n.jsx)(s.code,{className:"language-json",children:'// tsconfig.spec.json\n{\n "compilerOptions": {\n "module": "ESNext", // or ES2015/ES2020/ES2022\n "target": "ESNext",\n "esModuleInterop": true\n }\n}\n'})})]})}function h(e={}){const{wrapper:s}={...(0,r.R)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.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:()=>S});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 h(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 j(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(!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:o}))),[c,d]=m({queryString:t,groupId:r}),[j,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??j;return h({value:e,tabValues:o})?e:null})();(0,i.A)((()=>{f&&l(f)}),[f]);return{selectedValue:a,selectValue:(0,n.useCallback)((e=>{if(!h({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 E(e){const s=j(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 S(e){const s=(0,x.A)();return(0,g.jsx)(E,{...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/54f44165.a50d2bbe.js b/assets/js/54f44165.a50d2bbe.js new file mode 100644 index 0000000000..19ee63077c --- /dev/null +++ b/assets/js/54f44165.a50d2bbe.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7924],{2079:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>o,default:()=>p,frontMatter:()=>l,metadata:()=>c,toc:()=>d});var s=n(4848),r=n(8453),a=n(9489),i=n(7227);const l={id:"installation",title:"Installation"},o=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/installation.md",tags:[],version:"current",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,s.jsxs)(t.p,{children:["You can install ",(0,s.jsx)(t.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,s.jsxs)(a.A,{groupId:"npm2yarn",children:[(0,s.jsx)(i.A,{value:"npm",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})})}),(0,s.jsx)(i.A,{value:"yarn",label:"Yarn",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})})}),(0,s.jsx)(i.A,{value:"pnpm",label:"pnpm",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"pnpm add --save-dev jest typescript ts-jest @types/jest\n"})})})]}),"\n",(0,s.jsx)(t.admonition,{type:"tip",children:(0,s.jsxs)(t.p,{children:["Tip: If you get an error with the following ",(0,s.jsx)(t.code,{children:"npm"})," commands such as ",(0,s.jsx)(t.code,{children:"npx: command not found"}),", you can replace ",(0,s.jsx)(t.code,{children:"npx XXX"})," with ",(0,s.jsx)(t.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,s.jsx)(t.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,s.jsx)(t.h4,{id:"creating",children:"Creating"}),"\n",(0,s.jsxs)(t.p,{children:["By default, Jest can run without any config files, but it will not compile ",(0,s.jsx)(t.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,s.jsx)(t.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,s.jsx)(t.code,{children:"ts-jest"})," preset."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,s.jsxs)(a.A,{groupId:"code-examples",children:[(0,s.jsx)(i.A,{value:"npm",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-npm",metastring:"tab",children:"npx ts-jest config:init\n"})})}),(0,s.jsx)(i.A,{value:"Yarn",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-Yarn",metastring:"tab",children:"yarn ts-jest config:init\n"})})})]}),"\n",(0,s.jsxs)(t.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,s.jsx)(t.code,{children:".ts"})," files correctly."]}),"\n",(0,s.jsxs)(t.p,{children:["You can also use the ",(0,s.jsx)(t.code,{children:"jest --init"})," command (prefixed with either ",(0,s.jsx)(t.code,{children:"npx"})," or ",(0,s.jsx)(t.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,s.jsx)(t.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,s.jsx)(t.code,{children:'preset: "ts-jest"'})," to the ",(0,s.jsx)(t.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,s.jsx)(t.h4,{id:"customizing",children:"Customizing"}),"\n",(0,s.jsxs)(t.p,{children:["For customizing jest, please follow their ",(0,s.jsx)(t.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," specific options can be found ",(0,s.jsx)(t.a,{href:"options",children:"here"}),"."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/54f44165.bd5ddcf7.js b/assets/js/54f44165.bd5ddcf7.js deleted file mode 100644 index dfa6da107e..0000000000 --- a/assets/js/54f44165.bd5ddcf7.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7924],{2079:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>o,default:()=>p,frontMatter:()=>l,metadata:()=>c,toc:()=>d});var s=n(4848),r=n(8453),a=n(9489),i=n(7227);const l={id:"installation",title:"Installation"},o=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/installation.md",tags:[],version:"current",lastUpdatedBy:"renovate[bot]",lastUpdatedAt:1726058855e3,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"}},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,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,s.jsxs)(t.p,{children:["You can install ",(0,s.jsx)(t.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,s.jsxs)(a.A,{groupId:"npm2yarn",children:[(0,s.jsx)(i.A,{value:"npm",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})})}),(0,s.jsx)(i.A,{value:"yarn",label:"Yarn",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})})}),(0,s.jsx)(i.A,{value:"pnpm",label:"pnpm",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"pnpm add --save-dev jest typescript ts-jest @types/jest\n"})})})]}),"\n",(0,s.jsx)(t.admonition,{type:"tip",children:(0,s.jsxs)(t.p,{children:["Tip: If you get an error with the following ",(0,s.jsx)(t.code,{children:"npm"})," commands such as ",(0,s.jsx)(t.code,{children:"npx: command not found"}),", you can replace ",(0,s.jsx)(t.code,{children:"npx XXX"})," with ",(0,s.jsx)(t.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,s.jsx)(t.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,s.jsx)(t.h4,{id:"creating",children:"Creating"}),"\n",(0,s.jsxs)(t.p,{children:["By default, Jest can run without any config files, but it will not compile ",(0,s.jsx)(t.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,s.jsx)(t.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,s.jsx)(t.code,{children:"ts-jest"})," preset."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,s.jsxs)(a.A,{groupId:"code-examples",children:[(0,s.jsx)(i.A,{value:"npm",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-npm",metastring:"tab",children:"npx ts-jest config:init\n"})})}),(0,s.jsx)(i.A,{value:"Yarn",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-Yarn",metastring:"tab",children:"yarn ts-jest config:init\n"})})})]}),"\n",(0,s.jsxs)(t.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,s.jsx)(t.code,{children:".ts"})," files correctly."]}),"\n",(0,s.jsxs)(t.p,{children:["You can also use the ",(0,s.jsx)(t.code,{children:"jest --init"})," command (prefixed with either ",(0,s.jsx)(t.code,{children:"npx"})," or ",(0,s.jsx)(t.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,s.jsx)(t.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,s.jsx)(t.code,{children:'preset: "ts-jest"'})," to the ",(0,s.jsx)(t.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,s.jsx)(t.h4,{id:"customizing",children:"Customizing"}),"\n",(0,s.jsxs)(t.p,{children:["For customizing jest, please follow their ",(0,s.jsx)(t.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," specific options can be found ",(0,s.jsx)(t.a,{href:"options",children:"here"}),"."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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.7e164099.js b/assets/js/5bf3837a.7e164099.js deleted file mode 100644 index 48d5c0b651..0000000000 --- a/assets/js/5bf3837a.7e164099.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2276],{4206:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>a,frontMatter:()=>r,metadata:()=>c,toc:()=>u});var n=s(4848),o=s(8453);const r={id:"processing",title:"Processing flow"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},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,o.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,n.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,n.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,n.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,o.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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/5bf3837a.7fbecd09.js b/assets/js/5bf3837a.7fbecd09.js new file mode 100644 index 0000000000..22cce9e129 --- /dev/null +++ b/assets/js/5bf3837a.7fbecd09.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2276],{4206:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>a,frontMatter:()=>r,metadata:()=>c,toc:()=>d});var n=s(4848),o=s(8453);const r={id:"processing",title:"Processing flow"},i=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/processing.md",tags:[],version:"26.5",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},l={},d=[{value:"Jest process",id:"jest-process",level:2},{value:"ts-jest process",id:"ts-jest-process",level:2}];function u(e){const t={code:"code",em:"em",h2:"h2",img:"img",p:"p",...(0,o.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,n.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,n.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,n.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,o.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(u,{...e})}):u(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.4a538844.js b/assets/js/61b42bb5.4a538844.js deleted file mode 100644 index fb49163120..0000000000 --- a/assets/js/61b42bb5.4a538844.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[346],{3689:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>d,frontMatter:()=>i,metadata:()=>p,toc:()=>c});var s=n(4848),o=n(8453);const i={id:"paths-mapping",title:"Paths mapping"},r=void 0,p={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:!1,unlisted:!1,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:1726058855e3,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"}},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,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["If you use ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,s.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,s.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,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,s.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,s.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,s.jsxs)(t.p,{children:["With the below config in your ",(0,s.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/61b42bb5.bf799eaa.js b/assets/js/61b42bb5.bf799eaa.js new file mode 100644 index 0000000000..5a898311ac --- /dev/null +++ b/assets/js/61b42bb5.bf799eaa.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[346],{3689:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>d,frontMatter:()=>i,metadata:()=>p,toc:()=>c});var s=n(4848),o=n(8453);const i={id:"paths-mapping",title:"Paths mapping"},r=void 0,p={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["If you use ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,s.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,s.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,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,s.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,s.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,s.jsxs)(t.p,{children:["With the below config in your ",(0,s.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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.14cae06d.js b/assets/js/629085c0.14cae06d.js deleted file mode 100644 index a735a5a616..0000000000 --- a/assets/js/629085c0.14cae06d.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2452],{3138:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>m,frontMatter:()=>l,metadata:()=>c,toc:()=>d});var n=s(4848),r=s(8453),o=s(9489),a=s(7227);const l={title:"Compiler option"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Compiler option"}},u={},d=[{value:"Example",id:"example",level:3}];function p(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["The ",(0,n.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,n.jsxs)(t.p,{children:["The default value is ",(0,n.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,n.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,n.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,n.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,n.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,n.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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/629085c0.4cd59141.js b/assets/js/629085c0.4cd59141.js new file mode 100644 index 0000000000..57ddd7be13 --- /dev/null +++ b/assets/js/629085c0.4cd59141.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2452],{3138:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>m,frontMatter:()=>l,metadata:()=>c,toc:()=>d});var n=s(4848),r=s(8453),o=s(9489),a=s(7227);const l={title:"Compiler option"},i=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Compiler option"}},u={},d=[{value:"Example",id:"example",level:3}];function p(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["The ",(0,n.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,n.jsxs)(t.p,{children:["The default value is ",(0,n.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,n.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,n.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,n.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,n.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,n.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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.63c03b7d.js b/assets/js/6625be2a.63c03b7d.js new file mode 100644 index 0000000000..b3614fa2a0 --- /dev/null +++ b/assets/js/6625be2a.63c03b7d.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4136],{1918:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>m,frontMatter:()=>o,metadata:()=>i,toc:()=>d});var r=n(4848),a=n(8453),s=n(9489),l=n(7227);const o={id:"mock-es6-class",title:"Mock ES6 class"},u=void 0,i={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/guides/mock-es6-class.md",tags:[],version:"current",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},c={},d=[];function p(e){const t={code:"code",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,r.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,r.jsx)(t.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\n",(0,r.jsxs)(s.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.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\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.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\n })\n})\n"})})})]}),"\n",(0,r.jsx)(t.p,{children:"You will get the error"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,r.jsxs)(t.p,{children:["because ",(0,r.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,r.jsxs)(s.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.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\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.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\n }\n }),\n }\n})\n"})})})]}),"\n",(0,r.jsxs)(t.p,{children:["For named imports, like ",(0,r.jsx)(t.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,r.jsx)(t.code,{children:"default"})," with imported module name, ",(0,r.jsx)(t.code,{children:"OAuth2"})," in this example:"]}),"\n",(0,r.jsxs)(s.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.mock('./oauth', () => {\n return {\n OAuth2: ... // mock here\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.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,r.jsx)(t,{...e,children:(0,r.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),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: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 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}))),[i,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,c.Dv)(n);return[a,(0,r.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),g=(()=>{const e=i??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:i}=(0,s.a_)(),c=e=>{const t=e.currentTarget,n=u.indexOf(t),a=o[n].value;a!==r&&(i(t),l(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,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:c,...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/6625be2a.6a64d224.js b/assets/js/6625be2a.6a64d224.js deleted file mode 100644 index ab48c59508..0000000000 --- a/assets/js/6625be2a.6a64d224.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4136],{1918:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>m,frontMatter:()=>o,metadata:()=>i,toc:()=>d});var r=n(4848),a=n(8453),s=n(9489),l=n(7227);const o={id:"mock-es6-class",title:"Mock ES6 class"},u=void 0,i={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/guides/mock-es6-class.md",tags:[],version:"current",lastUpdatedBy:"renovate[bot]",lastUpdatedAt:1726058855e3,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"}},c={},d=[];function p(e){const t={code:"code",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,r.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,r.jsx)(t.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\n",(0,r.jsxs)(s.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.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\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.mock('./sound-player', () => {\n return jest.fn().mockImplementation(() => {\n return { playSoundFile: mockPlaySoundFile }\n })\n})\n"})})})]}),"\n",(0,r.jsx)(t.p,{children:"You will get the error"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,r.jsxs)(t.p,{children:["because ",(0,r.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,r.jsxs)(s.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.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\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.mock('./sound-player', () => {\n return {\n default: jest.fn().mockImplementation(() => {\n return {\n playSoundFile: mockPlaySoundFile,\n }\n }),\n }\n})\n"})})})]}),"\n",(0,r.jsxs)(t.p,{children:["For named imports, like ",(0,r.jsx)(t.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,r.jsx)(t.code,{children:"default"})," with imported module name, ",(0,r.jsx)(t.code,{children:"OAuth2"})," in this example:"]}),"\n",(0,r.jsxs)(s.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.mock('./oauth', () => {\n return {\n OAuth2: ... // mock here\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.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,r.jsx)(t,{...e,children:(0,r.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),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: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 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}))),[i,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,c.Dv)(n);return[a,(0,r.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),g=(()=>{const e=i??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:i}=(0,s.a_)(),c=e=>{const t=e.currentTarget,n=u.indexOf(t),a=o[n].value;a!==r&&(i(t),l(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,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:c,...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.315ed7ec.js b/assets/js/673550c0.315ed7ec.js deleted file mode 100644 index db098f68fb..0000000000 --- a/assets/js/673550c0.315ed7ec.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6460],{6689:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>d,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>l,toc:()=>c});var t=n(4848),o=n(8453);const r={id:"esm-support",title:"ESM Support"},i=void 0,l={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:!1,unlisted:!1,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:1726058855e3,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"}},d={},c=[{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,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(s.p,{children:["To use ",(0,t.jsx)(s.code,{children:"ts-jest"})," with ESM support:"]}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:["Check ",(0,t.jsx)(s.a,{href:"https://jestjs.io/docs/en/ecmascript-modules",children:"ESM Jest documentation"}),"."]}),"\n",(0,t.jsxs)(s.li,{children:["Enable ",(0,t.jsx)(s.a,{href:"../getting-started/options/useESM",children:"useESM"})," ",(0,t.jsx)(s.code,{children:"true"})," for ",(0,t.jsx)(s.code,{children:"ts-jest"})," config."]}),"\n",(0,t.jsxs)(s.li,{children:["Include ",(0,t.jsx)(s.code,{children:".ts"})," in ",(0,t.jsx)(s.a,{href:"https://jestjs.io/docs/en/next/configuration#extensionstotreatasesm-arraystring",children:"extensionsToTreatAsEsm"})," Jest config option."]}),"\n",(0,t.jsxs)(s.li,{children:["Ensure that ",(0,t.jsx)(s.code,{children:"tsconfig"})," has ",(0,t.jsx)(s.code,{children:"module"})," with value for ESM, e.g. ",(0,t.jsx)(s.code,{children:"ES2015"})," or ",(0,t.jsx)(s.code,{children:"ES2020"})," etc..."]}),"\n"]}),"\n",(0,t.jsx)(s.h3,{id:"esm-presets",children:"ESM presets"}),"\n",(0,t.jsxs)(s.p,{children:["There are also ",(0,t.jsx)(s.a,{href:"/ts-jest/docs/28.0/getting-started/presets",children:"3 presets"})," to work with ESM."]}),"\n",(0,t.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,t.jsx)(s.h4,{id:"manual-configuration",children:"Manual configuration"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.h4,{id:"use-esm-presets",children:"Use ESM presets"}),"\n",(0,t.jsx)(s.admonition,{type:"important",children:(0,t.jsxs)(s.p,{children:["Starting from ",(0,t.jsx)(s.strong,{children:"v28.0.0"}),", ",(0,t.jsx)(s.code,{children:"ts-jest"})," will gradually switch to ",(0,t.jsx)(s.code,{children:"esbuild"}),"/",(0,t.jsx)(s.code,{children:"swc"})," to transform ",(0,t.jsx)(s.code,{children:"ts"})," to ",(0,t.jsx)(s.code,{children:"js"}),". To make the transition smoothly, we introduce ",(0,t.jsx)(s.code,{children:"legacy"})," presets as a fallback when the new codes don't work yet."]})}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.pre,{children:(0,t.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,t.jsxs)(s.h4,{id:"support-mts-extension",children:["Support ",(0,t.jsx)(s.code,{children:".mts"})," extension"]}),"\n",(0,t.jsxs)(s.p,{children:["To work with ",(0,t.jsx)(s.code,{children:".mts"})," extension, besides the requirement to run Jest and ",(0,t.jsx)(s.code,{children:"ts-jest"})," in ESM mode, there are a few extra requirements to be met:"]}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"package.json"})," should contain ",(0,t.jsx)(s.code,{children:'"type": "module"'})]}),"\n",(0,t.jsxs)(s.li,{children:["A custom Jest resolver to resolve ",(0,t.jsx)(s.code,{children:".mjs"})," extension, see our simple one at ",(0,t.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,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"tsconfig.json"})," should at least contain these following options"]}),"\n"]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,o.R)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.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/673550c0.acb0cbe3.js b/assets/js/673550c0.acb0cbe3.js new file mode 100644 index 0000000000..77ac5ae20a --- /dev/null +++ b/assets/js/673550c0.acb0cbe3.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6460],{6689:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>d,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>l,toc:()=>c});var t=n(4848),o=n(8453);const r={id:"esm-support",title:"ESM Support"},i=void 0,l={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/guides/esm-support.md",tags:[],version:"28.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},c=[{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,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(s.p,{children:["To use ",(0,t.jsx)(s.code,{children:"ts-jest"})," with ESM support:"]}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:["Check ",(0,t.jsx)(s.a,{href:"https://jestjs.io/docs/en/ecmascript-modules",children:"ESM Jest documentation"}),"."]}),"\n",(0,t.jsxs)(s.li,{children:["Enable ",(0,t.jsx)(s.a,{href:"../getting-started/options/useESM",children:"useESM"})," ",(0,t.jsx)(s.code,{children:"true"})," for ",(0,t.jsx)(s.code,{children:"ts-jest"})," config."]}),"\n",(0,t.jsxs)(s.li,{children:["Include ",(0,t.jsx)(s.code,{children:".ts"})," in ",(0,t.jsx)(s.a,{href:"https://jestjs.io/docs/en/next/configuration#extensionstotreatasesm-arraystring",children:"extensionsToTreatAsEsm"})," Jest config option."]}),"\n",(0,t.jsxs)(s.li,{children:["Ensure that ",(0,t.jsx)(s.code,{children:"tsconfig"})," has ",(0,t.jsx)(s.code,{children:"module"})," with value for ESM, e.g. ",(0,t.jsx)(s.code,{children:"ES2015"})," or ",(0,t.jsx)(s.code,{children:"ES2020"})," etc..."]}),"\n"]}),"\n",(0,t.jsx)(s.h3,{id:"esm-presets",children:"ESM presets"}),"\n",(0,t.jsxs)(s.p,{children:["There are also ",(0,t.jsx)(s.a,{href:"/ts-jest/docs/28.0/getting-started/presets",children:"3 presets"})," to work with ESM."]}),"\n",(0,t.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,t.jsx)(s.h4,{id:"manual-configuration",children:"Manual configuration"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.h4,{id:"use-esm-presets",children:"Use ESM presets"}),"\n",(0,t.jsx)(s.admonition,{type:"important",children:(0,t.jsxs)(s.p,{children:["Starting from ",(0,t.jsx)(s.strong,{children:"v28.0.0"}),", ",(0,t.jsx)(s.code,{children:"ts-jest"})," will gradually switch to ",(0,t.jsx)(s.code,{children:"esbuild"}),"/",(0,t.jsx)(s.code,{children:"swc"})," to transform ",(0,t.jsx)(s.code,{children:"ts"})," to ",(0,t.jsx)(s.code,{children:"js"}),". To make the transition smoothly, we introduce ",(0,t.jsx)(s.code,{children:"legacy"})," presets as a fallback when the new codes don't work yet."]})}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.pre,{children:(0,t.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,t.jsxs)(s.h4,{id:"support-mts-extension",children:["Support ",(0,t.jsx)(s.code,{children:".mts"})," extension"]}),"\n",(0,t.jsxs)(s.p,{children:["To work with ",(0,t.jsx)(s.code,{children:".mts"})," extension, besides the requirement to run Jest and ",(0,t.jsx)(s.code,{children:"ts-jest"})," in ESM mode, there are a few extra requirements to be met:"]}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"package.json"})," should contain ",(0,t.jsx)(s.code,{children:'"type": "module"'})]}),"\n",(0,t.jsxs)(s.li,{children:["A custom Jest resolver to resolve ",(0,t.jsx)(s.code,{children:".mjs"})," extension, see our simple one at ",(0,t.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,t.jsxs)(s.li,{children:[(0,t.jsx)(s.code,{children:"tsconfig.json"})," should at least contain these following options"]}),"\n"]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,o.R)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.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.2bd66cbf.js b/assets/js/6789ef91.2bd66cbf.js new file mode 100644 index 0000000000..99385d29e0 --- /dev/null +++ b/assets/js/6789ef91.2bd66cbf.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3960],{5464:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>r,default:()=>j,frontMatter:()=>o,metadata:()=>d,toc:()=>l});var t=n(4848),i=n(8453);const o={id:"options",title:"Options"},r=void 0,d={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/getting-started/options.md",tags:[],version:"26.5",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,i.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(s.h3,{id:"introduction",children:"Introduction"}),"\n",(0,t.jsxs)(s.p,{children:["All ",(0,t.jsx)(s.code,{children:"ts-jest"})," specific options are located under the ",(0,t.jsx)(s.code,{children:"globals"})," of Jest config object in the ",(0,t.jsx)(s.code,{children:"package.json"})," file of your project,\nor through a ",(0,t.jsx)(s.code,{children:"jest.config.js"}),", or ",(0,t.jsx)(s.code,{children:"jest.config.ts"})," file."]}),"\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 // ts-jest configuration goes here\n }\n }\n }\n}\n'})}),"\n",(0,t.jsx)(s.p,{children:"Or through JavaScript:"}),"\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 // ts-jest configuration goes here\n },\n },\n}\n"})}),"\n",(0,t.jsxs)(s.admonition,{type:"tip",children:[(0,t.jsxs)(s.p,{children:["To utilize IDE suggestions, you can use ",(0,t.jsx)(s.code,{children:"JSDoc"})," comments to provide suggested ",(0,t.jsx)(s.code,{children:"ts-jest"})," configs for your Jest config:"]}),(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.h3,{id:"options",children:"Options"}),"\n",(0,t.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,t.jsxs)(s.table,{children:[(0,t.jsx)(s.thead,{children:(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.th,{children:"Option"}),(0,t.jsx)(s.th,{children:"Description"}),(0,t.jsx)(s.th,{children:"Type"}),(0,t.jsx)(s.th,{children:"Default"})]})}),(0,t.jsxs)(s.tbody,{children:[(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/compiler",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"compiler"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"string"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:'"typescript"'})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/tsconfig",children:(0,t.jsxs)(s.strong,{children:[(0,t.jsx)(s.code,{children:"tsconfig"})," or ",(0,t.jsx)(s.code,{children:"tsConfig(DEPRECATED)"})]})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"string"}),"|",(0,t.jsx)(s.code,{children:"object"}),"|",(0,t.jsx)(s.code,{children:"boolean"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"auto"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/isolatedModules",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"isolatedModules"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"boolean"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"disabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/astTransformers",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"astTransformers"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"object"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"auto"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/diagnostics",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"diagnostics"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"boolean"}),"|",(0,t.jsx)(s.code,{children:"object"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"enabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/babelConfig",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"babelConfig"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"boolean"}),"|",(0,t.jsx)(s.code,{children:"string"}),"|",(0,t.jsx)(s.code,{children:"object"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"disabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"stringifyContentPathRegex"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"string"}),"|",(0,t.jsx)(s.code,{children:"RegExp"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"disabled"})})]})]})]})]})}function j(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.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/6789ef91.78ef85f3.js b/assets/js/6789ef91.78ef85f3.js deleted file mode 100644 index 4e0d118ebb..0000000000 --- a/assets/js/6789ef91.78ef85f3.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3960],{5464:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>r,default:()=>j,frontMatter:()=>o,metadata:()=>d,toc:()=>l});var t=n(4848),i=n(8453);const o={id:"options",title:"Options"},r=void 0,d={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:!1,unlisted:!1,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:1726058855e3,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"}},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,i.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(s.h3,{id:"introduction",children:"Introduction"}),"\n",(0,t.jsxs)(s.p,{children:["All ",(0,t.jsx)(s.code,{children:"ts-jest"})," specific options are located under the ",(0,t.jsx)(s.code,{children:"globals"})," of Jest config object in the ",(0,t.jsx)(s.code,{children:"package.json"})," file of your project,\nor through a ",(0,t.jsx)(s.code,{children:"jest.config.js"}),", or ",(0,t.jsx)(s.code,{children:"jest.config.ts"})," file."]}),"\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 // ts-jest configuration goes here\n }\n }\n }\n}\n'})}),"\n",(0,t.jsx)(s.p,{children:"Or through JavaScript:"}),"\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 // ts-jest configuration goes here\n },\n },\n}\n"})}),"\n",(0,t.jsxs)(s.admonition,{type:"tip",children:[(0,t.jsxs)(s.p,{children:["To utilize IDE suggestions, you can use ",(0,t.jsx)(s.code,{children:"JSDoc"})," comments to provide suggested ",(0,t.jsx)(s.code,{children:"ts-jest"})," configs for your Jest config:"]}),(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.h3,{id:"options",children:"Options"}),"\n",(0,t.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,t.jsxs)(s.table,{children:[(0,t.jsx)(s.thead,{children:(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.th,{children:"Option"}),(0,t.jsx)(s.th,{children:"Description"}),(0,t.jsx)(s.th,{children:"Type"}),(0,t.jsx)(s.th,{children:"Default"})]})}),(0,t.jsxs)(s.tbody,{children:[(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/compiler",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"compiler"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"string"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:'"typescript"'})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/tsconfig",children:(0,t.jsxs)(s.strong,{children:[(0,t.jsx)(s.code,{children:"tsconfig"})," or ",(0,t.jsx)(s.code,{children:"tsConfig(DEPRECATED)"})]})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"string"}),"|",(0,t.jsx)(s.code,{children:"object"}),"|",(0,t.jsx)(s.code,{children:"boolean"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"auto"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/isolatedModules",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"isolatedModules"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"boolean"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"disabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/astTransformers",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"astTransformers"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"object"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"auto"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/diagnostics",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"diagnostics"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"boolean"}),"|",(0,t.jsx)(s.code,{children:"object"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"enabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/babelConfig",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"babelConfig"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"boolean"}),"|",(0,t.jsx)(s.code,{children:"string"}),"|",(0,t.jsx)(s.code,{children:"object"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"disabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"stringifyContentPathRegex"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"string"}),"|",(0,t.jsx)(s.code,{children:"RegExp"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"disabled"})})]})]})]})]})}function j(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.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.68408ce5.js b/assets/js/684ec830.68408ce5.js new file mode 100644 index 0000000000..4b1c725285 --- /dev/null +++ b/assets/js/684ec830.68408ce5.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5584],{8076:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>m,frontMatter:()=>l,metadata:()=>c,toc:()=>d});var n=s(4848),r=s(8453),o=s(9489),a=s(7227);const l={title:"Compiler option"},i=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Compiler option"}},u={},d=[{value:"Example",id:"example",level:3}];function p(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["The ",(0,n.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,n.jsxs)(t.p,{children:["The default value is ",(0,n.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,n.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,n.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,n.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,n.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,n.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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/684ec830.8ec8817b.js b/assets/js/684ec830.8ec8817b.js deleted file mode 100644 index de5d73ddaf..0000000000 --- a/assets/js/684ec830.8ec8817b.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5584],{8076:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>m,frontMatter:()=>l,metadata:()=>c,toc:()=>d});var n=s(4848),r=s(8453),o=s(9489),a=s(7227);const l={title:"Compiler option"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Compiler option"}},u={},d=[{value:"Example",id:"example",level:3}];function p(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["The ",(0,n.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,n.jsxs)(t.p,{children:["The default value is ",(0,n.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,n.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,n.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,n.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,n.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,n.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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.002ed3d5.js b/assets/js/6bc4332d.002ed3d5.js new file mode 100644 index 0000000000..736068f08a --- /dev/null +++ b/assets/js/6bc4332d.002ed3d5.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7350],{1363:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>a,frontMatter:()=>r,metadata:()=>c,toc:()=>d});var n=s(4848),o=s(8453);const r={id:"processing",title:"Processing flow"},i=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/processing.md",tags:[],version:"27.1",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},l={},d=[{value:"Jest process",id:"jest-process",level:2},{value:"ts-jest process",id:"ts-jest-process",level:2}];function u(e){const t={code:"code",em:"em",h2:"h2",img:"img",p:"p",...(0,o.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,n.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,n.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,n.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,o.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(u,{...e})}):u(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/6bc4332d.34515972.js b/assets/js/6bc4332d.34515972.js deleted file mode 100644 index 32c64a3ec3..0000000000 --- a/assets/js/6bc4332d.34515972.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7350],{1363:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>a,frontMatter:()=>r,metadata:()=>c,toc:()=>u});var n=s(4848),o=s(8453);const r={id:"processing",title:"Processing flow"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},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,o.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,n.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,n.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,n.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,o.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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.ae4d20a3.js b/assets/js/6cdc57e1.ae4d20a3.js deleted file mode 100644 index f93b6d9dc0..0000000000 --- a/assets/js/6cdc57e1.ae4d20a3.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9995],{8638:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>a,frontMatter:()=>r,metadata:()=>c,toc:()=>u});var n=s(4848),o=s(8453);const r={id:"processing",title:"Processing flow"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},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,o.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,n.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,n.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,n.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,o.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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.e9443e5b.js b/assets/js/6cdc57e1.e9443e5b.js new file mode 100644 index 0000000000..2ad7203573 --- /dev/null +++ b/assets/js/6cdc57e1.e9443e5b.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9995],{8638:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>a,frontMatter:()=>r,metadata:()=>c,toc:()=>d});var n=s(4848),o=s(8453);const r={id:"processing",title:"Processing flow"},i=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/processing.md",tags:[],version:"27.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},l={},d=[{value:"Jest process",id:"jest-process",level:2},{value:"ts-jest process",id:"ts-jest-process",level:2}];function u(e){const t={code:"code",em:"em",h2:"h2",img:"img",p:"p",...(0,o.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,n.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,n.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,n.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,o.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(u,{...e})}):u(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.97e8860d.js b/assets/js/6f04af8d.97e8860d.js new file mode 100644 index 0000000000..3664217743 --- /dev/null +++ b/assets/js/6f04af8d.97e8860d.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6018],{8994:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>p,frontMatter:()=>l,metadata:()=>c,toc:()=>d});var s=n(4848),a=n(8453),r=n(9489),o=n(7227);const l={title:"Isolated Modules option"},i=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/isolatedModules.md",tags:[],version:"current",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Isolated Modules option"}},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,a.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default ",(0,s.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,s.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,s.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,s.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,s.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,s.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsxs)(r.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.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,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.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,s.jsx)(o.A,{value:"JSON",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,s.jsxs)(t.p,{children:["Using ",(0,s.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,s.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,s.jsx)(t.code,{children:"include"})," in ",(0,s.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,s.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,s.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,s.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,s.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,s.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,s.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,s.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,s.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,s.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,s.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function p(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var s=n(4164);const a={tabItem:"tabItem_Ymn6"};var r=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,s.A)(a.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),a=n(4164),r=n(4245),o=n(6347),l=n(6494),i=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:a}}=e;return{value:t,label:n,attributes:s,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 p(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 a=(0,o.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,i.aZ)(r),(0,s.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:n=!1,groupId:a}=e,r=h(e),[o,i]=(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:r}))),[c,d]=m({queryString:n,groupId:a}),[f,j]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,r]=(0,u.Dv)(n);return[a,(0,s.useCallback)((e=>{n&&r.set(e)}),[n,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,s.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=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:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),u=e=>{const t=e.currentTarget,n=i.indexOf(t),a=l[n].value;a!==s&&(c(t),o(a))},d=e=>{let t=null;switch(e.key){case"Enter":u(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,b.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:r}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>i.push(e),onKeyDown:d,onClick:u,...r,className:(0,a.A)("tabs__item",g.tabItem,r?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:r}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===r));return e?(0,s.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,s.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,n)=>{n.d(t,{R:()=>o,x:()=>l});var s=n(6540);const a={},r=s.createContext(a);function o(e){const t=s.useContext(r);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(a):e.components||a:o(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/6f04af8d.f9a72019.js b/assets/js/6f04af8d.f9a72019.js deleted file mode 100644 index 3087ff621c..0000000000 --- a/assets/js/6f04af8d.f9a72019.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6018],{8994:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>p,frontMatter:()=>l,metadata:()=>c,toc:()=>d});var s=n(4848),a=n(8453),r=n(9489),o=n(7227);const l={title:"Isolated Modules option"},i=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/isolatedModules.md",tags:[],version:"current",lastUpdatedBy:"renovate[bot]",lastUpdatedAt:1726058855e3,frontMatter:{title:"Isolated Modules option"}},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,a.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default ",(0,s.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,s.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,s.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,s.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,s.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,s.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsxs)(r.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.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,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.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,s.jsx)(o.A,{value:"JSON",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,s.jsxs)(t.p,{children:["Using ",(0,s.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,s.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,s.jsx)(t.code,{children:"include"})," in ",(0,s.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,s.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,s.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,s.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,s.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,s.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,s.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,s.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,s.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,s.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,s.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function p(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var s=n(4164);const a={tabItem:"tabItem_Ymn6"};var r=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,s.A)(a.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),a=n(4164),r=n(4245),o=n(6347),l=n(6494),i=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:a}}=e;return{value:t,label:n,attributes:s,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 p(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 a=(0,o.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,i.aZ)(r),(0,s.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:n=!1,groupId:a}=e,r=h(e),[o,i]=(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:r}))),[c,d]=m({queryString:n,groupId:a}),[f,j]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,r]=(0,u.Dv)(n);return[a,(0,s.useCallback)((e=>{n&&r.set(e)}),[n,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,s.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=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:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),u=e=>{const t=e.currentTarget,n=i.indexOf(t),a=l[n].value;a!==s&&(c(t),o(a))},d=e=>{let t=null;switch(e.key){case"Enter":u(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,b.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:r}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>i.push(e),onKeyDown:d,onClick:u,...r,className:(0,a.A)("tabs__item",g.tabItem,r?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:r}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===r));return e?(0,s.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,s.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,n)=>{n.d(t,{R:()=>o,x:()=>l});var s=n(6540);const a={},r=s.createContext(a);function o(e){const t=s.useContext(r);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(a):e.components||a:o(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/6f4d8994.91909b8e.js b/assets/js/6f4d8994.91909b8e.js deleted file mode 100644 index f928d50521..0000000000 --- a/assets/js/6f4d8994.91909b8e.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3021],{6434:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>p,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var s=n(4848),i=n(8453);const r={id:"version-checking",title:"Version checking"},o=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},d={},a=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default, ",(0,s.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,s.jsx)(t.code,{children:"jest"}),"/",(0,s.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,s.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\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_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Windows"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,s.jsxs)(t.p,{children:["As long as the environment variable ",(0,s.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,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/6f4d8994.c98f430b.js b/assets/js/6f4d8994.c98f430b.js new file mode 100644 index 0000000000..e432f4050d --- /dev/null +++ b/assets/js/6f4d8994.c98f430b.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3021],{6434:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>p,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var s=n(4848),i=n(8453);const r={id:"version-checking",title:"Version checking"},o=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},a=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default, ",(0,s.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,s.jsx)(t.code,{children:"jest"}),"/",(0,s.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,s.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\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_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Windows"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,s.jsxs)(t.p,{children:["As long as the environment variable ",(0,s.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,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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.952f6ac2.js b/assets/js/6f82a5f4.952f6ac2.js new file mode 100644 index 0000000000..06e364c354 --- /dev/null +++ b/assets/js/6f82a5f4.952f6ac2.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3429],{9643:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>p,frontMatter:()=>i,metadata:()=>d,toc:()=>l});var o=s(4848),n=s(8453);const i={id:"test-helpers",title:"Test helpers"},r=void 0,d={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/guides/test-helpers.md",tags:[],version:"26.5",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,n.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(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 p(e={}){const{wrapper:t}={...(0,n.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:()=>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.44c93e87.js b/assets/js/7335c74d.44c93e87.js deleted file mode 100644 index ea86450741..0000000000 --- a/assets/js/7335c74d.44c93e87.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7983],{787:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>h,frontMatter:()=>l,metadata:()=>u,toc:()=>d});var r=n(4848),s=n(8453),a=n(9489),o=n(7227);const l={id:"debugging",title:"Debugging ts-jest"},i=void 0,u={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:!1,unlisted:!1,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:1726058855e3,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"}},c={},d=[];function g(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,s.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["You can activate the debug logger by setting the environment variable ",(0,r.jsx)(t.code,{children:"TS_JEST_LOG"})," before running tests.\nThe output of the logger will be in ",(0,r.jsx)(t.strong,{children:"ts-jest.log"})," in current working directory."]}),"\n",(0,r.jsxs)(t.p,{children:["The debug logger contains some useful information about how internal ",(0,r.jsx)(t.code,{children:"ts-jest"})," works, including which files are processed,\nwhich Jest config or TypeScript config is used etc."]}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{children:"export TS_JEST_LOG=ts-jest.log\n"})}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsx)(t.strong,{children:"Windows"})}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(o.A,{value:"Command",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-Command",metastring:"Prompt tab",children:"set TS_JEST_LOG=ts-jest.log\n"})})}),(0,r.jsx)(o.A,{value:"PowerShell",children:(0,r.jsx)(t.pre,{children:(0,r.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,r.jsx)(t,{...e,children:(0,r.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/7335c74d.ae52fb11.js b/assets/js/7335c74d.ae52fb11.js new file mode 100644 index 0000000000..2458c23c08 --- /dev/null +++ b/assets/js/7335c74d.ae52fb11.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7983],{787:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>h,frontMatter:()=>l,metadata:()=>u,toc:()=>d});var r=n(4848),s=n(8453),a=n(9489),o=n(7227);const l={id:"debugging",title:"Debugging ts-jest"},i=void 0,u={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/debugging.md",tags:[],version:"29.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},c={},d=[];function g(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,s.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["You can activate the debug logger by setting the environment variable ",(0,r.jsx)(t.code,{children:"TS_JEST_LOG"})," before running tests.\nThe output of the logger will be in ",(0,r.jsx)(t.strong,{children:"ts-jest.log"})," in current working directory."]}),"\n",(0,r.jsxs)(t.p,{children:["The debug logger contains some useful information about how internal ",(0,r.jsx)(t.code,{children:"ts-jest"})," works, including which files are processed,\nwhich Jest config or TypeScript config is used etc."]}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{children:"export TS_JEST_LOG=ts-jest.log\n"})}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsx)(t.strong,{children:"Windows"})}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(o.A,{value:"Command",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-Command",metastring:"Prompt tab",children:"set TS_JEST_LOG=ts-jest.log\n"})})}),(0,r.jsx)(o.A,{value:"PowerShell",children:(0,r.jsx)(t.pre,{children:(0,r.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,r.jsx)(t,{...e,children:(0,r.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.d3d9b6a3.js b/assets/js/73f5a02c.d3d9b6a3.js new file mode 100644 index 0000000000..49ba366507 --- /dev/null +++ b/assets/js/73f5a02c.d3d9b6a3.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8080],{7254:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>l,default:()=>p,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var s=n(4848),r=n(8453),o=n(9489),a=n(7227);const i={title:"Stringify content option"},l=void 0,u={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/stringifyContentPathRegex.md",tags:[],version:"current",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Stringify content option"}},c={},d=[{value:"Example",id:"example",level:3}];function h(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["The ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,s.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,s.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,s.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,s.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,s.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,s.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,s.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,s.jsx)(t.code,{children:"transform"})," option pointing to ",(0,s.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,s.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsxs)(t.p,{children:["In the ",(0,s.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,s.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,s.jsxs)(o.A,{groupId:"code-examples",children:[(0,s.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(a.A,{value:"JSON",children:(0,s.jsx)(t.pre,{children:(0,s.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,r.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/73f5a02c.d8a06853.js b/assets/js/73f5a02c.d8a06853.js deleted file mode 100644 index b780f369dd..0000000000 --- a/assets/js/73f5a02c.d8a06853.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8080],{7254:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>l,default:()=>p,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var s=n(4848),r=n(8453),o=n(9489),a=n(7227);const i={title:"Stringify content option"},l=void 0,u={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/stringifyContentPathRegex.md",tags:[],version:"current",lastUpdatedBy:"renovate[bot]",lastUpdatedAt:1726058855e3,frontMatter:{title:"Stringify content option"}},c={},d=[{value:"Example",id:"example",level:3}];function h(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["The ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,s.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,s.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,s.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,s.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,s.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,s.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,s.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,s.jsx)(t.code,{children:"transform"})," option pointing to ",(0,s.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,s.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsxs)(t.p,{children:["In the ",(0,s.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,s.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,s.jsxs)(o.A,{groupId:"code-examples",children:[(0,s.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(a.A,{value:"JSON",children:(0,s.jsx)(t.pre,{children:(0,s.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,r.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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.243e2453.js b/assets/js/75ab14ad.243e2453.js new file mode 100644 index 0000000000..972d842b9d --- /dev/null +++ b/assets/js/75ab14ad.243e2453.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6506],{4435:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>i,metadata:()=>a,toc:()=>d});var s=n(4848),o=n(8453);const i={title:"Stringify content option"},r=void 0,a={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Stringify content option"}},c={},d=[{value:"Example",id:"example",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["The ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,s.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,s.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,s.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,s.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,s.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,s.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,s.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,s.jsx)(t.code,{children:"transform"})," option pointing to ",(0,s.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,s.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsxs)(t.p,{children:["In the ",(0,s.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,s.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,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.pre,{children:(0,s.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,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(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/75ab14ad.9a1cdac9.js b/assets/js/75ab14ad.9a1cdac9.js deleted file mode 100644 index d433d9a2d7..0000000000 --- a/assets/js/75ab14ad.9a1cdac9.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6506],{4435:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>i,metadata:()=>a,toc:()=>d});var s=n(4848),o=n(8453);const i={title:"Stringify content option"},r=void 0,a={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Stringify content option"}},c={},d=[{value:"Example",id:"example",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["The ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,s.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,s.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,s.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,s.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,s.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,s.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,s.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,s.jsx)(t.code,{children:"transform"})," option pointing to ",(0,s.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,s.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsxs)(t.p,{children:["In the ",(0,s.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,s.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,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.pre,{children:(0,s.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,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(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.c2245ad6.js b/assets/js/78f0a226.c2245ad6.js new file mode 100644 index 0000000000..d3bbace3f9 --- /dev/null +++ b/assets/js/78f0a226.c2245ad6.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8313],{8502:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>r,contentTitle:()=>i,default:()=>b,frontMatter:()=>l,metadata:()=>a,toc:()=>c});var t=s(4848),o=s(8453);const l={title:"Babel Config option"},i=void 0,a={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Babel Config option"}},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,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.code,{children:"ts-jest"})," by default does ",(0,t.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,t.jsx)(n.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,t.jsxs)(n.p,{children:["The option is ",(0,t.jsx)(n.code,{children:"babelConfig"})," and it works pretty much as the ",(0,t.jsx)(n.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"true"}),": enables Babel processing. ",(0,t.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,t.jsx)(n.code,{children:".babelrc"}),", ",(0,t.jsx)(n.code,{children:".babelrc.js"}),", ",(0,t.jsx)(n.code,{children:"babel.config.js"})," file or a ",(0,t.jsx)(n.code,{children:"babel"})," section in the ",(0,t.jsx)(n.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,t.jsx)(n.code,{children:"babel-jest"})," processor."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"{ ... }"}),": inline ",(0,t.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,t.jsx)(n.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,t.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,t.jsxs)(n.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,t.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.pre,{children:(0,t.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,t.jsxs)(n.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,t.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,t.jsxs)(n.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,t.jsx)(n.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.p,{children:"or"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,t.jsxs)(n.p,{children:["Refer to the ",(0,t.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.pre,{children:(0,t.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,o.R)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(d,{...e})}):d(e)}},8453:(e,n,s)=>{s.d(n,{R:()=>i,x:()=>a});var t=s(6540);const o={},l=t.createContext(o);function i(e){const n=t.useContext(l);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),t.createElement(l.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/78f0a226.ca8528be.js b/assets/js/78f0a226.ca8528be.js deleted file mode 100644 index 4f4329df48..0000000000 --- a/assets/js/78f0a226.ca8528be.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8313],{8502:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>r,contentTitle:()=>i,default:()=>b,frontMatter:()=>l,metadata:()=>a,toc:()=>c});var t=s(4848),o=s(8453);const l={title:"Babel Config option"},i=void 0,a={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Babel Config option"}},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,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.code,{children:"ts-jest"})," by default does ",(0,t.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,t.jsx)(n.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,t.jsxs)(n.p,{children:["The option is ",(0,t.jsx)(n.code,{children:"babelConfig"})," and it works pretty much as the ",(0,t.jsx)(n.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"true"}),": enables Babel processing. ",(0,t.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,t.jsx)(n.code,{children:".babelrc"}),", ",(0,t.jsx)(n.code,{children:".babelrc.js"}),", ",(0,t.jsx)(n.code,{children:"babel.config.js"})," file or a ",(0,t.jsx)(n.code,{children:"babel"})," section in the ",(0,t.jsx)(n.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,t.jsx)(n.code,{children:"babel-jest"})," processor."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"{ ... }"}),": inline ",(0,t.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,t.jsx)(n.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,t.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,t.jsxs)(n.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,t.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.pre,{children:(0,t.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,t.jsxs)(n.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,t.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,t.jsxs)(n.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,t.jsx)(n.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.p,{children:"or"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,t.jsxs)(n.p,{children:["Refer to the ",(0,t.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.pre,{children:(0,t.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,o.R)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(d,{...e})}):d(e)}},8453:(e,n,s)=>{s.d(n,{R:()=>i,x:()=>a});var t=s(6540);const o={},l=t.createContext(o);function i(e){const n=t.useContext(l);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),t.createElement(l.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/7aac82f3.93026992.js b/assets/js/7aac82f3.93026992.js new file mode 100644 index 0000000000..848e4ba58a --- /dev/null +++ b/assets/js/7aac82f3.93026992.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6576],{6388:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>u,contentTitle:()=>l,default:()=>j,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var n=t(4848),r=t(8453),o=t(9489),a=t(7227);const i={id:"esm-support",title:"ESM Support"},l=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/guides/esm-support.md",tags:[],version:"29.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(s.p,{children:["To use ",(0,n.jsx)(s.code,{children:"ts-jest"})," with ESM support:"]}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:["Check ",(0,n.jsx)(s.a,{href:"https://jestjs.io/docs/en/ecmascript-modules",children:"ESM Jest documentation"}),"."]}),"\n",(0,n.jsxs)(s.li,{children:["Enable ",(0,n.jsx)(s.a,{href:"../getting-started/options/useESM",children:"useESM"})," ",(0,n.jsx)(s.code,{children:"true"})," for ",(0,n.jsx)(s.code,{children:"ts-jest"})," config."]}),"\n",(0,n.jsxs)(s.li,{children:["Include ",(0,n.jsx)(s.code,{children:".ts"})," in ",(0,n.jsx)(s.a,{href:"https://jestjs.io/docs/en/next/configuration#extensionstotreatasesm-arraystring",children:"extensionsToTreatAsEsm"})," Jest config option."]}),"\n",(0,n.jsxs)(s.li,{children:["Ensure that ",(0,n.jsx)(s.code,{children:"tsconfig"})," has ",(0,n.jsx)(s.code,{children:"module"})," with value for ESM, e.g. ",(0,n.jsx)(s.code,{children:"ES2015"})," or ",(0,n.jsx)(s.code,{children:"ES2020"})," etc..."]}),"\n"]}),"\n",(0,n.jsx)(s.h3,{id:"esm-presets",children:"ESM presets"}),"\n",(0,n.jsxs)(s.p,{children:["There are also ",(0,n.jsx)(s.a,{href:"/ts-jest/docs/29.0/getting-started/presets",children:"3 presets"})," to work with ESM."]}),"\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.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsx)(s.h4,{id:"manual-configuration",children:"Manual configuration"}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.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 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,n.jsx)(a.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 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,n.jsx)(a.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 "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,n.jsx)(s.h4,{id:"use-esm-presets",children:"Use ESM 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 switch to ",(0,n.jsx)(s.code,{children:"esbuild"}),"/",(0,n.jsx)(s.code,{children:"swc"})," to transform ",(0,n.jsx)(s.code,{children:"ts"})," to ",(0,n.jsx)(s.code,{children:"js"}),". 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.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.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 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,n.jsx)(a.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 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,n.jsx)(a.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 "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,n.jsxs)(s.h4,{id:"support-mts-extension",children:["Support ",(0,n.jsx)(s.code,{children:".mts"})," extension"]}),"\n",(0,n.jsxs)(s.p,{children:["To work with ",(0,n.jsx)(s.code,{children:".mts"})," extension, besides the requirement to run Jest and ",(0,n.jsx)(s.code,{children:"ts-jest"})," in ESM mode, there are a few extra requirements to be met:"]}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.code,{children:"package.json"})," should contain ",(0,n.jsx)(s.code,{children:'"type": "module"'})]}),"\n",(0,n.jsxs)(s.li,{children:["A custom Jest resolver to resolve ",(0,n.jsx)(s.code,{children:".mjs"})," extension, see our simple one at ",(0,n.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,n.jsxs)(s.li,{children:[(0,n.jsx)(s.code,{children:"tsconfig.json"})," should at least contain these following options"]}),"\n"]}),"\n",(0,n.jsx)(s.pre,{children:(0,n.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,r.R)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.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/7aac82f3.c87d5acd.js b/assets/js/7aac82f3.c87d5acd.js deleted file mode 100644 index 97ac9c1d3b..0000000000 --- a/assets/js/7aac82f3.c87d5acd.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6576],{6388:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>u,contentTitle:()=>l,default:()=>j,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var n=t(4848),r=t(8453),o=t(9489),a=t(7227);const i={id:"esm-support",title:"ESM Support"},l=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},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,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(s.p,{children:["To use ",(0,n.jsx)(s.code,{children:"ts-jest"})," with ESM support:"]}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:["Check ",(0,n.jsx)(s.a,{href:"https://jestjs.io/docs/en/ecmascript-modules",children:"ESM Jest documentation"}),"."]}),"\n",(0,n.jsxs)(s.li,{children:["Enable ",(0,n.jsx)(s.a,{href:"../getting-started/options/useESM",children:"useESM"})," ",(0,n.jsx)(s.code,{children:"true"})," for ",(0,n.jsx)(s.code,{children:"ts-jest"})," config."]}),"\n",(0,n.jsxs)(s.li,{children:["Include ",(0,n.jsx)(s.code,{children:".ts"})," in ",(0,n.jsx)(s.a,{href:"https://jestjs.io/docs/en/next/configuration#extensionstotreatasesm-arraystring",children:"extensionsToTreatAsEsm"})," Jest config option."]}),"\n",(0,n.jsxs)(s.li,{children:["Ensure that ",(0,n.jsx)(s.code,{children:"tsconfig"})," has ",(0,n.jsx)(s.code,{children:"module"})," with value for ESM, e.g. ",(0,n.jsx)(s.code,{children:"ES2015"})," or ",(0,n.jsx)(s.code,{children:"ES2020"})," etc..."]}),"\n"]}),"\n",(0,n.jsx)(s.h3,{id:"esm-presets",children:"ESM presets"}),"\n",(0,n.jsxs)(s.p,{children:["There are also ",(0,n.jsx)(s.a,{href:"/ts-jest/docs/29.0/getting-started/presets",children:"3 presets"})," to work with ESM."]}),"\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.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsx)(s.h4,{id:"manual-configuration",children:"Manual configuration"}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.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 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,n.jsx)(a.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 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,n.jsx)(a.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 "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,n.jsx)(s.h4,{id:"use-esm-presets",children:"Use ESM 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 switch to ",(0,n.jsx)(s.code,{children:"esbuild"}),"/",(0,n.jsx)(s.code,{children:"swc"})," to transform ",(0,n.jsx)(s.code,{children:"ts"})," to ",(0,n.jsx)(s.code,{children:"js"}),". 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.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.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 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,n.jsx)(a.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 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,n.jsx)(a.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 "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,n.jsxs)(s.h4,{id:"support-mts-extension",children:["Support ",(0,n.jsx)(s.code,{children:".mts"})," extension"]}),"\n",(0,n.jsxs)(s.p,{children:["To work with ",(0,n.jsx)(s.code,{children:".mts"})," extension, besides the requirement to run Jest and ",(0,n.jsx)(s.code,{children:"ts-jest"})," in ESM mode, there are a few extra requirements to be met:"]}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.code,{children:"package.json"})," should contain ",(0,n.jsx)(s.code,{children:'"type": "module"'})]}),"\n",(0,n.jsxs)(s.li,{children:["A custom Jest resolver to resolve ",(0,n.jsx)(s.code,{children:".mjs"})," extension, see our simple one at ",(0,n.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,n.jsxs)(s.li,{children:[(0,n.jsx)(s.code,{children:"tsconfig.json"})," should at least contain these following options"]}),"\n"]}),"\n",(0,n.jsx)(s.pre,{children:(0,n.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,r.R)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.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.87840e5d.js b/assets/js/7b562fc7.87840e5d.js new file mode 100644 index 0000000000..64ad43b4ce --- /dev/null +++ b/assets/js/7b562fc7.87840e5d.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8647],{7605:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>h,contentTitle:()=>r,default:()=>l,frontMatter:()=>o,metadata:()=>c,toc:()=>a});var n=s(4848),i=s(8453);const o={id:"contributing",title:"Contributing"},r=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/contributing.md",tags:[],version:"29.2",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},h={},a=[{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 d(e){const t={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,n.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,n.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,n.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,n.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,n.jsxs)(t.ol,{children:["\n",(0,n.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,n.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,n.jsxs)(t.li,{children:["Update the ",(0,n.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,n.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,n.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,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,n.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,n.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,n.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,n.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,n.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,n.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,n.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,n.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 l(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(d,{...e})}):d(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/7b562fc7.f9a240cf.js b/assets/js/7b562fc7.f9a240cf.js deleted file mode 100644 index 14465a0fc5..0000000000 --- a/assets/js/7b562fc7.f9a240cf.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8647],{7605:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>h,contentTitle:()=>r,default:()=>l,frontMatter:()=>o,metadata:()=>c,toc:()=>a});var n=s(4848),i=s(8453);const o={id:"contributing",title:"Contributing"},r=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},h={},a=[{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 d(e){const t={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,n.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,n.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,n.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,n.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,n.jsxs)(t.ol,{children:["\n",(0,n.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,n.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,n.jsxs)(t.li,{children:["Update the ",(0,n.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,n.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,n.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,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,n.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,n.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,n.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,n.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,n.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,n.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,n.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,n.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 l(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(d,{...e})}):d(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.854393d2.js b/assets/js/7d1a64ae.854393d2.js deleted file mode 100644 index 36bbeb108e..0000000000 --- a/assets/js/7d1a64ae.854393d2.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7352],{2296:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>h,contentTitle:()=>r,default:()=>l,frontMatter:()=>o,metadata:()=>c,toc:()=>a});var n=s(4848),i=s(8453);const o={id:"contributing",title:"Contributing"},r=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},h={},a=[{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 d(e){const t={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,n.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,n.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,n.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,n.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,n.jsxs)(t.ol,{children:["\n",(0,n.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,n.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,n.jsxs)(t.li,{children:["Update the ",(0,n.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,n.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,n.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,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,n.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,n.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,n.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,n.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,n.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,n.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,n.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,n.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 l(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(d,{...e})}):d(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.bcf0000d.js b/assets/js/7d1a64ae.bcf0000d.js new file mode 100644 index 0000000000..7275a0ed8c --- /dev/null +++ b/assets/js/7d1a64ae.bcf0000d.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7352],{2296:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>h,contentTitle:()=>r,default:()=>l,frontMatter:()=>o,metadata:()=>c,toc:()=>a});var n=s(4848),i=s(8453);const o={id:"contributing",title:"Contributing"},r=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/contributing.md",tags:[],version:"27.1",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},h={},a=[{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 d(e){const t={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,n.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,n.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,n.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,n.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,n.jsxs)(t.ol,{children:["\n",(0,n.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,n.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,n.jsxs)(t.li,{children:["Update the ",(0,n.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,n.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,n.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,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,n.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,n.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,n.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,n.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,n.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,n.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,n.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,n.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 l(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(d,{...e})}):d(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.0b808c94.js b/assets/js/7dafce35.0b808c94.js new file mode 100644 index 0000000000..cf6e274b41 --- /dev/null +++ b/assets/js/7dafce35.0b808c94.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7083],{9073:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>l,default:()=>p,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var n=s(4848),r=s(8453),a=s(9489),o=s(7227);const i={title:"AST transformers option"},l=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"AST transformers option"}},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,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:[(0,n.jsx)(t.code,{children:"ts-jest"})," by default does hoisting for a few ",(0,n.jsx)(t.code,{children:"jest"})," methods via a TypeScript AST transformer. One can also create custom\nTypeScript AST transformers and provide them to ",(0,n.jsx)(t.code,{children:"ts-jest"})," to include into compilation process."]}),"\n",(0,n.jsxs)(t.p,{children:["The option is ",(0,n.jsx)(t.code,{children:"astTransformers"})," and it allows ones to specify which 3 types of TypeScript AST transformers to use with ",(0,n.jsx)(t.code,{children:"ts-jest"}),":"]}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.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,n.jsx)(t.code,{children:"import"})," instead of ",(0,n.jsx)(t.code,{children:"require"})," or ",(0,n.jsx)(t.code,{children:"define"})," )."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"after"})," means your transformers get run after TS ones, which gets transpiled syntax."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"afterDeclarations"})," means your transformers get run during ",(0,n.jsx)(t.code,{children:"d.ts"})," generation phase, allowing you to transform output type declarations."]}),"\n"]}),"\n",(0,n.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsx)(t.h4,{id:"basic-transformers",children:"Basic Transformers"}),"\n",(0,n.jsxs)(a.A,{groupId:"code-examples",children:[(0,n.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.h4,{id:"configuring-transformers-with-options",children:"Configuring transformers with options"}),"\n",(0,n.jsxs)(a.A,{groupId:"code-examples",children:[(0,n.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.h3,{id:"writing-custom-typescript-ast-transformers",children:"Writing custom TypeScript AST transformers"}),"\n",(0,n.jsxs)(t.p,{children:["To write a custom TypeScript AST transformers, one can take a look at ",(0,n.jsx)(t.a,{href:"https://github.com/kulshekhar/ts-jest/tree/main/src/transformers",children:"the one"})," that ",(0,n.jsx)(t.code,{children:"ts-jest"})," is using."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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/7dafce35.e7fa56f2.js b/assets/js/7dafce35.e7fa56f2.js deleted file mode 100644 index acf378b7b1..0000000000 --- a/assets/js/7dafce35.e7fa56f2.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7083],{9073:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>l,default:()=>p,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var n=s(4848),r=s(8453),a=s(9489),o=s(7227);const i={title:"AST transformers option"},l=void 0,c={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"AST transformers option"}},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,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:[(0,n.jsx)(t.code,{children:"ts-jest"})," by default does hoisting for a few ",(0,n.jsx)(t.code,{children:"jest"})," methods via a TypeScript AST transformer. One can also create custom\nTypeScript AST transformers and provide them to ",(0,n.jsx)(t.code,{children:"ts-jest"})," to include into compilation process."]}),"\n",(0,n.jsxs)(t.p,{children:["The option is ",(0,n.jsx)(t.code,{children:"astTransformers"})," and it allows ones to specify which 3 types of TypeScript AST transformers to use with ",(0,n.jsx)(t.code,{children:"ts-jest"}),":"]}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.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,n.jsx)(t.code,{children:"import"})," instead of ",(0,n.jsx)(t.code,{children:"require"})," or ",(0,n.jsx)(t.code,{children:"define"})," )."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"after"})," means your transformers get run after TS ones, which gets transpiled syntax."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"afterDeclarations"})," means your transformers get run during ",(0,n.jsx)(t.code,{children:"d.ts"})," generation phase, allowing you to transform output type declarations."]}),"\n"]}),"\n",(0,n.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsx)(t.h4,{id:"basic-transformers",children:"Basic Transformers"}),"\n",(0,n.jsxs)(a.A,{groupId:"code-examples",children:[(0,n.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.h4,{id:"configuring-transformers-with-options",children:"Configuring transformers with options"}),"\n",(0,n.jsxs)(a.A,{groupId:"code-examples",children:[(0,n.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.h3,{id:"writing-custom-typescript-ast-transformers",children:"Writing custom TypeScript AST transformers"}),"\n",(0,n.jsxs)(t.p,{children:["To write a custom TypeScript AST transformers, one can take a look at ",(0,n.jsx)(t.a,{href:"https://github.com/kulshekhar/ts-jest/tree/main/src/transformers",children:"the one"})," that ",(0,n.jsx)(t.code,{children:"ts-jest"})," is using."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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.014154ce.js b/assets/js/7ec61308.014154ce.js deleted file mode 100644 index a035b98f22..0000000000 --- a/assets/js/7ec61308.014154ce.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[992],{7428:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>l,default:()=>h,frontMatter:()=>i,metadata:()=>c,toc:()=>p});var s=n(4848),r=n(8453),o=n(9489),a=n(7227);const i={id:"paths-mapping",title:"Paths mapping"},l=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/paths-mapping.md",tags:[],version:"current",lastUpdatedBy:"renovate[bot]",lastUpdatedAt:1726058855e3,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"}},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,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["If you use ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,s.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,s.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,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,s.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,s.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,s.jsxs)(t.p,{children:["With the below config in your ",(0,s.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,s.jsxs)(o.A,{groupId:"code-examples",children:[(0,s.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(a.A,{value:"JSON",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,s.jsxs)(o.A,{groupId:"code-examples",children:[(0,s.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.p,{children:"With extra options as 2nd argument:"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"prefix"}),": append prefix to each of mapped config in the result"]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"useESM"}),": when using ",(0,s.jsx)(t.code,{children:"type: module"})," in ",(0,s.jsx)(t.code,{children:"package.json"}),", TypeScript enforces users to have explicit ",(0,s.jsx)(t.code,{children:"js"})," extension when importing\na ",(0,s.jsx)(t.code,{children:"ts"})," file. This option is to help ",(0,s.jsx)(t.code,{children:"pathsToModuleNameMapper"})," to create a config to suit with this scenario."]}),"\n"]})]})}function h(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(d,{...e})}):d(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),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,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 f(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,o=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: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,i.A)((()=>{j&&l(j)}),[j]);return{selectedValue:a,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:a,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.a_)(),u=e=>{const t=e.currentTarget,n=l.indexOf(t),r=i[n].value;r!==s&&(c(t),a(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:i.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 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,b.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=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:()=>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/7ec61308.369ef40d.js b/assets/js/7ec61308.369ef40d.js new file mode 100644 index 0000000000..110a1c875b --- /dev/null +++ b/assets/js/7ec61308.369ef40d.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[992],{7428:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>l,default:()=>h,frontMatter:()=>i,metadata:()=>c,toc:()=>p});var s=n(4848),r=n(8453),o=n(9489),a=n(7227);const i={id:"paths-mapping",title:"Paths mapping"},l=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/paths-mapping.md",tags:[],version:"current",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["If you use ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,s.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,s.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,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,s.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,s.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,s.jsxs)(t.p,{children:["With the below config in your ",(0,s.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,s.jsxs)(o.A,{groupId:"code-examples",children:[(0,s.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(a.A,{value:"JSON",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,s.jsxs)(o.A,{groupId:"code-examples",children:[(0,s.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.p,{children:"With extra options as 2nd argument:"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"prefix"}),": append prefix to each of mapped config in the result"]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"useESM"}),": when using ",(0,s.jsx)(t.code,{children:"type: module"})," in ",(0,s.jsx)(t.code,{children:"package.json"}),", TypeScript enforces users to have explicit ",(0,s.jsx)(t.code,{children:"js"})," extension when importing\na ",(0,s.jsx)(t.code,{children:"ts"})," file. This option is to help ",(0,s.jsx)(t.code,{children:"pathsToModuleNameMapper"})," to create a config to suit with this scenario."]}),"\n"]})]})}function h(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(d,{...e})}):d(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),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,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 f(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,o=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: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,i.A)((()=>{j&&l(j)}),[j]);return{selectedValue:a,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:a,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.a_)(),u=e=>{const t=e.currentTarget,n=l.indexOf(t),r=i[n].value;r!==s&&(c(t),a(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:i.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 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,b.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=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:()=>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/801c4327.3d1d5688.js b/assets/js/801c4327.3d1d5688.js deleted file mode 100644 index 049b8a8c0e..0000000000 --- a/assets/js/801c4327.3d1d5688.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2817],{3333:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>o,contentTitle:()=>d,default:()=>a,frontMatter:()=>i,metadata:()=>c,toc:()=>l});var n=t(4848),r=t(8453);const i={id:"presets",title:"Presets"},d=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},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,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(s.h3,{id:"the-presets",children:"The presets"}),"\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-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.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.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.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.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"}),"."]})]})]})]}),"\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.jsx)(s.pre,{children:(0,n.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,n.jsx)(s.pre,{children:(0,n.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,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.jsx)(s.pre,{children:(0,n.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,n.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,n.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,n.jsx)(s.pre,{children:(0,n.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,r.R)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.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/801c4327.c4100bc3.js b/assets/js/801c4327.c4100bc3.js new file mode 100644 index 0000000000..4501134ef3 --- /dev/null +++ b/assets/js/801c4327.c4100bc3.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2817],{3333:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>o,contentTitle:()=>d,default:()=>a,frontMatter:()=>i,metadata:()=>c,toc:()=>l});var n=t(4848),r=t(8453);const i={id:"presets",title:"Presets"},d=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/presets.md",tags:[],version:"27.1",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(s.h3,{id:"the-presets",children:"The presets"}),"\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-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.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.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.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.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"}),"."]})]})]})]}),"\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.jsx)(s.pre,{children:(0,n.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,n.jsx)(s.pre,{children:(0,n.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,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.jsx)(s.pre,{children:(0,n.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,n.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,n.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,n.jsx)(s.pre,{children:(0,n.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,r.R)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.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.12564495.js b/assets/js/850a2979.12564495.js deleted file mode 100644 index 1cf198a1dc..0000000000 --- a/assets/js/850a2979.12564495.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6964],{2414:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>o,contentTitle:()=>d,default:()=>a,frontMatter:()=>i,metadata:()=>c,toc:()=>l});var n=t(4848),r=t(8453);const i={id:"presets",title:"Presets"},d=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},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,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(s.h3,{id:"the-presets",children:"The presets"}),"\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-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.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.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.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.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"}),"."]})]})]})]}),"\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.jsx)(s.pre,{children:(0,n.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,n.jsx)(s.pre,{children:(0,n.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,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.jsx)(s.pre,{children:(0,n.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,n.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,n.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,n.jsx)(s.pre,{children:(0,n.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,r.R)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.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.df36c707.js b/assets/js/850a2979.df36c707.js new file mode 100644 index 0000000000..5bf053bba8 --- /dev/null +++ b/assets/js/850a2979.df36c707.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6964],{2414:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>o,contentTitle:()=>d,default:()=>a,frontMatter:()=>i,metadata:()=>c,toc:()=>l});var n=t(4848),r=t(8453);const i={id:"presets",title:"Presets"},d=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/presets.md",tags:[],version:"27.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(s.h3,{id:"the-presets",children:"The presets"}),"\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-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.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.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.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.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"}),"."]})]})]})]}),"\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.jsx)(s.pre,{children:(0,n.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,n.jsx)(s.pre,{children:(0,n.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,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.jsx)(s.pre,{children:(0,n.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,n.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,n.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,n.jsx)(s.pre,{children:(0,n.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,r.R)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.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.377f8769.js b/assets/js/86b5844b.377f8769.js new file mode 100644 index 0000000000..4a7d164218 --- /dev/null +++ b/assets/js/86b5844b.377f8769.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[988],{5655:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>l,default:()=>f,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var s=n(4848),r=n(8453),a=n(9489),o=n(7227);const i={id:"react-native",title:"Using with React Native"},l=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/guides/react-native.md",tags:[],version:"current",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["To use ",(0,s.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,s.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,s.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,s.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,s.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,s.jsx)(t.code,{children:".babelrc"})," to ",(0,s.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,s.jsxs)(a.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.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\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.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,s.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,s.jsxs)(t.p,{children:["Create a new ",(0,s.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,s.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,s.jsx)(t.code,{children:"jest"})," key of ",(0,s.jsx)(t.code,{children:"package.json"})," to ",(0,s.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,s.jsxs)(a.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.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,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.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 f(e={}){const{wrapper:t}={...(0,r.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:()=>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 b(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}),[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 f({value:e,tabValues:a})?e:null})();(0,i.A)((()=>{m&&l(m)}),[m]);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 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/86b5844b.fcfd1e4e.js b/assets/js/86b5844b.fcfd1e4e.js deleted file mode 100644 index 55359ba2bf..0000000000 --- a/assets/js/86b5844b.fcfd1e4e.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[988],{5655:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>l,default:()=>f,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var s=n(4848),r=n(8453),a=n(9489),o=n(7227);const i={id:"react-native",title:"Using with React Native"},l=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/guides/react-native.md",tags:[],version:"current",lastUpdatedBy:"renovate[bot]",lastUpdatedAt:1726058855e3,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"}},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,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["To use ",(0,s.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,s.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,s.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,s.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,s.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,s.jsx)(t.code,{children:".babelrc"})," to ",(0,s.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,s.jsxs)(a.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.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\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.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,s.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,s.jsxs)(t.p,{children:["Create a new ",(0,s.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,s.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,s.jsx)(t.code,{children:"jest"})," key of ",(0,s.jsx)(t.code,{children:"package.json"})," to ",(0,s.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,s.jsxs)(a.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.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,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.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 f(e={}){const{wrapper:t}={...(0,r.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:()=>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 b(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}),[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 f({value:e,tabValues:a})?e:null})();(0,i.A)((()=>{m&&l(m)}),[m]);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 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.82e0c91e.js b/assets/js/8b2f9623.82e0c91e.js deleted file mode 100644 index f63f18efe1..0000000000 --- a/assets/js/8b2f9623.82e0c91e.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8629],{8763:(t,e,o)=>{o.r(e),o.d(e,{assets:()=>c,contentTitle:()=>r,default:()=>a,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var s=o(4848),n=o(8453);const i={id:"troubleshooting",title:"Troubleshooting"},r=void 0,u={id:"guides/troubleshooting",title:"Troubleshooting",description:"You can check Jest troubleshooting guide or visit ts-jest [troubleshooting",source:"@site/versioned_docs/version-29.0/guides/troubleshooting.md",sourceDirName:"guides",slug:"/guides/troubleshooting",permalink:"/ts-jest/docs/29.0/guides/troubleshooting",draft:!1,unlisted:!1,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:1726058855e3,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"}},c={},d=[];function l(t){const e={a:"a",code:"code",p:"p",...(0,n.R)(),...t.components};return(0,s.jsxs)(e.p,{children:["You can check Jest ",(0,s.jsx)(e.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," or visit ",(0,s.jsx)(e.code,{children:"ts-jest"})," ",(0,s.jsx)(e.a,{href:"https://github.com/kulshekhar/ts-jest/blob/main/TROUBLESHOOTING.md",children:"troubleshooting\nguide"})]})}function a(t={}){const{wrapper:e}={...(0,n.R)(),...t.components};return e?(0,s.jsx)(e,{...t,children:(0,s.jsx)(l,{...t})}):l(t)}},8453:(t,e,o)=>{o.d(e,{R:()=>r,x:()=>u});var s=o(6540);const n={},i=s.createContext(n);function r(t){const e=s.useContext(i);return s.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function u(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(n):t.components||n:r(t.components),s.createElement(i.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/8b2f9623.f92c17b5.js b/assets/js/8b2f9623.f92c17b5.js new file mode 100644 index 0000000000..7cce2fc7f7 --- /dev/null +++ b/assets/js/8b2f9623.f92c17b5.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8629],{8763:(t,e,o)=>{o.r(e),o.d(e,{assets:()=>c,contentTitle:()=>r,default:()=>a,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var s=o(4848),n=o(8453);const i={id:"troubleshooting",title:"Troubleshooting"},r=void 0,u={id:"guides/troubleshooting",title:"Troubleshooting",description:"You can check Jest troubleshooting guide or visit ts-jest [troubleshooting",source:"@site/versioned_docs/version-29.0/guides/troubleshooting.md",sourceDirName:"guides",slug:"/guides/troubleshooting",permalink:"/ts-jest/docs/29.0/guides/troubleshooting",draft:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/guides/troubleshooting.md",tags:[],version:"29.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},c={},d=[];function l(t){const e={a:"a",code:"code",p:"p",...(0,n.R)(),...t.components};return(0,s.jsxs)(e.p,{children:["You can check Jest ",(0,s.jsx)(e.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," or visit ",(0,s.jsx)(e.code,{children:"ts-jest"})," ",(0,s.jsx)(e.a,{href:"https://github.com/kulshekhar/ts-jest/blob/main/TROUBLESHOOTING.md",children:"troubleshooting\nguide"})]})}function a(t={}){const{wrapper:e}={...(0,n.R)(),...t.components};return e?(0,s.jsx)(e,{...t,children:(0,s.jsx)(l,{...t})}):l(t)}},8453:(t,e,o)=>{o.d(e,{R:()=>r,x:()=>u});var s=o(6540);const n={},i=s.createContext(n);function r(t){const e=s.useContext(i);return s.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function u(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(n):t.components||n:r(t.components),s.createElement(i.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/8b622911.07eaf719.js b/assets/js/8b622911.07eaf719.js new file mode 100644 index 0000000000..c617cd3658 --- /dev/null +++ b/assets/js/8b622911.07eaf719.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1268],{5325:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>r,contentTitle:()=>c,default:()=>p,frontMatter:()=>i,metadata:()=>l,toc:()=>a});var o=t(4848),s=t(8453);const i={title:"TypeScript Config option"},c=void 0,l={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"TypeScript Config option"}},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,s.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:["The ",(0,o.jsx)(n.code,{children:"tsconfig"})," option allows you to define which ",(0,o.jsx)(n.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,o.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,o.jsxs)(n.p,{children:["By default ",(0,o.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(n.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,o.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,o.jsx)(n.code,{children:"ES2015"})," is used as ",(0,o.jsx)(n.code,{children:"target"})," instead of ",(0,o.jsx)(n.code,{children:"ES5"}),"."]}),"\n",(0,o.jsxs)(n.p,{children:["If you need to use defaults and force ",(0,o.jsx)(n.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,o.jsx)(n.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,o.jsx)(n.code,{children:"false"}),"."]}),"\n",(0,o.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsxs)(n.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,o.jsx)(n.code,{children:"tsconfig"})," 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 to start from the project root dir."]}),"\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 tsconfig: 'tsconfig.test.json',\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 "tsconfig": "tsconfig.test.json"\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 TypeScript ",(0,o.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,o.jsx)(n.code,{children:"tsconfig.json"}),"'s ",(0,o.jsx)(n.code,{children:"compilerOptions"}),"."]}),"\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 tsconfig: {\n importHelpers: 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 "tsconfig": {\n "importHelpers": true\n }\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,o.jsxs)(n.p,{children:["By default ",(0,o.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,o.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,o.jsx)(n.code,{children:"tsconfig"})," to ",(0,o.jsx)(n.code,{children:"false"}),"."]}),"\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 tsconfig: 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 "tsconfig": false\n }\n }\n }\n}\n'})})]})}function p(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.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/8b622911.7f1a0076.js b/assets/js/8b622911.7f1a0076.js deleted file mode 100644 index 46af5a6b4d..0000000000 --- a/assets/js/8b622911.7f1a0076.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1268],{5325:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>r,contentTitle:()=>c,default:()=>p,frontMatter:()=>i,metadata:()=>l,toc:()=>a});var o=t(4848),s=t(8453);const i={title:"TypeScript Config option"},c=void 0,l={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"TypeScript Config option"}},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,s.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:["The ",(0,o.jsx)(n.code,{children:"tsconfig"})," option allows you to define which ",(0,o.jsx)(n.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,o.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,o.jsxs)(n.p,{children:["By default ",(0,o.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(n.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,o.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,o.jsx)(n.code,{children:"ES2015"})," is used as ",(0,o.jsx)(n.code,{children:"target"})," instead of ",(0,o.jsx)(n.code,{children:"ES5"}),"."]}),"\n",(0,o.jsxs)(n.p,{children:["If you need to use defaults and force ",(0,o.jsx)(n.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,o.jsx)(n.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,o.jsx)(n.code,{children:"false"}),"."]}),"\n",(0,o.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsxs)(n.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,o.jsx)(n.code,{children:"tsconfig"})," 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 to start from the project root dir."]}),"\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 tsconfig: 'tsconfig.test.json',\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 "tsconfig": "tsconfig.test.json"\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 TypeScript ",(0,o.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,o.jsx)(n.code,{children:"tsconfig.json"}),"'s ",(0,o.jsx)(n.code,{children:"compilerOptions"}),"."]}),"\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 tsconfig: {\n importHelpers: 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 "tsconfig": {\n "importHelpers": true\n }\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,o.jsxs)(n.p,{children:["By default ",(0,o.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,o.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,o.jsx)(n.code,{children:"tsconfig"})," to ",(0,o.jsx)(n.code,{children:"false"}),"."]}),"\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 tsconfig: 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 "tsconfig": false\n }\n }\n }\n}\n'})})]})}function p(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.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.03d57678.js b/assets/js/8cf61ec4.03d57678.js new file mode 100644 index 0000000000..c151b1c5f1 --- /dev/null +++ b/assets/js/8cf61ec4.03d57678.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5799],{5180:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>l,default:()=>h,frontMatter:()=>i,metadata:()=>d,toc:()=>c});var s=n(4848),o=n(8453);const i={title:"Isolated Modules option"},l=void 0,d={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Isolated Modules option"}},a={},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,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default ",(0,s.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,s.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,s.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,s.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,s.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,s.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\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 isolatedModules: true,\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 "isolatedModules": true\n }\n }\n }\n}\n'})}),"\n",(0,s.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,s.jsxs)(t.p,{children:["Using ",(0,s.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,s.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,s.jsx)(t.code,{children:"include"})," in ",(0,s.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,s.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,s.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,s.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,s.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,s.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,s.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,s.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,s.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,s.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,s.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function h(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(r,{...e})}):r(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>l,x:()=>d});var s=n(6540);const o={},i=s.createContext(o);function l(e){const t=s.useContext(i);return s.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(o):e.components||o:l(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/8cf61ec4.eda31ecc.js b/assets/js/8cf61ec4.eda31ecc.js deleted file mode 100644 index b1e84f26eb..0000000000 --- a/assets/js/8cf61ec4.eda31ecc.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5799],{5180:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>l,default:()=>h,frontMatter:()=>i,metadata:()=>a,toc:()=>c});var s=n(4848),o=n(8453);const i={title:"Isolated Modules option"},l=void 0,a={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Isolated Modules option"}},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,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default ",(0,s.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,s.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,s.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,s.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,s.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,s.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\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 isolatedModules: true,\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 "isolatedModules": true\n }\n }\n }\n}\n'})}),"\n",(0,s.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,s.jsxs)(t.p,{children:["Using ",(0,s.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,s.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,s.jsx)(t.code,{children:"include"})," in ",(0,s.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,s.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,s.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,s.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,s.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,s.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,s.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,s.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,s.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,s.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,s.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function h(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(r,{...e})}):r(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>l,x:()=>a});var s=n(6540);const o={},i=s.createContext(o);function l(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:l(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/8d536cde.90614982.js b/assets/js/8d536cde.90614982.js deleted file mode 100644 index 49ceb86d2b..0000000000 --- a/assets/js/8d536cde.90614982.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8979],{9934:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>h,contentTitle:()=>r,default:()=>l,frontMatter:()=>o,metadata:()=>c,toc:()=>a});var n=s(4848),i=s(8453);const o={id:"contributing",title:"Contributing"},r=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},h={},a=[{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 d(e){const t={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,n.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,n.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,n.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,n.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,n.jsxs)(t.ol,{children:["\n",(0,n.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,n.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,n.jsxs)(t.li,{children:["Update the ",(0,n.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,n.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,n.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,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,n.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,n.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,n.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,n.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,n.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,n.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,n.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,n.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 l(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(d,{...e})}):d(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/8d536cde.ec1daf61.js b/assets/js/8d536cde.ec1daf61.js new file mode 100644 index 0000000000..46add57619 --- /dev/null +++ b/assets/js/8d536cde.ec1daf61.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8979],{9934:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>h,contentTitle:()=>r,default:()=>l,frontMatter:()=>o,metadata:()=>c,toc:()=>a});var n=s(4848),i=s(8453);const o={id:"contributing",title:"Contributing"},r=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/contributing.md",tags:[],version:"28.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},h={},a=[{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 d(e){const t={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,n.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,n.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,n.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,n.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,n.jsxs)(t.ol,{children:["\n",(0,n.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,n.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,n.jsxs)(t.li,{children:["Update the ",(0,n.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,n.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,n.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,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,n.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,n.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,n.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,n.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,n.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,n.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,n.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,n.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 l(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(d,{...e})}):d(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.3ea7c194.js b/assets/js/8e5d45d9.3ea7c194.js new file mode 100644 index 0000000000..8037d19710 --- /dev/null +++ b/assets/js/8e5d45d9.3ea7c194.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7425],{9359:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var n=s(4848),o=s(8453);const r={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},i=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/introduction.md",tags:[],version:"29.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,o.R)(),...t.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,n.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,n.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,n.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,n.jsx)(e.code,{children:"preset-typescript"})," ",(0,n.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,n.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,n.jsx)(e.admonition,{type:"important",children:(0,n.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,n.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,n.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,o.R)(),...t.components};return e?(0,n.jsx)(e,{...t,children:(0,n.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/8e5d45d9.c14128ad.js b/assets/js/8e5d45d9.c14128ad.js deleted file mode 100644 index f46e9a473e..0000000000 --- a/assets/js/8e5d45d9.c14128ad.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7425],{9359:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var n=s(4848),o=s(8453);const r={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,o.R)(),...t.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,n.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,n.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,n.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,n.jsx)(e.code,{children:"preset-typescript"})," ",(0,n.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,n.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,n.jsx)(e.admonition,{type:"important",children:(0,n.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,n.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,n.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,o.R)(),...t.components};return e?(0,n.jsx)(e,{...t,children:(0,n.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.39d22b97.js b/assets/js/8e81f9bb.39d22b97.js deleted file mode 100644 index d77790f8a5..0000000000 --- a/assets/js/8e81f9bb.39d22b97.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8192],{8849:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>r,default:()=>j,frontMatter:()=>o,metadata:()=>d,toc:()=>l});var t=n(4848),i=n(8453);const o={id:"options",title:"Options"},r=void 0,d={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:!1,unlisted:!1,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:1726058855e3,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"}},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,i.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(s.h3,{id:"introduction",children:"Introduction"}),"\n",(0,t.jsxs)(s.p,{children:["All ",(0,t.jsx)(s.code,{children:"ts-jest"})," specific options are located under the ",(0,t.jsx)(s.code,{children:"globals"})," of Jest config object in the ",(0,t.jsx)(s.code,{children:"package.json"})," file of your project,\nor through a ",(0,t.jsx)(s.code,{children:"jest.config.js"}),", or ",(0,t.jsx)(s.code,{children:"jest.config.ts"})," file."]}),"\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 // ts-jest configuration goes here\n }\n }\n }\n}\n'})}),"\n",(0,t.jsx)(s.p,{children:"Or through JavaScript:"}),"\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 // ts-jest configuration goes here\n },\n },\n}\n"})}),"\n",(0,t.jsxs)(s.admonition,{type:"tip",children:[(0,t.jsxs)(s.p,{children:["To utilize IDE suggestions, you can use ",(0,t.jsx)(s.code,{children:"JSDoc"})," comments to provide suggested ",(0,t.jsx)(s.code,{children:"ts-jest"})," configs for your Jest config:"]}),(0,t.jsx)(s.pre,{children:(0,t.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,t.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,t.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.admonition,{type:"important",children:(0,t.jsxs)(s.p,{children:["When using TypeScript Jest config file, Jest will use ",(0,t.jsx)(s.code,{children:"ts-node"})," to compile the config file. ",(0,t.jsx)(s.code,{children:"ts-jest"})," doesn't take part in\nthat process."]})}),"\n",(0,t.jsx)(s.h3,{id:"options",children:"Options"}),"\n",(0,t.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,t.jsxs)(s.table,{children:[(0,t.jsx)(s.thead,{children:(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.th,{children:"Option"}),(0,t.jsx)(s.th,{children:"Description"}),(0,t.jsx)(s.th,{children:"Type"}),(0,t.jsx)(s.th,{children:"Default"})]})}),(0,t.jsxs)(s.tbody,{children:[(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/compiler",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"compiler"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"string"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:'"typescript"'})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/tsconfig",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"tsconfig"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"string"}),"|",(0,t.jsx)(s.code,{children:"object"}),"|",(0,t.jsx)(s.code,{children:"boolean"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"auto"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/isolatedModules",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"isolatedModules"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"boolean"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"disabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/astTransformers",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"astTransformers"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"object"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"auto"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/diagnostics",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"diagnostics"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"boolean"}),"|",(0,t.jsx)(s.code,{children:"object"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"enabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/babelConfig",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"babelConfig"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"boolean"}),"|",(0,t.jsx)(s.code,{children:"string"}),"|",(0,t.jsx)(s.code,{children:"object"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"disabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"stringifyContentPathRegex"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"string"}),"|",(0,t.jsx)(s.code,{children:"RegExp"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"disabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/useESM",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"useESM"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/useESM",children:"Enable ESM support"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"boolean"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"auto"})})]})]})]})]})}function j(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.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/8e81f9bb.efff498b.js b/assets/js/8e81f9bb.efff498b.js new file mode 100644 index 0000000000..2ed7a92900 --- /dev/null +++ b/assets/js/8e81f9bb.efff498b.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8192],{8849:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>r,default:()=>j,frontMatter:()=>o,metadata:()=>d,toc:()=>l});var t=n(4848),i=n(8453);const o={id:"options",title:"Options"},r=void 0,d={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/options.md",tags:[],version:"28.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,i.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(s.h3,{id:"introduction",children:"Introduction"}),"\n",(0,t.jsxs)(s.p,{children:["All ",(0,t.jsx)(s.code,{children:"ts-jest"})," specific options are located under the ",(0,t.jsx)(s.code,{children:"globals"})," of Jest config object in the ",(0,t.jsx)(s.code,{children:"package.json"})," file of your project,\nor through a ",(0,t.jsx)(s.code,{children:"jest.config.js"}),", or ",(0,t.jsx)(s.code,{children:"jest.config.ts"})," file."]}),"\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 // ts-jest configuration goes here\n }\n }\n }\n}\n'})}),"\n",(0,t.jsx)(s.p,{children:"Or through JavaScript:"}),"\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 // ts-jest configuration goes here\n },\n },\n}\n"})}),"\n",(0,t.jsxs)(s.admonition,{type:"tip",children:[(0,t.jsxs)(s.p,{children:["To utilize IDE suggestions, you can use ",(0,t.jsx)(s.code,{children:"JSDoc"})," comments to provide suggested ",(0,t.jsx)(s.code,{children:"ts-jest"})," configs for your Jest config:"]}),(0,t.jsx)(s.pre,{children:(0,t.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,t.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,t.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.admonition,{type:"important",children:(0,t.jsxs)(s.p,{children:["When using TypeScript Jest config file, Jest will use ",(0,t.jsx)(s.code,{children:"ts-node"})," to compile the config file. ",(0,t.jsx)(s.code,{children:"ts-jest"})," doesn't take part in\nthat process."]})}),"\n",(0,t.jsx)(s.h3,{id:"options",children:"Options"}),"\n",(0,t.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,t.jsxs)(s.table,{children:[(0,t.jsx)(s.thead,{children:(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.th,{children:"Option"}),(0,t.jsx)(s.th,{children:"Description"}),(0,t.jsx)(s.th,{children:"Type"}),(0,t.jsx)(s.th,{children:"Default"})]})}),(0,t.jsxs)(s.tbody,{children:[(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/compiler",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"compiler"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"string"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:'"typescript"'})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/tsconfig",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"tsconfig"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"string"}),"|",(0,t.jsx)(s.code,{children:"object"}),"|",(0,t.jsx)(s.code,{children:"boolean"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"auto"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/isolatedModules",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"isolatedModules"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"boolean"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"disabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/astTransformers",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"astTransformers"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"object"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"auto"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/diagnostics",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"diagnostics"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"boolean"}),"|",(0,t.jsx)(s.code,{children:"object"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"enabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/babelConfig",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"babelConfig"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"boolean"}),"|",(0,t.jsx)(s.code,{children:"string"}),"|",(0,t.jsx)(s.code,{children:"object"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"disabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"stringifyContentPathRegex"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"string"}),"|",(0,t.jsx)(s.code,{children:"RegExp"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"disabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/useESM",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"useESM"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/useESM",children:"Enable ESM support"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"boolean"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"auto"})})]})]})]})]})}function j(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.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.67cda88d.js b/assets/js/902acc05.67cda88d.js new file mode 100644 index 0000000000..444dce744e --- /dev/null +++ b/assets/js/902acc05.67cda88d.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8632],{474:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>l,contentTitle:()=>i,default:()=>u,frontMatter:()=>o,metadata:()=>c,toc:()=>d});var t=n(4848),r=n(8453);const o={id:"esm-support",title:"ESM Support"},i=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/guides/esm-support.md",tags:[],version:"27.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},l={},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}];function a(e){const s={a:"a",code:"code",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",ul:"ul",...(0,r.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(s.p,{children:["To use ",(0,t.jsx)(s.code,{children:"ts-jest"})," with ESM support:"]}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:["Check ",(0,t.jsx)(s.a,{href:"https://jestjs.io/docs/en/ecmascript-modules",children:"ESM Jest documentation"}),"."]}),"\n",(0,t.jsxs)(s.li,{children:["Enable ",(0,t.jsx)(s.a,{href:"../getting-started/options/useESM",children:"useESM"})," ",(0,t.jsx)(s.code,{children:"true"})," for ",(0,t.jsx)(s.code,{children:"ts-jest"})," config."]}),"\n",(0,t.jsxs)(s.li,{children:["Include ",(0,t.jsx)(s.code,{children:".ts"})," in ",(0,t.jsx)(s.a,{href:"https://jestjs.io/docs/en/next/configuration#extensionstotreatasesm-arraystring",children:"extensionsToTreatAsEsm"})," Jest config option."]}),"\n",(0,t.jsxs)(s.li,{children:["Ensure that ",(0,t.jsx)(s.code,{children:"tsconfig"})," has ",(0,t.jsx)(s.code,{children:"module"})," with value for ESM, e.g. ",(0,t.jsx)(s.code,{children:"ES2015"})," or ",(0,t.jsx)(s.code,{children:"ES2020"})," etc..."]}),"\n"]}),"\n",(0,t.jsx)(s.h3,{id:"esm-presets",children:"ESM presets"}),"\n",(0,t.jsxs)(s.p,{children:["There are also ",(0,t.jsx)(s.a,{href:"/ts-jest/docs/27.0/getting-started/presets",children:"3 presets"})," to work with ESM."]}),"\n",(0,t.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,t.jsx)(s.h4,{id:"manual-configuration",children:"Manual configuration"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.h4,{id:"use-esm-presets",children:"Use ESM presets"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.pre,{children:(0,t.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,r.R)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.jsx)(a,{...e})}):a(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/902acc05.fa9371f8.js b/assets/js/902acc05.fa9371f8.js deleted file mode 100644 index 49dad672e1..0000000000 --- a/assets/js/902acc05.fa9371f8.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8632],{474:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>l,contentTitle:()=>i,default:()=>u,frontMatter:()=>o,metadata:()=>c,toc:()=>a});var t=n(4848),r=n(8453);const o={id:"esm-support",title:"ESM Support"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},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,r.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(s.p,{children:["To use ",(0,t.jsx)(s.code,{children:"ts-jest"})," with ESM support:"]}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:["Check ",(0,t.jsx)(s.a,{href:"https://jestjs.io/docs/en/ecmascript-modules",children:"ESM Jest documentation"}),"."]}),"\n",(0,t.jsxs)(s.li,{children:["Enable ",(0,t.jsx)(s.a,{href:"../getting-started/options/useESM",children:"useESM"})," ",(0,t.jsx)(s.code,{children:"true"})," for ",(0,t.jsx)(s.code,{children:"ts-jest"})," config."]}),"\n",(0,t.jsxs)(s.li,{children:["Include ",(0,t.jsx)(s.code,{children:".ts"})," in ",(0,t.jsx)(s.a,{href:"https://jestjs.io/docs/en/next/configuration#extensionstotreatasesm-arraystring",children:"extensionsToTreatAsEsm"})," Jest config option."]}),"\n",(0,t.jsxs)(s.li,{children:["Ensure that ",(0,t.jsx)(s.code,{children:"tsconfig"})," has ",(0,t.jsx)(s.code,{children:"module"})," with value for ESM, e.g. ",(0,t.jsx)(s.code,{children:"ES2015"})," or ",(0,t.jsx)(s.code,{children:"ES2020"})," etc..."]}),"\n"]}),"\n",(0,t.jsx)(s.h3,{id:"esm-presets",children:"ESM presets"}),"\n",(0,t.jsxs)(s.p,{children:["There are also ",(0,t.jsx)(s.a,{href:"/ts-jest/docs/27.0/getting-started/presets",children:"3 presets"})," to work with ESM."]}),"\n",(0,t.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,t.jsx)(s.h4,{id:"manual-configuration",children:"Manual configuration"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.h4,{id:"use-esm-presets",children:"Use ESM presets"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.pre,{children:(0,t.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,r.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:()=>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.16a5a5a0.js b/assets/js/90645308.16a5a5a0.js new file mode 100644 index 0000000000..f628d7c345 --- /dev/null +++ b/assets/js/90645308.16a5a5a0.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1626],{8893:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>m,frontMatter:()=>l,metadata:()=>u,toc:()=>d});var n=s(4848),r=s(8453),a=s(9489),o=s(7227);const l={title:"useESM option"},i=void 0,u={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"useESM option"}},c={},d=[{value:"Examples",id:"examples",level:3}];function p(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["The ",(0,n.jsx)(t.code,{children:"useESM"})," option allows ",(0,n.jsx)(t.code,{children:"ts-jest"})," to transform codes to ESM syntax ",(0,n.jsx)(t.strong,{children:"if possible"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["The default value is ",(0,n.jsx)(t.strong,{children:"false"}),", ",(0,n.jsx)(t.code,{children:"ts-jest"})," will transform codes to ",(0,n.jsx)(t.code,{children:"CommonJS"})," syntax."]}),"\n",(0,n.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsxs)(a.A,{groupId:"code-examples",children:[(0,n.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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/90645308.2106edde.js b/assets/js/90645308.2106edde.js deleted file mode 100644 index 815cf2979f..0000000000 --- a/assets/js/90645308.2106edde.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1626],{8893:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>m,frontMatter:()=>l,metadata:()=>u,toc:()=>d});var n=s(4848),r=s(8453),a=s(9489),o=s(7227);const l={title:"useESM option"},i=void 0,u={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"useESM option"}},c={},d=[{value:"Examples",id:"examples",level:3}];function p(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["The ",(0,n.jsx)(t.code,{children:"useESM"})," option allows ",(0,n.jsx)(t.code,{children:"ts-jest"})," to transform codes to ESM syntax ",(0,n.jsx)(t.strong,{children:"if possible"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["The default value is ",(0,n.jsx)(t.strong,{children:"false"}),", ",(0,n.jsx)(t.code,{children:"ts-jest"})," will transform codes to ",(0,n.jsx)(t.code,{children:"CommonJS"})," syntax."]}),"\n",(0,n.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsxs)(a.A,{groupId:"code-examples",children:[(0,n.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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.06a948a7.js b/assets/js/9226f379.06a948a7.js new file mode 100644 index 0000000000..6a95f0b9c7 --- /dev/null +++ b/assets/js/9226f379.06a948a7.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5567],{2471:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>o,contentTitle:()=>c,default:()=>h,frontMatter:()=>d,metadata:()=>i,toc:()=>l});var n=t(4848),r=t(8453);const d={id:"presets",title:"Presets"},c=void 0,i={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/presets.md",tags:[],version:"28.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,r.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.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.jsx)(s.pre,{children:(0,n.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,n.jsx)(s.pre,{children:(0,n.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,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.jsx)(s.pre,{children:(0,n.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,n.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,n.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,n.jsx)(s.pre,{children:(0,n.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,r.R)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.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/9226f379.3ad6e23a.js b/assets/js/9226f379.3ad6e23a.js deleted file mode 100644 index 159b7d7c11..0000000000 --- a/assets/js/9226f379.3ad6e23a.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5567],{2471:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>o,contentTitle:()=>c,default:()=>h,frontMatter:()=>d,metadata:()=>i,toc:()=>l});var n=t(4848),r=t(8453);const d={id:"presets",title:"Presets"},c=void 0,i={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:!1,unlisted:!1,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:1726058855e3,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"}},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,r.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.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.jsx)(s.pre,{children:(0,n.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,n.jsx)(s.pre,{children:(0,n.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,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.jsx)(s.pre,{children:(0,n.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,n.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,n.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,n.jsx)(s.pre,{children:(0,n.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,r.R)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.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.10e68c2a.js b/assets/js/96f7df01.10e68c2a.js deleted file mode 100644 index 72a5414c03..0000000000 --- a/assets/js/96f7df01.10e68c2a.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4316],{2664:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>p,frontMatter:()=>o,metadata:()=>c,toc:()=>l});var s=n(4848),i=n(8453);const o={id:"babel7-or-ts",title:"Babel7 or TypeScript"},r=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},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,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,s.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,s.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,s.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,s.jsxs)(t.p,{children:["While ",(0,s.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,s.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,s.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,s.jsxs)(t.p,{children:["This is the big ",(0,s.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,s.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,s.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,s.jsx)(t.code,{children:"namespace"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,s.jsx)(t.code,{children:"const enum"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,s.jsx)(t.code,{children:"enum"}),", ",(0,s.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,s.jsxs)(t.p,{children:["You won't be able to do ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,s.jsx)(t.code,{children:"import"}),"/",(0,s.jsx)(t.code,{children:"export"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(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,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/96f7df01.9dd4e63c.js b/assets/js/96f7df01.9dd4e63c.js new file mode 100644 index 0000000000..8efc28e207 --- /dev/null +++ b/assets/js/96f7df01.9dd4e63c.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4316],{2664:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>p,frontMatter:()=>o,metadata:()=>c,toc:()=>l});var s=n(4848),i=n(8453);const o={id:"babel7-or-ts",title:"Babel7 or TypeScript"},r=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/babel7-or-ts.md",tags:[],version:"27.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,s.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,s.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,s.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,s.jsxs)(t.p,{children:["While ",(0,s.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,s.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,s.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,s.jsxs)(t.p,{children:["This is the big ",(0,s.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,s.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,s.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,s.jsx)(t.code,{children:"namespace"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,s.jsx)(t.code,{children:"const enum"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,s.jsx)(t.code,{children:"enum"}),", ",(0,s.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,s.jsxs)(t.p,{children:["You won't be able to do ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,s.jsx)(t.code,{children:"import"}),"/",(0,s.jsx)(t.code,{children:"export"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(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,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.836f6674.js b/assets/js/9762b2e9.836f6674.js new file mode 100644 index 0000000000..573bd19af1 --- /dev/null +++ b/assets/js/9762b2e9.836f6674.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6553],{2054:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>d,frontMatter:()=>i,metadata:()=>p,toc:()=>c});var s=n(4848),o=n(8453);const i={id:"paths-mapping",title:"Paths mapping"},r=void 0,p={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["If you use ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,s.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,s.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,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,s.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,s.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,s.jsxs)(t.p,{children:["With the below config in your ",(0,s.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/9762b2e9.b2879b6e.js b/assets/js/9762b2e9.b2879b6e.js deleted file mode 100644 index 0b9e29e237..0000000000 --- a/assets/js/9762b2e9.b2879b6e.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6553],{2054:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>d,frontMatter:()=>i,metadata:()=>p,toc:()=>c});var s=n(4848),o=n(8453);const i={id:"paths-mapping",title:"Paths mapping"},r=void 0,p={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:!1,unlisted:!1,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:1726058855e3,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"}},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,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["If you use ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,s.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,s.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,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,s.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,s.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,s.jsxs)(t.p,{children:["With the below config in your ",(0,s.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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.243a4200.js b/assets/js/981dc414.243a4200.js new file mode 100644 index 0000000000..9b89d996e4 --- /dev/null +++ b/assets/js/981dc414.243a4200.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2777],{8555:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>m,frontMatter:()=>l,metadata:()=>u,toc:()=>d});var n=s(4848),r=s(8453),a=s(9489),o=s(7227);const l={title:"useESM option"},i=void 0,u={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"useESM option"}},c={},d=[{value:"Examples",id:"examples",level:3}];function p(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["The ",(0,n.jsx)(t.code,{children:"useESM"})," option allows ",(0,n.jsx)(t.code,{children:"ts-jest"})," to transform codes to ESM syntax ",(0,n.jsx)(t.strong,{children:"if possible"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["The default value is ",(0,n.jsx)(t.strong,{children:"false"}),", ",(0,n.jsx)(t.code,{children:"ts-jest"})," will transform codes to ",(0,n.jsx)(t.code,{children:"CommonJS"})," syntax."]}),"\n",(0,n.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsxs)(a.A,{groupId:"code-examples",children:[(0,n.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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/981dc414.54652636.js b/assets/js/981dc414.54652636.js deleted file mode 100644 index 81aeac9b60..0000000000 --- a/assets/js/981dc414.54652636.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2777],{8555:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>m,frontMatter:()=>l,metadata:()=>u,toc:()=>d});var n=s(4848),r=s(8453),a=s(9489),o=s(7227);const l={title:"useESM option"},i=void 0,u={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"useESM option"}},c={},d=[{value:"Examples",id:"examples",level:3}];function p(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["The ",(0,n.jsx)(t.code,{children:"useESM"})," option allows ",(0,n.jsx)(t.code,{children:"ts-jest"})," to transform codes to ESM syntax ",(0,n.jsx)(t.strong,{children:"if possible"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["The default value is ",(0,n.jsx)(t.strong,{children:"false"}),", ",(0,n.jsx)(t.code,{children:"ts-jest"})," will transform codes to ",(0,n.jsx)(t.code,{children:"CommonJS"})," syntax."]}),"\n",(0,n.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsxs)(a.A,{groupId:"code-examples",children:[(0,n.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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.d262d361.js b/assets/js/9920b385.d262d361.js new file mode 100644 index 0000000000..d02160717b --- /dev/null +++ b/assets/js/9920b385.d262d361.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4571],{360:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>p,frontMatter:()=>l,metadata:()=>c,toc:()=>j});var n=s(4848),r=s(8453),o=s(9489),a=s(7227);const l={title:"Babel Config option"},i=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/babelConfig.md",tags:[],version:"current",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Babel Config option"}},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,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:[(0,n.jsx)(t.code,{children:"ts-jest"})," by default does ",(0,n.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,n.jsx)(t.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,n.jsxs)(t.p,{children:["The option is ",(0,n.jsx)(t.code,{children:"babelConfig"})," and it works pretty much as the ",(0,n.jsx)(t.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"true"}),": enables Babel processing. ",(0,n.jsx)(t.code,{children:"ts-jest"})," will try to find a ",(0,n.jsx)(t.code,{children:".babelrc"}),", ",(0,n.jsx)(t.code,{children:".babelrc.js"}),", ",(0,n.jsx)(t.code,{children:"babel.config.js"})," file or a ",(0,n.jsx)(t.code,{children:"babel"})," section in the ",(0,n.jsx)(t.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,n.jsx)(t.code,{children:"babel-jest"})," processor."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"{ ... }"}),": inline ",(0,n.jsx)(t.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,n.jsx)(t.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,n.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsxs)(t.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,n.jsx)(t.code,{children:"babelrc"})," file"]}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsxs)(t.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,n.jsx)(t.code,{children:"babelrc"})," file"]}),"\n",(0,n.jsxs)(t.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,n.jsx)(t.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.p,{children:"or importing directly the config file:"}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,n.jsxs)(t.p,{children:["Refer to the ",(0,n.jsx)(t.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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}),b=(()=>{const e=c??x;return p({value:e,tabValues:o})?e:null})();(0,l.A)((()=>{b&&i(b)}),[b]);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 b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var f=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,f.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,f.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",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,f.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,f.jsxs)("div",{className:(0,r.A)("tabs-container",b.tabList),children:[(0,f.jsx)(g,{...t,...e}),(0,f.jsx)(v,{...t,...e})]})}function w(e){const t=(0,m.A)();return(0,f.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/9920b385.d3c5cc85.js b/assets/js/9920b385.d3c5cc85.js deleted file mode 100644 index 761b6abe1b..0000000000 --- a/assets/js/9920b385.d3c5cc85.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4571],{360:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>p,frontMatter:()=>l,metadata:()=>c,toc:()=>j});var n=s(4848),r=s(8453),o=s(9489),a=s(7227);const l={title:"Babel Config option"},i=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/babelConfig.md",tags:[],version:"current",lastUpdatedBy:"renovate[bot]",lastUpdatedAt:1726058855e3,frontMatter:{title:"Babel Config option"}},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,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:[(0,n.jsx)(t.code,{children:"ts-jest"})," by default does ",(0,n.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,n.jsx)(t.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,n.jsxs)(t.p,{children:["The option is ",(0,n.jsx)(t.code,{children:"babelConfig"})," and it works pretty much as the ",(0,n.jsx)(t.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"true"}),": enables Babel processing. ",(0,n.jsx)(t.code,{children:"ts-jest"})," will try to find a ",(0,n.jsx)(t.code,{children:".babelrc"}),", ",(0,n.jsx)(t.code,{children:".babelrc.js"}),", ",(0,n.jsx)(t.code,{children:"babel.config.js"})," file or a ",(0,n.jsx)(t.code,{children:"babel"})," section in the ",(0,n.jsx)(t.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,n.jsx)(t.code,{children:"babel-jest"})," processor."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"{ ... }"}),": inline ",(0,n.jsx)(t.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,n.jsx)(t.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,n.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsxs)(t.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,n.jsx)(t.code,{children:"babelrc"})," file"]}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsxs)(t.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,n.jsx)(t.code,{children:"babelrc"})," file"]}),"\n",(0,n.jsxs)(t.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,n.jsx)(t.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.p,{children:"or importing directly the config file:"}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,n.jsxs)(t.p,{children:["Refer to the ",(0,n.jsx)(t.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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.7b4d9f23.js b/assets/js/9d036230.7b4d9f23.js deleted file mode 100644 index dc8bd75488..0000000000 --- a/assets/js/9d036230.7b4d9f23.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8810],{5923:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>h,contentTitle:()=>r,default:()=>l,frontMatter:()=>o,metadata:()=>c,toc:()=>a});var n=s(4848),i=s(8453);const o={id:"contributing",title:"Contributing"},r=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},h={},a=[{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 d(e){const t={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,n.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,n.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,n.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,n.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,n.jsxs)(t.ol,{children:["\n",(0,n.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,n.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,n.jsxs)(t.li,{children:["Update the ",(0,n.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,n.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,n.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,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,n.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,n.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,n.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,n.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,n.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,n.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,n.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,n.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 l(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(d,{...e})}):d(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/9d036230.b6c576d0.js b/assets/js/9d036230.b6c576d0.js new file mode 100644 index 0000000000..2c0ceadf5b --- /dev/null +++ b/assets/js/9d036230.b6c576d0.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8810],{5923:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>h,contentTitle:()=>r,default:()=>l,frontMatter:()=>o,metadata:()=>c,toc:()=>a});var n=s(4848),i=s(8453);const o={id:"contributing",title:"Contributing"},r=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/contributing.md",tags:[],version:"29.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},h={},a=[{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 d(e){const t={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,n.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,n.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,n.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,n.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,n.jsxs)(t.ol,{children:["\n",(0,n.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,n.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,n.jsxs)(t.li,{children:["Update the ",(0,n.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,n.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,n.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,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,n.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,n.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,n.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,n.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,n.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,n.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,n.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,n.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 l(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(d,{...e})}):d(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.0f1da44a.js b/assets/js/9ed06f50.0f1da44a.js new file mode 100644 index 0000000000..34c84fa546 --- /dev/null +++ b/assets/js/9ed06f50.0f1da44a.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5174],{7664:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>a,contentTitle:()=>r,default:()=>g,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var s=t(4848),o=t(8453);const i={id:"migration",title:"Migration from <=23.10"},r=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/migration.md",tags:[],version:"28.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(n.p,{children:["You can use the ",(0,s.jsx)(n.code,{children:"config:migrate"})," tool of ",(0,s.jsx)(n.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsxs)(n.em,{children:["If you're using ",(0,s.jsx)(n.code,{children:"jest.config.js"}),":"]})}),"\n",(0,s.jsx)(n.h3,{id:"npm",children:"NPM"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate jest.config.js\n"})}),"\n",(0,s.jsx)(n.h3,{id:"yarn",children:"Yarn"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate jest.config.js\n"})}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsxs)(n.em,{children:["If you're using ",(0,s.jsx)(n.code,{children:"jest"})," config property of ",(0,s.jsx)(n.code,{children:"package.json"}),":"]})}),"\n",(0,s.jsx)(n.h3,{id:"npm-1",children:"NPM"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate package.json\n"})}),"\n",(0,s.jsx)(n.h3,{id:"yarn-1",children:"Yarn"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate package.json\n"})})]})}function g(e={}){const{wrapper:n}={...(0,o.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.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/9ed06f50.f0f8dd1e.js b/assets/js/9ed06f50.f0f8dd1e.js deleted file mode 100644 index 0a8bd223bb..0000000000 --- a/assets/js/9ed06f50.f0f8dd1e.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5174],{7664:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>a,contentTitle:()=>r,default:()=>g,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var s=t(4848),o=t(8453);const i={id:"migration",title:"Migration from <=23.10"},r=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},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,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(n.p,{children:["You can use the ",(0,s.jsx)(n.code,{children:"config:migrate"})," tool of ",(0,s.jsx)(n.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsxs)(n.em,{children:["If you're using ",(0,s.jsx)(n.code,{children:"jest.config.js"}),":"]})}),"\n",(0,s.jsx)(n.h3,{id:"npm",children:"NPM"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate jest.config.js\n"})}),"\n",(0,s.jsx)(n.h3,{id:"yarn",children:"Yarn"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate jest.config.js\n"})}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsxs)(n.em,{children:["If you're using ",(0,s.jsx)(n.code,{children:"jest"})," config property of ",(0,s.jsx)(n.code,{children:"package.json"}),":"]})}),"\n",(0,s.jsx)(n.h3,{id:"npm-1",children:"NPM"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:migrate package.json\n"})}),"\n",(0,s.jsx)(n.h3,{id:"yarn-1",children:"Yarn"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:migrate package.json\n"})})]})}function g(e={}){const{wrapper:n}={...(0,o.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.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.079a363d.js b/assets/js/a09c2993.079a363d.js new file mode 100644 index 0000000000..61838dd86b --- /dev/null +++ b/assets/js/a09c2993.079a363d.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5899],{2738:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var n=s(4848),o=s(8453);const r={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},i=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/introduction.md",tags:[],version:"current",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,o.R)(),...t.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,n.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,n.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,n.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,n.jsx)(e.code,{children:"preset-typescript"})," ",(0,n.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,n.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,n.jsx)(e.admonition,{type:"important",children:(0,n.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,n.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,n.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,o.R)(),...t.components};return e?(0,n.jsx)(e,{...t,children:(0,n.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/a09c2993.a000208a.js b/assets/js/a09c2993.a000208a.js deleted file mode 100644 index b201692022..0000000000 --- a/assets/js/a09c2993.a000208a.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5899],{2738:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var n=s(4848),o=s(8453);const r={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},i=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/introduction.md",tags:[],version:"current",lastUpdatedBy:"renovate[bot]",lastUpdatedAt:1726058855e3,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"}},d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,o.R)(),...t.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,n.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,n.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,n.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,n.jsx)(e.code,{children:"preset-typescript"})," ",(0,n.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,n.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,n.jsx)(e.admonition,{type:"important",children:(0,n.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,n.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,n.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,o.R)(),...t.components};return e?(0,n.jsx)(e,{...t,children:(0,n.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.6fb3cc44.js b/assets/js/a132b5de.6fb3cc44.js deleted file mode 100644 index 92bded51f9..0000000000 --- a/assets/js/a132b5de.6fb3cc44.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7132],{4779:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>c,contentTitle:()=>l,default:()=>h,frontMatter:()=>t,metadata:()=>r,toc:()=>d});var i=s(4848),o=s(8453);const t={title:"Diagnostics option"},l=void 0,r={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Diagnostics option"}},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,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(n.p,{children:["The ",(0,i.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,i.jsxs)(n.p,{children:["If a diagnostic is not filtered out, ",(0,i.jsx)(n.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,i.jsx)(n.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,i.jsxs)(n.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,i.jsx)(n.code,{children:"diagnostics"})," option to ",(0,i.jsx)(n.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,i.jsx)(n.code,{children:"diagnostics"})," to ",(0,i.jsx)(n.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,i.jsx)(n.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"warnOnly"})}),": If specified and ",(0,i.jsx)(n.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,i.jsx)(n.em,{children:"disabled"}),")."]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,i.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,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"6059"}),": ",(0,i.jsx)(n.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"18002"}),": ",(0,i.jsx)(n.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"18003"}),": ",(0,i.jsx)(n.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,i.jsx)(n.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,i.jsx)(n.code,{children:"tsconfig"})," option ",(0,i.jsx)(n.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,i.jsx)(n.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,i.jsx)(n.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,i.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,i.jsx)(n.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,i.jsx)(n.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,i.jsxs)(n.p,{children:["Assuming all your test files ends with ",(0,i.jsx)(n.code,{children:".spec.ts"})," or ",(0,i.jsx)(n.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,i.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,i.jsx)(n.code,{children:"warnOnly"})," to ",(0,i.jsx)(n.code,{children:"true"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,i.jsxs)(n.p,{children:["All TypeScript error codes can be found ",(0,i.jsx)(n.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,i.jsx)(n.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,i.jsxs)(n.ol,{children:["\n",(0,i.jsxs)(n.li,{children:["A single ",(0,i.jsx)(n.code,{children:"number"})," (example: ",(0,i.jsx)(n.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,i.jsxs)(n.li,{children:["A ",(0,i.jsx)(n.code,{children:"string"})," with a code (example ",(0,i.jsx)(n.code,{children:'"1009"'}),", ",(0,i.jsx)(n.code,{children:'"TS1009"'})," or ",(0,i.jsx)(n.code,{children:'"TS1009"'}),")"]}),"\n",(0,i.jsxs)(n.li,{children:["A ",(0,i.jsx)(n.code,{children:"string"})," with a list of the above (example: ",(0,i.jsx)(n.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,i.jsxs)(n.li,{children:["An ",(0,i.jsx)(n.code,{children:"array"})," of one or more from ",(0,i.jsx)(n.code,{children:"1"})," or ",(0,i.jsx)(n.code,{children:"3"})," (example: ",(0,i.jsx)(n.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,o.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.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/a132b5de.f61bed0a.js b/assets/js/a132b5de.f61bed0a.js new file mode 100644 index 0000000000..9c0328baaa --- /dev/null +++ b/assets/js/a132b5de.f61bed0a.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7132],{4779:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>c,contentTitle:()=>l,default:()=>h,frontMatter:()=>t,metadata:()=>r,toc:()=>d});var i=s(4848),o=s(8453);const t={title:"Diagnostics option"},l=void 0,r={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Diagnostics option"}},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,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(n.p,{children:["The ",(0,i.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,i.jsxs)(n.p,{children:["If a diagnostic is not filtered out, ",(0,i.jsx)(n.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,i.jsx)(n.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,i.jsxs)(n.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,i.jsx)(n.code,{children:"diagnostics"})," option to ",(0,i.jsx)(n.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,i.jsx)(n.code,{children:"diagnostics"})," to ",(0,i.jsx)(n.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,i.jsx)(n.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"warnOnly"})}),": If specified and ",(0,i.jsx)(n.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,i.jsx)(n.em,{children:"disabled"}),")."]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,i.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,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"6059"}),": ",(0,i.jsx)(n.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"18002"}),": ",(0,i.jsx)(n.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"18003"}),": ",(0,i.jsx)(n.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,i.jsx)(n.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,i.jsx)(n.code,{children:"tsconfig"})," option ",(0,i.jsx)(n.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,i.jsx)(n.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,i.jsx)(n.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,i.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,i.jsx)(n.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,i.jsx)(n.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,i.jsxs)(n.p,{children:["Assuming all your test files ends with ",(0,i.jsx)(n.code,{children:".spec.ts"})," or ",(0,i.jsx)(n.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,i.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,i.jsx)(n.code,{children:"warnOnly"})," to ",(0,i.jsx)(n.code,{children:"true"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,i.jsxs)(n.p,{children:["All TypeScript error codes can be found ",(0,i.jsx)(n.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,i.jsx)(n.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,i.jsxs)(n.ol,{children:["\n",(0,i.jsxs)(n.li,{children:["A single ",(0,i.jsx)(n.code,{children:"number"})," (example: ",(0,i.jsx)(n.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,i.jsxs)(n.li,{children:["A ",(0,i.jsx)(n.code,{children:"string"})," with a code (example ",(0,i.jsx)(n.code,{children:'"1009"'}),", ",(0,i.jsx)(n.code,{children:'"TS1009"'})," or ",(0,i.jsx)(n.code,{children:'"TS1009"'}),")"]}),"\n",(0,i.jsxs)(n.li,{children:["A ",(0,i.jsx)(n.code,{children:"string"})," with a list of the above (example: ",(0,i.jsx)(n.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,i.jsxs)(n.li,{children:["An ",(0,i.jsx)(n.code,{children:"array"})," of one or more from ",(0,i.jsx)(n.code,{children:"1"})," or ",(0,i.jsx)(n.code,{children:"3"})," (example: ",(0,i.jsx)(n.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,o.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.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.e7a7f6ab.js b/assets/js/a21658d9.e7a7f6ab.js new file mode 100644 index 0000000000..2bfa76ca2e --- /dev/null +++ b/assets/js/a21658d9.e7a7f6ab.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1173],{5547:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>r,toc:()=>l});var n=s(4848),o=s(8453);const i={id:"react-native",title:"Using with React Native"},c=void 0,r={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/guides/react-native.md",tags:[],version:"28.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["To use ",(0,n.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,n.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,n.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,n.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,n.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,n.jsx)(t.code,{children:".babelrc"})," to ",(0,n.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-js",children:"// babel.config.js\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n"})}),"\n",(0,n.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,n.jsxs)(t.p,{children:["Create a new ",(0,n.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,n.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,n.jsx)(t.code,{children:"jest"})," key of ",(0,n.jsx)(t.code,{children:"package.json"})," to ",(0,n.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,n.jsx)(t.pre,{children:(0,n.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,o.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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/a21658d9.eedc0eb7.js b/assets/js/a21658d9.eedc0eb7.js deleted file mode 100644 index e06de1d6df..0000000000 --- a/assets/js/a21658d9.eedc0eb7.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1173],{5547:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>u,frontMatter:()=>i,metadata:()=>r,toc:()=>l});var n=s(4848),o=s(8453);const i={id:"react-native",title:"Using with React Native"},c=void 0,r={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:!1,unlisted:!1,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:1726058855e3,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"}},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,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["To use ",(0,n.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,n.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,n.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,n.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,n.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,n.jsx)(t.code,{children:".babelrc"})," to ",(0,n.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-js",children:"// babel.config.js\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n"})}),"\n",(0,n.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,n.jsxs)(t.p,{children:["Create a new ",(0,n.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,n.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,n.jsx)(t.code,{children:"jest"})," key of ",(0,n.jsx)(t.code,{children:"package.json"})," to ",(0,n.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,n.jsx)(t.pre,{children:(0,n.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,o.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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.a5fcf1cb.js b/assets/js/a5ea8355.a5fcf1cb.js deleted file mode 100644 index a8c9d15c1a..0000000000 --- a/assets/js/a5ea8355.a5fcf1cb.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3762],{1412:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>l,default:()=>h,frontMatter:()=>i,metadata:()=>a,toc:()=>c});var s=n(4848),o=n(8453);const i={title:"Isolated Modules option"},l=void 0,a={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Isolated Modules option"}},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,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default ",(0,s.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,s.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,s.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,s.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,s.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,s.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\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 isolatedModules: true,\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 "isolatedModules": true\n }\n }\n }\n}\n'})}),"\n",(0,s.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,s.jsxs)(t.p,{children:["Using ",(0,s.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,s.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,s.jsx)(t.code,{children:"include"})," in ",(0,s.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,s.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,s.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,s.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,s.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,s.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,s.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,s.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,s.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,s.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,s.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function h(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(r,{...e})}):r(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>l,x:()=>a});var s=n(6540);const o={},i=s.createContext(o);function l(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:l(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/a5ea8355.c3a193b8.js b/assets/js/a5ea8355.c3a193b8.js new file mode 100644 index 0000000000..b271ace30b --- /dev/null +++ b/assets/js/a5ea8355.c3a193b8.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3762],{1412:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>l,default:()=>h,frontMatter:()=>i,metadata:()=>d,toc:()=>c});var s=n(4848),o=n(8453);const i={title:"Isolated Modules option"},l=void 0,d={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Isolated Modules option"}},a={},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,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default ",(0,s.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,s.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,s.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,s.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,s.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,s.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\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 isolatedModules: true,\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 "isolatedModules": true\n }\n }\n }\n}\n'})}),"\n",(0,s.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,s.jsxs)(t.p,{children:["Using ",(0,s.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,s.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,s.jsx)(t.code,{children:"include"})," in ",(0,s.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,s.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,s.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,s.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,s.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,s.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,s.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,s.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,s.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,s.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,s.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function h(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(r,{...e})}):r(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>l,x:()=>d});var s=n(6540);const o={},i=s.createContext(o);function l(e){const t=s.useContext(i);return s.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(o):e.components||o:l(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/a6267c3c.1c2c040e.js b/assets/js/a6267c3c.1c2c040e.js new file mode 100644 index 0000000000..114521abe9 --- /dev/null +++ b/assets/js/a6267c3c.1c2c040e.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6586],{766:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var n=s(4848),o=s(8453);const r={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},i=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/introduction.md",tags:[],version:"28.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,o.R)(),...t.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,n.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,n.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,n.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,n.jsx)(e.code,{children:"preset-typescript"})," ",(0,n.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,n.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,n.jsx)(e.admonition,{type:"important",children:(0,n.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,n.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,n.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,o.R)(),...t.components};return e?(0,n.jsx)(e,{...t,children:(0,n.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/a6267c3c.1ca51ad2.js b/assets/js/a6267c3c.1ca51ad2.js deleted file mode 100644 index 39b65f5d49..0000000000 --- a/assets/js/a6267c3c.1ca51ad2.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6586],{766:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var n=s(4848),o=s(8453);const r={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,o.R)(),...t.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,n.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,n.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,n.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,n.jsx)(e.code,{children:"preset-typescript"})," ",(0,n.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,n.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,n.jsx)(e.admonition,{type:"important",children:(0,n.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,n.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,n.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,o.R)(),...t.components};return e?(0,n.jsx)(e,{...t,children:(0,n.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.51118034.js b/assets/js/a7423e3b.51118034.js deleted file mode 100644 index 590668e7ad..0000000000 --- a/assets/js/a7423e3b.51118034.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3322],{5844:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>o,default:()=>p,frontMatter:()=>l,metadata:()=>c,toc:()=>d});var s=n(4848),r=n(8453),a=n(9489),i=n(7227);const l={id:"installation",title:"Installation"},o=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},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,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,s.jsxs)(t.p,{children:["You can install ",(0,s.jsx)(t.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,s.jsxs)(a.A,{groupId:"npm2yarn",children:[(0,s.jsx)(i.A,{value:"npm",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})})}),(0,s.jsx)(i.A,{value:"yarn",label:"Yarn",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})})}),(0,s.jsx)(i.A,{value:"pnpm",label:"pnpm",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"pnpm add --save-dev jest typescript ts-jest @types/jest\n"})})})]}),"\n",(0,s.jsx)(t.admonition,{type:"tip",children:(0,s.jsxs)(t.p,{children:["Tip: If you get an error with the following ",(0,s.jsx)(t.code,{children:"npm"})," commands such as ",(0,s.jsx)(t.code,{children:"npx: command not found"}),", you can replace ",(0,s.jsx)(t.code,{children:"npx XXX"})," with ",(0,s.jsx)(t.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,s.jsx)(t.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,s.jsx)(t.h4,{id:"creating",children:"Creating"}),"\n",(0,s.jsxs)(t.p,{children:["By default, Jest can run without any config files, but it will not compile ",(0,s.jsx)(t.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,s.jsx)(t.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,s.jsx)(t.code,{children:"ts-jest"})," preset."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,s.jsxs)(a.A,{groupId:"code-examples",children:[(0,s.jsx)(i.A,{value:"npm",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-npm",metastring:"tab",children:"npx ts-jest config:init\n"})})}),(0,s.jsx)(i.A,{value:"Yarn",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-Yarn",metastring:"tab",children:"yarn ts-jest config:init\n"})})})]}),"\n",(0,s.jsxs)(t.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,s.jsx)(t.code,{children:".ts"})," files correctly."]}),"\n",(0,s.jsxs)(t.p,{children:["You can also use the ",(0,s.jsx)(t.code,{children:"jest --init"})," command (prefixed with either ",(0,s.jsx)(t.code,{children:"npx"})," or ",(0,s.jsx)(t.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,s.jsx)(t.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,s.jsx)(t.code,{children:'preset: "ts-jest"'})," to the ",(0,s.jsx)(t.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,s.jsx)(t.h4,{id:"customizing",children:"Customizing"}),"\n",(0,s.jsxs)(t.p,{children:["For customizing jest, please follow their ",(0,s.jsx)(t.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," specific options can be found ",(0,s.jsx)(t.a,{href:"options",children:"here"}),"."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/a7423e3b.c7adf1c8.js b/assets/js/a7423e3b.c7adf1c8.js new file mode 100644 index 0000000000..cab3f32e48 --- /dev/null +++ b/assets/js/a7423e3b.c7adf1c8.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3322],{5844:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>o,default:()=>p,frontMatter:()=>l,metadata:()=>c,toc:()=>d});var s=n(4848),r=n(8453),a=n(9489),i=n(7227);const l={id:"installation",title:"Installation"},o=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/installation.md",tags:[],version:"29.2",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,s.jsxs)(t.p,{children:["You can install ",(0,s.jsx)(t.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,s.jsxs)(a.A,{groupId:"npm2yarn",children:[(0,s.jsx)(i.A,{value:"npm",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})})}),(0,s.jsx)(i.A,{value:"yarn",label:"Yarn",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})})}),(0,s.jsx)(i.A,{value:"pnpm",label:"pnpm",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"pnpm add --save-dev jest typescript ts-jest @types/jest\n"})})})]}),"\n",(0,s.jsx)(t.admonition,{type:"tip",children:(0,s.jsxs)(t.p,{children:["Tip: If you get an error with the following ",(0,s.jsx)(t.code,{children:"npm"})," commands such as ",(0,s.jsx)(t.code,{children:"npx: command not found"}),", you can replace ",(0,s.jsx)(t.code,{children:"npx XXX"})," with ",(0,s.jsx)(t.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,s.jsx)(t.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,s.jsx)(t.h4,{id:"creating",children:"Creating"}),"\n",(0,s.jsxs)(t.p,{children:["By default, Jest can run without any config files, but it will not compile ",(0,s.jsx)(t.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,s.jsx)(t.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,s.jsx)(t.code,{children:"ts-jest"})," preset."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,s.jsxs)(a.A,{groupId:"code-examples",children:[(0,s.jsx)(i.A,{value:"npm",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-npm",metastring:"tab",children:"npx ts-jest config:init\n"})})}),(0,s.jsx)(i.A,{value:"Yarn",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-Yarn",metastring:"tab",children:"yarn ts-jest config:init\n"})})})]}),"\n",(0,s.jsxs)(t.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,s.jsx)(t.code,{children:".ts"})," files correctly."]}),"\n",(0,s.jsxs)(t.p,{children:["You can also use the ",(0,s.jsx)(t.code,{children:"jest --init"})," command (prefixed with either ",(0,s.jsx)(t.code,{children:"npx"})," or ",(0,s.jsx)(t.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,s.jsx)(t.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,s.jsx)(t.code,{children:'preset: "ts-jest"'})," to the ",(0,s.jsx)(t.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,s.jsx)(t.h4,{id:"customizing",children:"Customizing"}),"\n",(0,s.jsxs)(t.p,{children:["For customizing jest, please follow their ",(0,s.jsx)(t.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," specific options can be found ",(0,s.jsx)(t.a,{href:"options",children:"here"}),"."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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.09ac96b4.js b/assets/js/a7bc29db.09ac96b4.js deleted file mode 100644 index 4f17652c0e..0000000000 --- a/assets/js/a7bc29db.09ac96b4.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9123],{8474:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>a,contentTitle:()=>d,default:()=>x,frontMatter:()=>i,metadata:()=>o,toc:()=>j});var r=t(4848),n=t(8453),c=t(9489),l=t(7227);const i={id:"presets",title:"Presets"},d=void 0,o={id:"getting-started/presets",title:"Presets",description:"The presets",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:!1,unlisted:!1,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:1726058855e3,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"}},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={a:"a",admonition:"admonition",code:"code",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,n.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.jsx)(s.admonition,{type:"caution",children:(0,r.jsxs)(s.p,{children:["The list of ",(0,r.jsx)(s.code,{children:"preset"})," below is now deprecated in favor of util functions. If one is using ",(0,r.jsx)(s.code,{children:"preset"})," in Jest config, please run ",(0,r.jsx)(s.code,{children:"npx ts-jest config:migrate"})," or look into ",(0,r.jsx)(s.a,{href:"#advanced",children:"Advanced"})," section below for alternative solutions."]})}),"\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.jsxs)(c.A,{groupId:"code-examples",children:[(0,r.jsx)(l.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\nconst { createDefaultPreset } = require('ts-jest')\n\nconst defaultPreset = createDefaultPreset()\n\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 ...defaultPreset,\n}\n"})})}),(0,r.jsx)(l.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, createDefaultPreset } from 'ts-jest'\n\nconst defaultPreset = createDefaultPreset()\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n // Replace `ts-jest` with the preset you want to use\n // from the above list\n ...defaultPreset,\n}\n\nexport default jestConfig\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.jsx)(s.p,{children:"There are several util functions to create and extend the existing presets:"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createDefaultPreset"}),": for default preset"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createDefaultLegacyPreset"}),": for default preset in legacy mode"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createDefaultEsmPreset"}),": for default ESM preset"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createDefaultEsmLegacyPreset"}),": for default ESM preset in legacy mode"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithTsPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-ts"})," preset"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithTsLegacyPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-ts"})," preset in legacy mode"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithTsEsmPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-ts"})," ESM preset"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithTsEsmLegacyPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-ts"})," ESM preset in legacy mode"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithBabelPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-babel"})," preset"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithBabelLegacyPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-babel"})," preset in legacy mode"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithBabelEsmPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-babel"})," ESM preset"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithBabelEsmLegacyPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-babel"})," ESM preset in legacy mode"]}),"\n"]}),"\n",(0,r.jsx)(s.p,{children:"Example:"}),"\n",(0,r.jsxs)(c.A,{groupId:"code-examples",children:[(0,r.jsx)(l.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\nconst { createDefaultPreset } = require('ts-jest')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n ...createDefaultPreset().transform,\n // [...]\n },\n}\n"})})}),(0,r.jsx)(l.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 { createDefaultPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n ...createDefaultPreset().transform,\n // [...]\n },\n}\n\nexport default jestConfig\n"})})})]})]})}function x(e={}){const{wrapper:s}={...(0,n.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},7227:(e,s,t)=>{t.d(s,{A:()=>l});t(6540);var r=t(4164);const n={tabItem:"tabItem_Ymn6"};var c=t(4848);function l(e){let{children:s,hidden:t,className:l}=e;return(0,c.jsx)("div",{role:"tabpanel",className:(0,r.A)(n.tabItem,l),hidden:t,children:s})}},9489:(e,s,t)=>{t.d(s,{A:()=>w});var r=t(6540),n=t(4164),c=t(4245),l=t(6347),i=t(6494),d=t(2814),o=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,o.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 x(e){let{value:s,tabValues:t}=e;return t.some((e=>e.value===s))}function u(e){let{queryString:s=!1,groupId:t}=e;const n=(0,l.W6)(),c=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,d.aZ)(c),(0,r.useCallback)((e=>{if(!c)return;const s=new URLSearchParams(n.location.search);s.set(c,e),n.replace({...n.location,search:s.toString()})}),[c,n])]}function p(e){const{defaultValue:s,queryString:t=!1,groupId:n}=e,c=h(e),[l,d]=(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(!x({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:c}))),[o,j]=u({queryString:t,groupId:n}),[p,f]=function(e){let{groupId:s}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(s),[n,c]=(0,a.Dv)(t);return[n,(0,r.useCallback)((e=>{t&&c.set(e)}),[t,c])]}({groupId:n}),b=(()=>{const e=o??p;return x({value:e,tabValues:c})?e:null})();(0,i.A)((()=>{b&&d(b)}),[b]);return{selectedValue:l,selectValue:(0,r.useCallback)((e=>{if(!x({value:e,tabValues:c}))throw new Error(`Can't select invalid tab value=${e}`);d(e),j(e),f(e)}),[j,f,c]),tabValues:c}}var f=t(1062);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var m=t(4848);function g(e){let{className:s,block:t,selectedValue:r,selectValue:l,tabValues:i}=e;const d=[],{blockElementScrollPositionUntilNextRender:o}=(0,c.a_)(),a=e=>{const s=e.currentTarget,t=d.indexOf(s),n=i[t].value;n!==r&&(o(s),l(n))},j=e=>{let s=null;switch(e.key){case"Enter":a(e);break;case"ArrowRight":{const t=d.indexOf(e.currentTarget)+1;s=d[t]??d[0];break}case"ArrowLeft":{const t=d.indexOf(e.currentTarget)-1;s=d[t]??d[d.length-1];break}}s?.focus()};return(0,m.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,n.A)("tabs",{"tabs--block":t},s),children:i.map((e=>{let{value:s,label:t,attributes:c}=e;return(0,m.jsx)("li",{role:"tab",tabIndex:r===s?0:-1,"aria-selected":r===s,ref:e=>d.push(e),onKeyDown:j,onClick:a,...c,className:(0,n.A)("tabs__item",b.tabItem,c?.className,{"tabs__item--active":r===s}),children:t??s},s)}))})}function y(e){let{lazy:s,children:t,selectedValue:c}=e;const l=(Array.isArray(t)?t:[t]).filter(Boolean);if(s){const e=l.find((e=>e.props.value===c));return e?(0,r.cloneElement)(e,{className:(0,n.A)("margin-top--md",e.props.className)}):null}return(0,m.jsx)("div",{className:"margin-top--md",children:l.map(((e,s)=>(0,r.cloneElement)(e,{key:s,hidden:e.props.value!==c})))})}function v(e){const s=p(e);return(0,m.jsxs)("div",{className:(0,n.A)("tabs-container",b.tabList),children:[(0,m.jsx)(g,{...s,...e}),(0,m.jsx)(y,{...s,...e})]})}function w(e){const s=(0,f.A)();return(0,m.jsx)(v,{...e,children:j(e.children)},String(s))}},8453:(e,s,t)=>{t.d(s,{R:()=>l,x:()=>i});var r=t(6540);const n={},c=r.createContext(n);function l(e){const s=r.useContext(c);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(n):e.components||n:l(e.components),r.createElement(c.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/a7bc29db.e63d021c.js b/assets/js/a7bc29db.e63d021c.js new file mode 100644 index 0000000000..7fde6fda4e --- /dev/null +++ b/assets/js/a7bc29db.e63d021c.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9123],{8474:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>a,contentTitle:()=>d,default:()=>x,frontMatter:()=>i,metadata:()=>o,toc:()=>j});var r=t(4848),n=t(8453),c=t(9489),l=t(7227);const i={id:"presets",title:"Presets"},d=void 0,o={id:"getting-started/presets",title:"Presets",description:"The presets",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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/presets.md",tags:[],version:"29.2",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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={a:"a",admonition:"admonition",code:"code",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,n.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.jsx)(s.admonition,{type:"caution",children:(0,r.jsxs)(s.p,{children:["The list of ",(0,r.jsx)(s.code,{children:"preset"})," below is now deprecated in favor of util functions. If one is using ",(0,r.jsx)(s.code,{children:"preset"})," in Jest config, please run ",(0,r.jsx)(s.code,{children:"npx ts-jest config:migrate"})," or look into ",(0,r.jsx)(s.a,{href:"#advanced",children:"Advanced"})," section below for alternative solutions."]})}),"\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.jsxs)(c.A,{groupId:"code-examples",children:[(0,r.jsx)(l.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\nconst { createDefaultPreset } = require('ts-jest')\n\nconst defaultPreset = createDefaultPreset()\n\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 ...defaultPreset,\n}\n"})})}),(0,r.jsx)(l.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, createDefaultPreset } from 'ts-jest'\n\nconst defaultPreset = createDefaultPreset()\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n // Replace `ts-jest` with the preset you want to use\n // from the above list\n ...defaultPreset,\n}\n\nexport default jestConfig\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.jsx)(s.p,{children:"There are several util functions to create and extend the existing presets:"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createDefaultPreset"}),": for default preset"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createDefaultLegacyPreset"}),": for default preset in legacy mode"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createDefaultEsmPreset"}),": for default ESM preset"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createDefaultEsmLegacyPreset"}),": for default ESM preset in legacy mode"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithTsPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-ts"})," preset"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithTsLegacyPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-ts"})," preset in legacy mode"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithTsEsmPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-ts"})," ESM preset"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithTsEsmLegacyPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-ts"})," ESM preset in legacy mode"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithBabelPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-babel"})," preset"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithBabelLegacyPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-babel"})," preset in legacy mode"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithBabelEsmPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-babel"})," ESM preset"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithBabelEsmLegacyPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-babel"})," ESM preset in legacy mode"]}),"\n"]}),"\n",(0,r.jsx)(s.p,{children:"Example:"}),"\n",(0,r.jsxs)(c.A,{groupId:"code-examples",children:[(0,r.jsx)(l.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\nconst { createDefaultPreset } = require('ts-jest')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n ...createDefaultPreset().transform,\n // [...]\n },\n}\n"})})}),(0,r.jsx)(l.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 { createDefaultPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n ...createDefaultPreset().transform,\n // [...]\n },\n}\n\nexport default jestConfig\n"})})})]})]})}function x(e={}){const{wrapper:s}={...(0,n.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},7227:(e,s,t)=>{t.d(s,{A:()=>l});t(6540);var r=t(4164);const n={tabItem:"tabItem_Ymn6"};var c=t(4848);function l(e){let{children:s,hidden:t,className:l}=e;return(0,c.jsx)("div",{role:"tabpanel",className:(0,r.A)(n.tabItem,l),hidden:t,children:s})}},9489:(e,s,t)=>{t.d(s,{A:()=>w});var r=t(6540),n=t(4164),c=t(4245),l=t(6347),i=t(6494),d=t(2814),o=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,o.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 x(e){let{value:s,tabValues:t}=e;return t.some((e=>e.value===s))}function u(e){let{queryString:s=!1,groupId:t}=e;const n=(0,l.W6)(),c=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,d.aZ)(c),(0,r.useCallback)((e=>{if(!c)return;const s=new URLSearchParams(n.location.search);s.set(c,e),n.replace({...n.location,search:s.toString()})}),[c,n])]}function p(e){const{defaultValue:s,queryString:t=!1,groupId:n}=e,c=h(e),[l,d]=(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(!x({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:c}))),[o,j]=u({queryString:t,groupId:n}),[p,f]=function(e){let{groupId:s}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(s),[n,c]=(0,a.Dv)(t);return[n,(0,r.useCallback)((e=>{t&&c.set(e)}),[t,c])]}({groupId:n}),b=(()=>{const e=o??p;return x({value:e,tabValues:c})?e:null})();(0,i.A)((()=>{b&&d(b)}),[b]);return{selectedValue:l,selectValue:(0,r.useCallback)((e=>{if(!x({value:e,tabValues:c}))throw new Error(`Can't select invalid tab value=${e}`);d(e),j(e),f(e)}),[j,f,c]),tabValues:c}}var f=t(1062);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var m=t(4848);function g(e){let{className:s,block:t,selectedValue:r,selectValue:l,tabValues:i}=e;const d=[],{blockElementScrollPositionUntilNextRender:o}=(0,c.a_)(),a=e=>{const s=e.currentTarget,t=d.indexOf(s),n=i[t].value;n!==r&&(o(s),l(n))},j=e=>{let s=null;switch(e.key){case"Enter":a(e);break;case"ArrowRight":{const t=d.indexOf(e.currentTarget)+1;s=d[t]??d[0];break}case"ArrowLeft":{const t=d.indexOf(e.currentTarget)-1;s=d[t]??d[d.length-1];break}}s?.focus()};return(0,m.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,n.A)("tabs",{"tabs--block":t},s),children:i.map((e=>{let{value:s,label:t,attributes:c}=e;return(0,m.jsx)("li",{role:"tab",tabIndex:r===s?0:-1,"aria-selected":r===s,ref:e=>d.push(e),onKeyDown:j,onClick:a,...c,className:(0,n.A)("tabs__item",b.tabItem,c?.className,{"tabs__item--active":r===s}),children:t??s},s)}))})}function y(e){let{lazy:s,children:t,selectedValue:c}=e;const l=(Array.isArray(t)?t:[t]).filter(Boolean);if(s){const e=l.find((e=>e.props.value===c));return e?(0,r.cloneElement)(e,{className:(0,n.A)("margin-top--md",e.props.className)}):null}return(0,m.jsx)("div",{className:"margin-top--md",children:l.map(((e,s)=>(0,r.cloneElement)(e,{key:s,hidden:e.props.value!==c})))})}function v(e){const s=p(e);return(0,m.jsxs)("div",{className:(0,n.A)("tabs-container",b.tabList),children:[(0,m.jsx)(g,{...s,...e}),(0,m.jsx)(y,{...s,...e})]})}function w(e){const s=(0,f.A)();return(0,m.jsx)(v,{...e,children:j(e.children)},String(s))}},8453:(e,s,t)=>{t.d(s,{R:()=>l,x:()=>i});var r=t(6540);const n={},c=r.createContext(n);function l(e){const s=r.useContext(c);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(n):e.components||n:l(e.components),r.createElement(c.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/a8c654d7.04f13905.js b/assets/js/a8c654d7.04f13905.js deleted file mode 100644 index ba8f97651a..0000000000 --- a/assets/js/a8c654d7.04f13905.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2587],{1748:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>g});var s=n(4848),o=n(8453);const r={id:"debugging",title:"Debugging ts-jest"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},d={},g=[];function l(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,o.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.jsx)(t.p,{children:"Command Prompt (cmd)"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"set TS_JEST_LOG=ts-jest.log\n"})}),"\n",(0,s.jsx)(t.p,{children:"PowerShell"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"$env:TS_JEST_LOG = 'ts-jest.log'\n"})})]})}function u(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/a8c654d7.75ab4c15.js b/assets/js/a8c654d7.75ab4c15.js new file mode 100644 index 0000000000..7c96f87b07 --- /dev/null +++ b/assets/js/a8c654d7.75ab4c15.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2587],{1748:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>u,frontMatter:()=>i,metadata:()=>c,toc:()=>g});var s=n(4848),o=n(8453);const i={id:"debugging",title:"Debugging ts-jest"},r=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/debugging.md",tags:[],version:"28.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},g=[];function l(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,o.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.jsx)(t.p,{children:"Command Prompt (cmd)"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"set TS_JEST_LOG=ts-jest.log\n"})}),"\n",(0,s.jsx)(t.p,{children:"PowerShell"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"$env:TS_JEST_LOG = 'ts-jest.log'\n"})})]})}function u(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/a8e3f14e.184517ed.js b/assets/js/a8e3f14e.184517ed.js new file mode 100644 index 0000000000..47e748f249 --- /dev/null +++ b/assets/js/a8e3f14e.184517ed.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2234],{4813:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>l,default:()=>p,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var s=n(4848),r=n(8453),o=n(9489),a=n(7227);const i={title:"Stringify content option"},l=void 0,u={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Stringify content option"}},c={},d=[{value:"Example",id:"example",level:3}];function h(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["The ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,s.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,s.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,s.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,s.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,s.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,s.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,s.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,s.jsx)(t.code,{children:"transform"})," option pointing to ",(0,s.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,s.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsxs)(t.p,{children:["In the ",(0,s.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,s.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,s.jsxs)(o.A,{groupId:"code-examples",children:[(0,s.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(a.A,{value:"JSON",children:(0,s.jsx)(t.pre,{children:(0,s.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,r.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/a8e3f14e.4ca39d4c.js b/assets/js/a8e3f14e.4ca39d4c.js deleted file mode 100644 index d91ba6d24a..0000000000 --- a/assets/js/a8e3f14e.4ca39d4c.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2234],{4813:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>l,default:()=>p,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var s=n(4848),r=n(8453),o=n(9489),a=n(7227);const i={title:"Stringify content option"},l=void 0,u={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Stringify content option"}},c={},d=[{value:"Example",id:"example",level:3}];function h(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["The ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,s.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,s.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,s.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,s.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,s.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,s.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,s.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,s.jsx)(t.code,{children:"transform"})," option pointing to ",(0,s.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,s.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsxs)(t.p,{children:["In the ",(0,s.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,s.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,s.jsxs)(o.A,{groupId:"code-examples",children:[(0,s.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(a.A,{value:"JSON",children:(0,s.jsx)(t.pre,{children:(0,s.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,r.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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.c4f5c776.js b/assets/js/aaf1bd4c.c4f5c776.js new file mode 100644 index 0000000000..b55ade1bd4 --- /dev/null +++ b/assets/js/aaf1bd4c.c4f5c776.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[863],{2975:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>l,default:()=>h,frontMatter:()=>i,metadata:()=>d,toc:()=>c});var s=n(4848),o=n(8453);const i={title:"Isolated Modules option"},l=void 0,d={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Isolated Modules option"}},a={},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,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default ",(0,s.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,s.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,s.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,s.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,s.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,s.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\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 isolatedModules: true,\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 "isolatedModules": true\n }\n }\n }\n}\n'})}),"\n",(0,s.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,s.jsxs)(t.p,{children:["Using ",(0,s.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,s.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,s.jsx)(t.code,{children:"include"})," in ",(0,s.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,s.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,s.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,s.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,s.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,s.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,s.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,s.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,s.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,s.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,s.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function h(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(r,{...e})}):r(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>l,x:()=>d});var s=n(6540);const o={},i=s.createContext(o);function l(e){const t=s.useContext(i);return s.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(o):e.components||o:l(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/aaf1bd4c.d134d28d.js b/assets/js/aaf1bd4c.d134d28d.js deleted file mode 100644 index bd05ed57f7..0000000000 --- a/assets/js/aaf1bd4c.d134d28d.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[863],{2975:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>l,default:()=>h,frontMatter:()=>i,metadata:()=>a,toc:()=>c});var s=n(4848),o=n(8453);const i={title:"Isolated Modules option"},l=void 0,a={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Isolated Modules option"}},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,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default ",(0,s.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,s.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,s.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,s.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,s.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,s.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\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 isolatedModules: true,\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 "isolatedModules": true\n }\n }\n }\n}\n'})}),"\n",(0,s.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,s.jsxs)(t.p,{children:["Using ",(0,s.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,s.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,s.jsx)(t.code,{children:"include"})," in ",(0,s.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,s.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,s.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,s.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,s.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,s.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,s.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,s.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,s.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,s.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,s.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function h(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(r,{...e})}):r(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>l,x:()=>a});var s=n(6540);const o={},i=s.createContext(o);function l(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:l(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/ae1ffb77.484ff674.js b/assets/js/ae1ffb77.484ff674.js deleted file mode 100644 index 9c881cddc0..0000000000 --- a/assets/js/ae1ffb77.484ff674.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[698],{4500:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>p,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var s=n(4848),i=n(8453);const r={id:"version-checking",title:"Version checking"},o=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},d={},a=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default, ",(0,s.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,s.jsx)(t.code,{children:"jest"}),"/",(0,s.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,s.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\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_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Windows"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,s.jsxs)(t.p,{children:["As long as the environment variable ",(0,s.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,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/ae1ffb77.66fa1e5c.js b/assets/js/ae1ffb77.66fa1e5c.js new file mode 100644 index 0000000000..39cfed007c --- /dev/null +++ b/assets/js/ae1ffb77.66fa1e5c.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[698],{4500:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>p,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var s=n(4848),i=n(8453);const r={id:"version-checking",title:"Version checking"},o=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},a=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default, ",(0,s.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,s.jsx)(t.code,{children:"jest"}),"/",(0,s.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,s.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\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_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Windows"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,s.jsxs)(t.p,{children:["As long as the environment variable ",(0,s.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,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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.44ee925a.js b/assets/js/aeb5491d.44ee925a.js deleted file mode 100644 index d07d8adbd4..0000000000 --- a/assets/js/aeb5491d.44ee925a.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4572],{5507:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>p,frontMatter:()=>o,metadata:()=>c,toc:()=>l});var s=n(4848),i=n(8453);const o={id:"babel7-or-ts",title:"Babel7 or TypeScript"},r=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},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,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,s.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,s.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,s.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,s.jsxs)(t.p,{children:["While ",(0,s.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,s.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,s.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,s.jsxs)(t.p,{children:["This is the big ",(0,s.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,s.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,s.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,s.jsx)(t.code,{children:"namespace"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,s.jsx)(t.code,{children:"const enum"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,s.jsx)(t.code,{children:"enum"}),", ",(0,s.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,s.jsxs)(t.p,{children:["You won't be able to do ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,s.jsx)(t.code,{children:"import"}),"/",(0,s.jsx)(t.code,{children:"export"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(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,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/aeb5491d.74ba324f.js b/assets/js/aeb5491d.74ba324f.js new file mode 100644 index 0000000000..691c3be518 --- /dev/null +++ b/assets/js/aeb5491d.74ba324f.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4572],{5507:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>p,frontMatter:()=>o,metadata:()=>c,toc:()=>l});var s=n(4848),i=n(8453);const o={id:"babel7-or-ts",title:"Babel7 or TypeScript"},r=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/babel7-or-ts.md",tags:[],version:"28.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,s.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,s.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,s.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,s.jsxs)(t.p,{children:["While ",(0,s.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,s.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,s.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,s.jsxs)(t.p,{children:["This is the big ",(0,s.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,s.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,s.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,s.jsx)(t.code,{children:"namespace"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,s.jsx)(t.code,{children:"const enum"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,s.jsx)(t.code,{children:"enum"}),", ",(0,s.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,s.jsxs)(t.p,{children:["You won't be able to do ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,s.jsx)(t.code,{children:"import"}),"/",(0,s.jsx)(t.code,{children:"export"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(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,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.05b0b655.js b/assets/js/aeb823d8.05b0b655.js new file mode 100644 index 0000000000..98dc4ca6d4 --- /dev/null +++ b/assets/js/aeb823d8.05b0b655.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3790],{5859:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>p,frontMatter:()=>l,metadata:()=>c,toc:()=>d});var s=n(4848),a=n(8453),r=n(9489),o=n(7227);const l={title:"Isolated Modules option"},i=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Isolated Modules option"}},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,a.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default ",(0,s.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,s.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,s.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,s.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,s.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,s.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsxs)(r.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.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,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.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,s.jsx)(o.A,{value:"JSON",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,s.jsxs)(t.p,{children:["Using ",(0,s.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,s.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,s.jsx)(t.code,{children:"include"})," in ",(0,s.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,s.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,s.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,s.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,s.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,s.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,s.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,s.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,s.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,s.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,s.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function p(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var s=n(4164);const a={tabItem:"tabItem_Ymn6"};var r=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,s.A)(a.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),a=n(4164),r=n(4245),o=n(6347),l=n(6494),i=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:a}}=e;return{value:t,label:n,attributes:s,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 p(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 a=(0,o.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,i.aZ)(r),(0,s.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:n=!1,groupId:a}=e,r=h(e),[o,i]=(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:r}))),[c,d]=m({queryString:n,groupId:a}),[f,j]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,r]=(0,u.Dv)(n);return[a,(0,s.useCallback)((e=>{n&&r.set(e)}),[n,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,s.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=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:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),u=e=>{const t=e.currentTarget,n=i.indexOf(t),a=l[n].value;a!==s&&(c(t),o(a))},d=e=>{let t=null;switch(e.key){case"Enter":u(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,b.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:r}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>i.push(e),onKeyDown:d,onClick:u,...r,className:(0,a.A)("tabs__item",g.tabItem,r?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:r}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===r));return e?(0,s.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,s.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,n)=>{n.d(t,{R:()=>o,x:()=>l});var s=n(6540);const a={},r=s.createContext(a);function o(e){const t=s.useContext(r);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(a):e.components||a:o(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/aeb823d8.c5497753.js b/assets/js/aeb823d8.c5497753.js deleted file mode 100644 index 86e0e9a6a5..0000000000 --- a/assets/js/aeb823d8.c5497753.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3790],{5859:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>p,frontMatter:()=>l,metadata:()=>c,toc:()=>d});var s=n(4848),a=n(8453),r=n(9489),o=n(7227);const l={title:"Isolated Modules option"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Isolated Modules option"}},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,a.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default ",(0,s.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,s.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,s.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,s.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,s.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,s.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsxs)(r.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.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,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.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,s.jsx)(o.A,{value:"JSON",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,s.jsxs)(t.p,{children:["Using ",(0,s.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,s.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,s.jsx)(t.code,{children:"include"})," in ",(0,s.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,s.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,s.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,s.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,s.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,s.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,s.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,s.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,s.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,s.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,s.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function p(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var s=n(4164);const a={tabItem:"tabItem_Ymn6"};var r=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,s.A)(a.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),a=n(4164),r=n(4245),o=n(6347),l=n(6494),i=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:a}}=e;return{value:t,label:n,attributes:s,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 p(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 a=(0,o.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,i.aZ)(r),(0,s.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:n=!1,groupId:a}=e,r=h(e),[o,i]=(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:r}))),[c,d]=m({queryString:n,groupId:a}),[f,j]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,r]=(0,u.Dv)(n);return[a,(0,s.useCallback)((e=>{n&&r.set(e)}),[n,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,s.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=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:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),u=e=>{const t=e.currentTarget,n=i.indexOf(t),a=l[n].value;a!==s&&(c(t),o(a))},d=e=>{let t=null;switch(e.key){case"Enter":u(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,b.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:r}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>i.push(e),onKeyDown:d,onClick:u,...r,className:(0,a.A)("tabs__item",g.tabItem,r?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:r}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===r));return e?(0,s.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,s.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,n)=>{n.d(t,{R:()=>o,x:()=>l});var s=n(6540);const a={},r=s.createContext(a);function o(e){const t=s.useContext(r);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(a):e.components||a:o(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/afb030c9.413a6f86.js b/assets/js/afb030c9.413a6f86.js deleted file mode 100644 index fff567a0b3..0000000000 --- a/assets/js/afb030c9.413a6f86.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4746],{2198:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>a,frontMatter:()=>r,metadata:()=>c,toc:()=>u});var n=s(4848),o=s(8453);const r={id:"processing",title:"Processing flow"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},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,o.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,n.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,n.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,n.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,o.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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/afb030c9.491cb4a9.js b/assets/js/afb030c9.491cb4a9.js new file mode 100644 index 0000000000..146598fd1d --- /dev/null +++ b/assets/js/afb030c9.491cb4a9.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4746],{2198:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>a,frontMatter:()=>r,metadata:()=>c,toc:()=>d});var n=s(4848),o=s(8453);const r={id:"processing",title:"Processing flow"},i=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/processing.md",tags:[],version:"28.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},l={},d=[{value:"Jest process",id:"jest-process",level:2},{value:"ts-jest process",id:"ts-jest-process",level:2}];function u(e){const t={code:"code",em:"em",h2:"h2",img:"img",p:"p",...(0,o.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,n.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,n.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,n.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,o.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(u,{...e})}):u(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.3150b8d9.js b/assets/js/b317f538.3150b8d9.js deleted file mode 100644 index 32d59a9354..0000000000 --- a/assets/js/b317f538.3150b8d9.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8392],{6613:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>p,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var s=n(4848),i=n(8453);const r={id:"version-checking",title:"Version checking"},o=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},d={},a=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default, ",(0,s.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,s.jsx)(t.code,{children:"jest"}),"/",(0,s.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,s.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\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_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Windows"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,s.jsxs)(t.p,{children:["As long as the environment variable ",(0,s.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,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/b317f538.a300eae3.js b/assets/js/b317f538.a300eae3.js new file mode 100644 index 0000000000..6912efbe4e --- /dev/null +++ b/assets/js/b317f538.a300eae3.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8392],{6613:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>p,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var s=n(4848),i=n(8453);const r={id:"version-checking",title:"Version checking"},o=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},a=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default, ",(0,s.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,s.jsx)(t.code,{children:"jest"}),"/",(0,s.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,s.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\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_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Windows"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,s.jsxs)(t.p,{children:["As long as the environment variable ",(0,s.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,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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.40d2892d.js b/assets/js/b519512b.40d2892d.js deleted file mode 100644 index ee474d784a..0000000000 --- a/assets/js/b519512b.40d2892d.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8116],{6278:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>o,metadata:()=>r,toc:()=>l});var s=n(4848),i=n(8453);const o={id:"react-native",title:"Using with React Native"},c=void 0,r={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:!1,unlisted:!1,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:1726058855e3,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"}},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,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["To use ",(0,s.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,s.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,s.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,s.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,s.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,s.jsx)(t.code,{children:".babelrc"})," to ",(0,s.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",children:"// babel.config.js\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n"})}),"\n",(0,s.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,s.jsxs)(t.p,{children:["Create a new ",(0,s.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,s.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,s.jsx)(t.code,{children:"jest"})," key of ",(0,s.jsx)(t.code,{children:"package.json"})," to ",(0,s.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>c,x:()=>r});var s=n(6540);const i={},o=s.createContext(i);function c(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:c(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/b519512b.da6d212d.js b/assets/js/b519512b.da6d212d.js new file mode 100644 index 0000000000..b8478cc6e2 --- /dev/null +++ b/assets/js/b519512b.da6d212d.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8116],{6278:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>r,contentTitle:()=>c,default:()=>p,frontMatter:()=>o,metadata:()=>a,toc:()=>l});var s=n(4848),i=n(8453);const o={id:"react-native",title:"Using with React Native"},c=void 0,a={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/guides/react-native.md",tags:[],version:"27.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["To use ",(0,s.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,s.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,s.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,s.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,s.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,s.jsx)(t.code,{children:".babelrc"})," to ",(0,s.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",children:"// babel.config.js\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n"})}),"\n",(0,s.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,s.jsxs)(t.p,{children:["Create a new ",(0,s.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,s.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,s.jsx)(t.code,{children:"jest"})," key of ",(0,s.jsx)(t.code,{children:"package.json"})," to ",(0,s.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>c,x:()=>a});var s=n(6540);const i={},o=s.createContext(i);function c(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(i):e.components||i:c(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/b72fc7f8.47691ada.js b/assets/js/b72fc7f8.47691ada.js new file mode 100644 index 0000000000..bd512ddceb --- /dev/null +++ b/assets/js/b72fc7f8.47691ada.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9610],{3605:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>l,default:()=>p,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var r=n(4848),a=n(8453),s=n(9489),o=n(7227);const i={id:"migration",title:"Migration from <=23.10"},l=void 0,u={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/migration.md",tags:[],version:"29.2",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},c={},d=[];function m(e){const t={code:"code",em:"em",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["You can use the ",(0,r.jsx)(t.code,{children:"config:migrate"})," tool of ",(0,r.jsx)(t.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsxs)(t.em,{children:["If you're using ",(0,r.jsx)(t.code,{children:"jest.config.js"}),":"]})}),"\n",(0,r.jsxs)(s.A,{groupId:"code-examples",children:[(0,r.jsx)(o.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:migrate jest.config.js\n"})})}),(0,r.jsx)(o.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:migrate jest.config.js\n"})})})]}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsxs)(t.em,{children:["If you're using ",(0,r.jsx)(t.code,{children:"jest"})," config property of ",(0,r.jsx)(t.code,{children:"package.json"}),":"]})}),"\n",(0,r.jsxs)(s.A,{groupId:"code-examples",children:[(0,r.jsx)(o.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:migrate package.json\n"})})}),(0,r.jsx)(o.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:migrate package.json\n"})})})]})]})}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,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/b72fc7f8.a5963645.js b/assets/js/b72fc7f8.a5963645.js deleted file mode 100644 index d084a0f939..0000000000 --- a/assets/js/b72fc7f8.a5963645.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9610],{3605:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>l,default:()=>p,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var r=n(4848),a=n(8453),s=n(9489),o=n(7227);const i={id:"migration",title:"Migration from <=23.10"},l=void 0,u={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:!1,unlisted:!1,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:1726058855e3,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"}},c={},d=[];function m(e){const t={code:"code",em:"em",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["You can use the ",(0,r.jsx)(t.code,{children:"config:migrate"})," tool of ",(0,r.jsx)(t.code,{children:"ts-jest"})," CLI if you're coming from an older version to help you migrate your Jest configuration."]}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsxs)(t.em,{children:["If you're using ",(0,r.jsx)(t.code,{children:"jest.config.js"}),":"]})}),"\n",(0,r.jsxs)(s.A,{groupId:"code-examples",children:[(0,r.jsx)(o.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:migrate jest.config.js\n"})})}),(0,r.jsx)(o.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:migrate jest.config.js\n"})})})]}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsxs)(t.em,{children:["If you're using ",(0,r.jsx)(t.code,{children:"jest"})," config property of ",(0,r.jsx)(t.code,{children:"package.json"}),":"]})}),"\n",(0,r.jsxs)(s.A,{groupId:"code-examples",children:[(0,r.jsx)(o.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:migrate package.json\n"})})}),(0,r.jsx)(o.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:migrate package.json\n"})})})]})]})}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,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.d1c5637f.js b/assets/js/b809b403.d1c5637f.js deleted file mode 100644 index 24723a849f..0000000000 --- a/assets/js/b809b403.d1c5637f.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7693],{4457:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>a,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>d});var n=s(4848),o=s(8453);const r={title:"useESM option"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"useESM option"}},a={},d=[{value:"Examples",id:"examples",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["The ",(0,n.jsx)(t.code,{children:"useESM"})," option allows ",(0,n.jsx)(t.code,{children:"ts-jest"})," to transform codes to ESM syntax ",(0,n.jsx)(t.strong,{children:"if possible"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["The default value is ",(0,n.jsx)(t.strong,{children:"false"}),", ",(0,n.jsx)(t.code,{children:"ts-jest"})," will transform codes to ",(0,n.jsx)(t.code,{children:"CommonJS"})," syntax."]}),"\n",(0,n.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.pre,{children:(0,n.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 u(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(l,{...e})}):l(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/b809b403.ede8ac44.js b/assets/js/b809b403.ede8ac44.js new file mode 100644 index 0000000000..d0d22527c4 --- /dev/null +++ b/assets/js/b809b403.ede8ac44.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7693],{4457:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>d,contentTitle:()=>i,default:()=>p,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var n=s(4848),o=s(8453);const r={title:"useESM option"},i=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"useESM option"}},d={},a=[{value:"Examples",id:"examples",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["The ",(0,n.jsx)(t.code,{children:"useESM"})," option allows ",(0,n.jsx)(t.code,{children:"ts-jest"})," to transform codes to ESM syntax ",(0,n.jsx)(t.strong,{children:"if possible"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["The default value is ",(0,n.jsx)(t.strong,{children:"false"}),", ",(0,n.jsx)(t.code,{children:"ts-jest"})," will transform codes to ",(0,n.jsx)(t.code,{children:"CommonJS"})," syntax."]}),"\n",(0,n.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.pre,{children:(0,n.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,o.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(l,{...e})}):l(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/b96776d9.5cc0c986.js b/assets/js/b96776d9.5cc0c986.js new file mode 100644 index 0000000000..f6b4079dc7 --- /dev/null +++ b/assets/js/b96776d9.5cc0c986.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4623],{4778:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>l,default:()=>f,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var s=n(4848),r=n(8453),a=n(9489),o=n(7227);const i={id:"react-native",title:"Using with React Native"},l=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/guides/react-native.md",tags:[],version:"29.2",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["To use ",(0,s.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,s.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,s.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,s.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,s.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,s.jsx)(t.code,{children:".babelrc"})," to ",(0,s.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,s.jsxs)(a.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.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\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.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,s.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,s.jsxs)(t.p,{children:["Create a new ",(0,s.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,s.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,s.jsx)(t.code,{children:"jest"})," key of ",(0,s.jsx)(t.code,{children:"package.json"})," to ",(0,s.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,s.jsxs)(a.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.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,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.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 f(e={}){const{wrapper:t}={...(0,r.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:()=>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 b(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}),[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 f({value:e,tabValues:a})?e:null})();(0,i.A)((()=>{m&&l(m)}),[m]);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 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/b96776d9.bfdc48fb.js b/assets/js/b96776d9.bfdc48fb.js deleted file mode 100644 index a2af7cfb18..0000000000 --- a/assets/js/b96776d9.bfdc48fb.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4623],{4778:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>l,default:()=>f,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var s=n(4848),r=n(8453),a=n(9489),o=n(7227);const i={id:"react-native",title:"Using with React Native"},l=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},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,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["To use ",(0,s.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,s.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,s.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,s.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,s.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,s.jsx)(t.code,{children:".babelrc"})," to ",(0,s.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,s.jsxs)(a.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.config.js\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\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.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,s.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,s.jsxs)(t.p,{children:["Create a new ",(0,s.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,s.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,s.jsx)(t.code,{children:"jest"})," key of ",(0,s.jsx)(t.code,{children:"package.json"})," to ",(0,s.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,s.jsxs)(a.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.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,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.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 f(e={}){const{wrapper:t}={...(0,r.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:()=>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 b(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}),[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 f({value:e,tabValues:a})?e:null})();(0,i.A)((()=>{m&&l(m)}),[m]);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 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.5d7a8400.js b/assets/js/bdf18d96.5d7a8400.js deleted file mode 100644 index 020cc91b1f..0000000000 --- a/assets/js/bdf18d96.5d7a8400.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7555],{711:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>a,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>l});var t=n(4848),o=n(8453);const r={id:"mock-es6-class",title:"Mock ES6 class"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},a={},l=[];function d(e){const s={code:"code",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(s.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,t.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,t.jsx)(s.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.p,{children:"You will get the error"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,t.jsxs)(s.p,{children:["because ",(0,t.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,t.jsx)(s.pre,{children:(0,t.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,t.jsxs)(s.p,{children:["For named imports, like ",(0,t.jsx)(s.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,t.jsx)(s.code,{children:"default"})," with imported module name, ",(0,t.jsx)(s.code,{children:"OAuth2"})," in this example:"]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,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:()=>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/bdf18d96.70544916.js b/assets/js/bdf18d96.70544916.js new file mode 100644 index 0000000000..a6ec5266c7 --- /dev/null +++ b/assets/js/bdf18d96.70544916.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7555],{711:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>a,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>d});var t=n(4848),o=n(8453);const r={id:"mock-es6-class",title:"Mock ES6 class"},i=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},a={},d=[];function l(e){const s={code:"code",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(s.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,t.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,t.jsx)(s.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.p,{children:"You will get the error"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,t.jsxs)(s.p,{children:["because ",(0,t.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,t.jsx)(s.pre,{children:(0,t.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,t.jsxs)(s.p,{children:["For named imports, like ",(0,t.jsx)(s.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,t.jsx)(s.code,{children:"default"})," with imported module name, ",(0,t.jsx)(s.code,{children:"OAuth2"})," in this example:"]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,o.R)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.jsx)(l,{...e})}):l(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.46b4af4b.js b/assets/js/bdfec613.46b4af4b.js new file mode 100644 index 0000000000..3a58846b83 --- /dev/null +++ b/assets/js/bdfec613.46b4af4b.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4733],{856:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>r,default:()=>j,frontMatter:()=>o,metadata:()=>d,toc:()=>l});var t=n(4848),i=n(8453);const o={id:"options",title:"Options"},r=void 0,d={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/getting-started/options.md",tags:[],version:"27.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,i.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(s.h3,{id:"introduction",children:"Introduction"}),"\n",(0,t.jsxs)(s.p,{children:["All ",(0,t.jsx)(s.code,{children:"ts-jest"})," specific options are located under the ",(0,t.jsx)(s.code,{children:"globals"})," of Jest config object in the ",(0,t.jsx)(s.code,{children:"package.json"})," file of your project,\nor through a ",(0,t.jsx)(s.code,{children:"jest.config.js"}),", or ",(0,t.jsx)(s.code,{children:"jest.config.ts"})," file."]}),"\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 // ts-jest configuration goes here\n }\n }\n }\n}\n'})}),"\n",(0,t.jsx)(s.p,{children:"Or through JavaScript:"}),"\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 // ts-jest configuration goes here\n },\n },\n}\n"})}),"\n",(0,t.jsxs)(s.admonition,{type:"tip",children:[(0,t.jsxs)(s.p,{children:["To utilize IDE suggestions, you can use ",(0,t.jsx)(s.code,{children:"JSDoc"})," comments to provide suggested ",(0,t.jsx)(s.code,{children:"ts-jest"})," configs for your Jest config:"]}),(0,t.jsx)(s.pre,{children:(0,t.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,t.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,t.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.admonition,{type:"important",children:(0,t.jsxs)(s.p,{children:["When using TypeScript Jest config file, Jest will use ",(0,t.jsx)(s.code,{children:"ts-node"})," to compile the config file. ",(0,t.jsx)(s.code,{children:"ts-jest"})," doesn't take part in\nthat process."]})}),"\n",(0,t.jsx)(s.h3,{id:"options",children:"Options"}),"\n",(0,t.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,t.jsxs)(s.table,{children:[(0,t.jsx)(s.thead,{children:(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.th,{children:"Option"}),(0,t.jsx)(s.th,{children:"Description"}),(0,t.jsx)(s.th,{children:"Type"}),(0,t.jsx)(s.th,{children:"Default"})]})}),(0,t.jsxs)(s.tbody,{children:[(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/compiler",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"compiler"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"string"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:'"typescript"'})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/tsconfig",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"tsconfig"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"string"}),"|",(0,t.jsx)(s.code,{children:"object"}),"|",(0,t.jsx)(s.code,{children:"boolean"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"auto"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/isolatedModules",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"isolatedModules"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"boolean"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"disabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/astTransformers",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"astTransformers"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"object"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"auto"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/diagnostics",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"diagnostics"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"boolean"}),"|",(0,t.jsx)(s.code,{children:"object"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"enabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/babelConfig",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"babelConfig"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"boolean"}),"|",(0,t.jsx)(s.code,{children:"string"}),"|",(0,t.jsx)(s.code,{children:"object"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"disabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"stringifyContentPathRegex"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"string"}),"|",(0,t.jsx)(s.code,{children:"RegExp"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"disabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/useESM",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"useESM"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/useESM",children:"Enable ESM support"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"boolean"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"auto"})})]})]})]})]})}function j(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.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/bdfec613.a323a150.js b/assets/js/bdfec613.a323a150.js deleted file mode 100644 index bd2dd9fe5d..0000000000 --- a/assets/js/bdfec613.a323a150.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4733],{856:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>r,default:()=>j,frontMatter:()=>o,metadata:()=>d,toc:()=>l});var t=n(4848),i=n(8453);const o={id:"options",title:"Options"},r=void 0,d={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:!1,unlisted:!1,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:1726058855e3,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"}},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,i.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(s.h3,{id:"introduction",children:"Introduction"}),"\n",(0,t.jsxs)(s.p,{children:["All ",(0,t.jsx)(s.code,{children:"ts-jest"})," specific options are located under the ",(0,t.jsx)(s.code,{children:"globals"})," of Jest config object in the ",(0,t.jsx)(s.code,{children:"package.json"})," file of your project,\nor through a ",(0,t.jsx)(s.code,{children:"jest.config.js"}),", or ",(0,t.jsx)(s.code,{children:"jest.config.ts"})," file."]}),"\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 // ts-jest configuration goes here\n }\n }\n }\n}\n'})}),"\n",(0,t.jsx)(s.p,{children:"Or through JavaScript:"}),"\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 // ts-jest configuration goes here\n },\n },\n}\n"})}),"\n",(0,t.jsxs)(s.admonition,{type:"tip",children:[(0,t.jsxs)(s.p,{children:["To utilize IDE suggestions, you can use ",(0,t.jsx)(s.code,{children:"JSDoc"})," comments to provide suggested ",(0,t.jsx)(s.code,{children:"ts-jest"})," configs for your Jest config:"]}),(0,t.jsx)(s.pre,{children:(0,t.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,t.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,t.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.admonition,{type:"important",children:(0,t.jsxs)(s.p,{children:["When using TypeScript Jest config file, Jest will use ",(0,t.jsx)(s.code,{children:"ts-node"})," to compile the config file. ",(0,t.jsx)(s.code,{children:"ts-jest"})," doesn't take part in\nthat process."]})}),"\n",(0,t.jsx)(s.h3,{id:"options",children:"Options"}),"\n",(0,t.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,t.jsxs)(s.table,{children:[(0,t.jsx)(s.thead,{children:(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.th,{children:"Option"}),(0,t.jsx)(s.th,{children:"Description"}),(0,t.jsx)(s.th,{children:"Type"}),(0,t.jsx)(s.th,{children:"Default"})]})}),(0,t.jsxs)(s.tbody,{children:[(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/compiler",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"compiler"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"string"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:'"typescript"'})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/tsconfig",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"tsconfig"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"string"}),"|",(0,t.jsx)(s.code,{children:"object"}),"|",(0,t.jsx)(s.code,{children:"boolean"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"auto"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/isolatedModules",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"isolatedModules"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"boolean"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"disabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/astTransformers",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"astTransformers"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"object"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"auto"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/diagnostics",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"diagnostics"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"boolean"}),"|",(0,t.jsx)(s.code,{children:"object"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"enabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/babelConfig",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"babelConfig"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"boolean"}),"|",(0,t.jsx)(s.code,{children:"string"}),"|",(0,t.jsx)(s.code,{children:"object"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"disabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"stringifyContentPathRegex"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"string"}),"|",(0,t.jsx)(s.code,{children:"RegExp"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"disabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/useESM",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"useESM"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/useESM",children:"Enable ESM support"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"boolean"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"auto"})})]})]})]})]})}function j(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.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.72ae3200.js b/assets/js/bf341476.72ae3200.js new file mode 100644 index 0000000000..692687dfd0 --- /dev/null +++ b/assets/js/bf341476.72ae3200.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2402],{6225:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var n=s(4848),o=s(8453);const r={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},i=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.0/introduction.md",tags:[],version:"27.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,o.R)(),...t.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,n.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,n.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,n.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,n.jsx)(e.code,{children:"preset-typescript"})," ",(0,n.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,n.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,n.jsx)(e.admonition,{type:"important",children:(0,n.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,n.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,n.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,o.R)(),...t.components};return e?(0,n.jsx)(e,{...t,children:(0,n.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/bf341476.a75f1ddb.js b/assets/js/bf341476.a75f1ddb.js deleted file mode 100644 index 25dd1f182c..0000000000 --- a/assets/js/bf341476.a75f1ddb.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2402],{6225:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>d,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var n=s(4848),o=s(8453);const r={id:"introduction",title:"Introduction",description:"A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.",slug:"/"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},d={},a=[];function p(t){const e={a:"a",admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,o.R)(),...t.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:"ts-jest"})," is a Jest ",(0,n.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,n.jsxs)(e.p,{children:["It supports all features of TypeScript including type-checking. ",(0,n.jsxs)(e.a,{href:"babel7-or-ts",children:["Read more about Babel7 + ",(0,n.jsx)(e.code,{children:"preset-typescript"})," ",(0,n.jsx)(e.strong,{children:"vs"})," TypeScript (and ",(0,n.jsx)(e.code,{children:"ts-jest"}),")"]}),"."]}),"\n",(0,n.jsx)(e.admonition,{type:"important",children:(0,n.jsxs)(e.p,{children:["We are not doing semantic versioning and ",(0,n.jsx)(e.code,{children:"23.10"})," is a re-write, run ",(0,n.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,o.R)(),...t.components};return e?(0,n.jsx)(e,{...t,children:(0,n.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.49e72000.js b/assets/js/c010a830.49e72000.js new file mode 100644 index 0000000000..ac8e1cc1fe --- /dev/null +++ b/assets/js/c010a830.49e72000.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7015],{1576:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>d,contentTitle:()=>i,default:()=>p,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var n=s(4848),o=s(8453);const r={title:"useESM option"},i=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"useESM option"}},d={},a=[{value:"Examples",id:"examples",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["The ",(0,n.jsx)(t.code,{children:"useESM"})," option allows ",(0,n.jsx)(t.code,{children:"ts-jest"})," to transform codes to ESM syntax ",(0,n.jsx)(t.strong,{children:"if possible"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["The default value is ",(0,n.jsx)(t.strong,{children:"false"}),", ",(0,n.jsx)(t.code,{children:"ts-jest"})," will transform codes to ",(0,n.jsx)(t.code,{children:"CommonJS"})," syntax."]}),"\n",(0,n.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.pre,{children:(0,n.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,o.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(l,{...e})}):l(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/c010a830.bd6153dd.js b/assets/js/c010a830.bd6153dd.js deleted file mode 100644 index d15c04c601..0000000000 --- a/assets/js/c010a830.bd6153dd.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7015],{1576:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>a,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>d});var n=s(4848),o=s(8453);const r={title:"useESM option"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"useESM option"}},a={},d=[{value:"Examples",id:"examples",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["The ",(0,n.jsx)(t.code,{children:"useESM"})," option allows ",(0,n.jsx)(t.code,{children:"ts-jest"})," to transform codes to ESM syntax ",(0,n.jsx)(t.strong,{children:"if possible"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["The default value is ",(0,n.jsx)(t.strong,{children:"false"}),", ",(0,n.jsx)(t.code,{children:"ts-jest"})," will transform codes to ",(0,n.jsx)(t.code,{children:"CommonJS"})," syntax."]}),"\n",(0,n.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.pre,{children:(0,n.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 u(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(l,{...e})}):l(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/c1932cab.0ff76e2f.js b/assets/js/c1932cab.0ff76e2f.js new file mode 100644 index 0000000000..e5db75a321 --- /dev/null +++ b/assets/js/c1932cab.0ff76e2f.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8719],{8068:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>r,contentTitle:()=>i,default:()=>b,frontMatter:()=>l,metadata:()=>a,toc:()=>c});var t=s(4848),o=s(8453);const l={title:"Babel Config option"},i=void 0,a={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Babel Config option"}},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,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.code,{children:"ts-jest"})," by default does ",(0,t.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,t.jsx)(n.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,t.jsxs)(n.p,{children:["The option is ",(0,t.jsx)(n.code,{children:"babelConfig"})," and it works pretty much as the ",(0,t.jsx)(n.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"true"}),": enables Babel processing. ",(0,t.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,t.jsx)(n.code,{children:".babelrc"}),", ",(0,t.jsx)(n.code,{children:".babelrc.js"}),", ",(0,t.jsx)(n.code,{children:"babel.config.js"})," file or a ",(0,t.jsx)(n.code,{children:"babel"})," section in the ",(0,t.jsx)(n.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,t.jsx)(n.code,{children:"babel-jest"})," processor."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"{ ... }"}),": inline ",(0,t.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,t.jsx)(n.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,t.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,t.jsxs)(n.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,t.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.pre,{children:(0,t.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,t.jsxs)(n.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,t.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,t.jsxs)(n.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,t.jsx)(n.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.p,{children:"or"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,t.jsxs)(n.p,{children:["Refer to the ",(0,t.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.pre,{children:(0,t.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,o.R)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(d,{...e})}):d(e)}},8453:(e,n,s)=>{s.d(n,{R:()=>i,x:()=>a});var t=s(6540);const o={},l=t.createContext(o);function i(e){const n=t.useContext(l);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),t.createElement(l.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/c1932cab.495d8f47.js b/assets/js/c1932cab.495d8f47.js deleted file mode 100644 index 747a682cc1..0000000000 --- a/assets/js/c1932cab.495d8f47.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8719],{8068:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>r,contentTitle:()=>i,default:()=>b,frontMatter:()=>l,metadata:()=>a,toc:()=>c});var t=s(4848),o=s(8453);const l={title:"Babel Config option"},i=void 0,a={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Babel Config option"}},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,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.code,{children:"ts-jest"})," by default does ",(0,t.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,t.jsx)(n.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,t.jsxs)(n.p,{children:["The option is ",(0,t.jsx)(n.code,{children:"babelConfig"})," and it works pretty much as the ",(0,t.jsx)(n.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"true"}),": enables Babel processing. ",(0,t.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,t.jsx)(n.code,{children:".babelrc"}),", ",(0,t.jsx)(n.code,{children:".babelrc.js"}),", ",(0,t.jsx)(n.code,{children:"babel.config.js"})," file or a ",(0,t.jsx)(n.code,{children:"babel"})," section in the ",(0,t.jsx)(n.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,t.jsx)(n.code,{children:"babel-jest"})," processor."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"{ ... }"}),": inline ",(0,t.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,t.jsx)(n.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,t.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,t.jsxs)(n.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,t.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.pre,{children:(0,t.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,t.jsxs)(n.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,t.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,t.jsxs)(n.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,t.jsx)(n.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.p,{children:"or"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,t.jsxs)(n.p,{children:["Refer to the ",(0,t.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.pre,{children:(0,t.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,o.R)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(d,{...e})}):d(e)}},8453:(e,n,s)=>{s.d(n,{R:()=>i,x:()=>a});var t=s(6540);const o={},l=t.createContext(o);function i(e){const n=t.useContext(l);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),t.createElement(l.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/c1a7450f.02f62738.js b/assets/js/c1a7450f.02f62738.js deleted file mode 100644 index 5163c0a31c..0000000000 --- a/assets/js/c1a7450f.02f62738.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6120],{8290:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>m,frontMatter:()=>l,metadata:()=>i,toc:()=>d});var n=s(4848),r=s(8453),a=s(9489),o=s(7227);const l={title:"useESM option"},u=void 0,i={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/useESM.md",tags:[],version:"current",lastUpdatedBy:"renovate[bot]",lastUpdatedAt:1726058855e3,frontMatter:{title:"useESM option"}},c={},d=[{value:"Examples",id:"examples",level:3}];function p(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["The ",(0,n.jsx)(t.code,{children:"useESM"})," option allows ",(0,n.jsx)(t.code,{children:"ts-jest"})," to transform codes to ESM syntax ",(0,n.jsx)(t.strong,{children:"if possible"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["The default value is ",(0,n.jsx)(t.strong,{children:"false"}),", ",(0,n.jsx)(t.code,{children:"ts-jest"})," will transform codes to ",(0,n.jsx)(t.code,{children:"CommonJS"})," syntax."]}),"\n",(0,n.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsxs)(a.A,{groupId:"code-examples",children:[(0,n.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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/c1a7450f.21caf916.js b/assets/js/c1a7450f.21caf916.js new file mode 100644 index 0000000000..bc43e7534f --- /dev/null +++ b/assets/js/c1a7450f.21caf916.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6120],{8290:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>m,frontMatter:()=>l,metadata:()=>i,toc:()=>d});var n=s(4848),r=s(8453),a=s(9489),o=s(7227);const l={title:"useESM option"},u=void 0,i={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/useESM.md",tags:[],version:"current",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"useESM option"}},c={},d=[{value:"Examples",id:"examples",level:3}];function p(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["The ",(0,n.jsx)(t.code,{children:"useESM"})," option allows ",(0,n.jsx)(t.code,{children:"ts-jest"})," to transform codes to ESM syntax ",(0,n.jsx)(t.strong,{children:"if possible"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["The default value is ",(0,n.jsx)(t.strong,{children:"false"}),", ",(0,n.jsx)(t.code,{children:"ts-jest"})," will transform codes to ",(0,n.jsx)(t.code,{children:"CommonJS"})," syntax."]}),"\n",(0,n.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsxs)(a.A,{groupId:"code-examples",children:[(0,n.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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.41f03f71.js b/assets/js/c6326909.41f03f71.js new file mode 100644 index 0000000000..6e3fcf59f2 --- /dev/null +++ b/assets/js/c6326909.41f03f71.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6121],{3023:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>p,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var s=n(4848),i=n(8453);const r={id:"version-checking",title:"Version checking"},o=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},a=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default, ",(0,s.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,s.jsx)(t.code,{children:"jest"}),"/",(0,s.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,s.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\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_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Windows"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,s.jsxs)(t.p,{children:["As long as the environment variable ",(0,s.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,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/c6326909.efb42f1c.js b/assets/js/c6326909.efb42f1c.js deleted file mode 100644 index 3bedc8ccb5..0000000000 --- a/assets/js/c6326909.efb42f1c.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6121],{3023:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>p,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var s=n(4848),i=n(8453);const r={id:"version-checking",title:"Version checking"},o=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},d={},a=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default, ",(0,s.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,s.jsx)(t.code,{children:"jest"}),"/",(0,s.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,s.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\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_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Windows"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,s.jsxs)(t.p,{children:["As long as the environment variable ",(0,s.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,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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.831fd2bb.js b/assets/js/c8c88a41.831fd2bb.js new file mode 100644 index 0000000000..a5700b8e45 --- /dev/null +++ b/assets/js/c8c88a41.831fd2bb.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1907],{4080:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>d,frontMatter:()=>i,metadata:()=>p,toc:()=>c});var s=n(4848),o=n(8453);const i={id:"paths-mapping",title:"Paths mapping"},r=void 0,p={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["If you use ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,s.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,s.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,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,s.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,s.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,s.jsxs)(t.p,{children:["With the below config in your ",(0,s.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/c8c88a41.c4b416ec.js b/assets/js/c8c88a41.c4b416ec.js deleted file mode 100644 index fb14dac983..0000000000 --- a/assets/js/c8c88a41.c4b416ec.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1907],{4080:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>d,frontMatter:()=>i,metadata:()=>p,toc:()=>c});var s=n(4848),o=n(8453);const i={id:"paths-mapping",title:"Paths mapping"},r=void 0,p={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:!1,unlisted:!1,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:1726058855e3,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"}},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,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["If you use ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,s.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,s.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,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,s.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,s.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,s.jsxs)(t.p,{children:["With the below config in your ",(0,s.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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.0aa9087d.js b/assets/js/c8eced56.0aa9087d.js new file mode 100644 index 0000000000..657917bea9 --- /dev/null +++ b/assets/js/c8eced56.0aa9087d.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1344],{5190:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>d,contentTitle:()=>i,default:()=>p,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var n=s(4848),o=s(8453);const r={title:"useESM option"},i=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"useESM option"}},d={},a=[{value:"Examples",id:"examples",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["The ",(0,n.jsx)(t.code,{children:"useESM"})," option allows ",(0,n.jsx)(t.code,{children:"ts-jest"})," to transform codes to ESM syntax ",(0,n.jsx)(t.strong,{children:"if possible"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["The default value is ",(0,n.jsx)(t.strong,{children:"false"}),", ",(0,n.jsx)(t.code,{children:"ts-jest"})," will transform codes to ",(0,n.jsx)(t.code,{children:"CommonJS"})," syntax."]}),"\n",(0,n.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.pre,{children:(0,n.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,o.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(l,{...e})}):l(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/c8eced56.3fb01bcb.js b/assets/js/c8eced56.3fb01bcb.js deleted file mode 100644 index ce2f435a83..0000000000 --- a/assets/js/c8eced56.3fb01bcb.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1344],{5190:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>a,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>d});var n=s(4848),o=s(8453);const r={title:"useESM option"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"useESM option"}},a={},d=[{value:"Examples",id:"examples",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["The ",(0,n.jsx)(t.code,{children:"useESM"})," option allows ",(0,n.jsx)(t.code,{children:"ts-jest"})," to transform codes to ESM syntax ",(0,n.jsx)(t.strong,{children:"if possible"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["The default value is ",(0,n.jsx)(t.strong,{children:"false"}),", ",(0,n.jsx)(t.code,{children:"ts-jest"})," will transform codes to ",(0,n.jsx)(t.code,{children:"CommonJS"})," syntax."]}),"\n",(0,n.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.pre,{children:(0,n.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 u(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(l,{...e})}):l(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/ceaad8ca.46374681.js b/assets/js/ceaad8ca.46374681.js deleted file mode 100644 index 85f35c7f3f..0000000000 --- a/assets/js/ceaad8ca.46374681.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4681],{9954:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>d,contentTitle:()=>l,default:()=>h,frontMatter:()=>a,metadata:()=>c,toc:()=>j});var n=t(4848),i=t(8453),r=t(9489),o=t(7227);const a={title:"Diagnostics option"},l=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/diagnostics.md",tags:[],version:"current",lastUpdatedBy:"renovate[bot]",lastUpdatedAt:1726058855e3,frontMatter:{title:"Diagnostics option"}},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,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(s.p,{children:["The ",(0,n.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,n.jsxs)(s.p,{children:["If a diagnostic is not filtered out, ",(0,n.jsx)(s.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,n.jsx)(s.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,n.jsxs)(s.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,n.jsx)(s.code,{children:"diagnostics"})," option to ",(0,n.jsx)(s.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,n.jsx)(s.code,{children:"diagnostics"})," to ",(0,n.jsx)(s.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,n.jsx)(s.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,n.jsxs)(s.p,{children:["The ",(0,n.jsx)(s.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"warnOnly"})}),": If specified and ",(0,n.jsx)(s.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,n.jsx)(s.em,{children:"disabled"}),")."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,n.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,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.code,{children:"6059"}),": ",(0,n.jsx)(s.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.code,{children:"18002"}),": ",(0,n.jsx)(s.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.code,{children:"18003"}),": ",(0,n.jsx)(s.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,n.jsx)(s.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,n.jsx)(s.code,{children:"tsconfig"})," option ",(0,n.jsx)(s.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,n.jsx)(s.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,n.jsx)(s.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,n.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsx)(s.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,n.jsxs)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 "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,n.jsx)(s.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,n.jsx)(s.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,n.jsxs)(s.p,{children:["Assuming all your test files ends with ",(0,n.jsx)(s.code,{children:".spec.ts"})," or ",(0,n.jsx)(s.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,n.jsxs)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 "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,n.jsx)(s.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,n.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,n.jsx)(s.code,{children:"warnOnly"})," to ",(0,n.jsx)(s.code,{children:"true"}),":"]}),"\n",(0,n.jsxs)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 "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,n.jsx)(s.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,n.jsxs)(s.p,{children:["All TypeScript error codes can be found ",(0,n.jsx)(s.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,n.jsx)(s.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,n.jsxs)(s.ol,{children:["\n",(0,n.jsxs)(s.li,{children:["A single ",(0,n.jsx)(s.code,{children:"number"})," (example: ",(0,n.jsx)(s.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,n.jsxs)(s.li,{children:["A ",(0,n.jsx)(s.code,{children:"string"})," with a code (example ",(0,n.jsx)(s.code,{children:'"1009"'}),", ",(0,n.jsx)(s.code,{children:'"TS1009"'})," or ",(0,n.jsx)(s.code,{children:'"TS1009"'}),")"]}),"\n",(0,n.jsxs)(s.li,{children:["A ",(0,n.jsx)(s.code,{children:"string"})," with a list of the above (example: ",(0,n.jsx)(s.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,n.jsxs)(s.li,{children:["An ",(0,n.jsx)(s.code,{children:"array"})," of one or more from ",(0,n.jsx)(s.code,{children:"1"})," or ",(0,n.jsx)(s.code,{children:"3"})," (example: ",(0,n.jsx)(s.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,n.jsxs)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 "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,i.R)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.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/ceaad8ca.e567164b.js b/assets/js/ceaad8ca.e567164b.js new file mode 100644 index 0000000000..603e24f040 --- /dev/null +++ b/assets/js/ceaad8ca.e567164b.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4681],{9954:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>d,contentTitle:()=>l,default:()=>h,frontMatter:()=>a,metadata:()=>c,toc:()=>j});var n=t(4848),i=t(8453),r=t(9489),o=t(7227);const a={title:"Diagnostics option"},l=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/diagnostics.md",tags:[],version:"current",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Diagnostics option"}},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,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(s.p,{children:["The ",(0,n.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,n.jsxs)(s.p,{children:["If a diagnostic is not filtered out, ",(0,n.jsx)(s.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,n.jsx)(s.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,n.jsxs)(s.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,n.jsx)(s.code,{children:"diagnostics"})," option to ",(0,n.jsx)(s.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,n.jsx)(s.code,{children:"diagnostics"})," to ",(0,n.jsx)(s.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,n.jsx)(s.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,n.jsxs)(s.p,{children:["The ",(0,n.jsx)(s.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"warnOnly"})}),": If specified and ",(0,n.jsx)(s.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,n.jsx)(s.em,{children:"disabled"}),")."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,n.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,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.code,{children:"6059"}),": ",(0,n.jsx)(s.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.code,{children:"18002"}),": ",(0,n.jsx)(s.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.code,{children:"18003"}),": ",(0,n.jsx)(s.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,n.jsx)(s.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,n.jsx)(s.code,{children:"tsconfig"})," option ",(0,n.jsx)(s.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,n.jsx)(s.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,n.jsx)(s.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,n.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsx)(s.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,n.jsxs)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 "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,n.jsx)(s.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,n.jsx)(s.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,n.jsxs)(s.p,{children:["Assuming all your test files ends with ",(0,n.jsx)(s.code,{children:".spec.ts"})," or ",(0,n.jsx)(s.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,n.jsxs)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 "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,n.jsx)(s.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,n.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,n.jsx)(s.code,{children:"warnOnly"})," to ",(0,n.jsx)(s.code,{children:"true"}),":"]}),"\n",(0,n.jsxs)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 "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,n.jsx)(s.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,n.jsxs)(s.p,{children:["All TypeScript error codes can be found ",(0,n.jsx)(s.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,n.jsx)(s.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,n.jsxs)(s.ol,{children:["\n",(0,n.jsxs)(s.li,{children:["A single ",(0,n.jsx)(s.code,{children:"number"})," (example: ",(0,n.jsx)(s.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,n.jsxs)(s.li,{children:["A ",(0,n.jsx)(s.code,{children:"string"})," with a code (example ",(0,n.jsx)(s.code,{children:'"1009"'}),", ",(0,n.jsx)(s.code,{children:'"TS1009"'})," or ",(0,n.jsx)(s.code,{children:'"TS1009"'}),")"]}),"\n",(0,n.jsxs)(s.li,{children:["A ",(0,n.jsx)(s.code,{children:"string"})," with a list of the above (example: ",(0,n.jsx)(s.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,n.jsxs)(s.li,{children:["An ",(0,n.jsx)(s.code,{children:"array"})," of one or more from ",(0,n.jsx)(s.code,{children:"1"})," or ",(0,n.jsx)(s.code,{children:"3"})," (example: ",(0,n.jsx)(s.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,n.jsxs)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 "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,i.R)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.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.96432175.js b/assets/js/cf5c42a2.96432175.js deleted file mode 100644 index 2ac1e25fe2..0000000000 --- a/assets/js/cf5c42a2.96432175.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2659],{124:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>i,metadata:()=>a,toc:()=>d});var s=n(4848),o=n(8453);const i={title:"Stringify content option"},r=void 0,a={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Stringify content option"}},c={},d=[{value:"Example",id:"example",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["The ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,s.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,s.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,s.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,s.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,s.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,s.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,s.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,s.jsx)(t.code,{children:"transform"})," option pointing to ",(0,s.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,s.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsxs)(t.p,{children:["In the ",(0,s.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,s.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,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.pre,{children:(0,s.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,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(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/cf5c42a2.b2cacd27.js b/assets/js/cf5c42a2.b2cacd27.js new file mode 100644 index 0000000000..5d158e32cd --- /dev/null +++ b/assets/js/cf5c42a2.b2cacd27.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2659],{124:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>i,metadata:()=>a,toc:()=>d});var s=n(4848),o=n(8453);const i={title:"Stringify content option"},r=void 0,a={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Stringify content option"}},c={},d=[{value:"Example",id:"example",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["The ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,s.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,s.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,s.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,s.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,s.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,s.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,s.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,s.jsx)(t.code,{children:"transform"})," option pointing to ",(0,s.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,s.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsxs)(t.p,{children:["In the ",(0,s.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,s.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,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.pre,{children:(0,s.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,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(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.84411bbf.js b/assets/js/cffdf1e5.84411bbf.js new file mode 100644 index 0000000000..1606394e71 --- /dev/null +++ b/assets/js/cffdf1e5.84411bbf.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4631],{730:(t,e,o)=>{o.r(e),o.d(e,{assets:()=>c,contentTitle:()=>r,default:()=>a,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var s=o(4848),n=o(8453);const i={id:"troubleshooting",title:"Troubleshooting"},r=void 0,u={id:"guides/troubleshooting",title:"Troubleshooting",description:"You can check Jest troubleshooting guide or visit ts-jest [troubleshooting",source:"@site/versioned_docs/version-28.0/guides/troubleshooting.md",sourceDirName:"guides",slug:"/guides/troubleshooting",permalink:"/ts-jest/docs/28.0/guides/troubleshooting",draft:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/guides/troubleshooting.md",tags:[],version:"28.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},c={},d=[];function l(t){const e={a:"a",code:"code",p:"p",...(0,n.R)(),...t.components};return(0,s.jsxs)(e.p,{children:["You can check Jest ",(0,s.jsx)(e.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," or visit ",(0,s.jsx)(e.code,{children:"ts-jest"})," ",(0,s.jsx)(e.a,{href:"https://github.com/kulshekhar/ts-jest/blob/main/TROUBLESHOOTING.md",children:"troubleshooting\nguide"})]})}function a(t={}){const{wrapper:e}={...(0,n.R)(),...t.components};return e?(0,s.jsx)(e,{...t,children:(0,s.jsx)(l,{...t})}):l(t)}},8453:(t,e,o)=>{o.d(e,{R:()=>r,x:()=>u});var s=o(6540);const n={},i=s.createContext(n);function r(t){const e=s.useContext(i);return s.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function u(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(n):t.components||n:r(t.components),s.createElement(i.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/cffdf1e5.9060b2e6.js b/assets/js/cffdf1e5.9060b2e6.js deleted file mode 100644 index ced0485f3b..0000000000 --- a/assets/js/cffdf1e5.9060b2e6.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4631],{730:(t,e,o)=>{o.r(e),o.d(e,{assets:()=>c,contentTitle:()=>r,default:()=>a,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var s=o(4848),n=o(8453);const i={id:"troubleshooting",title:"Troubleshooting"},r=void 0,u={id:"guides/troubleshooting",title:"Troubleshooting",description:"You can check Jest troubleshooting guide or visit ts-jest [troubleshooting",source:"@site/versioned_docs/version-28.0/guides/troubleshooting.md",sourceDirName:"guides",slug:"/guides/troubleshooting",permalink:"/ts-jest/docs/28.0/guides/troubleshooting",draft:!1,unlisted:!1,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:1726058855e3,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"}},c={},d=[];function l(t){const e={a:"a",code:"code",p:"p",...(0,n.R)(),...t.components};return(0,s.jsxs)(e.p,{children:["You can check Jest ",(0,s.jsx)(e.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," or visit ",(0,s.jsx)(e.code,{children:"ts-jest"})," ",(0,s.jsx)(e.a,{href:"https://github.com/kulshekhar/ts-jest/blob/main/TROUBLESHOOTING.md",children:"troubleshooting\nguide"})]})}function a(t={}){const{wrapper:e}={...(0,n.R)(),...t.components};return e?(0,s.jsx)(e,{...t,children:(0,s.jsx)(l,{...t})}):l(t)}},8453:(t,e,o)=>{o.d(e,{R:()=>r,x:()=>u});var s=o(6540);const n={},i=s.createContext(n);function r(t){const e=s.useContext(i);return s.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function u(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(n):t.components||n:r(t.components),s.createElement(i.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/d0e697d4.4755e94b.js b/assets/js/d0e697d4.4755e94b.js new file mode 100644 index 0000000000..a6f5874d17 --- /dev/null +++ b/assets/js/d0e697d4.4755e94b.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6842],{3451:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>p,frontMatter:()=>i,metadata:()=>c,toc:()=>u});var s=o(4848),n=o(8453);const i={id:"using-with-monorepo",title:"Using with monorepo"},r=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},u=[];function a(e){const t={a:"a",code:"code",p:"p",...(0,n.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["To use ",(0,s.jsx)(t.code,{children:"ts-jest"})," in a project with monorepo structure, you'll need to use ",(0,s.jsx)(t.a,{href:"https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig",children:"Jest projects configuration"}),"."]}),"\n",(0,s.jsxs)(t.p,{children:["When using Jest ",(0,s.jsx)(t.code,{children:"projects"})," configuration, Jest will run ",(0,s.jsx)(t.code,{children:"ts-jest"})," against each project which is defined in the configuration."]})]})}function p(e={}){const{wrapper:t}={...(0,n.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/d0e697d4.9af7337f.js b/assets/js/d0e697d4.9af7337f.js deleted file mode 100644 index cbd8d625a4..0000000000 --- a/assets/js/d0e697d4.9af7337f.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6842],{3451:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>u,contentTitle:()=>r,default:()=>p,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var s=o(4848),n=o(8453);const i={id:"using-with-monorepo",title:"Using with monorepo"},r=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},u={},d=[];function a(e){const t={a:"a",code:"code",p:"p",...(0,n.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["To use ",(0,s.jsx)(t.code,{children:"ts-jest"})," in a project with monorepo structure, you'll need to use ",(0,s.jsx)(t.a,{href:"https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig",children:"Jest projects configuration"}),"."]}),"\n",(0,s.jsxs)(t.p,{children:["When using Jest ",(0,s.jsx)(t.code,{children:"projects"})," configuration, Jest will run ",(0,s.jsx)(t.code,{children:"ts-jest"})," against each project which is defined in the configuration."]})]})}function p(e={}){const{wrapper:t}={...(0,n.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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.01805ae1.js b/assets/js/d296dded.01805ae1.js new file mode 100644 index 0000000000..00d94f2616 --- /dev/null +++ b/assets/js/d296dded.01805ae1.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8563],{1942:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>p,frontMatter:()=>i,metadata:()=>c,toc:()=>u});var s=o(4848),n=o(8453);const i={id:"using-with-monorepo",title:"Using with monorepo"},r=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},u=[];function a(e){const t={a:"a",code:"code",p:"p",...(0,n.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["To use ",(0,s.jsx)(t.code,{children:"ts-jest"})," in a project with monorepo structure, you'll need to use ",(0,s.jsx)(t.a,{href:"https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig",children:"Jest projects configuration"}),"."]}),"\n",(0,s.jsxs)(t.p,{children:["When using Jest ",(0,s.jsx)(t.code,{children:"projects"})," configuration, Jest will run ",(0,s.jsx)(t.code,{children:"ts-jest"})," against each project which is defined in the configuration."]})]})}function p(e={}){const{wrapper:t}={...(0,n.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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.d24c2186.js b/assets/js/d296dded.d24c2186.js deleted file mode 100644 index 7dd3893430..0000000000 --- a/assets/js/d296dded.d24c2186.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8563],{1942:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>u,contentTitle:()=>r,default:()=>p,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var s=o(4848),n=o(8453);const i={id:"using-with-monorepo",title:"Using with monorepo"},r=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},u={},d=[];function a(e){const t={a:"a",code:"code",p:"p",...(0,n.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["To use ",(0,s.jsx)(t.code,{children:"ts-jest"})," in a project with monorepo structure, you'll need to use ",(0,s.jsx)(t.a,{href:"https://jestjs.io/docs/next/configuration#projects-arraystring--projectconfig",children:"Jest projects configuration"}),"."]}),"\n",(0,s.jsxs)(t.p,{children:["When using Jest ",(0,s.jsx)(t.code,{children:"projects"})," configuration, Jest will run ",(0,s.jsx)(t.code,{children:"ts-jest"})," against each project which is defined in the configuration."]})]})}function p(e={}){const{wrapper:t}={...(0,n.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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.fd3e89c7.js b/assets/js/d3b43630.fd3e89c7.js new file mode 100644 index 0000000000..cfc86d762a --- /dev/null +++ b/assets/js/d3b43630.fd3e89c7.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9592],{1920:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>a,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>d});var t=n(4848),o=n(8453);const r={id:"mock-es6-class",title:"Mock ES6 class"},i=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},a={},d=[];function l(e){const s={code:"code",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(s.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,t.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,t.jsx)(s.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.p,{children:"You will get the error"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,t.jsxs)(s.p,{children:["because ",(0,t.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,t.jsx)(s.pre,{children:(0,t.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,t.jsxs)(s.p,{children:["For named imports, like ",(0,t.jsx)(s.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,t.jsx)(s.code,{children:"default"})," with imported module name, ",(0,t.jsx)(s.code,{children:"OAuth2"})," in this example:"]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,o.R)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.jsx)(l,{...e})}):l(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.078838ad.js b/assets/js/d4836a8e.078838ad.js deleted file mode 100644 index 8fa8989845..0000000000 --- a/assets/js/d4836a8e.078838ad.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[106],{8125:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>l,default:()=>h,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var n=s(4848),r=s(8453),o=s(9489),a=s(7227);const i={id:"esm-support",title:"ESM Support"},l=void 0,c={id:"guides/esm-support",title:"ESM Support",description:"To use ts-jest with ESM support:",source:"@site/docs/guides/esm-support.md",sourceDirName:"guides",slug:"/guides/esm-support",permalink:"/ts-jest/docs/next/guides/esm-support",draft:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/guides/esm-support.md",tags:[],version:"current",lastUpdatedBy:"renovate[bot]",lastUpdatedAt:1726058855e3,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"}},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 t={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,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["To use ",(0,n.jsx)(t.code,{children:"ts-jest"})," with ESM support:"]}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:["Check ",(0,n.jsx)(t.a,{href:"https://jestjs.io/docs/en/ecmascript-modules",children:"ESM Jest documentation"}),"."]}),"\n",(0,n.jsxs)(t.li,{children:["Enable ",(0,n.jsx)(t.a,{href:"../getting-started/options/useESM",children:"useESM"})," ",(0,n.jsx)(t.code,{children:"true"})," for ",(0,n.jsx)(t.code,{children:"ts-jest"})," config."]}),"\n",(0,n.jsxs)(t.li,{children:["Include ",(0,n.jsx)(t.code,{children:".ts"})," in ",(0,n.jsx)(t.a,{href:"https://jestjs.io/docs/en/next/configuration#extensionstotreatasesm-arraystring",children:"extensionsToTreatAsEsm"})," Jest config option."]}),"\n",(0,n.jsxs)(t.li,{children:["Ensure that ",(0,n.jsx)(t.code,{children:"tsconfig"})," has ",(0,n.jsx)(t.code,{children:"module"})," with value for ESM, e.g. ",(0,n.jsx)(t.code,{children:"ES2015"})," or ",(0,n.jsx)(t.code,{children:"ES2020"})," etc..."]}),"\n"]}),"\n",(0,n.jsx)(t.h3,{id:"esm-presets",children:"ESM presets"}),"\n",(0,n.jsxs)(t.p,{children:["There are also ",(0,n.jsx)(t.a,{href:"/ts-jest/docs/next/getting-started/presets",children:"3 presets"})," to work with ESM."]}),"\n",(0,n.jsx)(t.admonition,{type:"caution",children:(0,n.jsxs)(t.p,{children:["If you are using custom ",(0,n.jsx)(t.code,{children:"transform"})," config, please remove ",(0,n.jsx)(t.code,{children:"preset"})," from your Jest config to avoid issues that Jest doesn't transform files correctly."]})}),"\n",(0,n.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsx)(t.h4,{id:"manual-configuration",children:"Manual configuration"}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.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,n.jsx)(a.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.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,n.jsx)(t.h4,{id:"use-esm-presets",children:"Use ESM presets"}),"\n",(0,n.jsx)(t.admonition,{type:"important",children:(0,n.jsxs)(t.p,{children:["Starting from ",(0,n.jsx)(t.strong,{children:"v28.0.0"}),", ",(0,n.jsx)(t.code,{children:"ts-jest"})," will gradually switch to ",(0,n.jsx)(t.code,{children:"esbuild"}),"/",(0,n.jsx)(t.code,{children:"swc"})," to transform ",(0,n.jsx)(t.code,{children:"ts"})," to ",(0,n.jsx)(t.code,{children:"js"}),". To make the transition smoothly, we introduce ",(0,n.jsx)(t.code,{children:"legacy"})," presets as a fallback when the new codes don't work yet."]})}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\nconst { createDefaultEsmPreset } = require('ts-jest')\n\nconst defaultEsmPreset = createDefaultEsmPreset()\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n ...defaultEsmPreset,\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n}\n"})})}),(0,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport { createDefaultEsmPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst defaultEsmPreset = createDefaultEsmPreset()\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n ...defaultEsmPreset,\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n}\n\nexport default jestConfig\n"})})})]}),"\n",(0,n.jsxs)(t.h4,{id:"support-mts-extension",children:["Support ",(0,n.jsx)(t.code,{children:".mts"})," extension"]}),"\n",(0,n.jsxs)(t.p,{children:["To work with ",(0,n.jsx)(t.code,{children:".mts"})," extension, besides the requirement to run Jest and ",(0,n.jsx)(t.code,{children:"ts-jest"})," in ESM mode, there are a few extra requirements to be met:"]}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"package.json"})," should contain ",(0,n.jsx)(t.code,{children:'"type": "module"'})]}),"\n",(0,n.jsxs)(t.li,{children:["A custom Jest resolver to resolve ",(0,n.jsx)(t.code,{children:".mjs"})," extension, see our simple one at ",(0,n.jsx)(t.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,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"tsconfig.json"})," should at least contain these following options"]}),"\n"]}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-json",children:'// tsconfig.spec.json\n{\n "compilerOptions": {\n "module": "ESNext", // or ES2015/ES2020/ES2022\n "target": "ESNext",\n "esModuleInterop": true\n }\n}\n'})})]})}function h(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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:()=>S});var n=s(6540),r=s(4164),o=s(4245),a=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 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 h(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 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,l.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 j(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,o=p(e),[a,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(!h({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]=m({queryString:s,groupId:r}),[j,x]=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??j;return h({value:e,tabValues:o})?e:null})();(0,i.A)((()=>{f&&l(f)}),[f]);return{selectedValue:a,selectValue:(0,n.useCallback)((e=>{if(!h({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=s(1062);const f={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=s(4848);function b(e){let{className:t,block:s,selectedValue:n,selectValue:a,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.a_)(),u=e=>{const t=e.currentTarget,s=l.indexOf(t),r=i[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=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:o}=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,...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,g.jsx)("div",{className:"margin-top--md",children:a.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==o})))})}function E(e){const t=j(e);return(0,g.jsxs)("div",{className:(0,r.A)("tabs-container",f.tabList),children:[(0,g.jsx)(b,{...t,...e}),(0,g.jsx)(v,{...t,...e})]})}function S(e){const t=(0,x.A)();return(0,g.jsx)(E,{...e,children:d(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>a,x:()=>i});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 i(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/d4836a8e.bfd0beed.js b/assets/js/d4836a8e.bfd0beed.js new file mode 100644 index 0000000000..e6c7d8894f --- /dev/null +++ b/assets/js/d4836a8e.bfd0beed.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[106],{8125:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>l,default:()=>h,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var n=s(4848),r=s(8453),o=s(9489),a=s(7227);const i={id:"esm-support",title:"ESM Support"},l=void 0,c={id:"guides/esm-support",title:"ESM Support",description:"To use ts-jest with ESM support:",source:"@site/docs/guides/esm-support.md",sourceDirName:"guides",slug:"/guides/esm-support",permalink:"/ts-jest/docs/next/guides/esm-support",draft:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/guides/esm-support.md",tags:[],version:"current",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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 t={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,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["To use ",(0,n.jsx)(t.code,{children:"ts-jest"})," with ESM support:"]}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:["Check ",(0,n.jsx)(t.a,{href:"https://jestjs.io/docs/en/ecmascript-modules",children:"ESM Jest documentation"}),"."]}),"\n",(0,n.jsxs)(t.li,{children:["Enable ",(0,n.jsx)(t.a,{href:"../getting-started/options/useESM",children:"useESM"})," ",(0,n.jsx)(t.code,{children:"true"})," for ",(0,n.jsx)(t.code,{children:"ts-jest"})," config."]}),"\n",(0,n.jsxs)(t.li,{children:["Include ",(0,n.jsx)(t.code,{children:".ts"})," in ",(0,n.jsx)(t.a,{href:"https://jestjs.io/docs/en/next/configuration#extensionstotreatasesm-arraystring",children:"extensionsToTreatAsEsm"})," Jest config option."]}),"\n",(0,n.jsxs)(t.li,{children:["Ensure that ",(0,n.jsx)(t.code,{children:"tsconfig"})," has ",(0,n.jsx)(t.code,{children:"module"})," with value for ESM, e.g. ",(0,n.jsx)(t.code,{children:"ES2015"})," or ",(0,n.jsx)(t.code,{children:"ES2020"})," etc..."]}),"\n"]}),"\n",(0,n.jsx)(t.h3,{id:"esm-presets",children:"ESM presets"}),"\n",(0,n.jsxs)(t.p,{children:["There are also ",(0,n.jsx)(t.a,{href:"/ts-jest/docs/next/getting-started/presets",children:"3 presets"})," to work with ESM."]}),"\n",(0,n.jsx)(t.admonition,{type:"caution",children:(0,n.jsxs)(t.p,{children:["If you are using custom ",(0,n.jsx)(t.code,{children:"transform"})," config, please remove ",(0,n.jsx)(t.code,{children:"preset"})," from your Jest config to avoid issues that Jest doesn't transform files correctly."]})}),"\n",(0,n.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsx)(t.h4,{id:"manual-configuration",children:"Manual configuration"}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.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,n.jsx)(a.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.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,n.jsx)(t.h4,{id:"use-esm-presets",children:"Use ESM presets"}),"\n",(0,n.jsx)(t.admonition,{type:"important",children:(0,n.jsxs)(t.p,{children:["Starting from ",(0,n.jsx)(t.strong,{children:"v28.0.0"}),", ",(0,n.jsx)(t.code,{children:"ts-jest"})," will gradually switch to ",(0,n.jsx)(t.code,{children:"esbuild"}),"/",(0,n.jsx)(t.code,{children:"swc"})," to transform ",(0,n.jsx)(t.code,{children:"ts"})," to ",(0,n.jsx)(t.code,{children:"js"}),". To make the transition smoothly, we introduce ",(0,n.jsx)(t.code,{children:"legacy"})," presets as a fallback when the new codes don't work yet."]})}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-js",metastring:"tab",children:"// jest.config.js\nconst { createDefaultEsmPreset } = require('ts-jest')\n\nconst defaultEsmPreset = createDefaultEsmPreset()\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n ...defaultEsmPreset,\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n}\n"})})}),(0,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-ts",metastring:"tab",children:"// jest.config.ts\nimport { createDefaultEsmPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst defaultEsmPreset = createDefaultEsmPreset()\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n ...defaultEsmPreset,\n moduleNameMapper: {\n '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n },\n}\n\nexport default jestConfig\n"})})})]}),"\n",(0,n.jsxs)(t.h4,{id:"support-mts-extension",children:["Support ",(0,n.jsx)(t.code,{children:".mts"})," extension"]}),"\n",(0,n.jsxs)(t.p,{children:["To work with ",(0,n.jsx)(t.code,{children:".mts"})," extension, besides the requirement to run Jest and ",(0,n.jsx)(t.code,{children:"ts-jest"})," in ESM mode, there are a few extra requirements to be met:"]}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"package.json"})," should contain ",(0,n.jsx)(t.code,{children:'"type": "module"'})]}),"\n",(0,n.jsxs)(t.li,{children:["A custom Jest resolver to resolve ",(0,n.jsx)(t.code,{children:".mjs"})," extension, see our simple one at ",(0,n.jsx)(t.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,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"tsconfig.json"})," should at least contain these following options"]}),"\n"]}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-json",children:'// tsconfig.spec.json\n{\n "compilerOptions": {\n "module": "ESNext", // or ES2015/ES2020/ES2022\n "target": "ESNext",\n "esModuleInterop": true\n }\n}\n'})})]})}function h(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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:()=>S});var n=s(6540),r=s(4164),o=s(4245),a=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 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 h(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 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,l.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 j(e){const{defaultValue:t,queryString:s=!1,groupId:r}=e,o=p(e),[a,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(!h({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]=m({queryString:s,groupId:r}),[j,x]=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??j;return h({value:e,tabValues:o})?e:null})();(0,i.A)((()=>{f&&l(f)}),[f]);return{selectedValue:a,selectValue:(0,n.useCallback)((e=>{if(!h({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=s(1062);const f={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=s(4848);function b(e){let{className:t,block:s,selectedValue:n,selectValue:a,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.a_)(),u=e=>{const t=e.currentTarget,s=l.indexOf(t),r=i[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=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:o}=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,...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,g.jsx)("div",{className:"margin-top--md",children:a.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==o})))})}function E(e){const t=j(e);return(0,g.jsxs)("div",{className:(0,r.A)("tabs-container",f.tabList),children:[(0,g.jsx)(b,{...t,...e}),(0,g.jsx)(v,{...t,...e})]})}function S(e){const t=(0,x.A)();return(0,g.jsx)(E,{...e,children:d(e.children)},String(t))}},8453:(e,t,s)=>{s.d(t,{R:()=>a,x:()=>i});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 i(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/d4a6dd78.02577404.js b/assets/js/d4a6dd78.02577404.js deleted file mode 100644 index 42de547120..0000000000 --- a/assets/js/d4a6dd78.02577404.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1163],{7433:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>r,contentTitle:()=>i,default:()=>b,frontMatter:()=>l,metadata:()=>a,toc:()=>c});var t=s(4848),o=s(8453);const l={title:"Babel Config option"},i=void 0,a={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Babel Config option"}},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,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.code,{children:"ts-jest"})," by default does ",(0,t.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,t.jsx)(n.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,t.jsxs)(n.p,{children:["The option is ",(0,t.jsx)(n.code,{children:"babelConfig"})," and it works pretty much as the ",(0,t.jsx)(n.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"true"}),": enables Babel processing. ",(0,t.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,t.jsx)(n.code,{children:".babelrc"}),", ",(0,t.jsx)(n.code,{children:".babelrc.js"}),", ",(0,t.jsx)(n.code,{children:"babel.config.js"})," file or a ",(0,t.jsx)(n.code,{children:"babel"})," section in the ",(0,t.jsx)(n.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,t.jsx)(n.code,{children:"babel-jest"})," processor."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"{ ... }"}),": inline ",(0,t.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,t.jsx)(n.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,t.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,t.jsxs)(n.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,t.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.pre,{children:(0,t.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,t.jsxs)(n.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,t.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,t.jsxs)(n.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,t.jsx)(n.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.p,{children:"or"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,t.jsxs)(n.p,{children:["Refer to the ",(0,t.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.pre,{children:(0,t.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,o.R)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(d,{...e})}):d(e)}},8453:(e,n,s)=>{s.d(n,{R:()=>i,x:()=>a});var t=s(6540);const o={},l=t.createContext(o);function i(e){const n=t.useContext(l);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),t.createElement(l.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/d4a6dd78.5d413484.js b/assets/js/d4a6dd78.5d413484.js new file mode 100644 index 0000000000..e8ab533eb4 --- /dev/null +++ b/assets/js/d4a6dd78.5d413484.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1163],{7433:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>r,contentTitle:()=>i,default:()=>b,frontMatter:()=>l,metadata:()=>a,toc:()=>c});var t=s(4848),o=s(8453);const l={title:"Babel Config option"},i=void 0,a={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Babel Config option"}},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,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.code,{children:"ts-jest"})," by default does ",(0,t.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,t.jsx)(n.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,t.jsxs)(n.p,{children:["The option is ",(0,t.jsx)(n.code,{children:"babelConfig"})," and it works pretty much as the ",(0,t.jsx)(n.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"true"}),": enables Babel processing. ",(0,t.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,t.jsx)(n.code,{children:".babelrc"}),", ",(0,t.jsx)(n.code,{children:".babelrc.js"}),", ",(0,t.jsx)(n.code,{children:"babel.config.js"})," file or a ",(0,t.jsx)(n.code,{children:"babel"})," section in the ",(0,t.jsx)(n.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,t.jsx)(n.code,{children:"babel-jest"})," processor."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"{ ... }"}),": inline ",(0,t.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,t.jsx)(n.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,t.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,t.jsxs)(n.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,t.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.pre,{children:(0,t.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,t.jsxs)(n.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,t.jsx)(n.code,{children:"babelrc"})," file"]}),"\n",(0,t.jsxs)(n.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,t.jsx)(n.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.p,{children:"or"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,t.jsxs)(n.p,{children:["Refer to the ",(0,t.jsx)(n.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.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,t.jsx)(n.pre,{children:(0,t.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,o.R)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(d,{...e})}):d(e)}},8453:(e,n,s)=>{s.d(n,{R:()=>i,x:()=>a});var t=s(6540);const o={},l=t.createContext(o);function i(e){const n=t.useContext(l);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),t.createElement(l.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/d6f9473b.2be18a88.js b/assets/js/d6f9473b.2be18a88.js new file mode 100644 index 0000000000..3ebabf6f31 --- /dev/null +++ b/assets/js/d6f9473b.2be18a88.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9314],{904:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>a,default:()=>p,frontMatter:()=>o,metadata:()=>i,toc:()=>l});var r=n(4848),t=n(8453);const o={title:"AST transformers option"},a=void 0,i={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"AST transformers option"}},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,t.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:'// 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,r.jsx)(s.h3,{id:"public-transformers",children:"Public transformers"}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.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,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"path-mapping"})," convert alias import/export to relative import/export path base on ",(0,r.jsx)(s.code,{children:"paths"})," in ",(0,r.jsx)(s.code,{children:"tsconfig"}),".\nThis transformer works similar to ",(0,r.jsx)(s.code,{children:"moduleNameMapper"})," in ",(0,r.jsx)(s.code,{children:"jest.config.js"}),". When using this transformer, one might not need\n",(0,r.jsx)(s.code,{children:"moduleNameMapper"})," anymore."]}),"\n"]}),"\n",(0,r.jsx)(s.admonition,{type:"warning",children:(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.code,{children:"path-mapping"})," AST transformer is now deprecated. Please should use an alternative one like ",(0,r.jsx)(s.a,{href:"https://github.com/LeDDGroup/typescript-transform-paths",children:"https://github.com/LeDDGroup/typescript-transform-paths"})," instead."]})}),"\n",(0,r.jsx)(s.h4,{id:"example-of-opt-in-transformers",children:"Example of opt-in 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: ['ts-jest/dist/transformers/path-mapping'],\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": ["ts-jest/dist/transformers/path-mapping"]\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 p(e={}){const{wrapper:s}={...(0,t.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:()=>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/d6f9473b.e7623284.js b/assets/js/d6f9473b.e7623284.js deleted file mode 100644 index 6037dcf448..0000000000 --- a/assets/js/d6f9473b.e7623284.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9314],{904:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>a,default:()=>p,frontMatter:()=>o,metadata:()=>i,toc:()=>l});var r=n(4848),t=n(8453);const o={title:"AST transformers option"},a=void 0,i={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"AST transformers option"}},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,t.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:'// 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,r.jsx)(s.h3,{id:"public-transformers",children:"Public transformers"}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.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,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"path-mapping"})," convert alias import/export to relative import/export path base on ",(0,r.jsx)(s.code,{children:"paths"})," in ",(0,r.jsx)(s.code,{children:"tsconfig"}),".\nThis transformer works similar to ",(0,r.jsx)(s.code,{children:"moduleNameMapper"})," in ",(0,r.jsx)(s.code,{children:"jest.config.js"}),". When using this transformer, one might not need\n",(0,r.jsx)(s.code,{children:"moduleNameMapper"})," anymore."]}),"\n"]}),"\n",(0,r.jsx)(s.admonition,{type:"warning",children:(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.code,{children:"path-mapping"})," AST transformer is now deprecated. Please should use an alternative one like ",(0,r.jsx)(s.a,{href:"https://github.com/LeDDGroup/typescript-transform-paths",children:"https://github.com/LeDDGroup/typescript-transform-paths"})," instead."]})}),"\n",(0,r.jsx)(s.h4,{id:"example-of-opt-in-transformers",children:"Example of opt-in 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: ['ts-jest/dist/transformers/path-mapping'],\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": ["ts-jest/dist/transformers/path-mapping"]\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 p(e={}){const{wrapper:s}={...(0,t.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:()=>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.3630a968.js b/assets/js/d8357ecf.3630a968.js new file mode 100644 index 0000000000..538e47b50a --- /dev/null +++ b/assets/js/d8357ecf.3630a968.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5580],{1059:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>a,frontMatter:()=>i,metadata:()=>l,toc:()=>p});var n=o(4848),s=o(8453);const i={title:"Compiler option"},r=void 0,l={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Compiler option"}},c={},p=[{value:"Example",id:"example",level:3}];function d(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["The ",(0,n.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,n.jsxs)(t.p,{children:["The default value is ",(0,n.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,n.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,n.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,n.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,n.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,n.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.pre,{children:(0,n.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,s.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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/d8357ecf.853f3df2.js b/assets/js/d8357ecf.853f3df2.js deleted file mode 100644 index 0ca9313b4a..0000000000 --- a/assets/js/d8357ecf.853f3df2.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5580],{1059:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>a,frontMatter:()=>i,metadata:()=>l,toc:()=>p});var n=o(4848),s=o(8453);const i={title:"Compiler option"},r=void 0,l={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Compiler option"}},c={},p=[{value:"Example",id:"example",level:3}];function d(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["The ",(0,n.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,n.jsxs)(t.p,{children:["The default value is ",(0,n.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,n.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,n.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,n.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,n.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,n.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.pre,{children:(0,n.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,s.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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.4a639865.js b/assets/js/d9f7da4b.4a639865.js deleted file mode 100644 index 43d9b2c827..0000000000 --- a/assets/js/d9f7da4b.4a639865.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6556],{2031:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>p,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var s=n(4848),i=n(8453);const r={id:"version-checking",title:"Version checking"},o=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},d={},a=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default, ",(0,s.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,s.jsx)(t.code,{children:"jest"}),"/",(0,s.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,s.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\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_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Windows"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,s.jsxs)(t.p,{children:["As long as the environment variable ",(0,s.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,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/d9f7da4b.aa77f940.js b/assets/js/d9f7da4b.aa77f940.js new file mode 100644 index 0000000000..ba87bca5dd --- /dev/null +++ b/assets/js/d9f7da4b.aa77f940.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6556],{2031:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>p,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var s=n(4848),i=n(8453);const r={id:"version-checking",title:"Version checking"},o=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},a=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default, ",(0,s.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,s.jsx)(t.code,{children:"jest"}),"/",(0,s.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,s.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\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_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Windows"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,s.jsxs)(t.p,{children:["As long as the environment variable ",(0,s.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,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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.1896ba19.js b/assets/js/da431c38.1896ba19.js new file mode 100644 index 0000000000..d2029c51b9 --- /dev/null +++ b/assets/js/da431c38.1896ba19.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1952],{5358:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>o,default:()=>p,frontMatter:()=>l,metadata:()=>c,toc:()=>d});var s=n(4848),r=n(8453),a=n(9489),i=n(7227);const l={id:"installation",title:"Installation"},o=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/getting-started/installation.md",tags:[],version:"29.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,s.jsxs)(t.p,{children:["You can install ",(0,s.jsx)(t.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,s.jsxs)(a.A,{groupId:"npm2yarn",children:[(0,s.jsx)(i.A,{value:"npm",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})})}),(0,s.jsx)(i.A,{value:"yarn",label:"Yarn",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})})}),(0,s.jsx)(i.A,{value:"pnpm",label:"pnpm",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"pnpm add --save-dev jest typescript ts-jest @types/jest\n"})})})]}),"\n",(0,s.jsx)(t.admonition,{type:"tip",children:(0,s.jsxs)(t.p,{children:["Tip: If you get an error with the following ",(0,s.jsx)(t.code,{children:"npm"})," commands such as ",(0,s.jsx)(t.code,{children:"npx: command not found"}),", you can replace ",(0,s.jsx)(t.code,{children:"npx XXX"})," with ",(0,s.jsx)(t.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,s.jsx)(t.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,s.jsx)(t.h4,{id:"creating",children:"Creating"}),"\n",(0,s.jsxs)(t.p,{children:["By default, Jest can run without any config files, but it will not compile ",(0,s.jsx)(t.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,s.jsx)(t.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,s.jsx)(t.code,{children:"ts-jest"})," preset."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,s.jsxs)(a.A,{groupId:"code-examples",children:[(0,s.jsx)(i.A,{value:"npm",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-npm",metastring:"tab",children:"npx ts-jest config:init\n"})})}),(0,s.jsx)(i.A,{value:"Yarn",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-Yarn",metastring:"tab",children:"yarn ts-jest config:init\n"})})})]}),"\n",(0,s.jsxs)(t.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,s.jsx)(t.code,{children:".ts"})," files correctly."]}),"\n",(0,s.jsxs)(t.p,{children:["You can also use the ",(0,s.jsx)(t.code,{children:"jest --init"})," command (prefixed with either ",(0,s.jsx)(t.code,{children:"npx"})," or ",(0,s.jsx)(t.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,s.jsx)(t.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,s.jsx)(t.code,{children:'preset: "ts-jest"'})," to the ",(0,s.jsx)(t.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,s.jsx)(t.h4,{id:"customizing",children:"Customizing"}),"\n",(0,s.jsxs)(t.p,{children:["For customizing jest, please follow their ",(0,s.jsx)(t.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," specific options can be found ",(0,s.jsx)(t.a,{href:"options",children:"here"}),"."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/da431c38.5a7485a0.js b/assets/js/da431c38.5a7485a0.js deleted file mode 100644 index 68f68cb030..0000000000 --- a/assets/js/da431c38.5a7485a0.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1952],{5358:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>o,default:()=>p,frontMatter:()=>l,metadata:()=>c,toc:()=>d});var s=n(4848),r=n(8453),a=n(9489),i=n(7227);const l={id:"installation",title:"Installation"},o=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},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,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,s.jsxs)(t.p,{children:["You can install ",(0,s.jsx)(t.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,s.jsxs)(a.A,{groupId:"npm2yarn",children:[(0,s.jsx)(i.A,{value:"npm",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})})}),(0,s.jsx)(i.A,{value:"yarn",label:"Yarn",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})})}),(0,s.jsx)(i.A,{value:"pnpm",label:"pnpm",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"pnpm add --save-dev jest typescript ts-jest @types/jest\n"})})})]}),"\n",(0,s.jsx)(t.admonition,{type:"tip",children:(0,s.jsxs)(t.p,{children:["Tip: If you get an error with the following ",(0,s.jsx)(t.code,{children:"npm"})," commands such as ",(0,s.jsx)(t.code,{children:"npx: command not found"}),", you can replace ",(0,s.jsx)(t.code,{children:"npx XXX"})," with ",(0,s.jsx)(t.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,s.jsx)(t.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,s.jsx)(t.h4,{id:"creating",children:"Creating"}),"\n",(0,s.jsxs)(t.p,{children:["By default, Jest can run without any config files, but it will not compile ",(0,s.jsx)(t.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,s.jsx)(t.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,s.jsx)(t.code,{children:"ts-jest"})," preset."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,s.jsxs)(a.A,{groupId:"code-examples",children:[(0,s.jsx)(i.A,{value:"npm",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-npm",metastring:"tab",children:"npx ts-jest config:init\n"})})}),(0,s.jsx)(i.A,{value:"Yarn",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-Yarn",metastring:"tab",children:"yarn ts-jest config:init\n"})})})]}),"\n",(0,s.jsxs)(t.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,s.jsx)(t.code,{children:".ts"})," files correctly."]}),"\n",(0,s.jsxs)(t.p,{children:["You can also use the ",(0,s.jsx)(t.code,{children:"jest --init"})," command (prefixed with either ",(0,s.jsx)(t.code,{children:"npx"})," or ",(0,s.jsx)(t.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,s.jsx)(t.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,s.jsx)(t.code,{children:'preset: "ts-jest"'})," to the ",(0,s.jsx)(t.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,s.jsx)(t.h4,{id:"customizing",children:"Customizing"}),"\n",(0,s.jsxs)(t.p,{children:["For customizing jest, please follow their ",(0,s.jsx)(t.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," specific options can be found ",(0,s.jsx)(t.a,{href:"options",children:"here"}),"."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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.2aad4fed.js b/assets/js/dabdf990.2aad4fed.js deleted file mode 100644 index d8b4c9555e..0000000000 --- a/assets/js/dabdf990.2aad4fed.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3808],{5365:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>a,frontMatter:()=>i,metadata:()=>l,toc:()=>p});var n=o(4848),s=o(8453);const i={title:"Compiler option"},r=void 0,l={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Compiler option"}},c={},p=[{value:"Example",id:"example",level:3}];function d(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["The ",(0,n.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,n.jsxs)(t.p,{children:["The default value is ",(0,n.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,n.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,n.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,n.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,n.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,n.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.pre,{children:(0,n.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,s.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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/dabdf990.95167e86.js b/assets/js/dabdf990.95167e86.js new file mode 100644 index 0000000000..1c9cb7bbb6 --- /dev/null +++ b/assets/js/dabdf990.95167e86.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3808],{5365:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>a,frontMatter:()=>i,metadata:()=>l,toc:()=>p});var n=o(4848),s=o(8453);const i={title:"Compiler option"},r=void 0,l={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Compiler option"}},c={},p=[{value:"Example",id:"example",level:3}];function d(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["The ",(0,n.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,n.jsxs)(t.p,{children:["The default value is ",(0,n.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,n.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,n.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,n.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,n.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,n.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.pre,{children:(0,n.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,s.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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/d3b43630.e1927d13.js b/assets/js/db49ae54.e5fc54dc.js similarity index 69% rename from assets/js/d3b43630.e1927d13.js rename to assets/js/db49ae54.e5fc54dc.js index b65ee79805..7defe04ae9 100644 --- a/assets/js/d3b43630.e1927d13.js +++ b/assets/js/db49ae54.e5fc54dc.js @@ -1 +1 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9592],{1920:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>a,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>l});var t=n(4848),o=n(8453);const r={id:"mock-es6-class",title:"Mock ES6 class"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},a={},l=[];function d(e){const s={code:"code",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(s.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,t.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,t.jsx)(s.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.p,{children:"You will get the error"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,t.jsxs)(s.p,{children:["because ",(0,t.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,t.jsx)(s.pre,{children:(0,t.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,t.jsxs)(s.p,{children:["For named imports, like ",(0,t.jsx)(s.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,t.jsx)(s.code,{children:"default"})," with imported module name, ",(0,t.jsx)(s.code,{children:"OAuth2"})," in this example:"]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,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:()=>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],{71:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>a,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>d});var t=n(4848),o=n(8453);const r={id:"mock-es6-class",title:"Mock ES6 class"},i=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},a={},d=[];function l(e){const s={code:"code",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(s.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,t.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,t.jsx)(s.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.p,{children:"You will get the error"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,t.jsxs)(s.p,{children:["because ",(0,t.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,t.jsx)(s.pre,{children:(0,t.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,t.jsxs)(s.p,{children:["For named imports, like ",(0,t.jsx)(s.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,t.jsx)(s.code,{children:"default"})," with imported module name, ",(0,t.jsx)(s.code,{children:"OAuth2"})," in this example:"]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,o.R)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.jsx)(l,{...e})}):l(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/db49ae54.e880f12f.js b/assets/js/db49ae54.e880f12f.js deleted file mode 100644 index 3168012adb..0000000000 --- a/assets/js/db49ae54.e880f12f.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9197],{71:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>a,contentTitle:()=>i,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>l});var t=n(4848),o=n(8453);const r={id:"mock-es6-class",title:"Mock ES6 class"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},a={},l=[];function d(e){const s={code:"code",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(s.p,{children:["TypeScript is transpiling your ts file and your module is likely being imported using ES2015s import.\n",(0,t.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,t.jsx)(s.code,{children:"new soundPlayer.default()"}),". However if you are mocking the class as suggested by the documentation."]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.p,{children:"You will get the error"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{children:"TypeError: sound_player_1.default is not a constructor\n"})}),"\n",(0,t.jsxs)(s.p,{children:["because ",(0,t.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,t.jsx)(s.pre,{children:(0,t.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,t.jsxs)(s.p,{children:["For named imports, like ",(0,t.jsx)(s.code,{children:"import { OAuth2 } from './oauth'"}),", replace ",(0,t.jsx)(s.code,{children:"default"})," with imported module name, ",(0,t.jsx)(s.code,{children:"OAuth2"})," in this example:"]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,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:()=>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.4f4d283a.js b/assets/js/db795cf2.4f4d283a.js deleted file mode 100644 index 7d6680803e..0000000000 --- a/assets/js/db795cf2.4f4d283a.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5369],{4442:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>l,frontMatter:()=>i,metadata:()=>c,toc:()=>g});var s=n(4848),o=n(8453);const i={id:"debugging",title:"Debugging ts-jest"},r=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},d={},g=[];function u(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,o.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.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"set TS_JEST_LOG=ts-jest.log\n"})})]})}function l(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(u,{...e})}):u(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/db795cf2.52b94872.js b/assets/js/db795cf2.52b94872.js new file mode 100644 index 0000000000..3463270462 --- /dev/null +++ b/assets/js/db795cf2.52b94872.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5369],{4442:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>l,frontMatter:()=>i,metadata:()=>c,toc:()=>g});var s=n(4848),o=n(8453);const i={id:"debugging",title:"Debugging ts-jest"},r=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/debugging.md",tags:[],version:"27.1",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},g=[];function u(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,o.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.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"set TS_JEST_LOG=ts-jest.log\n"})})]})}function l(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(u,{...e})}):u(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.047e412b.js b/assets/js/dcbdd84f.047e412b.js deleted file mode 100644 index e68a8d7c77..0000000000 --- a/assets/js/dcbdd84f.047e412b.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4716],{9586:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>l,frontMatter:()=>i,metadata:()=>c,toc:()=>g});var s=n(4848),o=n(8453);const i={id:"debugging",title:"Debugging ts-jest"},r=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},d={},g=[];function u(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,o.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.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"set TS_JEST_LOG=ts-jest.log\n"})})]})}function l(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(u,{...e})}):u(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.6786c2be.js b/assets/js/dcbdd84f.6786c2be.js new file mode 100644 index 0000000000..d9bcabb70c --- /dev/null +++ b/assets/js/dcbdd84f.6786c2be.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4716],{9586:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>l,frontMatter:()=>i,metadata:()=>c,toc:()=>g});var s=n(4848),o=n(8453);const i={id:"debugging",title:"Debugging ts-jest"},r=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/debugging.md",tags:[],version:"26.5",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},g=[];function u(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,o.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.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"set TS_JEST_LOG=ts-jest.log\n"})})]})}function l(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(u,{...e})}):u(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.abcf0180.js b/assets/js/e3a856ae.abcf0180.js deleted file mode 100644 index 0c79446edf..0000000000 --- a/assets/js/e3a856ae.abcf0180.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6771],{3897:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>u,frontMatter:()=>o,metadata:()=>r,toc:()=>l});var n=s(4848),i=s(8453);const o={id:"react-native",title:"Using with React Native"},c=void 0,r={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:!1,unlisted:!1,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:1726058855e3,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"}},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,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["To use ",(0,n.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,n.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,n.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,n.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,n.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,n.jsx)(t.code,{children:".babelrc"})," to ",(0,n.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-js",children:"// babel.config.js\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n"})}),"\n",(0,n.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,n.jsxs)(t.p,{children:["Create a new ",(0,n.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,n.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,n.jsx)(t.code,{children:"jest"})," key of ",(0,n.jsx)(t.code,{children:"package.json"})," to ",(0,n.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t,{...e,children:(0,n.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/e3a856ae.d73fd84d.js b/assets/js/e3a856ae.d73fd84d.js new file mode 100644 index 0000000000..0adcf7dfeb --- /dev/null +++ b/assets/js/e3a856ae.d73fd84d.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6771],{3897:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>o,metadata:()=>r,toc:()=>l});var n=s(4848),i=s(8453);const o={id:"react-native",title:"Using with React Native"},c=void 0,r={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/guides/react-native.md",tags:[],version:"27.1",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["To use ",(0,n.jsx)(t.code,{children:"ts-jest"})," with React Native + TypeScript and Babel 7, you'll first need to follow ",(0,n.jsx)(t.a,{href:"https://reactnative.dev/blog/2018/05/07/using-typescript-with-react-native",children:"this tutorial"}),"."]}),"\n",(0,n.jsx)(t.p,{children:"After that, some little modifications will be required as follows:"}),"\n",(0,n.jsx)(t.h3,{id:"babel-config",children:"Babel config"}),"\n",(0,n.jsxs)(t.p,{children:["If you didn't yet, move any Babel config from ",(0,n.jsx)(t.code,{children:".babelrc"})," to ",(0,n.jsx)(t.code,{children:"babel.config.js"}),". It should at least contain:"]}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-js",children:"// babel.config.js\nmodule.exports = {\n presets: ['module:metro-react-native-babel-preset'],\n}\n"})}),"\n",(0,n.jsx)(t.h3,{id:"typescript-configuration",children:"TypeScript Configuration"}),"\n",(0,n.jsxs)(t.p,{children:["Create a new ",(0,n.jsx)(t.code,{children:"tsconfig.spec.json"})," at the root of your project with the following content"]}),"\n",(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.h3,{id:"jest-config",children:"Jest config"}),"\n",(0,n.jsxs)(t.p,{children:["In the same way that you moved Babel config, move Jest config from ",(0,n.jsx)(t.code,{children:"jest"})," key of ",(0,n.jsx)(t.code,{children:"package.json"})," to ",(0,n.jsx)(t.code,{children:"jest.config.js"}),". It should look like this:"]}),"\n",(0,n.jsx)(t.pre,{children:(0,n.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,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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.8f4107df.js b/assets/js/e5e34c6b.8f4107df.js new file mode 100644 index 0000000000..4d7793f92c --- /dev/null +++ b/assets/js/e5e34c6b.8f4107df.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4218],{7512:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>p,frontMatter:()=>r,metadata:()=>c,toc:()=>a});var s=n(4848),i=n(8453);const r={id:"version-checking",title:"Version checking"},o=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/version-checking.md",tags:[],version:"current",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},a=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default, ",(0,s.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,s.jsx)(t.code,{children:"jest"}),"/",(0,s.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,s.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\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_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Windows"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,s.jsxs)(t.p,{children:["As long as the environment variable ",(0,s.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,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/e5e34c6b.e09961d8.js b/assets/js/e5e34c6b.e09961d8.js deleted file mode 100644 index 8d5b6b6bf1..0000000000 --- a/assets/js/e5e34c6b.e09961d8.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4218],{7512:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>o,default:()=>p,frontMatter:()=>r,metadata:()=>c,toc:()=>d});var s=n(4848),i=n(8453);const r={id:"version-checking",title:"Version checking"},o=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/version-checking.md",tags:[],version:"current",lastUpdatedBy:"renovate[bot]",lastUpdatedAt:1726058855e3,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"}},a={},d=[{value:"Note",id:"note",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default, ",(0,s.jsx)(t.code,{children:"ts-jest"})," supports a range of versions for ",(0,s.jsx)(t.code,{children:"jest"}),"/",(0,s.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,s.jsx)(t.code,{children:"TS_JEST_DISABLE_VER_CHECKER"}),":"]}),"\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_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Windows"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{children:"set TS_JEST_DISABLE_VER_CHECKER=true\n"})}),"\n",(0,s.jsx)(t.h3,{id:"note",children:"Note"}),"\n",(0,s.jsxs)(t.p,{children:["As long as the environment variable ",(0,s.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,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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.664ed307.js b/assets/js/e8085380.664ed307.js new file mode 100644 index 0000000000..70ecfb39d5 --- /dev/null +++ b/assets/js/e8085380.664ed307.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3284],{8134:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>c,contentTitle:()=>l,default:()=>h,frontMatter:()=>t,metadata:()=>r,toc:()=>d});var i=s(4848),o=s(8453);const t={title:"Diagnostics option"},l=void 0,r={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Diagnostics option"}},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,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(n.p,{children:["The ",(0,i.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,i.jsxs)(n.p,{children:["If a diagnostic is not filtered out, ",(0,i.jsx)(n.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,i.jsx)(n.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,i.jsxs)(n.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,i.jsx)(n.code,{children:"diagnostics"})," option to ",(0,i.jsx)(n.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,i.jsx)(n.code,{children:"diagnostics"})," to ",(0,i.jsx)(n.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,i.jsx)(n.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"warnOnly"})}),": If specified and ",(0,i.jsx)(n.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,i.jsx)(n.em,{children:"disabled"}),")."]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,i.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,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"6059"}),": ",(0,i.jsx)(n.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"18002"}),": ",(0,i.jsx)(n.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"18003"}),": ",(0,i.jsx)(n.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,i.jsx)(n.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,i.jsx)(n.code,{children:"tsconfig"})," option ",(0,i.jsx)(n.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,i.jsx)(n.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,i.jsx)(n.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,i.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,i.jsx)(n.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,i.jsx)(n.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,i.jsxs)(n.p,{children:["Assuming all your test files ends with ",(0,i.jsx)(n.code,{children:".spec.ts"})," or ",(0,i.jsx)(n.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,i.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,i.jsx)(n.code,{children:"warnOnly"})," to ",(0,i.jsx)(n.code,{children:"true"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,i.jsxs)(n.p,{children:["All TypeScript error codes can be found ",(0,i.jsx)(n.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,i.jsx)(n.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,i.jsxs)(n.ol,{children:["\n",(0,i.jsxs)(n.li,{children:["A single ",(0,i.jsx)(n.code,{children:"number"})," (example: ",(0,i.jsx)(n.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,i.jsxs)(n.li,{children:["A ",(0,i.jsx)(n.code,{children:"string"})," with a code (example ",(0,i.jsx)(n.code,{children:'"1009"'}),", ",(0,i.jsx)(n.code,{children:'"TS1009"'})," or ",(0,i.jsx)(n.code,{children:'"TS1009"'}),")"]}),"\n",(0,i.jsxs)(n.li,{children:["A ",(0,i.jsx)(n.code,{children:"string"})," with a list of the above (example: ",(0,i.jsx)(n.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,i.jsxs)(n.li,{children:["An ",(0,i.jsx)(n.code,{children:"array"})," of one or more from ",(0,i.jsx)(n.code,{children:"1"})," or ",(0,i.jsx)(n.code,{children:"3"})," (example: ",(0,i.jsx)(n.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,o.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.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/e8085380.c509d690.js b/assets/js/e8085380.c509d690.js deleted file mode 100644 index 242e56138a..0000000000 --- a/assets/js/e8085380.c509d690.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[3284],{8134:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>c,contentTitle:()=>l,default:()=>h,frontMatter:()=>t,metadata:()=>r,toc:()=>d});var i=s(4848),o=s(8453);const t={title:"Diagnostics option"},l=void 0,r={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Diagnostics option"}},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,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(n.p,{children:["The ",(0,i.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,i.jsxs)(n.p,{children:["If a diagnostic is not filtered out, ",(0,i.jsx)(n.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,i.jsx)(n.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,i.jsxs)(n.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,i.jsx)(n.code,{children:"diagnostics"})," option to ",(0,i.jsx)(n.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,i.jsx)(n.code,{children:"diagnostics"})," to ",(0,i.jsx)(n.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,i.jsx)(n.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"warnOnly"})}),": If specified and ",(0,i.jsx)(n.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,i.jsx)(n.em,{children:"disabled"}),")."]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,i.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,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"6059"}),": ",(0,i.jsx)(n.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"18002"}),": ",(0,i.jsx)(n.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"18003"}),": ",(0,i.jsx)(n.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,i.jsx)(n.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,i.jsx)(n.code,{children:"tsconfig"})," option ",(0,i.jsx)(n.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,i.jsx)(n.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,i.jsx)(n.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,i.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,i.jsx)(n.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,i.jsx)(n.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,i.jsxs)(n.p,{children:["Assuming all your test files ends with ",(0,i.jsx)(n.code,{children:".spec.ts"})," or ",(0,i.jsx)(n.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,i.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,i.jsx)(n.code,{children:"warnOnly"})," to ",(0,i.jsx)(n.code,{children:"true"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,i.jsxs)(n.p,{children:["All TypeScript error codes can be found ",(0,i.jsx)(n.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,i.jsx)(n.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,i.jsxs)(n.ol,{children:["\n",(0,i.jsxs)(n.li,{children:["A single ",(0,i.jsx)(n.code,{children:"number"})," (example: ",(0,i.jsx)(n.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,i.jsxs)(n.li,{children:["A ",(0,i.jsx)(n.code,{children:"string"})," with a code (example ",(0,i.jsx)(n.code,{children:'"1009"'}),", ",(0,i.jsx)(n.code,{children:'"TS1009"'})," or ",(0,i.jsx)(n.code,{children:'"TS1009"'}),")"]}),"\n",(0,i.jsxs)(n.li,{children:["A ",(0,i.jsx)(n.code,{children:"string"})," with a list of the above (example: ",(0,i.jsx)(n.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,i.jsxs)(n.li,{children:["An ",(0,i.jsx)(n.code,{children:"array"})," of one or more from ",(0,i.jsx)(n.code,{children:"1"})," or ",(0,i.jsx)(n.code,{children:"3"})," (example: ",(0,i.jsx)(n.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.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,i.jsx)(n.pre,{children:(0,i.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,o.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.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.27d68015.js b/assets/js/e87a3571.27d68015.js deleted file mode 100644 index c95e7d13af..0000000000 --- a/assets/js/e87a3571.27d68015.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7252],{5038:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>p,frontMatter:()=>o,metadata:()=>c,toc:()=>l});var s=n(4848),i=n(8453);const o={id:"babel7-or-ts",title:"Babel7 or TypeScript"},r=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},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,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,s.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,s.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,s.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,s.jsxs)(t.p,{children:["While ",(0,s.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,s.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,s.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,s.jsxs)(t.p,{children:["This is the big ",(0,s.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,s.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,s.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,s.jsx)(t.code,{children:"namespace"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,s.jsx)(t.code,{children:"const enum"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,s.jsx)(t.code,{children:"enum"}),", ",(0,s.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,s.jsxs)(t.p,{children:["You won't be able to do ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,s.jsx)(t.code,{children:"import"}),"/",(0,s.jsx)(t.code,{children:"export"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(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,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/e87a3571.a15fc949.js b/assets/js/e87a3571.a15fc949.js new file mode 100644 index 0000000000..2aee912193 --- /dev/null +++ b/assets/js/e87a3571.a15fc949.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7252],{5038:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>p,frontMatter:()=>o,metadata:()=>c,toc:()=>l});var s=n(4848),i=n(8453);const o={id:"babel7-or-ts",title:"Babel7 or TypeScript"},r=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.0/babel7-or-ts.md",tags:[],version:"29.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["In Sept. 2018 Babel7 got released with an interesting preset: ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),"."]}),"\n",(0,s.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,s.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,s.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,s.jsxs)(t.p,{children:["While ",(0,s.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,s.jsx)(t.code,{children:"ts-jest"}),"), which is not with Babel7 and ",(0,s.jsx)(t.code,{children:"@babel/preset-typescript"}),":"]}),"\n",(0,s.jsx)(t.h4,{id:"no-type-checking",children:"No type-checking"}),"\n",(0,s.jsxs)(t.p,{children:["This is the big ",(0,s.jsx)(t.strong,{children:"PRO"})," of using TypeScript vs Babel, you have type-checking out of the box."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll get a more fluent TDD experience (when using ",(0,s.jsx)(t.code,{children:"ts-jest"}),") since files will be type-checked at the same time they're compiled and ran."]}),"\n",(0,s.jsx)(t.p,{children:"Here TypeScript will throw while Babel won't:"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const str: string = 42\n"})}),"\n",(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-namespace",children:["No ",(0,s.jsx)(t.code,{children:"namespace"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-const-enum",children:["No ",(0,s.jsx)(t.code,{children:"const enum"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const enum Directions {\n Up,\n Down,\n Left,\n Right,\n}\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-declaration-merging-enum-namespace-",children:["No declaration merging (",(0,s.jsx)(t.code,{children:"enum"}),", ",(0,s.jsx)(t.code,{children:"namespace"}),", ...)"]}),"\n",(0,s.jsxs)(t.p,{children:["You won't be able to do ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/declaration-merging.html",children:"declaration merging"}),"."]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsxs)(t.h4,{id:"no-legacy-importexport",children:["No legacy ",(0,s.jsx)(t.code,{children:"import"}),"/",(0,s.jsx)(t.code,{children:"export"})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"import lib = require('lib')\n// ...\nexport = myVar\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h4,{id:"no-caret-type-casting-with-jsx-enabled",children:"No caret type-casting with JSX enabled"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-ts",children:"const val = input\n"})})]})}function p(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,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.830e4a58.js b/assets/js/e8b13364.830e4a58.js deleted file mode 100644 index 29bfd31ad7..0000000000 --- a/assets/js/e8b13364.830e4a58.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4523],{8495:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>a,default:()=>p,frontMatter:()=>o,metadata:()=>i,toc:()=>l});var r=n(4848),t=n(8453);const o={title:"AST transformers option"},a=void 0,i={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"AST transformers option"}},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,t.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:"public-transformers",children:"Public transformers"}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.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,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"path-mapping"})," convert alias import/export to relative import/export path base on ",(0,r.jsx)(s.code,{children:"paths"})," in ",(0,r.jsx)(s.code,{children:"tsconfig"}),".\nThis transformer works similar to ",(0,r.jsx)(s.code,{children:"moduleNameMapper"})," in ",(0,r.jsx)(s.code,{children:"jest.config.js"}),". When using this transformer, one might not need\n",(0,r.jsx)(s.code,{children:"moduleNameMapper"})," anymore."]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"example-of-opt-in-transformers",children:"Example of opt-in 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: ['ts-jest/dist/transformers/path-mapping'],\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": ["ts-jest/dist/transformers/path-mapping"]\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/v26.5.0/src/transformers",children:"the one"})," that ",(0,r.jsx)(s.code,{children:"ts-jest"})," is using."]})]})}function p(e={}){const{wrapper:s}={...(0,t.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:()=>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/e8b13364.c1414c7e.js b/assets/js/e8b13364.c1414c7e.js new file mode 100644 index 0000000000..2ab5533702 --- /dev/null +++ b/assets/js/e8b13364.c1414c7e.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4523],{8495:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>a,default:()=>p,frontMatter:()=>o,metadata:()=>i,toc:()=>l});var r=n(4848),t=n(8453);const o={title:"AST transformers option"},a=void 0,i={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"AST transformers option"}},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,t.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:"public-transformers",children:"Public transformers"}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.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,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"path-mapping"})," convert alias import/export to relative import/export path base on ",(0,r.jsx)(s.code,{children:"paths"})," in ",(0,r.jsx)(s.code,{children:"tsconfig"}),".\nThis transformer works similar to ",(0,r.jsx)(s.code,{children:"moduleNameMapper"})," in ",(0,r.jsx)(s.code,{children:"jest.config.js"}),". When using this transformer, one might not need\n",(0,r.jsx)(s.code,{children:"moduleNameMapper"})," anymore."]}),"\n"]}),"\n",(0,r.jsx)(s.h4,{id:"example-of-opt-in-transformers",children:"Example of opt-in 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: ['ts-jest/dist/transformers/path-mapping'],\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": ["ts-jest/dist/transformers/path-mapping"]\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/v26.5.0/src/transformers",children:"the one"})," that ",(0,r.jsx)(s.code,{children:"ts-jest"})," is using."]})]})}function p(e={}){const{wrapper:s}={...(0,t.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:()=>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.6b31301f.js b/assets/js/eabdbf07.6b31301f.js new file mode 100644 index 0000000000..b95273757a --- /dev/null +++ b/assets/js/eabdbf07.6b31301f.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5100],{7581:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>a,frontMatter:()=>r,metadata:()=>c,toc:()=>u});var n=s(4848),o=s(8453);const r={id:"processing",title:"Processing flow"},i=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/processing.md",tags:[],version:"current",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,o.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,n.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,n.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,n.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,o.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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/eabdbf07.a58aa90c.js b/assets/js/eabdbf07.a58aa90c.js deleted file mode 100644 index cd16b15e85..0000000000 --- a/assets/js/eabdbf07.a58aa90c.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5100],{7581:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>a,frontMatter:()=>r,metadata:()=>c,toc:()=>u});var n=s(4848),o=s(8453);const r={id:"processing",title:"Processing flow"},i=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/processing.md",tags:[],version:"current",lastUpdatedBy:"renovate[bot]",lastUpdatedAt:1726058855e3,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"}},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,o.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,n.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,n.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,n.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,o.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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/ec6c7123.3f9740db.js b/assets/js/ec6c7123.3f9740db.js new file mode 100644 index 0000000000..46193e9d0c --- /dev/null +++ b/assets/js/ec6c7123.3f9740db.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2091],{4585:(t,e,o)=>{o.r(e),o.d(e,{assets:()=>d,contentTitle:()=>r,default:()=>h,frontMatter:()=>i,metadata:()=>u,toc:()=>c});var s=o(4848),n=o(8453);const i={id:"troubleshooting",title:"Troubleshooting"},r=void 0,u={id:"guides/troubleshooting",title:"Troubleshooting",description:"You can check Jest troubleshooting guide or visit ts-jest [troubleshooting",source:"@site/versioned_docs/version-26.5/guides/troubleshooting.md",sourceDirName:"guides",slug:"/guides/troubleshooting",permalink:"/ts-jest/docs/26.5/guides/troubleshooting",draft:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/guides/troubleshooting.md",tags:[],version:"26.5",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},d={},c=[];function l(t){const e={a:"a",code:"code",p:"p",...(0,n.R)(),...t.components};return(0,s.jsxs)(e.p,{children:["You can check Jest ",(0,s.jsx)(e.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," or visit ",(0,s.jsx)(e.code,{children:"ts-jest"})," ",(0,s.jsx)(e.a,{href:"https://github.com/kulshekhar/ts-jest/blob/main/TROUBLESHOOTING.md",children:"troubleshooting\nguide"})]})}function h(t={}){const{wrapper:e}={...(0,n.R)(),...t.components};return e?(0,s.jsx)(e,{...t,children:(0,s.jsx)(l,{...t})}):l(t)}},8453:(t,e,o)=>{o.d(e,{R:()=>r,x:()=>u});var s=o(6540);const n={},i=s.createContext(n);function r(t){const e=s.useContext(i);return s.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function u(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(n):t.components||n:r(t.components),s.createElement(i.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/ec6c7123.a13017bf.js b/assets/js/ec6c7123.a13017bf.js deleted file mode 100644 index ac4ff0cd3b..0000000000 --- a/assets/js/ec6c7123.a13017bf.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2091],{4585:(t,e,o)=>{o.r(e),o.d(e,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var s=o(4848),n=o(8453);const i={id:"troubleshooting",title:"Troubleshooting"},r=void 0,u={id:"guides/troubleshooting",title:"Troubleshooting",description:"You can check Jest troubleshooting guide or visit ts-jest [troubleshooting",source:"@site/versioned_docs/version-26.5/guides/troubleshooting.md",sourceDirName:"guides",slug:"/guides/troubleshooting",permalink:"/ts-jest/docs/26.5/guides/troubleshooting",draft:!1,unlisted:!1,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:1726058855e3,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"}},c={},d=[];function l(t){const e={a:"a",code:"code",p:"p",...(0,n.R)(),...t.components};return(0,s.jsxs)(e.p,{children:["You can check Jest ",(0,s.jsx)(e.a,{href:"https://jestjs.io/docs/en/troubleshooting",children:"troubleshooting guide"})," or visit ",(0,s.jsx)(e.code,{children:"ts-jest"})," ",(0,s.jsx)(e.a,{href:"https://github.com/kulshekhar/ts-jest/blob/main/TROUBLESHOOTING.md",children:"troubleshooting\nguide"})]})}function h(t={}){const{wrapper:e}={...(0,n.R)(),...t.components};return e?(0,s.jsx)(e,{...t,children:(0,s.jsx)(l,{...t})}):l(t)}},8453:(t,e,o)=>{o.d(e,{R:()=>r,x:()=>u});var s=o(6540);const n={},i=s.createContext(n);function r(t){const e=s.useContext(i);return s.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function u(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(n):t.components||n:r(t.components),s.createElement(i.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/f01607c0.1ef0e44c.js b/assets/js/f01607c0.1ef0e44c.js new file mode 100644 index 0000000000..4b2c099814 --- /dev/null +++ b/assets/js/f01607c0.1ef0e44c.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6714],{6515:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>l,default:()=>h,frontMatter:()=>o,metadata:()=>r,toc:()=>d});var i=t(4848),s=t(8453);const o={id:"installation",title:"Installation"},l=void 0,r={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-28.0/getting-started/installation.md",tags:[],version:"28.0",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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 n={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,i.jsxs)(n.p,{children:["You can install ",(0,i.jsx)(n.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,i.jsx)(n.h4,{id:"npm",children:"NPM"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(n.h4,{id:"yarn",children:"Yarn"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:["Tip: If you get an error with the following ",(0,i.jsx)(n.code,{children:"npm"})," commands such as ",(0,i.jsx)(n.code,{children:"npx: command not found"}),", you can replace ",(0,i.jsx)(n.code,{children:"npx XXX"})," with ",(0,i.jsx)(n.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,i.jsx)(n.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,i.jsx)(n.h4,{id:"creating",children:"Creating"}),"\n",(0,i.jsxs)(n.p,{children:["By default, Jest can run without any config files, but it will not compile ",(0,i.jsx)(n.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,i.jsx)(n.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,i.jsx)(n.code,{children:"ts-jest"})," preset."]}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,i.jsx)(n.h4,{id:"npm-1",children:"NPM"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:init\n"})}),"\n",(0,i.jsx)(n.h4,{id:"yarn-1",children:"Yarn"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:init\n"})}),"\n",(0,i.jsxs)(n.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,i.jsx)(n.code,{children:".ts"})," files correctly."]}),"\n",(0,i.jsxs)(n.p,{children:["You can also use the ",(0,i.jsx)(n.code,{children:"jest --init"})," command (prefixed with either ",(0,i.jsx)(n.code,{children:"npx"})," or ",(0,i.jsx)(n.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,i.jsx)(n.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,i.jsx)(n.code,{children:'preset: "ts-jest"'})," to the ",(0,i.jsx)(n.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,i.jsx)(n.h4,{id:"customizing",children:"Customizing"}),"\n",(0,i.jsxs)(n.p,{children:["For customizing jest, please follow their ",(0,i.jsx)(n.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.code,{children:"ts-jest"})," specific options can be found ",(0,i.jsx)(n.a,{href:"options",children:"here"}),"."]})]})}function h(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(a,{...e})}):a(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>l,x:()=>r});var i=t(6540);const s={},o=i.createContext(s);function l(e){const n=i.useContext(o);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(s):e.components||s:l(e.components),i.createElement(o.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/f01607c0.e2ee583d.js b/assets/js/f01607c0.e2ee583d.js deleted file mode 100644 index 3c6fb8d223..0000000000 --- a/assets/js/f01607c0.e2ee583d.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6714],{6515:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>l,default:()=>h,frontMatter:()=>o,metadata:()=>r,toc:()=>d});var i=t(4848),s=t(8453);const o={id:"installation",title:"Installation"},l=void 0,r={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:!1,unlisted:!1,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:1726058855e3,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"}},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 n={a:"a",admonition:"admonition",code:"code",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.h3,{id:"dependencies",children:"Dependencies"}),"\n",(0,i.jsxs)(n.p,{children:["You can install ",(0,i.jsx)(n.code,{children:"ts-jest"})," and dependencies all at once with one of the following commands."]}),"\n",(0,i.jsx)(n.h4,{id:"npm",children:"NPM"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"npm install --save-dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(n.h4,{id:"yarn",children:"Yarn"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"yarn add --dev jest typescript ts-jest @types/jest\n"})}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:["Tip: If you get an error with the following ",(0,i.jsx)(n.code,{children:"npm"})," commands such as ",(0,i.jsx)(n.code,{children:"npx: command not found"}),", you can replace ",(0,i.jsx)(n.code,{children:"npx XXX"})," with ",(0,i.jsx)(n.code,{children:"node node_modules/.bin/XXX"})," from the root of your project."]})}),"\n",(0,i.jsx)(n.h3,{id:"jest-config-file",children:"Jest config file"}),"\n",(0,i.jsx)(n.h4,{id:"creating",children:"Creating"}),"\n",(0,i.jsxs)(n.p,{children:["By default, Jest can run without any config files, but it will not compile ",(0,i.jsx)(n.code,{children:".ts"})," files.\nTo make it transpile TypeScript with ",(0,i.jsx)(n.code,{children:"ts-jest"}),", we will need to create a configuration file that will tell Jest to use a ",(0,i.jsx)(n.code,{children:"ts-jest"})," preset."]}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.code,{children:"ts-jest"})," can create the configuration file for you automatically:"]}),"\n",(0,i.jsx)(n.h4,{id:"npm-1",children:"NPM"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"npx ts-jest config:init\n"})}),"\n",(0,i.jsx)(n.h4,{id:"yarn-1",children:"Yarn"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",children:"yarn ts-jest config:init\n"})}),"\n",(0,i.jsxs)(n.p,{children:["This will create a basic Jest configuration file which will inform Jest about how to handle ",(0,i.jsx)(n.code,{children:".ts"})," files correctly."]}),"\n",(0,i.jsxs)(n.p,{children:["You can also use the ",(0,i.jsx)(n.code,{children:"jest --init"})," command (prefixed with either ",(0,i.jsx)(n.code,{children:"npx"})," or ",(0,i.jsx)(n.code,{children:"yarn"})," depending on what you're using) to have more options related to Jest.\nHowever, answer ",(0,i.jsx)(n.code,{children:"no"})," to the Jest question about whether or not to enable TypeScript. Instead, add the line: ",(0,i.jsx)(n.code,{children:'preset: "ts-jest"'})," to the ",(0,i.jsx)(n.code,{children:"jest.config.js"})," file afterwards."]}),"\n",(0,i.jsx)(n.h4,{id:"customizing",children:"Customizing"}),"\n",(0,i.jsxs)(n.p,{children:["For customizing jest, please follow their ",(0,i.jsx)(n.a,{href:"https://jestjs.io/docs/en/configuration.html",children:"official guide online"}),"."]}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.code,{children:"ts-jest"})," specific options can be found ",(0,i.jsx)(n.a,{href:"options",children:"here"}),"."]})]})}function h(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(a,{...e})}):a(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>l,x:()=>r});var i=t(6540);const s={},o=i.createContext(s);function l(e){const n=i.useContext(o);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(s):e.components||s:l(e.components),i.createElement(o.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/f0683fd0.6361fb5c.js b/assets/js/f0683fd0.6361fb5c.js new file mode 100644 index 0000000000..170c813b07 --- /dev/null +++ b/assets/js/f0683fd0.6361fb5c.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6672],{1753:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>u,contentTitle:()=>r,default:()=>p,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var n=o(4848),s=o(8453);const i={id:"using-with-monorepo",title:"Using with monorepo"},r=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/guides/using-with-monorepo.md",tags:[],version:"current",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},u={},d=[];function a(e){const t={a:"a",code:"code",p:"p",...(0,s.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,s.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 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 c(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/f0683fd0.887df0ce.js b/assets/js/f0683fd0.887df0ce.js deleted file mode 100644 index 986af3c98d..0000000000 --- a/assets/js/f0683fd0.887df0ce.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6672],{1753:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>u,contentTitle:()=>r,default:()=>p,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var n=o(4848),s=o(8453);const i={id:"using-with-monorepo",title:"Using with monorepo"},r=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/guides/using-with-monorepo.md",tags:[],version:"current",lastUpdatedBy:"renovate[bot]",lastUpdatedAt:1726058855e3,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"}},u={},d=[];function a(e){const t={a:"a",code:"code",p:"p",...(0,s.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,s.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 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 c(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/f154e663.39b5a3de.js b/assets/js/f154e663.39b5a3de.js deleted file mode 100644 index 329017b06b..0000000000 --- a/assets/js/f154e663.39b5a3de.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9643],{417:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>d,contentTitle:()=>l,default:()=>h,frontMatter:()=>a,metadata:()=>c,toc:()=>j});var n=t(4848),i=t(8453),r=t(9489),o=t(7227);const a={title:"Diagnostics option"},l=void 0,c={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Diagnostics option"}},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,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(s.p,{children:["The ",(0,n.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,n.jsxs)(s.p,{children:["If a diagnostic is not filtered out, ",(0,n.jsx)(s.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,n.jsx)(s.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,n.jsxs)(s.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,n.jsx)(s.code,{children:"diagnostics"})," option to ",(0,n.jsx)(s.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,n.jsx)(s.code,{children:"diagnostics"})," to ",(0,n.jsx)(s.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,n.jsx)(s.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,n.jsxs)(s.p,{children:["The ",(0,n.jsx)(s.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"warnOnly"})}),": If specified and ",(0,n.jsx)(s.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,n.jsx)(s.em,{children:"disabled"}),")."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,n.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,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.code,{children:"6059"}),": ",(0,n.jsx)(s.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.code,{children:"18002"}),": ",(0,n.jsx)(s.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.code,{children:"18003"}),": ",(0,n.jsx)(s.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,n.jsx)(s.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,n.jsx)(s.code,{children:"tsconfig"})," option ",(0,n.jsx)(s.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,n.jsx)(s.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,n.jsx)(s.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,n.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsx)(s.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,n.jsxs)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 "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,n.jsx)(s.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,n.jsx)(s.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,n.jsxs)(s.p,{children:["Assuming all your test files ends with ",(0,n.jsx)(s.code,{children:".spec.ts"})," or ",(0,n.jsx)(s.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,n.jsxs)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 "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,n.jsx)(s.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,n.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,n.jsx)(s.code,{children:"warnOnly"})," to ",(0,n.jsx)(s.code,{children:"true"}),":"]}),"\n",(0,n.jsxs)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 "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,n.jsx)(s.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,n.jsxs)(s.p,{children:["All TypeScript error codes can be found ",(0,n.jsx)(s.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,n.jsx)(s.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,n.jsxs)(s.ol,{children:["\n",(0,n.jsxs)(s.li,{children:["A single ",(0,n.jsx)(s.code,{children:"number"})," (example: ",(0,n.jsx)(s.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,n.jsxs)(s.li,{children:["A ",(0,n.jsx)(s.code,{children:"string"})," with a code (example ",(0,n.jsx)(s.code,{children:'"1009"'}),", ",(0,n.jsx)(s.code,{children:'"TS1009"'})," or ",(0,n.jsx)(s.code,{children:'"TS1009"'}),")"]}),"\n",(0,n.jsxs)(s.li,{children:["A ",(0,n.jsx)(s.code,{children:"string"})," with a list of the above (example: ",(0,n.jsx)(s.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,n.jsxs)(s.li,{children:["An ",(0,n.jsx)(s.code,{children:"array"})," of one or more from ",(0,n.jsx)(s.code,{children:"1"})," or ",(0,n.jsx)(s.code,{children:"3"})," (example: ",(0,n.jsx)(s.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,n.jsxs)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 "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,i.R)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.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/f154e663.72cf3602.js b/assets/js/f154e663.72cf3602.js new file mode 100644 index 0000000000..a5c3effc17 --- /dev/null +++ b/assets/js/f154e663.72cf3602.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9643],{417:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>d,contentTitle:()=>l,default:()=>h,frontMatter:()=>a,metadata:()=>c,toc:()=>j});var n=t(4848),i=t(8453),o=t(9489),r=t(7227);const a={title:"Diagnostics option"},l=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Diagnostics option"}},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,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(s.p,{children:["The ",(0,n.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,n.jsxs)(s.p,{children:["If a diagnostic is not filtered out, ",(0,n.jsx)(s.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,n.jsx)(s.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,n.jsxs)(s.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,n.jsx)(s.code,{children:"diagnostics"})," option to ",(0,n.jsx)(s.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,n.jsx)(s.code,{children:"diagnostics"})," to ",(0,n.jsx)(s.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,n.jsx)(s.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,n.jsxs)(s.p,{children:["The ",(0,n.jsx)(s.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"warnOnly"})}),": If specified and ",(0,n.jsx)(s.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,n.jsx)(s.em,{children:"disabled"}),")."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,n.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,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.code,{children:"6059"}),": ",(0,n.jsx)(s.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.code,{children:"18002"}),": ",(0,n.jsx)(s.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.code,{children:"18003"}),": ",(0,n.jsx)(s.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,n.jsx)(s.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,n.jsx)(s.code,{children:"tsconfig"})," option ",(0,n.jsx)(s.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,n.jsx)(s.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,n.jsx)(s.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,n.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsx)(s.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,n.jsx)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,n.jsx)(r.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 "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,n.jsx)(s.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,n.jsx)(s.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,n.jsxs)(s.p,{children:["Assuming all your test files ends with ",(0,n.jsx)(s.code,{children:".spec.ts"})," or ",(0,n.jsx)(s.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,n.jsx)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,n.jsx)(r.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 "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,n.jsx)(s.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,n.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,n.jsx)(s.code,{children:"warnOnly"})," to ",(0,n.jsx)(s.code,{children:"true"}),":"]}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,n.jsx)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,n.jsx)(r.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 "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,n.jsx)(s.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,n.jsxs)(s.p,{children:["All TypeScript error codes can be found ",(0,n.jsx)(s.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,n.jsx)(s.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,n.jsxs)(s.ol,{children:["\n",(0,n.jsxs)(s.li,{children:["A single ",(0,n.jsx)(s.code,{children:"number"})," (example: ",(0,n.jsx)(s.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,n.jsxs)(s.li,{children:["A ",(0,n.jsx)(s.code,{children:"string"})," with a code (example ",(0,n.jsx)(s.code,{children:'"1009"'}),", ",(0,n.jsx)(s.code,{children:'"TS1009"'})," or ",(0,n.jsx)(s.code,{children:'"TS1009"'}),")"]}),"\n",(0,n.jsxs)(s.li,{children:["A ",(0,n.jsx)(s.code,{children:"string"})," with a list of the above (example: ",(0,n.jsx)(s.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,n.jsxs)(s.li,{children:["An ",(0,n.jsx)(s.code,{children:"array"})," of one or more from ",(0,n.jsx)(s.code,{children:"1"})," or ",(0,n.jsx)(s.code,{children:"3"})," (example: ",(0,n.jsx)(s.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,n.jsx)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,n.jsx)(r.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 "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,i.R)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.jsx)(u,{...e})}):u(e)}},7227:(e,s,t)=>{t.d(s,{A:()=>r});t(6540);var n=t(4164);const i={tabItem:"tabItem_Ymn6"};var o=t(4848);function r(e){let{children:s,hidden:t,className:r}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,n.A)(i.tabItem,r),hidden:t,children:s})}},9489:(e,s,t)=>{t.d(s,{A:()=>w});var n=t(6540),i=t(4164),o=t(4245),r=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,r.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(i.location.search);s.set(o,e),i.replace({...i.location,search:s.toString()})}),[o,i])]}function p(e){const{defaultValue:s,queryString:t=!1,groupId:i}=e,o=u(e),[r,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:o}))),[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,o]=(0,d.Dv)(t);return[i,(0,n.useCallback)((e=>{t&&o.set(e)}),[t,o])]}({groupId:i}),m=(()=>{const e=c??p;return h({value:e,tabValues:o})?e:null})();(0,a.A)((()=>{m&&l(m)}),[m]);return{selectedValue:r,selectValue:(0,n.useCallback)((e=>{if(!h({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);l(e),j(e),g(e)}),[j,g,o]),tabValues:o}}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:r,tabValues:a}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.a_)(),d=e=>{const s=e.currentTarget,t=l.indexOf(s),i=a[t].value;i!==n&&(c(s),r(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:o}=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,...o,className:(0,i.A)("tabs__item",m.tabItem,o?.className,{"tabs__item--active":n===s}),children:t??s},s)}))})}function v(e){let{lazy:s,children:t,selectedValue:o}=e;const r=(Array.isArray(t)?t:[t]).filter(Boolean);if(s){const e=r.find((e=>e.props.value===o));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:r.map(((e,s)=>(0,n.cloneElement)(e,{key:s,hidden:e.props.value!==o})))})}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:()=>r,x:()=>a});var n=t(6540);const i={},o=n.createContext(i);function r(e){const s=n.useContext(o);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:r(e.components),n.createElement(o.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/f298e69b.4fba9700.js b/assets/js/f298e69b.4fba9700.js deleted file mode 100644 index eb5781abb8..0000000000 --- a/assets/js/f298e69b.4fba9700.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2804],{2589:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>p,frontMatter:()=>l,metadata:()=>c,toc:()=>d});var s=n(4848),a=n(8453),r=n(9489),o=n(7227);const l={title:"Isolated Modules option"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Isolated Modules option"}},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,a.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default ",(0,s.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,s.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,s.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,s.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,s.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,s.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsxs)(r.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.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,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.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,s.jsx)(o.A,{value:"JSON",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,s.jsxs)(t.p,{children:["Using ",(0,s.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,s.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,s.jsx)(t.code,{children:"include"})," in ",(0,s.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,s.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,s.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,s.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,s.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,s.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,s.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,s.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,s.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,s.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,s.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function p(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var s=n(4164);const a={tabItem:"tabItem_Ymn6"};var r=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,s.A)(a.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),a=n(4164),r=n(4245),o=n(6347),l=n(6494),i=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:a}}=e;return{value:t,label:n,attributes:s,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 p(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 a=(0,o.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,i.aZ)(r),(0,s.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:n=!1,groupId:a}=e,r=h(e),[o,i]=(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:r}))),[c,d]=m({queryString:n,groupId:a}),[f,j]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,r]=(0,u.Dv)(n);return[a,(0,s.useCallback)((e=>{n&&r.set(e)}),[n,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,s.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=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:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),u=e=>{const t=e.currentTarget,n=i.indexOf(t),a=l[n].value;a!==s&&(c(t),o(a))},d=e=>{let t=null;switch(e.key){case"Enter":u(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,b.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:r}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>i.push(e),onKeyDown:d,onClick:u,...r,className:(0,a.A)("tabs__item",g.tabItem,r?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:r}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===r));return e?(0,s.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,s.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,n)=>{n.d(t,{R:()=>o,x:()=>l});var s=n(6540);const a={},r=s.createContext(a);function o(e){const t=s.useContext(r);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(a):e.components||a:o(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/f298e69b.5e533ece.js b/assets/js/f298e69b.5e533ece.js new file mode 100644 index 0000000000..e5bb9a1cb8 --- /dev/null +++ b/assets/js/f298e69b.5e533ece.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2804],{2589:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>p,frontMatter:()=>l,metadata:()=>c,toc:()=>d});var s=n(4848),a=n(8453),r=n(9489),o=n(7227);const l={title:"Isolated Modules option"},i=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Isolated Modules option"}},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,a.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["By default ",(0,s.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,s.jsx)(t.code,{children:"isolatedModules"})," option (which defaults to ",(0,s.jsx)(t.code,{children:"false"}),") does."]}),"\n",(0,s.jsxs)(t.p,{children:["You'll lose type-checking ability and some features such as ",(0,s.jsx)(t.code,{children:"const enum"}),", but in the case you plan on using Jest with the cache disabled (",(0,s.jsx)(t.code,{children:"jest --no-cache"}),"), your tests will then run much faster."]}),"\n",(0,s.jsx)(t.p,{children:"Here is how to disable type-checking and compile each file as an isolated module:"}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsxs)(r.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.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,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.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,s.jsx)(o.A,{value:"JSON",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h2,{id:"performance",children:"Performance"}),"\n",(0,s.jsxs)(t.p,{children:["Using ",(0,s.jsx)(t.code,{children:"isolatedModules: false"})," comes with a cost of performance comparing to ",(0,s.jsx)(t.code,{children:"isolatedModules: true"}),". There is a way\nto improve the performance when using this mode by changing the value of ",(0,s.jsx)(t.code,{children:"include"})," in ",(0,s.jsx)(t.code,{children:"tsconfig"})," which is used by ",(0,s.jsx)(t.code,{children:"ts-jest"}),".\nThe least amount of files which are provided in ",(0,s.jsx)(t.code,{children:"include"}),", the more performance the test run can gain."]}),"\n",(0,s.jsx)(t.h3,{id:"example-1",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-json",children:'// tsconfig.json\n{\n // ...other configs\n "include": ["my-typings/*", "my-global-modules/*"]\n}\n'})}),"\n",(0,s.jsx)(t.h2,{id:"caveats",children:"Caveats"}),"\n",(0,s.jsxs)(t.p,{children:["Limiting the amount of files loaded via ",(0,s.jsx)(t.code,{children:"include"})," can greatly boost performance when running tests. However, the trade off\nis ",(0,s.jsx)(t.code,{children:"ts-jest"})," might not recognize all files which are intended to use with ",(0,s.jsx)(t.code,{children:"jest"}),". One can run into issues with custom typings,\nglobal modules, etc..."]}),"\n",(0,s.jsxs)(t.p,{children:["The suggested solution is what is needed for the test environment should be captured by\nglob patterns in ",(0,s.jsx)(t.code,{children:"include"}),", to gain both performance boost and avoid breaking behaviors."]})]})}function p(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},7227:(e,t,n)=>{n.d(t,{A:()=>o});n(6540);var s=n(4164);const a={tabItem:"tabItem_Ymn6"};var r=n(4848);function o(e){let{children:t,hidden:n,className:o}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,s.A)(a.tabItem,o),hidden:n,children:t})}},9489:(e,t,n)=>{n.d(t,{A:()=>w});var s=n(6540),a=n(4164),r=n(4245),o=n(6347),l=n(6494),i=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:a}}=e;return{value:t,label:n,attributes:s,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 p(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 a=(0,o.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,i.aZ)(r),(0,s.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:n=!1,groupId:a}=e,r=h(e),[o,i]=(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:r}))),[c,d]=m({queryString:n,groupId:a}),[f,j]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,r]=(0,u.Dv)(n);return[a,(0,s.useCallback)((e=>{n&&r.set(e)}),[n,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,s.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=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:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.a_)(),u=e=>{const t=e.currentTarget,n=i.indexOf(t),a=l[n].value;a!==s&&(c(t),o(a))},d=e=>{let t=null;switch(e.key){case"Enter":u(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,b.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:r}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>i.push(e),onKeyDown:d,onClick:u,...r,className:(0,a.A)("tabs__item",g.tabItem,r?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:r}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===r));return e?(0,s.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,s.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,n)=>{n.d(t,{R:()=>o,x:()=>l});var s=n(6540);const a={},r=s.createContext(a);function o(e){const t=s.useContext(r);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(a):e.components||a:o(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/f371827f.468b1e1e.js b/assets/js/f371827f.468b1e1e.js deleted file mode 100644 index 97d18056ee..0000000000 --- a/assets/js/f371827f.468b1e1e.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4811],{2764:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>c,default:()=>j,frontMatter:()=>l,metadata:()=>a,toc:()=>u});var s=n(4848),r=n(8453),i=n(9489),o=n(7227);const l={id:"options",title:"Options"},c=void 0,a={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:!1,unlisted:!1,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:1726058855e3,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"}},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,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.h3,{id:"introduction",children:"Introduction"}),"\n",(0,s.jsx)(t.admonition,{type:"caution",children:(0,s.jsxs)(t.p,{children:["If you are using custom ",(0,s.jsx)(t.code,{children:"transform"})," config, please remove ",(0,s.jsx)(t.code,{children:"preset"})," from your Jest config to avoid issues that Jest doesn't transform files correctly."]})}),"\n",(0,s.jsxs)(t.p,{children:["All ",(0,s.jsx)(t.code,{children:"ts-jest"})," specific options can be defined in Jest ",(0,s.jsx)(t.code,{children:"transform"})," config object in the ",(0,s.jsx)(t.code,{children:"package.json"})," file of your project,\nor through a ",(0,s.jsx)(t.code,{children:"jest.config.js"}),", or ",(0,s.jsx)(t.code,{children:"jest.config.ts"})," file."]}),"\n",(0,s.jsxs)(i.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.config.js\nconst { createDefaultPreset } = require('ts-jest')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n ...createDefaultPreset(),\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.config.ts\nimport { createDefaultPreset, JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n ...createDefaultPreset(),\n}\n"})})})]}),"\n",(0,s.jsx)(t.admonition,{type:"important",children:(0,s.jsxs)(t.p,{children:["When using TypeScript Jest config file, Jest will use ",(0,s.jsx)(t.code,{children:"ts-node"})," to compile the config file. ",(0,s.jsx)(t.code,{children:"ts-jest"})," doesn't take part in\nthat process."]})}),"\n",(0,s.jsx)(t.h3,{id:"options",children:"Options"}),"\n",(0,s.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,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Option"}),(0,s.jsx)(t.th,{children:"Description"}),(0,s.jsx)(t.th,{children:"Type"}),(0,s.jsx)(t.th,{children:"Default"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/compiler",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"compiler"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"string"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:'"typescript"'})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/tsconfig",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"tsconfig"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,s.jsxs)(t.td,{children:[(0,s.jsx)(t.code,{children:"string"}),"|",(0,s.jsx)(t.code,{children:"object"}),"|",(0,s.jsx)(t.code,{children:"boolean"})]}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"auto"})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/isolatedModules",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"isolatedModules"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"boolean"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"disabled"})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/astTransformers",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"astTransformers"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"object"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"auto"})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/diagnostics",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"diagnostics"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,s.jsxs)(t.td,{children:[(0,s.jsx)(t.code,{children:"boolean"}),"|",(0,s.jsx)(t.code,{children:"object"})]}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"enabled"})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/babelConfig",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"babelConfig"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,s.jsxs)(t.td,{children:[(0,s.jsx)(t.code,{children:"boolean"}),"|",(0,s.jsx)(t.code,{children:"string"}),"|",(0,s.jsx)(t.code,{children:"object"})]}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"disabled"})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/stringifyContentPathRegex",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,s.jsxs)(t.td,{children:[(0,s.jsx)(t.code,{children:"string"}),"|",(0,s.jsx)(t.code,{children:"RegExp"})]}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"disabled"})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/useESM",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"useESM"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/useESM",children:"Enable ESM support"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"boolean"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"auto"})})]})]})]})]})}function j(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/f371827f.5c5649b3.js b/assets/js/f371827f.5c5649b3.js new file mode 100644 index 0000000000..eb928182c2 --- /dev/null +++ b/assets/js/f371827f.5c5649b3.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4811],{2764:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>c,default:()=>j,frontMatter:()=>l,metadata:()=>a,toc:()=>u});var s=n(4848),r=n(8453),i=n(9489),o=n(7227);const l={id:"options",title:"Options"},c=void 0,a={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/getting-started/options.md",tags:[],version:"29.2",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.h3,{id:"introduction",children:"Introduction"}),"\n",(0,s.jsx)(t.admonition,{type:"caution",children:(0,s.jsxs)(t.p,{children:["If you are using custom ",(0,s.jsx)(t.code,{children:"transform"})," config, please remove ",(0,s.jsx)(t.code,{children:"preset"})," from your Jest config to avoid issues that Jest doesn't transform files correctly."]})}),"\n",(0,s.jsxs)(t.p,{children:["All ",(0,s.jsx)(t.code,{children:"ts-jest"})," specific options can be defined in Jest ",(0,s.jsx)(t.code,{children:"transform"})," config object in the ",(0,s.jsx)(t.code,{children:"package.json"})," file of your project,\nor through a ",(0,s.jsx)(t.code,{children:"jest.config.js"}),", or ",(0,s.jsx)(t.code,{children:"jest.config.ts"})," file."]}),"\n",(0,s.jsxs)(i.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.config.js\nconst { createDefaultPreset } = require('ts-jest')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n ...createDefaultPreset(),\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.config.ts\nimport { createDefaultPreset, JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n ...createDefaultPreset(),\n}\n"})})})]}),"\n",(0,s.jsx)(t.admonition,{type:"important",children:(0,s.jsxs)(t.p,{children:["When using TypeScript Jest config file, Jest will use ",(0,s.jsx)(t.code,{children:"ts-node"})," to compile the config file. ",(0,s.jsx)(t.code,{children:"ts-jest"})," doesn't take part in\nthat process."]})}),"\n",(0,s.jsx)(t.h3,{id:"options",children:"Options"}),"\n",(0,s.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,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Option"}),(0,s.jsx)(t.th,{children:"Description"}),(0,s.jsx)(t.th,{children:"Type"}),(0,s.jsx)(t.th,{children:"Default"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/compiler",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"compiler"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"string"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:'"typescript"'})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/tsconfig",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"tsconfig"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,s.jsxs)(t.td,{children:[(0,s.jsx)(t.code,{children:"string"}),"|",(0,s.jsx)(t.code,{children:"object"}),"|",(0,s.jsx)(t.code,{children:"boolean"})]}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"auto"})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/isolatedModules",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"isolatedModules"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"boolean"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"disabled"})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/astTransformers",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"astTransformers"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"object"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"auto"})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/diagnostics",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"diagnostics"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,s.jsxs)(t.td,{children:[(0,s.jsx)(t.code,{children:"boolean"}),"|",(0,s.jsx)(t.code,{children:"object"})]}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"enabled"})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/babelConfig",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"babelConfig"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,s.jsxs)(t.td,{children:[(0,s.jsx)(t.code,{children:"boolean"}),"|",(0,s.jsx)(t.code,{children:"string"}),"|",(0,s.jsx)(t.code,{children:"object"})]}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"disabled"})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/stringifyContentPathRegex",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,s.jsxs)(t.td,{children:[(0,s.jsx)(t.code,{children:"string"}),"|",(0,s.jsx)(t.code,{children:"RegExp"})]}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"disabled"})})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/useESM",children:(0,s.jsx)(t.strong,{children:(0,s.jsx)(t.code,{children:"useESM"})})})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"options/useESM",children:"Enable ESM support"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"boolean"})}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.em,{children:"auto"})})]})]})]})]})}function j(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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.0d81a9bc.js b/assets/js/f4dd4a52.0d81a9bc.js deleted file mode 100644 index f8ad78e440..0000000000 --- a/assets/js/f4dd4a52.0d81a9bc.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[397],{1333:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>p,frontMatter:()=>l,metadata:()=>c,toc:()=>j});var n=s(4848),r=s(8453),o=s(9489),a=s(7227);const l={title:"Babel Config option"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Babel Config option"}},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,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:[(0,n.jsx)(t.code,{children:"ts-jest"})," by default does ",(0,n.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,n.jsx)(t.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,n.jsxs)(t.p,{children:["The option is ",(0,n.jsx)(t.code,{children:"babelConfig"})," and it works pretty much as the ",(0,n.jsx)(t.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"true"}),": enables Babel processing. ",(0,n.jsx)(t.code,{children:"ts-jest"})," will try to find a ",(0,n.jsx)(t.code,{children:".babelrc"}),", ",(0,n.jsx)(t.code,{children:".babelrc.js"}),", ",(0,n.jsx)(t.code,{children:"babel.config.js"})," file or a ",(0,n.jsx)(t.code,{children:"babel"})," section in the ",(0,n.jsx)(t.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,n.jsx)(t.code,{children:"babel-jest"})," processor."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"{ ... }"}),": inline ",(0,n.jsx)(t.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,n.jsx)(t.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,n.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsxs)(t.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,n.jsx)(t.code,{children:"babelrc"})," file"]}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsxs)(t.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,n.jsx)(t.code,{children:"babelrc"})," file"]}),"\n",(0,n.jsxs)(t.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,n.jsx)(t.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.p,{children:"or importing directly the config file:"}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,n.jsxs)(t.p,{children:["Refer to the ",(0,n.jsx)(t.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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/f4dd4a52.5b27e681.js b/assets/js/f4dd4a52.5b27e681.js new file mode 100644 index 0000000000..51a0479350 --- /dev/null +++ b/assets/js/f4dd4a52.5b27e681.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[397],{1333:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>p,frontMatter:()=>l,metadata:()=>c,toc:()=>j});var n=s(4848),r=s(8453),o=s(9489),a=s(7227);const l={title:"Babel Config option"},i=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Babel Config option"}},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,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:[(0,n.jsx)(t.code,{children:"ts-jest"})," by default does ",(0,n.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,n.jsx)(t.code,{children:"ts-jest"})," can call the BabelJest processor once TypeScript has transformed the source into JavaScript."]}),"\n",(0,n.jsxs)(t.p,{children:["The option is ",(0,n.jsx)(t.code,{children:"babelConfig"})," and it works pretty much as the ",(0,n.jsx)(t.code,{children:"tsconfig"})," option, except that it is disabled by default. Here is the possible values it can take:"]}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"false"}),": the default, disables the use of Babel"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"true"}),": enables Babel processing. ",(0,n.jsx)(t.code,{children:"ts-jest"})," will try to find a ",(0,n.jsx)(t.code,{children:".babelrc"}),", ",(0,n.jsx)(t.code,{children:".babelrc.js"}),", ",(0,n.jsx)(t.code,{children:"babel.config.js"})," file or a ",(0,n.jsx)(t.code,{children:"babel"})," section in the ",(0,n.jsx)(t.code,{children:"package.json"})," file of your project and use it as the config to pass to ",(0,n.jsx)(t.code,{children:"babel-jest"})," processor."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"{ ... }"}),": inline ",(0,n.jsx)(t.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"}),". You can also set this to an empty object (",(0,n.jsx)(t.code,{children:"{}"}),") so that the default Babel config file is not used."]}),"\n"]}),"\n",(0,n.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsxs)(t.h4,{id:"use-default-babelrc-file",children:["Use default ",(0,n.jsx)(t.code,{children:"babelrc"})," file"]}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsxs)(t.h4,{id:"path-to-a-babelrc-file",children:["Path to a ",(0,n.jsx)(t.code,{children:"babelrc"})," file"]}),"\n",(0,n.jsxs)(t.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,n.jsx)(t.code,{children:"\\"})," in the path, or use an absolute path (this last one is strongly not recommended)."]}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.p,{children:"or importing directly the config file:"}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,n.jsxs)(t.p,{children:["Refer to the ",(0,n.jsx)(t.a,{href:"https://babeljs.io/docs/en/next/options",children:"Babel options"})," to know what can be used there."]}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(a.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(a.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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}),b=(()=>{const e=c??x;return p({value:e,tabValues:o})?e:null})();(0,l.A)((()=>{b&&i(b)}),[b]);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 b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var f=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,f.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,f.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",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,f.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,f.jsxs)("div",{className:(0,r.A)("tabs-container",b.tabList),children:[(0,f.jsx)(g,{...t,...e}),(0,f.jsx)(v,{...t,...e})]})}function w(e){const t=(0,m.A)();return(0,f.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.1f683654.js b/assets/js/f6605416.1f683654.js deleted file mode 100644 index c7bdaa0824..0000000000 --- a/assets/js/f6605416.1f683654.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4343],{7727:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>l,default:()=>h,frontMatter:()=>a,metadata:()=>c,toc:()=>p});var s=n(4848),r=n(8453),o=n(9489),i=n(7227);const a={id:"paths-mapping",title:"Paths mapping"},l=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},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,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["If you use ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,s.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,s.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,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,s.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,s.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,s.jsxs)(t.p,{children:["With the below config in your ",(0,s.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,s.jsxs)(o.A,{groupId:"code-examples",children:[(0,s.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(i.A,{value:"JSON",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,s.jsxs)(o.A,{groupId:"code-examples",children:[(0,s.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.p,{children:"With extra options as 2nd argument:"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"prefix"}),": append prefix to each of mapped config in the result"]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"useESM"}),": when using ",(0,s.jsx)(t.code,{children:"type: module"})," in ",(0,s.jsx)(t.code,{children:"package.json"}),", TypeScript enforces users to have explicit ",(0,s.jsx)(t.code,{children:"js"})," extension when importing\na ",(0,s.jsx)(t.code,{children:"ts"})," file. This option is to help ",(0,s.jsx)(t.code,{children:"pathsToModuleNameMapper"})," to create a config to suit with this scenario."]}),"\n"]})]})}function h(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/f6605416.85cd8a2b.js b/assets/js/f6605416.85cd8a2b.js new file mode 100644 index 0000000000..399425f6bd --- /dev/null +++ b/assets/js/f6605416.85cd8a2b.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[4343],{7727:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>l,default:()=>h,frontMatter:()=>a,metadata:()=>c,toc:()=>p});var s=n(4848),r=n(8453),o=n(9489),i=n(7227);const a={id:"paths-mapping",title:"Paths mapping"},l=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["If you use ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,s.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,s.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,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,s.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,s.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,s.jsxs)(t.p,{children:["With the below config in your ",(0,s.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,s.jsxs)(o.A,{groupId:"code-examples",children:[(0,s.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(i.A,{value:"JSON",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,s.jsxs)(o.A,{groupId:"code-examples",children:[(0,s.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.p,{children:"With extra options as 2nd argument:"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"prefix"}),": append prefix to each of mapped config in the result"]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"useESM"}),": when using ",(0,s.jsx)(t.code,{children:"type: module"})," in ",(0,s.jsx)(t.code,{children:"package.json"}),", TypeScript enforces users to have explicit ",(0,s.jsx)(t.code,{children:"js"})," extension when importing\na ",(0,s.jsx)(t.code,{children:"ts"})," file. This option is to help ",(0,s.jsx)(t.code,{children:"pathsToModuleNameMapper"})," to create a config to suit with this scenario."]}),"\n"]})]})}function h(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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.3431234f.js b/assets/js/f6aab920.3431234f.js new file mode 100644 index 0000000000..0914eea5ce --- /dev/null +++ b/assets/js/f6aab920.3431234f.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7320],{2472:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>r,contentTitle:()=>c,default:()=>p,frontMatter:()=>i,metadata:()=>l,toc:()=>a});var o=t(4848),s=t(8453);const i={title:"TypeScript Config option"},c=void 0,l={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"TypeScript Config option"}},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,s.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:["The ",(0,o.jsx)(n.code,{children:"tsconfig"})," option allows you to define which ",(0,o.jsx)(n.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,o.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,o.jsxs)(n.p,{children:["By default ",(0,o.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(n.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,o.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,o.jsx)(n.code,{children:"ES2015"})," is used as ",(0,o.jsx)(n.code,{children:"target"})," instead of ",(0,o.jsx)(n.code,{children:"ES5"}),"."]}),"\n",(0,o.jsxs)(n.p,{children:["If you need to use defaults and force ",(0,o.jsx)(n.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,o.jsx)(n.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,o.jsx)(n.code,{children:"false"}),"."]}),"\n",(0,o.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsxs)(n.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,o.jsx)(n.code,{children:"tsconfig"})," 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 to start from the project root dir."]}),"\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 tsconfig: 'tsconfig.test.json',\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 "tsconfig": "tsconfig.test.json"\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 TypeScript ",(0,o.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,o.jsx)(n.code,{children:"tsconfig.json"}),"'s ",(0,o.jsx)(n.code,{children:"compilerOptions"}),"."]}),"\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 tsconfig: {\n importHelpers: 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 "tsconfig": {\n "importHelpers": true\n }\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,o.jsxs)(n.p,{children:["By default ",(0,o.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,o.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,o.jsx)(n.code,{children:"tsconfig"})," to ",(0,o.jsx)(n.code,{children:"false"}),"."]}),"\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 tsconfig: 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 "tsconfig": false\n }\n }\n }\n}\n'})})]})}function p(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.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/f6aab920.488c7de6.js b/assets/js/f6aab920.488c7de6.js deleted file mode 100644 index db2326cbf6..0000000000 --- a/assets/js/f6aab920.488c7de6.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7320],{2472:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>r,contentTitle:()=>c,default:()=>p,frontMatter:()=>i,metadata:()=>l,toc:()=>a});var o=t(4848),s=t(8453);const i={title:"TypeScript Config option"},c=void 0,l={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"TypeScript Config option"}},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,s.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:["The ",(0,o.jsx)(n.code,{children:"tsconfig"})," option allows you to define which ",(0,o.jsx)(n.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,o.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,o.jsxs)(n.p,{children:["By default ",(0,o.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(n.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,o.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,o.jsx)(n.code,{children:"ES2015"})," is used as ",(0,o.jsx)(n.code,{children:"target"})," instead of ",(0,o.jsx)(n.code,{children:"ES5"}),"."]}),"\n",(0,o.jsxs)(n.p,{children:["If you need to use defaults and force ",(0,o.jsx)(n.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,o.jsx)(n.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,o.jsx)(n.code,{children:"false"}),"."]}),"\n",(0,o.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsxs)(n.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,o.jsx)(n.code,{children:"tsconfig"})," 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 to start from the project root dir."]}),"\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 tsconfig: 'tsconfig.test.json',\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 "tsconfig": "tsconfig.test.json"\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 TypeScript ",(0,o.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,o.jsx)(n.code,{children:"tsconfig.json"}),"'s ",(0,o.jsx)(n.code,{children:"compilerOptions"}),"."]}),"\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 tsconfig: {\n importHelpers: 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 "tsconfig": {\n "importHelpers": true\n }\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,o.jsxs)(n.p,{children:["By default ",(0,o.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,o.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,o.jsx)(n.code,{children:"tsconfig"})," to ",(0,o.jsx)(n.code,{children:"false"}),"."]}),"\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 tsconfig: 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 "tsconfig": false\n }\n }\n }\n}\n'})})]})}function p(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.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.02694181.js b/assets/js/f6f550ec.02694181.js deleted file mode 100644 index ed98b3a0df..0000000000 --- a/assets/js/f6f550ec.02694181.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[983],{9989:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>l,default:()=>h,frontMatter:()=>a,metadata:()=>c,toc:()=>p});var s=n(4848),r=n(8453),o=n(9489),i=n(7227);const a={id:"paths-mapping",title:"Paths mapping"},l=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},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,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["If you use ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,s.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,s.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,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,s.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,s.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,s.jsxs)(t.p,{children:["With the below config in your ",(0,s.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,s.jsxs)(o.A,{groupId:"code-examples",children:[(0,s.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(i.A,{value:"JSON",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,s.jsxs)(o.A,{groupId:"code-examples",children:[(0,s.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.p,{children:"With extra options as 2nd argument:"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"prefix"}),": append prefix to each of mapped config in the result"]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"useESM"}),": when using ",(0,s.jsx)(t.code,{children:"type: module"})," in ",(0,s.jsx)(t.code,{children:"package.json"}),", TypeScript enforces users to have explicit ",(0,s.jsx)(t.code,{children:"js"})," extension when importing\na ",(0,s.jsx)(t.code,{children:"ts"})," file. This option is to help ",(0,s.jsx)(t.code,{children:"pathsToModuleNameMapper"})," to create a config to suit with this scenario."]}),"\n"]})]})}function h(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/f6f550ec.71c76044.js b/assets/js/f6f550ec.71c76044.js new file mode 100644 index 0000000000..503b623d5f --- /dev/null +++ b/assets/js/f6f550ec.71c76044.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[983],{9989:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>l,default:()=>h,frontMatter:()=>a,metadata:()=>c,toc:()=>p});var s=n(4848),r=n(8453),o=n(9489),i=n(7227);const a={id:"paths-mapping",title:"Paths mapping"},l=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["If you use ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,s.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,s.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,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,s.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,s.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,s.jsxs)(t.p,{children:["With the below config in your ",(0,s.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,s.jsxs)(o.A,{groupId:"code-examples",children:[(0,s.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(i.A,{value:"JSON",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,s.jsxs)(o.A,{groupId:"code-examples",children:[(0,s.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.p,{children:"With extra options as 2nd argument:"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"prefix"}),": append prefix to each of mapped config in the result"]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"useESM"}),": when using ",(0,s.jsx)(t.code,{children:"type: module"})," in ",(0,s.jsx)(t.code,{children:"package.json"}),", TypeScript enforces users to have explicit ",(0,s.jsx)(t.code,{children:"js"})," extension when importing\na ",(0,s.jsx)(t.code,{children:"ts"})," file. This option is to help ",(0,s.jsx)(t.code,{children:"pathsToModuleNameMapper"})," to create a config to suit with this scenario."]}),"\n"]})]})}function h(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/f7416098.02a03d42.js b/assets/js/f7416098.02a03d42.js deleted file mode 100644 index d8749551a8..0000000000 --- a/assets/js/f7416098.02a03d42.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2186],{7209:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>d,frontMatter:()=>i,metadata:()=>p,toc:()=>c});var s=n(4848),o=n(8453);const i={id:"paths-mapping",title:"Paths mapping"},r=void 0,p={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:!1,unlisted:!1,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:1726058855e3,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"}},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,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["If you use ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,s.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,s.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,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,s.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,s.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,s.jsxs)(t.p,{children:["With the below config in your ",(0,s.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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/f7416098.a035becd.js b/assets/js/f7416098.a035becd.js new file mode 100644 index 0000000000..2f471f5a4f --- /dev/null +++ b/assets/js/f7416098.a035becd.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2186],{7209:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>d,frontMatter:()=>i,metadata:()=>p,toc:()=>c});var s=n(4848),o=n(8453);const i={id:"paths-mapping",title:"Paths mapping"},r=void 0,p={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["If you use ",(0,s.jsx)(t.a,{href:"https://www.typescriptlang.org/docs/handbook/module-resolution.html",children:'"baseUrl" and "paths" options'})," in your ",(0,s.jsx)(t.code,{children:"tsconfig"})," file, you should make sure the ",(0,s.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,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"ts-jest"})," provides a helper to transform the mapping from ",(0,s.jsx)(t.code,{children:"tsconfig"})," to Jest config format, but it needs the ",(0,s.jsx)(t.code,{children:".js"})," version of the config file."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.h4,{id:"typescript-config",children:"TypeScript config"}),"\n",(0,s.jsxs)(t.p,{children:["With the below config in your ",(0,s.jsx)(t.code,{children:"tsconfig"}),":"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-without-helper",children:"Jest config (without helper)"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.h4,{id:"jest-config-with-helper",children:"Jest config (with helper)"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.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,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.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.8d1b4ebb.js b/assets/js/f7862b07.8d1b4ebb.js new file mode 100644 index 0000000000..db2dced350 --- /dev/null +++ b/assets/js/f7862b07.8d1b4ebb.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8539],{5569:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>h,contentTitle:()=>r,default:()=>l,frontMatter:()=>o,metadata:()=>c,toc:()=>a});var n=s(4848),i=s(8453);const o={id:"contributing",title:"Contributing"},r=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-26.5/contributing.md",tags:[],version:"26.5",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},h={},a=[{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 d(e){const t={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",...(0,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["When contributing to this repository, please first discuss the change you wish to make via ",(0,n.jsxs)(t.a,{href:"https://github.com/kulshekhar/ts-jest/discussions",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," GitHub discussion"]})," or ",(0,n.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,n.jsx)(t.p,{children:"Please note we have a code of conduct, please follow it in all your interactions with the project."}),"\n",(0,n.jsx)(t.h2,{id:"pull-request-process",children:"Pull Request Process"}),"\n",(0,n.jsxs)(t.ol,{children:["\n",(0,n.jsxs)(t.li,{children:["Ensure the tests are passing and that you have latest ",(0,n.jsx)(t.code,{children:"main"})," branch merged in."]}),"\n",(0,n.jsxs)(t.li,{children:["Update the ",(0,n.jsx)(t.code,{children:"docs/"})," with details of your changes if required."]}),"\n",(0,n.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,n.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,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"e2e-testing",children:"E2E Testing"}),"\n",(0,n.jsx)(t.h3,{id:"preparing",children:"Preparing"}),"\n",(0,n.jsxs)(t.p,{children:["The preparation of E2E test directory is done in ",(0,n.jsx)(t.code,{children:"scripts/e2e.js"}),". Here is the process:"]}),"\n",(0,n.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,n.jsx)(t.h3,{id:"running",children:"Running"}),"\n",(0,n.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,n.jsx)(t.code,{children:"e2e/__helpers__/test-case/runtime.ts"}),"):"]}),"\n",(0,n.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 l(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(d,{...e})}):d(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.3f68fa16.js b/assets/js/f7b7430f.3f68fa16.js new file mode 100644 index 0000000000..60b2369c75 --- /dev/null +++ b/assets/js/f7b7430f.3f68fa16.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1678],{4456:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>r,contentTitle:()=>c,default:()=>p,frontMatter:()=>i,metadata:()=>l,toc:()=>a});var o=t(4848),s=t(8453);const i={title:"TypeScript Config option"},c=void 0,l={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"TypeScript Config option"}},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,s.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:["The ",(0,o.jsx)(n.code,{children:"tsconfig"})," option allows you to define which ",(0,o.jsx)(n.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,o.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,o.jsxs)(n.p,{children:["By default ",(0,o.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(n.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,o.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,o.jsx)(n.code,{children:"ES2015"})," is used as ",(0,o.jsx)(n.code,{children:"target"})," instead of ",(0,o.jsx)(n.code,{children:"ES5"}),"."]}),"\n",(0,o.jsxs)(n.p,{children:["If you need to use defaults and force ",(0,o.jsx)(n.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,o.jsx)(n.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,o.jsx)(n.code,{children:"false"}),"."]}),"\n",(0,o.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsxs)(n.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,o.jsx)(n.code,{children:"tsconfig"})," 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 to start from the project root dir."]}),"\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 tsconfig: 'tsconfig.test.json',\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 "tsconfig": "tsconfig.test.json"\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 TypeScript ",(0,o.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,o.jsx)(n.code,{children:"tsconfig.json"}),"'s ",(0,o.jsx)(n.code,{children:"compilerOptions"}),"."]}),"\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 tsconfig: {\n importHelpers: 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 "tsconfig": {\n "importHelpers": true\n }\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,o.jsxs)(n.p,{children:["By default ",(0,o.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,o.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,o.jsx)(n.code,{children:"tsconfig"})," to ",(0,o.jsx)(n.code,{children:"false"}),"."]}),"\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 tsconfig: 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 "tsconfig": false\n }\n }\n }\n}\n'})})]})}function p(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.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/f7b7430f.aceaee6b.js b/assets/js/f7b7430f.aceaee6b.js deleted file mode 100644 index 29a627f7fb..0000000000 --- a/assets/js/f7b7430f.aceaee6b.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[1678],{4456:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>r,contentTitle:()=>c,default:()=>p,frontMatter:()=>i,metadata:()=>l,toc:()=>a});var o=t(4848),s=t(8453);const i={title:"TypeScript Config option"},c=void 0,l={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"TypeScript Config option"}},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,s.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:["The ",(0,o.jsx)(n.code,{children:"tsconfig"})," option allows you to define which ",(0,o.jsx)(n.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,o.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,o.jsxs)(n.p,{children:["By default ",(0,o.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,o.jsx)(n.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,o.jsx)(n.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,o.jsx)(n.code,{children:"ES2015"})," is used as ",(0,o.jsx)(n.code,{children:"target"})," instead of ",(0,o.jsx)(n.code,{children:"ES5"}),"."]}),"\n",(0,o.jsxs)(n.p,{children:["If you need to use defaults and force ",(0,o.jsx)(n.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,o.jsx)(n.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,o.jsx)(n.code,{children:"false"}),"."]}),"\n",(0,o.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,o.jsxs)(n.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,o.jsx)(n.code,{children:"tsconfig"})," 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 to start from the project root dir."]}),"\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 tsconfig: 'tsconfig.test.json',\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 "tsconfig": "tsconfig.test.json"\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 TypeScript ",(0,o.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,o.jsx)(n.code,{children:"tsconfig.json"}),"'s ",(0,o.jsx)(n.code,{children:"compilerOptions"}),"."]}),"\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 tsconfig: {\n importHelpers: 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 "tsconfig": {\n "importHelpers": true\n }\n }\n }\n }\n}\n'})}),"\n",(0,o.jsx)(n.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,o.jsxs)(n.p,{children:["By default ",(0,o.jsx)(n.code,{children:"ts-jest"})," will try to find a ",(0,o.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,o.jsx)(n.code,{children:"tsconfig"})," to ",(0,o.jsx)(n.code,{children:"false"}),"."]}),"\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 tsconfig: 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 "tsconfig": false\n }\n }\n }\n}\n'})})]})}function p(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.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.a066448e.js b/assets/js/f7cb2af4.a066448e.js deleted file mode 100644 index 5ced9faf01..0000000000 --- a/assets/js/f7cb2af4.a066448e.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7036],{7548:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>u,contentTitle:()=>l,default:()=>j,frontMatter:()=>a,metadata:()=>c,toc:()=>d});var n=s(4848),o=s(8453),r=s(9489),i=s(7227);const a={title:"TypeScript Config option"},l=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/tsconfig.md",tags:[],version:"current",lastUpdatedBy:"renovate[bot]",lastUpdatedAt:1726058855e3,frontMatter:{title:"TypeScript Config option"}},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,o.R)(),...t.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:["The ",(0,n.jsx)(e.code,{children:"tsconfig"})," option allows you to define which ",(0,n.jsx)(e.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,n.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,n.jsxs)(e.p,{children:["By default ",(0,n.jsx)(e.code,{children:"ts-jest"})," will try to find a ",(0,n.jsx)(e.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,n.jsx)(e.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,n.jsx)(e.code,{children:"ES2015"})," is used as ",(0,n.jsx)(e.code,{children:"target"})," instead of ",(0,n.jsx)(e.code,{children:"ES5"}),"."]}),"\n",(0,n.jsxs)(e.p,{children:["If you need to use defaults and force ",(0,n.jsx)(e.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,n.jsx)(e.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,n.jsx)(e.code,{children:"false"}),"."]}),"\n",(0,n.jsx)(e.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsxs)(e.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,n.jsx)(e.code,{children:"tsconfig"})," file"]}),"\n",(0,n.jsxs)(e.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,n.jsx)(e.code,{children:""})," in the path to start from the project root dir."]}),"\n",(0,n.jsxs)(r.A,{groupId:"code-examples",children:[(0,n.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"JSON",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(e.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,n.jsxs)(e.p,{children:["Refer to the TypeScript ",(0,n.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,n.jsx)(e.code,{children:"tsconfig.json"}),"'s ",(0,n.jsx)(e.code,{children:"compilerOptions"}),"."]}),"\n",(0,n.jsxs)(r.A,{groupId:"code-examples",children:[(0,n.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"JSON",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(e.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,n.jsxs)(e.p,{children:["By default ",(0,n.jsx)(e.code,{children:"ts-jest"})," will try to find a ",(0,n.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,n.jsx)(e.code,{children:"tsconfig"})," to ",(0,n.jsx)(e.code,{children:"false"}),"."]}),"\n",(0,n.jsxs)(r.A,{groupId:"code-examples",children:[(0,n.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"JSON",children:(0,n.jsx)(e.pre,{children:(0,n.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,o.R)(),...t.components};return e?(0,n.jsx)(e,{...t,children:(0,n.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/f7cb2af4.cd7f1041.js b/assets/js/f7cb2af4.cd7f1041.js new file mode 100644 index 0000000000..48ecbe29a1 --- /dev/null +++ b/assets/js/f7cb2af4.cd7f1041.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[7036],{7548:(t,e,s)=>{s.r(e),s.d(e,{assets:()=>u,contentTitle:()=>l,default:()=>j,frontMatter:()=>a,metadata:()=>c,toc:()=>d});var n=s(4848),o=s(8453),r=s(9489),i=s(7227);const a={title:"TypeScript Config option"},l=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/options/tsconfig.md",tags:[],version:"current",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"TypeScript Config option"}},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,o.R)(),...t.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:["The ",(0,n.jsx)(e.code,{children:"tsconfig"})," option allows you to define which ",(0,n.jsx)(e.code,{children:"tsconfig"})," JSON file to use. An inline ",(0,n.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,n.jsxs)(e.p,{children:["By default ",(0,n.jsx)(e.code,{children:"ts-jest"})," will try to find a ",(0,n.jsx)(e.code,{children:"tsconfig.json"})," in your project. If it cannot find one, it will use the default TypeScript ",(0,n.jsx)(e.a,{href:"https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options",children:"compiler options"}),"; except, ",(0,n.jsx)(e.code,{children:"ES2015"})," is used as ",(0,n.jsx)(e.code,{children:"target"})," instead of ",(0,n.jsx)(e.code,{children:"ES5"}),"."]}),"\n",(0,n.jsxs)(e.p,{children:["If you need to use defaults and force ",(0,n.jsx)(e.code,{children:"ts-jest"})," to use the defaults even if there is a ",(0,n.jsx)(e.code,{children:"tsconfig.json"})," in your project, you can set this option to ",(0,n.jsx)(e.code,{children:"false"}),"."]}),"\n",(0,n.jsx)(e.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsxs)(e.h4,{id:"path-to-a-tsconfig-file",children:["Path to a ",(0,n.jsx)(e.code,{children:"tsconfig"})," file"]}),"\n",(0,n.jsxs)(e.p,{children:["The path should be relative to the current working directory where you start Jest from. You can also use ",(0,n.jsx)(e.code,{children:""})," in the path to start from the project root dir."]}),"\n",(0,n.jsxs)(r.A,{groupId:"code-examples",children:[(0,n.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"JSON",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(e.h4,{id:"inline-compiler-options",children:"Inline compiler options"}),"\n",(0,n.jsxs)(e.p,{children:["Refer to the TypeScript ",(0,n.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,n.jsx)(e.code,{children:"tsconfig.json"}),"'s ",(0,n.jsx)(e.code,{children:"compilerOptions"}),"."]}),"\n",(0,n.jsxs)(r.A,{groupId:"code-examples",children:[(0,n.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"JSON",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(e.h4,{id:"disable-auto-lookup",children:"Disable auto-lookup"}),"\n",(0,n.jsxs)(e.p,{children:["By default ",(0,n.jsx)(e.code,{children:"ts-jest"})," will try to find a ",(0,n.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,n.jsx)(e.code,{children:"tsconfig"})," to ",(0,n.jsx)(e.code,{children:"false"}),"."]}),"\n",(0,n.jsxs)(r.A,{groupId:"code-examples",children:[(0,n.jsx)(i.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(e.pre,{children:(0,n.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,n.jsx)(i.A,{value:"JSON",children:(0,n.jsx)(e.pre,{children:(0,n.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,o.R)(),...t.components};return e?(0,n.jsx)(e,{...t,children:(0,n.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.39046353.js b/assets/js/f8fb2427.39046353.js new file mode 100644 index 0000000000..98f4d0d1f0 --- /dev/null +++ b/assets/js/f8fb2427.39046353.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6734],{911:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>d,contentTitle:()=>l,default:()=>h,frontMatter:()=>a,metadata:()=>c,toc:()=>j});var n=t(4848),i=t(8453),o=t(9489),r=t(7227);const a={title:"Diagnostics option"},l=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Diagnostics option"}},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,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(s.p,{children:["The ",(0,n.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,n.jsxs)(s.p,{children:["If a diagnostic is not filtered out, ",(0,n.jsx)(s.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,n.jsx)(s.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,n.jsxs)(s.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,n.jsx)(s.code,{children:"diagnostics"})," option to ",(0,n.jsx)(s.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,n.jsx)(s.code,{children:"diagnostics"})," to ",(0,n.jsx)(s.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,n.jsx)(s.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,n.jsxs)(s.p,{children:["The ",(0,n.jsx)(s.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"warnOnly"})}),": If specified and ",(0,n.jsx)(s.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,n.jsx)(s.em,{children:"disabled"}),")."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,n.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,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.code,{children:"6059"}),": ",(0,n.jsx)(s.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.code,{children:"18002"}),": ",(0,n.jsx)(s.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.code,{children:"18003"}),": ",(0,n.jsx)(s.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,n.jsx)(s.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,n.jsx)(s.code,{children:"tsconfig"})," option ",(0,n.jsx)(s.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,n.jsx)(s.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,n.jsx)(s.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,n.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsx)(s.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,n.jsx)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,n.jsx)(r.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 "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,n.jsx)(s.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,n.jsx)(s.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,n.jsxs)(s.p,{children:["Assuming all your test files ends with ",(0,n.jsx)(s.code,{children:".spec.ts"})," or ",(0,n.jsx)(s.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,n.jsx)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,n.jsx)(r.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 "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,n.jsx)(s.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,n.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,n.jsx)(s.code,{children:"warnOnly"})," to ",(0,n.jsx)(s.code,{children:"true"}),":"]}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,n.jsx)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,n.jsx)(r.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 "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,n.jsx)(s.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,n.jsxs)(s.p,{children:["All TypeScript error codes can be found ",(0,n.jsx)(s.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,n.jsx)(s.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,n.jsxs)(s.ol,{children:["\n",(0,n.jsxs)(s.li,{children:["A single ",(0,n.jsx)(s.code,{children:"number"})," (example: ",(0,n.jsx)(s.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,n.jsxs)(s.li,{children:["A ",(0,n.jsx)(s.code,{children:"string"})," with a code (example ",(0,n.jsx)(s.code,{children:'"1009"'}),", ",(0,n.jsx)(s.code,{children:'"TS1009"'})," or ",(0,n.jsx)(s.code,{children:'"TS1009"'}),")"]}),"\n",(0,n.jsxs)(s.li,{children:["A ",(0,n.jsx)(s.code,{children:"string"})," with a list of the above (example: ",(0,n.jsx)(s.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,n.jsxs)(s.li,{children:["An ",(0,n.jsx)(s.code,{children:"array"})," of one or more from ",(0,n.jsx)(s.code,{children:"1"})," or ",(0,n.jsx)(s.code,{children:"3"})," (example: ",(0,n.jsx)(s.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,n.jsxs)(o.A,{groupId:"code-examples",children:[(0,n.jsx)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,n.jsx)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,n.jsx)(r.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 "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,i.R)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.jsx)(u,{...e})}):u(e)}},7227:(e,s,t)=>{t.d(s,{A:()=>r});t(6540);var n=t(4164);const i={tabItem:"tabItem_Ymn6"};var o=t(4848);function r(e){let{children:s,hidden:t,className:r}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,n.A)(i.tabItem,r),hidden:t,children:s})}},9489:(e,s,t)=>{t.d(s,{A:()=>w});var n=t(6540),i=t(4164),o=t(4245),r=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,r.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(i.location.search);s.set(o,e),i.replace({...i.location,search:s.toString()})}),[o,i])]}function p(e){const{defaultValue:s,queryString:t=!1,groupId:i}=e,o=u(e),[r,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:o}))),[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,o]=(0,d.Dv)(t);return[i,(0,n.useCallback)((e=>{t&&o.set(e)}),[t,o])]}({groupId:i}),m=(()=>{const e=c??p;return h({value:e,tabValues:o})?e:null})();(0,a.A)((()=>{m&&l(m)}),[m]);return{selectedValue:r,selectValue:(0,n.useCallback)((e=>{if(!h({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);l(e),j(e),g(e)}),[j,g,o]),tabValues:o}}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:r,tabValues:a}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.a_)(),d=e=>{const s=e.currentTarget,t=l.indexOf(s),i=a[t].value;i!==n&&(c(s),r(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:o}=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,...o,className:(0,i.A)("tabs__item",m.tabItem,o?.className,{"tabs__item--active":n===s}),children:t??s},s)}))})}function v(e){let{lazy:s,children:t,selectedValue:o}=e;const r=(Array.isArray(t)?t:[t]).filter(Boolean);if(s){const e=r.find((e=>e.props.value===o));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:r.map(((e,s)=>(0,n.cloneElement)(e,{key:s,hidden:e.props.value!==o})))})}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:()=>r,x:()=>a});var n=t(6540);const i={},o=n.createContext(i);function r(e){const s=n.useContext(o);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:r(e.components),n.createElement(o.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/f8fb2427.71350db3.js b/assets/js/f8fb2427.71350db3.js deleted file mode 100644 index 11b75cdc62..0000000000 --- a/assets/js/f8fb2427.71350db3.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[6734],{911:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>d,contentTitle:()=>l,default:()=>h,frontMatter:()=>a,metadata:()=>c,toc:()=>j});var n=t(4848),i=t(8453),r=t(9489),o=t(7227);const a={title:"Diagnostics option"},l=void 0,c={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Diagnostics option"}},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,i.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(s.p,{children:["The ",(0,n.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,n.jsxs)(s.p,{children:["If a diagnostic is not filtered out, ",(0,n.jsx)(s.code,{children:"ts-jest"})," will fail the compilation and your test."]}),"\n",(0,n.jsx)(s.h3,{id:"disablingenabling",children:"Disabling/enabling"}),"\n",(0,n.jsxs)(s.p,{children:["By default all diagnostics are enabled. This is the same as setting the ",(0,n.jsx)(s.code,{children:"diagnostics"})," option to ",(0,n.jsx)(s.code,{children:"true"}),".\nTo disable all diagnostics, set ",(0,n.jsx)(s.code,{children:"diagnostics"})," to ",(0,n.jsx)(s.code,{children:"false"}),".\nThis might lead to slightly better performance, especially if you're not using Jest's cache."]}),"\n",(0,n.jsx)(s.h3,{id:"advanced-configuration",children:"Advanced configuration"}),"\n",(0,n.jsxs)(s.p,{children:["The ",(0,n.jsx)(s.code,{children:"diagnostics"})," option's value can also accept an object for more advanced configuration. Each config. key is optional:"]}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"warnOnly"})}),": If specified and ",(0,n.jsx)(s.code,{children:"true"}),", diagnostics will be reported but won't stop compilation (default: ",(0,n.jsx)(s.em,{children:"disabled"}),")."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"ignoreCodes"})}),": List of TypeScript error codes to ignore. Complete list can be found ",(0,n.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,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.code,{children:"6059"}),": ",(0,n.jsx)(s.em,{children:"'rootDir' is expected to contain all source files."})]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.code,{children:"18002"}),": ",(0,n.jsx)(s.em,{children:"The 'files' list in config file is empty."})," (it is strongly recommended including this one)"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.code,{children:"18003"}),": ",(0,n.jsx)(s.em,{children:"No inputs were found in config file."})]}),"\n"]}),"\n"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"exclude"})}),": If specified, diagnostics of source files which path ",(0,n.jsx)(s.strong,{children:"matches"})," will be ignored. This works a bit\nsimilar to ",(0,n.jsx)(s.code,{children:"tsconfig"})," option ",(0,n.jsx)(s.a,{href:"https://www.typescriptlang.org/tsconfig#exclude",children:"exclude"})," with the only difference is that\nin TypeScript, ",(0,n.jsx)(s.code,{children:"exclude"})," will also exclude files from compilation process."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.strong,{children:(0,n.jsx)(s.code,{children:"pretty"})}),": Enables/disables colorful and pretty output of errors (default: ",(0,n.jsx)(s.em,{children:"enabled"}),")."]}),"\n"]}),"\n",(0,n.jsx)(s.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsx)(s.h4,{id:"disabling-diagnostics",children:"Disabling diagnostics"}),"\n",(0,n.jsxs)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 "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,n.jsx)(s.h4,{id:"advanced-options",children:"Advanced options"}),"\n",(0,n.jsx)(s.h5,{id:"enabling-diagnostics-for-test-files-only",children:"Enabling diagnostics for test files only"}),"\n",(0,n.jsxs)(s.p,{children:["Assuming all your test files ends with ",(0,n.jsx)(s.code,{children:".spec.ts"})," or ",(0,n.jsx)(s.code,{children:".test.ts"}),", using the following config will enable error reporting only for those files:"]}),"\n",(0,n.jsxs)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 "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,n.jsx)(s.h5,{id:"do-not-fail-on-first-error",children:"Do not fail on first error"}),"\n",(0,n.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,n.jsx)(s.code,{children:"warnOnly"})," to ",(0,n.jsx)(s.code,{children:"true"}),":"]}),"\n",(0,n.jsxs)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 "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,n.jsx)(s.h5,{id:"ignoring-some-error-codes",children:"Ignoring some error codes"}),"\n",(0,n.jsxs)(s.p,{children:["All TypeScript error codes can be found ",(0,n.jsx)(s.a,{href:"https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json",children:"there"}),". The ",(0,n.jsx)(s.code,{children:"ignoreCodes"})," option accepts this values:"]}),"\n",(0,n.jsxs)(s.ol,{children:["\n",(0,n.jsxs)(s.li,{children:["A single ",(0,n.jsx)(s.code,{children:"number"})," (example: ",(0,n.jsx)(s.code,{children:"1009"}),"): unique error code to ignore"]}),"\n",(0,n.jsxs)(s.li,{children:["A ",(0,n.jsx)(s.code,{children:"string"})," with a code (example ",(0,n.jsx)(s.code,{children:'"1009"'}),", ",(0,n.jsx)(s.code,{children:'"TS1009"'})," or ",(0,n.jsx)(s.code,{children:'"TS1009"'}),")"]}),"\n",(0,n.jsxs)(s.li,{children:["A ",(0,n.jsx)(s.code,{children:"string"})," with a list of the above (example: ",(0,n.jsx)(s.code,{children:'"1009, TS2571, 4072"'}),")"]}),"\n",(0,n.jsxs)(s.li,{children:["An ",(0,n.jsx)(s.code,{children:"array"})," of one or more from ",(0,n.jsx)(s.code,{children:"1"})," or ",(0,n.jsx)(s.code,{children:"3"})," (example: ",(0,n.jsx)(s.code,{children:'[1009, "TS2571", "6031"]'}),")"]}),"\n"]}),"\n",(0,n.jsxs)(r.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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 transform: {\n // '^.+\\\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`\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,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 "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,i.R)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.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.17f8fb1a.js b/assets/js/fa061f97.17f8fb1a.js deleted file mode 100644 index 2333018bd4..0000000000 --- a/assets/js/fa061f97.17f8fb1a.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9547],{9683:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>l,default:()=>p,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var n=s(4848),r=s(8453),a=s(9489),o=s(7227);const i={title:"AST transformers option"},l=void 0,c={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"AST transformers option"}},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,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:[(0,n.jsx)(t.code,{children:"ts-jest"})," by default does hoisting for a few ",(0,n.jsx)(t.code,{children:"jest"})," methods via a TypeScript AST transformer. One can also create custom\nTypeScript AST transformers and provide them to ",(0,n.jsx)(t.code,{children:"ts-jest"})," to include into compilation process."]}),"\n",(0,n.jsxs)(t.p,{children:["The option is ",(0,n.jsx)(t.code,{children:"astTransformers"})," and it allows ones to specify which 3 types of TypeScript AST transformers to use with ",(0,n.jsx)(t.code,{children:"ts-jest"}),":"]}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.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,n.jsx)(t.code,{children:"import"})," instead of ",(0,n.jsx)(t.code,{children:"require"})," or ",(0,n.jsx)(t.code,{children:"define"})," )."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"after"})," means your transformers get run after TS ones, which gets transpiled syntax."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"afterDeclarations"})," means your transformers get run during ",(0,n.jsx)(t.code,{children:"d.ts"})," generation phase, allowing you to transform output type declarations."]}),"\n"]}),"\n",(0,n.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsx)(t.h4,{id:"basic-transformers",children:"Basic Transformers"}),"\n",(0,n.jsxs)(a.A,{groupId:"code-examples",children:[(0,n.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.h4,{id:"configuring-transformers-with-options",children:"Configuring transformers with options"}),"\n",(0,n.jsxs)(a.A,{groupId:"code-examples",children:[(0,n.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.h3,{id:"writing-custom-typescript-ast-transformers",children:"Writing custom TypeScript AST transformers"}),"\n",(0,n.jsxs)(t.p,{children:["To write a custom TypeScript AST transformers, one can take a look at ",(0,n.jsx)(t.a,{href:"https://github.com/kulshekhar/ts-jest/tree/main/src/transformers",children:"the one"})," that ",(0,n.jsx)(t.code,{children:"ts-jest"})," is using."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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/fa061f97.24b20705.js b/assets/js/fa061f97.24b20705.js new file mode 100644 index 0000000000..184a3bc520 --- /dev/null +++ b/assets/js/fa061f97.24b20705.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9547],{9683:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>u,contentTitle:()=>l,default:()=>p,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var n=s(4848),r=s(8453),a=s(9489),o=s(7227);const i={title:"AST transformers option"},l=void 0,c={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"AST transformers option"}},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,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:[(0,n.jsx)(t.code,{children:"ts-jest"})," by default does hoisting for a few ",(0,n.jsx)(t.code,{children:"jest"})," methods via a TypeScript AST transformer. One can also create custom\nTypeScript AST transformers and provide them to ",(0,n.jsx)(t.code,{children:"ts-jest"})," to include into compilation process."]}),"\n",(0,n.jsxs)(t.p,{children:["The option is ",(0,n.jsx)(t.code,{children:"astTransformers"})," and it allows ones to specify which 3 types of TypeScript AST transformers to use with ",(0,n.jsx)(t.code,{children:"ts-jest"}),":"]}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.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,n.jsx)(t.code,{children:"import"})," instead of ",(0,n.jsx)(t.code,{children:"require"})," or ",(0,n.jsx)(t.code,{children:"define"})," )."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"after"})," means your transformers get run after TS ones, which gets transpiled syntax."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"afterDeclarations"})," means your transformers get run during ",(0,n.jsx)(t.code,{children:"d.ts"})," generation phase, allowing you to transform output type declarations."]}),"\n"]}),"\n",(0,n.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,n.jsx)(t.h4,{id:"basic-transformers",children:"Basic Transformers"}),"\n",(0,n.jsxs)(a.A,{groupId:"code-examples",children:[(0,n.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.h4,{id:"configuring-transformers-with-options",children:"Configuring transformers with options"}),"\n",(0,n.jsxs)(a.A,{groupId:"code-examples",children:[(0,n.jsx)(o.A,{value:"js",label:"JavaScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"ts",label:"TypeScript",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(o.A,{value:"JSON",children:(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.h3,{id:"writing-custom-typescript-ast-transformers",children:"Writing custom TypeScript AST transformers"}),"\n",(0,n.jsxs)(t.p,{children:["To write a custom TypeScript AST transformers, one can take a look at ",(0,n.jsx)(t.a,{href:"https://github.com/kulshekhar/ts-jest/tree/main/src/transformers",children:"the one"})," that ",(0,n.jsx)(t.code,{children:"ts-jest"})," is using."]})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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.b3445ff3.js b/assets/js/fb1b7a48.b3445ff3.js new file mode 100644 index 0000000000..c9f5f558c3 --- /dev/null +++ b/assets/js/fb1b7a48.b3445ff3.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9566],{7698:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>i,metadata:()=>a,toc:()=>d});var s=n(4848),o=n(8453);const i={title:"Stringify content option"},r=void 0,a={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Stringify content option"}},c={},d=[{value:"Example",id:"example",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["The ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,s.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,s.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,s.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,s.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,s.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,s.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,s.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,s.jsx)(t.code,{children:"transform"})," option pointing to ",(0,s.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,s.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsxs)(t.p,{children:["In the ",(0,s.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,s.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,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.pre,{children:(0,s.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,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(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/fb1b7a48.c2c15ab6.js b/assets/js/fb1b7a48.c2c15ab6.js deleted file mode 100644 index eef8dd3d7f..0000000000 --- a/assets/js/fb1b7a48.c2c15ab6.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9566],{7698:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>h,frontMatter:()=>i,metadata:()=>a,toc:()=>d});var s=n(4848),o=n(8453);const i={title:"Stringify content option"},r=void 0,a={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Stringify content option"}},c={},d=[{value:"Example",id:"example",level:3}];function l(e){const t={code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["The ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," option has been kept for backward compatibility of ",(0,s.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,s.jsxs)(t.p,{children:["Let's say for example that you have a file ",(0,s.jsx)(t.code,{children:"foo.ts"})," which contains ",(0,s.jsx)(t.code,{children:'export default "bar"'}),", and your ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," is set to ",(0,s.jsx)(t.code,{children:"foo\\\\.ts$"}),", the resulting module won't be the result of compiling ",(0,s.jsx)(t.code,{children:"foo.ts"})," source, but instead it'll be a module which exports the string ",(0,s.jsx)(t.code,{children:'"export default \\"bar\\""'}),"."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.strong,{children:"CAUTION"}),": Whatever file(s) you want to match with ",(0,s.jsx)(t.code,{children:"stringifyContentPathRegex"})," pattern, you must ensure the Jest ",(0,s.jsx)(t.code,{children:"transform"})," option pointing to ",(0,s.jsx)(t.code,{children:"ts-jest"})," matches them. You may also have to add the extension(s) of this/those file(s) to ",(0,s.jsx)(t.code,{children:"moduleFileExtensions"})," Jest option."]}),"\n",(0,s.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,s.jsxs)(t.p,{children:["In the ",(0,s.jsx)(t.code,{children:"jest.config.js"})," version, you could do as in the ",(0,s.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,s.jsx)(t.pre,{children:(0,s.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,s.jsx)(t.pre,{children:(0,s.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,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(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.ab1b88bf.js b/assets/js/fc43d853.ab1b88bf.js deleted file mode 100644 index 72c1183e8c..0000000000 --- a/assets/js/fc43d853.ab1b88bf.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5609],{1850:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>a,frontMatter:()=>r,metadata:()=>c,toc:()=>u});var n=s(4848),o=s(8453);const r={id:"processing",title:"Processing flow"},i=void 0,c={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:!1,unlisted:!1,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:1726058855e3,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"}},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,o.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,n.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,n.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,n.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,o.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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/fc43d853.ad548b34.js b/assets/js/fc43d853.ad548b34.js new file mode 100644 index 0000000000..112ed0f27c --- /dev/null +++ b/assets/js/fc43d853.ad548b34.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[5609],{1850:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>a,frontMatter:()=>r,metadata:()=>c,toc:()=>d});var n=s(4848),o=s(8453);const r={id:"processing",title:"Processing flow"},i=void 0,c={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/processing.md",tags:[],version:"29.2",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},l={},d=[{value:"Jest process",id:"jest-process",level:2},{value:"ts-jest process",id:"ts-jest-process",level:2}];function u(e){const t={code:"code",em:"em",h2:"h2",img:"img",p:"p",...(0,o.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.p,{children:(0,n.jsxs)(t.em,{children:["These are internal technical documents. If you're not a contributor to ",(0,n.jsx)(t.code,{children:"ts-jest"}),", but simply trying to use the library you'll find nothing of value here"]})}),"\n",(0,n.jsx)(t.h2,{id:"jest-process",children:"Jest process"}),"\n",(0,n.jsx)(t.img,{src:"https://www.plantuml.com/plantuml/png/NP0n5e8m44Jxd68xaq8E08M5fQU8C97uS8FPJS7jVI0FmNRspyo-4VLPZQaptYLcs5E80qwkCIO6ihqNygJPiuIKNnT7seF9JX2t0Di9cMRu0RtwjiSDqn6kTsIresnLLQun60HaEJbJ5m4z8Kht4WSzHsuCk8lX-r5aQcVhN_fiMdHg4ojO3v7xxZ6d5Y9hRrt6pklgtOf-rbNOvfc70NSV"}),"\n",(0,n.jsxs)(t.h2,{id:"ts-jest-process",children:[(0,n.jsx)(t.code,{children:"ts-jest"})," process"]}),"\n",(0,n.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,o.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(u,{...e})}):u(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.19c809a7.js b/assets/js/fc80686b.19c809a7.js new file mode 100644 index 0000000000..3957fe5700 --- /dev/null +++ b/assets/js/fc80686b.19c809a7.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2440],{5675:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>a,contentTitle:()=>d,default:()=>x,frontMatter:()=>i,metadata:()=>o,toc:()=>j});var r=t(4848),n=t(8453),c=t(9489),l=t(7227);const i={id:"presets",title:"Presets"},d=void 0,o={id:"getting-started/presets",title:"Presets",description:"The presets",source:"@site/docs/getting-started/presets.md",sourceDirName:"getting-started",slug:"/getting-started/presets",permalink:"/ts-jest/docs/next/getting-started/presets",draft:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/presets.md",tags:[],version:"current",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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={a:"a",admonition:"admonition",code:"code",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,n.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.jsx)(s.admonition,{type:"caution",children:(0,r.jsxs)(s.p,{children:["The list of ",(0,r.jsx)(s.code,{children:"preset"})," below is now deprecated in favor of util functions. If one is using ",(0,r.jsx)(s.code,{children:"preset"})," in Jest config, please run ",(0,r.jsx)(s.code,{children:"npx ts-jest config:migrate"})," or look into ",(0,r.jsx)(s.a,{href:"#advanced",children:"Advanced"})," section below for alternative solutions."]})}),"\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.jsxs)(c.A,{groupId:"code-examples",children:[(0,r.jsx)(l.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\nconst { createDefaultPreset } = require('ts-jest')\n\nconst defaultPreset = createDefaultPreset()\n\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 ...defaultPreset,\n}\n"})})}),(0,r.jsx)(l.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, createDefaultPreset } from 'ts-jest'\n\nconst defaultPreset = createDefaultPreset()\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n // Replace `ts-jest` with the preset you want to use\n // from the above list\n ...defaultPreset,\n}\n\nexport default jestConfig\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.jsx)(s.p,{children:"There are several util functions to create and extend the existing presets:"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createDefaultPreset"}),": for default preset"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createDefaultLegacyPreset"}),": for default preset in legacy mode"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createDefaultEsmPreset"}),": for default ESM preset"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createDefaultEsmLegacyPreset"}),": for default ESM preset in legacy mode"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithTsPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-ts"})," preset"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithTsLegacyPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-ts"})," preset in legacy mode"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithTsEsmPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-ts"})," ESM preset"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithTsEsmLegacyPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-ts"})," ESM preset in legacy mode"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithBabelPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-babel"})," preset"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithBabelLegacyPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-babel"})," preset in legacy mode"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithBabelEsmPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-babel"})," ESM preset"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithBabelEsmLegacyPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-babel"})," ESM preset in legacy mode"]}),"\n"]}),"\n",(0,r.jsx)(s.p,{children:"Example:"}),"\n",(0,r.jsxs)(c.A,{groupId:"code-examples",children:[(0,r.jsx)(l.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\nconst { createDefaultPreset } = require('ts-jest')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n ...createDefaultPreset().transform,\n // [...]\n },\n}\n"})})}),(0,r.jsx)(l.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 { createDefaultPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n ...createDefaultPreset().transform,\n // [...]\n },\n}\n\nexport default jestConfig\n"})})})]})]})}function x(e={}){const{wrapper:s}={...(0,n.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},7227:(e,s,t)=>{t.d(s,{A:()=>l});t(6540);var r=t(4164);const n={tabItem:"tabItem_Ymn6"};var c=t(4848);function l(e){let{children:s,hidden:t,className:l}=e;return(0,c.jsx)("div",{role:"tabpanel",className:(0,r.A)(n.tabItem,l),hidden:t,children:s})}},9489:(e,s,t)=>{t.d(s,{A:()=>w});var r=t(6540),n=t(4164),c=t(4245),l=t(6347),i=t(6494),d=t(2814),o=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,o.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 x(e){let{value:s,tabValues:t}=e;return t.some((e=>e.value===s))}function u(e){let{queryString:s=!1,groupId:t}=e;const n=(0,l.W6)(),c=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,d.aZ)(c),(0,r.useCallback)((e=>{if(!c)return;const s=new URLSearchParams(n.location.search);s.set(c,e),n.replace({...n.location,search:s.toString()})}),[c,n])]}function p(e){const{defaultValue:s,queryString:t=!1,groupId:n}=e,c=h(e),[l,d]=(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(!x({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:c}))),[o,j]=u({queryString:t,groupId:n}),[p,f]=function(e){let{groupId:s}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(s),[n,c]=(0,a.Dv)(t);return[n,(0,r.useCallback)((e=>{t&&c.set(e)}),[t,c])]}({groupId:n}),b=(()=>{const e=o??p;return x({value:e,tabValues:c})?e:null})();(0,i.A)((()=>{b&&d(b)}),[b]);return{selectedValue:l,selectValue:(0,r.useCallback)((e=>{if(!x({value:e,tabValues:c}))throw new Error(`Can't select invalid tab value=${e}`);d(e),j(e),f(e)}),[j,f,c]),tabValues:c}}var f=t(1062);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var m=t(4848);function g(e){let{className:s,block:t,selectedValue:r,selectValue:l,tabValues:i}=e;const d=[],{blockElementScrollPositionUntilNextRender:o}=(0,c.a_)(),a=e=>{const s=e.currentTarget,t=d.indexOf(s),n=i[t].value;n!==r&&(o(s),l(n))},j=e=>{let s=null;switch(e.key){case"Enter":a(e);break;case"ArrowRight":{const t=d.indexOf(e.currentTarget)+1;s=d[t]??d[0];break}case"ArrowLeft":{const t=d.indexOf(e.currentTarget)-1;s=d[t]??d[d.length-1];break}}s?.focus()};return(0,m.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,n.A)("tabs",{"tabs--block":t},s),children:i.map((e=>{let{value:s,label:t,attributes:c}=e;return(0,m.jsx)("li",{role:"tab",tabIndex:r===s?0:-1,"aria-selected":r===s,ref:e=>d.push(e),onKeyDown:j,onClick:a,...c,className:(0,n.A)("tabs__item",b.tabItem,c?.className,{"tabs__item--active":r===s}),children:t??s},s)}))})}function y(e){let{lazy:s,children:t,selectedValue:c}=e;const l=(Array.isArray(t)?t:[t]).filter(Boolean);if(s){const e=l.find((e=>e.props.value===c));return e?(0,r.cloneElement)(e,{className:(0,n.A)("margin-top--md",e.props.className)}):null}return(0,m.jsx)("div",{className:"margin-top--md",children:l.map(((e,s)=>(0,r.cloneElement)(e,{key:s,hidden:e.props.value!==c})))})}function v(e){const s=p(e);return(0,m.jsxs)("div",{className:(0,n.A)("tabs-container",b.tabList),children:[(0,m.jsx)(g,{...s,...e}),(0,m.jsx)(y,{...s,...e})]})}function w(e){const s=(0,f.A)();return(0,m.jsx)(v,{...e,children:j(e.children)},String(s))}},8453:(e,s,t)=>{t.d(s,{R:()=>l,x:()=>i});var r=t(6540);const n={},c=r.createContext(n);function l(e){const s=r.useContext(c);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(n):e.components||n:l(e.components),r.createElement(c.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/fc80686b.701efd24.js b/assets/js/fc80686b.701efd24.js deleted file mode 100644 index a358c2472b..0000000000 --- a/assets/js/fc80686b.701efd24.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[2440],{5675:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>a,contentTitle:()=>d,default:()=>x,frontMatter:()=>i,metadata:()=>o,toc:()=>j});var r=t(4848),n=t(8453),c=t(9489),l=t(7227);const i={id:"presets",title:"Presets"},d=void 0,o={id:"getting-started/presets",title:"Presets",description:"The presets",source:"@site/docs/getting-started/presets.md",sourceDirName:"getting-started",slug:"/getting-started/presets",permalink:"/ts-jest/docs/next/getting-started/presets",draft:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/docs/getting-started/presets.md",tags:[],version:"current",lastUpdatedBy:"renovate[bot]",lastUpdatedAt:1726058855e3,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"}},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={a:"a",admonition:"admonition",code:"code",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,n.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.jsx)(s.admonition,{type:"caution",children:(0,r.jsxs)(s.p,{children:["The list of ",(0,r.jsx)(s.code,{children:"preset"})," below is now deprecated in favor of util functions. If one is using ",(0,r.jsx)(s.code,{children:"preset"})," in Jest config, please run ",(0,r.jsx)(s.code,{children:"npx ts-jest config:migrate"})," or look into ",(0,r.jsx)(s.a,{href:"#advanced",children:"Advanced"})," section below for alternative solutions."]})}),"\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.jsxs)(c.A,{groupId:"code-examples",children:[(0,r.jsx)(l.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\nconst { createDefaultPreset } = require('ts-jest')\n\nconst defaultPreset = createDefaultPreset()\n\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 ...defaultPreset,\n}\n"})})}),(0,r.jsx)(l.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, createDefaultPreset } from 'ts-jest'\n\nconst defaultPreset = createDefaultPreset()\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n // Replace `ts-jest` with the preset you want to use\n // from the above list\n ...defaultPreset,\n}\n\nexport default jestConfig\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.jsx)(s.p,{children:"There are several util functions to create and extend the existing presets:"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createDefaultPreset"}),": for default preset"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createDefaultLegacyPreset"}),": for default preset in legacy mode"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createDefaultEsmPreset"}),": for default ESM preset"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createDefaultEsmLegacyPreset"}),": for default ESM preset in legacy mode"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithTsPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-ts"})," preset"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithTsLegacyPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-ts"})," preset in legacy mode"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithTsEsmPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-ts"})," ESM preset"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithTsEsmLegacyPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-ts"})," ESM preset in legacy mode"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithBabelPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-babel"})," preset"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithBabelLegacyPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-babel"})," preset in legacy mode"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithBabelEsmPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-babel"})," ESM preset"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"createJsWithBabelEsmLegacyPreset"}),": for ",(0,r.jsx)(s.code,{children:"js-with-babel"})," ESM preset in legacy mode"]}),"\n"]}),"\n",(0,r.jsx)(s.p,{children:"Example:"}),"\n",(0,r.jsxs)(c.A,{groupId:"code-examples",children:[(0,r.jsx)(l.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\nconst { createDefaultPreset } = require('ts-jest')\n\n/** @type {import('ts-jest').JestConfigWithTsJest} */\nmodule.exports = {\n // [...]\n transform: {\n ...createDefaultPreset().transform,\n // [...]\n },\n}\n"})})}),(0,r.jsx)(l.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 { createDefaultPreset, type JestConfigWithTsJest } from 'ts-jest'\n\nconst jestConfig: JestConfigWithTsJest = {\n // [...]\n transform: {\n ...createDefaultPreset().transform,\n // [...]\n },\n}\n\nexport default jestConfig\n"})})})]})]})}function x(e={}){const{wrapper:s}={...(0,n.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},7227:(e,s,t)=>{t.d(s,{A:()=>l});t(6540);var r=t(4164);const n={tabItem:"tabItem_Ymn6"};var c=t(4848);function l(e){let{children:s,hidden:t,className:l}=e;return(0,c.jsx)("div",{role:"tabpanel",className:(0,r.A)(n.tabItem,l),hidden:t,children:s})}},9489:(e,s,t)=>{t.d(s,{A:()=>w});var r=t(6540),n=t(4164),c=t(4245),l=t(6347),i=t(6494),d=t(2814),o=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,o.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 x(e){let{value:s,tabValues:t}=e;return t.some((e=>e.value===s))}function u(e){let{queryString:s=!1,groupId:t}=e;const n=(0,l.W6)(),c=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,d.aZ)(c),(0,r.useCallback)((e=>{if(!c)return;const s=new URLSearchParams(n.location.search);s.set(c,e),n.replace({...n.location,search:s.toString()})}),[c,n])]}function p(e){const{defaultValue:s,queryString:t=!1,groupId:n}=e,c=h(e),[l,d]=(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(!x({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:c}))),[o,j]=u({queryString:t,groupId:n}),[p,f]=function(e){let{groupId:s}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(s),[n,c]=(0,a.Dv)(t);return[n,(0,r.useCallback)((e=>{t&&c.set(e)}),[t,c])]}({groupId:n}),b=(()=>{const e=o??p;return x({value:e,tabValues:c})?e:null})();(0,i.A)((()=>{b&&d(b)}),[b]);return{selectedValue:l,selectValue:(0,r.useCallback)((e=>{if(!x({value:e,tabValues:c}))throw new Error(`Can't select invalid tab value=${e}`);d(e),j(e),f(e)}),[j,f,c]),tabValues:c}}var f=t(1062);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var m=t(4848);function g(e){let{className:s,block:t,selectedValue:r,selectValue:l,tabValues:i}=e;const d=[],{blockElementScrollPositionUntilNextRender:o}=(0,c.a_)(),a=e=>{const s=e.currentTarget,t=d.indexOf(s),n=i[t].value;n!==r&&(o(s),l(n))},j=e=>{let s=null;switch(e.key){case"Enter":a(e);break;case"ArrowRight":{const t=d.indexOf(e.currentTarget)+1;s=d[t]??d[0];break}case"ArrowLeft":{const t=d.indexOf(e.currentTarget)-1;s=d[t]??d[d.length-1];break}}s?.focus()};return(0,m.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,n.A)("tabs",{"tabs--block":t},s),children:i.map((e=>{let{value:s,label:t,attributes:c}=e;return(0,m.jsx)("li",{role:"tab",tabIndex:r===s?0:-1,"aria-selected":r===s,ref:e=>d.push(e),onKeyDown:j,onClick:a,...c,className:(0,n.A)("tabs__item",b.tabItem,c?.className,{"tabs__item--active":r===s}),children:t??s},s)}))})}function y(e){let{lazy:s,children:t,selectedValue:c}=e;const l=(Array.isArray(t)?t:[t]).filter(Boolean);if(s){const e=l.find((e=>e.props.value===c));return e?(0,r.cloneElement)(e,{className:(0,n.A)("margin-top--md",e.props.className)}):null}return(0,m.jsx)("div",{className:"margin-top--md",children:l.map(((e,s)=>(0,r.cloneElement)(e,{key:s,hidden:e.props.value!==c})))})}function v(e){const s=p(e);return(0,m.jsxs)("div",{className:(0,n.A)("tabs-container",b.tabList),children:[(0,m.jsx)(g,{...s,...e}),(0,m.jsx)(y,{...s,...e})]})}function w(e){const s=(0,f.A)();return(0,m.jsx)(v,{...e,children:j(e.children)},String(s))}},8453:(e,s,t)=>{t.d(s,{R:()=>l,x:()=>i});var r=t(6540);const n={},c=r.createContext(n);function l(e){const s=r.useContext(c);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(n):e.components||n:l(e.components),r.createElement(c.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/fdcb7476.0eb8d33a.js b/assets/js/fdcb7476.0eb8d33a.js deleted file mode 100644 index c55e2a1ad7..0000000000 --- a/assets/js/fdcb7476.0eb8d33a.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9660],{795:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>r,default:()=>j,frontMatter:()=>o,metadata:()=>d,toc:()=>l});var t=n(4848),i=n(8453);const o={id:"options",title:"Options"},r=void 0,d={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:!1,unlisted:!1,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:1726058855e3,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"}},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,i.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(s.h3,{id:"introduction",children:"Introduction"}),"\n",(0,t.jsxs)(s.p,{children:["All ",(0,t.jsx)(s.code,{children:"ts-jest"})," specific options are located under the ",(0,t.jsx)(s.code,{children:"globals"})," of Jest config object in the ",(0,t.jsx)(s.code,{children:"package.json"})," file of your project,\nor through a ",(0,t.jsx)(s.code,{children:"jest.config.js"}),", or ",(0,t.jsx)(s.code,{children:"jest.config.ts"})," file."]}),"\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 // ts-jest configuration goes here\n }\n }\n }\n}\n'})}),"\n",(0,t.jsx)(s.p,{children:"Or through JavaScript:"}),"\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 // ts-jest configuration goes here\n },\n },\n}\n"})}),"\n",(0,t.jsxs)(s.admonition,{type:"tip",children:[(0,t.jsxs)(s.p,{children:["To utilize IDE suggestions, you can use ",(0,t.jsx)(s.code,{children:"JSDoc"})," comments to provide suggested ",(0,t.jsx)(s.code,{children:"ts-jest"})," configs for your Jest config:"]}),(0,t.jsx)(s.pre,{children:(0,t.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,t.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,t.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.admonition,{type:"important",children:(0,t.jsxs)(s.p,{children:["When using TypeScript Jest config file, Jest will use ",(0,t.jsx)(s.code,{children:"ts-node"})," to compile the config file. ",(0,t.jsx)(s.code,{children:"ts-jest"})," doesn't take part in\nthat process."]})}),"\n",(0,t.jsx)(s.h3,{id:"options",children:"Options"}),"\n",(0,t.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,t.jsxs)(s.table,{children:[(0,t.jsx)(s.thead,{children:(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.th,{children:"Option"}),(0,t.jsx)(s.th,{children:"Description"}),(0,t.jsx)(s.th,{children:"Type"}),(0,t.jsx)(s.th,{children:"Default"})]})}),(0,t.jsxs)(s.tbody,{children:[(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/compiler",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"compiler"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"string"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:'"typescript"'})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/tsconfig",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"tsconfig"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"string"}),"|",(0,t.jsx)(s.code,{children:"object"}),"|",(0,t.jsx)(s.code,{children:"boolean"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"auto"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/isolatedModules",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"isolatedModules"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"boolean"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"disabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/astTransformers",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"astTransformers"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"object"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"auto"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/diagnostics",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"diagnostics"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"boolean"}),"|",(0,t.jsx)(s.code,{children:"object"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"enabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/babelConfig",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"babelConfig"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"boolean"}),"|",(0,t.jsx)(s.code,{children:"string"}),"|",(0,t.jsx)(s.code,{children:"object"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"disabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"stringifyContentPathRegex"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"string"}),"|",(0,t.jsx)(s.code,{children:"RegExp"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"disabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/useESM",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"useESM"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/useESM",children:"Enable ESM support"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"boolean"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"auto"})})]})]})]})]})}function j(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.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/fdcb7476.a2ed2b08.js b/assets/js/fdcb7476.a2ed2b08.js new file mode 100644 index 0000000000..de8608b190 --- /dev/null +++ b/assets/js/fdcb7476.a2ed2b08.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[9660],{795:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>r,default:()=>j,frontMatter:()=>o,metadata:()=>d,toc:()=>l});var t=n(4848),i=n(8453);const o={id:"options",title:"Options"},r=void 0,d={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-27.1/getting-started/options.md",tags:[],version:"27.1",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,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"}},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,i.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(s.h3,{id:"introduction",children:"Introduction"}),"\n",(0,t.jsxs)(s.p,{children:["All ",(0,t.jsx)(s.code,{children:"ts-jest"})," specific options are located under the ",(0,t.jsx)(s.code,{children:"globals"})," of Jest config object in the ",(0,t.jsx)(s.code,{children:"package.json"})," file of your project,\nor through a ",(0,t.jsx)(s.code,{children:"jest.config.js"}),", or ",(0,t.jsx)(s.code,{children:"jest.config.ts"})," file."]}),"\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 // ts-jest configuration goes here\n }\n }\n }\n}\n'})}),"\n",(0,t.jsx)(s.p,{children:"Or through JavaScript:"}),"\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 // ts-jest configuration goes here\n },\n },\n}\n"})}),"\n",(0,t.jsxs)(s.admonition,{type:"tip",children:[(0,t.jsxs)(s.p,{children:["To utilize IDE suggestions, you can use ",(0,t.jsx)(s.code,{children:"JSDoc"})," comments to provide suggested ",(0,t.jsx)(s.code,{children:"ts-jest"})," configs for your Jest config:"]}),(0,t.jsx)(s.pre,{children:(0,t.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,t.jsxs)(s.p,{children:["Or through TypeScript (if ",(0,t.jsx)(s.code,{children:"ts-node"})," is installed):"]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.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,t.jsx)(s.admonition,{type:"important",children:(0,t.jsxs)(s.p,{children:["When using TypeScript Jest config file, Jest will use ",(0,t.jsx)(s.code,{children:"ts-node"})," to compile the config file. ",(0,t.jsx)(s.code,{children:"ts-jest"})," doesn't take part in\nthat process."]})}),"\n",(0,t.jsx)(s.h3,{id:"options",children:"Options"}),"\n",(0,t.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,t.jsxs)(s.table,{children:[(0,t.jsx)(s.thead,{children:(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.th,{children:"Option"}),(0,t.jsx)(s.th,{children:"Description"}),(0,t.jsx)(s.th,{children:"Type"}),(0,t.jsx)(s.th,{children:"Default"})]})}),(0,t.jsxs)(s.tbody,{children:[(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/compiler",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"compiler"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/compiler",children:"TypeScript module to use as compiler."})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"string"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:'"typescript"'})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/tsconfig",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"tsconfig"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/tsconfig",children:"TypeScript compiler related configuration."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"string"}),"|",(0,t.jsx)(s.code,{children:"object"}),"|",(0,t.jsx)(s.code,{children:"boolean"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"auto"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/isolatedModules",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"isolatedModules"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/isolatedModules",children:"Disable type-checking"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"boolean"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"disabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/astTransformers",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"astTransformers"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/astTransformers",children:"Custom TypeScript AST transformers"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"object"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"auto"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/diagnostics",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"diagnostics"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/diagnostics",children:"Diagnostics related configuration."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"boolean"}),"|",(0,t.jsx)(s.code,{children:"object"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"enabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/babelConfig",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"babelConfig"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/babelConfig",children:"Babel(Jest) related configuration."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"boolean"}),"|",(0,t.jsx)(s.code,{children:"string"}),"|",(0,t.jsx)(s.code,{children:"object"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"disabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"stringifyContentPathRegex"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/stringifyContentPathRegex",children:"Files which will become modules returning self content."})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.code,{children:"string"}),"|",(0,t.jsx)(s.code,{children:"RegExp"})]}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"disabled"})})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/useESM",children:(0,t.jsx)(s.strong,{children:(0,t.jsx)(s.code,{children:"useESM"})})})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.a,{href:"options/useESM",children:"Enable ESM support"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"boolean"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.em,{children:"auto"})})]})]})]})]})}function j(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.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.836cdf69.js b/assets/js/fe39109b.836cdf69.js new file mode 100644 index 0000000000..6dc5d52087 --- /dev/null +++ b/assets/js/fe39109b.836cdf69.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8718],{1537:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>h,frontMatter:()=>l,metadata:()=>u,toc:()=>d});var r=n(4848),s=n(8453),a=n(9489),o=n(7227);const l={id:"debugging",title:"Debugging ts-jest"},i=void 0,u={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:!1,unlisted:!1,editUrl:"https://github.com/kulshekhar/ts-jest/edit/main/website/versioned_docs/version-29.2/debugging.md",tags:[],version:"29.2",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{id:"debugging",title:"Debugging ts-jest"},sidebar:"version-29.1-docs",previous:{title:"Migration from <=23.10",permalink:"/ts-jest/docs/migration"}},c={},d=[];function g(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,s.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["You can activate the debug logger by setting the environment variable ",(0,r.jsx)(t.code,{children:"TS_JEST_LOG"})," before running tests.\nThe output of the logger will be in ",(0,r.jsx)(t.strong,{children:"ts-jest.log"})," in current working directory."]}),"\n",(0,r.jsxs)(t.p,{children:["The debug logger contains some useful information about how internal ",(0,r.jsx)(t.code,{children:"ts-jest"})," works, including which files are processed,\nwhich Jest config or TypeScript config is used etc."]}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{children:"export TS_JEST_LOG=ts-jest.log\n"})}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsx)(t.strong,{children:"Windows"})}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(o.A,{value:"Command",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-Command",metastring:"Prompt tab",children:"set TS_JEST_LOG=ts-jest.log\n"})})}),(0,r.jsx)(o.A,{value:"PowerShell",children:(0,r.jsx)(t.pre,{children:(0,r.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,r.jsx)(t,{...e,children:(0,r.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/fe39109b.b36dec47.js b/assets/js/fe39109b.b36dec47.js deleted file mode 100644 index c08a1b2200..0000000000 --- a/assets/js/fe39109b.b36dec47.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8718],{1537:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>h,frontMatter:()=>l,metadata:()=>u,toc:()=>d});var r=n(4848),s=n(8453),a=n(9489),o=n(7227);const l={id:"debugging",title:"Debugging ts-jest"},i=void 0,u={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{id:"debugging",title:"Debugging ts-jest"},sidebar:"version-29.1-docs",previous:{title:"Migration from <=23.10",permalink:"/ts-jest/docs/migration"}},c={},d=[];function g(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,s.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["You can activate the debug logger by setting the environment variable ",(0,r.jsx)(t.code,{children:"TS_JEST_LOG"})," before running tests.\nThe output of the logger will be in ",(0,r.jsx)(t.strong,{children:"ts-jest.log"})," in current working directory."]}),"\n",(0,r.jsxs)(t.p,{children:["The debug logger contains some useful information about how internal ",(0,r.jsx)(t.code,{children:"ts-jest"})," works, including which files are processed,\nwhich Jest config or TypeScript config is used etc."]}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsx)(t.strong,{children:"Linux/MacOS"})}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{children:"export TS_JEST_LOG=ts-jest.log\n"})}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsx)(t.strong,{children:"Windows"})}),"\n",(0,r.jsxs)(a.A,{groupId:"code-examples",children:[(0,r.jsx)(o.A,{value:"Command",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-Command",metastring:"Prompt tab",children:"set TS_JEST_LOG=ts-jest.log\n"})})}),(0,r.jsx)(o.A,{value:"PowerShell",children:(0,r.jsx)(t.pre,{children:(0,r.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,r.jsx)(t,{...e,children:(0,r.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.5071c141.js b/assets/js/fe3b9d2d.5071c141.js deleted file mode 100644 index d5f55afce0..0000000000 --- a/assets/js/fe3b9d2d.5071c141.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8418],{302:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>a,frontMatter:()=>i,metadata:()=>l,toc:()=>p});var n=o(4848),s=o(8453);const i={title:"Compiler option"},r=void 0,l={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:!1,unlisted:!1,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:1726058855e3,frontMatter:{title:"Compiler option"}},c={},p=[{value:"Example",id:"example",level:3}];function d(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["The ",(0,n.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,n.jsxs)(t.p,{children:["The default value is ",(0,n.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,n.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,n.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,n.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,n.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,n.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.pre,{children:(0,n.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,s.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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/fe3b9d2d.f126bde4.js b/assets/js/fe3b9d2d.f126bde4.js new file mode 100644 index 0000000000..f951bb4e1c --- /dev/null +++ b/assets/js/fe3b9d2d.f126bde4.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkts_jest_docs=self.webpackChunkts_jest_docs||[]).push([[8418],{302:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>a,frontMatter:()=>i,metadata:()=>l,toc:()=>p});var n=o(4848),s=o(8453);const i={title:"Compiler option"},r=void 0,l={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:!1,unlisted:!1,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:"dependabot[bot]",lastUpdatedAt:1726059549e3,frontMatter:{title:"Compiler option"}},c={},p=[{value:"Example",id:"example",level:3}];function d(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["The ",(0,n.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,n.jsxs)(t.p,{children:["The default value is ",(0,n.jsx)(t.code,{children:"typescript"}),", which will load the original ",(0,n.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,n.jsxs)(t.p,{children:["If you use a custom compiler, such as ",(0,n.jsx)(t.code,{children:"ttypescript"}),", make sure its API is the same as the original TypeScript, at least for what ",(0,n.jsx)(t.code,{children:"ts-jest"})," is using."]}),"\n",(0,n.jsx)(t.h3,{id:"example",children:"Example"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.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,n.jsx)(t.pre,{children:(0,n.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,s.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.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.82794501.js b/assets/js/main.73882c22.js similarity index 94% rename from assets/js/main.82794501.js rename to assets/js/main.73882c22.js index 767451b62f..87a2a2ea47 100644 --- a/assets/js/main.82794501.js +++ b/assets/js/main.73882c22.js @@ -1,2 +1,2 @@ -/*! For license information please see main.82794501.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,7074)),"@site/docs/getting-started/options/astTransformers.md",7074],"0259e2f2":[()=>n.e(378).then(n.bind(n,278)),"@site/versioned_docs/version-28.0/getting-started/options/astTransformers.md",278],"03be7dae":[()=>n.e(4768).then(n.bind(n,6262)),"@site/docs/guides/troubleshooting.md",6262],"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,5698)),"@site/versioned_docs/version-28.0/guides/mock-es6-class.md",5698],"06fbaa8e":[()=>n.e(942).then(n.bind(n,5429)),"@site/versioned_docs/version-27.0/debugging.md",5429],"07a7640f":[()=>n.e(7796).then(n.bind(n,5657)),"@site/versioned_docs/version-27.0/guides/troubleshooting.md",5657],"0833143f":[()=>n.e(2625).then(n.bind(n,1146)),"@site/versioned_docs/version-27.0/guides/using-with-monorepo.md",1146],"093c23a0":[()=>Promise.all([n.e(1869),n.e(5258)]).then(n.bind(n,6570)),"@site/versioned_docs/version-29.0/getting-started/options.md",6570],"0a51ecf3":[()=>Promise.all([n.e(1869),n.e(4441)]).then(n.bind(n,8004)),"@site/versioned_docs/version-29.0/guides/react-native.md",8004],"0b2fcab7":[()=>n.e(3004).then(n.bind(n,9881)),"@site/versioned_docs/version-27.0/migration.md",9881],"0d0f47fc":[()=>Promise.all([n.e(1869),n.e(4263)]).then(n.bind(n,3036)),"@site/versioned_docs/version-29.0/getting-started/presets.md",3036],"10aeaaf3":[()=>n.e(2957).then(n.bind(n,8765)),"@site/versioned_docs/version-26.5/guides/esm-support.md",8765],"1165ba55":[()=>n.e(8431).then(n.bind(n,4544)),"@site/versioned_docs/version-26.5/getting-started/installation.md",4544],12292045:[()=>n.e(610).then(n.bind(n,7613)),"@site/versioned_docs/version-29.2/introduction.md",7613],"15c7296a":[()=>Promise.all([n.e(1869),n.e(551)]).then(n.bind(n,1307)),"@site/versioned_docs/version-29.2/guides/mock-es6-class.md",1307],"16ada0e2":[()=>n.e(5623).then(n.bind(n,7205)),"@site/versioned_docs/version-28.0/guides/using-with-monorepo.md",7205],"16bac89a":[()=>n.e(5046).then(n.bind(n,8081)),"@site/versioned_docs/version-27.1/babel7-or-ts.md",8081],17896441:[()=>Promise.all([n.e(1869),n.e(8401)]).then(n.bind(n,3805)),"@theme/DocItem",3805],"1854c3e7":[()=>n.e(1797).then(n.bind(n,8152)),"@site/versioned_docs/version-26.5/babel7-or-ts.md",8152],"1917a510":[()=>Promise.all([n.e(1869),n.e(4076)]).then(n.bind(n,9295)),"@site/versioned_docs/version-29.2/getting-started/options/stringifyContentPathRegex.md",9295],"19f0fee7":[()=>n.e(8888).then(n.bind(n,2332)),"@site/versioned_docs/version-27.1/getting-started/options/diagnostics.md",2332],"1ca5b1f2":[()=>n.e(1682).then(n.bind(n,2331)),"@site/versioned_docs/version-29.2/getting-started/version-checking.md",2331],"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,8001)),"@site/versioned_docs/version-27.1/getting-started/installation.md",8001],"22e01789":[()=>n.e(2365).then(n.bind(n,9835)),"@site/versioned_docs/version-28.0/getting-started/options/tsconfig.md",9835],"22f8c605":[()=>n.e(6475).then(n.bind(n,9308)),"@site/versioned_docs/version-27.1/introduction.md",9308],"2331e073":[()=>n.e(1455).then(n.bind(n,9668)),"@site/versioned_docs/version-27.1/guides/test-helpers.md",9668],"2338618e":[()=>Promise.all([n.e(1869),n.e(8529)]).then(n.bind(n,6011)),"@site/versioned_docs/version-29.0/migration.md",6011],"24991caa":[()=>n.e(8317).then(n.bind(n,8224)),"@site/versioned_docs/version-29.0/processing.md",8224],"265d7427":[()=>n.e(7556).then(n.bind(n,8307)),"@site/versioned_docs/version-27.0/getting-started/options/stringifyContentPathRegex.md",8307],"270520cb":[()=>Promise.all([n.e(1869),n.e(3110)]).then(n.bind(n,1282)),"@site/versioned_docs/version-29.0/getting-started/options/tsconfig.md",1282],"295b567d":[()=>Promise.all([n.e(1869),n.e(3549)]).then(n.bind(n,644)),"@site/docs/migration.md",644],"2a3bd03a":[()=>n.e(6399).then(n.bind(n,7287)),"@site/versioned_docs/version-27.1/guides/troubleshooting.md",7287],"2b68f68f":[()=>n.e(4519).then(n.bind(n,912)),"@site/versioned_docs/version-27.0/getting-started/installation.md",912],"2b77ff19":[()=>n.e(3951).then(n.bind(n,7597)),"@site/versioned_docs/version-29.2/guides/troubleshooting.md",7597],"2b94ed59":[()=>n.e(6797).then(n.bind(n,4510)),"@site/versioned_docs/version-26.5/getting-started/options/compiler.md",4510],"2bccb399":[()=>Promise.all([n.e(1869),n.e(5154)]).then(n.bind(n,1416)),"@site/docs/debugging.md",1416],"2c53b5e4":[()=>n.e(8282).then(n.bind(n,59)),"@site/versioned_docs/version-27.0/guides/test-helpers.md",59],"2d143bed":[()=>n.e(1154).then(n.bind(n,6956)),"@site/versioned_docs/version-29.2/babel7-or-ts.md",6956],"2e89f3c4":[()=>n.e(4937).then(n.bind(n,5254)),"@site/versioned_docs/version-28.0/getting-started/options/isolatedModules.md",5254],"304054d0":[()=>Promise.all([n.e(1869),n.e(5501)]).then(n.bind(n,772)),"@site/versioned_docs/version-29.2/getting-started/options/tsconfig.md",772],"334e0bf3":[()=>n.e(3723).then(n.bind(n,2378)),"@site/versioned_docs/version-26.5/guides/using-with-monorepo.md",2378],"3432663a":[()=>n.e(9345).then(n.bind(n,5570)),"@site/versioned_docs/version-27.1/migration.md",5570],"35779d9e":[()=>Promise.all([n.e(1869),n.e(3152)]).then(n.bind(n,3099)),"@site/versioned_docs/version-29.0/getting-started/options/babelConfig.md",3099],"35ce71d5":[()=>n.e(9014).then(n.bind(n,2608)),"@site/versioned_docs/version-29.0/guides/using-with-monorepo.md",2608],"3787ba46":[()=>n.e(775).then(n.bind(n,3995)),"@site/versioned_docs/version-27.1/guides/esm-support.md",3995],"3bfdd655":[()=>n.e(4798).then(n.bind(n,8110)),"@site/versioned_docs/version-26.5/getting-started/presets.md",8110],"3e930f87":[()=>Promise.all([n.e(1869),n.e(2078)]).then(n.bind(n,1921)),"@site/docs/getting-started/options/compiler.md",1921],"4040fa6b":[()=>n.e(9032).then(n.bind(n,2513)),"@site/versioned_docs/version-26.5/introduction.md",2513],44207808:[()=>n.e(8120).then(n.bind(n,1417)),"@site/versioned_docs/version-26.5/getting-started/options/babelConfig.md",1417],"44d840ac":[()=>n.e(5775).then(n.bind(n,8779)),"@site/versioned_docs/version-26.5/getting-started/options/diagnostics.md",8779],"4aabdf82":[()=>n.e(8639).then(n.bind(n,8431)),"@site/docs/babel7-or-ts.md",8431],"4c23203f":[()=>n.e(8468).then(n.bind(n,6006)),"@site/versioned_docs/version-26.5/guides/react-native.md",6006],"4c757249":[()=>n.e(10).then(n.bind(n,7905)),"@site/versioned_docs/version-27.0/contributing.md",7905],"4d54d076":[()=>n.e(1459).then(n.bind(n,8538)),"@site/docs/contributing.md",8538],"4dd3fb5c":[()=>Promise.all([n.e(1869),n.e(2636)]).then(n.bind(n,7301)),"@site/versioned_docs/version-29.0/guides/mock-es6-class.md",7301],"4e0c07c5":[()=>Promise.all([n.e(1869),n.e(5250)]).then(n.bind(n,1101)),"@site/docs/getting-started/options.md",1101],"5316ff60":[()=>n.e(5520).then(n.bind(n,8863)),"@site/versioned_docs/version-27.0/getting-started/options/astTransformers.md",8863],"544d8072":[()=>n.e(9979).then(n.bind(n,6697)),"@site/versioned_docs/version-26.5/migration.md",6697],"54ceb25f":[()=>Promise.all([n.e(1869),n.e(4317)]).then(n.bind(n,1662)),"@site/versioned_docs/version-29.2/guides/esm-support.md",1662],"54f44165":[()=>Promise.all([n.e(1869),n.e(7924)]).then(n.bind(n,2079)),"@site/docs/getting-started/installation.md",2079],"5bf3837a":[()=>n.e(2276).then(n.bind(n,4206)),"@site/versioned_docs/version-26.5/processing.md",4206],"5d7f6371":[()=>n.e(5834).then(n.t.bind(n,4712,19)),"@generated/docusaurus-plugin-content-docs/default/p/ts-jest-docs-next-fd5.json",4712],"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,3689)),"@site/versioned_docs/version-26.5/getting-started/paths-mapping.md",3689],"629085c0":[()=>Promise.all([n.e(1869),n.e(2452)]).then(n.bind(n,3138)),"@site/versioned_docs/version-29.2/getting-started/options/compiler.md",3138],"6625be2a":[()=>Promise.all([n.e(1869),n.e(4136)]).then(n.bind(n,1918)),"@site/docs/guides/mock-es6-class.md",1918],"673550c0":[()=>n.e(6460).then(n.bind(n,6689)),"@site/versioned_docs/version-28.0/guides/esm-support.md",6689],"6789ef91":[()=>n.e(3960).then(n.bind(n,5464)),"@site/versioned_docs/version-26.5/getting-started/options.md",5464],"684ec830":[()=>Promise.all([n.e(1869),n.e(5584)]).then(n.bind(n,8076)),"@site/versioned_docs/version-29.0/getting-started/options/compiler.md",8076],"6bc4332d":[()=>n.e(7350).then(n.bind(n,1363)),"@site/versioned_docs/version-27.1/processing.md",1363],"6cdc57e1":[()=>n.e(9995).then(n.bind(n,8638)),"@site/versioned_docs/version-27.0/processing.md",8638],"6f04af8d":[()=>Promise.all([n.e(1869),n.e(6018)]).then(n.bind(n,8994)),"@site/docs/getting-started/options/isolatedModules.md",8994],"6f4d8994":[()=>n.e(3021).then(n.bind(n,6434)),"@site/versioned_docs/version-27.1/getting-started/version-checking.md",6434],"6f82a5f4":[()=>n.e(3429).then(n.bind(n,9643)),"@site/versioned_docs/version-26.5/guides/test-helpers.md",9643],"7335c74d":[()=>Promise.all([n.e(1869),n.e(7983)]).then(n.bind(n,787)),"@site/versioned_docs/version-29.0/debugging.md",787],"73f5a02c":[()=>Promise.all([n.e(1869),n.e(8080)]).then(n.bind(n,7254)),"@site/docs/getting-started/options/stringifyContentPathRegex.md",7254],"75ab14ad":[()=>n.e(6506).then(n.bind(n,4435)),"@site/versioned_docs/version-26.5/getting-started/options/stringifyContentPathRegex.md",4435],"78f0a226":[()=>n.e(8313).then(n.bind(n,8502)),"@site/versioned_docs/version-27.1/getting-started/options/babelConfig.md",8502],"7aac82f3":[()=>Promise.all([n.e(1869),n.e(6576)]).then(n.bind(n,6388)),"@site/versioned_docs/version-29.0/guides/esm-support.md",6388],"7b562fc7":[()=>n.e(8647).then(n.bind(n,7605)),"@site/versioned_docs/version-29.2/contributing.md",7605],"7d1a64ae":[()=>n.e(7352).then(n.bind(n,2296)),"@site/versioned_docs/version-27.1/contributing.md",2296],"7dafce35":[()=>Promise.all([n.e(1869),n.e(7083)]).then(n.bind(n,9073)),"@site/versioned_docs/version-29.0/getting-started/options/astTransformers.md",9073],"7ec61308":[()=>Promise.all([n.e(1869),n.e(992)]).then(n.bind(n,7428)),"@site/docs/getting-started/paths-mapping.md",7428],"801c4327":[()=>n.e(2817).then(n.bind(n,3333)),"@site/versioned_docs/version-27.1/getting-started/presets.md",3333],"850a2979":[()=>n.e(6964).then(n.bind(n,2414)),"@site/versioned_docs/version-27.0/getting-started/presets.md",2414],"86b5844b":[()=>Promise.all([n.e(1869),n.e(988)]).then(n.bind(n,5655)),"@site/docs/guides/react-native.md",5655],"8b2f9623":[()=>n.e(8629).then(n.bind(n,8763)),"@site/versioned_docs/version-29.0/guides/troubleshooting.md",8763],"8b622911":[()=>n.e(1268).then(n.bind(n,5325)),"@site/versioned_docs/version-27.1/getting-started/options/tsconfig.md",5325],"8cf61ec4":[()=>n.e(5799).then(n.bind(n,5180)),"@site/versioned_docs/version-27.0/getting-started/options/isolatedModules.md",5180],"8d536cde":[()=>n.e(8979).then(n.bind(n,9934)),"@site/versioned_docs/version-28.0/contributing.md",9934],"8e5d45d9":[()=>n.e(7425).then(n.bind(n,9359)),"@site/versioned_docs/version-29.0/introduction.md",9359],"8e81f9bb":[()=>n.e(8192).then(n.bind(n,8849)),"@site/versioned_docs/version-28.0/getting-started/options.md",8849],"902acc05":[()=>n.e(8632).then(n.bind(n,474)),"@site/versioned_docs/version-27.0/guides/esm-support.md",474],90645308:[()=>Promise.all([n.e(1869),n.e(1626)]).then(n.bind(n,8893)),"@site/versioned_docs/version-29.2/getting-started/options/useESM.md",8893],"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,2471)),"@site/versioned_docs/version-28.0/getting-started/presets.md",2471],"96f7df01":[()=>n.e(4316).then(n.bind(n,2664)),"@site/versioned_docs/version-27.0/babel7-or-ts.md",2664],"9762b2e9":[()=>n.e(6553).then(n.bind(n,2054)),"@site/versioned_docs/version-27.1/getting-started/paths-mapping.md",2054],"981dc414":[()=>Promise.all([n.e(1869),n.e(2777)]).then(n.bind(n,8555)),"@site/versioned_docs/version-29.0/getting-started/options/useESM.md",8555],"9920b385":[()=>Promise.all([n.e(1869),n.e(4571)]).then(n.bind(n,360)),"@site/docs/getting-started/options/babelConfig.md",360],"9d036230":[()=>n.e(8810).then(n.bind(n,5923)),"@site/versioned_docs/version-29.0/contributing.md",5923],"9ed06f50":[()=>n.e(5174).then(n.bind(n,7664)),"@site/versioned_docs/version-28.0/migration.md",7664],a09c2993:[()=>n.e(5899).then(n.bind(n,2738)),"@site/docs/introduction.md",2738],a132b5de:[()=>n.e(7132).then(n.bind(n,4779)),"@site/versioned_docs/version-27.0/getting-started/options/diagnostics.md",4779],a21658d9:[()=>n.e(1173).then(n.bind(n,5547)),"@site/versioned_docs/version-28.0/guides/react-native.md",5547],a5ea8355:[()=>n.e(3762).then(n.bind(n,1412)),"@site/versioned_docs/version-27.1/getting-started/options/isolatedModules.md",1412],a6267c3c:[()=>n.e(6586).then(n.bind(n,766)),"@site/versioned_docs/version-28.0/introduction.md",766],a7423e3b:[()=>Promise.all([n.e(1869),n.e(3322)]).then(n.bind(n,5844)),"@site/versioned_docs/version-29.2/getting-started/installation.md",5844],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(9123)]).then(n.bind(n,8474)),"@site/versioned_docs/version-29.2/getting-started/presets.md",8474],a7bd4aaa:[()=>n.e(7098).then(n.bind(n,9011)),"@theme/DocVersionRoot",9011],a8c654d7:[()=>n.e(2587).then(n.bind(n,1748)),"@site/versioned_docs/version-28.0/debugging.md",1748],a8e3f14e:[()=>Promise.all([n.e(1869),n.e(2234)]).then(n.bind(n,4813)),"@site/versioned_docs/version-29.0/getting-started/options/stringifyContentPathRegex.md",4813],a94703ab:[()=>Promise.all([n.e(1869),n.e(9048)]).then(n.bind(n,382)),"@theme/DocRoot",382],aaf1bd4c:[()=>n.e(863).then(n.bind(n,2975)),"@site/versioned_docs/version-26.5/getting-started/options/isolatedModules.md",2975],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,4500)),"@site/versioned_docs/version-28.0/getting-started/version-checking.md",4500],aeb5491d:[()=>n.e(4572).then(n.bind(n,5507)),"@site/versioned_docs/version-28.0/babel7-or-ts.md",5507],aeb823d8:[()=>Promise.all([n.e(1869),n.e(3790)]).then(n.bind(n,5859)),"@site/versioned_docs/version-29.2/getting-started/options/isolatedModules.md",5859],afb030c9:[()=>n.e(4746).then(n.bind(n,2198)),"@site/versioned_docs/version-28.0/processing.md",2198],b317f538:[()=>n.e(8392).then(n.bind(n,6613)),"@site/versioned_docs/version-29.0/getting-started/version-checking.md",6613],b519512b:[()=>n.e(8116).then(n.bind(n,6278)),"@site/versioned_docs/version-27.0/guides/react-native.md",6278],b72fc7f8:[()=>Promise.all([n.e(1869),n.e(9610)]).then(n.bind(n,3605)),"@site/versioned_docs/version-29.2/migration.md",3605],b809b403:[()=>n.e(7693).then(n.bind(n,4457)),"@site/versioned_docs/version-27.0/getting-started/options/useESM.md",4457],b96776d9:[()=>Promise.all([n.e(1869),n.e(4623)]).then(n.bind(n,4778)),"@site/versioned_docs/version-29.2/guides/react-native.md",4778],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,711)),"@site/versioned_docs/version-27.0/guides/mock-es6-class.md",711],bdfec613:[()=>n.e(4733).then(n.bind(n,856)),"@site/versioned_docs/version-27.0/getting-started/options.md",856],bf341476:[()=>n.e(2402).then(n.bind(n,6225)),"@site/versioned_docs/version-27.0/introduction.md",6225],c010a830:[()=>n.e(7015).then(n.bind(n,1576)),"@site/versioned_docs/version-27.1/getting-started/options/useESM.md",1576],c1932cab:[()=>n.e(8719).then(n.bind(n,8068)),"@site/versioned_docs/version-28.0/getting-started/options/babelConfig.md",8068],c1a7450f:[()=>Promise.all([n.e(1869),n.e(6120)]).then(n.bind(n,8290)),"@site/docs/getting-started/options/useESM.md",8290],c6326909:[()=>n.e(6121).then(n.bind(n,3023)),"@site/versioned_docs/version-27.0/getting-started/version-checking.md",3023],c8c88a41:[()=>n.e(1907).then(n.bind(n,4080)),"@site/versioned_docs/version-28.0/getting-started/paths-mapping.md",4080],c8eced56:[()=>n.e(1344).then(n.bind(n,5190)),"@site/versioned_docs/version-28.0/getting-started/options/useESM.md",5190],ceaad8ca:[()=>Promise.all([n.e(1869),n.e(4681)]).then(n.bind(n,9954)),"@site/docs/getting-started/options/diagnostics.md",9954],cf5c42a2:[()=>n.e(2659).then(n.bind(n,124)),"@site/versioned_docs/version-27.1/getting-started/options/stringifyContentPathRegex.md",124],cffdf1e5:[()=>n.e(4631).then(n.bind(n,730)),"@site/versioned_docs/version-28.0/guides/troubleshooting.md",730],d0e697d4:[()=>n.e(6842).then(n.bind(n,3451)),"@site/versioned_docs/version-27.1/guides/using-with-monorepo.md",3451],d296dded:[()=>n.e(8563).then(n.bind(n,1942)),"@site/versioned_docs/version-29.2/guides/using-with-monorepo.md",1942],d3b43630:[()=>n.e(9592).then(n.bind(n,1920)),"@site/versioned_docs/version-27.1/guides/mock-es6-class.md",1920],d4836a8e:[()=>Promise.all([n.e(1869),n.e(106)]).then(n.bind(n,8125)),"@site/docs/guides/esm-support.md",8125],d4a6dd78:[()=>n.e(1163).then(n.bind(n,7433)),"@site/versioned_docs/version-27.0/getting-started/options/babelConfig.md",7433],d6f9473b:[()=>n.e(9314).then(n.bind(n,904)),"@site/versioned_docs/version-27.1/getting-started/options/astTransformers.md",904],d8357ecf:[()=>n.e(5580).then(n.bind(n,1059)),"@site/versioned_docs/version-27.1/getting-started/options/compiler.md",1059],d9f7da4b:[()=>n.e(6556).then(n.bind(n,2031)),"@site/versioned_docs/version-26.5/getting-started/version-checking.md",2031],da431c38:[()=>Promise.all([n.e(1869),n.e(1952)]).then(n.bind(n,5358)),"@site/versioned_docs/version-29.0/getting-started/installation.md",5358],dabdf990:[()=>n.e(3808).then(n.bind(n,5365)),"@site/versioned_docs/version-28.0/getting-started/options/compiler.md",5365],db49ae54:[()=>n.e(9197).then(n.bind(n,71)),"@site/versioned_docs/version-26.5/guides/mock-es6-class.md",71],db795cf2:[()=>n.e(5369).then(n.bind(n,4442)),"@site/versioned_docs/version-27.1/debugging.md",4442],dcbdd84f:[()=>n.e(4716).then(n.bind(n,9586)),"@site/versioned_docs/version-26.5/debugging.md",9586],e3a856ae:[()=>n.e(6771).then(n.bind(n,3897)),"@site/versioned_docs/version-27.1/guides/react-native.md",3897],e5e34c6b:[()=>n.e(4218).then(n.bind(n,7512)),"@site/docs/getting-started/version-checking.md",7512],e8085380:[()=>n.e(3284).then(n.bind(n,8134)),"@site/versioned_docs/version-28.0/getting-started/options/diagnostics.md",8134],e87a3571:[()=>n.e(7252).then(n.bind(n,5038)),"@site/versioned_docs/version-29.0/babel7-or-ts.md",5038],e8b13364:[()=>n.e(4523).then(n.bind(n,8495)),"@site/versioned_docs/version-26.5/getting-started/options/astTransformers.md",8495],eabdbf07:[()=>n.e(5100).then(n.bind(n,7581)),"@site/docs/processing.md",7581],ec6c7123:[()=>n.e(2091).then(n.bind(n,4585)),"@site/versioned_docs/version-26.5/guides/troubleshooting.md",4585],f01607c0:[()=>n.e(6714).then(n.bind(n,6515)),"@site/versioned_docs/version-28.0/getting-started/installation.md",6515],f0683fd0:[()=>n.e(6672).then(n.bind(n,1753)),"@site/docs/guides/using-with-monorepo.md",1753],f154e663:[()=>Promise.all([n.e(1869),n.e(9643)]).then(n.bind(n,417)),"@site/versioned_docs/version-29.0/getting-started/options/diagnostics.md",417],f298e69b:[()=>Promise.all([n.e(1869),n.e(2804)]).then(n.bind(n,2589)),"@site/versioned_docs/version-29.0/getting-started/options/isolatedModules.md",2589],f371827f:[()=>Promise.all([n.e(1869),n.e(4811)]).then(n.bind(n,2764)),"@site/versioned_docs/version-29.2/getting-started/options.md",2764],f4dd4a52:[()=>Promise.all([n.e(1869),n.e(397)]).then(n.bind(n,1333)),"@site/versioned_docs/version-29.2/getting-started/options/babelConfig.md",1333],f6605416:[()=>Promise.all([n.e(1869),n.e(4343)]).then(n.bind(n,7727)),"@site/versioned_docs/version-29.0/getting-started/paths-mapping.md",7727],f6aab920:[()=>n.e(7320).then(n.bind(n,2472)),"@site/versioned_docs/version-26.5/getting-started/options/tsconfig.md",2472],f6f550ec:[()=>Promise.all([n.e(1869),n.e(983)]).then(n.bind(n,9989)),"@site/versioned_docs/version-29.2/getting-started/paths-mapping.md",9989],f7416098:[()=>n.e(2186).then(n.bind(n,7209)),"@site/versioned_docs/version-27.0/getting-started/paths-mapping.md",7209],f7862b07:[()=>n.e(8539).then(n.bind(n,5569)),"@site/versioned_docs/version-26.5/contributing.md",5569],f7b7430f:[()=>n.e(1678).then(n.bind(n,4456)),"@site/versioned_docs/version-27.0/getting-started/options/tsconfig.md",4456],f7cb2af4:[()=>Promise.all([n.e(1869),n.e(7036)]).then(n.bind(n,7548)),"@site/docs/getting-started/options/tsconfig.md",7548],f8fb2427:[()=>Promise.all([n.e(1869),n.e(6734)]).then(n.bind(n,911)),"@site/versioned_docs/version-29.2/getting-started/options/diagnostics.md",911],fa061f97:[()=>Promise.all([n.e(1869),n.e(9547)]).then(n.bind(n,9683)),"@site/versioned_docs/version-29.2/getting-started/options/astTransformers.md",9683],fa17a3e5:[()=>n.e(8054).then(n.bind(n,8350)),"@site/src/pages/versions.tsx",8350],fb1b7a48:[()=>n.e(9566).then(n.bind(n,7698)),"@site/versioned_docs/version-28.0/getting-started/options/stringifyContentPathRegex.md",7698],fc43d853:[()=>n.e(5609).then(n.bind(n,1850)),"@site/versioned_docs/version-29.2/processing.md",1850],fc80686b:[()=>Promise.all([n.e(1869),n.e(2440)]).then(n.bind(n,5675)),"@site/docs/getting-started/presets.md",5675],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,795)),"@site/versioned_docs/version-27.1/getting-started/options.md",795],fe39109b:[()=>Promise.all([n.e(1869),n.e(8718)]).then(n.bind(n,1537)),"@site/versioned_docs/version-29.2/debugging.md",1537],fe3b9d2d:[()=>n.e(8418).then(n.bind(n,302)),"@site/versioned_docs/version-27.0/getting-started/options/compiler.md",302]};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","8ee"),routes:[{path:"/ts-jest/docs/26.5",component:d("/ts-jest/docs/26.5","e6a"),routes:[{path:"/ts-jest/docs/26.5",component:d("/ts-jest/docs/26.5","36a"),routes:[{path:"/ts-jest/docs/26.5/",component:d("/ts-jest/docs/26.5/","194"),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","d27"),exact:!0,sidebar:"version-26.5-docs"},{path:"/ts-jest/docs/26.5/contributing",component:d("/ts-jest/docs/26.5/contributing","e8c"),exact:!0,sidebar:"version-26.5-docs"},{path:"/ts-jest/docs/26.5/debugging",component:d("/ts-jest/docs/26.5/debugging","8c7"),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","4b2"),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","002"),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","504"),exact:!0},{path:"/ts-jest/docs/26.5/getting-started/options/babelConfig",component:d("/ts-jest/docs/26.5/getting-started/options/babelConfig","e8a"),exact:!0},{path:"/ts-jest/docs/26.5/getting-started/options/compiler",component:d("/ts-jest/docs/26.5/getting-started/options/compiler","a42"),exact:!0},{path:"/ts-jest/docs/26.5/getting-started/options/diagnostics",component:d("/ts-jest/docs/26.5/getting-started/options/diagnostics","e68"),exact:!0},{path:"/ts-jest/docs/26.5/getting-started/options/isolatedModules",component:d("/ts-jest/docs/26.5/getting-started/options/isolatedModules","0f5"),exact:!0},{path:"/ts-jest/docs/26.5/getting-started/options/stringifyContentPathRegex",component:d("/ts-jest/docs/26.5/getting-started/options/stringifyContentPathRegex","d1b"),exact:!0},{path:"/ts-jest/docs/26.5/getting-started/options/tsconfig",component:d("/ts-jest/docs/26.5/getting-started/options/tsconfig","ed3"),exact:!0},{path:"/ts-jest/docs/26.5/getting-started/paths-mapping",component:d("/ts-jest/docs/26.5/getting-started/paths-mapping","a83"),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","bd8"),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","7b1"),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","0c7"),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","1c3"),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","681"),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","340"),exact:!0,sidebar:"version-26.5-docs"},{path:"/ts-jest/docs/26.5/guides/troubleshooting",component:d("/ts-jest/docs/26.5/guides/troubleshooting","e86"),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","f15"),exact:!0,sidebar:"version-26.5-docs"},{path:"/ts-jest/docs/26.5/migration",component:d("/ts-jest/docs/26.5/migration","f33"),exact:!0,sidebar:"version-26.5-docs"},{path:"/ts-jest/docs/26.5/processing",component:d("/ts-jest/docs/26.5/processing","8b0"),exact:!0,sidebar:"version-26.5-docs"}]}]},{path:"/ts-jest/docs/27.0",component:d("/ts-jest/docs/27.0","c16"),routes:[{path:"/ts-jest/docs/27.0",component:d("/ts-jest/docs/27.0","806"),routes:[{path:"/ts-jest/docs/27.0/",component:d("/ts-jest/docs/27.0/","8a0"),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","5a1"),exact:!0,sidebar:"version-27.0-docs"},{path:"/ts-jest/docs/27.0/contributing",component:d("/ts-jest/docs/27.0/contributing","4aa"),exact:!0,sidebar:"version-27.0-docs"},{path:"/ts-jest/docs/27.0/debugging",component:d("/ts-jest/docs/27.0/debugging","2d8"),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","805"),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","264"),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","200"),exact:!0},{path:"/ts-jest/docs/27.0/getting-started/options/babelConfig",component:d("/ts-jest/docs/27.0/getting-started/options/babelConfig","97e"),exact:!0},{path:"/ts-jest/docs/27.0/getting-started/options/compiler",component:d("/ts-jest/docs/27.0/getting-started/options/compiler","849"),exact:!0},{path:"/ts-jest/docs/27.0/getting-started/options/diagnostics",component:d("/ts-jest/docs/27.0/getting-started/options/diagnostics","8d0"),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","3ca"),exact:!0},{path:"/ts-jest/docs/27.0/getting-started/options/tsconfig",component:d("/ts-jest/docs/27.0/getting-started/options/tsconfig","31b"),exact:!0},{path:"/ts-jest/docs/27.0/getting-started/options/useESM",component:d("/ts-jest/docs/27.0/getting-started/options/useESM","8e9"),exact:!0},{path:"/ts-jest/docs/27.0/getting-started/paths-mapping",component:d("/ts-jest/docs/27.0/getting-started/paths-mapping","0aa"),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","4bf"),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","377"),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","192"),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","047"),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","b53"),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","757"),exact:!0,sidebar:"version-27.0-docs"},{path:"/ts-jest/docs/27.0/guides/troubleshooting",component:d("/ts-jest/docs/27.0/guides/troubleshooting","bd2"),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","593"),exact:!0,sidebar:"version-27.0-docs"},{path:"/ts-jest/docs/27.0/migration",component:d("/ts-jest/docs/27.0/migration","9db"),exact:!0,sidebar:"version-27.0-docs"},{path:"/ts-jest/docs/27.0/processing",component:d("/ts-jest/docs/27.0/processing","454"),exact:!0,sidebar:"version-27.0-docs"}]}]},{path:"/ts-jest/docs/27.1",component:d("/ts-jest/docs/27.1","7a0"),routes:[{path:"/ts-jest/docs/27.1",component:d("/ts-jest/docs/27.1","dc2"),routes:[{path:"/ts-jest/docs/27.1/",component:d("/ts-jest/docs/27.1/","ee4"),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","4be"),exact:!0,sidebar:"version-27.1-docs"},{path:"/ts-jest/docs/27.1/contributing",component:d("/ts-jest/docs/27.1/contributing","b9f"),exact:!0,sidebar:"version-27.1-docs"},{path:"/ts-jest/docs/27.1/debugging",component:d("/ts-jest/docs/27.1/debugging","ff2"),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","c51"),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","017"),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","189"),exact:!0},{path:"/ts-jest/docs/27.1/getting-started/options/babelConfig",component:d("/ts-jest/docs/27.1/getting-started/options/babelConfig","3d9"),exact:!0},{path:"/ts-jest/docs/27.1/getting-started/options/compiler",component:d("/ts-jest/docs/27.1/getting-started/options/compiler","3e3"),exact:!0},{path:"/ts-jest/docs/27.1/getting-started/options/diagnostics",component:d("/ts-jest/docs/27.1/getting-started/options/diagnostics","7ab"),exact:!0},{path:"/ts-jest/docs/27.1/getting-started/options/isolatedModules",component:d("/ts-jest/docs/27.1/getting-started/options/isolatedModules","bff"),exact:!0},{path:"/ts-jest/docs/27.1/getting-started/options/stringifyContentPathRegex",component:d("/ts-jest/docs/27.1/getting-started/options/stringifyContentPathRegex","9b6"),exact:!0},{path:"/ts-jest/docs/27.1/getting-started/options/tsconfig",component:d("/ts-jest/docs/27.1/getting-started/options/tsconfig","10f"),exact:!0},{path:"/ts-jest/docs/27.1/getting-started/options/useESM",component:d("/ts-jest/docs/27.1/getting-started/options/useESM","00f"),exact:!0},{path:"/ts-jest/docs/27.1/getting-started/paths-mapping",component:d("/ts-jest/docs/27.1/getting-started/paths-mapping","bdc"),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","c56"),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","7fd"),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","956"),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","b35"),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","050"),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","1da"),exact:!0,sidebar:"version-27.1-docs"},{path:"/ts-jest/docs/27.1/guides/troubleshooting",component:d("/ts-jest/docs/27.1/guides/troubleshooting","479"),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","62f"),exact:!0,sidebar:"version-27.1-docs"},{path:"/ts-jest/docs/27.1/migration",component:d("/ts-jest/docs/27.1/migration","e1f"),exact:!0,sidebar:"version-27.1-docs"},{path:"/ts-jest/docs/27.1/processing",component:d("/ts-jest/docs/27.1/processing","e36"),exact:!0,sidebar:"version-27.1-docs"}]}]},{path:"/ts-jest/docs/28.0",component:d("/ts-jest/docs/28.0","e41"),routes:[{path:"/ts-jest/docs/28.0",component:d("/ts-jest/docs/28.0","920"),routes:[{path:"/ts-jest/docs/28.0/",component:d("/ts-jest/docs/28.0/","8f9"),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","3d1"),exact:!0,sidebar:"version-28.0-docs"},{path:"/ts-jest/docs/28.0/contributing",component:d("/ts-jest/docs/28.0/contributing","cf4"),exact:!0,sidebar:"version-28.0-docs"},{path:"/ts-jest/docs/28.0/debugging",component:d("/ts-jest/docs/28.0/debugging","71a"),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","68b"),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","0f1"),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","9bf"),exact:!0},{path:"/ts-jest/docs/28.0/getting-started/options/babelConfig",component:d("/ts-jest/docs/28.0/getting-started/options/babelConfig","e0f"),exact:!0},{path:"/ts-jest/docs/28.0/getting-started/options/compiler",component:d("/ts-jest/docs/28.0/getting-started/options/compiler","78f"),exact:!0},{path:"/ts-jest/docs/28.0/getting-started/options/diagnostics",component:d("/ts-jest/docs/28.0/getting-started/options/diagnostics","9e9"),exact:!0},{path:"/ts-jest/docs/28.0/getting-started/options/isolatedModules",component:d("/ts-jest/docs/28.0/getting-started/options/isolatedModules","950"),exact:!0},{path:"/ts-jest/docs/28.0/getting-started/options/stringifyContentPathRegex",component:d("/ts-jest/docs/28.0/getting-started/options/stringifyContentPathRegex","41d"),exact:!0},{path:"/ts-jest/docs/28.0/getting-started/options/tsconfig",component:d("/ts-jest/docs/28.0/getting-started/options/tsconfig","45c"),exact:!0},{path:"/ts-jest/docs/28.0/getting-started/options/useESM",component:d("/ts-jest/docs/28.0/getting-started/options/useESM","7c0"),exact:!0},{path:"/ts-jest/docs/28.0/getting-started/paths-mapping",component:d("/ts-jest/docs/28.0/getting-started/paths-mapping","d09"),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","c23"),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","69b"),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","832"),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","fa4"),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","601"),exact:!0,sidebar:"version-28.0-docs"},{path:"/ts-jest/docs/28.0/guides/troubleshooting",component:d("/ts-jest/docs/28.0/guides/troubleshooting","80e"),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","063"),exact:!0,sidebar:"version-28.0-docs"},{path:"/ts-jest/docs/28.0/migration",component:d("/ts-jest/docs/28.0/migration","11c"),exact:!0,sidebar:"version-28.0-docs"},{path:"/ts-jest/docs/28.0/processing",component:d("/ts-jest/docs/28.0/processing","128"),exact:!0,sidebar:"version-28.0-docs"}]}]},{path:"/ts-jest/docs/29.0",component:d("/ts-jest/docs/29.0","507"),routes:[{path:"/ts-jest/docs/29.0",component:d("/ts-jest/docs/29.0","2de"),routes:[{path:"/ts-jest/docs/29.0/",component:d("/ts-jest/docs/29.0/","e95"),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","ab9"),exact:!0,sidebar:"version-29.0-docs"},{path:"/ts-jest/docs/29.0/contributing",component:d("/ts-jest/docs/29.0/contributing","764"),exact:!0,sidebar:"version-29.0-docs"},{path:"/ts-jest/docs/29.0/debugging",component:d("/ts-jest/docs/29.0/debugging","2c9"),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","e2d"),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","2f0"),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","b08"),exact:!0},{path:"/ts-jest/docs/29.0/getting-started/options/babelConfig",component:d("/ts-jest/docs/29.0/getting-started/options/babelConfig","848"),exact:!0},{path:"/ts-jest/docs/29.0/getting-started/options/compiler",component:d("/ts-jest/docs/29.0/getting-started/options/compiler","e6b"),exact:!0},{path:"/ts-jest/docs/29.0/getting-started/options/diagnostics",component:d("/ts-jest/docs/29.0/getting-started/options/diagnostics","0ec"),exact:!0},{path:"/ts-jest/docs/29.0/getting-started/options/isolatedModules",component:d("/ts-jest/docs/29.0/getting-started/options/isolatedModules","adc"),exact:!0},{path:"/ts-jest/docs/29.0/getting-started/options/stringifyContentPathRegex",component:d("/ts-jest/docs/29.0/getting-started/options/stringifyContentPathRegex","717"),exact:!0},{path:"/ts-jest/docs/29.0/getting-started/options/tsconfig",component:d("/ts-jest/docs/29.0/getting-started/options/tsconfig","683"),exact:!0},{path:"/ts-jest/docs/29.0/getting-started/options/useESM",component:d("/ts-jest/docs/29.0/getting-started/options/useESM","75a"),exact:!0},{path:"/ts-jest/docs/29.0/getting-started/paths-mapping",component:d("/ts-jest/docs/29.0/getting-started/paths-mapping","ac1"),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","98e"),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","275"),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","496"),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","08c"),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","b67"),exact:!0,sidebar:"version-29.0-docs"},{path:"/ts-jest/docs/29.0/guides/troubleshooting",component:d("/ts-jest/docs/29.0/guides/troubleshooting","e12"),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","694"),exact:!0,sidebar:"version-29.0-docs"},{path:"/ts-jest/docs/29.0/migration",component:d("/ts-jest/docs/29.0/migration","73e"),exact:!0,sidebar:"version-29.0-docs"},{path:"/ts-jest/docs/29.0/processing",component:d("/ts-jest/docs/29.0/processing","5d1"),exact:!0,sidebar:"version-29.0-docs"}]}]},{path:"/ts-jest/docs/next",component:d("/ts-jest/docs/next","7f0"),routes:[{path:"/ts-jest/docs/next",component:d("/ts-jest/docs/next","c8c"),routes:[{path:"/ts-jest/docs/next/",component:d("/ts-jest/docs/next/","79e"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/babel7-or-ts",component:d("/ts-jest/docs/next/babel7-or-ts","f58"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/contributing",component:d("/ts-jest/docs/next/contributing","c9d"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/debugging",component:d("/ts-jest/docs/next/debugging","59c"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/getting-started/installation",component:d("/ts-jest/docs/next/getting-started/installation","ea6"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/getting-started/options",component:d("/ts-jest/docs/next/getting-started/options","a92"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/getting-started/options/astTransformers",component:d("/ts-jest/docs/next/getting-started/options/astTransformers","c27"),exact:!0},{path:"/ts-jest/docs/next/getting-started/options/babelConfig",component:d("/ts-jest/docs/next/getting-started/options/babelConfig","246"),exact:!0},{path:"/ts-jest/docs/next/getting-started/options/compiler",component:d("/ts-jest/docs/next/getting-started/options/compiler","a39"),exact:!0},{path:"/ts-jest/docs/next/getting-started/options/diagnostics",component:d("/ts-jest/docs/next/getting-started/options/diagnostics","264"),exact:!0},{path:"/ts-jest/docs/next/getting-started/options/isolatedModules",component:d("/ts-jest/docs/next/getting-started/options/isolatedModules","aa6"),exact:!0},{path:"/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex",component:d("/ts-jest/docs/next/getting-started/options/stringifyContentPathRegex","706"),exact:!0},{path:"/ts-jest/docs/next/getting-started/options/tsconfig",component:d("/ts-jest/docs/next/getting-started/options/tsconfig","27c"),exact:!0},{path:"/ts-jest/docs/next/getting-started/options/useESM",component:d("/ts-jest/docs/next/getting-started/options/useESM","ffb"),exact:!0},{path:"/ts-jest/docs/next/getting-started/paths-mapping",component:d("/ts-jest/docs/next/getting-started/paths-mapping","030"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/getting-started/presets",component:d("/ts-jest/docs/next/getting-started/presets","77f"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/getting-started/version-checking",component:d("/ts-jest/docs/next/getting-started/version-checking","1d1"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/guides/esm-support",component:d("/ts-jest/docs/next/guides/esm-support","0f0"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/guides/mock-es6-class",component:d("/ts-jest/docs/next/guides/mock-es6-class","cee"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/guides/react-native",component:d("/ts-jest/docs/next/guides/react-native","4fe"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/guides/troubleshooting",component:d("/ts-jest/docs/next/guides/troubleshooting","816"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/guides/using-with-monorepo",component:d("/ts-jest/docs/next/guides/using-with-monorepo","75c"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/migration",component:d("/ts-jest/docs/next/migration","d2d"),exact:!0,sidebar:"docs"},{path:"/ts-jest/docs/next/processing",component:d("/ts-jest/docs/next/processing","501"),exact:!0,sidebar:"docs"}]}]},{path:"/ts-jest/docs",component:d("/ts-jest/docs","5cc"),routes:[{path:"/ts-jest/docs",component:d("/ts-jest/docs","b85"),routes:[{path:"/ts-jest/docs/",component:d("/ts-jest/docs/","95c"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/babel7-or-ts",component:d("/ts-jest/docs/babel7-or-ts","f6c"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/contributing",component:d("/ts-jest/docs/contributing","aff"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/debugging",component:d("/ts-jest/docs/debugging","c79"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/getting-started/installation",component:d("/ts-jest/docs/getting-started/installation","de7"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/getting-started/options",component:d("/ts-jest/docs/getting-started/options","bcd"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/getting-started/options/astTransformers",component:d("/ts-jest/docs/getting-started/options/astTransformers","d49"),exact:!0},{path:"/ts-jest/docs/getting-started/options/babelConfig",component:d("/ts-jest/docs/getting-started/options/babelConfig","632"),exact:!0},{path:"/ts-jest/docs/getting-started/options/compiler",component:d("/ts-jest/docs/getting-started/options/compiler","ec2"),exact:!0},{path:"/ts-jest/docs/getting-started/options/diagnostics",component:d("/ts-jest/docs/getting-started/options/diagnostics","894"),exact:!0},{path:"/ts-jest/docs/getting-started/options/isolatedModules",component:d("/ts-jest/docs/getting-started/options/isolatedModules","5df"),exact:!0},{path:"/ts-jest/docs/getting-started/options/stringifyContentPathRegex",component:d("/ts-jest/docs/getting-started/options/stringifyContentPathRegex","5a6"),exact:!0},{path:"/ts-jest/docs/getting-started/options/tsconfig",component:d("/ts-jest/docs/getting-started/options/tsconfig","77b"),exact:!0},{path:"/ts-jest/docs/getting-started/options/useESM",component:d("/ts-jest/docs/getting-started/options/useESM","8b9"),exact:!0},{path:"/ts-jest/docs/getting-started/paths-mapping",component:d("/ts-jest/docs/getting-started/paths-mapping","cd3"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/getting-started/presets",component:d("/ts-jest/docs/getting-started/presets","41f"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/getting-started/version-checking",component:d("/ts-jest/docs/getting-started/version-checking","5b5"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/guides/esm-support",component:d("/ts-jest/docs/guides/esm-support","d75"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/guides/mock-es6-class",component:d("/ts-jest/docs/guides/mock-es6-class","a11"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/guides/react-native",component:d("/ts-jest/docs/guides/react-native","b66"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/guides/troubleshooting",component:d("/ts-jest/docs/guides/troubleshooting","b45"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/guides/using-with-monorepo",component:d("/ts-jest/docs/guides/using-with-monorepo","9b2"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/migration",component:d("/ts-jest/docs/migration","cd3"),exact:!0,sidebar:"version-29.1-docs"},{path:"/ts-jest/docs/processing",component:d("/ts-jest/docs/processing","348"),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 D 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 M=D,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)(M,{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.5.2","siteVersion":"0.0.0","pluginVersions":{"docusaurus-plugin-content-docs":{"type":"package","name":"@docusaurus/plugin-content-docs","version":"3.5.2"},"docusaurus-plugin-content-blog":{"type":"package","name":"@docusaurus/plugin-content-blog","version":"3.5.2"},"docusaurus-plugin-content-pages":{"type":"package","name":"@docusaurus/plugin-content-pages","version":"3.5.2"},"docusaurus-plugin-sitemap":{"type":"package","name":"@docusaurus/plugin-sitemap","version":"3.5.2"},"docusaurus-theme-classic":{"type":"package","name":"@docusaurus/theme-classic","version":"3.5.2"},"docusaurus-plugin-ideal-image":{"type":"package","name":"@docusaurus/plugin-ideal-image","version":"3.5.2"},"docusaurus-plugin-pwa":{"type":"package","name":"@docusaurus/plugin-pwa","version":"3.5.2"}}}');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)(),D=()=>{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 M=A?.startsWith("#")??!1,I=!v.target||"_self"===v.target,F=!A||!C||!I||M&&"hash"!==x;h||!M&&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:D,onTouchStart:D,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;globalThis.Prism=e,r.forEach((e=>{"php"===e&&n(9700),n(8692)(`./prism-${e}`)})),delete globalThis.Prism}(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 D(e){if(e.component){const t=e.component;return(0,u.jsx)(t,{...e.props})}}function M(){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:D(s)})),[o,s,t])}function I(e){let{header:t,primaryMenu:n,secondaryMenu:r}=e;const{shown:s}=M();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",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=M();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 De(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 Me(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)(De,{onClick:n,className:"button button--primary shadow--lw"})}),(0,u.jsx)("hr",{}),(0,u.jsx)("div",{className:"margin-vert--md",children:(0,u.jsx)(Me,{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=f,e.exports.parse=s,e.exports.compile=function(e,t){return i(s(e,t),t)},e.exports.tokensToFunction=i,e.exports.tokensToRegExp=p;var o=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g");function s(e,t){for(var n,r=[],s=0,a=0,i="",u=t&&t.delimiter||"/";null!=(n=o.exec(e));){var d=n[0],p=n[1],f=n.index;if(i+=e.slice(a,f),a=f+d.length,p)i+=p[1];else{var g=e[a],m=n[2],h=n[3],b=n[4],v=n[5],y=n[6],w=n[7];i&&(r.push(i),i="");var k=null!=m&&null!=g&&g!==m,x="+"===y||"*"===y,j="?"===y||"*"===y,_=n[2]||u,S=b||v;r.push({name:h||s++,prefix:m||"",delimiter:_,optional:j,repeat:x,partial:k,asterisk:!!w,pattern:S?c(S):w?".*":"[^"+l(_)+"]+?"})}}return a{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