Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch back to mocha from ava. #143

Merged
merged 6 commits into from
Jun 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ cache:
- bigquery/node_modules/
- computeengine/node_modules/
- datastore/node_modules/
- debugger/node_modules/
- functions/uuid/node_modules/
- logging/node_modules/
- monitoring/node_modules/
- prediction/node_modules/
- pubsub/node_modules/
- storage/node_modules/
- trace/node_modules/
- vision/node_modules/

services:
- redis-server
Expand Down
19 changes: 8 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
"before",
"beforeEach",
"describe",
"it"
"it",
"assert",
"sinon"
],
"ignore": [
"appengine/bower/public/bower_components/**",
Expand All @@ -45,10 +47,8 @@
]
},
"scripts": {
"ava": "ava --match='!*: dependencies should install*' --timeout=2m --fail-fast --concurrency=5",
"ava:deps": "npm run deps_appengine && npm run ava",
"cover": "npm run deps_appengine && nyc ava --match='!*: dependencies should install*' --timeout=2m --fail-fast --concurrency=5 --cache",
"deps_appengine": "ava --match='*: dependencies should install*'",
"mocha": "mocha -R dot -t 120000 --require intelli-espower-loader test/_setup.js test/**/*.test.js",
"cover": "nyc mocha --cache -R dot -t 180000 --require intelli-espower-loader test/_setup.js test/**/*.test.js",
"deps_bigquery": "cd bigquery; npm i; cd ../",
"deps_computeengine": "cd computeengine; npm i; cd ../",
"deps_datastore": "cd datastore; npm i; cd ../",
Expand All @@ -69,17 +69,14 @@
"report-html": "nyc report --reporter=html",
"test": "npm run lint && npm run cover"
},
"ava": {
"files": [
"test/**/*.test.js"
]
},
"devDependencies": {
"async": "^1.5.2",
"ava": "^0.15.2",
"codecov": "^1.0.1",
"intelli-espower-loader": "^1.0.1",
"mocha": "^2.5.3",
"nodejs-repo-tools": "git+https://github.com/GoogleCloudPlatform/nodejs-repo-tools.git#bbbb6035d77671eb053dbe6b6f0e3ff983f79639",
"nyc": "^6.4.4",
"power-assert": "^1.4.1",
"proxyquire": "^1.7.9",
"request": "^2.72.0",
"semistandard": "^8.0.0",
Expand Down
30 changes: 30 additions & 0 deletions test/_setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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 assert = require('power-assert');
var sinon = require('sinon');

global.assert = assert;
global.sinon = sinon;

beforeEach(function () {
sinon.stub(console, 'error');
sinon.stub(console, 'log');
});

afterEach(function () {
console.error.restore();
console.log.restore();
});
52 changes: 27 additions & 25 deletions test/appengine/all.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@

'use strict';

var test = require('ava');
var spawn = require('child_process').spawn;
var request = require('request');
var fs = require('fs');
var path = require('path');
var async = require('async');
var cwd = process.cwd();
var projectId = process.env.GCLOUD_PROJECT;

function getPath (dir) {
return path.join(cwd, '/../../', dir);
return path.join(__dirname, '/../../', dir);
}

function changeScaling (dir) {
Expand Down Expand Up @@ -323,36 +321,40 @@ function testRequest (url, sample, cb) {

var port = 8080;
sampleTests.forEach(function (sample) {
sample.env = sample.env || {};
sample.env.PORT = port;
if (sample.dir === 'appengine/parse-server') {
sample.env.SERVER_URL = sample.env.SERVER_URL + port + '/parse';
}
port++;
test.cb.serial(sample.dir + ': dependencies should install', function (t) {
testInstallation(sample, t.end);
});
describe(sample.dir, function () {
sample.env = sample.env || {};
sample.env.PORT = port;
if (sample.dir === 'appengine/parse-server') {
sample.env.SERVER_URL = sample.env.SERVER_URL + port + '/parse';
}
port++;
it('should install dependencies', function (done) {
testInstallation(sample, done);
});

if (sample.TRAVIS && !process.env.TRAVIS) {
return;
}
if (sample.TRAVIS && !process.env.TRAVIS) {
return;
}

if (sample.TRAVIS_NODE_VERSION && process.env.TRAVIS &&
process.env.TRAVIS_NODE_VERSION !== sample.TRAVIS_NODE_VERSION) {
return;
}
if (sample.TRAVIS_NODE_VERSION && process.env.TRAVIS &&
process.env.TRAVIS_NODE_VERSION !== sample.TRAVIS_NODE_VERSION) {
return;
}

test.cb.serial(sample.dir + ' should return 200 and Hello World', function (t) {
testLocalApp(sample, t.end);
it('should return 200 and Hello World', function (done) {
testLocalApp(sample, done);
});
});
});

if (process.env.TRAVIS && process.env.DEPLOY_TESTS) {
test.cb.serial('should deploy all samples', function (t) {
// 30 minutes because deployments are slow
this.timeout(30 * 60 * 1000);
describe('deployments', function () {
it('should deploy all samples', function (done) {
// 30 minutes because deployments are slow
this.timeout(30 * 60 * 1000);

testDeployments(t.end);
testDeployments(done);
});
});
}

Expand Down
25 changes: 13 additions & 12 deletions test/bigquery/dataset_size.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@

'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();
}
);
describe('bigquery:dataset_size', function () {
it('should return the size of a dataset', function (done) {
datasetSizeExample.main(
'bigquery-public-data',
'hacker_news',
function (err, size) {
assert(!err);
assert.equal(typeof size, 'string');
assert(size.indexOf(' GB') === size.length - 3);
done();
}
);
});
});
21 changes: 11 additions & 10 deletions test/bigquery/getting_started.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@

'use strict';

var test = require('ava');
var gettingStartedExample = require('../../bigquery/getting_started');

test.cb.serial('should run a query', function (t) {
gettingStartedExample.main(
function (err, rows) {
t.ifError(err);
t.truthy(Array.isArray(rows));
t.is(rows.length, 10);
t.end();
}
);
describe('bigquery:getting_started', function () {
it('should run a query', function (done) {
gettingStartedExample.main(
function (err, rows) {
assert(!err);
assert(Array.isArray(rows));
assert.equal(rows.length, 10);
done();
}
);
});
});
69 changes: 35 additions & 34 deletions test/bigquery/load_data_from_csv.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,47 @@

var async = require('async');
var path = require('path');
var test = require('ava');
var loadDataFromCsvExample = require('../../bigquery/load_data_from_csv');
var pathToCsvFile = path.join(__dirname, '/../../bigquery/resources/data.csv');
var datasetId = 'nodejs_docs_samples';
var tableName = 'test_' + new Date().getTime() + '_' +
Math.floor(Math.random() * 10000);

test.cb.serial('should load data from a csv file', function (t) {
async.series([
function (cb) {
loadDataFromCsvExample.createTable(datasetId, tableName, cb);
},
function (cb) {
loadDataFromCsvExample.main(pathToCsvFile, datasetId, tableName, cb);
},
function (cb) {
loadDataFromCsvExample.deleteTable(datasetId, tableName, cb);
}
], function (err, results) {
if (err) {
loadDataFromCsvExample.deleteTable(datasetId, tableName, function () {
t.end(err);
});
} else {
t.ifError(err);
// metadata
t.is(results[1].status.state, 'DONE');
t.end();
}
describe('bigquery:load_data_from_csv', function () {
it('should load data from a csv file', function (done) {
async.series([
function (cb) {
loadDataFromCsvExample.createTable(datasetId, tableName, cb);
},
function (cb) {
loadDataFromCsvExample.main(pathToCsvFile, datasetId, tableName, cb);
},
function (cb) {
loadDataFromCsvExample.deleteTable(datasetId, tableName, cb);
}
], function (err, results) {
if (err) {
loadDataFromCsvExample.deleteTable(datasetId, tableName, function () {
done(err);
});
} else {
assert(!err);
// metadata
assert.equal(results[1].status.state, 'DONE');
done();
}
});
});
});

test('should require correct arguments', function (t) {
t.throws(function () {
loadDataFromCsvExample.main();
}, Error, 'pathToCsvFile is required!');
t.throws(function () {
loadDataFromCsvExample.main(pathToCsvFile);
}, Error, 'datasetId is required!');
t.throws(function () {
loadDataFromCsvExample.main(pathToCsvFile, datasetId);
}, Error, 'tableName is required!');
it('should require correct arguments', function () {
assert.throws(function () {
loadDataFromCsvExample.main();
}, Error, 'pathToCsvFile is required!');
assert.throws(function () {
loadDataFromCsvExample.main(pathToCsvFile);
}, Error, 'datasetId is required!');
assert.throws(function () {
loadDataFromCsvExample.main(pathToCsvFile, datasetId);
}, Error, 'tableName is required!');
});
});
Loading