11/* eslint-disable import/no-named-as-default-member */
22import { describe , it , before , after } from 'node:test' ;
33import assert from 'node:assert' ;
4+ import fs from 'node:fs' ;
5+ import os from 'node:os' ;
6+ import nodePath from 'node:path' ;
47import TestCLI from '../fixtures/test_cli.js' ;
58import 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