mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
* fix #1854 - added latest version of eslint-config-airbnb-base package * fix #1854 - added latest npm shrinkwrap scheme * fix #1854 - added latest npm coveralls package * fix #1854 - added latest npm eslint package * fix #1854 - added latest npm eslint-config-airbnb package * fix #1854 - added latest npm eslint-plugin-import package * fix #1854 - added latest npm eslint-plugin-jsx-a11y package * fix #1854 - added latest npm eslint-plugin-react package * fix #1854 - fixed estlint new-parens errors for integration test * fix #1854 - fixed estlint new-parens errors for yaml parsers tests * fix #1854 - fixed estlint max-len errors for util tests * fix #1854 - disabled no-extraneous-dependencies on eslintrc for NodeJS 4 incapability on this feature * fix #1854 - fixed eslint new-parens errors for Service tests * fix #1854 - fixed eslint new-parens errors for Serverless tests * fix #1854 - fixed eslint new-parens errors for plugin manager tests * fix #1854 - fixed eslint new-parens errors for plugin tracking tests * fix #1854 - fixed eslint new-parens errors for plugin package zipService lib * fix #1854 - fixed eslint new-parens errors for plugin package zipService tests * fix #1854 - fixed eslint trailing spaces errors for plugin package zipService lib * fix #1854 - fixed eslint new-parens errors for plugin package cleanup tests * fix #1854 - fixed eslint new-parens errors for plugin create tests * fix #1854 - fixed eslint dot same line expectation error on plugin aws logs index * fix #1854 - fixed eslint operator assignment error on plugin aws logs index * fix #1854 - fixed eslint dot location error on plugin aws invoke tests * fix #1854 - fixed eslint new-parens error on plugin aws invoke tests * fix #1854 - fixed eslint new-parens error on plugin aws deployFunction tests * fix #1854 - fixed eslint new-parens error on plugin aws deploy uploadDeploymentPackage tests * fix #1854 - fixed eslint new-parens error on plugin aws deploy updateStack tests * fix #1854 - fixed eslint new-parens error on plugin aws deploy createStack tests * fix #1854 - fixed eslint new-parens error on plugin aws deploy apiGateway lib deployment * fix #1854 - fixed eslint unary typeof whitespace req error on Serverless Service class * fix #1854 - fixed eslint unary typeof whitespace req error on Serverless Service class ( second fix ) * fix #1854 - fixed eslint no-lonely-if req error on Serverless Service class * fix #1854 - disabled react/require-extension on eslintrc because it's deprecated * fix #1854 - AwsCompileApigEvents #constructor() should resolve if no functions are given: Error: Resolution method is overspecified. Specify a callback *or* return a Promise; not both. * fix #1854 - createStack #postCreate() should resolve: Error: Resolution method is overspecified. Specify a callback *or* return a Promise; not both. * fix #1854 - emptyS3Bucket #deleteObjects() should resolve if objectsInBucket is empty: Error: Resolution method is overspecified. Specify a callback *or* return a Promise; not both. * fix #1854 - AwsInvoke #extendedValidate() should resolve if path is not given: Error: Resolution method is overspecified. Specify a callback *or* return a Promise; not both. * fix #1854 - #cleanup() should resolve if the .serverless directory is not present: Error: Resolution method is overspecified. Specify a callback *or* return a Promise; not both. * fix #1854 -#validate() should resolve if servicePath is given: Error: Resolution method is overspecified. Specify a callback *or* return a Promise; not both. * fix #1854 - Service #load() should resolve if no servicePath is found: Error: Resolution method is overspecified. Specify a callback *or* return a Promise; not both. * fix #1854 - added latest mocha package * fix #1854 - added latest sinon npm package * fix #1854 - serverless/lib/plugins/aws/deploy/tests/createStack.js 136:48 error Missing semicolon semi * fix #1854 - serverless/lib/plugins/package/tests/cleanup.js 35:7 error Missing semicolon semi * fix #1854 - serverless/lib/plugins/package/tests/validate.js 22:49 error Missing semicolon semi * fix #1854 - added latest npm shrinkwrap * fix #1854 - fixed no-extra-boolean-cast eslint error on aws deploy apiGateway methods * fix #1854 - fixed new-parens eslint error on serverless tests for Service class
171 lines
6.0 KiB
JavaScript
171 lines
6.0 KiB
JavaScript
'use strict';
|
|
|
|
const expect = require('chai').expect;
|
|
const Serverless = require('../../lib/Serverless');
|
|
const semverRegex = require('semver-regex');
|
|
const fs = require('fs');
|
|
const fse = require('fs-extra');
|
|
const path = require('path');
|
|
const os = require('os');
|
|
|
|
const YamlParser = require('../../lib/classes/YamlParser');
|
|
const PluginManager = require('../../lib/classes/PluginManager');
|
|
const Utils = require('../../lib/classes/Utils');
|
|
const Service = require('../../lib/classes/Service');
|
|
const CLI = require('../../lib/classes/CLI');
|
|
const Error = require('../../lib/classes/Error').SError;
|
|
|
|
describe('Serverless', () => {
|
|
let serverless;
|
|
|
|
beforeEach(() => {
|
|
serverless = new Serverless();
|
|
});
|
|
|
|
describe('#constructor()', () => {
|
|
it('should set the correct config if a config object is passed', () => {
|
|
const configObj = { some: 'config' };
|
|
const serverlessWithConfig = new Serverless(configObj);
|
|
|
|
expect(serverlessWithConfig.config.some).to.equal('config');
|
|
});
|
|
|
|
it('should set an empty config object if no config object passed', () => {
|
|
// we're only expecting to have "serverless", "serverlessPath" and "servicePath"
|
|
expect(Object.keys(serverless.config).length).to.equal(3);
|
|
expect(Object.keys(serverless.config)).to.include('serverless');
|
|
expect(Object.keys(serverless.config)).to.include('serverlessPath');
|
|
expect(Object.keys(serverless.config)).to.include('servicePath');
|
|
});
|
|
|
|
it('should set the Serverless version', () => {
|
|
expect(serverless.version.length).to.be.at.least(1);
|
|
});
|
|
|
|
it('should set the YamlParser class instance', () => {
|
|
expect(serverless.yamlParser).to.be.instanceof(YamlParser);
|
|
});
|
|
|
|
it('should set the PluginManager class instance', () => {
|
|
expect(serverless.pluginManager).to.be.instanceof(PluginManager);
|
|
});
|
|
|
|
it('should set the Utils class instance', () => {
|
|
expect(serverless.utils).to.be.instanceof(Utils);
|
|
});
|
|
|
|
it('should set the Service class instance', () => {
|
|
expect(serverless.service).to.be.instanceof(Service);
|
|
});
|
|
|
|
it('should set the servicePath property if it was set in the config object', () => {
|
|
const configObj = { servicePath: 'some/path' };
|
|
const serverlessWithConfig = new Serverless(configObj);
|
|
|
|
expect(serverlessWithConfig.config.servicePath).to.equal('some/path');
|
|
});
|
|
|
|
// note: we only test if the property is there
|
|
// the test if the correct servicePath is set is done in the Utils class test file
|
|
it('should set the servicePath property if no config object is given', () => {
|
|
expect(serverless.config.servicePath).to.not.equal(undefined);
|
|
});
|
|
|
|
it('should have a config object', () => {
|
|
expect(serverless.config).to.not.equal(undefined);
|
|
});
|
|
|
|
it('should have a classes object', () => {
|
|
expect(serverless.classes).to.not.equal(undefined);
|
|
});
|
|
|
|
it('should store the CLI class inside the classes object', () => {
|
|
expect(serverless.classes.CLI).to.deep.equal(CLI);
|
|
});
|
|
|
|
it('should store the YamlParser class inside the classes object', () => {
|
|
expect(serverless.classes.YamlParser).to.deep.equal(YamlParser);
|
|
});
|
|
|
|
it('should store the PluginManager class inside the classes object', () => {
|
|
expect(serverless.classes.PluginManager).to.deep.equal(PluginManager);
|
|
});
|
|
|
|
it('should store the Utils class inside the classes object', () => {
|
|
expect(serverless.classes.Utils).to.deep.equal(Utils);
|
|
});
|
|
|
|
it('should store the Service class inside the classes object', () => {
|
|
expect(serverless.classes.Service).to.deep.equal(Service);
|
|
});
|
|
|
|
it('should store the Error class inside the classes object', () => {
|
|
expect(serverless.classes.Error).to.deep.equal(Error);
|
|
});
|
|
});
|
|
|
|
describe('#init()', () => {
|
|
it('should create a new CLI instance', () => {
|
|
serverless.init();
|
|
expect(serverless.cli).to.be.instanceOf(CLI);
|
|
});
|
|
|
|
// note: we just test that the processedInput variable is set (not the content of it)
|
|
// the test for the correct input is done in the CLI class test file
|
|
it('should receive the processed input form the CLI instance', () => {
|
|
serverless.init();
|
|
expect(serverless.processedInput).to.not.deep.equal({});
|
|
});
|
|
|
|
it('should resolve after loading the service', (done) => {
|
|
serverless.init().then(() => done());
|
|
});
|
|
});
|
|
|
|
describe('#run()', () => {
|
|
beforeEach(() => {
|
|
serverless.init();
|
|
serverless.processedInput = { commands: [], options: {} };
|
|
});
|
|
|
|
it('should track if tracking is enabled', (done) => {
|
|
const tmpDirPath = path.join(os.tmpdir(), (new Date()).getTime().toString());
|
|
fse.mkdirsSync(tmpDirPath);
|
|
|
|
serverless.config.serverlessPath = tmpDirPath;
|
|
|
|
serverless.run().then(() => done());
|
|
});
|
|
|
|
it('should not track if tracking is disabled', (done) => {
|
|
const tmpDirPath = path.join(os.tmpdir(), (new Date()).getTime().toString());
|
|
fse.mkdirsSync(tmpDirPath);
|
|
fs.writeFileSync(path.join(tmpDirPath, 'do-not-track'), 'some-content');
|
|
|
|
serverless.config.serverlessPath = tmpDirPath;
|
|
|
|
serverless.run().then(() => done());
|
|
});
|
|
|
|
it('should forward the entered command to the PluginManager class', () => {
|
|
serverless.processedInput.commands = ['someNotAvailableCommand'];
|
|
|
|
// we expect that an error is returned because the PluginManager will check if
|
|
// there's a plugin which will fail but our command is forwarded to the PluginManager
|
|
// and the PluginManager reports back that the command was not found (therefore the RegExp)
|
|
expect(() => serverless.run()).to.throw(Error, /someNotAvailableCommand/);
|
|
});
|
|
|
|
it('should resolve if help is displayed or no commands are entered', (done) => {
|
|
serverless.processedInput.commands = ['help'];
|
|
serverless.run().then(() => done());
|
|
});
|
|
});
|
|
|
|
describe('#getVersion()', () => {
|
|
it('should get the correct Serverless version', () => {
|
|
expect(semverRegex().test(serverless.getVersion())).to.equal(true);
|
|
});
|
|
});
|
|
});
|