File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11"use strict" ;
2- const configYmlPath = "docs/_config.yml" ;
2+ const configYmlPath = process . env . SINON_DOCS_CONFIG_PATH || "docs/_config.yml" ;
33const UTF8 = "utf8" ;
44
55const fs = require ( "fs" ) ;
66const yaml = require ( "js-yaml" ) ;
77const semver = require ( "semver" ) ;
88const releaseId = `v${ require ( "../package.json" ) . version } ` ;
9- const config = yaml . safeLoad ( fs . readFileSync ( configYmlPath , UTF8 ) ) ;
9+ const config = yaml . load ( fs . readFileSync ( configYmlPath , UTF8 ) ) ;
1010
1111config . sinon . current_release = releaseId ; // eslint-disable-line camelcase
1212config . sinon . current_major_version = semver . major ( releaseId ) ; // eslint-disable-line camelcase
1313
14- fs . writeFileSync ( configYmlPath , yaml . safeDump ( config ) , UTF8 ) ;
14+ fs . writeFileSync ( configYmlPath , yaml . dump ( config ) , UTF8 ) ;
Original file line number Diff line number Diff line change 1+ "use strict" ;
2+
3+ const assert = require ( "@sinonjs/referee" ) . assert ;
4+ const childProcess = require ( "child_process" ) ;
5+ const fs = require ( "fs" ) ;
6+ const os = require ( "os" ) ;
7+ const path = require ( "path" ) ;
8+
9+ describe ( "set-release-id-in-config-yml" , function ( ) {
10+ it ( "updates current release and major version in a config file" , function ( ) {
11+ const fixtureDir = fs . mkdtempSync (
12+ path . join ( os . tmpdir ( ) , "sinon-release-config-" ) ,
13+ ) ;
14+ const configPath = path . join ( fixtureDir , "_config.yml" ) ;
15+
16+ fs . writeFileSync (
17+ configPath ,
18+ [
19+ "sinon:" ,
20+ " current_release: v0.0.0" ,
21+ " current_major_version: 0" ,
22+ "" ,
23+ ] . join ( "\n" ) ,
24+ "utf8" ,
25+ ) ;
26+
27+ childProcess . execFileSync (
28+ process . execPath ,
29+ [
30+ path . resolve (
31+ __dirname ,
32+ "../../scripts/set-release-id-in-config-yml.cjs" ,
33+ ) ,
34+ ] ,
35+ {
36+ cwd : path . resolve ( __dirname , "../.." ) ,
37+ env : {
38+ ...process . env ,
39+ SINON_DOCS_CONFIG_PATH : configPath ,
40+ } ,
41+ } ,
42+ ) ;
43+
44+ const written = fs . readFileSync ( configPath , "utf8" ) ;
45+
46+ assert . match ( written , / c u r r e n t _ r e l e a s e : v 2 1 \. 0 \. 2 / ) ;
47+ assert . match ( written , / c u r r e n t _ m a j o r _ v e r s i o n : 2 1 / ) ;
48+ } ) ;
49+ } ) ;
You can’t perform that action at this time.
0 commit comments