本文整理汇总了TypeScript中ava.before函数的典型用法代码示例。如果您正苦于以下问题:TypeScript before函数的具体用法?TypeScript before怎么用?TypeScript before使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了before函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: require
import test from 'ava';
import * as got from 'got';
var pkg = require('../source/package.json');
import {createServer} from './helpers/server';
let s;
test.before('setup', async () => {
s = await createServer();
s.on('/', (req, res) => {
req.resume();
res.end(JSON.stringify(req.headers));
});
await s.listen(s.port);
});
test('user-agent', async (t) => {
const headers = (await got(s.url, {json: true})).body;
t.is(headers['user-agent'], `${pkg.name}/${pkg.version} (https://github.com/sindresorhus/got)`);
});
test('accept-encoding', async (t) => {
const headers = (await got(s.url, {json: true})).body;
t.is(headers['accept-encoding'], 'gzip,deflate');
});
test('accept header with json option', async (t) => {
let headers = (await got(s.url, {json: true})).body;
t.is(headers.accept, 'application/json');
示例2:
'use strict';
import test from 'ava';
import * as _ from 'lodash';
import * as tools from '../src/tools';
import { Chunk } from '../types';
import { Orb } from '../types';
let orbs;
let chunks: Orb[][][];
let chunksWithPositionInformation: Chunk[];
test.before(() => {
orbs = [ [ 6, 5, 4, 1 ],
[ 3, 2, 2, 5 ],
[ 3, 3, 4, 2 ],
[ 6, 4, 0, 6 ] ];
chunks = [];
_.each(tools.iterchunks(orbs), metadata => {
chunks.push(metadata.chunk);
});
chunksWithPositionInformation = tools.iterchunks(orbs, [4, 2], true);
});
test('has the correct length', t => {
t.is(chunks.length, 6);
});
test('has the correct chunk size', t => {
t.deepEqual(_.map(chunks, 'length'), _.fill(Array(6), 2));
});
test('each chunk has the correct slice size', t => {
示例3: cb
import * as test from 'ava';
import Migration from '../../../lib/db/migration';
import * as Operations from '../../../lib/db/operations';
import * as sinon from 'sinon';
import * as inquirer from 'inquirer';
import * as add from '../fixtures/field/add';
import * as drop from '../fixtures/field/drop';
import * as rename from '../fixtures/field/rename';
Migration.silent = true;
test.before(t => {
sinon.stub(inquirer, 'prompt', (q, cb) => {
const obj = {};
q.forEach(q => obj[q.name] = true);
cb(obj);
});
});
test(`should generate the proper migration path for a field drop`, async function(t) {
const r = new Migration(drop.one, drop.two);
t.same(await r.up(), [
new Operations.AlterModel({ name: 'test_table', fields: [
new Operations.DropField({ name: 'myText' })
]})
]);
});
test(`should generate the proper migration path for a field create`, async function(t) {
const r = new Migration(add.one, add.two);
示例4: serveSchema
import test from 'ava'
import { graphql, introspectionQuery } from 'graphql'
import { GraphQLProjectConfig } from '../../'
import { serveSchema } from '../utils'
test.before(async t => {
return await serveSchema()
})
const confPath = `${__dirname}/.graphqlconfig`
test('getEndpointsMap when endpoint is string url', async t => {
const configData = {
schemaPath: '../schema.json',
extensions: {
endpoints: {
dev: 'http://default',
},
},
}
const config = new GraphQLProjectConfig(configData, confPath)
const endpoints = config.endpointsExtension
t.deepEqual(endpoints && endpoints.getRawEndpointsMap(), {
dev: { url: 'http://default' },
})
})
test('getEndpointsMap when endpoint is single endpoint config', async t => {
const configData = {
schemaPath: '../schema.json',
示例5: createTestData
import { graphqlize } from '../src';
import { createTestData } from './data';
import * as cases from './cases/';
test.before(async () => {
const mongoClient = await mongodb.MongoClient.connect(
'mongodb://127.0.0.1:27017/_tyranid_graphql_test',
{ useNewUrlParser: true }
);
Tyr.config({
mongoClient,
db: mongoClient.db(),
validate: [
{
dir: __dirname,
fileMatch: 'models.js'
}
]
});
await createTestData();
graphqlize(Tyr);
});
interface AvaTest {
name: string;
fn: (...args: any[]) => Promise<any>;
}
示例6: tempfile
import {format} from 'util';
import * as tempfile from 'tempfile';
import test from 'ava';
import * as got from 'got';
import {createServer} from './helpers/server';
const socketPath = tempfile('.socket');
let s;
test.before('setup', async () => {
s = await createServer();
s.on('/', (req, res) => {
res.end('ok');
});
await s.listen(socketPath);
});
test('works', async (t) => {
const url = format('http://unix:%s:%s', socketPath, '/');
t.is((await got(url)).body, 'ok');
});
// "protocol-less works failed with "Protocol "unix:" not supported. Expected "http:".""
//t est('protocol-less works', async (t) => {
// const url = format('unix:%s:%s', socketPath, '/');
// t.is((await got(url)).body, 'ok');
// });
示例7: require
import router from "../../src/global/routing";
import test from "ava";
import * as express from "express";
import * as mongoose from "mongoose";
import * as request from "supertest-as-promised";
import bodyParser = require("body-parser");
const app = express();
test.before("set mongodb", () => {
(mongoose as any).Promise = databaseConfig.promise;
return mongoose.connect("mongodb://localhost/twitter-test-controller").then(() => {
mongoose.connection.db.dropDatabase();
Object.defineProperty(Error.prototype, "toJSON", errorConfig);
// noinspection TypeScriptValidateTypes
app.use(bodyParser.json());
// noinspection TypeScriptValidateTypes
app.use(bodyParser.urlencoded({extended: true}));
// noinspection TypeScriptValidateTypes
app.use("/test/api", router);
});
});
test("register:Success", async(t) => {
const userForRegistration = {
email: "dominikus@test.test",
password: "admin",
passwordConfirm: "admin",
username: "dominikus1993",
};
const res = await request(app)
示例8: async
let s;
test.before('setup', async () => {
s = await createServer();
s.on('/', (req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.setHeader('Content-Encoding', 'gzip');
if (req.method === 'HEAD') {
res.end();
return;
}
zlib.gzip(testContent, (_, data) => res.end(data));
});
s.on('/corrupted', (req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.setHeader('Content-Encoding', 'gzip');
res.end('Not gzipped content');
});
await s.listen(s.port);
});
test('decompress content', async (t) => {
t.is((await got(s.url)).body, testContent);
示例9: async
import {createServer} from './helpers/server';
let s;
test.before('setup', async () => {
s = await createServer();
s.on('/', (req, res) => {
res.end('ok');
});
s.on('/empty', (req, res) => {
res.end();
});
s.on('/404', (req, res) => {
setTimeout(() => {
res.statusCode = 404;
res.end('not');
}, 10);
});
s.on('/?recent=true', (req, res) => {
res.end('recent');
});
await s.listen(s.port);
});
test('simple request', async (t) => {
t.is((await got(s.url)).body, 'ok');
});
示例10: async
let s;
test.before('setup', async () => {
s = await createServer();
s.on('/', (req, res) => {
res.end('ok');
});
s.on('/post', (req, res) => {
req.pipe(res);
});
s.on('/redirect', (req, res) => {
res.writeHead(302, {
location: s.url
});
res.end();
});
s.on('/error', (req, res) => {
res.statusCode = 404;
res.end();
});
await s.listen(s.port);
});
test('option.json can not be used', (t) => {
t.throws(() => {