Skip to content

Commit ca59c02

Browse files
authored
Switch back to mocha from ava. (#143)
* Switch back to mocha from ava. * Make lint happy. * Uncache vision. * Make canvas dependency optional. * Change node version. * Remove const
1 parent 242e891 commit ca59c02

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2393
-2363
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,15 @@ cache:
5353
- bigquery/node_modules/
5454
- computeengine/node_modules/
5555
- datastore/node_modules/
56+
- debugger/node_modules/
5657
- functions/uuid/node_modules/
5758
- logging/node_modules/
5859
- monitoring/node_modules/
5960
- prediction/node_modules/
6061
- pubsub/node_modules/
6162
- storage/node_modules/
63+
- trace/node_modules/
64+
- vision/node_modules/
6265

6366
services:
6467
- redis-server

package.json

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
"before",
3131
"beforeEach",
3232
"describe",
33-
"it"
33+
"it",
34+
"assert",
35+
"sinon"
3436
],
3537
"ignore": [
3638
"appengine/bower/public/bower_components/**",
@@ -45,10 +47,8 @@
4547
]
4648
},
4749
"scripts": {
48-
"ava": "ava --match='!*: dependencies should install*' --timeout=2m --fail-fast --concurrency=5",
49-
"ava:deps": "npm run deps_appengine && npm run ava",
50-
"cover": "npm run deps_appengine && nyc ava --match='!*: dependencies should install*' --timeout=2m --fail-fast --concurrency=5 --cache",
51-
"deps_appengine": "ava --match='*: dependencies should install*'",
50+
"mocha": "mocha -R dot -t 120000 --require intelli-espower-loader test/_setup.js test/**/*.test.js",
51+
"cover": "nyc mocha --cache -R dot -t 180000 --require intelli-espower-loader test/_setup.js test/**/*.test.js",
5252
"deps_bigquery": "cd bigquery; npm i; cd ../",
5353
"deps_computeengine": "cd computeengine; npm i; cd ../",
5454
"deps_datastore": "cd datastore; npm i; cd ../",
@@ -69,17 +69,14 @@
6969
"report-html": "nyc report --reporter=html",
7070
"test": "npm run lint && npm run cover"
7171
},
72-
"ava": {
73-
"files": [
74-
"test/**/*.test.js"
75-
]
76-
},
7772
"devDependencies": {
7873
"async": "^1.5.2",
79-
"ava": "^0.15.2",
8074
"codecov": "^1.0.1",
75+
"intelli-espower-loader": "^1.0.1",
76+
"mocha": "^2.5.3",
8177
"nodejs-repo-tools": "git+https://github.com/GoogleCloudPlatform/nodejs-repo-tools.git#bbbb6035d77671eb053dbe6b6f0e3ff983f79639",
8278
"nyc": "^6.4.4",
79+
"power-assert": "^1.4.1",
8380
"proxyquire": "^1.7.9",
8481
"request": "^2.72.0",
8582
"semistandard": "^8.0.0",

test/_setup.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2016, Google, Inc.
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
'use strict';
15+
16+
var assert = require('power-assert');
17+
var sinon = require('sinon');
18+
19+
global.assert = assert;
20+
global.sinon = sinon;
21+
22+
beforeEach(function () {
23+
sinon.stub(console, 'error');
24+
sinon.stub(console, 'log');
25+
});
26+
27+
afterEach(function () {
28+
console.error.restore();
29+
console.log.restore();
30+
});

test/appengine/all.test.js

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@
1313

1414
'use strict';
1515

16-
var test = require('ava');
1716
var spawn = require('child_process').spawn;
1817
var request = require('request');
1918
var fs = require('fs');
2019
var path = require('path');
2120
var async = require('async');
22-
var cwd = process.cwd();
2321
var projectId = process.env.GCLOUD_PROJECT;
2422

2523
function getPath (dir) {
26-
return path.join(cwd, '/../../', dir);
24+
return path.join(__dirname, '/../../', dir);
2725
}
2826

2927
function changeScaling (dir) {
@@ -323,36 +321,40 @@ function testRequest (url, sample, cb) {
323321

324322
var port = 8080;
325323
sampleTests.forEach(function (sample) {
326-
sample.env = sample.env || {};
327-
sample.env.PORT = port;
328-
if (sample.dir === 'appengine/parse-server') {
329-
sample.env.SERVER_URL = sample.env.SERVER_URL + port + '/parse';
330-
}
331-
port++;
332-
test.cb.serial(sample.dir + ': dependencies should install', function (t) {
333-
testInstallation(sample, t.end);
334-
});
324+
describe(sample.dir, function () {
325+
sample.env = sample.env || {};
326+
sample.env.PORT = port;
327+
if (sample.dir === 'appengine/parse-server') {
328+
sample.env.SERVER_URL = sample.env.SERVER_URL + port + '/parse';
329+
}
330+
port++;
331+
it('should install dependencies', function (done) {
332+
testInstallation(sample, done);
333+
});
335334

336-
if (sample.TRAVIS && !process.env.TRAVIS) {
337-
return;
338-
}
335+
if (sample.TRAVIS && !process.env.TRAVIS) {
336+
return;
337+
}
339338

340-
if (sample.TRAVIS_NODE_VERSION && process.env.TRAVIS &&
341-
process.env.TRAVIS_NODE_VERSION !== sample.TRAVIS_NODE_VERSION) {
342-
return;
343-
}
339+
if (sample.TRAVIS_NODE_VERSION && process.env.TRAVIS &&
340+
process.env.TRAVIS_NODE_VERSION !== sample.TRAVIS_NODE_VERSION) {
341+
return;
342+
}
344343

345-
test.cb.serial(sample.dir + ' should return 200 and Hello World', function (t) {
346-
testLocalApp(sample, t.end);
344+
it('should return 200 and Hello World', function (done) {
345+
testLocalApp(sample, done);
346+
});
347347
});
348348
});
349349

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

355-
testDeployments(t.end);
356+
testDeployments(done);
357+
});
356358
});
357359
}
358360

