Skip to content

Commit

Permalink
Prevent cypress environments from being treated as unit tests (#2273)
Browse files Browse the repository at this point in the history
  • Loading branch information
r100-stack authored Sep 30, 2024
1 parent 65d3349 commit f03975a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/slow-otters-deny.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 3 additions & 1 deletion packages/itwinui-react/src/utils/functions/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f03975a

Please sign in to comment.