Skip to content

Commit b836fcc

Browse files
committed
fix: js-yaml breaking change from v3 to v4
1 parent ebf0c43 commit b836fcc

2 files changed

Lines changed: 52 additions & 3 deletions

File tree

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"use strict";
2-
const configYmlPath = "docs/_config.yml";
2+
const configYmlPath = process.env.SINON_DOCS_CONFIG_PATH || "docs/_config.yml";
33
const UTF8 = "utf8";
44

55
const fs = require("fs");
66
const yaml = require("js-yaml");
77
const semver = require("semver");
88
const 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

1111
config.sinon.current_release = releaseId; // eslint-disable-line camelcase
1212
config.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);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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, /current_release: v21\.0\.2/);
47+
assert.match(written, /current_major_version: 21/);
48+
});
49+
});

0 commit comments

Comments
 (0)