Skip to content

Commit

Permalink
Switch from Mocha to Ava for faster tests (#289)
Browse files Browse the repository at this point in the history
* Switch from Mocha to Ava

* Concurrency: 5
  • Loading branch information
jmdobry authored and Ace Nassri committed Nov 21, 2022
1 parent ca2557b commit 1df87ca
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 159 deletions.
7 changes: 2 additions & 5 deletions compute/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
"license": "Apache Version 2.0",
"author": "Google Inc.",
"scripts": {
"test": "mocha -R spec -t 120000 --require intelli-espower-loader ../test/_setup.js test/*.test.js",
"system-test": "mocha -R spec -t 120000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js"
"test": "cd ..; npm run t -- computeengine/test/*.test.js",
"system-test": "cd ..; npm run t -- computeengine/system-test/*.test.js"
},
"dependencies": {
"@google-cloud/compute": "0.4.0",
"googleapis": "^12.2.0",
"nodemailer": "^2.4.1",
"nodemailer-smtp-transport": "^2.5.0",
"sendgrid": "^4.0.1"
},
"devDependencies": {
"mocha": "^3.0.2"
}
}
18 changes: 0 additions & 18 deletions compute/system-test/mailjet.test.js

This file was deleted.

18 changes: 0 additions & 18 deletions compute/system-test/sendgrid.test.js

This file was deleted.

21 changes: 12 additions & 9 deletions compute/system-test/vms.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@

'use strict';

var vmsExample = require('../vms');
require(`../../system-test/_setup`);

describe('computeengine:vms', function () {
it('should retrieve vms', function (done) {
vmsExample.main(function (err, result) {
assert.ifError(err);
assert(result);
assert(Array.isArray(result));
done();
});
const vmsExample = require(`../vms`);

test.beforeEach(stubConsole);
test.afterEach(restoreConsole);

test.cb(`should retrieve vms`, (t) => {
vmsExample.main((err, result) => {
t.ifError(err);
t.truthy(result);
t.true(Array.isArray(result));
t.end();
});
});
19 changes: 11 additions & 8 deletions compute/system-test/vms_api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@

'use strict';

var vmsExample = require('../vms_api');
require(`../../system-test/_setup`);

describe('computeengine:vms_api', function () {
it('should retrieve vms', function (done) {
vmsExample.main(function (err, result) {
assert.ifError(err);
assert(result);
done();
});
const vmsExample = require(`../vms_api`);

test.beforeEach(stubConsole);
test.afterEach(restoreConsole);

test.cb('should retrieve vms', (t) => {
vmsExample.main((err, result) => {
t.ifError(err);
t.truthy(result);
t.end();
});
});
69 changes: 36 additions & 33 deletions compute/test/mailjet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,44 @@

'use strict';

var proxyquire = require('proxyquire').noPreserveCache();
process.env.MAILJET_API_KEY = 'foo';
process.env.MAILJET_API_SECRET = 'bar';
require(`../../test/_setup`);

describe('computeengine:mailjet', function () {
it('should send an email', function (done) {
proxyquire('../mailjet', {
nodemailer: {
createTransport: function (arg) {
assert.equal(arg, 'test');
return {
sendMail: function (payload, cb) {
assert.deepEqual(payload, {
from: 'ANOTHER_EMAIL@ANOTHER_EXAMPLE.COM',
to: 'EMAIL@EXAMPLE.COM',
subject: 'test email from Node.js on Google Cloud Platform',
text: 'Hello!\n\nThis a test email from Node.js.'
});
cb('done');
done();
}
};
}
},
'nodemailer-smtp-transport': function (options) {
assert.deepEqual(options, {
host: 'in.mailjet.com',
port: 2525,
auth: {
user: 'foo',
pass: 'bar'
const proxyquire = require(`proxyquire`).noPreserveCache();
process.env.MAILJET_API_KEY = `foo`;
process.env.MAILJET_API_SECRET = `bar`;

test.beforeEach(stubConsole);
test.afterEach(restoreConsole);

test.cb(`should send an email`, (t) => {
proxyquire(`../mailjet`, {
nodemailer: {
createTransport: (arg) => {
t.is(arg, `test`);
return {
sendMail: (payload, cb) => {
t.deepEqual(payload, {
from: `ANOTHER_EMAIL@ANOTHER_EXAMPLE.COM`,
to: `EMAIL@EXAMPLE.COM`,
subject: `test email from Node.js on Google Cloud Platform`,
text: `Hello!\n\nThis a test email from Node.js.`
});
cb(`done`);
t.end();
}
});
return 'test';
};
}
});
},
'nodemailer-smtp-transport': (options) => {
t.deepEqual(options, {
host: `in.mailjet.com`,
port: 2525,
auth: {
user: `foo`,
pass: `bar`
}
});
return `test`;
}
});
});
65 changes: 33 additions & 32 deletions compute/test/sendgrid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,39 @@

'use strict';

var proxyquire = require('proxyquire').noPreserveCache();
process.env.SENDGRID_API_KEY = 'foo';
require(`../../test/_setup`);

describe('computeengine:sendgrid', function () {
it('should send an email', function (done) {
proxyquire('../sendgrid', {
sendgrid: function (key) {
assert.equal(key, 'foo');
return {
emptyRequest: function (x) {
return x;
},
API: function (request, cb) {
assert.deepEqual(request, {
method: 'POST',
path: '/v3/mail/send',
body: {
personalizations: [{
to: [{ email: 'to_email@example.com' }],
subject: 'Sendgrid test email from Node.js on Google Cloud Platform'
}],
from: { email: 'from_email@example.com' },
content: [{
type: 'text/plain',
value: 'Hello!\n\nThis a Sendgrid test email from Node.js on Google Cloud Platform.'
}]
}
});
done();
}
};
}
});
const proxyquire = require(`proxyquire`).noPreserveCache();
process.env.SENDGRID_API_KEY = `foo`;

test.beforeEach(stubConsole);
test.afterEach(restoreConsole);

test.cb(`should send an email`, (t) => {
proxyquire(`../sendgrid`, {
sendgrid: (key) => {
t.is(key, `foo`);
return {
emptyRequest: (x) => x,
API: (request, cb) => {
t.deepEqual(request, {
method: `POST`,
path: `/v3/mail/send`,
body: {
personalizations: [{
to: [{ email: `to_email@example.com` }],
subject: `Sendgrid test email from Node.js on Google Cloud Platform`
}],
from: { email: `from_email@example.com` },
content: [{
type: `text/plain`,
value: `Hello!\n\nThis a Sendgrid test email from Node.js on Google Cloud Platform.`
}]
}
});
t.end();
}
};
}
});
});
18 changes: 0 additions & 18 deletions compute/test/vms.test.js

This file was deleted.

18 changes: 0 additions & 18 deletions compute/test/vms_api.test.js

This file was deleted.

0 comments on commit 1df87ca

Please sign in to comment.