Skip to content

Commit

Permalink
test: switch to seeded test factory
Browse files Browse the repository at this point in the history
  • Loading branch information
thisislawatts committed Aug 17, 2022
1 parent 6490751 commit 2cbbe1a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 23 deletions.
36 changes: 30 additions & 6 deletions test/__snapshots__/security.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
// Vitest Snapshot v1

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

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

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

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

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

exports[`security > seed: 1337 > cwe() 1`] = `"CWE-363"`;
exports[`security > 1211 > cwe 1`] = `"CWE-1289"`;

exports[`security > 1337 > cve 1`] = `"CVE-2005-51225"`;

exports[`security > 1337 > cvss 1`] = `
{
"rating": "low",
"score": 0.5,
"vector": "CVSS:3.1/AV:A/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:N",
}
`;

exports[`security > 1337 > cwe 1`] = `"CWE-363"`;
20 changes: 3 additions & 17 deletions test/security.spec.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
import { afterEach, describe, expect, it } from 'vitest';
import { faker } from '../src';
import { seededRuns } from './support/seededRuns';
import { seededTests } from './support/seededRuns';

const NON_SEEDED_BASED_RUN = 5;

const functionNames = ['cve', 'cwe'];
const functionNames = ['cve', 'cwe', 'cvss'] as const;

describe('security', () => {
afterEach(() => {
faker.locale = 'en';
});

for (const seed of seededRuns) {
describe(`seed: ${seed}`, () => {
for (const functionName of functionNames) {
it(`${functionName}()`, () => {
faker.seed(seed);

const actual = faker.security[functionName]();
expect(actual).toMatchSnapshot();
});
}
});
}

// Create and log-back the seed for debug purposes
faker.seed(Math.ceil(Math.random() * 1_000_000_000));
seededTests(faker, 'security', (t) => t.itEach(...functionNames));

describe(`random seeded tests for seed ${JSON.stringify(
faker.seed()
Expand Down

0 comments on commit 2cbbe1a

Please sign in to comment.