From 2541cce1678c7cf44202c045d80fc24e8bec56df Mon Sep 17 00:00:00 2001 From: nulltoken Date: Sun, 8 Mar 2020 10:22:33 +0100 Subject: [PATCH] chore: cover assets generation with some expectations --- src/__tests__/generate-assets.jest.test.ts | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/__tests__/generate-assets.jest.test.ts diff --git a/src/__tests__/generate-assets.jest.test.ts b/src/__tests__/generate-assets.jest.test.ts new file mode 100644 index 0000000000..f9609b16ec --- /dev/null +++ b/src/__tests__/generate-assets.jest.test.ts @@ -0,0 +1,38 @@ +import { existsSync, readFileSync } from 'fs'; + +describe('generate-assets', () => { + let assets: Record; + + beforeAll(() => { + const path = __dirname + '/../../rulesets/assets/assets.json'; + if (!existsSync(path)) { + fail('Missing assets.json file. Please run `yarn generate-assets`.'); + } + + const content = readFileSync(path, { encoding: 'utf8' }); + assets = JSON.parse(content); + expect(assets).not.toBeUndefined(); + expect(Object.keys(assets).length).toBeGreaterThan(1); + }); + + describe('produces properly serialized built-in rulesets', () => { + const testCases = [ + ['oas', 'oas2-schema', 'title', 'A JSON Schema for Swagger 2.0 API.'], + ['oas', 'oas3-schema', 'description', 'Validation schema for OpenAPI Specification 3.0.X.'], + ]; + + it.each(testCases)( + "Ruleset '%s' contains a rule '%s' with an inlined schema bearing a '%s' property", + (ruleset: string, ruleName: string, schemaKey: string, schemaValue: string) => { + const key = `@stoplight/spectral/rulesets/${ruleset}/index.json`; + expect(Object.keys(assets)).toContain(key); + const content = JSON.parse(assets[key]); + const rule = content.rules[ruleName]; + expect(rule).not.toBeUndefined(); + const schema = rule.then.functionOptions.schema; + expect(schema[schemaKey]).not.toBeUndefined(); + expect(schema[schemaKey]).toEqual(schemaValue); + }, + ); + }); +});