Skip to content

Commit 4f475f5

Browse files
committed
test: run yaml load in before hook
1 parent 7613498 commit 4f475f5

File tree

2 files changed

+9
-27
lines changed

2 files changed

+9
-27
lines changed

tests/utils/yaml.combine.tests.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ const combineSchema = yaml.DEFAULT_SCHEMA.extend([combineType, esseType]);
1212

1313
describe("YAML tag: !combine", () => {
1414
let yamlFixture;
15+
let parsed;
1516

1617
// eslint-disable-next-line func-names
1718
before(function () {
1819
this.timeout(5000);
1920
yamlFixture = fs.readFileSync(YAML_COMBINE_FILE, "utf8");
21+
parsed = yaml.load(yamlFixture, { schema: combineSchema });
2022
});
2123

2224
it("should correctly parse a custom !combine tag with forEach and config keys", () => {
23-
const parsed = yaml.load(yamlFixture, { schema: combineSchema });
2425
const expectedResult = [
2526
{ name: "mytest", a: 1, b: 3, c: 5 },
2627
{ name: "mytest", a: 1, b: 4, c: 5 },
@@ -32,72 +33,57 @@ describe("YAML tag: !combine", () => {
3233
});
3334

3435
it("should correctly parse a custom !combine tag with only a name key", () => {
35-
const parsed = yaml.load(yamlFixture, { schema: combineSchema });
3636
const expectedResult = [{ name: "mytest" }];
37-
3837
expect(parsed.case2).to.have.deep.members(expectedResult);
3938
});
4039

4140
it("should correctly parse a custom !combine tag with forEach key and no values", () => {
42-
const parsed = yaml.load(yamlFixture, { schema: combineSchema });
4341
const expectedResult = [{ name: "mytest" }];
44-
4542
expect(parsed.case3).to.have.deep.members(expectedResult);
4643
});
4744

4845
it("should correctly parse a custom !combine tag with an empty forEach key and a config key", () => {
49-
const parsed = yaml.load(yamlFixture, { schema: combineSchema });
5046
const expectedResult = [{ name: "mytest", c: 5 }];
51-
5247
expect(parsed.case4).to.have.deep.members(expectedResult);
5348
});
5449

5550
it("should correctly generate name based on template", () => {
56-
const parsed = yaml.load(yamlFixture, { schema: combineSchema });
5751
const expectedResult = [
5852
{ name: "A1 with B2 and C5", a: 1, b: "two", c: 5 },
5953
{ name: "A1 with B4 and C5", a: 1, b: "four", c: 5 },
6054
];
61-
6255
expect(parsed.case5).to.have.deep.members(expectedResult);
6356
});
6457

6558
it("should correctly parse a custom !combine tag with additional property", () => {
66-
const parsed = yaml.load(yamlFixture, { schema: combineSchema });
6759
const expectedResult = [
6860
{ name: "mytest", a: 1, b: 3 },
6961
{ name: "mytest", a: 1, b: 4 },
7062
{ name: "additional property", x: 7 },
7163
];
72-
7364
expect(parsed.case6).to.have.deep.members(expectedResult);
7465
});
7566

7667
it("should correctly parse a custom !combine tag with additional property from !combine tag", () => {
77-
const parsed = yaml.load(yamlFixture, { schema: combineSchema });
7868
const expectedResult = [
7969
{ name: "mytest", a: 1, b: 3 },
8070
{ name: "mytest", a: 1, b: 4 },
8171
{ name: "additional property", x: 7, y: 9 },
8272
{ name: "additional property", x: 8, y: 9 },
8373
];
84-
8574
expect(parsed.case7).to.have.deep.members(expectedResult);
8675
});
8776

8877
it("should create an additional config when falsy parameter is provided", () => {
89-
const parsed = yaml.load(yamlFixture, { schema: combineSchema });
9078
const expectedResult = [
9179
{ name: "A1 with B2", a: 1, b: "two" },
9280
{ name: "A1 with B4", a: 1, b: "four" },
9381
{ name: "A1", a: 1 },
9482
];
95-
9683
expect(parsed.case8).to.have.deep.members(expectedResult);
9784
});
9885

9986
it("should create all combinations of n optional parameters", () => {
100-
const parsed = yaml.load(yamlFixture, { schema: combineSchema });
10187
const expectedResult = [
10288
{ name: "optional params", a: 1 },
10389
{ name: "optional params", a: 1, b: 2 },
@@ -106,19 +92,15 @@ describe("YAML tag: !combine", () => {
10692
{ name: "optional params", a: 1, b: 2, c: 4 },
10793
{ name: "optional params", a: 1, b: 3, c: 4 },
10894
];
109-
11095
expect(parsed.case9).to.have.deep.members(expectedResult);
11196
});
11297

11398
it("should allow to exclude certain parameter-specified combinations", () => {
114-
const parsed = yaml.load(yamlFixture, { schema: combineSchema });
11599
const expectedResult = [{ name: "ignore test", a: { c: 3 }, d: 4 }];
116-
117100
expect(parsed.case10).to.have.deep.members(expectedResult);
118101
});
119102

120103
it("should use the push action to add value to an array parameter", () => {
121-
const parsed = yaml.load(yamlFixture, { schema: combineSchema });
122104
const expectedResult = [
123105
{ name: "push test", units: [{ a: 1 }, { b: 4 }] },
124106
{ name: "push test", units: [{ a: 2 }, { b: 4 }] },
@@ -136,7 +118,6 @@ describe("YAML tag: !combine", () => {
136118
});
137119

138120
it("should use cloned objects when pushing to array", () => {
139-
const parsed = yaml.load(yamlFixture, { schema: combineSchema });
140121
const [config1, config2] = parsed.case12;
141122

142123
// deleting property in one should not affect the other

tests/utils/yaml.esse.tests.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@ import { YAML_ESSE_FILE } from "../enums";
99
const yamlSchema = yaml.DEFAULT_SCHEMA.extend([esseType]);
1010

1111
describe("YAML tag: !esse", () => {
12-
const yamlFixture = fs.readFileSync(YAML_ESSE_FILE, "utf8");
12+
let yamlFixture;
13+
let parsed;
14+
15+
before(() => {
16+
yamlFixture = fs.readFileSync(YAML_ESSE_FILE, "utf8");
17+
parsed = yaml.load(yamlFixture, { schema: yamlSchema });
18+
});
1319

1420
it("should correctly parse a custom !esse tag and return ESSE schema", () => {
15-
const parsed = yaml.load(yamlFixture, { schema: yamlSchema });
1621
const expected = {
1722
$id: "core/primitive/scalar",
1823
$schema: "http://json-schema.org/draft-04/schema#",
@@ -29,24 +34,20 @@ describe("YAML tag: !esse", () => {
2934
});
3035

3136
it("should return the original data when an error occurs", () => {
32-
const parsed = yaml.load(yamlFixture, { schema: yamlSchema });
3337
expect(parsed.case2).to.be.equal("non-existent-schema-id");
3438
});
3539

3640
it("should parse a custom !esse tag and return a value from the ESSE schema", () => {
37-
const parsed = yaml.load(yamlFixture, { schema: yamlSchema });
3841
const expected = ["kbar", "pa"];
3942
expect(parsed.case3).to.have.deep.members(expected);
4043
});
4144

4245
it("should correctly return nested value from esse schema", () => {
43-
const parsed = yaml.load(yamlFixture, { schema: yamlSchema });
4446
const expected = "array containing values of x Axis";
4547
expect(parsed.case4).to.be.eql(expected);
4648
});
4749

4850
it("should correctly return array item from esse schema", () => {
49-
const parsed = yaml.load(yamlFixture, { schema: yamlSchema });
5051
const expected = "yDataSeries";
5152
expect(parsed.case5).to.be.eql(expected);
5253
});

0 commit comments

Comments
 (0)