How to use the ava.before function in ava

To help you get started, we’ve selected a few ava 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 bdash-app / bdash / test / lib / DataSourceDefinition / Postgres.js View on Github external
import test from 'ava';
import initialize from '../../fixtures/postgres/initialize';
import Postgres from '../../../src/lib/DataSourceDefinition/Postgres';

test.before(async () => {
  await initialize();
});

// TODO: Make it possible to change the config via enviroment variables
let config = {
  host: '127.0.0.1',
  database: 'bdash_test',
};

test('execute', async t => {
  let result = await new Postgres(config).execute('select id, text from test order by id');
  t.deepEqual(result, {
    fields: ['id', 'text'],
    rows: [['1', 'foo'], ['2', 'bar'], ['3', 'baz']],
  });
});
github kub1x / rodnecislo / test / rodnecislo.js View on Github external
import sinon from 'sinon';
import test from 'ava';

import { rodnecislo, RodneCislo } from '../src/lib/rodnecislo';

// Mock new Date()

const NOW_SEC = 1485865800000; // 31.1.2017 13:30

let clock;

test.before(() => {
  clock = sinon.useFakeTimers(NOW_SEC);
});

test.after(() => {
  clock.restore();
});

// Tests

test('constructor returns RodneCislo', (t) => {
  const v = rodnecislo();

  t.truthy(v);
  t.true(v instanceof RodneCislo);
});
github nodecg / nodecg / test / assets.js View on Github external
// Packages
import test from 'ava';
import * as axios from 'axios';

// Ours
import * as server from './helpers/server';
import * as browser from './helpers/browser';

server.setup();
const {initDashboard} = browser.setup();

import * as C from './helpers/test-constants';
import * as util from './helpers/utilities';

let dashboard;
test.before(async () => {
	dashboard = await initDashboard();
});

const UPLOAD_SOURCE_PATH = path.resolve(__dirname, 'fixtures/assets-to-upload/twitter_banner.png');
const TWITTER_BANNER_PATH = path.join(C.assetsRoot(), 'test-bundle/assets/twitter_banner.png');

