var expectedMsg = 'No message defined!'; var context = getMockContext(); var backgroundSample = getSample(); backgroundSample.sample.helloWorld(context, {}); t.is(context.failure.calledOnce, true); t.is(context.failure.firstCall.args[0], expectedMsg); t.is(context.success.called, false); }); test.cb.serial('should make a promise request', function (t) { var backgroundSample = getSample(); backgroundSample.sample.helloPromise({ endpoint: 'foo.com' }).then(function (result) { t.deepEqual(backgroundSample.mocks.requestPromise.firstCall.args[0], { uri: 'foo.com' }); t.is(result, 'test'); t.end(); }, function () { t.fail(); }); }); test('should return synchronously', function (t) { var backgroundSample = getSample(); t.is(backgroundSample.sample.helloSynchronous({ something: true }), 'Something is true!'); }); test('should throw an error', function (t) { var backgroundSample = getSample(); t.throws(function () {
'app/components/App.js', 'app/components/ItemView.js', 'app/styles/app.css', 'app/templates/item.jst' ]; expectedFiles = expectedFiles.map(function(file) { return path.join(filesPath, file); }); test.cb.before(function(t) { var deps = [ [yoHelpers.createDummyGenerator(), 'ava:app'] ]; yoHelpers.run(path.join(__dirname)) .inDir(tempPath) .withOptions({browserify: true}) .withGenerators(deps) .on('end', t.end); }); test('copy files', function() { assert.file(expectedFiles); }); test('"getOption" return value equal to boilerplate name', function(t) { var options = {'foo': true}; var option = helpers.getOption(boilerplates, options); t.is(option, 'foo'); });
import rm from 'rmdir'; import md from 'mkdirp'; import path from 'path'; import sizeof from 'image-size'; import square from './'; const dest = '.tmp'; const src = './fixtures/grey-chrome.png'; const verifyImage = (image, size) => { var dimensions = sizeof(path.join(dest, image)); size = Math.floor(size); return (dimensions.height === size) && (dimensions.width === size); }; test.cb.before(t => { rm(dest, () => md(dest, t.end)); }); test.serial('square to a image', t => { return square(src, dest, 32).then(images => { Object.keys(images).forEach(size => t.ok(verifyImage(images[size].src, size))); }); }); test.serial('square to multiple images', t => { return square(src, dest, [64, 92]).then(images => { Object.keys(images).forEach(size => t.ok(verifyImage(images[size].src, size))); }); }); test.serial('square to multiple images in various options', t => {
loaders: [ { test: /\.jsx?/, loader: babelLoader, exclude: /node_modules/, }, ], }, }; // Create a separate directory for each test so that the tests // can run in parallel test.cb.beforeEach((t) => { const directory = path.join(outputDir, t.title.replace(/ /g, "_")); t.context.directory = directory; rimraf(directory, (err) => { if (err) return t.end(err); mkdirp(directory, t.end); }); }); test.cb.afterEach((t) => rimraf(t.context.directory, t.end)); test.cb("should interpret options given to the loader", (t) => { const config = assign({}, globalConfig, { output: { path: t.context.directory, }, module: { loaders: [ { test: /\.jsx?/,
{ test: /\.js$/, loader: babelLoader, exclude: /node_modules/, }, ], }, }; // Create a separate directory for each test so that the tests // can run in parallel test.cb.beforeEach((t) => { const directory = path.join(outputDir, t.title.replace(/ /g, "_")); t.context.directory = directory; rimraf(directory, (err) => { if (err) return t.end(err); mkdirp(directory, t.end); }); }); test.cb.beforeEach((t) => { const cacheDirectory = path.join(cacheDir, t.title.replace(/ /g, "_")); t.context.cacheDirectory = cacheDirectory; rimraf(cacheDirectory, (err) => { if (err) return t.end(err); mkdirp(cacheDirectory, t.end); }); }); test.cb.beforeEach((t) => rimraf(defaultCacheDir, t.end)); test.cb.afterEach((t) => rimraf(t.context.directory, t.end)); test.cb.afterEach((t) => rimraf(t.context.cacheDirectory, t.end));
var test = require('ava'); var testUtil = require('../../util'); var GlobalModulePrompt; var KickstartPrompt; var NPMModulePrompt; var initCwd = process.cwd(); test.cb.before(function(t) { testUtil.copyTempTheme({ namespace: 'kickstart_prompt' }, function(config) { GlobalModulePrompt = require('../../../lib/prompts/global_module_prompt.js'); KickstartPrompt = require('../../../lib/prompts/kickstart_prompt.js'); NPMModulePrompt = require('../../../lib/prompts/npm_module_prompt.js'); t.end(); }); }); test.after(function() { process.chdir(initCwd); testUtil.cleanTempTheme('base-theme', '7.0', 'kickstart_prompt'); }); var prototype; test.beforeEach(function() {
test.cb.serial('async without spawn', t => { t.plan(3); const beforeTest = {}; // unset env vars and cache for restoration unsetEnvVars(beforeTest); // mock child_process.execFile beforeTest.childProcessExecFile = childProcess.execFile; childProcess.execFile = () => { const args = Array.prototype.slice.call(arguments); const execFileCb = args[args.length - 1]; if (typeof execFileCb === 'function') { // passing Error here causes osLocale callback not to be called execFileCb(null, 'spawn_NOTALLOWED'); } }; // callback to restore env vars and undo mock const afterTest = () => { restoreEnvVars(beforeTest); childProcess.execFile = beforeTest.childProcessExecFile; }; // test async method requireUncached('./')({spawn: false}, (err, locale) => { console.log('Locale identifier:', locale); afterTest(); t.ifError(err); t.is(locale, expectedFallback, 'Locale did not match expected fallback'); t.not(locale, 'spawn_NOTALLOWED', 'Attempted to spawn subprocess'); t.end(); }); });
// Copyright 2016, Google, Inc. // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 'use strict'; var test = require('ava'); var datasetSizeExample = require('../../bigquery/dataset_size'); test.cb.serial('should return the size of a dataset', function (t) { datasetSizeExample.main( 'bigquery-public-data', 'hacker_news', function (err, size) { t.ifError(err); t.is(typeof size, 'string'); t.truthy(size.indexOf(' GB') === size.length - 3); t.end(); } ); });
import test from 'ava' import testData from './testData.json' import request from 'supertest' import cobalt from '../../src/index' import Food from '../../src/api/food/model' test.cb.before('setup', t => { // Drop all documents Food.remove({}, err => { if (err) t.fail(err.message) // Insert test data Food.create(testData, err => { if (err) t.fail(err.message) t.end() }) }) }) /* list tests */ test.cb('/', t => { request(cobalt.Server) .get('/1.0/food') .expect('Content-Type', /json/) .expect(200) .expect(testData.slice(0, 10)) .end((err, res) => { if (err) t.fail(err.message) t.pass() t.end()
// Copyright 2015-2016, Google, Inc. // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 'use strict'; var test = require('ava'); var writeExample = require('../../logging/write'); test.cb.serial('should write entries', function (t) { writeExample.main(function (err, results) { if (err && err.code === 404) { return t.end(); } t.ifError(err); t.is(results.length, 2, 'should have two results'); t.end(); }); });
var testUtil = require('../../util'); var runSequence; var tempPath; var initCwd = process.cwd(); test.cb.before(function(t) { testUtil.copyTempTheme({ namespace: 'upgrade_task_convert_bootstrap', themeName: 'upgrade-theme', version: '6.2', registerTasksOptions: { pathSrc: 'src', rubySass: true } }, function(config) { runSequence = config.runSequence; tempPath = config.tempPath; t.end(); }); }); test.after(function() { process.chdir(initCwd); testUtil.cleanTempTheme('upgrade-theme', '6.2', 'upgrade_task_convert_bootstrap'); }); test.cb('upgrade:convert-bootstrap should run convert-bootstrap-2-to-3 module on css files', function(t) {
const path = require('path') const test = require('ava') const Sprout = require('sprout') const Spike = require('spike-core') const rimraf = require('rimraf-promise') const tmpdir = require('os-tmpdir') const W = require('when') const node = require('when/node') const {exec} = require('child_process') const tplTestPath = path.join(__dirname, 'example') test.cb.before((t) => { rimraf(tplTestPath, () => { t.end() }) }) test('initializes with sprout, compiles with spike', t => { const tplName = 'spike-tpl-base-test' const locals = { name: 'doge', description: 'wow', github_username: '******', production: false } const sprout = new Sprout(tmpdir()) t.plan(1) return sprout.add(tplName, path.resolve(__dirname, '..')) .tap(() => console.log('initializing template...')) .then(sprout.init.bind(sprout, tplName, tplTestPath, { locals: locals })) .tap(() => console.log('installing dependencies...')) .then(npmInstall.bind(null, tplTestPath)) .tap(() => console.log('compiling with spike...')) .then(() => { return W.promise((resolve, reject) => {
const generated = 17; const lang = 'api-test'; const fixtures = utils.generate(generated, lang); const live = fixtures.live; const allTypes = fixtures.types.full; test.cb.before(t => { database.init().then(() => { database('live').where('language', lang).del().then(() => { database('live').insert(live).then(() => { t.end(); }).catch(e => { // because we can't return in a before, this catch doesn't bubble out console.error(e.stack); // eslint-disable-line no-console t.fail(e.stack); }); }); }) .catch(e => { console.error(e.stack); // eslint-disable-line no-console t.fail(e.stack); }); }); ////////////////////////////// // Utils - attributes ////////////////////////////// test.serial('Utils: attributes - empty query', t => { const testable = utils.testables(live, allTypes); const query = {};
t.is(context.failure.calledOnce, true); t.is(context.failure.firstCall.args[0], expectedMsg); t.is(context.success.called, false); }); test.cb.serial('Reads the file line by line', function (t) { var expectedMsg = 'The file sample.txt has 114 words'; var data = { bucket: 'bucket', file: 'sample.txt' }; var context = { success: function (message) { t.is(message, expectedMsg); t.end(); }, failure: function () { t.end('Should have succeeded!'); } }; var gcsSample = getSample(); gcsSample.sample.wordCount(context, data); t.is(gcsSample.mocks.storage.bucket.calledOnce, true); t.is(gcsSample.mocks.storage.bucket.firstCall.args[0], data.bucket); t.is(gcsSample.mocks.bucket.file.calledOnce, true); t.is(gcsSample.mocks.bucket.file.firstCall.args[0], data.file); });
"use strict"; const test = require("ava"); const fixtures = require("pow-mongodb-fixtures"); const mocksConfig = require("../../../lib/mocksConfig"); const SQS = require("../../../lib/SQS"); const AWSErrors = require("../../../lib/AWSErrors"); const MissingRequiredParameterError = AWSErrors.MissingRequiredParameterError; const QueueDoesNotExistError = AWSErrors.QueueDoesNotExistError; const QueueUrl = "https://example.com/1234/test_queue"; let db; test.cb.before((t) => { db = fixtures.connect(mocksConfig.db); db.clear(t.end); }); test.cb.beforeEach((t) => { db.clearAndLoad({ queue_settings: [{ Name: QueueUrl.split("/").slice(-1).pop(), URL: QueueUrl, Created: new Date().toISOString(), DelaySeconds: 0, MaxMessageSize: 0, MessageRetentionPeriod: 0, ReceiveMessageWaitTimeSeconds: 0, VisibilityTimeout: 0, }], }, t.end);
var testUtil = require('../../util'); var runSequence; var tempPath; var initCwd = process.cwd(); test.cb.before(function(t) { testUtil.copyTempTheme({ namespace: 'upgrade_task_create_deprecated_mixins', themeName: 'upgrade-theme', version: '6.2', registerTasksOptions: { pathSrc: 'src', rubySass: true } }, function(config) { runSequence = config.runSequence; tempPath = config.tempPath; t.end(); }); }); test.cb.after(function(t) { process.chdir(initCwd); testUtil.cleanTempTheme('upgrade-theme', '6.2', 'upgrade_task_create_deprecated_mixins', t.end); }); test.cb('should create deprecated mixins file', function(t) {
loader: babelLoader, query: { presets: ["es2015"], }, exclude: /node_modules/, }, ], }, }; // Create a separate directory for each test so that the tests // can run in parallel test.cb.beforeEach((t) => { createTestDirectory(outputDir, t.title, (err, directory) => { if (err) return t.end(err); t.context.directory = directory; t.end(); }); }); test.cb.afterEach((t) => rimraf(t.context.directory, t.end)); test.cb("should transpile the code snippet", (t) => { const config = assign({}, globalConfig, { output: { path: t.context.directory, }, }); webpack(config, (err) => { t.is(err, null);
}, 'themelet-3': { liferayTheme: liferayThemeThemletMetaData, name: 'themelet-3', realPath: 'path/to/themelet-3', version: liferayVersion } }; var initCwd = process.cwd(); test.cb.before(function(t) { testUtil.copyTempTheme({ namespace: 'extend_prompt' }, function(config) { ExtendPrompt = require('../../../lib/prompts/extend_prompt'); t.end(); }); }); test.after(function() { process.chdir(initCwd); testUtil.cleanTempTheme('base-theme', '7.0', 'extend_prompt'); }); var prototype; test.beforeEach(function() { prototype = _.create(ExtendPrompt.prototype);
import { MongoClient } from "mongodb"; import fixtures from "pow-mongodb-fixtures"; import config from "../../../lib/config"; import SQS from "../../../lib/SQS"; import { MultipleValidationErrors } from "../../../lib/AWSErrors"; let db; let rawDb; const QueueUrl = "https://example.com/1234/test_queue"; test.cb.before((t) => { db = fixtures.connect(config.db); connect((err, database) => { if (err) { throw err; } rawDb = database; t.end(); }); }); test.cb.beforeEach((t) => { db.clearAndLoad({ queue_settings: [{ Name: QueueUrl.split("/").slice(-1).pop(), URL: QueueUrl, Created: new Date().toISOString(), DelaySeconds: 0, MaxMessageSize: 0, MessageRetentionPeriod: 0,
'use strict'; const fs = require('fs'); const test = require('ava'); const mockery = require('mockery'); const streamTransformer = '../lib/credential-to-json.js'; test.cb.beforeEach((t) => { mockery.enable({ useCleanCache: true }); mockery.registerAllowable(streamTransformer, true); mockery.registerAllowables(['stream', 'util', 'os']); t.end(); }); test.cb.afterEach((t) => { mockery.warnOnUnregistered(true); mockery.deregisterAll(); mockery.resetCache(); mockery.disable(); t.end(); }); test.cb('it turns a single profile into an array with 3 entries', (t) => { const fixture = './fixtures/default-only'; const transformer = require(streamTransformer)(); fs.readFile(fixture, {encoding: 'utf-8'}, (err, data) => { if (err) { return t.end(err); } const result = transformer.chunkToArray(data);
import test from 'ava'; import fs from 'fs'; import { getUserDatabase } from '../../server/lib/get_user_database.js'; import { updateUserDatabase } from '../../server/lib/update_user_database.js'; import { addUserDatabase } from '../../server/lib/add_user_database.js'; import { addItemDatabase } from '../../server/lib/add_item_database.js'; import { getItemDatabase } from '../../server/lib/get_item_database.js'; import client from '../../server/lib/pg_client.js'; const sql = fs.readFileSync(`${__dirname}/../fixtures/schema.txt`).toString(); test.cb.beforeEach(t => { client.query(sql, (err) => { if (err) throw err; t.end(); }); }); test.serial.cb('adds user to database', t => { const fakeUser = { name: 'Rory', email: '*****@*****.**', facebookId: '12345677', profileImgUrl: 'rory.jpg', postcode: 'E2 0SY', }; addUserDatabase(client, fakeUser, (err, reply) => { t.is(reply.command, 'INSERT', 'Should return an insert command'); t.end(); });
const test = require('ava') const path = require('path') const rimraf = require('rimraf') const {compileFixture, fixturesPath, fs} = require('./_helpers') test.cb.beforeEach((t) => { rimraf(path.join(fixturesPath, 'loaders', 'public'), () => { t.end() }) }) test('compiles a project with a custom loader', (t) => { return compileFixture(t, 'loaders') .then(({publicPath}) => { return path.join(publicPath, 'js/main.js') }) .tap((index) => { return fs.stat(index).tap(t.truthy.bind(t)) }) .then((index) => { return fs.readFile(index, 'utf8') }) .then((contents) => { return t.regex(contents, /overwritten from local loader/) }) })
var customMetricsExample = require('../../monitoring/create_custom_metric'); /** Refactored out to keep lines shorter */ function getPointValue (timeSeries) { return timeSeries.timeSeries[0].points[0].value.int64Value; } test.cb.serial('should create and read back a custom metric', function (t) { customMetricsExample.main( process.env.GCLOUD_PROJECT, Math.random().toString(36).substring(7), function (err, results) { t.ifError(err); // console.log('---------------------------------------------'); // console.log(JSON.stringify(results, null, 2)); // console.log('---------------------------------------------'); t.is(results.length, 4); // Result of creating metric t.truthy(typeof results[0].name === 'string'); // Result of writing time series t.deepEqual(results[1], {}); // Result of reading time series t.truthy(typeof getPointValue(results[2]) === 'string'); t.truthy(!isNaN(parseInt(getPointValue(results[2]), 10))); // Result of deleting metric t.deepEqual(results[3], {}); t.end(); } ); });
import test from "ava"; import fixtures from "pow-mongodb-fixtures"; import config from "../../../lib/config"; import SQS from "../../../lib/SQS"; let db; const QueueUrl = "https://example.com/1234/test_queue"; test.cb.before((t) => { db = fixtures.connect(config.db); db.clear(t.end); }); test("instantiates with default options", (t) => { const sqs = new SQS(); t.truthy(sqs.options); t.is(sqs.options.region, "us-east-1"); t.truthy(sqs.options.params); }); test("accepts an options argument that overrides the defaults", (t) => { const sqs = new SQS({ region: "us-west-1" }); t.is(sqs.options.region, "us-west-1"); t.truthy(sqs.options.params); }); test("accepts bound parameters", (t) => { const sqs = new SQS({ params: { QueueUrl } }); t.is(sqs.options.params.QueueUrl, QueueUrl); });
index = new Index(projectId); entity = new Entity(projectId); query = new Query(projectId); }); test.after.cb.serial(function (t) { var datastore = transaction.datastore; var query = datastore.createQuery('Task'); testUtil.deleteEntities(datastore, query, t.end); }); // Transactions test.cb.serial('performs a transactional update', function (t) { transaction.testTransactionalUpdate(t.end); }); test.cb.serial('performs retries if necessary', function (t) { transaction.testTransactionalRetry(t.end); }); test.cb.serial('performs a get or create', function (t) { transaction.testTransactionalGetOrCreate(t.end); }); test.cb.serial('gets a snapshot of task list entities', function (t) { transaction.testSingleEntityGroupReadOnly(t.end); }); // Metadata
test.before(() => { m.install(); }); test.after(() => { m.uninstall(); }); test.cb.beforeEach(t => { t.context.port = PORT++; t.context.server = restify.createServer(); t.context.client = restifyClients.createJsonClient({ url: 'http://127.0.0.1:' + t.context.port, }); t.context.server.use( restify.plugins.throttle({ burst: 1, rate: 1, ip: true, }) ); t.context.server.listen(t.context.port, '127.0.0.1', t.end); }); test.cb.afterEach(t => { t.context.client.close(); t.context.server.close(t.end); }); test.cb('should set RNFE as errno if the endpoint does not exists', t => { t.context.client.get('/foo/bar', err => {
test.beforeEach(t => { nock('https://earthquake.usgs.gov') .get('/fdsnws/event/1/query') .query({format: 'geojson', minmagnitude: 6}) .reply(200, {features: []}) t.context.room = helper.createRoom({httpd: false}) }) test.afterEach(t => { t.context.room.destroy() }) test.cb.serial('Es imposible que no hayan temblores sobre 6 en el mundo durante un mes.', t => { t.context.room.user.say('user', 'hubot temblores') setTimeout(() => { t.deepEqual(t.context.room.messages, [ ['user', 'hubot temblores'], ['hubot', 'Por suerte, ningún temblor mayor a 6 grados en todo el mundo.'] ]) t.end() }, 500) }) test.cb.serial('Lugar donde no hayan temblores. Nunca.', t => { t.context.room.user.say('user', 'hubot temblores enunlugardondenuncatiembla') setTimeout(() => { t.deepEqual(t.context.room.messages, [ ['user', 'hubot temblores enunlugardondenuncatiembla'], ['hubot', 'Por suerte, ningún temblor mayor a 6 grados en ENUNLUGARDONDENUNCATIEMBLA.'] ]) t.end() }, 500) })
test: /\.js?$/, exclude: /node_modules/, loaders: ['babel?cacheDirectory&presets[]=es2015'] }, { test: /\.json?$/, loader: 'json' } ] } }; test.cb.beforeEach(t => { const demoServer = requireSubvert.require('./server'); t.context.port = ~~(Math.random() * (8999 - 8000 + 1)) + 8000; t.context[`demoServer-${t.context.port}`] = demoServer.listen(t.context.port, () => { t.end(); }); }); test.afterEach.cb(t => { t.context[`demoServer-${t.context.port}`].close(); t.end(); }); test.cb('Webpack Build', t => { webpack(webpackConfig, (err, stats) => { t.is(err, null, 'An error was returned from Webpack'); t.end(); }); });
test.cb.serial('should send an email', function (t) { proxyquire('../../computeengine/mailjet.js', { nodemailer: { createTransport: function (arg) { t.is(arg, 'test'); return { sendMail: function (payload, cb) { t.deepEqual(payload, { from: 'ANOTHER_EMAIL@ANOTHER_EXAMPLE.COM', to: '*****@*****.**', subject: 'test email from Node.js on Google Cloud Platform', text: 'Hello!\n\nThis a test email from Node.js.' }); cb('done'); t.end(); } }; } }, 'nodemailer-smtp-transport': function (options) { t.deepEqual(options, { host: 'in.mailjet.com', port: 2525, auth: { user: '******', pass: '******' } }); return 'test'; } }); });
"use strict"; const crypto = require("crypto"); const test = require("ava"); const fixtures = require("pow-mongodb-fixtures"); const SQS = require("../../../lib/SQS"); const mocksConfig = require("../../../lib/mocksConfig"); const AWSErrors = require("../../../lib/AWSErrors"); const MissingRequiredParameterError = AWSErrors.MissingRequiredParameterError; const QueueUrl = "https://example.com/1234/test_queue"; test.cb.before((t) => { const db = fixtures.connect(mocksConfig.db); db.clear(t.end); }); test.cb("requires a QueueUrl", (t) => { const sqs = new SQS({ params: { MessageBody: "test" } }); sqs.sendMessage((err, data) => { t.truthy(err); t.falsy(data); t.is(err.code, new MissingRequiredParameterError().code); t.end(); }); }); test.cb("requires a MessageBody", (t) => { const sqs = new SQS({ params: { QueueUrl } });