How to use the @loopback/testlab.supertest function in @loopback/testlab

To help you get started, we’ve selected a few @loopback/testlab examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github strongloop / loopback-next / packages / cli / smoke-test / openapi / real-world-apis.smoke.js View on Github external
realWorldAPIs = process.env.APIS.split(/\s+/)
        .filter(Boolean)
        .map(url => ({
          swaggerUrl: url,
          name: '',
          version: '',
        }));
      return;
    }

    // This hook sometimes takes several seconds, due to the large download
    // eslint-disable-next-line no-invalid-this
    this.timeout(10000);

    // Download a list of over 1500 real-world Swagger APIs from apis.guru
    const res = await supertest('https://api.apis.guru')
      .get('/v2/list.json')
      .expect(200);
    if (!res.ok) {
      throw new Error('Unable to download API listing from apis.guru');
    }

    // Remove certain APIs that are known to cause problems
    const apis = res.body;

    // GitHub's CORS policy blocks this request
    delete apis['googleapis.com:adsense'];

    // These APIs cause infinite loops in json-schema-ref-parser.  Still investigating.
    // https://github.com/BigstickCarpet/json-schema-ref-parser/issues/56
    delete apis['bungie.net'];
    delete apis['stripe.com'];
github strongloop / loopback-next / packages / rest / src / __tests__ / integration / rest.server.integration.ts View on Github external
it('parses query without decorated rest query params', async () => {
    // This handler responds with the query object (which is expected to
    // be parsed by Express)
    function requestWithQueryHandler({request, response}: RequestContext) {
      response.json(request.query);
      response.end();
    }

    // See https://github.com/strongloop/loopback-next/issues/2088
    const server = await givenAServer();
    server.handler(requestWithQueryHandler);
    await server.start();
    await supertest(server.url)
      .get('/?x=1&y[a]=2')
      .expect(200, {x: '1', y: {a: '2'}});
    await server.stop();
  });
github strongloop / loopback-next / packages / rest / src / __tests__ / integration / request-context.integration.ts View on Github external
it('combines both baseUrl and basePath', async () => {
      const lbApp = new RestApplication();
      lbApp.handler(contextObservingHandler);
      lbApp.basePath('/v1'); // set basePath at LoopBack level

      const expressApp = express();
      expressApp.use('/api', lbApp.requestHandler); // mount the app at baseUrl

      await supertest(expressApp)
        .get('/api/v1/products')
        .expect(200);

      expect(observedCtx.basePath).to.equal('/api/v1');
    });
github strongloop / loopback-next / examples / express-composition / src / __tests__ / acceptance / test-helper.ts View on Github external
export async function setupExpressApplication(): Promise {
  const server = new ExpressServer({rest: givenHttpServerConfig()});
  await server.boot();
  await server.start();

  const lbApp = server.lbApp;

  const client = supertest('http://127.0.0.1:3000');

  return {server, client, lbApp};
}
github strongloop / loopback-next / examples / lb3-application / src / __tests__ / acceptance / test-helper.ts View on Github external
export async function setupApplication(): Promise {
  const app = new ExpressServer({
    rest: givenHttpServerConfig(),
  });

  await app.boot();
  await app.start();

  const client = supertest(app.url);

  return {app, client};
}
github strongloop / loopback-next / packages / http-server / src / __tests__ / integration / http-server.integration.ts View on Github external
it('starts server', async () => {
    const serverOptions = givenHttpServerConfig();
    server = new HttpServer(dummyRequestHandler, serverOptions);
    await server.start();
    await supertest(server.url)
      .get('/')
      .expect(200);
  });
github strongloop / loopback-next / packages / rest / src / __tests__ / integration / rest.server.integration.ts View on Github external
it('exports rootUrl property', async () => {
        server = await givenAServer();
        server.handler(dummyRequestHandler);
        expect(server.rootUrl).to.be.undefined();
        await server.start();
        expect(server)
          .to.have.property('rootUrl')
          .which.is.a.String()
          .match(/http|https\:\/\//);
        await supertest(server.rootUrl)
          .get('/api')
          .expect(200, 'Hello');
      });
github strongloop / loopback-next / packages / rest / src / __tests__ / acceptance / bootstrapping / rest.acceptance.ts View on Github external
async function startServerCheck(app: Application) {
  const server = await app.getServer(RestServer);
  await app.start();
  const port = await server.get(RestBindings.PORT);

  await supertest(`http://localhost:${port}`)
    .get('/')
    .expect(200, 'hello world');
  await app.stop();
}