jest-date-mock 1.0.7 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4
+ patreon: # Replace with a single Patreon username
5
+ open_collective: # Replace with a single Open Collective username
6
+ ko_fi: # Replace with a single Ko-fi username
7
+ tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8
+ community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9
+ liberapay: # Replace with a single Liberapay username
10
+ issuehunt: # Replace with a single IssueHunt username
11
+ otechie: # Replace with a single Otechie username
12
+ custom: ['https://paypal.me/hustcc', 'https://atool.vip']
@@ -0,0 +1,31 @@
1
+ name: build
2
+
3
+ on: [push, pull_request]
4
+
5
+ concurrency:
6
+ group: ${{github.workflow}}-${{github.event_name}}-${{github.ref}}
7
+ cancel-in-progress: true
8
+
9
+ jobs:
10
+ test-and-build:
11
+ runs-on: macos-latest
12
+ steps:
13
+ - name: Checkout
14
+ uses: actions/checkout@v3
15
+
16
+ - name: Install Node.js
17
+ uses: actions/setup-node@v3
18
+ with:
19
+ node-version: 13
20
+
21
+ - name: Install Dependencies
22
+ run: npm install
23
+
24
+ - name: Run build & test
25
+ run: |
26
+ npm run build
27
+
28
+ - name: Coveralls GitHub Action
29
+ uses: coverallsapp/github-action@v2.2.3
30
+ with:
31
+ github-token: ${{ secrets.GITHUB_TOKEN }}
package/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # jest-date-mock
2
2
 