// Doing twice to assert file 'change' event
for (let i = 0; i < 2; i++) {
	test.serial(`uploading #${i}`, async t => {
		const assetRep = t.context.apis.extension.Replicant('assets:assets');

		// Make sure the file to upload does not exist first
		if (i === 0) {
			t.false(fs.existsSync(TWITTER_BANNER_PATH));
		}
github melonproject / protocol / tests / integration / competitionRegistration.js View on Github external
const environment = "development";
const config = environmentConfig[environment];
const competitionTerms =
  "0x12208E21FD34B8B2409972D30326D840C9D747438A118580D6BA8C0735ED53810491";

// hoisted variables
let accounts;
let deployer;
let fund;
let manager;
let mlnToken;
let version;
let competition;
let deployed;

test.before(async () => {
  deployed = await deployEnvironment(environment);
  accounts = await api.eth.accounts();
  [deployer, manager] = accounts;
  version = await deployed.Version;
  competition = await deployed.Competition;
  mlnToken = await deployed.MlnToken;
  const [r, s, v] = await getTermsSignatureParameters(manager);
  await version.instance.setupFund.postTransaction(
    { from: manager, gas: config.gas, gasPrice: config.gasPrice },
    [
      "Suisse Fund",
      deployed.EthToken.address, // base asset
      config.protocol.fund.managementFee,
      config.protocol.fund.performanceFee,
      deployed.NoCompliance.address,
      deployed.RMMakeOrders.address,
github voluntarily / vly2 / server / api / goal / __tests__ / loadGoals.spec.js View on Github external
import test from 'ava'
import { loadGoals } from '../loadGoals'
import MemoryMongo from '../../../util/test-memory-mongo'
import Goal from '../goal'
import goals from './goal.fixture.js'

test.before('before connect to database', async (t) => {
  try {
    t.context.memMongo = new MemoryMongo()
    await t.context.memMongo.start()
    t.context.goals = await Goal.create(goals).catch((e) => console.error('Unable to create goals', e))
  } catch (e) { console.error('goal.spec.js before error:', e) }
})

test.after.always(async (t) => {
  await t.context.memMongo.stop()
})

test('Should correctly give count of all goals sorted by rank', async t => {
  let count = await Goal.countDocuments()
  t.is(count, goals.length)
  await loadGoals()
  count = await Goal.countDocuments()
github Swiip / compo / src / __tests__ / component / component.js View on Github external
import test from 'ava';
import sinon from 'sinon';

import { component } from '../../component.js';

let clock;

test.before(() => {
  clock = sinon.useFakeTimers();
});

test.after(() => {
  clock.restore();
});

test('component function asynchronously call define with the right name', (t) => {
  const componentName = 'test';
  global.customElements = { define: sinon.spy() };
  global.HTMLElement = class Mock {};

  component(componentName);

  t.false(global.customElements.define.called);
  clock.tick(0);
github jysperm / elecpass / test / git-adapter.js View on Github external
import fs from 'fs';
import os from 'os';

import _ from 'lodash';
import Promise from 'bluebird';
import rmdir from 'rmdir';
import test from 'ava';

import GitAdapter from '../src/common/git-adapter';

const testRepo = `${os.tmpdir()}/elecpass-repo`

test.before( () => {
  return Promise.promisify(rmdir)(testRepo).catch( err => {
    if (err.code !== 'ENOENT') {
      throw err;
    }
  }).then( () => {
    return Promise.promisify(fs.mkdir)(testRepo);
  });
});

test('initRepo', t => {
  const gitAdapter = new GitAdapter({
    passStorePath: testRepo
  });

  return gitAdapter.initRepo().then( () => {
    return Promise.promisify(fs.readFile)(`${testRepo}/README.md`).then( result => {
github Nipher / pkg-diff / test / parseDep.js View on Github external
}
}

const fakeDep = {
  name: 'test',
  diff: [
    {value: '1.'},
    {value: '1', removed: true},
    {value: '2', added: true},
    {value: '.0'}
  ],
  left: '1.1.0',
  right: '1.2.0'
}

test.before(t => parseDep.__Rewire__('chalk', chalkMock))
test.after(t => parseDep.__ResetDependency__('chalk'))

test('returns messages for the dependency object', t => {
  const message = parseDep(fakeDep)

  t.is(chalkMock.bold.red.calledWith('1'), true)
  t.is(chalkMock.bold.green.calledWith('2'), true)
  t.is(chalkMock.bold.white.calledWith('1.'), true)
  t.is(chalkMock.bold.white.calledWith('.0'), true)

  t.deepEqual(message, {[fakeDep.name]: ['1.1.0', '1.2.0', 'wrgw']})
})

test('uses N/D when appropiate', t => {
  const fakeDep2 = Object.assign({}, fakeDep)
  delete fakeDep2.left
github voluntarily / vly2 / server / api / person / __tests__ / personController.spec.js View on Github external
import test from 'ava'
import sinon from 'sinon'
import { Ability } from '@casl/ability'
import { appReady } from '../../../server'
import Person from '../person'
import MockExpressRequest from 'mock-express-request'
import MockResponse from 'mock-res'
import { updatePersonDetail } from '../person.controller'
import MemoryMongo from '../../../util/test-memory-mongo'
import people from '../__tests__/person.fixture'

test.before('before connect to database', async (t) => {
  try {
    t.context.memMongo = new MemoryMongo()
    await t.context.memMongo.start()
    await appReady
    await Person.create(people).catch((err) => console.error('Unable to create people:', err))
  } catch (e) {
    console.error('personController.spec.js, before connect to database', e)
  }
})

test.after.always(async (t) => {
  await t.context.memMongo.stop()
})

test.serial('Should call send status function for null record ', async t => {
  const userIDWantToUpdate = 'asdfasdfgadf'
github TTLabs / EvaporateJS / test / retry.spec.js View on Github external
let server,
    requestMap = {
      'GET:to_sign': 'sign',
      'POST:uploads': 'initiate',
      'POST:uploadId': 'complete',
      'DELETE:uploadId': 'cancel',
      'GET:uploadId': 'check for parts'
    },
    headersForMethod,
    headStatus

function randomAwsKey() {
  return Math.random().toString().substr(2) + '_' + AWS_UPLOAD_KEY
}

test.before(() => {
  sinon.xhr.supportsCORS = true
  global.XMLHttpRequest = sinon.useFakeXMLHttpRequest()
  global.window = {
    localStorage: {},
    console: console
  };
})

test.beforeEach((t) => {
  t.context.requestedAwsObjectKey = randomAwsKey()

  t.context.baseAddConfig = {
    name: t.context.requestedAwsObjectKey,
    file: new File({
      path: '/tmp/file',
      size: 6000000,