Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/git-node.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

```
Expand Down
24 changes: 1 addition & 23 deletions lib/wpt/index.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
}
Expand All @@ -41,10 +34,6 @@ export class WPTUpdater {
return this.fixtures('versions.json');
}

get readmePath() {
return this.fixtures('README.md');
}

getLocalVersions() {
return readJson(this.versionsPath);
}
Expand Down Expand Up @@ -98,12 +87,10 @@ export class WPTUpdater {
}

/**
* @param {string} nodedir
* @param {Object<string, {commit: string, path: string}>} updated
*/
async updateVersions(updated) {
const versionsPath = this.versionsPath;
const readmePath = this.readmePath;
let versions = this.getLocalVersions();

this.cli.startSpinner('Updating versions.json ...');
Expand All @@ -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() {
Expand Down
16 changes: 0 additions & 16 deletions lib/wpt/templates/README.md

This file was deleted.

47 changes: 46 additions & 1 deletion test/unit/wpt_updater.test.js
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -26,6 +29,7 @@ describe('WPTUpdater', function() {
gql: sinon.stub()
};
nodedir = '.';
path = UNKNOWN_PATH;
request.gql.withArgs(
'LastCommit',
{
Expand All @@ -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 {
Expand All @@ -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 });
}
});
});
Loading