3
- > Mock `window.Date` when run unit test cases with jest. Make tests of `Date` easier.
3
+ > Mock `Date` when run unit test cases with jest. Make tests of `Date` easier.
4
+ > - [jest-random-mock](https://github.com/hustcc/jest-random-mock) Mock `Math.random` in jest, with deterministic random generator.
5
+ > - [jest-canvas-mock](https://github.com/hustcc/jest-canvas-mock) Mock `canvas` when run unit test cases with jest.
4
6
 
5
- [![Build Status](https://travis-ci.org/hustcc/jest-date-mock.svg?branch=master)](https://travis-ci.org/hustcc/jest-date-mock)
7
+ [![Build Status](https://github.com/hustcc/jest-date-mock/workflows/build/badge.svg)](https://github.com/hustcc/jest-date-mock/actions)
6
8
  [![Coverage Status](https://coveralls.io/repos/github/hustcc/jest-date-mock/badge.svg?branch=master)](https://coveralls.io/github/hustcc/jest-date-mock)
7
9
  [![npm](https://img.shields.io/npm/v/jest-date-mock.svg)](https://www.npmjs.com/package/jest-date-mock)
8
10
  [![npm](https://img.shields.io/npm/dm/jest-date-mock.svg)](https://www.npmjs.com/package/jest-date-mock)
package/lib/date.js CHANGED
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.now = exports.clear = exports.advanceTo = exports.advanceBy = void 0;
6
7
  /**
7
8
  * Created by hustcc 18/05/27.
8
9
  * Contract: i@hust.cc
package/lib/index.js CHANGED
@@ -1,42 +1,47 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.version = exports.clear = exports.advanceTo = exports.advanceBy = undefined;
7
-
8
- var _date = require('./date');
9
-
10
- Object.defineProperty(exports, 'advanceBy', {
6
+ Object.defineProperty(exports, "advanceBy", {
11
7
  enumerable: true,
12
8
  get: function get() {
13
9
  return _date.advanceBy;
14
10
  }
15
11
  });
16
- Object.defineProperty(exports, 'advanceTo', {
12
+ Object.defineProperty(exports, "advanceTo", {
17
13
  enumerable: true,
18
14
  get: function get() {
19
15
  return _date.advanceTo;
20
16
  }
21
17
  });
22
- Object.defineProperty(exports, 'clear', {
18
+ Object.defineProperty(exports, "clear", {
23
19
  enumerable: true,
24
20
  get: function get() {
25
21
  return _date.clear;
26
22
  }
27
23
  });
28
-
29
- var _mockDate = require('./mockDate');
24
+ exports.version = void 0;
25
+ var _date = require("./date");
26
+ var _mockDate = require("./mockDate");
27
+ /**
28
+ * Created by hustcc 18/05/27.
29
+ * Contract: i@hust.cc
30
+ */
30
31
 
31
32
  // mock Date class
32
33
  var dateClass = (0, _mockDate.mockDateClass)(Date);
33
-
34
34
  if (global.window) {
35
35
  // dom env
36
36
  global.window.Date = dateClass;
37
+ global.window.performance.now = function () {
38
+ return dateClass.now();
39
+ };
37
40
  } else {
38
41
  // node / native env
39
42
  global.Date = dateClass;
43
+ require('perf_hooks').performance.now = function () {
44
+ return dateClass.now();
45
+ };
40
46
  }
41
-
42
- var version = exports.version = '1.0.7';
47
+ var version = exports.version = "1.0.9";
package/lib/mockDate.js CHANGED
@@ -1,45 +1,49 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.mockDateClass = undefined;
7
-
8
- var _date = require('./date');
9
-
6
+ exports.mockDateClass = void 0;
7
+ var _date = require("./date");
8
+ function _construct(t, e, r) { if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && _setPrototypeOf(p, r.prototype), p; }
9
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
10
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
11
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
12
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
13
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
14
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
15
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
16
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } /**
17
+ * Created by hustcc 18/05/27.
18
+ * Contract: i@hust.cc
19
+ */
10
20
  var mockDateClass = exports.mockDateClass = function mockDateClass(D) {
11
21
  // if undefined, use real date, or else mock date
12
22
  var mockNow = function mockNow() {
13
23
  return (0, _date.now)() === undefined ? D.now() : (0, _date.now)();
14
24
  };
15
-
16
- function MD() {
17
- for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
25
+ function Date() {
26
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
18
27
  args[_key] = arguments[_key];
19
28
  }
20
-
21
29
  var dateArgs = args.length === 0 ? [mockNow()] : args;
22
- var instance = new (Function.prototype.bind.apply(D, [null].concat(dateArgs)))();
30
+ var instance = _construct(D, _toConsumableArray(dateArgs));
23
31
  Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
32
+ instance.constructor = Date;
24
33
  return instance;
25
34
  }
26
-
27
- MD.prototype = Object.create(D.prototype);
28
- Object.setPrototypeOf(MD, D);
35
+ Date.prototype = Object.create(D.prototype);
36
+ Object.setPrototypeOf(Date, D);
29
37
 
30
38
  // undefined means do not mock date
31
- MD.now = function () {
39
+ Date.now = function () {
32
40
  return mockNow();
33
41
  };
34
42
  // original Date class
35
- MD.__OriginalDate__ = D;
43
+ Date.__OriginalDate__ = D;
36
44
  // current() is for test.
37
- MD.current = function () {
45
+ Date.current = function () {
38
46
  return D.now();
39
47
  };
40
-
41
- return MD;
42
- }; /**
43
- * Created by hustcc 18/05/27.
44
- * Contract: i@hust.cc
45
- */
48
+ return Date;
49
+ };
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "jest-date-mock",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Mock `window.Date` when run unit test cases with jest. Make tests of `Date` easier.",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "scripts": {
8
8
  "test": "jest --no-cache",
9
- "build": "babel src --out-dir lib --copy-files && npm run test",
10
- "coveralls": "cat ./coverage/lcov.info | coveralls"
9
+ "build": "babel src --out-dir lib --copy-files && npm run test"
11
10
  },
12
11
  "repository": {
13
12
  "type": "git",
@@ -28,12 +27,12 @@
28
27
  },
29
28
  "homepage": "https://github.com/hustcc/jest-date-mock#readme",
30
29
  "devDependencies": {
31
- "babel-cli": "^6.26.0",
32
- "babel-jest": "^22.0.4",
30
+ "@babel/cli": "^7.7.7",
31
+ "@babel/core": "^7.7.7",
32
+ "@babel/preset-env": "^7.7.7",
33
+ "babel-jest": "^24.9.0",
33
34
  "babel-plugin-version": "^0.2.2",
34
- "babel-preset-env": "^1.6.1",
35
- "coveralls": "^3.0.0",
36
- "jest": "^21.2.1"
35
+ "jest": "^24.9.0"
37
36
  },
38
37
  "jest": {
39
38
  "collectCoverage": true,