Skip to content

Commit 2cbbe1a

Browse files
committed
test: switch to seeded test factory
1 parent 6490751 commit 2cbbe1a

File tree

2 files changed

+33
-23
lines changed

2 files changed

+33
-23
lines changed
+30-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
11
// Vitest Snapshot v1
22

3-
exports[`security > seed: 42 > cve() 1`] = `"CVE-2007-79177"`;
3+
exports[`security > 42 > cve 1`] = `"CVE-2007-79177"`;
44

5-
exports[`security > seed: 42 > cwe() 1`] = `"CWE-520"`;
5+
exports[`security > 42 > cvss 1`] = `
6+
{
7+
"rating": "none",
8+
"score": 0.5,
9+
"vector": "CVSS:3.1/AV:A/AC:H/PR:H/UI:N/S:C/C:H/I:L/A:L",
10+
}
11+
`;
612

7-
exports[`security > seed: 1211 > cve() 1`] = `"CVE-2020-48721"`;
13+
exports[`security > 42 > cwe 1`] = `"CWE-520"`;
814

9-
exports[`security > seed: 1211 > cwe() 1`] = `"CWE-1289"`;
15+
exports[`security > 1211 > cve 1`] = `"CVE-2020-48721"`;
1016

11-
exports[`security > seed: 1337 > cve() 1`] = `"CVE-2005-51225"`;
17+
exports[`security > 1211 > cvss 1`] = `
18+
{
19+
"rating": "high",
20+
"score": 0.5,
21+
"vector": "CVSS:3.1/AV:P/AC:L/PR:H/UI:R/S:U/C:N/I:H/A:N",
22+
}
23+
`;
1224

13-
exports[`security > seed: 1337 > cwe() 1`] = `"CWE-363"`;
25+
exports[`security > 1211 > cwe 1`] = `"CWE-1289"`;
26+
27+
exports[`security > 1337 > cve 1`] = `"CVE-2005-51225"`;
28+
29+
exports[`security > 1337 > cvss 1`] = `
30+
{
31+
"rating": "low",
32+
"score": 0.5,
33+
"vector": "CVSS:3.1/AV:A/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:N",
34+
}
35+
`;
36+
37+
exports[`security > 1337 > cwe 1`] = `"CWE-363"`;

test/security.spec.ts

+3-17
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,17 @@
11
import { afterEach, describe, expect, it } from 'vitest';
22
import { faker } from '../src';
3-
import { seededRuns } from './support/seededRuns';
3+
import { seededTests } from './support/seededRuns';
44

55
const NON_SEEDED_BASED_RUN = 5;
66

7-
const functionNames = ['cve', 'cwe'];
7+
const functionNames = ['cve', 'cwe', 'cvss'] as const;
88

99
describe('security', () => {
1010
afterEach(() => {
1111
faker.locale = 'en';
1212
});
1313

14-
for (const seed of seededRuns) {
15-
describe(`seed: ${seed}`, () => {
16-
for (const functionName of functionNames) {
17-
it(`${functionName}()`, () => {
18-
faker.seed(seed);
19-
20-
const actual = faker.security[functionName]();
21-
expect(actual).toMatchSnapshot();
22-
});
23-
}
24-
});
25-
}
26-
27-
// Create and log-back the seed for debug purposes
28-
faker.seed(Math.ceil(Math.random() * 1_000_000_000));
14+
seededTests(faker, 'security', (t) => t.itEach(...functionNames));
2915

3016
describe(`random seeded tests for seed ${JSON.stringify(
3117
faker.seed()

0 commit comments

Comments
 (0)