Repository: skovhus/jest-codemods
Pull request #571 (2024-05-06 17:40:46)

feat: support `jest.setSystemTime`
Closes https://github.com/skovhus/jest-codemods/issues/570

Seems pretty straight forward. In the interest of keeping it simple, I opted to go with `setSystemTime` rather than trying to locate and pass a config option to `useFakeTimers`.

puglyfe: @skovhus looks like this needs approval to run tests
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/skovhus/jest-codemods/pull/571?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kenneth+Skovhus) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 92.59%. Comparing base [(`a94e2b5`)](https://app.codecov.io/gh/skovhus/jest-codemods/commit/a94e2b561fed619cbebf0b9c28e0a919c44aa4e3?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kenneth+Skovhus) to head [(`443e9d7`)](https://app.codecov.io/gh/skovhus/jest-codemods/pull/571?dropdown=coverage&src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kenneth+Skovhus).
> Report is 47 commits behind head on main.


<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main     #571      +/-   ##
==========================================
+ Coverage   92.38%   92.59%   +0.20%     
==========================================
  Files          26       27       +1     
  Lines        1944     1999      +55     
  Branches      405      414       +9     
==========================================
+ Hits         1796     1851      +55     
  Misses        102      102              
  Partials       46       46              
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/skovhus/jest-codemods/pull/571?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kenneth+Skovhus).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kenneth+Skovhus).


Patch:
diff --git a/src/transformers/jasmine-globals.ts b/src/transformers/jasmine-globals.ts
index 262341f..06f9725 100644
--- a/src/transformers/jasmine-globals.ts
+++ b/src/transformers/jasmine-globals.ts
@@ -431,9 +431,10 @@ export default function jasmineGlobals(fileInfo, api, options) {
           break
         }
         case 'mockDate': {
-          logWarning(
-            'Unsupported Jasmine functionality "jasmine.clock().mockDate(*)".',
-            path
+          // make it `jest.setSystemTime(date)`
+          path.node.callee = j.memberExpression(
+            j.identifier('jest'),
+            j.identifier('setSystemTime')
           )
           break
         }


Test patch:
diff --git a/src/transformers/jasmine-globals.test.ts b/src/transformers/jasmine-globals.test.ts
index 7783acb..1d74c48 100644
--- a/src/transformers/jasmine-globals.test.ts
+++ b/src/transformers/jasmine-globals.test.ts
@@ -164,24 +164,24 @@ test('jasmine.clock()', () => {
     jasmine.clock().install();
     jasmine.clock().uninstall();
     jasmine.clock().tick(50);
+    jasmine.clock().mockDate(new Date(2013, 9, 23));
     `,
     `
     jest.useFakeTimers();
     jest.useRealTimers();
     jest.advanceTimersByTime(50);
+    jest.setSystemTime(new Date(2013, 9, 23));
     `
   )
 })
 
 test('not supported jasmine.clock()', () => {
   wrappedPlugin(`
-        jasmine.clock().mockDate(new Date(2013, 9, 23));
         jasmine.clock().unknownUtil();
     `)
 
   expect(consoleWarnings).toEqual([
-    'jest-codemods warning: (test.js line 2) Unsupported Jasmine functionality "jasmine.clock().mockDate(*)".',
-    'jest-codemods warning: (test.js line 3) Unsupported Jasmine functionality "jasmine.clock().unknownUtil".',
+    'jest-codemods warning: (test.js line 2) Unsupported Jasmine functionality "jasmine.clock().unknownUtil".',
   ])
 })