diff options
author | Michaƫl Zasso <targos@protonmail.com> | 2021-06-08 13:44:33 +0300 |
---|---|---|
committer | Danielle Adams <adamzdanielle@gmail.com> | 2021-06-15 05:31:05 +0300 |
commit | a1d0aef60ee9253b53486332710815731306c85a (patch) | |
tree | 39dc98a22415c1c38767f50eae930b7a24ae6318 /test | |
parent | 902bb858d7ada071fdaf3b8de39f44f4237080fb (diff) |
tools: update doctool dependencies, migrate to ESM
- Migrated to ESM because some dependencies now require it.
- Did not update `highlight.js` to v11 because it has many breaking
changes.
- Used non-deprecated `highlight.js` API.
Refs: https://github.com/highlightjs/highlight.js/issues/2277
Fixes: https://github.com/nodejs/node/issues/38938
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/38966
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/common/index.mjs | 2 | ||||
-rw-r--r-- | test/doctool/test-apilinks.mjs (renamed from test/doctool/test-apilinks.js) | 23 | ||||
-rw-r--r-- | test/doctool/test-doctool-html.mjs (renamed from test/doctool/test-doctool-html.js) | 24 | ||||
-rw-r--r-- | test/doctool/test-doctool-json.mjs (renamed from test/doctool/test-doctool-json.js) | 22 | ||||
-rw-r--r-- | test/doctool/test-doctool-versions.mjs (renamed from test/doctool/test-doctool-versions.js) | 19 | ||||
-rw-r--r-- | test/doctool/test-local-md-file-reference-regex.mjs (renamed from test/doctool/test-local-md-file-reference-regex.js) | 7 | ||||
-rw-r--r-- | test/doctool/test-make-doc.mjs (renamed from test/doctool/test-make-doc.js) | 27 |
7 files changed, 56 insertions, 68 deletions
diff --git a/test/common/index.mjs b/test/common/index.mjs index 73049004759..9700fe8039c 100644 --- a/test/common/index.mjs +++ b/test/common/index.mjs @@ -30,6 +30,7 @@ const { allowGlobals, mustCall, mustCallAtLeast, + mustSucceed, hasMultiLocalhost, skipIfDumbTerminal, skipIfEslintMissing, @@ -75,6 +76,7 @@ export { allowGlobals, mustCall, mustCallAtLeast, + mustSucceed, hasMultiLocalhost, skipIfDumbTerminal, skipIfEslintMissing, diff --git a/test/doctool/test-apilinks.js b/test/doctool/test-apilinks.mjs index 91de4b79f86..e3c334b19e7 100644 --- a/test/doctool/test-apilinks.js +++ b/test/doctool/test-apilinks.mjs @@ -1,14 +1,15 @@ -'use strict'; - -require('../common'); -const fixtures = require('../common/fixtures'); -const tmpdir = require('../common/tmpdir'); -const fs = require('fs'); -const assert = require('assert'); -const path = require('path'); -const { execFileSync } = require('child_process'); - -const script = path.join(__dirname, '..', '..', 'tools', 'doc', 'apilinks.js'); +import '../common/index.mjs'; +import * as fixtures from '../common/fixtures.mjs'; +import tmpdir from '../common/tmpdir.js'; + +import assert from 'assert'; +import { execFileSync } from 'child_process'; +import fs from 'fs'; +import path from 'path'; +import { fileURLToPath } from 'url'; + +const script = fileURLToPath( + new URL('../../tools/doc/apilinks.mjs', import.meta.url)); const apilinks = fixtures.path('apilinks'); tmpdir.refresh(); diff --git a/test/doctool/test-doctool-html.js b/test/doctool/test-doctool-html.mjs index dd651a66c1e..bf3475c6a61 100644 --- a/test/doctool/test-doctool-html.js +++ b/test/doctool/test-doctool-html.mjs @@ -1,22 +1,14 @@ -'use strict'; +import '../common/index.mjs'; +import * as fixtures from '../common/fixtures.mjs'; -const common = require('../common'); -// The doctool currently uses js-yaml from the tool/node_modules/eslint/ tree. -try { - require('../../tools/node_modules/eslint/node_modules/js-yaml'); -} catch { - common.skip('missing js-yaml (eslint not present)'); -} +import assert from 'assert'; +import { readFileSync } from 'fs'; +import { createRequire } from 'module'; -const assert = require('assert'); -const { readFileSync } = require('fs'); -const fixtures = require('../common/fixtures'); -const { replaceLinks } = require('../../tools/doc/markdown.js'); -const html = require('../../tools/doc/html.js'); -const path = require('path'); +import * as html from '../../tools/doc/html.mjs'; +import { replaceLinks } from '../../tools/doc/markdown.mjs'; -module.paths.unshift( - path.join(__dirname, '..', '..', 'tools', 'doc', 'node_modules')); +const require = createRequire(new URL('../../tools/doc/', import.meta.url)); const unified = require('unified'); const markdown = require('remark-parse'); const remark2rehype = require('remark-rehype'); diff --git a/test/doctool/test-doctool-json.js b/test/doctool/test-doctool-json.mjs index 70e6aa50f0c..d3badf84f55 100644 --- a/test/doctool/test-doctool-json.js +++ b/test/doctool/test-doctool-json.mjs @@ -1,21 +1,13 @@ -'use strict'; +import * as common from '../common/index.mjs'; +import * as fixtures from '../common/fixtures.mjs'; -const common = require('../common'); -// The doctool currently uses js-yaml from the tool/node_modules/eslint/ tree. -try { - require('../../tools/node_modules/eslint/node_modules/js-yaml'); -} catch { - common.skip('missing js-yaml (eslint not present)'); -} +import assert from 'assert'; +import fs from 'fs'; +import { createRequire } from 'module'; -const assert = require('assert'); -const fs = require('fs'); -const path = require('path'); -const fixtures = require('../common/fixtures'); -const json = require('../../tools/doc/json.js'); +import * as json from '../../tools/doc/json.mjs'; -module.paths.unshift( - path.join(__dirname, '..', '..', 'tools', 'doc', 'node_modules')); +const require = createRequire(new URL('../../tools/doc/', import.meta.url)); const unified = require('unified'); const markdown = require('remark-parse'); diff --git a/test/doctool/test-doctool-versions.js b/test/doctool/test-doctool-versions.mjs index 5673cc79402..92dedab9cc4 100644 --- a/test/doctool/test-doctool-versions.js +++ b/test/doctool/test-doctool-versions.mjs @@ -1,15 +1,16 @@ -'use strict'; +import '../common/index.mjs'; +import tmpdir from '../common/tmpdir.js'; -require('../common'); -const assert = require('assert'); -const { spawnSync } = require('child_process'); -const fs = require('fs'); -const path = require('path'); -const tmpdir = require('../common/tmpdir'); -const util = require('util'); +import assert from 'assert'; +import { spawnSync } from 'child_process'; +import fs from 'fs'; +import path from 'path'; +import { fileURLToPath } from 'url'; +import util from 'util'; const debuglog = util.debuglog('test'); -const versionsTool = path.resolve(__dirname, '../../tools/doc/versions.js'); +const versionsTool = fileURLToPath( + new URL('../../tools/doc/versions.mjs', import.meta.url)); // At the time of writing these are the minimum expected versions. // New versions of Node.js do not have to be explicitly added here. diff --git a/test/doctool/test-local-md-file-reference-regex.js b/test/doctool/test-local-md-file-reference-regex.mjs index f0fa922d89c..3cc312b8401 100644 --- a/test/doctool/test-local-md-file-reference-regex.js +++ b/test/doctool/test-local-md-file-reference-regex.mjs @@ -1,9 +1,8 @@ -'use strict'; +import '../common/index.mjs'; -require('../common'); -const assert = require('assert'); +import assert from 'assert'; -const { referenceToLocalMdFile } = require('../../tools/doc/markdown.js'); +import { referenceToLocalMdFile } from '../../tools/doc/markdown.mjs'; { const shouldBeSpotted = [ diff --git a/test/doctool/test-make-doc.js b/test/doctool/test-make-doc.mjs index 7f4f3ae6fbf..06ec6e028bf 100644 --- a/test/doctool/test-make-doc.js +++ b/test/doctool/test-make-doc.mjs @@ -1,5 +1,9 @@ -'use strict'; -const common = require('../common'); +import * as common from '../common/index.mjs'; + +import assert from 'assert'; +import fs from 'fs'; +import path from 'path'; + if (common.isWindows) { common.skip('`make doc` does not run on Windows'); } @@ -7,14 +11,10 @@ if (common.isWindows) { // This tests that `make doc` generates the documentation properly. // Note that for this test to pass, `make doc` must be run first. -const assert = require('assert'); -const fs = require('fs'); -const path = require('path'); - -const apiPath = path.resolve(__dirname, '..', '..', 'out', 'doc', 'api'); -const mdPath = path.resolve(__dirname, '..', '..', 'doc', 'api'); -const allMD = fs.readdirSync(mdPath); -const allDocs = fs.readdirSync(apiPath); +const apiURL = new URL('../../out/doc/api/', import.meta.url); +const mdURL = new URL('../../doc/api/', import.meta.url); +const allMD = fs.readdirSync(mdURL); +const allDocs = fs.readdirSync(apiURL); assert.ok(allDocs.includes('index.html')); const actualDocs = allDocs.filter( @@ -33,7 +33,7 @@ for (const name of actualDocs) { ); } -const toc = fs.readFileSync(path.resolve(apiPath, 'index.html'), 'utf8'); +const toc = fs.readFileSync(new URL('./index.html', apiURL), 'utf8'); const re = /href="([^/]+\.html)"/; const globalRe = new RegExp(re, 'g'); const links = toc.match(globalRe); @@ -56,8 +56,9 @@ for (const actualDoc of actualDocs) { assert.ok( expectedDocs.includes(actualDoc), `${actualDoc} does not match TOC`); - assert.ok( - fs.statSync(path.join(apiPath, actualDoc)).size !== 0, + assert.notStrictEqual( + fs.statSync(new URL(`./${actualDoc}`, apiURL)).size, + 0, `${actualDoc} is empty` ); } |