From 95082d7a41069d91f2d0773f52f5e7a6af85ccc8 Mon Sep 17 00:00:00 2001 From: Matan Borenkraout Date: Fri, 13 Oct 2023 17:00:55 +0300 Subject: [PATCH 1/4] chore: add warnings when globals are missing --- src/index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index bb0d0270..272b75b4 100644 --- a/src/index.js +++ b/src/index.js @@ -20,10 +20,13 @@ if (typeof process === 'undefined' || !process.env?.RTL_SKIP_AUTO_CLEANUP) { teardown(() => { cleanup() }) + } else { + console.warn( + `The current test runner does not support afterEach/teardown. This means won't be able to run automatic cleanup and you should be callin cleanup() manually.`, + ) } // No test setup with other test runners available - /* istanbul ignore else */ if (typeof beforeAll === 'function' && typeof afterAll === 'function') { // This matches the behavior of React < 18. let previousIsReactActEnvironment = getIsReactActEnvironment() @@ -35,6 +38,10 @@ if (typeof process === 'undefined' || !process.env?.RTL_SKIP_AUTO_CLEANUP) { afterAll(() => { setReactActEnvironment(previousIsReactActEnvironment) }) + } else { + console.warn( + 'The current test runner does not support beforeAll/afterAll. This means you should be setting IS_REACT_ACT_ENVIRONMENT manually.', + ) } } From 6440a4a22b35986e25b8351d870944ce138a32d7 Mon Sep 17 00:00:00 2001 From: Matan Borenkraout Date: Tue, 24 Oct 2023 10:45:54 +0300 Subject: [PATCH 2/4] revert the istanbul ignore removal --- src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.js b/src/index.js index 272b75b4..fa586f89 100644 --- a/src/index.js +++ b/src/index.js @@ -27,6 +27,7 @@ if (typeof process === 'undefined' || !process.env?.RTL_SKIP_AUTO_CLEANUP) { } // No test setup with other test runners available + /* istanbul ignore else */ if (typeof beforeAll === 'function' && typeof afterAll === 'function') { // This matches the behavior of React < 18. let previousIsReactActEnvironment = getIsReactActEnvironment() From 6dae7e6e756a8c62d864bf603d8fa8821a49c169 Mon Sep 17 00:00:00 2001 From: Matan Borenkraout Date: Tue, 24 Oct 2023 10:47:32 +0300 Subject: [PATCH 3/4] improve error message --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index fa586f89..11df1ef1 100644 --- a/src/index.js +++ b/src/index.js @@ -22,7 +22,7 @@ if (typeof process === 'undefined' || !process.env?.RTL_SKIP_AUTO_CLEANUP) { }) } else { console.warn( - `The current test runner does not support afterEach/teardown. This means won't be able to run automatic cleanup and you should be callin cleanup() manually.`, + `The current test runner does not support afterEach/teardown. This means we won't be able to run automatic cleanup and you should be calling cleanup() manually.`, ) } From 39fdc6cc7cdf05fb2e59c0c4035c3b19eed68330 Mon Sep 17 00:00:00 2001 From: Matan Borenkraout Date: Mon, 6 Nov 2023 20:10:11 +0200 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com> --- src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 11df1ef1..26028a9a 100644 --- a/src/index.js +++ b/src/index.js @@ -22,7 +22,7 @@ if (typeof process === 'undefined' || !process.env?.RTL_SKIP_AUTO_CLEANUP) { }) } else { console.warn( - `The current test runner does not support afterEach/teardown. This means we won't be able to run automatic cleanup and you should be calling cleanup() manually.`, + `The current test runner does not support afterEach/teardown hooks. This means we won't be able to run automatic cleanup and you should be calling cleanup() manually.`, ) } @@ -41,7 +41,7 @@ if (typeof process === 'undefined' || !process.env?.RTL_SKIP_AUTO_CLEANUP) { }) } else { console.warn( - 'The current test runner does not support beforeAll/afterAll. This means you should be setting IS_REACT_ACT_ENVIRONMENT manually.', + 'The current test runner does not support beforeAll/afterAll hooks. This means you should be setting IS_REACT_ACT_ENVIRONMENT manually.', ) } }