Skip to content

Commit f5869a0

Browse files
jmdobryAce Nassri
authored and
Ace Nassri
committed
Switch from Mocha to Ava for faster tests (#289)
* Switch from Mocha to Ava * Concurrency: 5
1 parent 350056a commit f5869a0

File tree

5 files changed

+51
-85
lines changed

5 files changed

+51
-85
lines changed

monitoring/snippets/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
"license": "Apache Version 2.0",
66
"author": "Google Inc.",
77
"scripts": {
8-
"test": "cd ..; npm run t -- monitoring/test/*.test.js",
9-
"system-test": "cd ..; npm run st -- monitoring/system-test/*.test.js"
8+
"test": "cd ..; npm run st -- monitoring/system-test/*.test.js"
109
},
1110
"dependencies": {
1211
"async":"2.1.2",

monitoring/snippets/system-test/create_custom_metric.test.js

+30-27
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,40 @@
1313

1414
'use strict';
1515

16-
var customMetricsExample = require('../create_custom_metric');
16+
require(`../../system-test/_setup`);
17+
18+
const customMetricsExample = require('../create_custom_metric');
1719

1820
/** Refactored out to keep lines shorter */
1921
function getPointValue (timeSeries) {
2022
return timeSeries.timeSeries[0].points[0].value.int64Value;
2123
}
2224

23-
describe('monitoring:create_custom_metric', function () {
24-
it('should create and read back a custom metric', function (done) {
25-
customMetricsExample.main(
26-
process.env.GCLOUD_PROJECT,
27-
Math.random().toString(36).substring(7),
28-
function (err, results) {
29-
assert.ifError(err);
30-
assert(results.length === 4);
31-
// Result of creating metric
32-
assert(typeof results[0].name === 'string');
33-
// Result of writing time series
34-
assert.deepEqual(results[1], {});
35-
// Result of reading time series
36-
assert(typeof getPointValue(results[2]) === 'string');
37-
assert(!isNaN(parseInt(getPointValue(results[2]), 10)));
38-
// Result of deleting metric
39-
assert.deepEqual(results[3], {});
40-
assert(console.log.calledWith('Created custom metric'));
41-
assert(console.log.calledWith('Wrote time series'));
42-
assert(console.log.calledWith('Reading metric type'));
43-
assert(console.log.calledWith('Time series'));
44-
assert(console.log.calledWith('Deleted metric'));
45-
done();
46-
}
47-
);
48-
});
25+
test.before(stubConsole);
26+
test.after(restoreConsole);
27+
28+
test.cb('should create and read back a custom metric', (t) => {
29+
customMetricsExample.main(
30+
process.env.GCLOUD_PROJECT,
31+
Math.random().toString(36).substring(7),
32+
(err, results) => {
33+
t.ifError(err);
34+
t.is(results.length, 4);
35+
// Result of creating metric
36+
t.is(typeof results[0].name, 'string');
37+
// Result of writing time series
38+
t.deepEqual(results[1], {});
39+
// Result of reading time series
40+
t.is(typeof getPointValue(results[2]), 'string');
41+
t.false(isNaN(parseInt(getPointValue(results[2]), 10)));
42+
// Result of deleting metric
43+
t.deepEqual(results[3], {});
44+
t.true(console.log.calledWith('Created custom metric'));
45+
t.true(console.log.calledWith('Wrote time series'));
46+
t.true(console.log.calledWith('Reading metric type'));
47+
t.true(console.log.calledWith('Time series'));
48+
t.true(console.log.calledWith('Deleted metric'));
49+
t.end();
50+
}
51+
);
4952
});

monitoring/snippets/system-test/list_resources.test.js

+20-20
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,26 @@
1313

1414
'use strict';
1515

16-
var listResourcesExample = require('../list_resources');
16+
require(`../../system-test/_setup`);
1717

18-
describe('monitoring:list_resources', function () {
19-
it('should list a bunch of stuff', function (done) {
20-
listResourcesExample.main(
21-
process.env.GCLOUD_PROJECT,
22-
function (err, results) {
23-
assert.ifError(err);
24-
assert(results.length === 3);
25-
// Monitored resources
26-
assert(Array.isArray(results[0].resourceDescriptors));
27-
// Metric descriptors
28-
assert(Array.isArray(results[1].metricDescriptors));
29-
// Time series
30-
assert(Array.isArray(results[2].timeSeries));
31-
assert(console.log.calledWith('Monitored resources'));
32-
assert(console.log.calledWith('Metric descriptors'));
33-
assert(console.log.calledWith('Time series'));
34-
done();
35-
}
36-
);
18+
const listResourcesExample = require(`../list_resources`);
19+
20+
test.before(stubConsole);
21+
test.after(restoreConsole);
22+
23+
test.cb(`should list a bunch of stuff`, (t) => {
24+
listResourcesExample.main(process.env.GCLOUD_PROJECT, (err, results) => {
25+
t.ifError(err);
26+
t.is(results.length, 3);
27+
// Monitored resources
28+
t.true(Array.isArray(results[0].resourceDescriptors));
29+
// Metric descriptors
30+
t.true(Array.isArray(results[1].metricDescriptors));
31+
// Time series
32+
t.true(Array.isArray(results[2].timeSeries));
33+
t.true(console.log.calledWith('Monitored resources'));
34+
t.true(console.log.calledWith('Metric descriptors'));
35+
t.true(console.log.calledWith('Time series'));
36+
t.end();
3737
});
3838
});

monitoring/snippets/test/create_custom_metric.test.js

-18
This file was deleted.

monitoring/snippets/test/list_resources.test.js

-18
This file was deleted.

0 commit comments

Comments
 (0)