From f03975a0df333166a722c2dc59adc78ba1760790 Mon Sep 17 00:00:00 2001 From: Rohan <45748283+r100-stack@users.noreply.github.com> Date: Mon, 30 Sep 2024 14:44:46 -0400 Subject: [PATCH] Prevent cypress environments from being treated as unit tests (#2273) --- .changeset/slow-otters-deny.md | 5 +++++ packages/itwinui-react/src/utils/functions/dev.ts | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .changeset/slow-otters-deny.md diff --git a/.changeset/slow-otters-deny.md b/.changeset/slow-otters-deny.md new file mode 100644 index 00000000000..2d8cf3b7449 --- /dev/null +++ b/.changeset/slow-otters-deny.md @@ -0,0 +1,5 @@ +--- +'@itwin/itwinui-react': patch +--- + +Fixed an issue where the internal unit test detection logic was incorrectly treating Cypress like a unit test environment. diff --git a/packages/itwinui-react/src/utils/functions/dev.ts b/packages/itwinui-react/src/utils/functions/dev.ts index 32a5fc3a066..5fb8e911d2b 100644 --- a/packages/itwinui-react/src/utils/functions/dev.ts +++ b/packages/itwinui-react/src/utils/functions/dev.ts @@ -6,10 +6,12 @@ // @ts-expect-error -- jest is not used in iTwinUI but may be used in consuming apps const isJest = typeof jest !== 'undefined'; +const isCypress = typeof (globalThis as any).Cypress !== 'undefined'; const isMocha = typeof (globalThis as any).beforeEach !== 'undefined' && `${(globalThis as any).beforeEach}`.replace(/\s/g, '') === - 'function(name,fn){suites[0].beforeEach(name,fn);}'; + 'function(name,fn){suites[0].beforeEach(name,fn);}' && + !isCypress; const isVitest = typeof (globalThis as any).__vitest_index__ !== 'undefined'; const isUnitTest = isJest || isVitest || isMocha;