Skip to content

Commit 7402db3

Browse files
committed
chore: add sinon for mocking current date to test useCurrentYearIfMissing option
1 parent 64959db commit 7402db3

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
},
2828
"homepage": "https://github.com/textlint-rule/textlint-rule-date-weekday-mismatch",
2929
"devDependencies": {
30+
"sinon": "^20.0.0",
3031
"textlint-scripts": "^12.0.2"
3132
},
3233
"keywords": [

test/textlint-rule-date-weekday-mismatch-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
import TextLintTester from "textlint-tester";
2+
import sinon from "sinon";
23

34
const tester = new TextLintTester();
45
// rule
56
const rule = require("../src/textlint-rule-date-weekday-mismatch");
7+
8+
// Mock: fix current date to 2025-04-23 to test `useCurrentYearIfMissing` option
9+
let clock;
10+
before(() => {
11+
clock = sinon.useFakeTimers(new Date(2025, 4, 23).getTime());
12+
});
13+
after(() => {
14+
clock.restore();
15+
});
16+
617
// ruleName, rule, { valid, invalid }
718
tester.run("rule", rule, {
819
valid: [

yarn.lock

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,29 @@
993993
readdirp "^2.2.1"
994994
upath "^1.1.1"
995995

996+
"@sinonjs/commons@^3.0.1":
997+
version "3.0.1"
998+
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-3.0.1.tgz#1029357e44ca901a615585f6d27738dbc89084cd"
999+
integrity sha512-K3mCHKQ9sVh8o1C9cxkwxaOmXoAMlDxC1mYyHrjqOWEcBjYr76t96zL2zlj5dUGZ3HSw240X1qgH3Mjf1yJWpQ==
1000+
dependencies:
1001+
type-detect "4.0.8"
1002+
1003+
"@sinonjs/fake-timers@^13.0.5":
1004+
version "13.0.5"
1005+
resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-13.0.5.tgz#36b9dbc21ad5546486ea9173d6bea063eb1717d5"
1006+
integrity sha512-36/hTbH2uaWuGVERyC6da9YwGWnzUZXuPro/F2LfsdOsLnCojz/iSH8MxUt/FD2S5XBSVPhmArFUXcpCQ2Hkiw==
1007+
dependencies:
1008+
"@sinonjs/commons" "^3.0.1"
1009+
1010+
"@sinonjs/samsam@^8.0.1":
1011+
version "8.0.2"
1012+
resolved "https://registry.yarnpkg.com/@sinonjs/samsam/-/samsam-8.0.2.tgz#e4386bf668ff36c95949e55a38dc5f5892fc2689"
1013+
integrity sha512-v46t/fwnhejRSFTGqbpn9u+LQ9xJDse10gNnPgAcxgdoCDMXj/G2asWAC/8Qs+BAZDicX+MNZouXT1A7c83kVw==
1014+
dependencies:
1015+
"@sinonjs/commons" "^3.0.1"
1016+
lodash.get "^4.4.2"
1017+
type-detect "^4.1.0"
1018+
9961019
"@textlint/ast-node-types@^12.0.0":
9971020
version "12.0.0"
9981021
resolved "https://registry.yarnpkg.com/@textlint/ast-node-types/-/ast-node-types-12.0.0.tgz#23bd683f9fc04209ae28bff72954c8aa67c6b1ca"
@@ -1785,6 +1808,11 @@ diff@^4.0.2:
17851808
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
17861809
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
17871810

1811+
diff@^7.0.0:
1812+
version "7.0.0"
1813+
resolved "https://registry.yarnpkg.com/diff/-/diff-7.0.0.tgz#3fb34d387cd76d803f6eebea67b921dab0182a9a"
1814+
integrity sha512-PJWHUb1RFevKCwaFA9RlG5tCd+FO5iRh9A8HEtkmBH2Li03iJriB6m6JIN4rGz3K3JLawI7/veA1xzRKP6ISBw==
1815+
17881816
ejs@^2.4.1:
17891817
version "2.7.1"
17901818
resolved "https://registry.yarnpkg.com/ejs/-/ejs-2.7.1.tgz#5b5ab57f718b79d4aca9254457afecd36fa80228"
@@ -2565,6 +2593,11 @@ lodash.debounce@^4.0.8:
25652593
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
25662594
integrity sha1-gteb/zCmfEAF/9XiUVMArZyk168=
25672595

2596+
lodash.get@^4.4.2:
2597+
version "4.4.2"
2598+
resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"
2599+
integrity sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==
2600+
25682601
lodash.truncate@^4.4.2:
25692602
version "4.4.2"
25702603
resolved "https://registry.yarnpkg.com/lodash.truncate/-/lodash.truncate-4.4.2.tgz#5a350da0b1113b837ecfffd5812cbe58d6eae193"
@@ -3614,6 +3647,17 @@ signal-exit@^3.0.0:
36143647
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
36153648
integrity sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=
36163649

3650+
sinon@^20.0.0:
3651+
version "20.0.0"
3652+
resolved "https://registry.yarnpkg.com/sinon/-/sinon-20.0.0.tgz#4b653468735f7152ba694d05498c2b5d024ab006"
3653+
integrity sha512-+FXOAbdnj94AQIxH0w1v8gzNxkawVvNqE3jUzRLptR71Oykeu2RrQXXl/VQjKay+Qnh73fDt/oDfMo6xMeDQbQ==
3654+
dependencies:
3655+
"@sinonjs/commons" "^3.0.1"
3656+
"@sinonjs/fake-timers" "^13.0.5"
3657+
"@sinonjs/samsam" "^8.0.1"
3658+
diff "^7.0.0"
3659+
supports-color "^7.2.0"
3660+
36173661
slash@^2.0.0:
36183662
version "2.0.0"
36193663
resolved "https://registry.yarnpkg.com/slash/-/slash-2.0.0.tgz#de552851a1759df3a8f206535442f5ec4ddeab44"
@@ -3842,7 +3886,7 @@ supports-color@^5.3.0:
38423886
dependencies:
38433887
has-flag "^3.0.0"
38443888

3845-
supports-color@^7.1.0:
3889+
supports-color@^7.1.0, supports-color@^7.2.0:
38463890
version "7.2.0"
38473891
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da"
38483892
integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==
@@ -3990,6 +4034,16 @@ type-check@^0.4.0, type-check@~0.4.0:
39904034
dependencies:
39914035
prelude-ls "^1.2.1"
39924036

4037+
4038+
version "4.0.8"
4039+
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"
4040+
integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==
4041+
4042+
type-detect@^4.1.0:
4043+
version "4.1.0"
4044+
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.1.0.tgz#deb2453e8f08dcae7ae98c626b13dddb0155906c"
4045+
integrity sha512-Acylog8/luQ8L7il+geoSxhEkazvkslg7PSNKOX59mbB9cOveP5aq9h74Y7YU8yDpJwetzQQrfIwtf4Wp4LKcw==
4046+
39934047
unicode-canonical-property-names-ecmascript@^1.0.4:
39944048
version "1.0.4"
39954049
resolved "https://registry.yarnpkg.com/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz#2619800c4c825800efdd8343af7dd9933cbe2818"

0 commit comments

Comments
 (0)