Repository: asciidwango/js-primer (2025-08-11T09:13:44Z)

Issue:
mocha to node:test
mochaが残ってる部分をnode:testとtest runnerに置き換える


Discussion:

Patch:
diff --git a/package.json b/package.json
index 84a8670351..3a51c5998d 100644
--- a/package.json
+++ b/package.json
@@ -30,10 +30,10 @@
     "lint": "npm-run-all --parallel textlint eslint",
     "lint:fix": "npm-run-all --parallel textlint:fix eslint:fix",
     "test:example": "node --test --test-force-exit \"test/*.js\"",
-    "test:basic": "mocha \"./source/basic/**/*-test.js\"",
+    "test:basic": "node --test \"./source/basic/**/*-test.js\"",
     "test:nodecli": "cd ./source/use-case/nodecli && npm install && npm test",
     "test:nodecli-unittest": "cd ./source/use-case/nodecli/refactor-and-unittest/src/test && npm install && npm test",
-    "test:ajaxapp": "mocha \"./source/use-case/ajaxapp/!(node_modules)**/*-test.js\"",
+    "test:ajaxapp": "node --test \"./source/use-case/ajaxapp/!(node_modules)**/*-test.js\"",
     "test:todoapp": "cd ./source/use-case/todoapp && npm install && npm test",
     "test": "npm-run-all -l --parallel test:* lint",
     "e2e:todoapp": "cd ./source/use-case/todoapp && npm install && npm run e2e",
@@ -86,7 +86,6 @@
     "jsdom-global": "3.0.2",
     "meow": "^7.1.1",
     "micromatch": "^4.0.5",
-    "mocha": "^11.7.1",
     "npm-run-all2": "^8.0.4",
     "power-assert": "^1.6.1",
     "prettier": "^3.6.2",


Test patch:
diff --git a/source/basic/condition/test/if/leap-year-flat-example-test.js b/source/basic/condition/test/if/leap-year-flat-example-test.js
index ff4944dc6d..a2ede87d0e 100644
--- a/source/basic/condition/test/if/leap-year-flat-example-test.js
+++ b/source/basic/condition/test/if/leap-year-flat-example-test.js
@@ -3,6 +3,7 @@ import strictEval from "strict-eval";
 import fs from "fs";
 import path from "path";
 import url from "url";
+import { describe, it } from "node:test";
 const __filename__ = url.fileURLToPath(import.meta.url);
 const __dirname = path.dirname(__filename__);
 const Code = fs.readFileSync(path.join(__dirname, "../../src/if/leap-year-flat-example.js"), "utf-8");
