Skip to content

Commit

Permalink
test: Refactor to use 'log' library instead of console.log
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Aug 26, 2020
1 parent 877d474 commit 5f85543
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 56 deletions.
4 changes: 0 additions & 4 deletions tests/.eslintrc.js
Expand Up @@ -4,10 +4,6 @@ module.exports = {
parserOptions: {
ecmaVersion: 2017,
},
rules: {
// console.info allowed to report on long going tasks or valuable debug information
'no-console': ['error', { allow: ['info'] }],
},
overrides: [
{
files: ['utils/**.js'],
Expand Down
14 changes: 7 additions & 7 deletions tests/integration-all/api-gateway/tests.js
Expand Up @@ -39,7 +39,7 @@ describe('AWS - API Gateway Integration Test', function() {

before(async () => {
tmpDirPath = getTmpDirPath();
console.info(`Temporary path: ${tmpDirPath}`);
log.notice(`Temporary path: ${tmpDirPath}`);
serverlessFilePath = path.join(tmpDirPath, 'serverless.yml');
const serverlessConfig = await createTestService(tmpDirPath, {
templateDir: path.join(__dirname, 'service'),
Expand All @@ -52,15 +52,15 @@ describe('AWS - API Gateway Integration Test', function() {
});
serviceName = serverlessConfig.service;
stackName = `${serviceName}-${stage}`;
console.info(`Deploying "${stackName}" service...`);
log.notice(`Deploying "${stackName}" service...`);
await deployService(tmpDirPath);
isDeployed = true;
return resolveEndpoint();
});

after(async () => {
if (!isDeployed) return;
console.info('Removing service...');
log.notice('Removing service...');
await removeService(tmpDirPath);
});

Expand Down Expand Up @@ -258,7 +258,7 @@ describe('AWS - API Gateway Integration Test', function() {
})
.then(resources => {
restApiRootResourceId = resources[0].id;
console.info(
log.notice(
'Created external rest API ' +
`(id: ${restApiId}, root resource id: ${restApiRootResourceId})`
);
Expand All @@ -283,7 +283,7 @@ describe('AWS - API Gateway Integration Test', function() {
},
});
writeYamlFile(serverlessFilePath, serverless);
console.info('Redeploying service (with external Rest API ID)...');
log.notice('Redeploying service (with external Rest API ID)...');
await deployService(tmpDirPath);
return resolveEndpoint();
});
Expand All @@ -295,9 +295,9 @@ describe('AWS - API Gateway Integration Test', function() {
delete serverless.provider.apiGateway.restApiRootResourceId;
writeYamlFile(serverlessFilePath, serverless);
// NOTE: deploying once again to get the stack into the original state
console.info('Redeploying service (without external Rest API ID)...');
log.notice('Redeploying service (without external Rest API ID)...');
await deployService(tmpDirPath);
console.info('Deleting external rest API...');
log.notice('Deleting external rest API...');
return deleteRestApi(restApiId);
});

Expand Down
11 changes: 6 additions & 5 deletions tests/integration-all/cognito-user-pool/tests.js
Expand Up @@ -3,6 +3,7 @@
const path = require('path');
const BbPromise = require('bluebird');
const { expect } = require('chai');
const log = require('log').get('serverless:test');
const hasFailed = require('@serverless/test/has-failed');

const { getTmpDirPath } = require('../../utils/fs');
Expand Down Expand Up @@ -32,7 +33,7 @@ describe('AWS - Cognito User Pool Integration Test', function() {

before(async () => {
tmpDirPath = getTmpDirPath();
console.info(`Temporary path: ${tmpDirPath}`);
log.notice(`Temporary path: ${tmpDirPath}`);
const serverlessConfig = await createTestService(tmpDirPath, {
templateDir: path.join(__dirname, 'service'),
filesToAdd: [path.join(__dirname, '..', 'shared')],
Expand All @@ -57,21 +58,21 @@ describe('AWS - Cognito User Pool Integration Test', function() {
EmailVerificationSubject: 'email{####}subject',
};
// NOTE: deployment can only be done once the Cognito User Pools are created
console.info('Creating Cognito User Pools');
log.notice('Creating Cognito User Pools');
await BbPromise.all([
createUserPool(poolExistingSimpleSetup, poolExistingSimpleSetupConfig),
createUserPool(poolExistingMultiSetup),
]);
console.info(`Deploying "${stackName}" service...`);
log.notice(`Deploying "${stackName}" service...`);
return deployService(tmpDirPath);
});

after(async function() {
// Do not clean on fail, to allow further state investigation
if (hasFailed(this.test.parent)) return null;
console.info('Removing service...');
log.notice('Removing service...');
await removeService(tmpDirPath);
console.info('Deleting Cognito User Pools');
log.notice('Deleting Cognito User Pools');
return BbPromise.all([
deleteUserPool(poolExistingSimpleSetup),
deleteUserPool(poolExistingMultiSetup),
Expand Down
13 changes: 7 additions & 6 deletions tests/integration-all/event-bridge/tests.js
Expand Up @@ -2,6 +2,7 @@

const path = require('path');
const { expect } = require('chai');
const log = require('log').get('serverless:test');

const { getTmpDirPath, readYamlFile, writeYamlFile } = require('../../utils/fs');
const { confirmCloudWatchLogs } = require('../../utils/misc');
Expand Down Expand Up @@ -35,7 +36,7 @@ describe('AWS - Event Bridge Integration Test', function() {

before(async () => {
tmpDirPath = getTmpDirPath();
console.info(`Temporary path: ${tmpDirPath}`);
log.notice(`Temporary path: ${tmpDirPath}`);

// get default event bus ARN
const defaultEventBusArn = (await describeEventBus('default')).Arn;
Expand All @@ -57,25 +58,25 @@ describe('AWS - Event Bridge Integration Test', function() {
stackName = `${serviceName}-${stage}`;
// create an external Event Bus
// NOTE: deployment can only be done once the Event Bus is created
console.info(`Creating Event Bus "${arnEventBusName}"...`);
log.notice(`Creating Event Bus "${arnEventBusName}"...`);
return createEventBus(arnEventBusName).then(data => {
arnEventBusArn = data.EventBusArn;
// update the YAML file with the arn
console.info(`Updating serverless.yml with Event Bus arn "${arnEventBusArn}"`);
log.notice(`Updating serverless.yml with Event Bus arn "${arnEventBusArn}"`);
const serverlessFilePath = path.join(tmpDirPath, 'serverless.yml');
const config = readYamlFile(serverlessFilePath);
config.functions.eventBusArn.events[0].eventBridge.eventBus = arnEventBusArn;
writeYamlFile(serverlessFilePath, config);
// deploy the service
console.info(`Deploying "${stackName}" service...`);
log.notice(`Deploying "${stackName}" service...`);
return deployService(tmpDirPath);
});
});

after(async () => {
console.info('Removing service...');
log.notice('Removing service...');
await removeService(tmpDirPath);
console.info(`Deleting Event Bus "${arnEventBusName}"...`);
log.notice(`Deleting Event Bus "${arnEventBusName}"...`);
return deleteEventBus(arnEventBusName);
});

Expand Down
13 changes: 7 additions & 6 deletions tests/integration-all/file-system-config/tests.js
Expand Up @@ -2,6 +2,7 @@

const path = require('path');
const { expect } = require('chai');
const log = require('log').get('serverless:test');

const awsRequest = require('@serverless/test/aws-request');
const fs = require('fs');
Expand All @@ -24,10 +25,10 @@ describe('AWS - FileSystemConfig Integration Test', function() {

before(async () => {
tmpDirPath = getTmpDirPath();
console.info(`Temporary path: ${tmpDirPath}`);
log.notice(`Temporary path: ${tmpDirPath}`);
const cfnTemplate = fs.readFileSync(path.join(__dirname, 'cloudformation.yml'), 'utf8');

console.info('Deploying CloudFormation stack with required resources...');
log.notice('Deploying CloudFormation stack with required resources...');
await awsRequest('CloudFormation', 'createStack', {
StackName: resourcesStackName,
TemplateBody: cfnTemplate,
Expand Down Expand Up @@ -58,15 +59,15 @@ describe('AWS - FileSystemConfig Integration Test', function() {
});
serviceName = serverlessConfig.service;
stackName = `${serviceName}-${stage}`;
console.info(`Deploying "${stackName}" service...`);
log.notice(`Deploying "${stackName}" service...`);
await deployService(tmpDirPath);
startTime = Date.now();
});

after(async () => {
console.info('Removing service...');
log.notice('Removing service...');
await removeService(tmpDirPath);
console.info('Removing CloudFormation stack with required resources...');
log.notice('Removing CloudFormation stack with required resources...');
await awsRequest('CloudFormation', 'deleteStack', { StackName: resourcesStackName });
return awsRequest('CloudFormation', 'waitFor', 'stackDeleteComplete', {
StackName: resourcesStackName,
Expand All @@ -86,7 +87,7 @@ describe('AWS - FileSystemConfig Integration Test', function() {
e.code === 'EFSMountFailureException' &&
Date.now() - startTime < EFS_MAX_PROPAGATION_TIME
) {
console.info('Failed to invoke, retry');
log.warn('Failed to invoke, retry');
return self();
}
throw e;
Expand Down
7 changes: 4 additions & 3 deletions tests/integration-all/iot/tests.js
Expand Up @@ -2,6 +2,7 @@

const path = require('path');
const { expect } = require('chai');
const log = require('log').get('serverless:test');

const { getTmpDirPath } = require('../../utils/fs');
const { publishIotData } = require('../../utils/iot');
Expand All @@ -23,7 +24,7 @@ describe('AWS - IoT Integration Test', function() {

before(async () => {
tmpDirPath = getTmpDirPath();
console.info(`Temporary path: ${tmpDirPath}`);
log.notice(`Temporary path: ${tmpDirPath}`);
const serverlessConfig = await createTestService(tmpDirPath, {
templateDir: path.join(__dirname, 'service'),
filesToAdd: [path.join(__dirname, '..', 'shared')],
Expand All @@ -36,13 +37,13 @@ describe('AWS - IoT Integration Test', function() {
});
serviceName = serverlessConfig.service;
stackName = `${serviceName}-${stage}`;
console.info(`Deploying "${stackName}" service...`);
log.notice(`Deploying "${stackName}" service...`);
return deployService(tmpDirPath);
});

after(() => {
// Topics are ephemeral and IoT endpoint is part of the account
console.info('Removing service...');
log.notice('Removing service...');
return removeService(tmpDirPath);
});

Expand Down
11 changes: 6 additions & 5 deletions tests/integration-all/s3/tests.js
Expand Up @@ -3,6 +3,7 @@
const path = require('path');
const BbPromise = require('bluebird');
const { expect } = require('chai');
const log = require('log').get('serverless:test');

const { getTmpDirPath } = require('../../utils/fs');
const { createBucket, createAndRemoveInBucket, deleteBucket } = require('../../utils/s3');
Expand All @@ -23,7 +24,7 @@ describe('AWS - S3 Integration Test', function() {

before(async () => {
tmpDirPath = getTmpDirPath();
console.info(`Temporary path: ${tmpDirPath}`);
log.notice(`Temporary path: ${tmpDirPath}`);
const serverlessConfig = await createTestService(tmpDirPath, {
templateDir: path.join(__dirname, 'service'),
filesToAdd: [path.join(__dirname, '..', 'shared')],
Expand All @@ -49,20 +50,20 @@ describe('AWS - S3 Integration Test', function() {
stackName = `${serviceName}-${stage}`;
// create external S3 buckets
// NOTE: deployment can only be done once the S3 buckets are created
console.info('Creating S3 buckets...');
log.notice('Creating S3 buckets...');
return BbPromise.all([
createBucket(bucketExistingSimpleSetup),
createBucket(bucketExistingComplexSetup),
]).then(() => {
console.info(`Deploying "${stackName}" service...`);
log.notice(`Deploying "${stackName}" service...`);
return deployService(tmpDirPath);
});
});

after(async () => {
console.info('Removing service...');
log.notice('Removing service...');
await removeService(tmpDirPath);
console.info('Deleting S3 buckets');
log.notice('Deleting S3 buckets');
return BbPromise.all([
deleteBucket(bucketExistingSimpleSetup),
deleteBucket(bucketExistingComplexSetup),
Expand Down
7 changes: 4 additions & 3 deletions tests/integration-all/schedule/tests.js
Expand Up @@ -2,6 +2,7 @@

const path = require('path');
const { expect } = require('chai');
const log = require('log').get('serverless:test');

const { getTmpDirPath } = require('../../utils/fs');
const {
Expand All @@ -21,19 +22,19 @@ describe('AWS - Schedule Integration Test', function() {

before(async () => {
tmpDirPath = getTmpDirPath();
console.info(`Temporary path: ${tmpDirPath}`);
log.notice(`Temporary path: ${tmpDirPath}`);
const serverlessConfig = await createTestService(tmpDirPath, {
templateDir: path.join(__dirname, 'service'),
filesToAdd: [path.join(__dirname, '..', 'shared')],
});
serviceName = serverlessConfig.service;
stackName = `${serviceName}-${stage}`;
console.info(`Deploying "${stackName}" service...`);
log.notice(`Deploying "${stackName}" service...`);
return deployService(tmpDirPath);
});

after(async () => {
console.info('Removing service...');
log.notice('Removing service...');
return removeService(tmpDirPath);
});

Expand Down
11 changes: 6 additions & 5 deletions tests/integration-all/sns/tests.js
Expand Up @@ -3,6 +3,7 @@
const path = require('path');
const BbPromise = require('bluebird');
const { expect } = require('chai');
const log = require('log').get('serverless:test');

const { getTmpDirPath } = require('../../utils/fs');
const { confirmCloudWatchLogs } = require('../../utils/misc');
Expand All @@ -21,7 +22,7 @@ describe('AWS - SNS Integration Test', function() {

before(async () => {
tmpDirPath = getTmpDirPath();
console.info(`Temporary path: ${tmpDirPath}`);
log.notice(`Temporary path: ${tmpDirPath}`);
const serverlessConfig = await createTestService(tmpDirPath, {
templateDir: path.join(__dirname, 'service'),
filesToAdd: [path.join(__dirname, '..', 'shared')],
Expand All @@ -45,17 +46,17 @@ describe('AWS - SNS Integration Test', function() {
stackName = `${serviceName}-${stage}`;
// create "existing" SNS topics
// NOTE: deployment can only be done once the SNS topics are created
console.info(`Creating SNS topic "${existingTopicName}"...`);
log.notice(`Creating SNS topic "${existingTopicName}"...`);
return createSnsTopic(existingTopicName).then(() => {
console.info(`Deploying "${stackName}" service...`);
log.notice(`Deploying "${stackName}" service...`);
return deployService(tmpDirPath);
});
});

after(async () => {
console.info('Removing service...');
log.notice('Removing service...');
await removeService(tmpDirPath);
console.info('Deleting SNS topics');
log.notice('Deleting SNS topics');
return removeSnsTopic(existingTopicName);
});

Expand Down
11 changes: 6 additions & 5 deletions tests/integration-all/sqs/tests.js
Expand Up @@ -3,6 +3,7 @@
const path = require('path');
const { expect } = require('chai');
const hasFailed = require('@serverless/test/has-failed');
const log = require('log').get('serverless:test');

const { getTmpDirPath } = require('../../utils/fs');
const { createSqsQueue, deleteSqsQueue, sendSqsMessage } = require('../../utils/sqs');
Expand All @@ -19,7 +20,7 @@ describe('AWS - SQS Integration Test', function() {

before(async () => {
tmpDirPath = getTmpDirPath();
console.info(`Temporary path: ${tmpDirPath}`);
log.notice(`Temporary path: ${tmpDirPath}`);
const serverlessConfig = await createTestService(tmpDirPath, {
templateDir: path.join(__dirname, 'service'),
filesToAdd: [path.join(__dirname, '..', 'shared')],
Expand All @@ -34,18 +35,18 @@ describe('AWS - SQS Integration Test', function() {
stackName = `${serviceName}-${stage}`;
// create existing SQS queue
// NOTE: deployment can only be done once the SQS queue is created
console.info(`Creating SQS queue "${queueName}"...`);
log.notice(`Creating SQS queue "${queueName}"...`);
return createSqsQueue(queueName).then(() => {
console.info(`Deploying "${stackName}" service...`);
log.notice(`Deploying "${stackName}" service...`);
return deployService(tmpDirPath);
});
});

after(async function() {
if (hasFailed(this.test.parent)) return null;
console.info('Removing service...');
log.notice('Removing service...');
await removeService(tmpDirPath);
console.info('Deleting SQS queue');
log.notice('Deleting SQS queue');
return deleteSqsQueue(queueName);
});

Expand Down

0 comments on commit 5f85543

Please sign in to comment.