chore: replace Sinon usage with Jest (#75940)

This commit is contained in:
Simen Bekkhus 2023-10-04 12:12:30 +02:00 committed by GitHub
parent 8ba7a73278
commit 3749c17556
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 17 additions and 121 deletions

View File

@ -3,16 +3,7 @@
// 2. Any wrong timezone handling could be hidden if we use UTC/GMT local time (which would happen in CI).
process.env.TZ = 'Pacific/Easter'; // UTC-06:00 or UTC-05:00 depending on daylight savings
const esModules = [
'ol',
'd3',
'd3-color',
'd3-interpolate',
'delaunator',
'internmap',
'robust-predicates',
'sinon',
].join('|');
const esModules = ['ol', 'd3', 'd3-color', 'd3-interpolate', 'delaunator', 'internmap', 'robust-predicates'].join('|');
module.exports = {
verbose: false,

View File

@ -211,7 +211,6 @@
"rudder-sdk-js": "2.37.0",
"sass": "1.63.6",
"sass-loader": "13.3.2",
"sinon": "15.2.0",
"style-loader": "3.3.3",
"stylelint": "15.10.1",
"stylelint-config-prettier": "9.0.5",

View File

@ -80,7 +80,6 @@
"@types/papaparse": "5.3.7",
"@types/react": "18.2.15",
"@types/react-dom": "18.2.7",
"@types/sinon": "10.0.15",
"@types/testing-library__jest-dom": "5.14.8",
"@types/tinycolor2": "1.4.3",
"esbuild": "0.18.12",
@ -92,7 +91,6 @@
"rollup-plugin-dts": "^5.0.0",
"rollup-plugin-esbuild": "5.0.0",
"rollup-plugin-node-externals": "^5.0.0",
"sinon": "15.2.0",
"typescript": "4.8.4"
},
"peerDependencies": {

View File

@ -1,5 +1,4 @@
import { each } from 'lodash';
import sinon, { SinonFakeTimers } from 'sinon';
import * as dateMath from './datemath';
import { dateTime, DurationUnit, DateTime } from './moment_wrapper';
@ -9,7 +8,6 @@ describe('DateMath', () => {
const anchor = '2014-01-01T06:06:06.666Z';
const unix = dateTime(anchor).valueOf();
const format = 'YYYY-MM-DDTHH:mm:ss.SSSZ';
let clock: SinonFakeTimers;
describe('errors', () => {
it('should return undefined if passed empty string', () => {
@ -57,11 +55,11 @@ describe('DateMath', () => {
describe('with fiscal quarters', () => {
beforeEach(() => {
const fixedTime = dateTime('2023-07-05T06:06:06.666Z').valueOf();
clock = sinon.useFakeTimers(fixedTime);
jest.useFakeTimers({ now: fixedTime });
});
afterEach(() => {
clock.restore();
jest.useRealTimers();
});
it('should parse current fiscal quarter correctly', () => {
@ -106,7 +104,7 @@ describe('DateMath', () => {
let anchored: DateTime;
beforeEach(() => {
clock = sinon.useFakeTimers(unix);
jest.useFakeTimers({ now: unix });
now = dateTime();
anchored = dateTime(anchor);
});
@ -125,7 +123,7 @@ describe('DateMath', () => {
});
afterEach(() => {
clock.restore();
jest.useRealTimers();
});
});
@ -133,7 +131,7 @@ describe('DateMath', () => {
let now: DateTime;
beforeEach(() => {
clock = sinon.useFakeTimers(unix);
jest.useFakeTimers({ now: unix });
now = dateTime();
});
@ -148,7 +146,7 @@ describe('DateMath', () => {
});
afterEach(() => {
clock.restore();
jest.useRealTimers();
});
});

View File

@ -30,7 +30,6 @@
"expect": true,
"it": true,
"describe": true,
"sinon": true,
"define": true,
"module": true,
"beforeEach": true,

View File

@ -1,9 +1,7 @@
const _global = window as any;
const sinon = _global.sinon;
const angularMocks = {
module: _global.module,
inject: _global.inject,
};
export { sinon, angularMocks };
export { angularMocks };

View File

@ -6,7 +6,7 @@ import config from 'app/core/config';
import { ContextSrv } from 'app/core/services/context_srv';
import { PanelModel } from 'app/features/dashboard/state/PanelModel';
import { angularMocks, sinon } from '../lib/common';
import { angularMocks } from '../lib/common';
export function ControllerTestContext(this: any) {
const self = this;
@ -56,8 +56,8 @@ export function ControllerTestContext(this: any) {
return self.isUtc ? 'utc' : 'browser';
};
$rootScope.appEvent = sinon.spy();
$rootScope.onAppEvent = sinon.spy();
$rootScope.appEvent = jest.fn();
$rootScope.onAppEvent = jest.fn();
$rootScope.colors = [];
for (let i = 0; i < 50; i++) {
@ -85,8 +85,8 @@ export function ControllerTestContext(this: any) {
self.scope.dashboard = { meta: {} };
self.scope.dashboardMeta = {};
self.scope.dashboardViewState = DashboardViewStateStub();
self.scope.appEvent = sinon.spy();
self.scope.onAppEvent = sinon.spy();
self.scope.appEvent = jest.fn();
self.scope.onAppEvent = jest.fn();
$rootScope.colors = [];
for (let i = 0; i < 50; i++) {

View File

@ -3007,7 +3007,6 @@ __metadata:
"@types/papaparse": 5.3.7
"@types/react": 18.2.15
"@types/react-dom": 18.2.7
"@types/sinon": 10.0.15
"@types/string-hash": 1.1.1
"@types/testing-library__jest-dom": 5.14.8
"@types/tinycolor2": 1.4.3
@ -3036,7 +3035,6 @@ __metadata:
rollup-plugin-esbuild: 5.0.0
rollup-plugin-node-externals: ^5.0.0
rxjs: 7.8.1
sinon: 15.2.0
string-hash: ^1.1.3
tinycolor2: 1.6.0
tslib: 2.6.0
@ -7027,15 +7025,6 @@ __metadata:
languageName: node
linkType: hard
"@sinonjs/commons@npm:^2.0.0":
version: 2.0.0
resolution: "@sinonjs/commons@npm:2.0.0"
dependencies:
type-detect: 4.0.8
checksum: 5023ba17edf2b85ed58262313b8e9b59e23c6860681a9af0200f239fe939e2b79736d04a260e8270ddd57196851dde3ba754d7230be5c5234e777ae2ca8af137
languageName: node
linkType: hard
"@sinonjs/commons@npm:^3.0.0":
version: 3.0.0
resolution: "@sinonjs/commons@npm:3.0.0"
@ -7045,7 +7034,7 @@ __metadata:
languageName: node
linkType: hard
"@sinonjs/fake-timers@npm:^10.0.2, @sinonjs/fake-timers@npm:^10.3.0":
"@sinonjs/fake-timers@npm:^10.0.2":
version: 10.3.0
resolution: "@sinonjs/fake-timers@npm:10.3.0"
dependencies:
@ -7054,24 +7043,6 @@ __metadata:
languageName: node
linkType: hard
"@sinonjs/samsam@npm:^8.0.0":
version: 8.0.0
resolution: "@sinonjs/samsam@npm:8.0.0"
dependencies:
"@sinonjs/commons": ^2.0.0
lodash.get: ^4.4.2
type-detect: ^4.0.8
checksum: 95e40d0bb9f7288e27c379bee1b03c3dc51e7e78b9d5ea6aef66a690da7e81efc4715145b561b449cefc5361a171791e3ce30fb1a46ab247d4c0766024c60a60
languageName: node
linkType: hard
"@sinonjs/text-encoding@npm:^0.7.1":
version: 0.7.1
resolution: "@sinonjs/text-encoding@npm:0.7.1"
checksum: 130de0bb568c5f8a611ec21d1a4e3f80ab0c5ec333010f49cfc1adc5cba6d8808699c8a587a46b0f0b016a1f4c1389bc96141e773e8460fcbb441875b2e91ba7
languageName: node
linkType: hard
"@storybook/addon-a11y@npm:7.4.5":
version: 7.4.5
resolution: "@storybook/addon-a11y@npm:7.4.5"
@ -9819,16 +9790,7 @@ __metadata:
languageName: node
linkType: hard
"@types/sinon@npm:10.0.15":
version: 10.0.15
resolution: "@types/sinon@npm:10.0.15"
dependencies:
"@types/sinonjs__fake-timers": "*"
checksum: cec6d7d9d5582ca3ac851b029d5d90451bfe6d376164253792a6eb6ddcd609a0411a7fac9ed92e1879e7d3ec091d2ea2e8dbb4f6140a1065439b81dc20cafa7c
languageName: node
linkType: hard
"@types/sinonjs__fake-timers@npm:*, @types/sinonjs__fake-timers@npm:8.1.1":
"@types/sinonjs__fake-timers@npm:8.1.1":
version: 8.1.1
resolution: "@types/sinonjs__fake-timers@npm:8.1.1"
checksum: ca09d54d47091d87020824a73f026300fa06b17cd9f2f9b9387f28b549364b141ef194ee28db762f6588de71d8febcd17f753163cb7ea116b8387c18e80ebd5c
@ -14812,13 +14774,6 @@ __metadata:
languageName: node
linkType: hard
"diff@npm:^5.1.0":
version: 5.1.0
resolution: "diff@npm:5.1.0"
checksum: c7bf0df7c9bfbe1cf8a678fd1b2137c4fb11be117a67bc18a0e03ae75105e8533dbfb1cda6b46beb3586ef5aed22143ef9d70713977d5fb1f9114e21455fba90
languageName: node
linkType: hard
"dir-glob@npm:^3.0.1":
version: 3.0.1
resolution: "dir-glob@npm:3.0.1"
@ -17966,7 +17921,6 @@ __metadata:
sass-loader: 13.3.2
selecto: 1.26.0
semver: 7.5.4
sinon: 15.2.0
slate: 0.47.9
slate-plain-serializer: 0.7.13
slate-react: 0.22.10
@ -20779,13 +20733,6 @@ __metadata:
languageName: node
linkType: hard
"just-extend@npm:^4.0.2":
version: 4.2.1
resolution: "just-extend@npm:4.2.1"
checksum: ff9fdede240fad313efeeeb68a660b942e5586d99c0058064c78884894a2690dc09bba44c994ad4e077e45d913fef01a9240c14a72c657b53687ac58de53b39c
languageName: node
linkType: hard
"kbar@npm:0.1.0-beta.40":
version: 0.1.0-beta.40
resolution: "kbar@npm:0.1.0-beta.40"
@ -21134,13 +21081,6 @@ __metadata:
languageName: node
linkType: hard
"lodash.get@npm:^4.4.2":
version: 4.4.2
resolution: "lodash.get@npm:4.4.2"
checksum: e403047ddb03181c9d0e92df9556570e2b67e0f0a930fcbbbd779370972368f5568e914f913e93f3b08f6d492abc71e14d4e9b7a18916c31fa04bd2306efe545
languageName: node
linkType: hard
"lodash.intersection@npm:^4.4.0":
version: 4.4.0
resolution: "lodash.intersection@npm:4.4.0"
@ -22304,19 +22244,6 @@ __metadata:
languageName: node
linkType: hard
"nise@npm:^5.1.4":
version: 5.1.4
resolution: "nise@npm:5.1.4"
dependencies:
"@sinonjs/commons": ^2.0.0
"@sinonjs/fake-timers": ^10.0.2
"@sinonjs/text-encoding": ^0.7.1
just-extend: ^4.0.2
path-to-regexp: ^1.7.0
checksum: bc57c10eaec28a6a7ddfb2e1e9b21d5e1fe22710e514f8858ae477cf9c7e9c891475674d5241519193403db43d16c3675f4207bc094a7a27b7e4f56584a78c1b
languageName: node
linkType: hard
"no-case@npm:^3.0.4":
version: 3.0.4
resolution: "no-case@npm:3.0.4"
@ -27090,20 +27017,6 @@ __metadata:
languageName: node
linkType: hard
"sinon@npm:15.2.0":
version: 15.2.0
resolution: "sinon@npm:15.2.0"
dependencies:
"@sinonjs/commons": ^3.0.0
"@sinonjs/fake-timers": ^10.3.0
"@sinonjs/samsam": ^8.0.0
diff: ^5.1.0
nise: ^5.1.4
supports-color: ^7.2.0
checksum: 1641b9af8a73ba57c73c9b6fd955a2d062a5d78cce719887869eca45faf33b0fd20cabfeffdfd856bb35bfbd3d49debb2d954ff6ae5e9825a3da5ff4f604ab6c
languageName: node
linkType: hard
"sirv@npm:^1.0.7":
version: 1.0.18
resolution: "sirv@npm:1.0.18"
@ -28148,7 +28061,7 @@ __metadata:
languageName: node
linkType: hard
"supports-color@npm:^7.0.0, supports-color@npm:^7.1.0, supports-color@npm:^7.2.0":
"supports-color@npm:^7.0.0, supports-color@npm:^7.1.0":
version: 7.2.0
resolution: "supports-color@npm:7.2.0"
dependencies:
@ -28996,7 +28909,7 @@ __metadata:
languageName: node
linkType: hard
"type-detect@npm:4.0.8, type-detect@npm:^4.0.8":
"type-detect@npm:4.0.8":
version: 4.0.8
resolution: "type-detect@npm:4.0.8"
checksum: 62b5628bff67c0eb0b66afa371bd73e230399a8d2ad30d852716efcc4656a7516904570cd8631a49a3ce57c10225adf5d0cbdcb47f6b0255fe6557c453925a15