How to use the ava.test.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 plopjs / node-plop / tests.ava.js View on Github external
const test = require('ava').test;
const path = require('path');
const del = require('del');
const srcPath = path.resolve(__dirname, 'tests/mock/src');
const clear = () => require('del').sync(srcPath);

// clean out the /src dir when done
test.before(clear);
test.after(clear);
// clear screen before each run
test.before(() => process.stdout.write('\u001B[2J\u001B[0;0f'));

/////
// plop specs
//

// basic action test with plopfile
test('basic add action', require('./tests/basic-plopfile'));

// dynamic actions (the potato tests)
const dynActions = require('./tests/dynamic-actions');
test('dynamic actions (yes potato)', dynActions.yesPotatoes);
test('dynamic actions (no potato)', dynActions.noPotatoes);
github klazuka / elm-hot / test / setup.js View on Github external
const {test} = require('ava');
const puppeteer = require('puppeteer');
const childProcess = require("child_process");

const {startServer} = require('./server.js');

test.before(async () => {
    console.log("Building the Elm code");
    const output = childProcess.execFileSync('./build.sh', {cwd: "./test/fixtures"});
    console.log("Elm build.sh output: " + output);

    global.browser = await puppeteer.launch({
        headless: true,         // default is true; set to false when debugging failed tests
        slowMo: 50,             // introduce a little delay between each operation
        dumpio: false,          // default is false; set to true when debugging failed tests
        args: ['--no-sandbox']  // required for CI builds
    });
});

