Skip to content

Commit 23f43d1

Browse files
committed
update: add test coverage for listToString tag
1 parent a9339ba commit 23f43d1

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

tests/enums.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as path from "path";
22

33
export const FIXTURES_DIR = path.resolve(__dirname, "./fixtures");
44
export const YAML_COMBINE_FILE = path.resolve(FIXTURES_DIR, "yaml_combine_tag.yml");
5+
export const YAML_LIST_TO_STRING_FILE = path.resolve(FIXTURES_DIR, "yaml_listToString_tag.yml");
56
export const YAML_PARAMETER_FILE = path.resolve(FIXTURES_DIR, "yaml_parameter_tag.yml");
67
export const YAML_ESSE_FILE = path.resolve(FIXTURES_DIR, "yaml_esse_tag.yml");
78
export const YAML_INCLUDE_FILE = path.resolve(FIXTURES_DIR, "yaml_include_tag.yml");
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
# listToString content from another Yaml file
22
case1:
33
here: original content
4-
there: !listToString "tests/fixtures/yaml_parameter_ref.yml#/job/workflow"
4+
there: !listToString
5+
- one # comment 1
6+
- two # comment 2
7+
case2:
8+
here: original content
9+
there: !listToString
10+
- one # comment 1
11+
- 1 # non-string ignored
12+
- some: 1 # object also skipped
13+
other: "object"
14+
- two # comment 2

tests/utils/yaml.listToString.tests.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,31 @@ import { expect } from "chai";
33
import fs from "fs";
44
import yaml from "js-yaml";
55

6-
import { includeType } from "../../src/utils/yaml";
7-
import { YAML_INCLUDE_FILE } from "../enums";
6+
import { listToStringType } from "../../src/utils/yaml";
7+
import { YAML_LIST_TO_STRING_FILE } from "../enums";
88

9-
const includeSchema = yaml.DEFAULT_SCHEMA.extend([includeType]);
9+
const includeSchema = yaml.DEFAULT_SCHEMA.extend([listToStringType]);
1010

11-
describe.only("YAML tag: !listToString", () => {
12-
const yamlFixture = fs.readFileSync(YAML_INCLUDE_FILE, "utf8");
11+
describe("YAML tag: !listToString", () => {
12+
const yamlFixture = fs.readFileSync(YAML_LIST_TO_STRING_FILE, "utf8");
1313

1414
it("should correctly concatenate content from list to string", () => {
1515
const parsed = yaml.load(yamlFixture, { schema: includeSchema });
16+
1617
const expected = {
1718
here: "original content",
18-
there: ["run", "stop", "pause"],
19+
there: "onetwo",
1920
};
2021
expect(parsed.case1).to.be.eql(expected);
2122
});
23+
24+
it("should correctly filter out and concatenate only strings from list", () => {
25+
const parsed = yaml.load(yamlFixture, { schema: includeSchema });
26+
27+
const expected = {
28+
here: "original content",
29+
there: "onetwo",
30+
};
31+
expect(parsed.case2).to.be.eql(expected);
32+
});
2233
});

0 commit comments

Comments
 (0)