@@ -23,7 +24,7 @@ const testLeapYear = (year, expectedMessage) => {
     });
 };
 describe("leap-year-flat", function() {
-    context("うるう年であるならば", function() {
+    describe("うるう年であるならば", function() {
         it("should return \"うるう年です\"", function() {
             const message = (year) => `${year}年はうるう年です`;
             testLeapYear(0, message);
@@ -34,7 +35,7 @@ describe("leap-year-flat", function() {
             testLeapYear(1289031804, message);
         });
     });
-    context("うるう年でないならば", function() {
+    describe("うるう年でないならば", function() {
         it("should return \"うるう年ではありません\"", function() {
             const message = (year) => `${year}年はうるう年ではありません`;
             testLeapYear(100, message);
diff --git a/source/basic/condition/test/if/leap-year-nest-example-test.js b/source/basic/condition/test/if/leap-year-nest-example-test.js
index 10da2d43df..0654f76ff2 100644
--- a/source/basic/condition/test/if/leap-year-nest-example-test.js
+++ b/source/basic/condition/test/if/leap-year-nest-example-test.js
@@ -3,6 +3,7 @@ import strictEval from "strict-eval";
 import fs from "fs";
 import path from "path";
 import url from "url";
+import { describe, it } from "node:test";
 const __filename__ = url.fileURLToPath(import.meta.url);
 const __dirname = path.dirname(__filename__);
 const Code = fs.readFileSync(path.join(__dirname, "../../src/if/leap-year-nest-example.js"), "utf-8");
@@ -23,7 +24,7 @@ const testLeapYear = (year, expectedMessage) => {
     });
 };
 describe("leap-year-nest", function() {
-    context("うるう年であるならば", function() {
+    describe("うるう年であるならば", function() {
         it("should return \"うるう年です\"", function() {
             const message = (year) => `${year}年はうるう年です`;
             testLeapYear(0, message);
@@ -34,7 +35,7 @@ describe("leap-year-nest", function() {
             testLeapYear(1289031804, message);
         });
     });
-    context("うるう年でないならば", function() {
+    describe("うるう年でないならば", function() {
         it("should return \"うるう年ではありません\"", function() {
             const message = (year) => `${year}年はうるう年ではありません`;
             testLeapYear(100, message);
diff --git a/source/basic/condition/test/swtich/miss-case-example-test.js b/source/basic/condition/test/swtich/miss-case-example-test.js
index 963fb8603a..aae6b8c27f 100644
--- a/source/basic/condition/test/swtich/miss-case-example-test.js
+++ b/source/basic/condition/test/swtich/miss-case-example-test.js
@@ -3,6 +3,7 @@ import strictEval from "strict-eval";
 import fs from "fs";
 import path from "path";
 import url from "node:url";
+import { describe, it } from "node:test";
 const __filename__ = url.fileURLToPath(import.meta.url);
 const __dirname = path.dirname(__filename__);
 
diff --git a/source/basic/condition/test/swtich/switch-example-test.js b/source/basic/condition/test/swtich/switch-example-test.js
index 7e37eb27c9..ff2f52f0d4 100644
--- a/source/basic/condition/test/swtich/switch-example-test.js
+++ b/source/basic/condition/test/swtich/switch-example-test.js
@@ -3,6 +3,7 @@ import strictEval from "strict-eval";
 import fs from "fs";
 import path from "path";
 import url from "node:url";
+import { describe, it } from "node:test";
 const __filename__ = url.fileURLToPath(import.meta.url);
 const __dirname = path.dirname(__filename__);
 
diff --git a/source/basic/loop/test/do-while/do-while-example-test.js b/source/basic/loop/test/do-while/do-while-example-test.js
index 0d948f3656..5ec246393c 100644
--- a/source/basic/loop/test/do-while/do-while-example-test.js
+++ b/source/basic/loop/test/do-while/do-while-example-test.js
@@ -3,6 +3,7 @@ import strictEval from "strict-eval";
 import fs from "fs";
 import url from "node:url";
 import path from "node:path";
+import { describe, it } from "node:test";
 
 const __filename__ = url.fileURLToPath(import.meta.url);
 const __dirname = path.dirname(__filename__);
diff --git a/source/basic/loop/test/for-in/for-in-array-bug-example-test.js b/source/basic/loop/test/for-in/for-in-array-bug-example-test.js
index d8313c0363..a86cf88733 100644
--- a/source/basic/loop/test/for-in/for-in-array-bug-example-test.js
+++ b/source/basic/loop/test/for-in/for-in-array-bug-example-test.js
@@ -3,6 +3,7 @@ import strictEval from "strict-eval";
 import fs from "fs";
 import url from "node:url";
 import path from "node:path";
+import { describe, it } from "node:test";
 
 const __filename__ = url.fileURLToPath(import.meta.url);
 const __dirname = path.dirname(__filename__);
diff --git a/source/basic/loop/test/for-in/for-in-object-example-test.js b/source/basic/loop/test/for-in/for-in-object-example-test.js
index 8bf9277e1a..0e49337726 100644
--- a/source/basic/loop/test/for-in/for-in-object-example-test.js
+++ b/source/basic/loop/test/for-in/for-in-object-example-test.js
@@ -3,6 +3,7 @@ import strictEval from "strict-eval";
 import fs from "fs";
 import url from "node:url";
 import path from "node:path";
+import { describe, it } from "node:test";
 
 const __filename__ = url.fileURLToPath(import.meta.url);
 const __dirname = path.dirname(__filename__);
diff --git a/source/basic/loop/test/for-in/object-keys-for-each-example-test.js b/source/basic/loop/test/for-in/object-keys-for-each-example-test.js
index 045da182c0..6aada3bc84 100644
--- a/source/basic/loop/test/for-in/object-keys-for-each-example-test.js
+++ b/source/basic/loop/test/for-in/object-keys-for-each-example-test.js
@@ -3,6 +3,7 @@ import strictEval from "strict-eval";
 import fs from "node:fs";
 import url from "node:url";
 import path from "node:path";
+import { describe, it } from "node:test";
 
 const __filename__ = url.fileURLToPath(import.meta.url);
 const __dirname = path.dirname(__filename__);
diff --git a/source/basic/loop/test/for-of/for-of-array-example-test.js b/source/basic/loop/test/for-of/for-of-array-example-test.js
index e4ff275068..63a5c74e29 100644
--- a/source/basic/loop/test/for-of/for-of-array-example-test.js
+++ b/source/basic/loop/test/for-of/for-of-array-example-test.js
@@ -3,6 +3,7 @@ import strictEval from "strict-eval";
 import fs from "fs";
 import path from "path";
 import url from "node:url";
+import { describe, it } from "node:test";
 
 const __filename__ = url.fileURLToPath(import.meta.url);
 const __dirname = path.dirname(__filename__);
diff --git a/source/basic/loop/test/for-of/for-of-string-example-test.js b/source/basic/loop/test/for-of/for-of-string-example-test.js
index 5d099eb630..d04a90e318 100644
--- a/source/basic/loop/test/for-of/for-of-string-example-test.js
+++ b/source/basic/loop/test/for-of/for-of-string-example-test.js
@@ -3,6 +3,7 @@ import strictEval from "strict-eval";
 import fs from "fs";
 import url from "node:url";
 import path from "node:path";
+import { describe, it } from "node:test";
 
 const __filename__ = url.fileURLToPath(import.meta.url);
 const __dirname = path.dirname(__filename__);
diff --git a/source/basic/loop/test/while/while-add-example-test.js b/source/basic/loop/test/while/while-add-example-test.js
index 3ea6926387..5cf999869f 100644
--- a/source/basic/loop/test/while/while-add-example-test.js
+++ b/source/basic/loop/test/while/while-add-example-test.js
@@ -3,6 +3,7 @@ import strictEval from "strict-eval";
 import fs from "fs";
 import url from "node:url";
 import path from "node:path";
+import { describe, it } from "node:test";
 
 const __filename__ = url.fileURLToPath(import.meta.url);
 const __dirname = path.dirname(__filename__);