Skip to content

Commit 0a0a9f7

Browse files
authored
chore: update eslint-plugin-unicorn (#15336)
1 parent b0eb836 commit 0a0a9f7

File tree

24 files changed

+800
-816
lines changed

24 files changed

+800
-816
lines changed

.eslintrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ module.exports = {
226226
'unicorn/no-static-only-class': 'off',
227227
'unicorn/prefer-number-properties': 'off',
228228
'unicorn/prefer-string-raw': 'off',
229+
'unicorn/prefer-global-this': 'off',
229230
},
230231
},
231232
// demonstration of matchers usage

e2e/__tests__/__snapshots__/wrongEnv.test.ts.snap

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ exports[`Wrong globals for environment on node <=18 print useful error for navig
1313
1414
ReferenceError: navigator is not defined
1515
16-
30 |
17-
31 | test('use navigator', () => {
18-
> 32 | const userAgent = navigator.userAgent;
16+
31 |
17+
32 | test('use navigator', () => {
18+
> 33 | const userAgent = navigator.userAgent;
1919
| ^
20-
33 |
21-
34 | console.log(userAgent);
22-
35 |
20+
34 |
21+
35 | console.log(userAgent);
22+
36 |
2323
24-
at Object.navigator (__tests__/node.js:32:21)"
24+
at Object.navigator (__tests__/node.js:33:21)"
2525
`;
2626
2727
exports[`Wrong globals for environment print useful error for document 1`] = `
@@ -83,15 +83,15 @@ exports[`Wrong globals for environment print useful error for window 1`] = `
8383
8484
ReferenceError: window is not defined
8585
86-
22 |
8786
23 | test('use window', () => {
88-
> 24 | const location = window.location;
87+
24 | // eslint-disable-next-line unicorn/prefer-global-this
88+
> 25 | const location = window.location;
8989
| ^
90-
25 |
91-
26 | console.log(location);
92-
27 |
90+
26 |
91+
27 | console.log(location);
92+
28 |
9393
94-
at Object.window (__tests__/node.js:24:20)"
94+
at Object.window (__tests__/node.js:25:20)"
9595
`;
9696
9797
exports[`Wrong globals for environment print useful error when it explodes during evaluation 1`] = `

e2e/console-jsdom/__tests__/console.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ test('can mock console.error calls from jsdom', () => {
3030

3131
function onError(event) {}
3232

33-
window.addEventListener('error', onError);
33+
globalThis.addEventListener('error', onError);
3434
fakeNode.addEventListener(evtType, callCallback, false);
3535
evt.initEvent(evtType, false, false);
3636
fakeNode.dispatchEvent(evt);
37-
window.removeEventListener('error', onError);
37+
globalThis.removeEventListener('error', onError);
3838

3939
expect(console.error).toHaveBeenCalledTimes(1);
4040
expect(console.error).toHaveBeenCalledWith(

e2e/env-test/__tests__/equivalent.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
const {isArrayBuffer} = require('util').types;
1010
const isJSDOM =
11+
// eslint-disable-next-line unicorn/prefer-global-this
1112
typeof window !== 'undefined' && typeof document !== 'undefined';
1213

1314
const skipTestJSDOM = isJSDOM ? test.skip : test;

e2e/environmentOptions/__tests__/environmentOptions.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
/*eslint-env browser */
99

1010
test('found url jestjs.io', () => {
11-
expect(window.location.href).toBe('https://jestjs.io/');
11+
expect(globalThis.location.href).toBe('https://jestjs.io/');
1212
});

e2e/fake-timers/do-not-fake/__tests__/doNotFake.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
'use strict';
1111

1212
const mockPerformanceMark = jest.fn();
13-
window.performance.mark = mockPerformanceMark;
13+
globalThis.performance.mark = mockPerformanceMark;
1414

1515
test('fakes all APIs', () => {
1616
jest.useFakeTimers();
1717

18-
expect(window.performance.mark).toBeUndefined();
18+
expect(globalThis.performance.mark).toBeUndefined();
1919
});
2020

2121
test('does not fake `performance` instance', () => {
2222
jest.useFakeTimers({doNotFake: ['performance']});
2323

24-
expect(window.performance.mark).toBe(mockPerformanceMark);
24+
expect(globalThis.performance.mark).toBe(mockPerformanceMark);
2525
});

e2e/nested-event-loop/__tests__/nestedEventLoop.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ it('can assert on errors across nested event loops', () => {
1717
throw new Error('This should be caught.');
1818
});
1919
let caught = null;
20-
window.addEventListener('error', e => {
20+
globalThis.addEventListener('error', e => {
2121
caught = e.error;
2222
});
2323
expect(() => {

e2e/override-globals/__tests__/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ describe('parent', () => {
2929
});
3030

3131
it('can override atob and btoa', () => {
32-
// eslint-disable-next-line no-restricted-globals
33-
global.atob = () => 'hello';
34-
// eslint-disable-next-line no-restricted-globals
35-
global.btoa = () => 'there';
32+
globalThis.atob = () => 'hello';
33+
globalThis.btoa = () => 'there';
3634

3735
expect(`${atob()} ${btoa()}`).toBe('hello there');
3836
});

e2e/test-environment/__tests__/environmentOptionsFromDocblock.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
/*eslint-env browser */
1212

1313
test('use jsdom and set the URL in this test file', () => {
14-
expect(window.location.href).toBe('https://jestjs.io/');
14+
expect(globalThis.location.href).toBe('https://jestjs.io/');
1515
});

e2e/wrong-env/__tests__/node.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ test('use document', () => {
2121
});
2222

2323
test('use window', () => {
24+
// eslint-disable-next-line unicorn/prefer-global-this
2425
const location = window.location;
2526

2627
console.log(location);

0 commit comments

Comments
 (0)