From 60390de41a4c5c96327aa263252fc0ac5cae71ff Mon Sep 17 00:00:00 2001 From: AayushSaini101 Date: Sat, 4 Jan 2025 13:59:22 +0530 Subject: [PATCH] Add test case for the validate command --- src/core/models/SpecificationFile.ts | 8 +++++--- test/fixtures/newtemplate/__transpiled/index.js | 2 +- test/integration/validate.test.ts | 9 +++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/core/models/SpecificationFile.ts b/src/core/models/SpecificationFile.ts index f8e2b26a152..d43045d8ec1 100644 --- a/src/core/models/SpecificationFile.ts +++ b/src/core/models/SpecificationFile.ts @@ -106,19 +106,21 @@ export class Specification { if (proxyUrl) { try { new URL(proxyUrl); - const proxyAgent = new HttpsProxyAgent(proxyUrl,); + const proxyAgent = new HttpsProxyAgent(proxyUrl); fetchOptions.agent = proxyAgent; + response = await fetch(targetUrl,fetchOptions); } catch (error) { throw new Error(`Invalid proxy URL: ${proxyUrl}`); } } - // Fetch the target URL - response = await fetch(targetUrl, fetchOptions); + response = await fetch(targetUrl); if (!response.ok) { + // console.log(response+" sdf") throw new ErrorLoadingSpec('url', targetUrl); } } catch (error) { + console.log(error); throw new ErrorLoadingSpec('url', targetUrl); } diff --git a/test/fixtures/newtemplate/__transpiled/index.js b/test/fixtures/newtemplate/__transpiled/index.js index 785dbde1b29..d1963faea69 100644 --- a/test/fixtures/newtemplate/__transpiled/index.js +++ b/test/fixtures/newtemplate/__transpiled/index.js @@ -2,7 +2,7 @@ require('source-map-support/register'); var generatorReactSdk = require('@asyncapi/generator-react-sdk'); -var jsxRuntime = require('/media/souvik/HDDA/Programs/asyncapi/cli/node_modules/@asyncapi/generator-react-sdk/node_modules/react/cjs/react-jsx-runtime.production.min.js'); +var jsxRuntime = require('/Users/aaayush/Desktop/OpenSourceContribution/cli/node_modules/@asyncapi/generator-react-sdk/node_modules/react/cjs/react-jsx-runtime.production.min.js'); function index ({ asyncapi, diff --git a/test/integration/validate.test.ts b/test/integration/validate.test.ts index 29e04e1cf97..36ebde23e5c 100644 --- a/test/integration/validate.test.ts +++ b/test/integration/validate.test.ts @@ -65,6 +65,15 @@ describe('validate', () => { expect(ctx.stderr).to.equal(''); done(); }); + test + .stderr() + .stdout() + .command(['validate', 'http://localhost:8080/dummySpec.yml --proxyHost=host --proxyPort=8080']) + .it('works when url is passed with proxyHost and proxyPort with invalid host ', (ctx, done) => { + expect(ctx.stdout).to.contain(''); + expect(ctx.stderr).to.equal('error loading AsyncAPI document from url: Failed to download http://localhost:8080/dummySpec.yml --proxyHost=host --proxyPort=8080.\n'); + done(); + }); test .stderr()