Skip to content

Commit e41c156

Browse files
committed
fix: protect import helpers for setting env variables and comment why try/catch is being used
1 parent a16578a commit e41c156

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

disable-error-filtering.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
process.env.RHTL_DISABLE_ERROR_FILTERING = true
1+
try {
2+
process.env.RHTL_DISABLE_ERROR_FILTERING = true
3+
} catch {
4+
// falling back in the case that process.env.RHTL_DISABLE_ERROR_FILTERING cannot be accessed (e.g. browser environment)
5+
console.warn(
6+
'Could not disable error filtering as process.env.RHTL_DISABLE_ERROR_FILTERING could not be accessed.'
7+
)
8+
}

dont-cleanup-after-each.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
process.env.RHTL_SKIP_AUTO_CLEANUP = true
1+
try {
2+
process.env.RHTL_SKIP_AUTO_CLEANUP = true
3+
} catch {
4+
// falling back in the case that process.env.RHTL_SKIP_AUTO_CLEANUP cannot be accessed (e.g. browser environment)
5+
console.warn(
6+
'Could not skip auto cleanup as process.env.RHTL_SKIP_AUTO_CLEANUP could not be accessed.'
7+
)
8+
}

src/core/cleanup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function skipAutoCleanup() {
2222
try {
2323
return !!process.env.RHTL_SKIP_AUTO_CLEANUP
2424
} catch {
25+
// falling back in the case that process.env.RHTL_SKIP_AUTO_CLEANUP cannot be accessed (e.g. browser environment)
2526
return false
2627
}
2728
}

src/core/console.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function errorFilteringDisabled() {
2424
try {
2525
return !!process.env.RHTL_DISABLE_ERROR_FILTERING
2626
} catch {
27+
// falling back in the case that process.env.RHTL_DISABLE_ERROR_FILTERING cannot be accessed (e.g. browser environment)
2728
return false
2829
}
2930
}

0 commit comments

Comments
 (0)