• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript ava.before函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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');
开发者ID:cyounkins,项目名称:typed-got,代码行数:31,代码来源:headers.ts


示例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 => {
开发者ID:rbcasperson,项目名称:match-three-js,代码行数:31,代码来源:iterchunks.ts


示例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);  
开发者ID:gitter-badger,项目名称:overland,代码行数:31,代码来源:fieldOperations.ts


示例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',
开发者ID:graphcool,项目名称:graphql-config,代码行数:31,代码来源:resolve.ts


示例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>;
}
开发者ID:tyranid-org,项目名称:tyranid,代码行数:30,代码来源:index.ts


示例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');
// });
开发者ID:cyounkins,项目名称:typed-got,代码行数:30,代码来源:unix-socket.ts


示例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: "[email protected]",
        password: "admin",
        passwordConfirm: "admin",
        username: "dominikus1993",
    };
    const res = await request(app)
开发者ID:dominikus1993,项目名称:twitterClone,代码行数:31,代码来源:controllerTest.ts


示例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);
开发者ID:cyounkins,项目名称:typed-got,代码行数:30,代码来源:gzip.ts


示例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');
});
开发者ID:cyounkins,项目名称:typed-got,代码行数:32,代码来源:http.ts


示例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(() => {
开发者ID:cyounkins,项目名称:typed-got,代码行数:30,代码来源:stream.ts



注:本文中的ava.before函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript ava.beforeEach函数代码示例发布时间:2022-05-25
下一篇:
TypeScript ava.afterEach函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap