Skip to content

Commit d9fff73

Browse files
committed
fix(wpt): avoid test/fixtures/wpt/README.md conflicts
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
1 parent 4ea22b8 commit d9fff73

4 files changed

Lines changed: 47 additions & 41 deletions

File tree

docs/git-node.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,6 @@ The updated files are placed under `./test/fixtures/wpt` by default. In addition
539539
to the assets, this also updates:
540540

541541
- `./test/fixtures/wpt/versions.json`
542-
- `./test/fixtures/wpt/README.md`
543542
- `./test/fixtures/wpt/LICENSE.md`
544543

545544
```

lib/wpt/index.js

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import path from 'node:path';
22

3-
import _ from 'lodash';
4-
53
import GitHubTree from '../github/tree.js';
64
import {
7-
writeFile, readJson, writeJson, readFile, removeDirectory
5+
writeFile, readJson, writeJson, removeDirectory
86
} from '../file.js';
97
import {
108
shortSha
@@ -28,11 +26,6 @@ export class WPTUpdater {
2826
this.assets = [];
2927
}
3028

31-
templates(...args) {
32-
const file = path.posix.join('templates', ...args);
33-
return _.template(readFile(new URL(file, import.meta.url)));
34-
}
35-
3629
fixtures(...args) {
3730
return path.join(this.nodedir, 'test', 'fixtures', 'wpt', ...args);
3831
}
@@ -41,10 +34,6 @@ export class WPTUpdater {
4134
return this.fixtures('versions.json');
4235
}
4336

44-
get readmePath() {
45-
return this.fixtures('README.md');
46-
}
47-
4837
getLocalVersions() {
4938
return readJson(this.versionsPath);
5039
}
@@ -98,12 +87,10 @@ export class WPTUpdater {
9887
}
9988

10089
/**
101-
* @param {string} nodedir
10290
* @param {Object<string, {commit: string, path: string}>} updated
10391
*/
10492
async updateVersions(updated) {
10593
const versionsPath = this.versionsPath;
106-
const readmePath = this.readmePath;
10794
let versions = this.getLocalVersions();
10895

10996
this.cli.startSpinner('Updating versions.json ...');
@@ -116,15 +103,6 @@ export class WPTUpdater {
116103
);
117104
writeJson(versionsPath, versions);
118105
this.cli.stopSpinner(`Updated ${versionsPath}`);
119-
120-
const urlMap = Object.keys(versions).map(
121-
(key) => [key, this.getTreeUrl(versions[key].path, versions[key].commit)]
122-
);
123-
124-
this.cli.startSpinner('Updating README ...');
125-
const readme = this.templates('README.md')({ map: urlMap });
126-
writeFile(readmePath, readme);
127-
this.cli.stopSpinner(`Updated ${readmePath}`);
128106
}
129107

130108
async updateLicense() {

lib/wpt/templates/README.md

Lines changed: 0 additions & 16 deletions
This file was deleted.

test/unit/wpt_updater.test.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/* eslint-disable import/no-named-as-default-member */
22
import { describe, it, before, after } from 'node:test';
33
import assert from 'node:assert';
4+
import fs from 'node:fs';
5+
import os from 'node:os';
6+
import nodePath from 'node:path';
47
import TestCLI from '../fixtures/test_cli.js';
58
import sinon from 'sinon';
69

@@ -26,6 +29,7 @@ describe('WPTUpdater', function() {
2629
gql: sinon.stub()
2730
};
2831
nodedir = '.';
32+
path = UNKNOWN_PATH;
2933
request.gql.withArgs(
3034
'LastCommit',
3135
{
@@ -42,7 +46,6 @@ describe('WPTUpdater', function() {
4246
});
4347

4448
it('exits with meaningful error when WPT name not found', async() => {
45-
path = UNKNOWN_PATH;
4649
wptUpdater = new WPTUpdater(path, cli, request, nodedir);
4750
let thrown;
4851
try {
@@ -62,4 +65,46 @@ describe('WPTUpdater', function() {
6265
]]
6366
}, { ignore: ['startSpinner', 'separator', 'log', 'updateSpinner'] });
6467
});
68+
69+
it('updates versions.json without rewriting README.md', async() => {
70+
cli.clearCalls();
71+
const tempDir = fs.mkdtempSync(nodePath.join(os.tmpdir(), 'ncu-wpt-'));
72+
try {
73+
const fixtures = nodePath.join(tempDir, 'test', 'fixtures', 'wpt');
74+
fs.mkdirSync(fixtures, { recursive: true });
75+
76+
const versionsPath = nodePath.join(fixtures, 'versions.json');
77+
const readmePath = nodePath.join(fixtures, 'README.md');
78+
const readme = 'stable README\n';
79+
fs.writeFileSync(readmePath, readme);
80+
fs.writeFileSync(versionsPath, JSON.stringify({
81+
url: {
82+
commit: 'e4a4672e9e607fc2b28e7173b83ce4e38ef53071',
83+
path: 'url'
84+
}
85+
}, null, 2) + '\n');
86+
87+
wptUpdater = new WPTUpdater('url', cli, request, tempDir);
88+
await wptUpdater.updateVersions({
89+
url: {
90+
commit: 'd4598eba0959249d8715818a402b432c513f9492',
91+
path: 'url'
92+
}
93+
});
94+
95+
assert.strictEqual(fs.readFileSync(readmePath, 'utf8'), readme);
96+
assert.deepStrictEqual(JSON.parse(fs.readFileSync(versionsPath, 'utf8')), {
97+
url: {
98+
commit: 'd4598eba0959249d8715818a402b432c513f9492',
99+
path: 'url'
100+
}
101+
});
102+
cli.assertCalledWith({
103+
startSpinner: [['Updating versions.json ...']],
104+
stopSpinner: [[`Updated ${versionsPath}`]]
105+
});
106+
} finally {
107+
fs.rmSync(tempDir, { recursive: true, force: true });
108+
}
109+
});
65110
});

0 commit comments

Comments
 (0)