Skip to content

Commit

Permalink
fixup! WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nulltoken committed Mar 13, 2020
1 parent 6429157 commit 36379ee
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions src/rulesets/asyncapi/__tests__/streetlights.jest.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as path from '@stoplight/path';
import * as fs from 'fs';
import * as nock from 'nock';

import { Document } from '../../../document';
import { isAsyncApiv2 } from '../../../formats';
Expand All @@ -8,15 +10,23 @@ import * as Parsers from '../../../parsers';
import { httpAndFileResolver } from '../../../resolvers/http-and-file';

describe('streetlights', () => {
const streetlights = path.join(__dirname, './__fixtures__/streetlights.yaml');
let s: Spectral;

beforeEach(() => {
s = new Spectral({ resolver: httpAndFileResolver });
s.registerFormat('asyncapi2', isAsyncApiv2);
});

afterEach(() => {
Spectral.registerStaticAssets({});
});

const s = new Spectral({ resolver: httpAndFileResolver });
s.registerFormat('asyncapi2', isAsyncApiv2);
const streetlights = path.join(__dirname, './__fixtures__/streetlights.yaml');

test('can be linted', async () => {
const lint = async (content: string, source?: string) => {
await s.loadRuleset('spectral:asyncapi');

const document = new Document(await readParsable(streetlights, { encoding: 'utf8' }), Parsers.Yaml, streetlights);
const document = new Document(content, Parsers.Yaml, source);

const results = await s.run(document);

Expand All @@ -26,5 +36,27 @@ describe('streetlights', () => {
path: ['info'],
}),
]);
};

test('can be linted in standard context', async () => {
const content = await readParsable(streetlights, { encoding: 'utf8' });

await lint(content, streetlights);
});

test('can be linted in offline context', async () => {
Spectral.registerStaticAssets(require('../../../../rulesets/assets/assets.json'));

const content = await readParsable(streetlights, { encoding: 'utf8' });

const readFileSpy = jest.spyOn(fs, 'readFile').mockImplementation(() => {
throw new Error();
});

nock.disableNetConnect();

await lint(content);

readFileSpy.mockRestore();
});
});

0 comments on commit 36379ee

Please sign in to comment.