forked from as-pect/as-pect
/
PerformanceConfiguration.spec.ts
121 lines (106 loc) 路 4.28 KB
/
PerformanceConfiguration.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import { IPerformanceConfiguration } from "../src/util/IPerformanceConfiguration";
import { TestContext } from "../src/test/TestContext";
import { createPerformanceConfigurationModule } from "./setup/createPerformanceConfigurationModule";
let ctx: TestContext;
let start = new Promise<void>((resolve, reject) => {
createPerformanceConfigurationModule({}, (err, result) => {
if (err) {
console.log(err);
reject(err);
} else {
ctx = result!;
resolve();
}
});
});
type PartialConfiguration = Partial<IPerformanceConfiguration>
describe("Performance Configuration", () => {
it("should have no warings if maxSamples configured correctly", () => {
const performanceConfiguration: PartialConfiguration = {
maxSamples: 1000
};
const context: TestContext = new TestContext({ performanceConfiguration });
expect(context.warnings).toHaveLength(0);
});
it("should have warnings if configured to run less than 0 max samples", () => {
const performanceConfiguration: PartialConfiguration = {
maxSamples: -1
};
const context: TestContext = new TestContext({ performanceConfiguration });
for (const warning of context.warnings) {
expect(warning.type).toMatchSnapshot("type");
expect(warning.message).toMatchSnapshot("message");
}
});
it("should have warnings if configured to run less than allowed max samples", () => {
const performanceConfiguration: PartialConfiguration = {
maxSamples: 999999999999999
};
const context: TestContext = new TestContext({ performanceConfiguration });
for (const warning of context.warnings) {
expect(warning.type).toMatchSnapshot("type");
expect(warning.message).toMatchSnapshot("message");
}
});
it("should have warnings if configured maxTestRuntime is too large", () => {
const performanceConfiguration: PartialConfiguration = {
maxTestRunTime: 999999999999999
};
const context: TestContext = new TestContext({ performanceConfiguration });
for (const warning of context.warnings) {
expect(warning.type).toMatchSnapshot("type");
expect(warning.message).toMatchSnapshot("message");
}
});
it("should have warnings if configured maxTestRuntime is too negative", () => {
const performanceConfiguration: PartialConfiguration = {
maxTestRunTime: -1
};
const context: TestContext = new TestContext({ performanceConfiguration });
for (const warning of context.warnings) {
expect(warning.type).toMatchSnapshot("type");
expect(warning.message).toMatchSnapshot("message");
}
});
it("should have not warnings if configured maxTestRuntime is configured correctly", () => {
const performanceConfiguration: PartialConfiguration = {
maxTestRunTime: 500
};
const context: TestContext = new TestContext({ performanceConfiguration });
expect(context.warnings).toHaveLength(0);
});
it("should have warnings if configured decimalPlaces is too large", () => {
const performanceConfiguration: PartialConfiguration = {
roundDecimalPlaces: 100
};
const context: TestContext = new TestContext({ performanceConfiguration });
for (const warning of context.warnings) {
expect(warning.type).toMatchSnapshot("type");
expect(warning.message).toMatchSnapshot("message");
}
});
it("should have warnings if configured decimalPlaces is negative", () => {
const performanceConfiguration: PartialConfiguration = {
roundDecimalPlaces: -1
};
const context: TestContext = new TestContext({ performanceConfiguration });
for (const warning of context.warnings) {
expect(warning.type).toMatchSnapshot("type");
expect(warning.message).toMatchSnapshot("message");
}
});
it("should have not warnings if configured decimalPlaces is configured correctly", () => {
const performanceConfiguration: PartialConfiguration = {
roundDecimalPlaces: 3
};
const context: TestContext = new TestContext({ performanceConfiguration });
expect(context.warnings).toHaveLength(0);
});
it("should catch performanceConfiguration warnings at runtime", async () => {
await start;
for (const warning of ctx.warnings) {
expect(warning.type).toMatchSnapshot("type");
expect(warning.message).toMatchSnapshot("message");
}
});
});