test/bigquery/dataset_size.test.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@
1313

1414
'use strict';
1515

16-
var test = require('ava');
1716
var datasetSizeExample = require('../../bigquery/dataset_size');
1817

19-
test.cb.serial('should return the size of a dataset', function (t) {
20-
datasetSizeExample.main(
21-
'bigquery-public-data',
22-
'hacker_news',
23-
function (err, size) {
24-
t.ifError(err);
25-
t.is(typeof size, 'string');
26-
t.truthy(size.indexOf(' GB') === size.length - 3);
27-
t.end();
28-
}
29-
);
18+
describe('bigquery:dataset_size', function () {
19+
it('should return the size of a dataset', function (done) {
20+
datasetSizeExample.main(
21+
'bigquery-public-data',
22+
'hacker_news',
23+
function (err, size) {
24+
assert(!err);
25+
assert.equal(typeof size, 'string');
26+
assert(size.indexOf(' GB') === size.length - 3);
27+
done();
28+
}
29+
);
30+
});
3031
});

test/bigquery/getting_started.test.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@
1313

1414
'use strict';
1515

16-
var test = require('ava');
1716
var gettingStartedExample = require('../../bigquery/getting_started');
1817

19-
test.cb.serial('should run a query', function (t) {
20-
gettingStartedExample.main(
21-
function (err, rows) {
22-
t.ifError(err);
23-
t.truthy(Array.isArray(rows));
24-
t.is(rows.length, 10);
25-
t.end();
26-
}
27-
);
18+
describe('bigquery:getting_started', function () {
19+
it('should run a query', function (done) {
20+
gettingStartedExample.main(
21+
function (err, rows) {
22+
assert(!err);
23+
assert(Array.isArray(rows));
24+
assert.equal(rows.length, 10);
25+
done();
26+
}
27+
);
28+
});
2829
});

test/bigquery/load_data_from_csv.test.js

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,46 +15,47 @@
1515

1616
var async = require('async');
1717
var path = require('path');
18-
var test = require('ava');
1918
var loadDataFromCsvExample = require('../../bigquery/load_data_from_csv');
2019
var pathToCsvFile = path.join(__dirname, '/../../bigquery/resources/data.csv');
2120
var datasetId = 'nodejs_docs_samples';
2221
var tableName = 'test_' + new Date().getTime() + '_' +
2322
Math.floor(Math.random() * 10000);
2423

25-
test.cb.serial('should load data from a csv file', function (t) {
26-
async.series([
27-
function (cb) {
28-
loadDataFromCsvExample.createTable(datasetId, tableName, cb);
29-
},
30-
function (cb) {
31-
loadDataFromCsvExample.main(pathToCsvFile, datasetId, tableName, cb);
32-
},
33-
function (cb) {
34-
loadDataFromCsvExample.deleteTable(datasetId, tableName, cb);
35-
}
36-
], function (err, results) {
37-
if (err) {
38-
loadDataFromCsvExample.deleteTable(datasetId, tableName, function () {
39-
t.end(err);
40-
});
41-
} else {
42-
t.ifError(err);
43-
// metadata
44-
t.is(results[1].status.state, 'DONE');
45-
t.end();
46-
}
24+
describe('bigquery:load_data_from_csv', function () {
25+
it('should load data from a csv file', function (done) {
26+
async.series([
27+
function (cb) {
28+
loadDataFromCsvExample.createTable(datasetId, tableName, cb);
29+
},
30+
function (cb) {
31+
loadDataFromCsvExample.main(pathToCsvFile, datasetId, tableName, cb);
32+
},
33+
function (cb) {
34+
loadDataFromCsvExample.deleteTable(datasetId, tableName, cb);
35+
}
36+
], function (err, results) {
37+
if (err) {
38+
loadDataFromCsvExample.deleteTable(datasetId, tableName, function () {
39+
done(err);
40+
});
41+
} else {
42+
assert(!err);
43+
// metadata
44+
assert.equal(results[1].status.state, 'DONE');
45+
done();
46+
}
47+
});
4748
});
48-
});
4949

50-
test('should require correct arguments', function (t) {
51-
t.throws(function () {
52-
loadDataFromCsvExample.main();
53-
}, Error, 'pathToCsvFile is required!');
54-
t.throws(function () {
55-
loadDataFromCsvExample.main(pathToCsvFile);
56-
}, Error, 'datasetId is required!');
57-
t.throws(function () {
58-
loadDataFromCsvExample.main(pathToCsvFile, datasetId);
59-
}, Error, 'tableName is required!');
50+
it('should require correct arguments', function () {
51+
assert.throws(function () {
52+
loadDataFromCsvExample.main();
53+
}, Error, 'pathToCsvFile is required!');
54+
assert.throws(function () {
55+
loadDataFromCsvExample.main(pathToCsvFile);
56+
}, Error, 'datasetId is required!');
57+
assert.throws(function () {
58+
loadDataFromCsvExample.main(pathToCsvFile, datasetId);
59+
}, Error, 'tableName is required!');
60+
});
6061
});

0 commit comments

Comments
 (0)