How to use fusion-test-utils - 10 common examples

To help you get started, we’ve selected a few fusion-test-utils 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 fusionjs / fusionjs / fusion-plugin-rpc / src / __tests__ / index.node.js View on Github external
test('service - requires ctx', t => {
  const app = createTestFixture();

  let wasResolved = false;
  getSimulator(
    app,
    createPlugin({
      deps: {rpcFactory: MockPluginToken},
      provides: ({rpcFactory}) => {
        // $FlowFixMe
        t.throws(() => rpcFactory());
        wasResolved = true;
      },
    })
  );
  t.true(wasResolved, 'service was resolved');

  t.end();
});
github fusionjs / fusionjs / fusion-plugin-service-worker / src / __tests__ / health.node.js View on Github external
test('/health request', async t => {
  t.plan(2);
  const app = new App('el', el => el);
  app.register(SWTemplateFunctionToken, swTemplateFunction);
  app.register(ServiceWorker);
  const sim = getSimulator(app);
  // Basic /health request
  const ctx_1 = await sim.request('/sw.js');
  t.equal(ctx_1.status, 200, 'sends 200 status on sw request');
  t.ok(
    String(ctx_1.body)
      .trim()
      .replace(/\n/g, '')
      .startsWith(`import {getHandlers} from '../../index'`),
    'sends correct response'
  );
  t.end();

  await app.cleanup();
});
github fusionjs / fusionjs / fusion-plugin-node-performance-emitter / src / __tests__ / index.node.js View on Github external
test('service - cannot track the same types more than once at a time', t => {
  const perfService = getService(
    createTestFixture,
    NodePerformanceEmitterPlugin
  );

  t.throws(() => perfService.start(), 'already running trackers cannot start');

  // Able to start now that we've stopped
  t.doesNotThrow(() => perfService.stop(), 'service can be stopped');
  t.doesNotThrow(
    () => perfService.start(),
    'service can run if the trackers are not active'
  );

  t.doesNotThrow(() => perfService.stop(), 'service can be stopped');
  t.doesNotThrow(
    () => perfService.stop(),
github fusionjs / fusion-cli / test / e2e / test-jest-app / fixture / src / __tests__ / class-props.js View on Github external
// @noflow
import {test} from 'fusion-test-utils';

import classPropFixture from '../class-props';

test('Class properties work /w flow annotation', async assert => {
  const result = new classPropFixture();
  assert.equal(
    result.classProp(),
    true,
    'class props work and evaluates to true'
  );
});
github fusionjs / fusionjs / fusion-plugin-react-helmet-async / src / __tests__ / render.js View on Github external
if (__BROWSER__) {
    root = document.createElement('div');
    root.setAttribute('id', 'root2');
    if (document.body) {
      document.body.appendChild(root);
    }
    app = new App(Root, el => render(el, root));
  } else {
    app = new App(Root);
  }
  app.register(HelmetPlugin);
  app.middleware((ctx, next) => {
    ctx.nonce = 'test-nonce';
    return next();
  });
  const sim = getSimulator(app);
  const ctx = await sim.render('/');

  if (__NODE__) {
    const fixtureFile = './src/__fixtures__/ssr1.html';
    // Uncomment to regenerate fixture
    // fs.writeFileSync(fixtureFile, ctx.body);
    t.equal(ctx.body, fs.readFileSync(fixtureFile).toString());
  } else if (__BROWSER__) {
    // need to wait until next tick for dom changes
    await new Promise(resolve => setTimeout(resolve, 10));
    t.equal(document.title, "My Title's ");
    const baseEl = document.querySelector('base');
    if (!baseEl) {
      throw new Error('Could not find base element');
    }
    t.equal(baseEl.getAttribute('href'), 'http://mysite.com/');
github fusionjs / fusionjs / fusion-plugin-universal-logger / src / __tests__ / index.browser.js View on Github external
// $FlowFixMe
    t.equal(typeof payload.args[0].error.stack, 'string');
    // $FlowFixMe
    t.equal(typeof payload.args[0].error.message, 'string');
    called = true;
  });
  const mockEmitterPlugin = createPlugin({
    provides: () => mockEmitter,
  });

  app.register(UniversalEventsToken, mockEmitterPlugin);
  app.middleware({logger: LoggerToken}, ({logger}) => {
    logger.error(new Error('fail'));
    return (ctx, next) => next();
  });
  getSimulator(app);
  t.equals(called, true, 'called');
  t.end();
});
github fusionjs / fusionjs / fusion-plugin-react-redux / src / __tests__ / index.node.js View on Github external
t.fail();
          t.end();
          return;
        }

        const store = await reduxScoped.initStore();
        // $FlowFixMe
        t.equals(store.mock, true, '[Final store] ctx provided by ctxEnhancer');

        return next();
      };
    },
  });
  app.register(testPlugin);

  const simulator = getSimulator(app);
  await simulator.render('/');
};
github fusionjs / fusionjs / fusion-plugin-react-redux / src / __tests__ / index.node.js View on Github external
tape('non-ssr routes', async t => {
  const reducer = (state, action) => ({test: action.payload || 1});
  const plugin = getService(appCreator(reducer), Redux);
  let mockCtx = {
    body: null,
    memoized: new Map(),
  };

  t.plan(1);
  if (!Redux.middleware) {
    t.end();
    return;
  }

  // $FlowFixMe
  await Redux.middleware(null, plugin)((mockCtx: any), () => Promise.resolve());
  t.notok(plugin.from((mockCtx: any)).store);
  t.end();
});
github fusionjs / fusionjs / create-fusion-plugin / templates / plugin / content / src / __tests__ / index.browser.js View on Github external
tape('browser middleware', async t => {
  const element = React.createElement('div');
  const ctx: any = {element, template: {body: []}, memoized: new Map()};
  const service = getService(appCreator(), Plugin);
  try {
    await (Plugin.middleware &&
      // $FlowFixMe
      Plugin.middleware(null, service)((ctx: any), () => Promise.resolve()));
  } catch (e) {
    t.ifError(e);
  }

  t.end();
});
github fusionjs / fusionjs / fusion-plugin-rpc / src / __tests__ / test-mock.js View on Github external
test('mock with missing handler', async t => {
  const app = createTestFixture();

  t.plan(1);
  getSimulator(
    app,
    createPlugin({
      deps: {rpcFactory: MockPluginToken},
      provides: async deps => {
        const rpc = deps.rpcFactory.from(mockCtx);
        try {
          await rpc.request('test');
        } catch (e) {
          t.equal(e.message, 'Missing RPC handler for test');
        } finally {
          t.end();
        }
      },
    })
  );
});

fusion-test-utils

Test utilities for FusionJS

MIT
Latest version published 2 years ago

Package Health Score

54 / 100
Full package analysis

Similar packages