How to use the @loopback/testlab.TestSandbox 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 / boot / src / __tests__ / unit / booters / datasource.booter.unit.ts View on Github external
describe('datasource booter unit tests', () => {
  const SANDBOX_PATH = resolve(__dirname, '../../../.sandbox');
  const sandbox = new TestSandbox(SANDBOX_PATH);

  const DATASOURCES_PREFIX = 'datasources';
  const DATASOURCES_TAG = 'datasource';

  class AppWithRepo extends RepositoryMixin(Application) {}

  let app: AppWithRepo;
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  let stub: sinon.SinonStub<[any?, ...any[]], void>;

  beforeEach('reset sandbox', () => sandbox.reset());
  beforeEach(getApp);
  beforeEach(createStub);
  afterEach(restoreStub);

  it('gives a warning if called on an app without RepositoryMixin', async () => {
github strongloop / loopback-next / packages / boot / src / __tests__ / unit / booters / repository.booter.unit.ts View on Github external
describe('repository booter unit tests', () => {
  const SANDBOX_PATH = resolve(__dirname, '../../../.sandbox');
  const sandbox = new TestSandbox(SANDBOX_PATH);

  const REPOSITORIES_PREFIX = 'repositories';
  const REPOSITORIES_TAG = 'repository';

  class RepoApp extends RepositoryMixin(Application) {}

  let app: RepoApp;
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  let stub: sinon.SinonStub<[any?, ...any[]], void>;

  beforeEach('reset sandbox', () => sandbox.reset());
  beforeEach(getApp);
  beforeEach(createStub);
  afterEach(restoreStub);

  it('gives a warning if called on an app without RepositoryMixin', async () => {
github strongloop / loopback-next / packages / boot / src / __tests__ / integration / repository.booter.integration.ts View on Github external
describe('repository booter integration tests', () => {
  const SANDBOX_PATH = resolve(__dirname, '../../.sandbox');
  const sandbox = new TestSandbox(SANDBOX_PATH);

  // Remnants from Refactor -- need to add these to core
  const REPOSITORIES_PREFIX = 'repositories';
  const REPOSITORIES_TAG = 'repository';

  let app: BooterApp;

  beforeEach('reset sandbox', () => sandbox.reset());
  beforeEach(getApp);

  it('boots repositories when app.boot() is called', async () => {
    const expectedBindings = [
      `${REPOSITORIES_PREFIX}.ArtifactOne`,
      `${REPOSITORIES_PREFIX}.ArtifactTwo`,
    ];
github strongloop / loopback-next / packages / boot / src / __tests__ / integration / lifecycle-observer.booter.integration.ts View on Github external
describe('lifecycle script booter integration tests', () => {
  const SANDBOX_PATH = resolve(__dirname, '../../.sandbox');
  const sandbox = new TestSandbox(SANDBOX_PATH);

  const OBSERVER_PREFIX = CoreBindings.LIFE_CYCLE_OBSERVERS;
  const OBSERVER_TAG = CoreTags.LIFE_CYCLE_OBSERVER;

  let app: BooterApp;

  beforeEach(function resetSandbox() {
    return sandbox.reset();
  });
  beforeEach(getApp);

  it('boots life cycle observers when app.boot() is called', async () => {
    const expectedBinding = {
      key: `${OBSERVER_PREFIX}.MyLifeCycleObserver`,
      tags: [ContextTags.TYPE, OBSERVER_TAG],
      scope: BindingScope.SINGLETON,
github strongloop / loopback-next / packages / boot / src / __tests__ / integration / interceptor.booter.integration.ts View on Github external
describe('interceptor script booter integration tests', () => {
  const SANDBOX_PATH = resolve(__dirname, '../../.sandbox');
  const sandbox = new TestSandbox(SANDBOX_PATH);

  let app: BooterApp;

  beforeEach(function resetSandbox() {
    return sandbox.reset();
  });
  beforeEach(buildAppWithInterceptors);

  it('boots global interceptors when app.boot() is called', async () => {
    const expectedBinding = {
      key: `${GLOBAL_INTERCEPTOR_NAMESPACE}.myGlobalInterceptor`,
      tags: [
        ContextTags.PROVIDER,
        ContextTags.TYPE,
        ContextTags.GLOBAL_INTERCEPTOR,
        ContextTags.NAMESPACE,
github strongloop / loopback-next / packages / boot / src / __tests__ / unit / booters / booter-utils.unit.ts View on Github external
describe('booter-utils unit tests', () => {
  const SANDBOX_PATH = resolve(__dirname, '../../../.sandbox');
  const sandbox = new TestSandbox(SANDBOX_PATH);

  beforeEach('reset sandbox', () => sandbox.reset());

  describe('discoverFiles()', () => {
    beforeEach(setupSandbox);

    it('discovers files matching a nested glob pattern', async () => {
      const expected = [
        resolve(SANDBOX_PATH, 'empty.artifact.js'),
        resolve(SANDBOX_PATH, 'nested/multiple.artifact.js'),
      ];
      const glob = '/**/*.artifact.js';

      const files = await discoverFiles(glob, SANDBOX_PATH);
      expect(files.sort()).to.eql(expected.sort());
    });
github strongloop / loopback-next / packages / boot / src / __tests__ / unit / booters / controller.booter.unit.ts View on Github external
describe('controller booter unit tests', () => {
  const SANDBOX_PATH = resolve(__dirname, '../../../.sandbox');
  const sandbox = new TestSandbox(SANDBOX_PATH);

  const CONTROLLERS_PREFIX = 'controllers';
  const CONTROLLERS_TAG = 'controller';

  let app: Application;

  beforeEach('reset sandbox', () => sandbox.reset());
  beforeEach(getApp);

  it(`constructor uses ControllerDefaults for 'options' if none are given`, () => {
    const booterInst = new ControllerBooter(app, SANDBOX_PATH);
    expect(booterInst.options).to.deepEqual(ControllerDefaults);
  });

  it('overrides defaults with provided options and uses defaults for rest', () => {
    const options = {
github strongloop / loopback-next / packages / boot / src / __tests__ / integration / datasource.booter.integration.ts View on Github external
describe('datasource booter integration tests', () => {
  const SANDBOX_PATH = resolve(__dirname, '../../.sandbox');
  const sandbox = new TestSandbox(SANDBOX_PATH);

  const DATASOURCES_PREFIX = 'datasources';
  const DATASOURCES_TAG = 'datasource';

  let app: BooterApp;

  beforeEach('reset sandbox', () => sandbox.reset());
  beforeEach(getApp);

  it('boots datasources when app.boot() is called', async () => {
    const expectedBindings = [`${DATASOURCES_PREFIX}.db`];

    await app.boot();

    const bindings = app.findByTag(DATASOURCES_TAG).map(b => b.key);
    expect(bindings.sort()).to.eql(expectedBindings.sort());
github strongloop / loopback-next / packages / boot / src / __tests__ / integration / service.booter.integration.ts View on Github external
describe('service booter integration tests', () => {
  const SANDBOX_PATH = resolve(__dirname, '../../.sandbox');
  const sandbox = new TestSandbox(SANDBOX_PATH);

  const SERVICES_PREFIX = 'services';
  const SERVICES_TAG = 'service';

  let app: BooterApp;

  beforeEach('reset sandbox', () => sandbox.reset());
  beforeEach(getApp);

  it('boots services when app.boot() is called', async () => {
    const expectedBindings = [
      'services.BindableGreetingService',
      'services.CurrentDate',
      'services.GeocoderService',
      'services.NotBindableDate',
    ];
github strongloop / loopback-next / packages / boot / src / __tests__ / acceptance / application-metadata.booter.acceptance.ts View on Github external
describe('application metadata booter acceptance tests', () => {
  let app: BooterApp;
  const SANDBOX_PATH = resolve(__dirname, '../../.sandbox');
  const sandbox = new TestSandbox(SANDBOX_PATH);

  beforeEach('reset sandbox', () => sandbox.reset());
  beforeEach(getApp);

  it('binds content of package.json to application metadata', async () => {
    await app.boot();
    const metadata = await app.get(CoreBindings.APPLICATION_METADATA);
    expect(metadata).containEql({
      name: 'boot-test-app',
      version: '1.0.0',
      description: 'boot-test-app',
    });
  });

  async function getApp() {
    await sandbox.copyFile(resolve(__dirname, '../fixtures/package.json'));