Skip to content
Permalink
Browse files

Support new nodejs12.x runtime

  • Loading branch information
KariHe committed Nov 22, 2019
1 parent 7e50529 commit 92a410e9726835d71ff2ce88ab3f3f7bd3c3f685
@@ -23,6 +23,7 @@ const functionTemplateFile = path.join('templates', 'function-template.ejs');
const validFunctionRuntimes = [
'aws-nodejs8.10',
'aws-nodejs10.x',
'aws-nodejs12.x',
];

const humanReadableFunctionRuntimes = `${validFunctionRuntimes
@@ -323,7 +324,7 @@ class mochaPlugin {
mocha.run((failures) => {
process.on('exit', () => {
myModule.runScripts('postTestCommands')
// exit with non-zero status if there were failures
// exit with non-zero status if there were failures
.then(() => process.exit(failures));
});
if (myModule.options.exit) {
@@ -0,0 +1,82 @@
'use strict';

const Serverless = require('serverless');
const { execSync } = require('child_process');
const path = require('path');
const fse = require('fs-extra');
const { expect } = require('chai');
const testUtils = require('./testUtils');

const serverless = new Serverless();
serverless.init();
const serverlessExec = path.join(serverless.config.serverlessPath, '..', 'bin', 'serverless');

describe('integration (node v12.x template)', () => {
before(() => {
// create temporary directory and copy test service there
process.env.MOCHA_PLUGIN_TEST_DIR = path.join(__dirname);
const tmpDir = testUtils.getTmpDirPath();
fse.mkdirsSync(tmpDir);
fse.copySync(path.join(process.env.MOCHA_PLUGIN_TEST_DIR, 'test-service-node12.x'), tmpDir);
process.chdir(tmpDir);
});

it('should contain test params in cli info', () => {
const test = execSync(`${serverlessExec}`);
const result = test.toString();
expect(result).to.have.string(
'create test ................... Create mocha tests for service / function',
);
expect(result).to.have.string(
'create function ............... Create a function into the service',
);
expect(result).to.have.string(
'invoke test ................... Invoke test(s)',
);
});

it('should create test for hello function', () => {
const test = execSync(`${serverlessExec} create test --function hello`);
const result = test.toString();
expect(result).to.have.string(
'serverless-mocha-plugin: created test/hello.js',
);
});

it('should create function goodbye', () => {
const test = execSync(`${serverlessExec} create function --function goodbye --handler goodbye/index.handler`);
const result = test.toString();
expect(result).to.have.string(
'serverless-mocha-plugin: created test/goodbye.js',
);
});

it('should run tests successfully', () => {
// change test files to use local proxy version of mocha plugin
testUtils.replaceTextInFile(
path.join(process.cwd(), 'test', 'hello.js'),
'require(\'serverless-mocha-plugin\')',
'require(\'../.serverless_plugins/serverless-mocha-plugin/index.js\')',
);
testUtils.replaceTextInFile(
path.join(process.cwd(), 'test', 'goodbye.js'),
'require(\'serverless-mocha-plugin\')',
'require(\'../.serverless_plugins/serverless-mocha-plugin/index.js\')',
);

const test = execSync(`${serverlessExec} invoke test`);
const result = test.toString();

expect(result).to.have.string(
'goodbye\n ✓ implement tests here',
);

expect(result).to.have.string(
'hello\n ✓ implement tests here',
);

expect(result).to.have.string(
'2 passing',
);
});
});
@@ -0,0 +1,6 @@
# package directories
node_modules
jspm_packages

# Serverless directories
.serverless
@@ -0,0 +1,4 @@
// Proxy
const path = require('path');
const mochaDir = path.join(process.env.MOCHA_PLUGIN_TEST_DIR, '../', 'index.js');
module.exports = require(mochaDir);
@@ -0,0 +1,16 @@
'use strict';

module.exports.hello = async (event, context) => {
const response = {
statusCode: 200,
body: JSON.stringify({
message: 'Go Serverless v1.0! Your function executed successfully!',
input: event,
}),
};

return response;

// Use this code if you don't use the http event with the LAMBDA-PROXY integration
// callback(null, { message: 'Go Serverless v1.0! Your function executed successfully!', event });
};
@@ -0,0 +1,89 @@
# Welcome to Serverless!
#
# This file is the main config file for your service.
# It's very minimal at this point and uses default values.
# You can always add more config options for more control.
# We've included some commented out config examples here.
# Just uncomment any of them to get that config option.
#
# For full config options, check the docs:
# docs.serverless.com
#
# Happy Coding!

service: mocha-test-suite

# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
# frameworkVersion: "=X.X.X"

provider:
name: aws
runtime: nodejs12.x

# you can overwrite defaults here
# stage: dev
# region: us-east-1

# you can add statements to the Lambda function's IAM Role here
# iamRoleStatements:
# - Effect: "Allow"
# Action:
# - "s3:ListBucket"
# Resource: { "Fn::Join" : ["", ["arn:aws:s3:::", { "Ref" : "ServerlessDeploymentBucket" } ] ] }
# - Effect: "Allow"
# Action:
# - "s3:PutObject"
# Resource:
# Fn::Join:
# - ""
# - - "arn:aws:s3:::"
# - "Ref" : "ServerlessDeploymentBucket"

# you can define service wide environment variables here
# environment:
# variable1: value1

# you can add packaging information here
#package:
# include:
# - include-me.js
# - include-me-dir/**
# exclude:
# - exclude-me.js
# - exclude-me-dir/**

functions:
hello:
handler: handler.hello

# The following are a few example events you can configure
# NOTE: Please make sure to change your handler code to work with those events
# Check the event documentation for details
# events:
# - http:
# path: users/create
# method: get
# - s3: ${env:BUCKET}
# - schedule: rate(10 minutes)
# - sns: greeter-topic
# - stream: arn:aws:dynamodb:region:XXXXXX:table/foo/stream/1970-01-01T00:00:00.000

# Define function environment variables here
# environment:
# variable2: value2

# you can add CloudFormation resource templates here
#resources:
# Resources:
# NewResource:
# Type: AWS::S3::Bucket
# Properties:
# BucketName: my-new-bucket
# Outputs:
# NewOutput:
# Description: "Description for the output"
# Value: "Some output value"

plugins:
- serverless-mocha-plugin

0 comments on commit 92a410e

Please sign in to comment.
You can’t perform that action at this time.