Skip to content

Commit 92b9482

Browse files
authored
refactor: mocha を v6→v11 へアップデート (#385)
1 parent 970f05c commit 92b9482

File tree

8 files changed

+337
-360
lines changed

8 files changed

+337
-360
lines changed

.mocharc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"require": [
3+
"intelli-espower-loader",
4+
"test/node-helper.js",
5+
"test/test-helper.js"
6+
]
7+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"inlining-node-require": "^0.2.0",
5656
"intelli-espower-loader": "^1.0.0",
5757
"minifyify": "^7.0.1",
58-
"mocha": "^6.2.1",
58+
"mocha": "^11.6.0",
5959
"npm-run-all2": "^8.0.4",
6060
"power-assert": "^1.6.1",
6161
"promise-test-helper": "^0.2.1",

test/echo-server.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
var http = require("http");
2-
var url = require("url");
3-
var querystring = require("querystring");
4-
var server = null;
5-
var port = process.env.PORT || 3000;
1+
const http = require("http");
2+
const url = require("url");
3+
const querystring = require("querystring");
4+
let server = null;
5+
const port = process.env.PORT || 3000;
66
function start() {
77
server = http.createServer();
8-
server.on("request", function (request, response) {
9-
var uri = url.parse(request.url);
10-
var qs = uri.query ? querystring.parse(uri.query) : {};
8+
server.on("request", (request, response) => {
9+
const uri = url.parse(request.url);
10+
const qs = uri.query ? querystring.parse(uri.query) : {};
1111

12-
var status = qs.status || 200;
13-
var contentType = qs.contentType || "text/plain";
14-
var body = qs.body || "hello there!";
12+
const status = qs.status || 200;
13+
const contentType = qs.contentType || "text/plain";
14+
const body = qs.body || "hello there!";
1515

1616
response.writeHead(status, {
1717
"Content-Type": contentType,
@@ -24,7 +24,7 @@ function start() {
2424
});
2525

2626
return new Promise((resolve, reject) => {
27-
server.listen(port, function (error) {
27+
server.listen(port, (error) => {
2828
if (error) {
2929
return reject(error);
3030
}

test/html/missing-internal-link.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"use strict";
2-
var cheerio = require('cheerio');
2+
const cheerio = require("cheerio");
33
function checkInternalLinks(source) {
4-
var $ = cheerio.load(source, {
4+
const $ = cheerio.load(source, {
55
normalizeWhitespace: false,
66
xmlMode: false,
77
decodeEntities: true
88
});
9-
var $links = $("a");
10-
var $internalLinks = $links.filter(function (idx, a) {
9+
const $links = $("a");
10+
const $internalLinks = $links.filter(function(idx, a) {
1111
return /^#/.test($(this).attr("href"));
1212
});
1313

@@ -16,10 +16,10 @@ function checkInternalLinks(source) {
1616
}
1717

1818
function checkLinks($links) {
19-
var errors = [];
20-
$links.each(function (idx, a) {
21-
var hash = $(this).attr("href");
22-
var source = $(escapeSelector(hash));
19+
const errors = [];
20+
$links.each(function(idx, a) {
21+
const hash = $(this).attr("href");
22+
const source = $(escapeSelector(hash));
2323
if (source.length === 0) {
2424
errors.push(new Error("[Error] Not Found:" + hash + " | " + $(this).parent().text()));
2525
}

test/inline-script/inline-script-tester.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
"use strict";
2-
var Q = require("q");
3-
var FS = require("q-io/fs");
4-
var esprima = require("esprima");
5-
var pather = require("path");
2+
const Q = require("q");
3+
const FS = require("q-io/fs");
4+
const esprima = require("esprima");
5+
const pather = require("path");
66
// http://www.regexr.com/38t47
7-
var inlineCodeReg = /\[source.*?javascript\]\n[\s\S]*?----([\s\S]*?)----/gm;
8-
var includeCodeReg = /include::/;
9-
var skipContentPattern = /Syntax Error/;
7+
const inlineCodeReg = /\[source.*?javascript\]\n[\s\S]*?----([\s\S]*?)----/gm;
8+
const includeCodeReg = /include::/;
9+
const skipContentPattern = /Syntax Error/;
1010
function trimIncludeCode(code) {
11-
var replaceRegExp = /include::.*/g;
12-
var trimedCode = code.replace(replaceRegExp, "");
11+
const replaceRegExp = /include::.*/g;
12+
const trimedCode = code.replace(replaceRegExp, "");
1313
return trimedCode.trim();
1414
}
1515
function pickupContent(content) {
16-
var results = [];
17-
var matches;
16+
const results = [];
17+
let matches;
1818
while ((matches = inlineCodeReg.exec(content)) !== null) {
19-
var code = matches[1];
19+
const code = matches[1];
2020
if (includeCodeReg.test(code)) {
21-
var trimedCode = trimIncludeCode(code);
21+
const trimedCode = trimIncludeCode(code);
2222
if (trimedCode.length > 0) {
2323
results.push(trimedCode);
2424
}
@@ -30,7 +30,7 @@ function pickupContent(content) {
3030
}
3131
function parseContents(content, filePath) {
3232
// skip
33-
if (skipContentPattern.test(content)){
33+
if (skipContentPattern.test(content)) {
3434
return;
3535
}
3636
try {
@@ -43,39 +43,39 @@ function parseContents(content, filePath) {
4343
}
4444

4545
function printResults(results) {
46-
results.forEach(function (errors) {
47-
errors.forEach(function (error) {
46+
results.forEach((errors) => {
47+
errors.forEach((error) => {
4848
console.error(">> filePath : " + pather.resolve(error.filePath) + "\n"
4949
+ "----\n" + error.fileContent.trim() + "\n----\n",
50-
error,
51-
"\n\n"
50+
error,
51+
"\n\n"
5252
);
5353
});
5454
});
5555
}
5656

5757
module.exports.checkInlineScript = function checkInlineScript(rootPath) {
58-
var asciidocPromises = FS.listTree(rootPath, function isAsciiDoc(filePath, stat) {
58+
const asciidocPromises = FS.listTree(rootPath, (filePath, stat) => {
5959
if (stat.isDirectory()) {
6060
return false;
6161
}
6262
return pather.extname(filePath) === ".adoc";
6363
});
6464

65-
return asciidocPromises.then(function (filePathList) {
66-
var promises = filePathList.map(function (filePath) {
65+
return asciidocPromises.then((filePathList) => {
66+
const promises = filePathList.map((filePath) => {
6767
return FS.read(filePath)
6868
.then(pickupContent)
69-
.then(function (contents) {
70-
return contents.map(function (content) {
69+
.then((contents) => {
70+
return contents.map((content) => {
7171
return parseContents(content, filePath);
72-
}).filter(function hasError(error) {
72+
}).filter((error) => {
7373
return error != null && error instanceof Error;
7474
});
7575
});
7676
});
77-
return Q.all(promises).then(function (results) {
78-
var filteredResults = results.filter(function (errors) {
77+
return Q.all(promises).then((results) => {
78+
const filteredResults = results.filter((errors) => {
7979
return Array.isArray(errors) && errors.length > 0;
8080
});
8181

test/mocha.opts

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/node-helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
*/
55
"use strict";
66
if (!global.XMLHttpRequest) {
7-
global.XMLHttpRequest = require('w3c-xmlhttprequest').XMLHttpRequest;
7+
global.XMLHttpRequest = require("w3c-xmlhttprequest").XMLHttpRequest;
88
}

0 commit comments

Comments
 (0)