test.beforeEach(async t => {
    t.context.httpServer = startServer();
    t.context.serverUrl = 'http://127.0.0.1:' + t.context.httpServer.address().port;
github klazuka / elm-hot / test / example-webpack / setup-webpack.js View on Github external
const puppeteer = require('puppeteer');
const childProcess = require("child_process");

var devServerProcess = null;

function startServer() {
    // Ideally we would use webpack dev server's NodeJS API to start the server, but I couldn't
    // get HMR to work in that case. So we will settle for just spawning the server in a separate process.
    devServerProcess = childProcess.exec("npm run dev", {cwd: 'test/example-webpack'}, (error, stdout, stderr) => {
        if (error) {
            console.error(`failed to launch dev server process; error: ${error}`);
        }
    });
}

test.before(async () => {
    global.browser = await puppeteer.launch({
        headless: true,         // default is true; set to false when debugging failed tests
        slowMo: 50,             // introduce a little delay between each operation
        dumpio: false,          // default is false; set to true when debugging failed tests
        args: ['--no-sandbox']  // required for CI builds
    });
});

test.beforeEach(async t => {
    // TODO [kl] if we ever do multiple webpack tests, we will need to randomize the server listen port
    t.context.httpServer = startServer();
    t.context.serverUrl = 'http://127.0.0.1:3333';

    const page = await browser.newPage();

    // TODO [kl] get rid of the brittle sleep. find a better way
github jasongin / nvs / test / cli / cmdTests.js View on Github external
'use strict';

const childProcess = require('child_process');
const path = require('path');
let test = require('ava').test;

const nvsRootDir = path.resolve(__dirname, '..', '..');
const testParentDir = path.resolve(__dirname, '..', 'temp');
const testDir = path.join(testParentDir, 'cmd');

const testNodeVersion = '8.5.0';
const testNpmVersion = '6.4.1';

test.before(t => {
	require('../fsUtil').createDirectoryIfNotFound(testParentDir);
});

test.after.always(t => {
	require('../fsUtil').removeDirectoryIfEmpty(testParentDir);
});

if (process.platform !== 'win32') {
	test = test.skip;
}

test('Command Prompt CLI', t => {
	const commands = [
		'echo %NVS_HOME%',
		'.\\nvs.cmd lsr 8',
		'.\\nvs.cmd add ' + testNodeVersion,
github fimbullinter / wotan / test / conformance / services.spec.ts View on Github external
const container = new Container();
        container.bind(DirectoryService).toConstantValue(directoryService);
        container.bind(FormatterLoaderHost).toConstantValue(host);
        const loader = container.resolve(FormatterLoader);
        t.is(loader.loadFormatter('foo'), Formatter);
        t.is(coreRequested, 1);
        t.is(loader.loadFormatter('foo-bar'), Formatter);
        t.is(coreRequested, 2);
        t.is(loader.loadFormatter('/foo/bar'), Formatter);
        t.is(coreRequested, 2);
    })();
});

let tmpDir: string;
test.before(() => {
    tmpDir = fs.mkdtempSync('fs-test');
});

test('FileSystem', (t) => {
    const fileSystem = new NodeFileSystem();
    t.is(fileSystem.normalizePath('C:\\foo\\bar/baz'), getCanonicalFileName('C:/foo/bar/baz'));
    t.is(fileSystem.normalizePath('/foo/bar/baz'), getCanonicalFileName('/foo/bar/baz'));
    t.is(fileSystem.normalizePath('/Foo/Bar/Baz'), getCanonicalFileName('/Foo/Bar/Baz'));

    const dir = path.posix.join(tmpDir, 'sub');
    const deepDir = path.posix.join(dir, 'dir');
    t.throws(() => fileSystem.createDirectory(deepDir));
    t.throws(() => fileSystem.createDirectory(tmpDir));
    fileSystem.createDirectory(dir);
    fileSystem.createDirectory(deepDir);
    t.true(fs.existsSync(dir));
github jasongin / nvs / test / cli / psTests.js View on Github external
'use strict';

const childProcess = require('child_process');
const path = require('path');
let test = require('ava').test;

const nvsRootDir = path.resolve(__dirname, '..', '..');
const testParentDir = path.resolve(__dirname, '..', 'temp');
const testDir = path.join(testParentDir, 'ps');

const testNodeVersion = '8.5.0';
const testNpmVersion = '6.4.1';

test.before(t => {
	require('../fsUtil').createDirectoryIfNotFound(testParentDir);
});

test.after.always(t => {
	require('../fsUtil').removeDirectoryIfEmpty(testParentDir);
});

if (process.platform !== 'win32') {
	test = test.skip;
}

test('PowerShell CLI', t => {
	const commands = [
		'echo $env:NVS_HOME',
		'.\\nvs.ps1 lsr 8',
		'.\\nvs.ps1 add ' + testNodeVersion,
github thinkjs / think-model / test / mysql / index.js View on Github external
const mysqlSocket = require('think-mysql');
const DBConfig = {
  database: 'test',
  prefix: 'think_',
  encoding: 'utf8',
  nums_per_page: 10,
  host: '127.0.0.1',
  port: '',
  user: 'root',
  password: 'root'
};

const model = (name = 'user') => new Base(name, DBConfig);
let Base;

test.before(() => {
  muk(mysqlSocket.prototype, 'query', function(sql){
    if(helper.isObject(sql)){
      sql = sql.sql;
    }
    if (sql === 'SHOW COLUMNS FROM `think_friend`') {
      var data = [
        {"Field":"id","Type":"int(11) unsigned","Null":"NO","Key":"PRI","Default":null,"Extra":"auto_increment"},
        {"Field":"title","Type":"varchar(255)","Null":"NO","Key":"UNI","Default":null,"Extra":""},
        {"Field":"cate_id","Type":"tinyint(255)","Null":"NO","Key":"MUL","Default":null,"Extra":""},
        {"Field":"cate_no","Type":"int(11)","Null":"YES","Key":"","Default":null,"Extra":""},
      ];
      return Promise.resolve(data);
    }else if (sql === 'SHOW COLUMNS FROM `think_cate`') {
      var data = [
        {"Field":"id","Type":"int(11) unsigned","Null":"NO","Key":"","Default":null,"Extra":""},
        {"Field":"title","Type":"varchar(255)","Null":"NO","Key":"UNI","Default":null,"Extra":""},
github jasongin / nvs / test / availableTests.js View on Github external
const test = require('ava').test;

test.before(require('./checkNodeVersion'));

test.todo('List available - single remote');
test.todo('List available - all remotes');
test.todo('List available - index not found');
github jasongin / nvs / test / modules / migrateTests.js View on Github external
'use strict';

const path = require('path');
const test = require('ava').test;
const rewire = require('rewire');
const Error = require('../../lib/error');

test.before(require('../checkNodeVersion'));

const mockFs = require('../mocks/fs');
const testHome = mockFs.fixSep('/home/test/nvs/');

require('../../lib/settings').settings = {
	home: testHome,
	aliases: {},
	remotes: {
		'default': 'test',
		'test': 'http://example.com/test',
	},
	quiet: true,
};

const NodeVersion = require('../../lib/version');
const nvsMigrate = rewire('../../lib/migrate');
github jasongin / nvs / test / modules / linkTests.js View on Github external
'use strict';

const path = require('path');
const test = require('ava').test;
const rewire = require('rewire');

test.before(require('../checkNodeVersion'));

const mockFs = require('../mocks/fs');
const testHome = mockFs.fixSep('/home/test/nvs/');

const settings = require('../../lib/settings').settings = {
	home: testHome,
	aliases: {},
	remotes: {
		'test': 'http://example.com/test',
	},
	skipUpdateShellEnv: true,
	linkToSystem: false,
};

const linkPath = testHome + 'default';