diff --git a/docs/git-node.md b/docs/git-node.md index f36be7c5..550d4e4a 100644 --- a/docs/git-node.md +++ b/docs/git-node.md @@ -539,7 +539,6 @@ The updated files are placed under `./test/fixtures/wpt` by default. In addition to the assets, this also updates: - `./test/fixtures/wpt/versions.json` -- `./test/fixtures/wpt/README.md` - `./test/fixtures/wpt/LICENSE.md` ``` diff --git a/lib/wpt/index.js b/lib/wpt/index.js index e7f6c38f..fe7e9bd5 100644 --- a/lib/wpt/index.js +++ b/lib/wpt/index.js @@ -1,10 +1,8 @@ import path from 'node:path'; -import _ from 'lodash'; - import GitHubTree from '../github/tree.js'; import { - writeFile, readJson, writeJson, readFile, removeDirectory + writeFile, readJson, writeJson, removeDirectory } from '../file.js'; import { shortSha @@ -28,11 +26,6 @@ export class WPTUpdater { this.assets = []; } - templates(...args) { - const file = path.posix.join('templates', ...args); - return _.template(readFile(new URL(file, import.meta.url))); - } - fixtures(...args) { return path.join(this.nodedir, 'test', 'fixtures', 'wpt', ...args); } @@ -41,10 +34,6 @@ export class WPTUpdater { return this.fixtures('versions.json'); } - get readmePath() { - return this.fixtures('README.md'); - } - getLocalVersions() { return readJson(this.versionsPath); } @@ -98,12 +87,10 @@ export class WPTUpdater { } /** - * @param {string} nodedir * @param {Object} updated */ async updateVersions(updated) { const versionsPath = this.versionsPath; - const readmePath = this.readmePath; let versions = this.getLocalVersions(); this.cli.startSpinner('Updating versions.json ...'); @@ -116,15 +103,6 @@ export class WPTUpdater { ); writeJson(versionsPath, versions); this.cli.stopSpinner(`Updated ${versionsPath}`); - - const urlMap = Object.keys(versions).map( - (key) => [key, this.getTreeUrl(versions[key].path, versions[key].commit)] - ); - - this.cli.startSpinner('Updating README ...'); - const readme = this.templates('README.md')({ map: urlMap }); - writeFile(readmePath, readme); - this.cli.stopSpinner(`Updated ${readmePath}`); } async updateLicense() { diff --git a/lib/wpt/templates/README.md b/lib/wpt/templates/README.md deleted file mode 100644 index 532e1f95..00000000 --- a/lib/wpt/templates/README.md +++ /dev/null @@ -1,16 +0,0 @@ -# Web Platform Test Fixtures - -The files in this folder, including this document, -are generated by [`git node wpt`][]. - -This folder contains a subset of the [Web Platform Tests][] for the -implementation of Web APIs in Node.js. - -See [test/wpt](../../wpt/README.md) for information on how these tests are run. - -Last update: -<% for (const [path, url] of map) { %> -- <%= path %>: <%= url %><% } %> - -[Web Platform Tests]: https://github.com/web-platform-tests/wpt -[`git node wpt`]: https://github.com/nodejs/node-core-utils/blob/main/docs/git-node.md#git-node-wpt diff --git a/test/unit/wpt_updater.test.js b/test/unit/wpt_updater.test.js index 34a03abd..92065d55 100644 --- a/test/unit/wpt_updater.test.js +++ b/test/unit/wpt_updater.test.js @@ -1,6 +1,9 @@ /* eslint-disable import/no-named-as-default-member */ import { describe, it, before, after } from 'node:test'; import assert from 'node:assert'; +import fs from 'node:fs'; +import os from 'node:os'; +import nodePath from 'node:path'; import TestCLI from '../fixtures/test_cli.js'; import sinon from 'sinon'; @@ -26,6 +29,7 @@ describe('WPTUpdater', function() { gql: sinon.stub() }; nodedir = '.'; + path = UNKNOWN_PATH; request.gql.withArgs( 'LastCommit', { @@ -42,7 +46,6 @@ describe('WPTUpdater', function() { }); it('exits with meaningful error when WPT name not found', async() => { - path = UNKNOWN_PATH; wptUpdater = new WPTUpdater(path, cli, request, nodedir); let thrown; try { @@ -62,4 +65,46 @@ describe('WPTUpdater', function() { ]] }, { ignore: ['startSpinner', 'separator', 'log', 'updateSpinner'] }); }); + + it('updates versions.json without rewriting README.md', async() => { + cli.clearCalls(); + const tempDir = fs.mkdtempSync(nodePath.join(os.tmpdir(), 'ncu-wpt-')); + try { + const fixtures = nodePath.join(tempDir, 'test', 'fixtures', 'wpt'); + fs.mkdirSync(fixtures, { recursive: true }); + + const versionsPath = nodePath.join(fixtures, 'versions.json'); + const readmePath = nodePath.join(fixtures, 'README.md'); + const readme = 'stable README\n'; + fs.writeFileSync(readmePath, readme); + fs.writeFileSync(versionsPath, JSON.stringify({ + url: { + commit: 'e4a4672e9e607fc2b28e7173b83ce4e38ef53071', + path: 'url' + } + }, null, 2) + '\n'); + + wptUpdater = new WPTUpdater('url', cli, request, tempDir); + await wptUpdater.updateVersions({ + url: { + commit: 'd4598eba0959249d8715818a402b432c513f9492', + path: 'url' + } + }); + + assert.strictEqual(fs.readFileSync(readmePath, 'utf8'), readme); + assert.deepStrictEqual(JSON.parse(fs.readFileSync(versionsPath, 'utf8')), { + url: { + commit: 'd4598eba0959249d8715818a402b432c513f9492', + path: 'url' + } + }); + cli.assertCalledWith({ + startSpinner: [['Updating versions.json ...']], + stopSpinner: [[`Updated ${versionsPath}`]] + }); + } finally { + fs.rmSync(tempDir, { recursive: true, force: true }); + } + }); });