diff --git a/.eslintrc.js b/.eslintrc.js index 60abf1402..4218e236c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -3,6 +3,7 @@ module.exports = { "extends": "airbnb", "plugins": [], "rules": { + "arrow-body-style": "off", "func-names": "off", "global-require": "off", // Interfers with optional and eventual circular references "import/no-extraneous-dependencies": ["error", {"devDependencies": ["**/*.test.js", "**/scripts/**", "**/tests/**"]}], diff --git a/.gitignore b/.gitignore index 79c552a12..d62ad120c 100755 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,7 @@ dist # Directory for instrumented libs generated by jscoverage/JSCover lib-cov -# Coverage directory used by tools like istanbul +# Coverage directory used by tools like nyc coverage /.nyc_output @@ -59,3 +59,6 @@ jest # DotNet obj/ [Oo]bj/ + +# Tests +!tests/**/*.zip diff --git a/.travis.yml b/.travis.yml index 0e7d73b41..75084c208 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,6 @@ matrix: node_js: "10.7" env: - INTEGRATION_TEST=true - - INTEGRATION_TEST_SUITE=simple - SLS_IGNORE_WARNING=* - secure: Ia2nYzOeYvTE6qOP7DBKX3BO7s/U7TXdsvB2nlc3kOPFi//IbTVD0/cLKCAE5XqTzrrliHINSVsFcJNSfjCwmDSRmgoIGrHj5CJkWpkI6FEPageo3mdqFQYEc8CZeAjsPBNaHe6Ewzg0Ev/sjTByLSJYVqokzDCF1QostSxx1Ss6SGt1zjxeP/Hp4yOJn52VAm9IHAKYn7Y62nMAFTaaTPUQHvW0mJj6m2Z8TWyPU+2Bx6mliO65gTPFGs+PdHGwHtmSF/4IcUO504x+HjDuwzW2itomLXZmIOFfGDcFYadKWzVMAfJzoRWOcVKF4jXdMoSCOviWpHGtK35E7K956MTXkroVoWCS7V0knQDovbRZj8c8td8mS4tdprUA+TzgZoHet2atWNtMuTh79rdmwoAO+IAWJegYj62Tdfy3ycESzY+KxSaV8kysG9sR3PRFoWjZerA7MhLZEzQMORXDGjJlgwLaZfYVqjlsGe5p5etFBUTd0WbFgSwOKLoA2U/fm7WzqItkjs3UWaHuvFVvwYixGxjEVmVczS6wa2cdGpHtVD9H7km4fPEzljHqQ26v0P5e8eylgqLF2IB6mL7UqGFrAtrMvAgN/M3gnq4dTs/wq1AJIOxEP7YW7kc0NAldk8vUz6t5GzCPNcuukxAku91Awnh0twxgUywatgJLZPY= - secure: Dgaa5XIsA5Vbw/CYQLUAuVVsDX26C8+f1XYGwsbNmFQKbKvM8iy9lGrHlfrT3jftJkJH6re8tP1RjyZjjzLe25KPk4Tps7grNteCyiIIEDsC2aHhiXHD6zNHsItpxYusaFfyQinFWnK4CAYKWb9ZNIwHIDUIB4vq807QGAhYsnoj1Lg/ajWvtEKBwYjEzDz9OjB91lw7lpCnHtmKKw5A+TNIVGpDDZ/jRBqETsPaePtiXC9UTHZQyM3gFoeVXiJw9KSU/gjIx9REihCaWWPbnuQSeIONGGlVWY9V4DTZIsJr9/uwDcbioeXDD3G1ezGtNPPRSNTtq08QlUtE4mEtKea/+ObpllKZCeZGn6AJhMn+uqMIP95FFlqBB55YzRcLZY+Igi/qm/9LJ9RinAhxRVXiwzeQ+BdVA6jshAAzr+7wklux6lZAa0xGw9pgTv7MI4RP2LJ/LMP1ppFsnv9n/qt93Ax1VEwEu3xHZe3VTYL9tbXOPTZutf6fKjUrW7wSSuy637queESjYnnPKSb1vZcPxjSFlyh+GJvxu/3PurF9aqfiBdiorIBre+pQS4lakLtoft5nsbA+4iYUwrXR58qUPVUqQ7a0A0hedOWlp6g9ixLa6nugUP5aobJzR71T8l/IjqpnY2EEd/iINEb0XfUiZtB5zHaqFWejBtmWwCI= @@ -44,8 +43,11 @@ script: - if [[ -z "$INTEGRATION_TEST" && -z "$DISABLE_TESTS" ]]; then npm test; fi - if [[ ! -z "$DISABLE_TESTS" && ! -z "$LINTING" && -z "$INTEGRATION_TEST" ]]; then npm run lint; fi - - if [[ ! -z "$INTEGRATION_TEST" && ! -z ${AWS_ACCESS_KEY_ID+x} && "$INTEGRATION_TEST_SUITE" - == "simple" ]]; then npm run simple-integration-test; fi + - if [[ ! -z "$INTEGRATION_TEST" ]]; then npm run integration-test-run-package; fi + - if [[ ! -z "$INTEGRATION_TEST" && ! -z ${AWS_ACCESS_KEY_ID+x} ]]; then npm run integration-test-run-basic; fi + - if [[ ! -z "$INTEGRATION_TEST" && ! -z ${AWS_ACCESS_KEY_ID+x} && "$TRAVIS_BRANCH" + == "master" && "$TRAVIS_PULL_REQUEST" == "false" ]]; then npm run integration-test-run-all; fi + - if [[ ! -z "$INTEGRATION_TEST" && ! -z ${AWS_ACCESS_KEY_ID+x} ]]; then npm run integration-test-cleanup; fi after_success: - cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage deploy: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index dacac1823..6f71d94c5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -65,7 +65,7 @@ If you add a new template or want to test a template after changing it you can r To run all integration tests run: ``` -./tests/templates/test_all_templates +./tests/templates/test-all-templates ``` To run only a specific integration test run: @@ -80,7 +80,7 @@ so for example: tests/templates/integration-test-template aws-java-maven mvn package ``` -If you add a new template make sure to add it to the `test_all_templates` file and configure the `docker-compose.yml` file for your template. +If you add a new template make sure to add it to the `test-all-templates` file and configure the `docker-compose.yml` file for your template. # Our Code of Conduct diff --git a/lib/Serverless.test.js b/lib/Serverless.test.js index a1c42707c..14d33e321 100644 --- a/lib/Serverless.test.js +++ b/lib/Serverless.test.js @@ -13,8 +13,8 @@ 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 ServerlessError = require('../lib/classes/Error').ServerlessError; -const testUtils = require('../tests/utils'); +const { ServerlessError } = require('../lib/classes/Error'); +const { getTmpDirPath } = require('../tests/utils/fs'); describe('Serverless', () => { let serverless; @@ -157,7 +157,7 @@ describe('Serverless', () => { it('should resolve after loading the service', () => { const SUtils = new Utils(); - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); const serverlessYml = { service: 'new-service', provider: 'aws', diff --git a/lib/classes/CLI.test.js b/lib/classes/CLI.test.js index 06bc86e33..cf88a0d7e 100644 --- a/lib/classes/CLI.test.js +++ b/lib/classes/CLI.test.js @@ -9,7 +9,7 @@ const exec = require('child_process').exec; const path = require('path'); const stripAnsi = require('strip-ansi'); const Serverless = require('../../lib/Serverless'); -const testUtils = require('../../tests/utils'); +const { getTmpDirPath } = require('../../tests/utils/fs'); describe('CLI', () => { let cli; @@ -613,7 +613,7 @@ describe('CLI', () => { const that = this; before(() => { - const tmpDir = testUtils.getTmpDirPath(); + const tmpDir = getTmpDirPath(); that.cwd = process.cwd(); diff --git a/lib/classes/PluginManager.test.js b/lib/classes/PluginManager.test.js index b6e978d0a..53dbc1cc4 100644 --- a/lib/classes/PluginManager.test.js +++ b/lib/classes/PluginManager.test.js @@ -12,14 +12,15 @@ const _ = require('lodash'); const path = require('path'); const fs = require('fs'); const fse = require('fs-extra'); -const execSync = require('child_process').execSync; const mockRequire = require('mock-require'); -const testUtils = require('../../tests/utils'); const os = require('os'); const sinon = require('sinon'); const proxyquire = require('proxyquire'); const BbPromise = require('bluebird'); const getCacheFilePath = require('../utils/getCacheFilePath'); +const { execSync } = require('child_process'); +const { installPlugin } = require('../../tests/utils/plugins'); +const { getTmpDirPath } = require('../../tests/utils/fs'); chai.use(require('chai-as-promised')); chai.use(require('sinon-chai')); @@ -1879,7 +1880,7 @@ describe('PluginManager', () => { let serviceDir; let tmpDir; beforeEach(function () { // eslint-disable-line prefer-arrow-callback - tmpDir = testUtils.getTmpDirPath(); + tmpDir = getTmpDirPath(); serviceDir = path.join(tmpDir, 'service'); fse.mkdirsSync(serviceDir); process.chdir(serviceDir); @@ -1888,7 +1889,7 @@ describe('PluginManager', () => { it('should load plugins from .serverless_plugins', () => { const localPluginDir = path.join(serviceDir, '.serverless_plugins', 'local-plugin'); - testUtils.installPlugin(localPluginDir, SynchronousPluginMock); + installPlugin(localPluginDir, SynchronousPluginMock); pluginManager.loadServicePlugins(['local-plugin']); expect(pluginManager.plugins).to.satisfy(plugins => @@ -1897,7 +1898,7 @@ describe('PluginManager', () => { it('should load plugins from custom folder', () => { const localPluginDir = path.join(serviceDir, 'serverless-plugins-custom', 'local-plugin'); - testUtils.installPlugin(localPluginDir, SynchronousPluginMock); + installPlugin(localPluginDir, SynchronousPluginMock); pluginManager.loadServicePlugins({ localPath: path.join(serviceDir, 'serverless-plugins-custom'), @@ -1912,7 +1913,7 @@ describe('PluginManager', () => { it('should load plugins from custom folder outside of serviceDir', () => { serviceDir = path.join(tmpDir, 'serverless-plugins-custom'); const localPluginDir = path.join(serviceDir, 'local-plugin'); - testUtils.installPlugin(localPluginDir, SynchronousPluginMock); + installPlugin(localPluginDir, SynchronousPluginMock); pluginManager.loadServicePlugins({ localPath: serviceDir, @@ -1949,7 +1950,7 @@ describe('PluginManager', () => { const execPrefix = os.platform() === 'win32' ? 'node ' : ''; serverlessExec = execPrefix + path.join(serverlessInstance.config.serverlessPath, '..', 'bin', 'serverless'); - const tmpDir = testUtils.getTmpDirPath(); + const tmpDir = getTmpDirPath(); serviceDir = path.join(tmpDir, 'service'); fse.mkdirsSync(serviceDir); process.chdir(serviceDir); @@ -1968,8 +1969,8 @@ describe('PluginManager', () => { it('should load plugins relatively to the working directory', () => { const localPluginDir = path.join(serviceDir, 'node_modules', 'local-plugin'); const parentPluginDir = path.join(serviceDir, '..', 'node_modules', 'parent-plugin'); - testUtils.installPlugin(localPluginDir, SynchronousPluginMock); - testUtils.installPlugin(parentPluginDir, PromisePluginMock); + installPlugin(localPluginDir, SynchronousPluginMock); + installPlugin(parentPluginDir, PromisePluginMock); fs.appendFileSync(path.join(serviceDir, 'serverless.yml'), 'plugins:\n - local-plugin\n - parent-plugin'); diff --git a/lib/classes/Service.test.js b/lib/classes/Service.test.js index fd77a8eed..746fcb532 100644 --- a/lib/classes/Service.test.js +++ b/lib/classes/Service.test.js @@ -8,7 +8,7 @@ const sinon = require('sinon'); const Service = require('../../lib/classes/Service'); const Utils = require('../../lib/classes/Utils'); const Serverless = require('../../lib/Serverless'); -const testUtils = require('../../tests/utils'); +const { getTmpDirPath } = require('../../tests/utils/fs'); // Configure chai chai.use(require('chai-as-promised')); @@ -113,7 +113,7 @@ describe('Service', () => { let tmpDirPath; beforeEach(() => { - tmpDirPath = testUtils.getTmpDirPath(); + tmpDirPath = getTmpDirPath(); }); it('should resolve if no servicePath is found', () => { @@ -696,7 +696,7 @@ describe('Service', () => { let tmpDirPath; beforeEach(() => { - tmpDirPath = testUtils.getTmpDirPath(); + tmpDirPath = getTmpDirPath(); }); it('should throw if a function\'s event is not an array or a variable', () => { @@ -972,7 +972,7 @@ describe('Service', () => { let tmpDirPath; beforeEach(() => { - tmpDirPath = testUtils.getTmpDirPath(); + tmpDirPath = getTmpDirPath(); }); it('should make sure function name contains the default stage', () => { diff --git a/lib/classes/Utils.test.js b/lib/classes/Utils.test.js index aa0f2d49f..2ba1bb696 100644 --- a/lib/classes/Utils.test.js +++ b/lib/classes/Utils.test.js @@ -6,13 +6,14 @@ const uuid = require('uuid'); const chai = require('chai'); const sinon = require('sinon'); const Serverless = require('../../lib/Serverless'); -const testUtils = require('../../tests/utils'); const configUtils = require('../utils/config'); -const serverlessVersion = require('../../package.json').version; const segment = require('../utils/segment'); -chai.use(require('chai-as-promised')); -const expect = require('chai').expect; const Utils = require('../../lib/classes/Utils'); +const { expect } = require('chai'); +const { getTmpFilePath, getTmpDirPath } = require('../../tests/utils/fs'); +const serverlessVersion = require('../../package.json').version; + +chai.use(require('chai-as-promised')); describe('Utils', () => { let utils; @@ -53,7 +54,7 @@ describe('Utils', () => { describe('#writeFileDir()', () => { it('should create a directory for the path of the given file', () => { - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); const rootDir = serverless.utils .writeFileDir(path.join(tmpDirPath, 'foo', 'bar', 'somefile.js')); @@ -66,7 +67,7 @@ describe('Utils', () => { describe('#writeFileSync()', () => { it('should write a .json file synchronously', () => { - const tmpFilePath = testUtils.getTmpFilePath('anything.json'); + const tmpFilePath = getTmpFilePath('anything.json'); serverless.utils.writeFileSync(tmpFilePath, { foo: 'bar' }); const obj = serverless.utils.readFileSync(tmpFilePath); @@ -75,7 +76,7 @@ describe('Utils', () => { }); it('should write a .yml file synchronously', () => { - const tmpFilePath = testUtils.getTmpFilePath('anything.yml'); + const tmpFilePath = getTmpFilePath('anything.yml'); serverless.utils.writeFileSync(tmpFilePath, { foo: 'bar' }); @@ -85,7 +86,7 @@ describe('Utils', () => { }); it('should write a .yaml file synchronously', () => { - const tmpFilePath = testUtils.getTmpFilePath('anything.yaml'); + const tmpFilePath = getTmpFilePath('anything.yaml'); serverless.utils.writeFileSync(tmpFilePath, { foo: 'bar' }); @@ -101,7 +102,7 @@ describe('Utils', () => { describe('#writeFile()', () => { it('should write a file asynchronously', () => { - const tmpFilePath = testUtils.getTmpFilePath('anything.json'); + const tmpFilePath = getTmpFilePath('anything.json'); // note: use return when testing promises otherwise you'll have unhandled rejection errors return expect(serverless.utils.writeFile(tmpFilePath, { foo: 'bar' })) @@ -115,7 +116,7 @@ describe('Utils', () => { describe('#appendFileSync()', () => { it('should append a line to a text file', () => { - const tmpFilePath = testUtils.getTmpFilePath('appendedfile.txt'); + const tmpFilePath = getTmpFilePath('appendedfile.txt'); serverless.utils.writeFileSync(tmpFilePath, `line 1 ${os.EOL}`); serverless.utils.appendFileSync(tmpFilePath, 'line 2'); @@ -131,7 +132,7 @@ describe('Utils', () => { describe('#readFileSync()', () => { it('should read a file synchronously', () => { - const tmpFilePath = testUtils.getTmpFilePath('anything.json'); + const tmpFilePath = getTmpFilePath('anything.json'); serverless.utils.writeFileSync(tmpFilePath, { foo: 'bar' }); const obj = serverless.utils.readFileSync(tmpFilePath); @@ -140,7 +141,7 @@ describe('Utils', () => { }); it('should read a filename extension .yml', () => { - const tmpFilePath = testUtils.getTmpFilePath('anything.yml'); + const tmpFilePath = getTmpFilePath('anything.yml'); serverless.utils.writeFileSync(tmpFilePath, { foo: 'bar' }); const obj = serverless.utils.readFileSync(tmpFilePath); @@ -149,7 +150,7 @@ describe('Utils', () => { }); it('should read a filename extension .yaml', () => { - const tmpFilePath = testUtils.getTmpFilePath('anything.yaml'); + const tmpFilePath = getTmpFilePath('anything.yaml'); serverless.utils.writeFileSync(tmpFilePath, { foo: 'bar' }); const obj = serverless.utils.readFileSync(tmpFilePath); @@ -158,7 +159,7 @@ describe('Utils', () => { }); it('should throw YAMLException with filename if yml file is invalid format', () => { - const tmpFilePath = testUtils.getTmpFilePath('invalid.yml'); + const tmpFilePath = getTmpFilePath('invalid.yml'); serverless.utils.writeFileSync(tmpFilePath, ': a'); @@ -170,7 +171,7 @@ describe('Utils', () => { describe('#readFile()', () => { it('should read a file asynchronously', () => { - const tmpFilePath = testUtils.getTmpFilePath('anything.json'); + const tmpFilePath = getTmpFilePath('anything.json'); serverless.utils.writeFileSync(tmpFilePath, { foo: 'bar' }); @@ -183,7 +184,7 @@ describe('Utils', () => { describe('#walkDirSync()', () => { it('should return an array with corresponding paths to the found files', () => { - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); const nestedDir1 = path.join(tmpDirPath, 'foo'); const nestedDir2 = path.join(tmpDirPath, 'foo', 'bar'); @@ -246,7 +247,7 @@ describe('Utils', () => { const testDir = process.cwd(); it('should detect if the CWD is a service directory when using Serverless .yaml files', () => { - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); const tmpFilePath = path.join(tmpDirPath, 'serverless.yaml'); serverless.utils.writeFileSync(tmpFilePath, 'foo'); @@ -258,7 +259,7 @@ describe('Utils', () => { }); it('should detect if the CWD is a service directory when using Serverless .yml files', () => { - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); const tmpFilePath = path.join(tmpDirPath, 'serverless.yml'); serverless.utils.writeFileSync(tmpFilePath, 'foo'); @@ -270,7 +271,7 @@ describe('Utils', () => { }); it('should detect if the CWD is a service directory when using Serverless .json files', () => { - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); const tmpFilePath = path.join(tmpDirPath, 'serverless.json'); serverless.utils.writeFileSync(tmpFilePath, 'foo'); @@ -282,7 +283,7 @@ describe('Utils', () => { }); it('should detect if the CWD is a service directory when using Serverless .js files', () => { - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); const tmpFilePath = path.join(tmpDirPath, 'serverless.js'); serverless.utils.writeFileSync(tmpFilePath, 'foo'); diff --git a/lib/classes/Variables.test.js b/lib/classes/Variables.test.js index 7da83663b..b655df29c 100644 --- a/lib/classes/Variables.test.js +++ b/lib/classes/Variables.test.js @@ -16,9 +16,9 @@ const AwsProvider = require('../plugins/aws/provider/awsProvider'); const fse = require('../utils/fs/fse'); const Serverless = require('../../lib/Serverless'); const slsError = require('./Error'); -const testUtils = require('../../tests/utils'); const Utils = require('../../lib/classes/Utils'); const Variables = require('../../lib/classes/Variables'); +const { getTmpDirPath } = require('../../tests/utils/fs'); BbPromise.longStackTraces(true); @@ -932,7 +932,7 @@ describe('Variables', () => { describe('file reading cases', () => { let tmpDirPath; beforeEach(() => { - tmpDirPath = testUtils.getTmpDirPath(); + tmpDirPath = getTmpDirPath(); fse.mkdirsSync(tmpDirPath); serverless.config.update({ servicePath: tmpDirPath }); }); @@ -1622,7 +1622,7 @@ module.exports = { it('should populate an entire variable file', () => { const SUtils = new Utils(); - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); const configYml = { test: 1, test2: 'test2', @@ -1638,7 +1638,7 @@ module.exports = { }); it('should get undefined if non existing file and the second argument is true', () => { - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); serverless.config.update({ servicePath: tmpDirPath }); const realpathSync = sinon.spy(fse, 'realpathSync'); const existsSync = sinon.spy(fse, 'existsSync'); @@ -1656,7 +1656,7 @@ module.exports = { it('should populate non json/yml files', () => { const SUtils = new Utils(); - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); SUtils.writeFileSync(path.join(tmpDirPath, 'someFile'), 'hello world'); serverless.config.update({ servicePath: tmpDirPath }); return serverless.variables.getValueFromFile('file(./someFile)') @@ -1665,7 +1665,7 @@ module.exports = { it('should populate symlinks', () => { const SUtils = new Utils(); - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); const realFilePath = path.join(tmpDirPath, 'someFile'); const symlinkPath = path.join(tmpDirPath, 'refSomeFile'); SUtils.writeFileSync(realFilePath, 'hello world'); @@ -1681,7 +1681,7 @@ module.exports = { it('should trim trailing whitespace and new line character', () => { const SUtils = new Utils(); - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); SUtils.writeFileSync(path.join(tmpDirPath, 'someFile'), 'hello world \n'); serverless.config.update({ servicePath: tmpDirPath }); return serverless.variables.getValueFromFile('file(./someFile)') @@ -1690,7 +1690,7 @@ module.exports = { it('should populate from another file when variable is of any type', () => { const SUtils = new Utils(); - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); const configYml = { test0: 0, test1: 'test1', @@ -1707,7 +1707,7 @@ module.exports = { it('should populate from a javascript file', () => { const SUtils = new Utils(); - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); const jsData = 'module.exports.hello=function(){return "hello world";};'; SUtils.writeFileSync(path.join(tmpDirPath, 'hello.js'), jsData); serverless.config.update({ servicePath: tmpDirPath }); @@ -1717,7 +1717,7 @@ module.exports = { it('should populate an entire variable exported by a javascript file', () => { const SUtils = new Utils(); - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); const jsData = 'module.exports=function(){return { hello: "hello world" };};'; SUtils.writeFileSync(path.join(tmpDirPath, 'hello.js'), jsData); serverless.config.update({ servicePath: tmpDirPath }); @@ -1727,7 +1727,7 @@ module.exports = { it('should throw if property exported by a javascript file is not a function', () => { const SUtils = new Utils(); - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); const jsData = 'module.exports={ hello: "hello world" };'; SUtils.writeFileSync(path.join(tmpDirPath, 'hello.js'), jsData); serverless.config.update({ servicePath: tmpDirPath }); @@ -1737,7 +1737,7 @@ module.exports = { it('should populate deep object from a javascript file', () => { const SUtils = new Utils(); - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); const jsData = `module.exports.hello=function(){ return {one:{two:{three: 'hello world'}}} };`; @@ -1750,7 +1750,7 @@ module.exports = { it('should preserve the exported function context when executing', () => { const SUtils = new Utils(); - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); const jsData = ` module.exports.one = {two: {three: 'hello world'}} module.exports.hello=function(){ return this; };`; @@ -1763,7 +1763,7 @@ module.exports = { it('should file variable not using ":" syntax', () => { const SUtils = new Utils(); - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); const configYml = { test: 1, test2: 'test2', diff --git a/lib/classes/YamlParser.test.js b/lib/classes/YamlParser.test.js index c64331f10..71742ae86 100644 --- a/lib/classes/YamlParser.test.js +++ b/lib/classes/YamlParser.test.js @@ -8,7 +8,7 @@ const chai = require('chai'); const YAML = require('js-yaml'); const path = require('path'); const Serverless = require('../../lib/Serverless'); -const testUtils = require('../../tests/utils'); +const { getTmpFilePath, getTmpDirPath } = require('../../tests/utils/fs'); // Configure chai chai.use(require('chai-as-promised')); @@ -19,7 +19,7 @@ const serverless = new Serverless(); describe('YamlParser', () => { describe('#parse()', () => { it('should parse a simple .yaml file', () => { - const tmpFilePath = testUtils.getTmpFilePath('simple.yaml'); + const tmpFilePath = getTmpFilePath('simple.yaml'); serverless.utils.writeFileSync(tmpFilePath, YAML.dump({ foo: 'bar' })); @@ -28,7 +28,7 @@ describe('YamlParser', () => { }); it('should parse a simple .yml file', () => { - const tmpFilePath = testUtils.getTmpFilePath('simple.yml'); + const tmpFilePath = getTmpFilePath('simple.yml'); serverless.utils.writeFileSync(tmpFilePath, YAML.dump({ foo: 'bar' })); @@ -37,7 +37,7 @@ describe('YamlParser', () => { }); it('should parse a .yml file with JSON-REF to YAML', () => { - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); serverless.utils.writeFileSync(path.join(tmpDirPath, 'ref.yml'), { foo: 'bar' }); @@ -54,7 +54,7 @@ describe('YamlParser', () => { }); it('should parse a .yml file with JSON-REF to JSON', () => { - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); serverless.utils.writeFileSync(path.join(tmpDirPath, 'ref.json'), { foo: 'bar' }); @@ -71,7 +71,7 @@ describe('YamlParser', () => { }); it('should parse a .yml file with recursive JSON-REF', () => { - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); serverless.utils.writeFileSync(path.join(tmpDirPath, 'three.yml'), { foo: 'bar' }); diff --git a/lib/plugins/aws/common/lib/artifacts.test.js b/lib/plugins/aws/common/lib/artifacts.test.js index b61f6fc00..b898d7907 100644 --- a/lib/plugins/aws/common/lib/artifacts.test.js +++ b/lib/plugins/aws/common/lib/artifacts.test.js @@ -5,12 +5,12 @@ const path = require('path'); const fse = require('fs-extra'); const AWSCommon = require('../index'); const Serverless = require('../../../../../lib/Serverless'); -const testUtils = require('../../../../../tests/utils'); +const { getTmpDirPath } = require('../../../../../tests/utils/fs'); describe('#moveArtifactsToPackage()', () => { let serverless; let awsCommon; - const moveBasePath = path.join(testUtils.getTmpDirPath(), 'move'); + const moveBasePath = path.join(getTmpDirPath(), 'move'); const moveServerlessPath = path.join(moveBasePath, '.serverless'); beforeEach(() => { @@ -99,7 +99,7 @@ describe('#moveArtifactsToPackage()', () => { describe('#moveArtifactsToTemp()', () => { let serverless; let awsCommon; - const moveBasePath = path.join(testUtils.getTmpDirPath(), 'move'); + const moveBasePath = path.join(getTmpDirPath(), 'move'); const moveServerlessPath = path.join(moveBasePath, '.serverless'); const moveTargetPath = path.join(moveBasePath, 'target'); diff --git a/lib/plugins/aws/common/lib/cleanupTempDir.test.js b/lib/plugins/aws/common/lib/cleanupTempDir.test.js index 5eb71126c..680f4ceba 100644 --- a/lib/plugins/aws/common/lib/cleanupTempDir.test.js +++ b/lib/plugins/aws/common/lib/cleanupTempDir.test.js @@ -4,7 +4,7 @@ const expect = require('chai').expect; const path = require('path'); const Package = require('../index'); const Serverless = require('../../../../../lib/Serverless'); -const testUtils = require('../../../../../tests/utils'); +const { getTmpDirPath } = require('../../../../../tests/utils/fs'); describe('#cleanupTempDir()', () => { let serverless; @@ -14,7 +14,7 @@ describe('#cleanupTempDir()', () => { serverless = new Serverless(); packageService = new Package(serverless); - serverless.config.servicePath = testUtils.getTmpDirPath(); + serverless.config.servicePath = getTmpDirPath(); }); it('should remove .serverless in the service directory', () => { diff --git a/lib/plugins/aws/configCredentials/awsConfigCredentials.test.js b/lib/plugins/aws/configCredentials/awsConfigCredentials.test.js index 025295f1b..ec282dc08 100644 --- a/lib/plugins/aws/configCredentials/awsConfigCredentials.test.js +++ b/lib/plugins/aws/configCredentials/awsConfigCredentials.test.js @@ -7,9 +7,9 @@ const fs = require('fs'); const fse = require('fs-extra'); const os = require('os'); const path = require('path'); -const testUtils = require('../../../../tests/utils'); const AwsConfigCredentials = require('./awsConfigCredentials'); const Serverless = require('../../../Serverless'); +const { getTmpDirPath } = require('../../../../tests/utils/fs'); describe('AwsConfigCredentials', () => { let awsConfigCredentials; @@ -22,7 +22,7 @@ describe('AwsConfigCredentials', () => { beforeEach(() => { sandbox = sinon.sandbox.create(); - tmpDirPath = testUtils.getTmpDirPath(); + tmpDirPath = getTmpDirPath(); credentialsFilePath = path.join(tmpDirPath, '.aws', 'credentials'); credentialsFileContent = '[my-profile]\n'; credentialsFileContent += 'aws_access_key_id = my-old-profile-key\n'; diff --git a/lib/plugins/aws/deploy/lib/createStack.test.js b/lib/plugins/aws/deploy/lib/createStack.test.js index 467061309..1f9d97262 100644 --- a/lib/plugins/aws/deploy/lib/createStack.test.js +++ b/lib/plugins/aws/deploy/lib/createStack.test.js @@ -6,12 +6,12 @@ const path = require('path'); const AwsProvider = require('../../provider/awsProvider'); const AwsDeploy = require('../index'); const Serverless = require('../../../../Serverless'); -const testUtils = require('../../../../../tests/utils'); +const { getTmpDirPath } = require('../../../../../tests/utils/fs'); describe('createStack', () => { let awsDeploy; let sandbox; - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); const serverlessYmlPath = path.join(tmpDirPath, 'serverless.yml'); const serverlessYml = { diff --git a/lib/plugins/aws/deploy/lib/extendedValidate.test.js b/lib/plugins/aws/deploy/lib/extendedValidate.test.js index 7cbabdc5f..c34160510 100644 --- a/lib/plugins/aws/deploy/lib/extendedValidate.test.js +++ b/lib/plugins/aws/deploy/lib/extendedValidate.test.js @@ -6,7 +6,7 @@ const path = require('path'); const AwsProvider = require('../../provider/awsProvider'); const AwsDeploy = require('../index'); const Serverless = require('../../../../Serverless'); -const testUtils = require('../../../../../tests/utils'); +const { getTmpDirPath } = require('../../../../../tests/utils/fs'); chai.use(require('sinon-chai')); @@ -14,7 +14,7 @@ const expect = chai.expect; describe('extendedValidate', () => { let awsDeploy; - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); const serverlessYmlPath = path.join(tmpDirPath, 'serverless.yml'); const serverlessYml = { diff --git a/lib/plugins/aws/deploy/lib/uploadArtifacts.test.js b/lib/plugins/aws/deploy/lib/uploadArtifacts.test.js index 532a8bac2..bdc72583c 100644 --- a/lib/plugins/aws/deploy/lib/uploadArtifacts.test.js +++ b/lib/plugins/aws/deploy/lib/uploadArtifacts.test.js @@ -11,7 +11,7 @@ const normalizeFiles = require('../../lib/normalizeFiles'); const AwsProvider = require('../../provider/awsProvider'); const AwsDeploy = require('../index'); const Serverless = require('../../../../Serverless'); -const testUtils = require('../../../../../tests/utils'); +const { getTmpDirPath } = require('../../../../../tests/utils/fs'); chai.use(require('chai-as-promised')); chai.use(require('sinon-chai')); @@ -171,7 +171,7 @@ describe('uploadArtifacts', () => { it('should upload the .zip file to the S3 bucket', () => { cryptoStub.createHash().update().digest.onCall(0).returns('local-hash-zip-file'); - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); const artifactFilePath = path.join(tmpDirPath, 'artifact.zip'); serverless.utils.writeFileSync(artifactFilePath, 'artifact.zip file content'); @@ -197,7 +197,7 @@ describe('uploadArtifacts', () => { it('should upload the .zip file to a bucket with SSE bucket policy', () => { cryptoStub.createHash().update().digest.onCall(0).returns('local-hash-zip-file'); - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); const artifactFilePath = path.join(tmpDirPath, 'artifact.zip'); serverless.utils.writeFileSync(artifactFilePath, 'artifact.zip file content'); awsDeploy.serverless.service.provider.deploymentBucketObject = { diff --git a/lib/plugins/aws/deployFunction/index.test.js b/lib/plugins/aws/deployFunction/index.test.js index 015e930b0..d456cc390 100644 --- a/lib/plugins/aws/deployFunction/index.test.js +++ b/lib/plugins/aws/deployFunction/index.test.js @@ -7,7 +7,7 @@ const fs = require('fs'); const proxyquire = require('proxyquire'); const AwsProvider = require('../provider/awsProvider'); const Serverless = require('../../../Serverless'); -const testUtils = require('../../../../tests/utils'); +const { getTmpDirPath } = require('../../../../tests/utils/fs'); chai.use(require('chai-as-promised')); chai.use(require('sinon-chai')); @@ -442,7 +442,7 @@ describe('AwsDeployFunction', () => { beforeEach(() => { // write a file to disc to simulate that the deployment artifact exists - awsDeployFunction.packagePath = testUtils.getTmpDirPath(); + awsDeployFunction.packagePath = getTmpDirPath(); artifactFilePath = path.join(awsDeployFunction.packagePath, 'first.zip'); serverless.utils.writeFileSync(artifactFilePath, 'first.zip file content'); updateFunctionCodeStub = sinon diff --git a/lib/plugins/aws/invoke/index.test.js b/lib/plugins/aws/invoke/index.test.js index 3e1211ef4..2716dca8e 100644 --- a/lib/plugins/aws/invoke/index.test.js +++ b/lib/plugins/aws/invoke/index.test.js @@ -6,7 +6,7 @@ const path = require('path'); const proxyquire = require('proxyquire'); const AwsProvider = require('../provider/awsProvider'); const Serverless = require('../../../Serverless'); -const testUtils = require('../../../../tests/utils'); +const { getTmpDirPath } = require('../../../../tests/utils/fs'); chai.use(require('chai-as-promised')); @@ -143,7 +143,7 @@ describe('AwsInvoke', () => { }); it('it should parse file if relative file path is provided', () => { - serverless.config.servicePath = testUtils.getTmpDirPath(); + serverless.config.servicePath = getTmpDirPath(); const data = { testProp: 'testValue', }; @@ -158,7 +158,7 @@ describe('AwsInvoke', () => { }); it('it should parse file if absolute file path is provided', () => { - serverless.config.servicePath = testUtils.getTmpDirPath(); + serverless.config.servicePath = getTmpDirPath(); const data = { testProp: 'testValue', }; @@ -173,7 +173,7 @@ describe('AwsInvoke', () => { }); it('it should parse a yaml file if file path is provided', () => { - serverless.config.servicePath = testUtils.getTmpDirPath(); + serverless.config.servicePath = getTmpDirPath(); const yamlContent = 'testProp: testValue'; serverless.utils.writeFileSync(path @@ -194,7 +194,7 @@ describe('AwsInvoke', () => { }); it('it should throw error if file path does not exist', () => { - serverless.config.servicePath = testUtils.getTmpDirPath(); + serverless.config.servicePath = getTmpDirPath(); awsInvoke.options.path = 'some/path'; return expect(awsInvoke.extendedValidate()) diff --git a/lib/plugins/aws/invokeLocal/index.test.js b/lib/plugins/aws/invokeLocal/index.test.js index 880f9a385..0dcca6430 100644 --- a/lib/plugins/aws/invokeLocal/index.test.js +++ b/lib/plugins/aws/invokeLocal/index.test.js @@ -12,7 +12,7 @@ const stripAnsi = require('strip-ansi'); const AwsProvider = require('../provider/awsProvider'); const Serverless = require('../../../Serverless'); const CLI = require('../../../classes/CLI'); -const testUtils = require('../../../../tests/utils'); +const { getTmpDirPath } = require('../../../../tests/utils/fs'); chai.use(require('chai-as-promised')); @@ -185,7 +185,7 @@ describe('AwsInvokeLocal', () => { }); it('it should parse file if relative file path is provided', () => { - serverless.config.servicePath = testUtils.getTmpDirPath(); + serverless.config.servicePath = getTmpDirPath(); const data = { testProp: 'testValue', }; @@ -200,7 +200,7 @@ describe('AwsInvokeLocal', () => { }); it('it should parse file if absolute file path is provided', () => { - serverless.config.servicePath = testUtils.getTmpDirPath(); + serverless.config.servicePath = getTmpDirPath(); const data = { event: { testProp: 'testValue', @@ -218,7 +218,7 @@ describe('AwsInvokeLocal', () => { }); it('it should parse a yaml file if file path is provided', () => { - serverless.config.servicePath = testUtils.getTmpDirPath(); + serverless.config.servicePath = getTmpDirPath(); const yamlContent = 'event: data'; serverless.utils.writeFileSync(path @@ -232,7 +232,7 @@ describe('AwsInvokeLocal', () => { }); it('it should require a js file if file path is provided', () => { - serverless.config.servicePath = testUtils.getTmpDirPath(); + serverless.config.servicePath = getTmpDirPath(); const jsContent = [ 'module.exports = {', ' headers: { "Content-Type" : "application/json" },', @@ -260,7 +260,7 @@ describe('AwsInvokeLocal', () => { }); it('it should reject error if file path does not exist', () => { - serverless.config.servicePath = testUtils.getTmpDirPath(); + serverless.config.servicePath = getTmpDirPath(); awsInvokeLocal.options.path = 'some/path'; return expect(awsInvokeLocal.extendedValidate()).to.be.rejected; diff --git a/lib/plugins/aws/lib/updateStack.test.js b/lib/plugins/aws/lib/updateStack.test.js index dbde9a841..1421a7355 100644 --- a/lib/plugins/aws/lib/updateStack.test.js +++ b/lib/plugins/aws/lib/updateStack.test.js @@ -5,12 +5,12 @@ const sinon = require('sinon'); const AwsProvider = require('../provider/awsProvider'); const AwsDeploy = require('../deploy'); const Serverless = require('../../../Serverless'); -const testUtils = require('../../../../tests/utils'); +const { getTmpDirPath } = require('../../../../tests/utils/fs'); describe('updateStack', () => { let serverless; let awsDeploy; - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); beforeEach(() => { const options = { diff --git a/lib/plugins/aws/package/compile/functions/index.test.js b/lib/plugins/aws/package/compile/functions/index.test.js index 51a8cc132..9d67915f5 100644 --- a/lib/plugins/aws/package/compile/functions/index.test.js +++ b/lib/plugins/aws/package/compile/functions/index.test.js @@ -5,8 +5,8 @@ const path = require('path'); const chai = require('chai'); const AwsProvider = require('../../../provider/awsProvider'); const AwsCompileFunctions = require('./index'); -const testUtils = require('../../../../../../tests/utils'); const Serverless = require('../../../../../Serverless'); +const { getTmpDirPath } = require('../../../../../../tests/utils/fs'); chai.use(require('chai-as-promised')); @@ -34,7 +34,7 @@ describe('AwsCompileFunctions', () => { const serviceArtifact = 'new-service.zip'; const individualArtifact = 'test.zip'; - awsCompileFunctions.packagePath = testUtils.getTmpDirPath(); + awsCompileFunctions.packagePath = getTmpDirPath(); // The contents of the test artifacts need to be predictable so the hashes stay the same serverless.utils.writeFileSync(path.join(awsCompileFunctions.packagePath, serviceArtifact), 'foobar'); diff --git a/lib/plugins/aws/package/compile/layers/index.test.js b/lib/plugins/aws/package/compile/layers/index.test.js index 22245035b..0687ce350 100644 --- a/lib/plugins/aws/package/compile/layers/index.test.js +++ b/lib/plugins/aws/package/compile/layers/index.test.js @@ -5,8 +5,8 @@ const path = require('path'); const chai = require('chai'); const AwsProvider = require('../../../provider/awsProvider'); const AwsCompileLayers = require('./index'); -const testUtils = require('../../../../../../tests/utils'); const Serverless = require('../../../../../Serverless'); +const { getTmpDirPath } = require('../../../../../../tests/utils/fs'); chai.use(require('chai-as-promised')); @@ -35,7 +35,7 @@ describe('AwsCompileLayers', () => { const serviceArtifact = 'new-service.zip'; const individualArtifact = 'test.zip'; - awsCompileLayers.packagePath = testUtils.getTmpDirPath(); + awsCompileLayers.packagePath = getTmpDirPath(); // The contents of the test artifacts need to be predictable so the hashes stay the same serverless.utils.writeFileSync(path.join(awsCompileLayers.packagePath, serviceArtifact), 'foobar'); diff --git a/lib/plugins/aws/package/lib/generateCoreTemplate.test.js b/lib/plugins/aws/package/lib/generateCoreTemplate.test.js index 177693e10..5d487b32d 100644 --- a/lib/plugins/aws/package/lib/generateCoreTemplate.test.js +++ b/lib/plugins/aws/package/lib/generateCoreTemplate.test.js @@ -7,8 +7,8 @@ const AwsProvider = require('../../provider/awsProvider'); const Serverless = require('../../../../Serverless'); const validate = require('../../lib/validate'); const generateCoreTemplate = require('./generateCoreTemplate'); -const testUtils = require('../../../../../tests/utils'); const expect = require('chai').expect; +const { getTmpDirPath } = require('../../../../../tests/utils/fs'); chai.use(require('chai-as-promised')); @@ -29,7 +29,7 @@ describe('#generateCoreTemplate()', () => { Object.assign(awsPlugin, generateCoreTemplate, validate); awsPlugin.serverless.cli = new serverless.classes.CLI(); - awsPlugin.serverless.config.servicePath = testUtils.getTmpDirPath(); + awsPlugin.serverless.config.servicePath = getTmpDirPath(); awsPlugin.serverless.service.provider.compiledCloudFormationTemplate = { Resources: {}, diff --git a/lib/plugins/aws/provider/awsProvider.test.js b/lib/plugins/aws/provider/awsProvider.test.js index 89d2c7ee0..f7b69e8aa 100644 --- a/lib/plugins/aws/provider/awsProvider.test.js +++ b/lib/plugins/aws/provider/awsProvider.test.js @@ -13,7 +13,8 @@ const path = require('path'); const AwsProvider = require('./awsProvider'); const Serverless = require('../../../Serverless'); -const testUtils = require('../../../../tests/utils'); +const { replaceEnv } = require('../../../../tests/utils/misc'); +const { getTmpFilePath } = require('../../../../tests/utils/fs'); chai.use(require('chai-as-promised')); chai.use(require('sinon-chai')); @@ -813,7 +814,7 @@ describe('AwsProvider', () => { let originalProviderProfile; let originalEnvironmentVariables; const relevantEnvironment = { - AWS_SHARED_CREDENTIALS_FILE: testUtils.getTmpFilePath('credentials'), + AWS_SHARED_CREDENTIALS_FILE: getTmpFilePath('credentials'), }; let BK_AWS_PROFILE; @@ -821,7 +822,7 @@ describe('AwsProvider', () => { BK_AWS_PROFILE = process.env.AWS_PROFILE; delete process.env.AWS_PROFILE; originalProviderProfile = serverless.service.provider.profile; - originalEnvironmentVariables = testUtils.replaceEnv(relevantEnvironment); + originalEnvironmentVariables = replaceEnv(relevantEnvironment); serverless.utils.writeFileSync( relevantEnvironment.AWS_SHARED_CREDENTIALS_FILE, '[default]\n' + @@ -838,7 +839,7 @@ describe('AwsProvider', () => { afterEach(() => { if (BK_AWS_PROFILE) process.env.AWS_PROFILE = BK_AWS_PROFILE; else delete process.env.AWS_PROFILE; - testUtils.replaceEnv(originalEnvironmentVariables); + replaceEnv(originalEnvironmentVariables); serverless.service.provider.profile = originalProviderProfile; }); @@ -899,7 +900,7 @@ describe('AwsProvider', () => { AWS_TESTSTAGE_ACCESS_KEY_ID: 'undefined', AWS_TESTSTAGE_SECRET_ACCESS_KEY: 'undefined', AWS_TESTSTAGE_SESSION_TOKEN: 'undefined', - AWS_SHARED_CREDENTIALS_FILE: testUtils.getTmpFilePath('credentials'), + AWS_SHARED_CREDENTIALS_FILE: getTmpFilePath('credentials'), AWS_PROFILE: 'undefined', AWS_TESTSTAGE_PROFILE: 'undefined', }; @@ -924,7 +925,7 @@ describe('AwsProvider', () => { beforeEach(() => { originalProviderCredentials = serverless.service.provider.credentials; originalProviderProfile = serverless.service.provider.profile; - originalEnvironmentVariables = testUtils.replaceEnv(relevantEnvironment); + originalEnvironmentVariables = replaceEnv(relevantEnvironment); // make temporary credentials file serverless.utils.writeFileSync( relevantEnvironment.AWS_SHARED_CREDENTIALS_FILE, @@ -945,7 +946,7 @@ describe('AwsProvider', () => { }); afterEach(() => { - testUtils.replaceEnv(originalEnvironmentVariables); + replaceEnv(originalEnvironmentVariables); serverless.service.provider.profile = originalProviderProfile; serverless.service.provider.credentials = originalProviderCredentials; }); diff --git a/lib/plugins/create/create.test.js b/lib/plugins/create/create.test.js index 76e5482aa..315974333 100644 --- a/lib/plugins/create/create.test.js +++ b/lib/plugins/create/create.test.js @@ -7,10 +7,10 @@ const fse = require('fs-extra'); const Create = require('./create'); const Serverless = require('../../Serverless'); const sinon = require('sinon'); -const testUtils = require('../../../tests/utils'); const walkDirSync = require('../../utils/fs/walkDirSync'); const download = require('../../utils/downloadTemplateFromRepo'); const userStats = require('../../utils/userStats'); +const { getTmpDirPath } = require('../../../tests/utils/fs'); describe('Create', () => { let create; @@ -51,7 +51,7 @@ describe('Create', () => { let cwd; beforeEach(() => { - tmpDir = testUtils.getTmpDirPath(); + tmpDir = getTmpDirPath(); fse.mkdirsSync(tmpDir); cwd = process.cwd(); }); diff --git a/lib/plugins/install/install.test.js b/lib/plugins/install/install.test.js index 6ae38ba95..be6763911 100644 --- a/lib/plugins/install/install.test.js +++ b/lib/plugins/install/install.test.js @@ -4,11 +4,11 @@ const expect = require('chai').expect; const Serverless = require('../../Serverless'); const Install = require('./install.js'); const sinon = require('sinon'); -const testUtils = require('../../../tests/utils'); const download = require('../../utils/downloadTemplateFromRepo'); const userStats = require('../../utils/userStats'); const fse = require('fs-extra'); const path = require('path'); +const { getTmpDirPath } = require('../../../tests/utils/fs'); describe('Install', () => { let install; @@ -19,7 +19,7 @@ describe('Install', () => { let servicePath; beforeEach(() => { - const tmpDir = testUtils.getTmpDirPath(); + const tmpDir = getTmpDirPath(); cwd = process.cwd(); fse.mkdirsSync(tmpDir); diff --git a/lib/plugins/package/lib/zipService.test.js b/lib/plugins/package/lib/zipService.test.js index 562663229..ef8fc194e 100644 --- a/lib/plugins/package/lib/zipService.test.js +++ b/lib/plugins/package/lib/zipService.test.js @@ -14,7 +14,7 @@ const childProcess = BbPromise.promisifyAll(require('child_process')); const sinon = require('sinon'); const Package = require('../package'); const Serverless = require('../../../Serverless'); -const testUtils = require('../../../../tests/utils'); +const { getTmpDirPath } = require('../../../../tests/utils/fs'); // Configure chai chai.use(require('chai-as-promised')); @@ -28,7 +28,7 @@ describe('zipService', () => { let params; beforeEach(() => { - tmpDirPath = testUtils.getTmpDirPath(); + tmpDirPath = getTmpDirPath(); serverless = new Serverless(); serverless.service.service = 'first-service'; serverless.config.servicePath = tmpDirPath; diff --git a/lib/plugins/plugin/install/install.test.js b/lib/plugins/plugin/install/install.test.js index 7e49c19ad..2999ded74 100644 --- a/lib/plugins/plugin/install/install.test.js +++ b/lib/plugins/plugin/install/install.test.js @@ -11,11 +11,12 @@ const fse = require('fs-extra'); const PluginInstall = require('./install'); const Serverless = require('../../../Serverless'); const CLI = require('../../../classes/CLI'); -const testUtils = require('../../../../tests/utils'); -const userStats = require('../../../utils/userStats'); -chai.use(require('chai-as-promised')); -const expect = require('chai').expect; const _ = require('lodash'); +const userStats = require('../../../utils/userStats'); +const { expect } = require('chai'); +const { getTmpDirPath } = require('../../../../tests/utils/fs'); + +chai.use(require('chai-as-promised')); describe('PluginInstall', () => { let pluginInstall; @@ -110,7 +111,7 @@ describe('PluginInstall', () => { let installPeerDependenciesStub; beforeEach(() => { - servicePath = testUtils.getTmpDirPath(); + servicePath = getTmpDirPath(); pluginInstall.serverless.config.servicePath = servicePath; fse.ensureDirSync(servicePath); serverlessYmlFilePath = path.join(servicePath, 'serverless.yml'); @@ -261,7 +262,7 @@ describe('PluginInstall', () => { beforeEach(() => { pluginInstall.options.pluginName = 'serverless-plugin-1'; pluginInstall.options.pluginVersion = 'latest'; - servicePath = testUtils.getTmpDirPath(); + servicePath = getTmpDirPath(); pluginInstall.serverless.config.servicePath = servicePath; fse.ensureDirSync(servicePath); packageJsonFilePath = path.join(servicePath, 'package.json'); @@ -327,7 +328,7 @@ describe('PluginInstall', () => { let serverlessYmlFilePath; beforeEach(() => { - servicePath = testUtils.getTmpDirPath(); + servicePath = getTmpDirPath(); pluginInstall.serverless.config.servicePath = servicePath; serverlessYmlFilePath = path.join(servicePath, 'serverless.yml'); }); @@ -507,7 +508,7 @@ describe('PluginInstall', () => { beforeEach(() => { pluginName = 'some-plugin'; pluginInstall.options.pluginName = pluginName; - servicePath = testUtils.getTmpDirPath(); + servicePath = getTmpDirPath(); fse.ensureDirSync(servicePath); pluginInstall.serverless.config.servicePath = servicePath; servicePackageJsonFilePath = path.join(servicePath, 'package.json'); diff --git a/lib/plugins/plugin/lib/utils.test.js b/lib/plugins/plugin/lib/utils.test.js index 018883a2f..75dd046b1 100644 --- a/lib/plugins/plugin/lib/utils.test.js +++ b/lib/plugins/plugin/lib/utils.test.js @@ -10,9 +10,10 @@ const chalk = require('chalk'); const PluginInstall = require('./../install/install'); const Serverless = require('../../../Serverless'); const CLI = require('../../../classes/CLI'); -const testUtils = require('../../../../tests/utils'); +const { expect } = require('chai'); +const { getTmpDirPath } = require('../../../../tests/utils/fs'); + chai.use(require('chai-as-promised')); -const expect = require('chai').expect; describe('PluginUtils', () => { let pluginUtils; @@ -66,7 +67,7 @@ describe('PluginUtils', () => { let servicePath; beforeEach(() => { - servicePath = testUtils.getTmpDirPath(); + servicePath = getTmpDirPath(); pluginUtils.serverless.config.servicePath = servicePath; }); diff --git a/lib/plugins/plugin/uninstall/uninstall.test.js b/lib/plugins/plugin/uninstall/uninstall.test.js index ab6b418c8..d7e272e94 100644 --- a/lib/plugins/plugin/uninstall/uninstall.test.js +++ b/lib/plugins/plugin/uninstall/uninstall.test.js @@ -10,10 +10,11 @@ const fse = require('fs-extra'); const PluginUninstall = require('./uninstall'); const Serverless = require('../../../Serverless'); const CLI = require('../../../classes/CLI'); -const testUtils = require('../../../../tests/utils'); const userStats = require('../../../utils/userStats'); +const { expect } = require('chai'); +const { getTmpDirPath } = require('../../../../tests/utils/fs'); + chai.use(require('chai-as-promised')); -const expect = require('chai').expect; describe('PluginUninstall', () => { let pluginUninstall; @@ -105,7 +106,7 @@ describe('PluginUninstall', () => { let uninstallPeerDependenciesStub; beforeEach(() => { - servicePath = testUtils.getTmpDirPath(); + servicePath = getTmpDirPath(); pluginUninstall.serverless.config.servicePath = servicePath; fse.ensureDirSync(servicePath); serverlessYmlFilePath = path.join(servicePath, 'serverless.yml'); @@ -203,7 +204,7 @@ describe('PluginUninstall', () => { beforeEach(() => { pluginUninstall.options.pluginName = 'serverless-plugin-1'; - servicePath = testUtils.getTmpDirPath(); + servicePath = getTmpDirPath(); pluginUninstall.serverless.config.servicePath = servicePath; fse.ensureDirSync(servicePath); packageJsonFilePath = path.join(servicePath, 'package.json'); @@ -249,7 +250,7 @@ describe('PluginUninstall', () => { let serverlessYmlFilePath; beforeEach(() => { - servicePath = testUtils.getTmpDirPath(); + servicePath = getTmpDirPath(); pluginUninstall.serverless.config.servicePath = servicePath; serverlessYmlFilePath = path.join(servicePath, 'serverless.yml'); }); @@ -477,7 +478,7 @@ describe('PluginUninstall', () => { beforeEach(() => { pluginName = 'some-plugin'; pluginUninstall.options.pluginName = pluginName; - servicePath = testUtils.getTmpDirPath(); + servicePath = getTmpDirPath(); pluginUninstall.serverless.config.servicePath = servicePath; pluginPath = path.join( servicePath, 'node_modules', pluginName); diff --git a/lib/utils/downloadTemplateFromRepo.test.js b/lib/utils/downloadTemplateFromRepo.test.js index dcafe3a39..8fad468f5 100644 --- a/lib/utils/downloadTemplateFromRepo.test.js +++ b/lib/utils/downloadTemplateFromRepo.test.js @@ -1,19 +1,19 @@ 'use strict'; -const expect = require('chai').expect; const sinon = require('sinon'); const BbPromise = require('bluebird'); -const testUtils = require('../../tests/utils'); const fse = require('fs-extra'); const path = require('path'); const proxyquire = require('proxyquire'); +const { expect } = require('chai'); +const { getTmpDirPath } = require('../../tests/utils/fs'); const writeFileSync = require('./fs/writeFileSync'); const readFileSync = require('./fs/readFileSync'); const remove = BbPromise.promisify(fse.remove); -const parseRepoURL = require('./downloadTemplateFromRepo').parseRepoURL; +const { parseRepoURL } = require('./downloadTemplateFromRepo'); describe('downloadTemplateFromRepo', () => { let downloadTemplateFromRepo; @@ -24,7 +24,7 @@ describe('downloadTemplateFromRepo', () => { let newServicePath; beforeEach(() => { - const tmpDir = testUtils.getTmpDirPath(); + const tmpDir = getTmpDirPath(); cwd = process.cwd(); fse.mkdirsSync(tmpDir); diff --git a/lib/utils/fs/readFile.test.js b/lib/utils/fs/readFile.test.js index 87625df4d..9809d808c 100644 --- a/lib/utils/fs/readFile.test.js +++ b/lib/utils/fs/readFile.test.js @@ -1,9 +1,9 @@ 'use strict'; -const testUtils = require('../../../tests/utils'); const chai = require('chai'); const writeFile = require('./writeFile'); const readFile = require('./readFile'); +const { getTmpFilePath } = require('../../../tests/utils/fs'); // Configure chai chai.use(require('chai-as-promised')); @@ -12,28 +12,28 @@ const expect = require('chai').expect; describe('#readFile()', () => { it('should read a file asynchronously', () => { - const tmpFilePath = testUtils.getTmpFilePath('anything.json'); + const tmpFilePath = getTmpFilePath('anything.json'); return writeFile(tmpFilePath, { foo: 'bar' }) .then(() => expect(readFile(tmpFilePath)).to.eventually.deep.equal({ foo: 'bar' })); }); it('should read a filename extension .yml', () => { - const tmpFilePath = testUtils.getTmpFilePath('anything.yml'); + const tmpFilePath = getTmpFilePath('anything.yml'); return writeFile(tmpFilePath, { foo: 'bar' }) .then(() => expect(readFile(tmpFilePath)).to.eventually.deep.equal({ foo: 'bar' })); }); it('should read a filename extension .yaml', () => { - const tmpFilePath = testUtils.getTmpFilePath('anything.yaml'); + const tmpFilePath = getTmpFilePath('anything.yaml'); return writeFile(tmpFilePath, { foo: 'bar' }) .then(() => expect(readFile(tmpFilePath)).to.eventually.deep.equal({ foo: 'bar' })); }); it('should throw YAMLException with filename if yml file is invalid format', () => { - const tmpFilePath = testUtils.getTmpFilePath('invalid.yml'); + const tmpFilePath = getTmpFilePath('invalid.yml'); return writeFile(tmpFilePath, ': a').then(() => readFile(tmpFilePath)) .catch(e => { expect(e.name).to.equal('YAMLException'); diff --git a/lib/utils/fs/readFileSync.test.js b/lib/utils/fs/readFileSync.test.js index 652432040..328d38028 100644 --- a/lib/utils/fs/readFileSync.test.js +++ b/lib/utils/fs/readFileSync.test.js @@ -1,13 +1,13 @@ 'use strict'; -const testUtils = require('../../../tests/utils'); const expect = require('chai').expect; const writeFileSync = require('./writeFileSync'); const readFileSync = require('./readFileSync'); +const { getTmpFilePath } = require('../../../tests/utils/fs'); describe('#readFileSync()', () => { it('should read a file synchronously', () => { - const tmpFilePath = testUtils.getTmpFilePath('anything.json'); + const tmpFilePath = getTmpFilePath('anything.json'); writeFileSync(tmpFilePath, { foo: 'bar' }); const obj = readFileSync(tmpFilePath); @@ -16,7 +16,7 @@ describe('#readFileSync()', () => { }); it('should read a filename extension .yml', () => { - const tmpFilePath = testUtils.getTmpFilePath('anything.yml'); + const tmpFilePath = getTmpFilePath('anything.yml'); writeFileSync(tmpFilePath, { foo: 'bar' }); const obj = readFileSync(tmpFilePath); @@ -25,7 +25,7 @@ describe('#readFileSync()', () => { }); it('should read a filename extension .yaml', () => { - const tmpFilePath = testUtils.getTmpFilePath('anything.yaml'); + const tmpFilePath = getTmpFilePath('anything.yaml'); writeFileSync(tmpFilePath, { foo: 'bar' }); const obj = readFileSync(tmpFilePath); @@ -34,7 +34,7 @@ describe('#readFileSync()', () => { }); it('should throw YAMLException with filename if yml file is invalid format', () => { - const tmpFilePath = testUtils.getTmpFilePath('invalid.yml'); + const tmpFilePath = getTmpFilePath('invalid.yml'); writeFileSync(tmpFilePath, ': a'); diff --git a/lib/utils/fs/walkDirSync.test.js b/lib/utils/fs/walkDirSync.test.js index 2ef3a2600..27f3466cd 100644 --- a/lib/utils/fs/walkDirSync.test.js +++ b/lib/utils/fs/walkDirSync.test.js @@ -2,14 +2,14 @@ const fs = require('fs'); const path = require('path'); -const expect = require('chai').expect; -const testUtils = require('../../../tests/utils'); const writeFileSync = require('./writeFileSync'); const walkDirSync = require('./walkDirSync'); +const { expect } = require('chai'); +const { getTmpDirPath } = require('../../../tests/utils/fs'); describe('#walkDirSync()', () => { it('should return an array with corresponding paths to the found files', () => { - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); const nestedDir1 = path.join(tmpDirPath, 'foo'); const nestedDir2 = path.join(tmpDirPath, 'foo', 'bar'); @@ -31,7 +31,7 @@ describe('#walkDirSync()', () => { }); it('should check noLinks option', () => { - const tmpDirPath = testUtils.getTmpDirPath(); + const tmpDirPath = getTmpDirPath(); const realFile = path.join(tmpDirPath, 'real'); writeFileSync(realFile, 'content'); diff --git a/lib/utils/fs/writeFile.test.js b/lib/utils/fs/writeFile.test.js index 966c928d4..01c4addda 100644 --- a/lib/utils/fs/writeFile.test.js +++ b/lib/utils/fs/writeFile.test.js @@ -1,11 +1,11 @@ 'use strict'; const fse = require('./fse'); -const testUtils = require('../../../tests/utils'); const Serverless = require('../../../lib/Serverless'); const chai = require('chai'); const writeFile = require('./writeFile'); const readFile = require('./readFile'); +const { getTmpFilePath } = require('../../../tests/utils/fs'); // Configure chai chai.use(require('chai-as-promised')); @@ -21,14 +21,14 @@ describe('#writeFile()', function () { }); it('should write a .json file asynchronously', () => { - const tmpFilePath = testUtils.getTmpFilePath('anything.json'); + const tmpFilePath = getTmpFilePath('anything.json'); return writeFile(tmpFilePath, { foo: 'bar' }) .then(() => expect(readFile(tmpFilePath)) .to.eventually.deep.equal({ foo: 'bar' })); }); it('should write a .yml file synchronously', () => { - const tmpFilePath = testUtils.getTmpFilePath('anything.yml'); + const tmpFilePath = getTmpFilePath('anything.yml'); return writeFile(tmpFilePath, { foo: 'bar' }) .then(() => expect(serverless.yamlParser.parse(tmpFilePath)) @@ -36,7 +36,7 @@ describe('#writeFile()', function () { }); it('should write a .yaml file synchronously', () => { - const tmpFilePath = testUtils.getTmpFilePath('anything.yaml'); + const tmpFilePath = getTmpFilePath('anything.yaml'); return writeFile(tmpFilePath, { foo: 'bar' }) .then(() => expect(serverless.yamlParser.parse(tmpFilePath)) @@ -44,7 +44,7 @@ describe('#writeFile()', function () { }); it('should be able to write an object with circular references', () => { - const tmpFilePath = testUtils.getTmpFilePath('anything.json'); + const tmpFilePath = getTmpFilePath('anything.json'); const bar = {}; bar.foo = bar; const expected = '{\n "foo": {\n "$ref": "$"\n }\n}'; diff --git a/lib/utils/fs/writeFileSync.test.js b/lib/utils/fs/writeFileSync.test.js index 87ec760a5..c43337fb8 100644 --- a/lib/utils/fs/writeFileSync.test.js +++ b/lib/utils/fs/writeFileSync.test.js @@ -1,11 +1,11 @@ 'use strict'; const fse = require('./fse'); -const testUtils = require('../../../tests/utils'); const Serverless = require('../../../lib/Serverless'); -const expect = require('chai').expect; const writeFileSync = require('./writeFileSync'); const readFileSync = require('./readFileSync'); +const { expect } = require('chai'); +const { getTmpFilePath } = require('../../../tests/utils/fs'); describe('#writeFileSync()', () => { let serverless; @@ -15,7 +15,7 @@ describe('#writeFileSync()', () => { }); it('should write a .json file synchronously', () => { - const tmpFilePath = testUtils.getTmpFilePath('anything.json'); + const tmpFilePath = getTmpFilePath('anything.json'); writeFileSync(tmpFilePath, { foo: 'bar' }); const obj = readFileSync(tmpFilePath); @@ -24,7 +24,7 @@ describe('#writeFileSync()', () => { }); it('should write a .yml file synchronously', () => { - const tmpFilePath = testUtils.getTmpFilePath('anything.yml'); + const tmpFilePath = getTmpFilePath('anything.yml'); writeFileSync(tmpFilePath, { foo: 'bar' }); @@ -34,7 +34,7 @@ describe('#writeFileSync()', () => { }); it('should write a .yaml file synchronously', () => { - const tmpFilePath = testUtils.getTmpFilePath('anything.yaml'); + const tmpFilePath = getTmpFilePath('anything.yaml'); writeFileSync(tmpFilePath, { foo: 'bar' }); @@ -48,7 +48,7 @@ describe('#writeFileSync()', () => { }); it('should be able to write an object with circular references', () => { - const tmpFilePath = testUtils.getTmpFilePath('anything.json'); + const tmpFilePath = getTmpFilePath('anything.json'); const bar = {}; bar.foo = bar; const expected = '{\n "foo": {\n "$ref": "$"\n }\n}'; diff --git a/lib/utils/getServerlessConfigFile.test.js b/lib/utils/getServerlessConfigFile.test.js index 33b9661fb..2c4dc1236 100644 --- a/lib/utils/getServerlessConfigFile.test.js +++ b/lib/utils/getServerlessConfigFile.test.js @@ -2,9 +2,9 @@ const path = require('path'); const chai = require('chai'); -const testUtils = require('../../tests/utils'); const writeFileSync = require('./fs/writeFileSync'); const serverlessConfigFileUtils = require('./getServerlessConfigFile'); +const { getTmpDirPath } = require('../../tests/utils/fs'); const getServerlessConfigFile = serverlessConfigFileUtils.getServerlessConfigFile; @@ -16,7 +16,7 @@ describe('#getServerlessConfigFile()', () => { let tmpDirPath; beforeEach(() => { - tmpDirPath = testUtils.getTmpDirPath(); + tmpDirPath = getTmpDirPath(); }); it('should return an empty string if no serverless file is found', () => { diff --git a/lib/utils/renameService.test.js b/lib/utils/renameService.test.js index d580a8cfc..c6e50fdbe 100644 --- a/lib/utils/renameService.test.js +++ b/lib/utils/renameService.test.js @@ -1,12 +1,12 @@ 'use strict'; -const expect = require('chai').expect; const Serverless = require('../Serverless'); -const testUtils = require('../../tests/utils'); const fse = require('fs-extra'); const path = require('path'); +const { expect } = require('chai'); +const { getTmpDirPath } = require('../../tests/utils/fs'); -const renameService = require('./renameService').renameService; +const { renameService } = require('./renameService'); describe('renameService', () => { let serverless; @@ -15,7 +15,7 @@ describe('renameService', () => { let servicePath; beforeEach(() => { - const tmpDir = testUtils.getTmpDirPath(); + const tmpDir = getTmpDirPath(); cwd = process.cwd(); fse.mkdirsSync(tmpDir); diff --git a/lib/utils/yamlAstParser.test.js b/lib/utils/yamlAstParser.test.js index 3dbbb2361..84e083390 100644 --- a/lib/utils/yamlAstParser.test.js +++ b/lib/utils/yamlAstParser.test.js @@ -2,12 +2,12 @@ const path = require('path'); const chai = require('chai'); -const testUtils = require('../../tests/utils'); const writeFileSync = require('./fs/writeFileSync'); const readFileSync = require('./fs/readFileSync'); const yamlAstParser = require('./yamlAstParser'); const _ = require('lodash'); const chaiAsPromised = require('chai-as-promised'); +const { getTmpDirPath } = require('../../tests/utils/fs'); chai.use(chaiAsPromised); const expect = require('chai').expect; @@ -16,7 +16,7 @@ describe('#yamlAstParser', () => { let tmpDirPath; beforeEach(() => { - tmpDirPath = testUtils.getTmpDirPath(); + tmpDirPath = getTmpDirPath(); }); describe('#addNewArrayItem()', () => { diff --git a/package-lock.json b/package-lock.json index 287ddc192..9b885bf9e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -274,21 +274,6 @@ "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.2.0.tgz", "integrity": "sha512-cBhpre4ma+U0T1oM5fXg7Dy1Jw7zzwv7lt/GoCpr+hDQJoYnKVPLL4dCvSEFMmQurOQvSrwT7SL/DAlhBI97RQ==", "dev": true - }, - "ansi-regex": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", - "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", - "dev": true - }, - "strip-ansi": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", - "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", - "dev": true, - "requires": { - "ansi-regex": "^4.1.0" - } } } }, @@ -522,11 +507,10 @@ } }, "@serverless/platform-sdk": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@serverless/platform-sdk/-/platform-sdk-1.0.0.tgz", - "integrity": "sha512-+MYfXA36tXERShJDbfMQcEJKt4eRHQBbUeAzrY7emzJ/RYViPTw49Z8iHvYXhsMIi0v0DOlGHma7xNtGaKNm6Q==", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@serverless/platform-sdk/-/platform-sdk-1.0.1.tgz", + "integrity": "sha512-x7DWlvAEOdwur7pYLPHkqsEJ4+1xgmOHjSqpv3krthqQoUuh1+IBexL+GhtYqpN1t3N//a4mXDREb2Vd5eqIhA==", "requires": { - "babel-polyfill": "^6.26.0", "body-parser": "^1.19.0", "chalk": "^2.4.1", "cors": "^2.8.4", @@ -538,6 +522,7 @@ "querystring": "^0.2.0", "ramda": "^0.25.0", "rc": "^1.2.8", + "regenerator-runtime": "^0.13.1", "source-map-support": "^0.5.12", "uuid": "^3.3.2", "write-file-atomic": "^2.4.2" @@ -1021,9 +1006,9 @@ "dev": true }, "aws-sdk": { - "version": "2.452.0", - "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.452.0.tgz", - "integrity": "sha512-l6J2NmUg12xpDKG9YdlPje5+Z+nNvqyWMA85ookzPqwx8RcD28D3vg4K1aGi27/oo/3NsngR3XfKUBPSqUpUMA==", + "version": "2.454.0", + "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.454.0.tgz", + "integrity": "sha512-1vB9DNIwh+mqKD2IZspYTQapCD6f5VnMT5V2VPlXJ1CNcUdFSU8FFyxKmYApNs+S3re1h3fhWDjpwTreS+XLRQ==", "requires": { "buffer": "4.9.1", "events": "1.1.1", @@ -1098,17 +1083,15 @@ "has-ansi": "^2.0.0", "strip-ansi": "^3.0.0", "supports-color": "^2.0.0" - }, - "dependencies": { - "strip-ansi": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", - "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", - "dev": true, - "requires": { - "ansi-regex": "^2.0.0" - } - } + } + }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "dev": true, + "requires": { + "ansi-regex": "^2.0.0" } }, "supports-color": { @@ -1173,23 +1156,6 @@ "@types/babel__traverse": "^7.0.6" } }, - "babel-polyfill": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/babel-polyfill/-/babel-polyfill-6.26.0.tgz", - "integrity": "sha1-N5k3q8Z9eJWXCtxiHyhM2WbPIVM=", - "requires": { - "babel-runtime": "^6.26.0", - "core-js": "^2.5.0", - "regenerator-runtime": "^0.10.5" - }, - "dependencies": { - "regenerator-runtime": { - "version": "0.10.5", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz", - "integrity": "sha1-M2w+/BIgrc7dosn6tntaeVWjNlg=" - } - } - }, "babel-preset-jest": { "version": "24.6.0", "resolved": "https://registry.npmjs.org/babel-preset-jest/-/babel-preset-jest-24.6.0.tgz", @@ -1200,22 +1166,6 @@ "babel-plugin-jest-hoist": "^24.6.0" } }, - "babel-runtime": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", - "integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=", - "requires": { - "core-js": "^2.4.0", - "regenerator-runtime": "^0.11.0" - }, - "dependencies": { - "regenerator-runtime": { - "version": "0.11.1", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz", - "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==" - } - } - }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", @@ -1865,9 +1815,9 @@ "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" }, "combined-stream": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.7.tgz", - "integrity": "sha512-brWl9y6vOB1xYPZcpZde3N9zDByXTosAeMDo4p1wzo6UMOX4vumB+TP1RZ76sfE6Md68Q0NJSrE/gbezd4Ul+w==", + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", "requires": { "delayed-stream": "~1.0.0" } @@ -1988,11 +1938,6 @@ "resolved": "https://registry.npmjs.org/copy-descriptor/-/copy-descriptor-0.1.1.tgz", "integrity": "sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=" }, - "core-js": { - "version": "2.6.8", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.8.tgz", - "integrity": "sha512-RWlREFU74TEkdXzyl1bka66O3kYp8jeTXrvJZDzVVMH8AiHUSOFpL1yfhQJ+wHocAm1m+4971W1PPzfLuCv1vg==" - }, "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", @@ -2653,17 +2598,6 @@ "has-ansi": "^2.0.0", "strip-ansi": "^3.0.0", "supports-color": "^2.0.0" - }, - "dependencies": { - "strip-ansi": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", - "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", - "dev": true, - "requires": { - "ansi-regex": "^2.0.0" - } - } } }, "debug": { @@ -2694,17 +2628,6 @@ "string-width": "^1.0.1", "strip-ansi": "^3.0.0", "through": "^2.3.6" - }, - "dependencies": { - "strip-ansi": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", - "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", - "dev": true, - "requires": { - "ansi-regex": "^2.0.0" - } - } } }, "ms": { @@ -2722,6 +2645,15 @@ "once": "^1.3.0" } }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "dev": true, + "requires": { + "ansi-regex": "^2.0.0" + } + }, "supports-color": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", @@ -3135,9 +3067,9 @@ } }, "express": { - "version": "4.17.0", - "resolved": "https://registry.npmjs.org/express/-/express-4.17.0.tgz", - "integrity": "sha512-1Z7/t3Z5ZnBG252gKUPyItc4xdeaA0X934ca2ewckAsVsw9EG71i++ZHZPYnus8g/s5Bty8IMpSVEuRkmwwPRQ==", + "version": "4.17.1", + "resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz", + "integrity": "sha512-mHJ9O79RqluphRrcw2X/GTh3k9tVv8YcoyY4Kkh4WDMUYKRZUq0h1o0w2rrrxBqM7VoeUVqgb27xlEMXTnYt4g==", "requires": { "accepts": "~1.3.7", "array-flatten": "1.1.1", @@ -3612,8 +3544,7 @@ "version": "2.1.1", "resolved": false, "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", - "dev": true, - "optional": true + "dev": true }, "aproba": { "version": "1.2.0", @@ -3637,15 +3568,13 @@ "version": "1.0.0", "resolved": false, "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true, - "optional": true + "dev": true }, "brace-expansion": { "version": "1.1.11", "resolved": false, "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -3662,22 +3591,19 @@ "version": "1.1.0", "resolved": false, "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", - "dev": true, - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", "resolved": false, "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true, - "optional": true + "dev": true }, "console-control-strings": { "version": "1.1.0", "resolved": false, "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=", - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -3808,8 +3734,7 @@ "version": "2.0.3", "resolved": false, "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", - "dev": true, - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -3823,7 +3748,6 @@ "resolved": false, "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", "dev": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -3840,7 +3764,6 @@ "resolved": false, "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -3849,15 +3772,13 @@ "version": "0.0.8", "resolved": false, "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", - "dev": true, - "optional": true + "dev": true }, "minipass": { "version": "2.3.5", "resolved": false, "integrity": "sha512-Gi1W4k059gyRbyVUZQ4mEqLm0YIUiGYfvxhF6SIlk3ui1WVxMTGfGdQ2SInh3PDrRTVvPKgULkpJtT4RH10+VA==", "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -3878,7 +3799,6 @@ "resolved": false, "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "dev": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -3967,8 +3887,7 @@ "version": "1.0.1", "resolved": false, "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=", - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -3982,7 +3901,6 @@ "resolved": false, "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -4078,8 +3996,7 @@ "version": "5.1.2", "resolved": false, "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", - "dev": true, - "optional": true + "dev": true }, "safer-buffer": { "version": "2.1.2", @@ -4121,7 +4038,6 @@ "resolved": false, "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -4143,7 +4059,6 @@ "resolved": false, "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", "dev": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -4192,15 +4107,13 @@ "version": "1.0.2", "resolved": false, "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true, - "optional": true + "dev": true }, "yallist": { "version": "3.0.3", "resolved": false, "integrity": "sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A==", - "dev": true, - "optional": true + "dev": true } } }, @@ -5230,6 +5143,30 @@ } } }, + "jest-circus": { + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/jest-circus/-/jest-circus-24.8.0.tgz", + "integrity": "sha512-2QASG3QuDdk0SMP2O73D8u3/lc/A/E2G7q23v5WhbUR+hCGzWZXwRMKif18f11dSLfL1wcrMbwE4IorvV0DRVw==", + "dev": true, + "requires": { + "@babel/traverse": "^7.1.0", + "@jest/environment": "^24.8.0", + "@jest/test-result": "^24.8.0", + "@jest/types": "^24.8.0", + "chalk": "^2.0.1", + "co": "^4.6.0", + "expect": "^24.8.0", + "is-generator-fn": "^2.0.0", + "jest-each": "^24.8.0", + "jest-matcher-utils": "^24.8.0", + "jest-message-util": "^24.8.0", + "jest-snapshot": "^24.8.0", + "jest-util": "^24.8.0", + "pretty-format": "^24.8.0", + "stack-utils": "^1.0.1", + "throat": "^4.0.0" + } + }, "jest-cli": { "version": "24.8.0", "resolved": "https://registry.npmjs.org/jest-cli/-/jest-cli-24.8.0.tgz", @@ -6750,9 +6687,9 @@ "integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==" }, "neo-async": { - "version": "2.6.0", - "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.0.tgz", - "integrity": "sha512-MFh0d/Wa7vkKO3Y3LlacqAEeHK0mckVqzDieUKTT+KGxi+zIpeVsFxymkIiRpbpDziHc290Xr9A1O4Om7otoRA==", + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.1.tgz", + "integrity": "sha512-iyam8fBuCUpWeKPGpaNMetEocMt364qkCsfL9JuhjXX6dRnguRVOfk2GZaDpPjcOKiiXCPINZC1GczQ7iTq3Zw==", "dev": true }, "nested-error-stacks": { @@ -8968,12 +8905,6 @@ "json-stable-stringify": "^1.0.1" } }, - "ansi-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", - "dev": true - }, "ansi-styles": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", @@ -8991,23 +8922,6 @@ "has-ansi": "^2.0.0", "strip-ansi": "^3.0.0", "supports-color": "^2.0.0" - }, - "dependencies": { - "ansi-regex": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", - "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", - "dev": true - }, - "strip-ansi": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", - "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", - "dev": true, - "requires": { - "ansi-regex": "^2.0.0" - } - } } }, "is-fullwidth-code-point": { @@ -9026,6 +8940,12 @@ "strip-ansi": "^4.0.0" }, "dependencies": { + "ansi-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", + "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", + "dev": true + }, "strip-ansi": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", @@ -9037,6 +8957,15 @@ } } }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "dev": true, + "requires": { + "ansi-regex": "^2.0.0" + } + }, "supports-color": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", @@ -9337,9 +9266,9 @@ "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=" }, "uglify-js": { - "version": "3.5.11", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.5.11.tgz", - "integrity": "sha512-izPJg8RsSyqxbdnqX36ExpbH3K7tDBsAU/VfNv89VkMFy3z39zFjunQGsSHOlGlyIfGLGprGeosgQno3bo2/Kg==", + "version": "3.5.12", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.5.12.tgz", + "integrity": "sha512-KeQesOpPiZNgVwJj8Ge3P4JYbQHUdZzpx6Fahy6eKAYRSV4zhVmLXoC+JtOeYxcHCHTve8RG1ZGdTvpeOUM26Q==", "dev": true, "optional": true, "requires": { diff --git a/package.json b/package.json index 48c093b88..13cfd03ac 100644 --- a/package.json +++ b/package.json @@ -57,10 +57,10 @@ "test": "nyc --reporter=lcov --reporter=html --reporter=text-summary npm run test-bare", "lint": "eslint . --cache", "docs": "node scripts/generate-readme.js", - "integration-test-cleanup": "node scripts/integration-test-cleanup.js", - "packaging-integration-test": "jest --maxWorkers=5 packaging-suite", - "simple-integration-test": "jest --maxWorkers=5 simple-suite", - "complex-integration-test": "jest --maxWorkers=5 integration", + "integration-test-run-package": "jest --maxWorkers=5 integration-package", + "integration-test-run-basic": "jest --maxWorkers=5 integration-basic", + "integration-test-run-all": "jest --maxWorkers=5 integration-all", + "integration-test-cleanup": "node tests/utils/aws-cleanup.js", "postinstall": "node ./scripts/postinstall.js" }, "mocha": { @@ -71,8 +71,9 @@ "testRegex": "(\\.|/)(tests)\\.js$", "testEnvironment": "node", "setupFilesAfterEnv": [ - "/tests/setupTests.js" - ] + "/tests/setup-tests.js" + ], + "testRunner": "jest-circus/runner" }, "devDependencies": { "chai": "^3.5.0", @@ -86,6 +87,7 @@ "eslint-plugin-import": "^1.13.0", "eslint-plugin-jsx-a11y": "^2.1.0", "eslint-plugin-react": "^6.1.1", + "jest-circus": "^24.8.0", "jest-cli": "^24.5.0", "markdown-link": "^0.1.1", "markdown-magic": "^0.1.25", diff --git a/scripts/integration-test-cleanup.js b/scripts/integration-test-cleanup.js deleted file mode 100644 index 35276c64f..000000000 --- a/scripts/integration-test-cleanup.js +++ /dev/null @@ -1,97 +0,0 @@ -'use strict'; - -const BbPromise = require('bluebird'); -const AWS = require('aws-sdk'); - -const CF = new AWS.CloudFormation({ region: 'us-east-1' }); -const S3 = new AWS.S3({ region: 'us-east-1' }); - -BbPromise.promisifyAll(CF, { suffix: 'Promised' }); -BbPromise.promisifyAll(S3, { suffix: 'Promised' }); - -const logger = console; - -const emptyS3Bucket = (bucket) => ( - S3.listObjectsPromised({ Bucket: bucket }) - .then(data => { - logger.log('Bucket', bucket, 'has', data.Contents.length, 'items'); - if (data.Contents.length) { - const keys = data.Contents.map(item => Object.assign({}, { Key: item.Key })); - return S3.deleteObjectsPromised({ - Bucket: bucket, - Delete: { - Objects: keys, - }, - }); - } - return BbPromise.resolve(); - }) -); - -const deleteS3Bucket = (bucket) => ( - emptyS3Bucket(bucket) - .then(() => { - logger.log('Bucket', bucket, 'is now empty, deleting ...'); - return S3.deleteBucketPromised({ Bucket: bucket }); - }) -); - -const cleanupS3Buckets = (token) => { - logger.log('Looking through buckets ...'); - - const params = {}; - - if (token) { - params.NextToken = token; - } - - return S3.listBucketsPromised() - .then(response => - response.Buckets.reduce((memo, bucket) => memo - .then(() => deleteS3Bucket(bucket.Name)), BbPromise.resolve()) - .then(() => { - if (response.NextToken) { - return cleanupS3Buckets(response.NextToken); - } - return BbPromise.resolve(); - }) - ); -}; - -const cleanupCFStacks = (token) => { - const params = { - StackStatusFilter: [ - 'CREATE_FAILED', - 'CREATE_COMPLETE', - 'ROLLBACK_FAILED', - 'ROLLBACK_COMPLETE', - 'DELETE_FAILED', - 'UPDATE_ROLLBACK_FAILED', - 'UPDATE_ROLLBACK_COMPLETE', - ], - }; - - if (token) { - params.NextToken = token; - } - - logger.log('Looking through stacks ...'); - return CF.listStacksPromised(params) - .then(response => - response.StackSummaries.reduce((memo, stack) => { - if (['DELETE_COMPLETE', 'DELETE_IN_PROGRESS'].indexOf(stack.StackStatus) === -1) { - logger.log('Deleting stack', stack.StackName); - return memo.then(() => CF.deleteStackPromised({ StackName: stack.StackName })); - } - return memo; - }, BbPromise.resolve()) - .then(() => { - if (response.NextToken) { - return cleanupCFStacks(response.NextToken); - } - return BbPromise.resolve(); - }) - ); -}; - -cleanupS3Buckets().then(cleanupCFStacks); diff --git a/tests/.eslintrc.js b/tests/.eslintrc.js new file mode 100644 index 000000000..162340ca5 --- /dev/null +++ b/tests/.eslintrc.js @@ -0,0 +1,5 @@ +module.exports = { + "parserOptions": { + "ecmaVersion": 2017, + } +}; diff --git a/tests/integration-all/api-gateway/service/core.js b/tests/integration-all/api-gateway/service/core.js new file mode 100644 index 000000000..326d614cb --- /dev/null +++ b/tests/integration-all/api-gateway/service/core.js @@ -0,0 +1,51 @@ +'use strict'; + +async function minimal(event) { + return { + statusCode: 200, + body: JSON.stringify({ + message: 'Hello from API Gateway! - (minimal)', + event, + }), + }; +} + +async function cors(event) { + return { + statusCode: 200, + headers: { + 'Access-Control-Allow-Origin': '*', + }, + body: JSON.stringify({ + message: 'Hello from API Gateway! - (cors)', + event, + }), + }; +} + +async function customAuthorizers(event) { + return ({ + statusCode: 200, + body: JSON.stringify({ + message: 'Hello from API Gateway! - (customAuthorizers)', + event, + }), + }); +} + +async function apiKeys(event) { + return { + statusCode: 200, + body: JSON.stringify({ + message: 'Hello from API Gateway! - (apiKeys)', + event, + }), + }; +} + +module.exports = { + minimal, + cors, + customAuthorizers, + apiKeys, +}; diff --git a/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/service/handler.js b/tests/integration-all/api-gateway/service/helper.js similarity index 63% rename from tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/service/handler.js rename to tests/integration-all/api-gateway/service/helper.js index d47160ae6..000efbc5c 100644 --- a/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/service/handler.js +++ b/tests/integration-all/api-gateway/service/helper.js @@ -1,6 +1,7 @@ 'use strict'; -const generatePolicy = (principalId, effect, resource) => { +// custom authorizer +function generatePolicy(principalId, effect, resource) { const authResponse = {}; authResponse.principalId = principalId; @@ -18,20 +19,18 @@ const generatePolicy = (principalId, effect, resource) => { } return authResponse; -}; +} -// protected function -module.exports.hello = (event, context, callback) => { - callback(null, { message: 'Successfully authorized!', event }); -}; - -// auth function -module.exports.auth = (event, context) => { +async function auth(event, context) { const token = event.authorizationToken.split(' '); if (token[0] === 'Bearer' && token[1] === 'ShouldBeAuthorized') { - context.succeed(generatePolicy('SomeRandomId', 'Allow', '*')); + return context.succeed(generatePolicy('SomeRandomId', 'Allow', '*')); } - context.fail('Unauthorized'); + return context.fail('Unauthorized'); +} + +module.exports = { + auth, }; diff --git a/tests/integration-all/api-gateway/service/serverless.yml b/tests/integration-all/api-gateway/service/serverless.yml new file mode 100644 index 000000000..75bdd3fd2 --- /dev/null +++ b/tests/integration-all/api-gateway/service/serverless.yml @@ -0,0 +1,62 @@ +service: aws-nodejs # NOTE: update this with your service name + +provider: + name: aws + runtime: nodejs10.x + versionFunctions: false + apiKeys: + - name: api-key-1 + value: 0p3ns3s4m3-0p3ns3s4m3-0p3ns3s4m3 + +functions: + # core functions + minimal: + handler: core.minimal + events: + - http: GET / + - http: + method: POST + path: minimal-1 + - http: + method: PUT + path: /minimal-2 + - http: + method: DELETE + path: /minimal-3/ + cors: + handler: core.cors + events: + - http: + method: GET + path: simple-cors + cors: true + - http: + method: GET + path: complex-cors + cors: + origin: '*' + headers: + - Content-Type + - X-Amz-Date + - Authorization + - X-Api-Key + - X-Amz-Security-Token + - X-Amz-User-Agent + allowCredentials: true + customAuthorizers: + handler: core.customAuthorizers + events: + - http: + path: custom-auth + method: GET + authorizer: authorizer + apiKeys: + handler: core.apiKeys + events: + - http: + path: api-keys + method: GET + private: true + # helper functions + authorizer: + handler: helper.auth diff --git a/tests/integration-all/api-gateway/tests.js b/tests/integration-all/api-gateway/tests.js new file mode 100644 index 000000000..bdd1d5578 --- /dev/null +++ b/tests/integration-all/api-gateway/tests.js @@ -0,0 +1,267 @@ +'use strict'; + +const path = require('path'); +const AWS = require('aws-sdk'); +const _ = require('lodash'); +const fetch = require('node-fetch'); +const { expect } = require('chai'); + +const { getTmpDirPath, readYamlFile, writeYamlFile } = require('../../utils/fs'); +const { region, createTestService, deployService, removeService } = require('../../utils/misc'); +const { createRestApi, deleteRestApi, getResources } = require('../../utils/api-gateway'); + +const CF = new AWS.CloudFormation({ region }); + +describe('AWS - API Gateway Integration Test', () => { + let serviceName; + let endpoint; + let StackName; + let tmpDirPath; + let serverlessFilePath; + let restApiId; + let restApiRootResourceId; + const stage = 'dev'; + + beforeAll(() => { + tmpDirPath = getTmpDirPath(); + serverlessFilePath = path.join(tmpDirPath, 'serverless.yml'); + serviceName = createTestService('aws-nodejs', tmpDirPath, path.join(__dirname, 'service')); + StackName = `${serviceName}-${stage}`; + deployService(); + // create an external REST API + const externalRestApiName = `${stage}-${serviceName}-ext-api`; + return createRestApi(externalRestApiName) + .then((restApiMeta) => { + restApiId = restApiMeta.id; + return getResources(restApiId); + }) + .then((resources) => { + restApiRootResourceId = resources[0].id; + }); + }); + + afterAll(() => { + // NOTE: deleting the references to the old, external REST API + const serverless = readYamlFile(serverlessFilePath); + delete serverless.provider.apiGateway.restApiId; + delete serverless.provider.apiGateway.restApiRootResourceId; + writeYamlFile(serverlessFilePath, serverless); + // NOTE: deploying once again to get the stack into the original state + deployService(); + removeService(); + return deleteRestApi(restApiId); + }); + + beforeEach(() => { + return CF.describeStacks({ StackName }).promise() + .then((result) => _.find(result.Stacks[0].Outputs, + { OutputKey: 'ServiceEndpoint' }).OutputValue) + .then((endpointOutput) => { + endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; + endpoint = `${endpoint}`; + }); + }); + + describe('Minimal Setup', () => { + const expectedMessage = 'Hello from API Gateway! - (minimal)'; + + it('should expose an accessible GET HTTP endpoint', () => { + const testEndpoint = `${endpoint}`; + + return fetch(testEndpoint, { method: 'GET' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal(expectedMessage)); + }); + + it('should expose an accessible POST HTTP endpoint', () => { + const testEndpoint = `${endpoint}/minimal-1`; + + return fetch(testEndpoint, { method: 'POST' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal(expectedMessage)); + }); + + it('should expose an accessible PUT HTTP endpoint', () => { + const testEndpoint = `${endpoint}/minimal-2`; + + return fetch(testEndpoint, { method: 'PUT' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal(expectedMessage)); + }); + + it('should expose an accessible DELETE HTTP endpoint', () => { + const testEndpoint = `${endpoint}/minimal-3`; + + return fetch(testEndpoint, { method: 'DELETE' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal(expectedMessage)); + }); + }); + + describe('CORS', () => { + it('should setup simple CORS support via cors: true config', () => { + const testEndpoint = `${endpoint}/simple-cors`; + + return fetch(testEndpoint, { method: 'OPTIONS' }) + .then((response) => { + const headers = response.headers; + const allowHeaders = [ + 'Content-Type', + 'X-Amz-Date', + 'Authorization', + 'X-Api-Key', + 'X-Amz-Security-Token', + 'X-Amz-User-Agent', + ].join(','); + expect(headers.get('access-control-allow-headers')).to.equal(allowHeaders); + expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); + expect(headers.get('access-control-allow-credentials')).to.equal('false'); + // TODO: for some reason this test fails for now... + // expect(headers.get('access-control-allow-origin')).to.equal('*'); + }); + }); + + it('should setup CORS support with complex object config', () => { + const testEndpoint = `${endpoint}/complex-cors`; + + return fetch(testEndpoint, { method: 'OPTIONS' }) + .then((response) => { + const headers = response.headers; + const allowHeaders = [ + 'Content-Type', + 'X-Amz-Date', + 'Authorization', + 'X-Api-Key', + 'X-Amz-Security-Token', + 'X-Amz-User-Agent', + ].join(','); + expect(headers.get('access-control-allow-headers')).to.equal(allowHeaders); + expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); + expect(headers.get('access-control-allow-credentials')).to.equal('true'); + expect(headers.get('access-control-allow-origin')).to.equal('*'); + }); + }); + }); + + describe('Custom Authorizers', () => { + let testEndpoint; + + beforeEach(() => { + testEndpoint = `${endpoint}/custom-auth`; + }); + + it('should reject requests without authorization', () => { + return fetch(testEndpoint) + .then((response) => { + expect(response.status).to.equal(401); + }); + }); + + it('should reject requests with wrong authorization', () => { + return fetch(testEndpoint, { headers: { Authorization: 'Bearer ShouldNotBeAuthorized' } }) + .then((response) => { + expect(response.status).to.equal(401); + }); + }); + + it('should authorize requests with correct authorization', () => { + return fetch(testEndpoint, { headers: { Authorization: 'Bearer ShouldBeAuthorized' } }) + .then(response => response.json()) + .then((json) => { + expect(json.message).to.equal('Hello from API Gateway! - (customAuthorizers)'); + expect(json.event.requestContext.authorizer.principalId).to.equal('SomeRandomId'); + expect(json.event.headers.Authorization).to.equal('Bearer ShouldBeAuthorized'); + }); + }); + }); + + describe('API Keys', () => { + let testEndpoint; + + beforeEach(() => { + testEndpoint = `${endpoint}/api-keys`; + }); + + it('should reject a request with an invalid API Key', () => { + return fetch(testEndpoint) + .then((response) => { + expect(response.status).to.equal(403); + }); + }); + + it('should succeed if correct API key is given', () => { + const apiKey = '0p3ns3s4m3-0p3ns3s4m3-0p3ns3s4m3'; + + return fetch(testEndpoint, { headers: { 'X-API-Key': apiKey } }) + .then(response => response.json()) + .then((json) => { + expect(json.message).to.equal('Hello from API Gateway! - (apiKeys)'); + }); + }); + }); + + describe('Using stage specific configuration', () => { + beforeAll(() => { + const serverless = readYamlFile(serverlessFilePath); + // enable Logs, Tags and Tracing + _.merge(serverless.provider, { + tags: { + foo: 'bar', + baz: 'qux', + }, + tracing: { + apiGateway: true, + }, + logs: { + restApi: true, + }, + }); + writeYamlFile(serverlessFilePath, serverless); + deployService(); + }); + + it('should update the stage without service interruptions', () => { + // re-using the endpoint from the "minimal" test case + const testEndpoint = `${endpoint}`; + + return fetch(testEndpoint, { method: 'GET' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway! - (minimal)')); + }); + }); + + // NOTE: this test should be at the very end because we're using an external REST API here + describe('when using an existing REST API with stage specific configuration', () => { + beforeAll(() => { + const serverless = readYamlFile(serverlessFilePath); + // enable Logs, Tags and Tracing + _.merge(serverless.provider, { + apiGateway: { + restApiId, + restApiRootResourceId, + }, + tags: { + foo: 'bar', + baz: 'qux', + }, + tracing: { + apiGateway: true, + }, + logs: { + restApi: true, + }, + }); + writeYamlFile(serverlessFilePath, serverless); + deployService(); + }); + + it('should update the stage without service interruptions', () => { + // re-using the endpoint from the "minimal" test case + const testEndpoint = `${endpoint}/minimal-1`; + + return fetch(testEndpoint, { method: 'POST' }) + .then(response => response.json()) + .then((json) => expect(json.message).to.equal('Hello from API Gateway! - (minimal)')); + }); + }); +}); diff --git a/tests/simple-suite/tests.js b/tests/integration-basic/tests.js similarity index 70% rename from tests/simple-suite/tests.js rename to tests/integration-basic/tests.js index 84713c8a4..e1eadf416 100644 --- a/tests/simple-suite/tests.js +++ b/tests/integration-basic/tests.js @@ -1,45 +1,55 @@ 'use strict'; -const fs = require('fs'); -const expect = require('chai').expect; const path = require('path'); +const fs = require('fs'); const fse = require('fs-extra'); const BbPromise = require('bluebird'); -const execSync = require('child_process').execSync; const AWS = require('aws-sdk'); -const testUtils = require('../utils/index'); +const { expect } = require('chai'); +const { execSync } = require('child_process'); +const { getTmpDirPath, replaceTextInFile } = require('../utils/fs'); +const { region, getServiceName } = require('../utils/misc'); const serverlessExec = path.join(__dirname, '..', '..', 'bin', 'serverless'); -const tmpDir = testUtils.getTmpDirPath(); -fse.mkdirsSync(tmpDir); -process.chdir(tmpDir); - -const templateName = 'aws-nodejs'; -const newServiceName = `service-${(new Date()).getTime().toString()}`; -const stackName = `${newServiceName}-dev`; - -const CF = new AWS.CloudFormation({ region: 'us-east-1' }); -BbPromise.promisifyAll(CF, { suffix: 'Promised' }); +const CF = new AWS.CloudFormation({ region }); describe('Service Lifecyle Integration Test', () => { + const templateName = 'aws-nodejs'; + const tmpDir = getTmpDirPath(); + let oldCwd; + let serviceName; + let StackName; + + beforeAll(() => { + oldCwd = process.cwd(); + serviceName = getServiceName(); + StackName = `${serviceName}-dev`; + fse.mkdirsSync(tmpDir); + process.chdir(tmpDir); + }); + + afterAll(() => { + process.chdir(oldCwd); + }); + it('should create service in tmp directory', () => { - execSync(`${serverlessExec} create --template ${templateName}`, { stdio: 'inherit' }); - testUtils.replaceTextInFile('serverless.yml', templateName, newServiceName); + execSync(`${serverlessExec} create --template ${templateName}`); + replaceTextInFile('serverless.yml', templateName, serviceName); expect(fs.existsSync(path.join(tmpDir, 'serverless.yml'))).to.be.equal(true); expect(fs.existsSync(path.join(tmpDir, 'handler.js'))).to.be.equal(true); }); it('should deploy service to aws', () => { - execSync(`${serverlessExec} deploy`, { stdio: 'inherit' }); + execSync(`${serverlessExec} deploy`); - return CF.describeStacksPromised({ StackName: stackName }) + return CF.describeStacks({ StackName }).promise() .then(d => expect(d.Stacks[0].StackStatus).to.be.equal('UPDATE_COMPLETE')); }); it('should invoke function from aws', () => { const invoked = execSync(`${serverlessExec} invoke --function hello --noGreeting true`); - const result = JSON.parse(new Buffer(invoked, 'base64').toString()); + const result = JSON.parse(Buffer.from(invoked, 'base64').toString()); // parse it once again because the body is stringified to be LAMBDA-PROXY ready const message = JSON.parse(result.body).message; expect(message).to.be.equal('Go Serverless v1.0! Your function executed successfully!'); @@ -56,12 +66,12 @@ describe('Service Lifecyle Integration Test', () => { `; fs.writeFileSync(path.join(tmpDir, 'handler.js'), newHandler); - execSync(`${serverlessExec} deploy`, { stdio: 'inherit' }); + execSync(`${serverlessExec} deploy`); }); it('should invoke updated function from aws', () => { const invoked = execSync(`${serverlessExec} invoke --function hello --noGreeting true`); - const result = JSON.parse(new Buffer(invoked, 'base64').toString()); + const result = JSON.parse(Buffer.from(invoked, 'base64').toString()); expect(result.message).to.be.equal('Service Update Succeeded'); }); @@ -79,16 +89,16 @@ describe('Service Lifecyle Integration Test', () => { execSync(`${serverlessExec} rollback -t ${timestamp}`); const invoked = execSync(`${serverlessExec} invoke --function hello --noGreeting true`); - const result = JSON.parse(new Buffer(invoked, 'base64').toString()); + const result = JSON.parse(Buffer.from(invoked, 'base64').toString()); // parse it once again because the body is stringified to be LAMBDA-PROXY ready const message = JSON.parse(result.body).message; expect(message).to.be.equal('Go Serverless v1.0! Your function executed successfully!'); }); it('should remove service from aws', () => { - execSync(`${serverlessExec} remove`, { stdio: 'inherit' }); + execSync(`${serverlessExec} remove`); - return CF.describeStacksPromised({ StackName: stackName }) + return CF.describeStacks({ StackName }).promise() .then(d => expect(d.Stacks[0].StackStatus).to.be.equal('DELETE_COMPLETE')) .catch(error => { if (error.message.indexOf('does not exist') > -1) return BbPromise.resolve(); diff --git a/tests/packaging-suite/artifact.zip b/tests/integration-package/artifact.zip similarity index 100% rename from tests/packaging-suite/artifact.zip rename to tests/integration-package/artifact.zip diff --git a/tests/packaging-suite/handler.js b/tests/integration-package/handler.js similarity index 100% rename from tests/packaging-suite/handler.js rename to tests/integration-package/handler.js diff --git a/tests/packaging-suite/individually.yml b/tests/integration-package/individually.yml similarity index 100% rename from tests/packaging-suite/individually.yml rename to tests/integration-package/individually.yml diff --git a/tests/packaging-suite/packaging.tests.js b/tests/integration-package/packaging.tests.js similarity index 90% rename from tests/packaging-suite/packaging.tests.js rename to tests/integration-package/packaging.tests.js index 93da7ee95..6203525dd 100644 --- a/tests/packaging-suite/packaging.tests.js +++ b/tests/integration-package/packaging.tests.js @@ -2,16 +2,15 @@ const fs = require('fs'); const path = require('path'); -const execSync = require('child_process').execSync; const fse = require('fs-extra'); -const testUtils = require('../utils/index'); - -const serverlessExec = path.join(__dirname, '..', '..', 'bin', 'serverless'); +const { execSync } = require('child_process'); +const { serverlessExec } = require('../utils/misc'); +const { getTmpDirPath, listZipFiles } = require('../utils/fs'); describe('Integration test - Packaging', () => { let cwd; beforeEach(() => { - cwd = testUtils.getTmpDirPath(); + cwd = getTmpDirPath(); fse.mkdirsSync(cwd); }); @@ -19,7 +18,7 @@ describe('Integration test - Packaging', () => { fse.copySync(path.join(__dirname, 'serverless.yml'), path.join(cwd, 'serverless.yml')); fse.copySync(path.join(__dirname, 'handler.js'), path.join(cwd, 'handler.js')); execSync(`${serverlessExec} package`, { cwd }); - return testUtils.listZipFiles(path.join(cwd, '.serverless/aws-nodejs.zip')) + return listZipFiles(path.join(cwd, '.serverless/aws-nodejs.zip')) .then(zipfiles => { expect(zipfiles).toEqual(['handler.js']); }); @@ -31,7 +30,7 @@ describe('Integration test - Packaging', () => { execSync('npm init --yes', { cwd }); execSync('npm i lodash', { cwd }); execSync(`${serverlessExec} package`, { cwd }); - return testUtils.listZipFiles(path.join(cwd, '.serverless/aws-nodejs.zip')) + return listZipFiles(path.join(cwd, '.serverless/aws-nodejs.zip')) .then(zipfiles => { const nodeModules = new Set( zipfiles.filter(f => f.startsWith('node_modules')).map(f => f.split(path.sep)[1])); @@ -47,7 +46,7 @@ describe('Integration test - Packaging', () => { execSync('npm init --yes', { cwd }); execSync('npm i --save-dev lodash', { cwd }); execSync(`${serverlessExec} package`, { cwd }); - return testUtils.listZipFiles(path.join(cwd, '.serverless/aws-nodejs.zip')) + return listZipFiles(path.join(cwd, '.serverless/aws-nodejs.zip')) .then(zipfiles => { const nodeModules = new Set( zipfiles.filter(f => f.startsWith('node_modules')).map(f => f.split(path.sep)[1])); @@ -64,7 +63,7 @@ describe('Integration test - Packaging', () => { execSync('echo \'package: {exclude: ["package*.json"]}\' >> serverless.yml', { cwd }); execSync('npm i lodash', { cwd }); execSync(`${serverlessExec} package`, { cwd }); - return testUtils.listZipFiles(path.join(cwd, '.serverless/aws-nodejs.zip')) + return listZipFiles(path.join(cwd, '.serverless/aws-nodejs.zip')) .then(zipfiles => { const nodeModules = new Set( zipfiles.filter(f => f.startsWith('node_modules')).map(f => f.split(path.sep)[1])); @@ -145,7 +144,7 @@ describe('Integration test - Packaging', () => { 'IamRoleLambdaExecution', ], }); - return testUtils.listZipFiles(path.join(cwd, '.serverless/aws-nodejs.zip')) + return listZipFiles(path.join(cwd, '.serverless/aws-nodejs.zip')) .then(zipfiles => { expect(zipfiles).toEqual(['handler.js']); }); @@ -188,9 +187,9 @@ describe('Integration test - Packaging', () => { 'IamRoleLambdaExecution', ], }); - return testUtils.listZipFiles(path.join(cwd, '.serverless/hello.zip')) + return listZipFiles(path.join(cwd, '.serverless/hello.zip')) .then(zipfiles => expect(zipfiles).toEqual(['handler.js'])) - .then(() => testUtils.listZipFiles(path.join(cwd, '.serverless/hello2.zip'))) + .then(() => listZipFiles(path.join(cwd, '.serverless/hello2.zip'))) .then(zipfiles => expect(zipfiles).toEqual(['handler2.js'])); }); }); diff --git a/tests/packaging-suite/serverless.yml b/tests/integration-package/serverless.yml similarity index 100% rename from tests/packaging-suite/serverless.yml rename to tests/integration-package/serverless.yml diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/service/handler.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/service/handler.js deleted file mode 100644 index a33dec9e5..000000000 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/service/handler.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict'; - -module.exports.hello = (event, context, callback) => { - const response = { - statusCode: 200, - body: JSON.stringify({ - message: 'Hello from API Gateway!', - event, - }), - }; - - callback(null, response); -}; diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/service/serverless.yml b/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/service/serverless.yml deleted file mode 100644 index 19f08adba..000000000 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/service/serverless.yml +++ /dev/null @@ -1,16 +0,0 @@ -service: aws-nodejs # NOTE: update this with your service name - -provider: - name: aws - runtime: nodejs10.x - apiKeys: - - WillBeReplacedBeforeDeployment - -functions: - hello: - handler: handler.hello - events: - - http: - path: hello - method: GET - private: true diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js deleted file mode 100644 index a3048eda1..000000000 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/api-keys/tests.js +++ /dev/null @@ -1,83 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const BbPromise = require('bluebird'); -const execSync = require('child_process').execSync; -const AWS = require('aws-sdk'); -const _ = require('lodash'); -const fetch = require('node-fetch'); -const fse = require('fs-extra'); -const crypto = require('crypto'); - -const Utils = require('../../../../../utils/index'); - -const CF = new AWS.CloudFormation({ region: 'us-east-1' }); -const APIG = new AWS.APIGateway({ region: 'us-east-1' }); -BbPromise.promisifyAll(CF, { suffix: 'Promised' }); -BbPromise.promisifyAll(APIG, { suffix: 'Promised' }); - -describe('AWS - API Gateway (Integration: Lambda Proxy): API keys test', () => { - let stackName; - let endpoint; - let apiKey; - - beforeAll(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - - // replace name of the API key with something unique - const serverlessYmlFilePath = path.join(process.cwd(), 'serverless.yml'); - let serverlessYmlFileContent = fse.readFileSync(serverlessYmlFilePath).toString(); - - const apiKeyName = crypto.randomBytes(8).toString('hex'); - - serverlessYmlFileContent = serverlessYmlFileContent - .replace(/WillBeReplacedBeforeDeployment/, apiKeyName); - - fse.writeFileSync(serverlessYmlFilePath, serverlessYmlFileContent); - - Utils.deployService(); - }); - - beforeAll(() => { - const info = execSync(`${Utils.serverlessExec} info`); - const stringifiedOutput = (new Buffer(info, 'base64').toString()); - // some regex magic to extract the first API key value from the info output - apiKey = stringifiedOutput.match(/(api keys:\n)(\s*)(.+):(\s*)(.+)/)[5]; - }); - - it('should expose the endpoint(s) in the CloudFormation Outputs', () => - CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'ServiceEndpoint' }).OutputValue) - .then((endpointOutput) => { - const matched = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; - endpoint = `${matched}/hello`; - }) - ); - - it('should expose the API key(s) with its values when running the info command', () => { - expect(apiKey.length).to.be.above(0); - }); - - it('should reject a request with an invalid API Key', () => - fetch(endpoint) - .then((response) => { - expect(response.status).to.equal(403); - }) - ); - - it('should succeed if correct API key is given', () => - fetch(endpoint, { headers: { 'x-api-key': apiKey } }) - .then(response => response.json()) - .then((json) => { - expect(json.message).to.equal('Hello from API Gateway!'); - expect(json.event.requestContext.identity.apiKey).to.equal(apiKey); - expect(json.event.headers['x-api-key']).to.equal(apiKey); - }) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/service/handler.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/service/handler.js deleted file mode 100644 index af4dfe714..000000000 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/service/handler.js +++ /dev/null @@ -1,16 +0,0 @@ -'use strict'; - -module.exports.hello = (event, context, callback) => { - const response = { - statusCode: 200, - headers: { - 'Access-Control-Allow-Origin': '*', - }, - body: JSON.stringify({ - message: 'Hello from API Gateway!', - input: event, - }), - }; - - callback(null, response); -}; diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/service/serverless.yml b/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/service/serverless.yml deleted file mode 100644 index b0f885660..000000000 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/service/serverless.yml +++ /dev/null @@ -1,27 +0,0 @@ -service: aws-nodejs # NOTE: update this with your service name - -provider: - name: aws - runtime: nodejs10.x - -functions: - hello: - handler: handler.hello - events: - - http: - method: GET - path: simple-cors - cors: true - - http: - method: GET - path: complex-cors - cors: - origins: - - '*' - headers: - - Content-Type - - X-Amz-Date - - Authorization - - X-Api-Key - - X-Amz-Security-Token - - X-Amz-User-Agent diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/tests.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/tests.js deleted file mode 100644 index 92095960c..000000000 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/cors/tests.js +++ /dev/null @@ -1,62 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const BbPromise = require('bluebird'); -const AWS = require('aws-sdk'); -const _ = require('lodash'); -const fetch = require('node-fetch'); - -const Utils = require('../../../../../utils/index'); - -const CF = new AWS.CloudFormation({ region: 'us-east-1' }); -BbPromise.promisifyAll(CF, { suffix: 'Promised' }); - -describe('AWS - API Gateway (Integration: Lambda Proxy): CORS test', () => { - let stackName; - let endpointBase; - - beforeAll(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should expose the endpoint(s) in the CloudFormation Outputs', () => - CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'ServiceEndpoint' }).OutputValue) - .then((endpointOutput) => { - endpointBase = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; - }) - ); - - it('should setup CORS support with simple string config', () => - fetch(`${endpointBase}/simple-cors`, { method: 'OPTIONS' }) - .then((response) => { - const headers = response.headers; - - expect(headers.get('access-control-allow-headers')) - .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,' - + 'X-Amz-Security-Token,X-Amz-User-Agent'); - expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); - expect(headers.get('access-control-allow-origin')).to.equal('*'); - }) - ); - - it('should setup CORS support with complex object config', () => - fetch(`${endpointBase}/complex-cors`, { method: 'OPTIONS' }) - .then((response) => { - const headers = response.headers; - - expect(headers.get('access-control-allow-headers')) - .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,' - + 'X-Amz-Security-Token,X-Amz-User-Agent'); - expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); - expect(headers.get('access-control-allow-origin')).to.equal('*'); - }) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/service/handler.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/service/handler.js deleted file mode 100644 index 08f981b24..000000000 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/service/handler.js +++ /dev/null @@ -1,45 +0,0 @@ -'use strict'; - -const generatePolicy = (principalId, effect, resource) => { - const authResponse = {}; - authResponse.principalId = principalId; - - if (effect && resource) { - const policyDocument = {}; - policyDocument.Version = '2012-10-17'; - policyDocument.Statement = []; - - const statementOne = {}; - statementOne.Action = 'execute-api:Invoke'; - statementOne.Effect = effect; - statementOne.Resource = resource; - policyDocument.Statement[0] = statementOne; - authResponse.policyDocument = policyDocument; - } - - return authResponse; -}; - -// protected function -module.exports.hello = (event, context, callback) => { - const response = { - statusCode: 200, - body: JSON.stringify({ - message: 'Successfully authorized!', - event, - }), - }; - - callback(null, response); -}; - -// auth function -module.exports.auth = (event, context) => { - const token = event.authorizationToken.split(' '); - - if (token[0] === 'Bearer' && token[1] === 'ShouldBeAuthorized') { - context.succeed(generatePolicy('SomeRandomId', 'Allow', '*')); - } - - context.fail('Unauthorized'); -}; diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/service/serverless.yml b/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/service/serverless.yml deleted file mode 100644 index c5d573a40..000000000 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/service/serverless.yml +++ /dev/null @@ -1,16 +0,0 @@ -service: aws-nodejs # NOTE: update this with your service name - -provider: - name: aws - runtime: nodejs10.x - -functions: - hello: - handler: handler.hello - events: - - http: - path: hello - method: GET - authorizer: auth - auth: - handler: handler.auth diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/tests.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/tests.js deleted file mode 100644 index ffe2ec57b..000000000 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/custom-authorizers/tests.js +++ /dev/null @@ -1,62 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const BbPromise = require('bluebird'); -const AWS = require('aws-sdk'); -const _ = require('lodash'); -const fetch = require('node-fetch'); - -const Utils = require('../../../../../utils/index'); - -const CF = new AWS.CloudFormation({ region: 'us-east-1' }); -BbPromise.promisifyAll(CF, { suffix: 'Promised' }); - - -describe('AWS - API Gateway (Integration: Lambda Proxy): Custom authorizers test', () => { - let stackName; - let endpoint; - - beforeAll(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should expose the endpoint(s) in the CloudFormation Outputs', () => - CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'ServiceEndpoint' }).OutputValue) - .then((endpointOutput) => { - endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; - endpoint = `${endpoint}/hello`; - }) - ); - - it('should reject requests without authorization', () => - fetch(endpoint) - .then((response) => { - expect(response.status).to.equal(401); - }) - ); - - it('should reject requests with wrong authorization', () => - fetch(endpoint, { headers: { Authorization: 'Bearer ShouldNotBeAuthorized' } }) - .then((response) => { - expect(response.status).to.equal(401); - }) - ); - - it('should authorize requests with correct authorization', () => - fetch(endpoint, { headers: { Authorization: 'Bearer ShouldBeAuthorized' } }) - .then(response => response.json()) - .then((json) => { - expect(json.message).to.equal('Successfully authorized!'); - expect(json.event.requestContext.authorizer.principalId).to.equal('SomeRandomId'); - expect(json.event.headers.Authorization).to.equal('Bearer ShouldBeAuthorized'); - }) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/simple-api/service/handler.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/simple-api/service/handler.js deleted file mode 100644 index 60924d588..000000000 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/simple-api/service/handler.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict'; - -module.exports.hello = (event, context, callback) => { - const response = { - statusCode: 200, - body: JSON.stringify({ - message: 'Hello from API Gateway!', - input: event, - }), - }; - - callback(null, response); -}; diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/simple-api/service/serverless.yml b/tests/integration/aws/api-gateway/integration-lambda-proxy/simple-api/service/serverless.yml deleted file mode 100644 index b72f5a4c1..000000000 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/simple-api/service/serverless.yml +++ /dev/null @@ -1,37 +0,0 @@ -service: aws-nodejs # NOTE: update this with your service name - -provider: - name: aws - runtime: nodejs10.x - -functions: - hello: - handler: handler.hello - events: - # paths without a slash - - http: POST without-slash - - http: GET without-slash - - http: - method: PUT - path: without-slash - - http: - method: DELETE - path: without-slash - # paths with a slash - - http: POST /with-slash - - http: GET /with-slash - - http: - method: PUT - path: /with-slash - - http: - method: DELETE - path: /with-slash - # root only paths - - http: POST / - - http: GET / - - http: - method: PUT - path: / - - http: - method: DELETE - path: / diff --git a/tests/integration/aws/api-gateway/integration-lambda-proxy/simple-api/tests.js b/tests/integration/aws/api-gateway/integration-lambda-proxy/simple-api/tests.js deleted file mode 100644 index 49b09b77e..000000000 --- a/tests/integration/aws/api-gateway/integration-lambda-proxy/simple-api/tests.js +++ /dev/null @@ -1,139 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const BbPromise = require('bluebird'); -const AWS = require('aws-sdk'); -const _ = require('lodash'); -const fetch = require('node-fetch'); - -const Utils = require('../../../../../utils/index'); - -const CF = new AWS.CloudFormation({ region: 'us-east-1' }); -BbPromise.promisifyAll(CF, { suffix: 'Promised' }); - -describe('AWS - API Gateway (Integration: Lambda Proxy): Simple API test', () => { - let stackName; - let endpoint; - - beforeAll(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should expose the endpoint(s) in the CloudFormation Outputs', () => - CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'ServiceEndpoint' }).OutputValue) - .then((endpointOutput) => { - endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; - endpoint = `${endpoint}`; - }) - ); - - describe('when having a "without-slash" path setup', () => { - it('should expose an accessible POST HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; - - return fetch(testEndpoint, { method: 'POST' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible GET HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; - - return fetch(testEndpoint) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible PUT HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; - - return fetch(testEndpoint, { method: 'PUT' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible DELETE HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; - - return fetch(testEndpoint, { method: 'DELETE' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - }); - - describe('when having a "/with-slash" path setup', () => { - it('should expose an accessible POST HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint, { method: 'POST' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible GET HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible PUT HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint, { method: 'PUT' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible DELETE HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint, { method: 'DELETE' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - }); - - describe('when having a "/" path setup', () => { - it('should expose an accessible POST HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint, { method: 'POST' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible GET HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible PUT HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint, { method: 'PUT' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible DELETE HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint, { method: 'DELETE' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - }); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/api-gateway/integration-lambda/api-keys/service/handler.js b/tests/integration/aws/api-gateway/integration-lambda/api-keys/service/handler.js deleted file mode 100644 index a05213486..000000000 --- a/tests/integration/aws/api-gateway/integration-lambda/api-keys/service/handler.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; - -module.exports.hello = (event, context, callback) => { - callback(null, { message: 'Hello from API Gateway!', event }); -}; diff --git a/tests/integration/aws/api-gateway/integration-lambda/api-keys/service/serverless.yml b/tests/integration/aws/api-gateway/integration-lambda/api-keys/service/serverless.yml deleted file mode 100644 index dca0516ba..000000000 --- a/tests/integration/aws/api-gateway/integration-lambda/api-keys/service/serverless.yml +++ /dev/null @@ -1,17 +0,0 @@ -service: aws-nodejs # NOTE: update this with your service name - -provider: - name: aws - runtime: nodejs10.x - apiKeys: - - WillBeReplacedBeforeDeployment - -functions: - hello: - handler: handler.hello - events: - - http: - path: hello - method: GET - integration: lambda - private: true diff --git a/tests/integration/aws/api-gateway/integration-lambda/api-keys/tests.js b/tests/integration/aws/api-gateway/integration-lambda/api-keys/tests.js deleted file mode 100644 index 3f21813db..000000000 --- a/tests/integration/aws/api-gateway/integration-lambda/api-keys/tests.js +++ /dev/null @@ -1,83 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const BbPromise = require('bluebird'); -const execSync = require('child_process').execSync; -const AWS = require('aws-sdk'); -const _ = require('lodash'); -const fetch = require('node-fetch'); -const fse = require('fs-extra'); -const crypto = require('crypto'); - -const Utils = require('../../../../../utils/index'); - -const CF = new AWS.CloudFormation({ region: 'us-east-1' }); -const APIG = new AWS.APIGateway({ region: 'us-east-1' }); -BbPromise.promisifyAll(CF, { suffix: 'Promised' }); -BbPromise.promisifyAll(APIG, { suffix: 'Promised' }); - -describe('AWS - API Gateway (Integration: Lambda): API keys test', () => { - let stackName; - let endpoint; - let apiKey; - - beforeAll(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - - // replace name of the API key with something unique - const serverlessYmlFilePath = path.join(process.cwd(), 'serverless.yml'); - let serverlessYmlFileContent = fse.readFileSync(serverlessYmlFilePath).toString(); - - const apiKeyName = crypto.randomBytes(8).toString('hex'); - - serverlessYmlFileContent = serverlessYmlFileContent - .replace(/WillBeReplacedBeforeDeployment/, apiKeyName); - - fse.writeFileSync(serverlessYmlFilePath, serverlessYmlFileContent); - - Utils.deployService(); - }); - - it('should expose the endpoint(s) in the CloudFormation Outputs', () => - CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'ServiceEndpoint' }).OutputValue) - .then((endpointOutput) => { - endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; - endpoint = `${endpoint}/hello`; - }) - ); - - it('should expose the API key(s) with its values when running the info command', () => { - const info = execSync(`${Utils.serverlessExec} info`); - - const stringifiedOutput = (new Buffer(info, 'base64').toString()); - - // some regex magic to extract the first API key value from the info output - apiKey = stringifiedOutput.match(/(api keys:\n)(\s*)(.+):(\s*)(.+)/)[5]; - - expect(apiKey.length).to.be.above(0); - }); - - it('should reject a request with an invalid API Key', () => - fetch(endpoint) - .then((response) => { - expect(response.status).to.equal(403); - }) - ); - - it('should succeed if correct API key is given', () => - fetch(endpoint, { headers: { 'x-api-key': apiKey } }) - .then(response => response.json()) - .then((json) => { - expect(json.message).to.equal('Hello from API Gateway!'); - expect(json.event.identity.apiKey).to.equal(apiKey); - expect(json.event.headers['x-api-key']).to.equal(apiKey); - }) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/api-gateway/integration-lambda/cors/service/handler.js b/tests/integration/aws/api-gateway/integration-lambda/cors/service/handler.js deleted file mode 100644 index a05213486..000000000 --- a/tests/integration/aws/api-gateway/integration-lambda/cors/service/handler.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; - -module.exports.hello = (event, context, callback) => { - callback(null, { message: 'Hello from API Gateway!', event }); -}; diff --git a/tests/integration/aws/api-gateway/integration-lambda/cors/service/serverless.yml b/tests/integration/aws/api-gateway/integration-lambda/cors/service/serverless.yml deleted file mode 100644 index 89d6fc2d6..000000000 --- a/tests/integration/aws/api-gateway/integration-lambda/cors/service/serverless.yml +++ /dev/null @@ -1,29 +0,0 @@ -service: aws-nodejs # NOTE: update this with your service name - -provider: - name: aws - runtime: nodejs10.x - -functions: - hello: - handler: handler.hello - events: - - http: - method: GET - path: simple-cors - integration: lambda - cors: true - - http: - method: GET - path: complex-cors - integration: lambda - cors: - origins: - - '*' - headers: - - Content-Type - - X-Amz-Date - - Authorization - - X-Api-Key - - X-Amz-Security-Token - - X-Amz-User-Agent diff --git a/tests/integration/aws/api-gateway/integration-lambda/cors/tests.js b/tests/integration/aws/api-gateway/integration-lambda/cors/tests.js deleted file mode 100644 index 7b8171559..000000000 --- a/tests/integration/aws/api-gateway/integration-lambda/cors/tests.js +++ /dev/null @@ -1,62 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const BbPromise = require('bluebird'); -const AWS = require('aws-sdk'); -const _ = require('lodash'); -const fetch = require('node-fetch'); - -const Utils = require('../../../../../utils/index'); - -const CF = new AWS.CloudFormation({ region: 'us-east-1' }); -BbPromise.promisifyAll(CF, { suffix: 'Promised' }); - -describe('AWS - API Gateway (Integration: Lambda): CORS test', () => { - let stackName; - let endpointBase; - - beforeAll(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should expose the endpoint(s) in the CloudFormation Outputs', () => - CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'ServiceEndpoint' }).OutputValue) - .then((endpointOutput) => { - endpointBase = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; - }) - ); - - it('should setup CORS support with simple string config', () => - fetch(`${endpointBase}/simple-cors`, { method: 'OPTIONS' }) - .then((response) => { - const headers = response.headers; - - expect(headers.get('access-control-allow-headers')) - .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,' - + 'X-Amz-Security-Token,X-Amz-User-Agent'); - expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); - expect(headers.get('access-control-allow-origin')).to.equal('*'); - }) - ); - - it('should setup CORS support with complex object config', () => - fetch(`${endpointBase}/complex-cors`, { method: 'OPTIONS' }) - .then((response) => { - const headers = response.headers; - - expect(headers.get('access-control-allow-headers')) - .to.equal('Content-Type,X-Amz-Date,Authorization,X-Api-Key,' - + 'X-Amz-Security-Token,X-Amz-User-Agent'); - expect(headers.get('access-control-allow-methods')).to.equal('OPTIONS,GET'); - expect(headers.get('access-control-allow-origin')).to.equal('*'); - }) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/service/serverless.yml b/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/service/serverless.yml deleted file mode 100644 index c0b5a7250..000000000 --- a/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/service/serverless.yml +++ /dev/null @@ -1,17 +0,0 @@ -service: aws-nodejs # NOTE: update this with your service name - -provider: - name: aws - runtime: nodejs10.x - -functions: - hello: - handler: handler.hello - events: - - http: - path: hello - method: GET - integration: lambda - authorizer: auth - auth: - handler: handler.auth diff --git a/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/tests.js b/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/tests.js deleted file mode 100644 index 33a4f9706..000000000 --- a/tests/integration/aws/api-gateway/integration-lambda/custom-authorizers/tests.js +++ /dev/null @@ -1,61 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const BbPromise = require('bluebird'); -const AWS = require('aws-sdk'); -const _ = require('lodash'); -const fetch = require('node-fetch'); - -const Utils = require('../../../../../utils/index'); - -const CF = new AWS.CloudFormation({ region: 'us-east-1' }); -BbPromise.promisifyAll(CF, { suffix: 'Promised' }); - -describe('AWS - API Gateway (Integration: Lambda): Custom authorizers test', () => { - let stackName; - let endpoint; - - beforeAll(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should expose the endpoint(s) in the CloudFormation Outputs', () => - CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'ServiceEndpoint' }).OutputValue) - .then((endpointOutput) => { - endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; - endpoint = `${endpoint}/hello`; - }) - ); - - it('should reject requests without authorization', () => - fetch(endpoint) - .then((response) => { - expect(response.status).to.equal(401); - }) - ); - - it('should reject requests with wrong authorization', () => - fetch(endpoint, { headers: { Authorization: 'Bearer ShouldNotBeAuthorized' } }) - .then((response) => { - expect(response.status).to.equal(401); - }) - ); - - it('should authorize requests with correct authorization', () => - fetch(endpoint, { headers: { Authorization: 'Bearer ShouldBeAuthorized' } }) - .then(response => response.json()) - .then((json) => { - expect(json.message).to.equal('Successfully authorized!'); - expect(json.event.principalId).to.equal('SomeRandomId'); - expect(json.event.headers.Authorization).to.equal('Bearer ShouldBeAuthorized'); - }) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/api-gateway/integration-lambda/simple-api/service/handler.js b/tests/integration/aws/api-gateway/integration-lambda/simple-api/service/handler.js deleted file mode 100644 index a05213486..000000000 --- a/tests/integration/aws/api-gateway/integration-lambda/simple-api/service/handler.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; - -module.exports.hello = (event, context, callback) => { - callback(null, { message: 'Hello from API Gateway!', event }); -}; diff --git a/tests/integration/aws/api-gateway/integration-lambda/simple-api/service/serverless.yml b/tests/integration/aws/api-gateway/integration-lambda/simple-api/service/serverless.yml deleted file mode 100644 index b4ef6a1a2..000000000 --- a/tests/integration/aws/api-gateway/integration-lambda/simple-api/service/serverless.yml +++ /dev/null @@ -1,61 +0,0 @@ -service: aws-nodejs # NOTE: update this with your service name - -provider: - name: aws - runtime: nodejs10.x - -functions: - hello: - handler: handler.hello - events: - # paths without a slash - - http: - method: POST - path: without-slash - integration: lambda - - http: - method: GET - path: without-slash - integration: lambda - - http: - method: PUT - path: without-slash - integration: lambda - - http: - method: DELETE - path: without-slash - integration: lambda - # paths with a slash - - http: - method: POST - path: /with-slash - integration: lambda - - http: - method: GET - path: /with-slash - integration: lambda - - http: - method: PUT - path: /with-slash - integration: lambda - - http: - method: DELETE - path: /with-slash - integration: lambda - # root only paths - - http: - method: POST - path: / - integration: lambda - - http: - method: GET - path: / - integration: lambda - - http: - method: PUT - path: / - integration: lambda - - http: - method: DELETE - path: / - integration: lambda diff --git a/tests/integration/aws/api-gateway/integration-lambda/simple-api/tests.js b/tests/integration/aws/api-gateway/integration-lambda/simple-api/tests.js deleted file mode 100644 index 6050c13f3..000000000 --- a/tests/integration/aws/api-gateway/integration-lambda/simple-api/tests.js +++ /dev/null @@ -1,139 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const BbPromise = require('bluebird'); -const AWS = require('aws-sdk'); -const _ = require('lodash'); -const fetch = require('node-fetch'); - -const Utils = require('../../../../../utils/index'); - -const CF = new AWS.CloudFormation({ region: 'us-east-1' }); -BbPromise.promisifyAll(CF, { suffix: 'Promised' }); - -describe('AWS - API Gateway (Integration: Lambda): Simple API test', () => { - let stackName; - let endpoint; - - beforeAll(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should expose the endpoint(s) in the CloudFormation Outputs', () => - CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'ServiceEndpoint' }).OutputValue) - .then((endpointOutput) => { - endpoint = endpointOutput.match(/https:\/\/.+\.execute-api\..+\.amazonaws\.com.+/)[0]; - endpoint = `${endpoint}`; - }) - ); - - describe('when having a "without-slash" path setup', () => { - it('should expose an accessible POST HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; - - return fetch(testEndpoint, { method: 'POST' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible GET HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; - - return fetch(testEndpoint) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible PUT HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; - - return fetch(testEndpoint, { method: 'PUT' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible DELETE HTTP endpoint', () => { - const testEndpoint = `${endpoint}/without-slash`; - - return fetch(testEndpoint, { method: 'DELETE' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - }); - - describe('when having a "/with-slash" path setup', () => { - it('should expose an accessible POST HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint, { method: 'POST' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible GET HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible PUT HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint, { method: 'PUT' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible DELETE HTTP endpoint', () => { - const testEndpoint = `${endpoint}/with-slash`; - - return fetch(testEndpoint, { method: 'DELETE' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - }); - - describe('when having a "/" path setup', () => { - it('should expose an accessible POST HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint, { method: 'POST' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible GET HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible PUT HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint, { method: 'PUT' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - - it('should expose an accessible DELETE HTTP endpoint', () => { - const testEndpoint = `${endpoint}`; - - return fetch(testEndpoint, { method: 'DELETE' }) - .then(response => response.json()) - .then((json) => expect(json.message).to.equal('Hello from API Gateway!')); - }); - }); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/cloud-watch-event/multiple-events-multiple-functions/service/handler.js b/tests/integration/aws/cloud-watch-event/multiple-events-multiple-functions/service/handler.js deleted file mode 100644 index 8ea67e830..000000000 --- a/tests/integration/aws/cloud-watch-event/multiple-events-multiple-functions/service/handler.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -module.exports.cwe1 = (event, context, callback) => { - process.stdout.write(JSON.stringify(event)); - callback(null, {}); -}; - -module.exports.cwe2 = (event, context, callback) => { - process.stdout.write(JSON.stringify(event)); - callback(null, {}); -}; diff --git a/tests/integration/aws/cloud-watch-event/multiple-events-multiple-functions/service/serverless.yml b/tests/integration/aws/cloud-watch-event/multiple-events-multiple-functions/service/serverless.yml deleted file mode 100644 index ab1075c76..000000000 --- a/tests/integration/aws/cloud-watch-event/multiple-events-multiple-functions/service/serverless.yml +++ /dev/null @@ -1,29 +0,0 @@ -service: aws-nodejs - -provider: - name: aws - runtime: nodejs10.x - -functions: - cwe1: - handler: handler.cwe1 - events: - - cloudwatchEvent: - event: - source: - - serverless.testapp1 - - cloudwatchEvent: - event: - source: - - serverless.testapp2 - cwe2: - handler: handler.cwe2 - events: - - cloudwatchEvent: - event: - source: - - serverless.testapp1 - - cloudwatchEvent: - event: - source: - - serverless.testapp2 diff --git a/tests/integration/aws/cloud-watch-event/multiple-events-multiple-functions/tests.js b/tests/integration/aws/cloud-watch-event/multiple-events-multiple-functions/tests.js deleted file mode 100644 index 33d4d59b9..000000000 --- a/tests/integration/aws/cloud-watch-event/multiple-events-multiple-functions/tests.js +++ /dev/null @@ -1,29 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const Utils = require('../../../../utils/index'); - -describe('AWS - CloudWatch Event: Multiple events with multiple functions', () => { - beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should trigger functions when cloudwatchEvent runs', () => Utils - .putCloudWatchEvents(['serverless.testapp1', 'serverless.testapp2']) - .delay(60000) - .then(() => { - const logs1 = Utils.getFunctionLogs('cwe1'); - const logs2 = Utils.getFunctionLogs('cwe2'); - expect(/serverless\.testapp1/g.test(logs1)).to.equal(true); - expect(/serverless\.testapp1/g.test(logs2)).to.equal(true); - expect(/serverless\.testapp2/g.test(logs1)).to.equal(true); - expect(/serverless\.testapp2/g.test(logs2)).to.equal(true); - }) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/cloud-watch-event/multiple-events-single-function/service/handler.js b/tests/integration/aws/cloud-watch-event/multiple-events-single-function/service/handler.js deleted file mode 100644 index 53d42c6dc..000000000 --- a/tests/integration/aws/cloud-watch-event/multiple-events-single-function/service/handler.js +++ /dev/null @@ -1,6 +0,0 @@ -'use strict'; - -module.exports.cwe1 = (event, context, callback) => { - process.stdout.write(JSON.stringify(event)); - callback(null, {}); -}; diff --git a/tests/integration/aws/cloud-watch-event/multiple-events-single-function/service/serverless.yml b/tests/integration/aws/cloud-watch-event/multiple-events-single-function/service/serverless.yml deleted file mode 100644 index b17378649..000000000 --- a/tests/integration/aws/cloud-watch-event/multiple-events-single-function/service/serverless.yml +++ /dev/null @@ -1,18 +0,0 @@ -service: aws-nodejs - -provider: - name: aws - runtime: nodejs10.x - -functions: - cwe1: - handler: handler.cwe1 - events: - - cloudwatchEvent: - event: - source: - - serverless.testapp1 - - cloudwatchEvent: - event: - source: - - serverless.testapp2 diff --git a/tests/integration/aws/cloud-watch-event/multiple-events-single-function/tests.js b/tests/integration/aws/cloud-watch-event/multiple-events-single-function/tests.js deleted file mode 100644 index 9b662b686..000000000 --- a/tests/integration/aws/cloud-watch-event/multiple-events-single-function/tests.js +++ /dev/null @@ -1,26 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const Utils = require('../../../../utils/index'); - -describe('AWS - CloudWatch Event: Multiple events with single function', () => { - beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should trigger function when cloudwatchEvent runs', () => Utils - .putCloudWatchEvents(['serverless.testapp1', 'serverless.testapp2']) - .delay(60000) - .then(() => { - const logs = Utils.getFunctionLogs('cwe1'); - expect(/serverless\.testapp1/g.test(logs)).to.equal(true); - expect(/serverless\.testapp2/g.test(logs)).to.equal(true); - }) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/cloud-watch-event/single-event-multiple-functions/service/handler.js b/tests/integration/aws/cloud-watch-event/single-event-multiple-functions/service/handler.js deleted file mode 100644 index 8ea67e830..000000000 --- a/tests/integration/aws/cloud-watch-event/single-event-multiple-functions/service/handler.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -module.exports.cwe1 = (event, context, callback) => { - process.stdout.write(JSON.stringify(event)); - callback(null, {}); -}; - -module.exports.cwe2 = (event, context, callback) => { - process.stdout.write(JSON.stringify(event)); - callback(null, {}); -}; diff --git a/tests/integration/aws/cloud-watch-event/single-event-multiple-functions/service/serverless.yml b/tests/integration/aws/cloud-watch-event/single-event-multiple-functions/service/serverless.yml deleted file mode 100644 index ac28afdca..000000000 --- a/tests/integration/aws/cloud-watch-event/single-event-multiple-functions/service/serverless.yml +++ /dev/null @@ -1,21 +0,0 @@ -service: aws-nodejs - -provider: - name: aws - runtime: nodejs10.x - -functions: - cwe1: - handler: handler.cwe1 - events: - - cloudwatchEvent: - event: - source: - - serverless.testapp1 - cwe2: - handler: handler.cwe2 - events: - - cloudwatchEvent: - event: - source: - - serverless.testapp1 diff --git a/tests/integration/aws/cloud-watch-event/single-event-multiple-functions/tests.js b/tests/integration/aws/cloud-watch-event/single-event-multiple-functions/tests.js deleted file mode 100644 index 433708734..000000000 --- a/tests/integration/aws/cloud-watch-event/single-event-multiple-functions/tests.js +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const Utils = require('../../../../utils/index'); - -describe('AWS - CloudWatch Event: Single event with multiple functions', () => { - beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should trigger functions when cloudwatchEvent runs', () => Utils - .putCloudWatchEvents(['serverless.testapp1']) - .delay(60000) - .then(() => { - const logs1 = Utils.getFunctionLogs('cwe1'); - const logs2 = Utils.getFunctionLogs('cwe2'); - expect(/serverless\.testapp1/g.test(logs1)).to.equal(true); - expect(/serverless\.testapp1/g.test(logs2)).to.equal(true); - }) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/cloud-watch-event/single-event-single-function/service/handler.js b/tests/integration/aws/cloud-watch-event/single-event-single-function/service/handler.js deleted file mode 100644 index 53d42c6dc..000000000 --- a/tests/integration/aws/cloud-watch-event/single-event-single-function/service/handler.js +++ /dev/null @@ -1,6 +0,0 @@ -'use strict'; - -module.exports.cwe1 = (event, context, callback) => { - process.stdout.write(JSON.stringify(event)); - callback(null, {}); -}; diff --git a/tests/integration/aws/cloud-watch-event/single-event-single-function/service/serverless.yml b/tests/integration/aws/cloud-watch-event/single-event-single-function/service/serverless.yml deleted file mode 100644 index 09df4393c..000000000 --- a/tests/integration/aws/cloud-watch-event/single-event-single-function/service/serverless.yml +++ /dev/null @@ -1,14 +0,0 @@ -service: aws-nodejs - -provider: - name: aws - runtime: nodejs10.x - -functions: - cwe1: - handler: handler.cwe1 - events: - - cloudwatchEvent: - event: - source: - - serverless.testapp1 diff --git a/tests/integration/aws/cloud-watch-event/single-event-single-function/tests.js b/tests/integration/aws/cloud-watch-event/single-event-single-function/tests.js deleted file mode 100644 index c0ab408d8..000000000 --- a/tests/integration/aws/cloud-watch-event/single-event-single-function/tests.js +++ /dev/null @@ -1,25 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const Utils = require('../../../../utils/index'); - -describe('AWS - CloudWatch Event: Single event with single function', () => { - beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should trigger function when cloudwatchEvent runs', () => Utils - .putCloudWatchEvents(['serverless.testapp1']) - .delay(60000) - .then(() => { - const logs = Utils.getFunctionLogs('cwe1'); - expect(/serverless\.testapp1/g.test(logs)).to.equal(true); - }) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/cognito-user-pool/multiple-pools-multiple-events-multiple-functions/service/handler.js b/tests/integration/aws/cognito-user-pool/multiple-pools-multiple-events-multiple-functions/service/handler.js deleted file mode 100644 index a1e2afe62..000000000 --- a/tests/integration/aws/cognito-user-pool/multiple-pools-multiple-events-multiple-functions/service/handler.js +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; - -const preSignUp = (event, context, callback) => { - const nextEvent = Object.assign({}, event); - nextEvent.response.autoConfirmUser = true; - - process.stdout.write(JSON.stringify(nextEvent)); - callback(null, nextEvent); -}; - -const customMessage = (event, context, callback) => { - const nextEvent = Object.assign({}, event); - if (event.triggerSource === 'CustomMessage_SignUp') { - nextEvent.response.smsMessage = `Welcome to the service. Your confirmation code is ${ - event.request.codeParameter}`; - nextEvent.response.emailSubject = 'Welcome to the service'; - nextEvent.response.emailMessage = `Thank you for signing up. ${ - event.request.codeParameter} is your verification code`; - } - process.stdout.write(JSON.stringify(nextEvent)); - callback(null, nextEvent); -}; - -module.exports.preSignUp1 = preSignUp; -module.exports.preSignUp2 = preSignUp; -module.exports.customMessage1 = customMessage; -module.exports.customMessage2 = customMessage; diff --git a/tests/integration/aws/cognito-user-pool/multiple-pools-multiple-events-multiple-functions/service/serverless.yml b/tests/integration/aws/cognito-user-pool/multiple-pools-multiple-events-multiple-functions/service/serverless.yml deleted file mode 100644 index 9335d606a..000000000 --- a/tests/integration/aws/cognito-user-pool/multiple-pools-multiple-events-multiple-functions/service/serverless.yml +++ /dev/null @@ -1,31 +0,0 @@ -service: aws-nodejs - -provider: - name: aws - runtime: nodejs10.x - -functions: - preSignUp1: - handler: handler.preSignUp1 - events: - - cognitoUserPool: - pool: ${env:COGNITO_USER_POOL_1} - trigger: PreSignUp - customMessage1: - handler: handler.customMessage1 - events: - - cognitoUserPool: - pool: ${env:COGNITO_USER_POOL_1} - trigger: CustomMessage - preSignUp2: - handler: handler.preSignUp2 - events: - - cognitoUserPool: - pool: ${env:COGNITO_USER_POOL_2} - trigger: PreSignUp - customMessage2: - handler: handler.customMessage2 - events: - - cognitoUserPool: - pool: ${env:COGNITO_USER_POOL_2} - trigger: CustomMessage diff --git a/tests/integration/aws/cognito-user-pool/multiple-pools-multiple-events-multiple-functions/tests.js b/tests/integration/aws/cognito-user-pool/multiple-pools-multiple-events-multiple-functions/tests.js deleted file mode 100644 index df2ba5d40..000000000 --- a/tests/integration/aws/cognito-user-pool/multiple-pools-multiple-events-multiple-functions/tests.js +++ /dev/null @@ -1,77 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const Utils = require('../../../../utils/index'); - -describe('AWS - Cognito User Pool: Multiple User Pools with multiple ' + - 'events with multiple functions', () => { - beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should call the specified function on the first User Pool when PreSignUp ' + - 'event is triggered', () => Utils - .getCognitoUserPoolId(process.env.COGNITO_USER_POOL_1) - .then((poolId) => - Promise.all([ - poolId, - Utils.createCognitoUser(poolId, 'test@test.com', 'Password123!'), - ]) - ) - .delay(60000) - .then((promiseResponse) => { - const poolId = promiseResponse[0]; - const logs = Utils.getFunctionLogs('preSignUp1'); - - expect(RegExp(`"userPoolId":"${poolId}"`, 'g').test(logs)).to.equal(true); - expect(/"triggerSource":"PreSignUp_\w+"/g.test(logs)).to.equal(true); - }) - ); - - it('should call the specified function on the first User Pool when CustomMessage ' + - 'event is triggered', () => Utils - .getCognitoUserPoolId(process.env.COGNITO_USER_POOL_1) - .then((poolId) => { - const logs = Utils.getFunctionLogs('customMessage1'); - - expect(RegExp(`"userPoolId":"${poolId}"`, 'g').test(logs)).to.equal(true); - expect(/"triggerSource":"CustomMessage_AdminCreateUser"/g.test(logs)).to.equal(true); - }) - ); - - it('should call the specified function on the second User Pool when PreSignUp ' + - 'event is triggered', () => Utils - .getCognitoUserPoolId(process.env.COGNITO_USER_POOL_2) - .then((poolId) => - Promise.all([ - poolId, - Utils.createCognitoUser(poolId, 'test@test.com', 'Password123!'), - ]) - ) - .delay(60000) - .then((promiseResponse) => { - const poolId = promiseResponse[0]; - const logs = Utils.getFunctionLogs('preSignUp2'); - - expect(RegExp(`"userPoolId":"${poolId}"`, 'g').test(logs)).to.equal(true); - expect(/"triggerSource":"PreSignUp_\w+"/g.test(logs)).to.equal(true); - }) - ); - - it('should call the specified function on the second User Pool when CustomMessage ' + - 'event is triggered', () => Utils - .getCognitoUserPoolId(process.env.COGNITO_USER_POOL_2) - .then((poolId) => { - const logs = Utils.getFunctionLogs('customMessage2'); - - expect(RegExp(`"userPoolId":"${poolId}"`, 'g').test(logs)).to.equal(true); - expect(/"triggerSource":"CustomMessage_AdminCreateUser"/g.test(logs)).to.equal(true); - }) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/cognito-user-pool/multiple-pools-single-event-single-function/service/handler.js b/tests/integration/aws/cognito-user-pool/multiple-pools-single-event-single-function/service/handler.js deleted file mode 100644 index b7f044321..000000000 --- a/tests/integration/aws/cognito-user-pool/multiple-pools-single-event-single-function/service/handler.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -module.exports.preSignUp = (event, context, callback) => { - const nextEvent = Object.assign({}, event); - nextEvent.response.autoConfirmUser = true; - - process.stdout.write(JSON.stringify(nextEvent)); - callback(null, nextEvent); -}; diff --git a/tests/integration/aws/cognito-user-pool/multiple-pools-single-event-single-function/service/serverless.yml b/tests/integration/aws/cognito-user-pool/multiple-pools-single-event-single-function/service/serverless.yml deleted file mode 100644 index e2d62ae50..000000000 --- a/tests/integration/aws/cognito-user-pool/multiple-pools-single-event-single-function/service/serverless.yml +++ /dev/null @@ -1,16 +0,0 @@ -service: aws-nodejs - -provider: - name: aws - runtime: nodejs10.x - -functions: - preSignUp: - handler: handler.preSignUp - events: - - cognitoUserPool: - pool: ${env:COGNITO_USER_POOL_1} - trigger: PreSignUp - - cognitoUserPool: - pool: ${env:COGNITO_USER_POOL_2} - trigger: PreSignUp diff --git a/tests/integration/aws/cognito-user-pool/multiple-pools-single-event-single-function/tests.js b/tests/integration/aws/cognito-user-pool/multiple-pools-single-event-single-function/tests.js deleted file mode 100644 index 9a9477545..000000000 --- a/tests/integration/aws/cognito-user-pool/multiple-pools-single-event-single-function/tests.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const Utils = require('../../../../utils/index'); - -describe('AWS - Cognito User Pool: Multiple User Pools with single ' + - 'event with single function', () => { - beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should call the specified function on the first User Pool when PreSignUp ' + - 'event is triggered', () => Utils - .getCognitoUserPoolId(process.env.COGNITO_USER_POOL_1) - .then((poolId) => - Promise.all([ - poolId, - Utils.createCognitoUser(poolId, 'test@test.com', 'Password123!'), - ]) - ) - .delay(60000) - .then((promiseResponse) => { - const poolId = promiseResponse[0]; - const logs = Utils.getFunctionLogs('preSignUp'); - expect(RegExp(`"userPoolId":"${poolId}"`, 'g').test(logs)).to.equal(true); - expect(/"triggerSource":"PreSignUp_\w+"/g.test(logs)).to.equal(true); - }) - ); - - it('should call the specified function on the second User Pool when PreSignUp ' + - 'event is triggered', () => Utils - .getCognitoUserPoolId(process.env.COGNITO_USER_POOL_2) - .then((poolId) => - Promise.all([ - poolId, - Utils.createCognitoUser(poolId, 'test@test.com', 'Password123!'), - ]) - ) - .delay(60000) - .then((promiseResponse) => { - const poolId = promiseResponse[0]; - const logs = Utils.getFunctionLogs('preSignUp'); - expect(RegExp(`"userPoolId":"${poolId}"`, 'g').test(logs)).to.equal(true); - expect(/"triggerSource":"PreSignUp_\w+"/g.test(logs)).to.equal(true); - }) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/cognito-user-pool/single-pool-multiple-events-multiple-functions/service/handler.js b/tests/integration/aws/cognito-user-pool/single-pool-multiple-events-multiple-functions/service/handler.js deleted file mode 100644 index 2801cf8c5..000000000 --- a/tests/integration/aws/cognito-user-pool/single-pool-multiple-events-multiple-functions/service/handler.js +++ /dev/null @@ -1,22 +0,0 @@ -'use strict'; - -module.exports.preSignUp = (event, context, callback) => { - const nextEvent = Object.assign({}, event); - nextEvent.response.autoConfirmUser = true; - - process.stdout.write(JSON.stringify(nextEvent)); - callback(null, nextEvent); -}; - -module.exports.customMessage = (event, context, callback) => { - const nextEvent = Object.assign({}, event); - if (event.triggerSource === 'CustomMessage_SignUp') { - nextEvent.response.smsMessage = `Welcome to the service. Your confirmation code is ${ - event.request.codeParameter}`; - nextEvent.response.emailSubject = 'Welcome to the service'; - nextEvent.response.emailMessage = `Thank you for signing up. ${ - event.request.codeParameter} is your verification code`; - } - process.stdout.write(JSON.stringify(nextEvent)); - callback(null, nextEvent); -}; diff --git a/tests/integration/aws/cognito-user-pool/single-pool-multiple-events-multiple-functions/service/serverless.yml b/tests/integration/aws/cognito-user-pool/single-pool-multiple-events-multiple-functions/service/serverless.yml deleted file mode 100644 index b3d78c5b9..000000000 --- a/tests/integration/aws/cognito-user-pool/single-pool-multiple-events-multiple-functions/service/serverless.yml +++ /dev/null @@ -1,19 +0,0 @@ -service: aws-nodejs - -provider: - name: aws - runtime: nodejs10.x - -functions: - preSignUp: - handler: handler.preSignUp - events: - - cognitoUserPool: - pool: ${env:COGNITO_USER_POOL_1} - trigger: PreSignUp - customMessage: - handler: handler.customMessage - events: - - cognitoUserPool: - pool: ${env:COGNITO_USER_POOL_1} - trigger: CustomMessage diff --git a/tests/integration/aws/cognito-user-pool/single-pool-multiple-events-multiple-functions/tests.js b/tests/integration/aws/cognito-user-pool/single-pool-multiple-events-multiple-functions/tests.js deleted file mode 100644 index 96d25c39b..000000000 --- a/tests/integration/aws/cognito-user-pool/single-pool-multiple-events-multiple-functions/tests.js +++ /dev/null @@ -1,39 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const Utils = require('../../../../utils/index'); - -describe('AWS - Cognito User Pool: Single User Pool with multiple ' + - 'events with multiple functions', () => { - beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should call the specified function when PreSignUp event is triggered', () => Utils - .getCognitoUserPoolId(process.env.COGNITO_USER_POOL_1) - .then((poolId) => - Utils.createCognitoUser(poolId, 'test@test.com', 'Password123!') - ) - .delay(60000) - .then(() => { - const logs = Utils.getFunctionLogs('preSignUp'); - expect(/"triggerSource":"PreSignUp_\w+"/g.test(logs)).to.equal(true); - }) - ); - - it('should call the specified function when CustomMessage event is triggered', () => Utils - .getCognitoUserPoolId(process.env.COGNITO_USER_POOL_1) - .then((poolId) => { - const logs = Utils.getFunctionLogs('customMessage'); - - expect(RegExp(`"userPoolId":"${poolId}"`, 'g').test(logs)).to.equal(true); - expect(/"triggerSource":"CustomMessage_AdminCreateUser"/g.test(logs)).to.equal(true); - }) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/cognito-user-pool/single-pool-single-event-single-function/service/handler.js b/tests/integration/aws/cognito-user-pool/single-pool-single-event-single-function/service/handler.js deleted file mode 100644 index b7f044321..000000000 --- a/tests/integration/aws/cognito-user-pool/single-pool-single-event-single-function/service/handler.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -module.exports.preSignUp = (event, context, callback) => { - const nextEvent = Object.assign({}, event); - nextEvent.response.autoConfirmUser = true; - - process.stdout.write(JSON.stringify(nextEvent)); - callback(null, nextEvent); -}; diff --git a/tests/integration/aws/cognito-user-pool/single-pool-single-event-single-function/service/serverless.yml b/tests/integration/aws/cognito-user-pool/single-pool-single-event-single-function/service/serverless.yml deleted file mode 100644 index 4e5dcd826..000000000 --- a/tests/integration/aws/cognito-user-pool/single-pool-single-event-single-function/service/serverless.yml +++ /dev/null @@ -1,13 +0,0 @@ -service: aws-nodejs - -provider: - name: aws - runtime: nodejs10.x - -functions: - preSignUp: - handler: handler.preSignUp - events: - - cognitoUserPool: - pool: ${env:COGNITO_USER_POOL_1} - trigger: PreSignUp diff --git a/tests/integration/aws/cognito-user-pool/single-pool-single-event-single-function/tests.js b/tests/integration/aws/cognito-user-pool/single-pool-single-event-single-function/tests.js deleted file mode 100644 index b77837821..000000000 --- a/tests/integration/aws/cognito-user-pool/single-pool-single-event-single-function/tests.js +++ /dev/null @@ -1,29 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const Utils = require('../../../../utils/index'); - -describe('AWS - Cognito User Pool: Single User Pool with single ' + - 'event with single function', () => { - beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should call the specified function when PreSignUp event is triggered', () => Utils - .getCognitoUserPoolId(process.env.COGNITO_USER_POOL_1) - .then((poolId) => - Utils.createCognitoUser(poolId, 'test@test.com', 'Password123!') - ) - .delay(60000) - .then(() => { - const logs = Utils.getFunctionLogs('preSignUp'); - expect(/"triggerSource":"PreSignUp_\w+"/g.test(logs)).to.equal(true); - }) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/general/custom-resources/service/handler.js b/tests/integration/aws/general/custom-resources/service/handler.js deleted file mode 100644 index 57b45f44f..000000000 --- a/tests/integration/aws/general/custom-resources/service/handler.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; - -module.exports.hello = (event, context, callback) => { - callback(null, { message: 'Go Serverless v1.0! Your function executed successfully!', event }); -}; diff --git a/tests/integration/aws/general/custom-resources/service/serverless.yml b/tests/integration/aws/general/custom-resources/service/serverless.yml deleted file mode 100644 index 30d1b454f..000000000 --- a/tests/integration/aws/general/custom-resources/service/serverless.yml +++ /dev/null @@ -1,20 +0,0 @@ -service: aws-nodejs # NOTE: update this with your service name - -provider: - name: aws - runtime: nodejs10.x - -functions: - hello: - handler: handler.hello - -resources: - Resources: - MyCustomS3Bucket: - Type: 'AWS::S3::Bucket' - Properties: - BucketName: WillBeReplacedBeforeDeployment - Outputs: - MyCustomOutput: - Value: SomeValue - Description: Used to test custom outputs diff --git a/tests/integration/aws/general/custom-resources/tests.js b/tests/integration/aws/general/custom-resources/tests.js deleted file mode 100644 index 66222e495..000000000 --- a/tests/integration/aws/general/custom-resources/tests.js +++ /dev/null @@ -1,58 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const AWS = require('aws-sdk'); -const BbPromise = require('bluebird'); -const _ = require('lodash'); -const fse = require('fs-extra'); -const crypto = require('crypto'); - -const Utils = require('../../../../utils/index'); - -const CF = new AWS.CloudFormation({ region: 'us-east-1' }); -const S3 = new AWS.S3({ region: 'us-east-1' }); -BbPromise.promisifyAll(CF, { suffix: 'Promised' }); -BbPromise.promisifyAll(S3, { suffix: 'Promised' }); - -describe('AWS - General: Custom resources test', () => { - let stackName; - let s3BucketName; - - beforeAll(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - - // replace name of bucket which is created through custom resources with something unique - const serverlessYmlFilePath = path.join(process.cwd(), 'serverless.yml'); - let serverlessYmlFileContent = fse.readFileSync(serverlessYmlFilePath).toString(); - - s3BucketName = crypto.randomBytes(8).toString('hex'); - - serverlessYmlFileContent = serverlessYmlFileContent - .replace(/WillBeReplacedBeforeDeployment/, s3BucketName); - - fse.writeFileSync(serverlessYmlFilePath, serverlessYmlFileContent); - - Utils.deployService(); - }); - - it('should add the custom outputs to the Outputs section', () => - CF.describeStacksPromised({ StackName: stackName }) - .then((result) => _.find(result.Stacks[0].Outputs, - { OutputKey: 'MyCustomOutput' }).OutputValue) - .then((endpointOutput) => { - expect(endpointOutput).to.equal('SomeValue'); - }) - ); - - it('should create the custom resources (a S3 bucket)', () => - S3.listBucketsPromised() - .then((result) => !!_.find(result.Buckets, - { Name: s3BucketName })) - .then((found) => expect(found).to.equal(true)) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/general/environment-variables/service/handler.js b/tests/integration/aws/general/environment-variables/service/handler.js deleted file mode 100644 index 6f5d68a82..000000000 --- a/tests/integration/aws/general/environment-variables/service/handler.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict'; - -module.exports.hello = (event, context, callback) => { - callback(null, { - environment_variables: process.env, - }); -}; diff --git a/tests/integration/aws/general/environment-variables/service/serverless.yml b/tests/integration/aws/general/environment-variables/service/serverless.yml deleted file mode 100644 index 00cc3e865..000000000 --- a/tests/integration/aws/general/environment-variables/service/serverless.yml +++ /dev/null @@ -1,16 +0,0 @@ -service: aws-nodejs # NOTE: update this with your service name - -provider: - name: aws - runtime: nodejs10.x - environment: - provider_level_variable_1: provider_level_1 - provider_level_variable_2: provider_level_2 - -functions: - hello: - handler: handler.hello - environment: - function_level_variable_1: function_level_1 - function_level_variable_2: function_level_2 - provider_level_variable_2: overwritten_by_function diff --git a/tests/integration/aws/general/environment-variables/tests.js b/tests/integration/aws/general/environment-variables/tests.js deleted file mode 100644 index af1dcb368..000000000 --- a/tests/integration/aws/general/environment-variables/tests.js +++ /dev/null @@ -1,33 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const execSync = require('child_process').execSync; - -const Utils = require('../../../../utils/index'); - -describe('AWS - General: Environment variables test', () => { - beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should expose environment variables', () => { - const invoked = execSync(`${Utils.serverlessExec} invoke --function hello --noGreeting true`); - - const result = JSON.parse(new Buffer(invoked, 'base64').toString()); - - expect(result.environment_variables.provider_level_variable_1) - .to.be.equal('provider_level_1'); - expect(result.environment_variables.function_level_variable_1) - .to.be.equal('function_level_1'); - expect(result.environment_variables.function_level_variable_2) - .to.be.equal('function_level_2'); - expect(result.environment_variables.provider_level_variable_2) - .to.be.equal('overwritten_by_function'); - }); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/general/nested-handlers/service/deeply/nested/handler.js b/tests/integration/aws/general/nested-handlers/service/deeply/nested/handler.js deleted file mode 100644 index 6313e306f..000000000 --- a/tests/integration/aws/general/nested-handlers/service/deeply/nested/handler.js +++ /dev/null @@ -1,6 +0,0 @@ -'use strict'; - -// Your first function handler -module.exports.hello = (event, context, callback) => { - callback(null, { message: 'Go Serverless v1.0! Your function executed successfully!', event }); -}; diff --git a/tests/integration/aws/general/nested-handlers/service/serverless.yml b/tests/integration/aws/general/nested-handlers/service/serverless.yml deleted file mode 100644 index 870644b34..000000000 --- a/tests/integration/aws/general/nested-handlers/service/serverless.yml +++ /dev/null @@ -1,9 +0,0 @@ -service: aws-nodejs # NOTE: update this with your service name - -provider: - name: aws - runtime: nodejs10.x - -functions: - hello: - handler: deeply/nested/handler.hello diff --git a/tests/integration/aws/general/nested-handlers/tests.js b/tests/integration/aws/general/nested-handlers/tests.js deleted file mode 100644 index ed4083d95..000000000 --- a/tests/integration/aws/general/nested-handlers/tests.js +++ /dev/null @@ -1,25 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const execSync = require('child_process').execSync; - -const Utils = require('../../../../utils/index'); - -describe('AWS - General: Nested handlers test', () => { - beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should invoke the nested handler function from AWS', () => { - const invoked = execSync(`${Utils.serverlessExec} invoke --function hello --noGreeting true`); - - const result = JSON.parse(new Buffer(invoked, 'base64').toString()); - expect(result.message).to.be.equal('Go Serverless v1.0! Your function executed successfully!'); - }); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/general/overwrite-resources/service/handler.js b/tests/integration/aws/general/overwrite-resources/service/handler.js deleted file mode 100644 index c45399eaa..000000000 --- a/tests/integration/aws/general/overwrite-resources/service/handler.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict'; - -module.exports.hello = (event, context, callback) => { - callback(null, { message: 'Go Serverless v1.0! Your function executed successfully!', event }); -}; - -module.exports.world = (event, context, callback) => { - callback(null, { message: 'Go Serverless v1.0! Your function executed successfully!', event }); -}; - diff --git a/tests/integration/aws/general/overwrite-resources/service/serverless.yml b/tests/integration/aws/general/overwrite-resources/service/serverless.yml deleted file mode 100644 index 19d78e077..000000000 --- a/tests/integration/aws/general/overwrite-resources/service/serverless.yml +++ /dev/null @@ -1,18 +0,0 @@ -service: aws-nodejs # NOTE: update this with your service name - -provider: - name: aws - runtime: nodejs10.x - -functions: - hello: - handler: handler.hello - world: - handler: handler.world - -resources: - Resources: - HelloLambdaFunction: - Type: "AWS::Lambda::Function" - Properties: - Timeout: 10 diff --git a/tests/integration/aws/general/overwrite-resources/tests.js b/tests/integration/aws/general/overwrite-resources/tests.js deleted file mode 100644 index 06e615005..000000000 --- a/tests/integration/aws/general/overwrite-resources/tests.js +++ /dev/null @@ -1,42 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const AWS = require('aws-sdk'); -const BbPromise = require('bluebird'); - -const Utils = require('../../../../utils/index'); - -const Lambda = new AWS.Lambda({ region: 'us-east-1' }); -BbPromise.promisifyAll(Lambda, { suffix: 'Promised' }); - -describe('AWS - General: Overwrite resources test', () => { - let stackName; - - beforeAll(() => { - stackName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should overwrite timeout config for hello function', () => { - const helloFunctionName = `${stackName}-hello`; - return Lambda.getFunctionPromised({ FunctionName: helloFunctionName }) - .then(data => { - const timeout = data.Configuration.Timeout; - expect(timeout).to.equal(10); - }); - }); - - it('should NOT overwrite timeout config for world function', () => { - const worldFunctionName = `${stackName}-world`; - return Lambda.getFunctionPromised({ FunctionName: worldFunctionName }) - .then(data => { - const timeout = data.Configuration.Timeout; - expect(timeout).to.equal(6); - }); - }); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/general/package/service/handler.js b/tests/integration/aws/general/package/service/handler.js deleted file mode 100644 index 57b45f44f..000000000 --- a/tests/integration/aws/general/package/service/handler.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; - -module.exports.hello = (event, context, callback) => { - callback(null, { message: 'Go Serverless v1.0! Your function executed successfully!', event }); -}; diff --git a/tests/integration/aws/general/package/service/serverless.yml b/tests/integration/aws/general/package/service/serverless.yml deleted file mode 100644 index b01bfe299..000000000 --- a/tests/integration/aws/general/package/service/serverless.yml +++ /dev/null @@ -1,9 +0,0 @@ -service: aws-nodejs # NOTE: update this with your service name - -provider: - name: aws - runtime: nodejs10.x - -functions: - hello: - handler: handler.hello diff --git a/tests/integration/aws/general/package/tests.js b/tests/integration/aws/general/package/tests.js deleted file mode 100644 index 2e466cd7a..000000000 --- a/tests/integration/aws/general/package/tests.js +++ /dev/null @@ -1,35 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const execSync = require('child_process').execSync; -const AWS = require('aws-sdk'); -const fs = require('fs'); - -const CF = new AWS.CloudFormation({ region: 'us-east-1' }); -const Utils = require('../../../../utils/index'); - -describe('AWS - General: Package', () => { - let serviceName; - - beforeAll(() => { - serviceName = Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - execSync(`${Utils.serverlessExec} package`); - }); - - it('should have create cloudformation files and functions zip', () => { - const deployedFiles = fs.readdirSync(path.join(process.cwd(), '.serverless')); - expect(deployedFiles[0]).to.equal('cloudformation-template-create-stack.json'); - expect(deployedFiles[1]).to.equal('cloudformation-template-update-stack.json'); - expect(deployedFiles[2]).to.equal('serverless-state.json'); - // Note: noticed the seconds section can vary a lot - expect(deployedFiles[3]).to.match(/test-[0-9]{1,}-[0-9]{1,}.zip/); - }); - - it('should not found stack from AWS', (done) => { - CF.describeStackResources({ StackName: serviceName }, (error) => { - expect(error.message).to.equal(`Stack with id ${serviceName} does not exist`); - done(); - }); - }); -}); diff --git a/tests/integration/aws/iot/multiple-rules-multiple-functions/service/handler.js b/tests/integration/aws/iot/multiple-rules-multiple-functions/service/handler.js deleted file mode 100644 index cdfd5c5b9..000000000 --- a/tests/integration/aws/iot/multiple-rules-multiple-functions/service/handler.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -module.exports.iot1 = (event, context, callback) => { - process.stdout.write(JSON.stringify(event)); - callback(null, {}); -}; - -module.exports.iot2 = (event, context, callback) => { - process.stdout.write(JSON.stringify(event)); - callback(null, {}); -}; diff --git a/tests/integration/aws/iot/multiple-rules-multiple-functions/service/serverless.yml b/tests/integration/aws/iot/multiple-rules-multiple-functions/service/serverless.yml deleted file mode 100644 index c018fbd45..000000000 --- a/tests/integration/aws/iot/multiple-rules-multiple-functions/service/serverless.yml +++ /dev/null @@ -1,17 +0,0 @@ -service: aws-nodejs - -provider: - name: aws - runtime: nodejs10.x - -functions: - iot1: - handler: handler.iot1 - events: - - iot: - sql: "SELECT * FROM 'mybutton'" - iot2: - handler: handler.iot2 - events: - - iot: - sql: "SELECT * FROM 'weather'" diff --git a/tests/integration/aws/iot/multiple-rules-multiple-functions/tests.js b/tests/integration/aws/iot/multiple-rules-multiple-functions/tests.js deleted file mode 100644 index a54ace65c..000000000 --- a/tests/integration/aws/iot/multiple-rules-multiple-functions/tests.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const Utils = require('../../../../utils/index'); - -describe('AWS - IoT: Multiple rules with multiple functions', () => { - beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should trigger function when ruletopic message is published', () => Utils - .publishIotData('mybutton', '{"message":"hello serverless"}') - .then(() => Utils.publishIotData('weather', '{"message":"sunny today"}')) - .delay(60000) - .then(() => { - const iot1Logs = Utils.getFunctionLogs('iot1'); - const iot2Logs = Utils.getFunctionLogs('iot2'); - expect(/{"message":"hello serverless"}/g.test(iot1Logs)).to.equal(true); - expect(/{"message":"sunny today"}/g.test(iot2Logs)).to.equal(true); - }) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/iot/multiple-rules-single-function/service/handler.js b/tests/integration/aws/iot/multiple-rules-single-function/service/handler.js deleted file mode 100644 index 0f770c560..000000000 --- a/tests/integration/aws/iot/multiple-rules-single-function/service/handler.js +++ /dev/null @@ -1,6 +0,0 @@ -'use strict'; - -module.exports.iot1 = (event, context, callback) => { - process.stdout.write(JSON.stringify(event)); - callback(null, {}); -}; diff --git a/tests/integration/aws/iot/multiple-rules-single-function/service/serverless.yml b/tests/integration/aws/iot/multiple-rules-single-function/service/serverless.yml deleted file mode 100644 index 5e13e0c96..000000000 --- a/tests/integration/aws/iot/multiple-rules-single-function/service/serverless.yml +++ /dev/null @@ -1,14 +0,0 @@ -service: aws-nodejs - -provider: - name: aws - runtime: nodejs10.x - -functions: - iot1: - handler: handler.iot1 - events: - - iot: - sql: "SELECT * FROM 'mybutton'" - - iot: - sql: "SELECT * FROM 'weather'" diff --git a/tests/integration/aws/iot/multiple-rules-single-function/tests.js b/tests/integration/aws/iot/multiple-rules-single-function/tests.js deleted file mode 100644 index 11065591f..000000000 --- a/tests/integration/aws/iot/multiple-rules-single-function/tests.js +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const Utils = require('../../../../utils/index'); - -describe('AWS - IoT: Multiple rules with single function', () => { - beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should trigger function when ruletopic message is published', () => Utils - .publishIotData('mybutton', '{"message":"hello serverless"}') - .then(() => Utils.publishIotData('weather', '{"message":"sunny today"}')) - .delay(60000) - .then(() => { - const logs = Utils.getFunctionLogs('iot1'); - expect(/{"message":"hello serverless"}/g.test(logs)).to.equal(true); - expect(/{"message":"sunny today"}/g.test(logs)).to.equal(true); - }) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/iot/single-rule-multiple-functions/service/handler.js b/tests/integration/aws/iot/single-rule-multiple-functions/service/handler.js deleted file mode 100644 index cdfd5c5b9..000000000 --- a/tests/integration/aws/iot/single-rule-multiple-functions/service/handler.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -module.exports.iot1 = (event, context, callback) => { - process.stdout.write(JSON.stringify(event)); - callback(null, {}); -}; - -module.exports.iot2 = (event, context, callback) => { - process.stdout.write(JSON.stringify(event)); - callback(null, {}); -}; diff --git a/tests/integration/aws/iot/single-rule-multiple-functions/service/serverless.yml b/tests/integration/aws/iot/single-rule-multiple-functions/service/serverless.yml deleted file mode 100644 index 0d8e4d393..000000000 --- a/tests/integration/aws/iot/single-rule-multiple-functions/service/serverless.yml +++ /dev/null @@ -1,17 +0,0 @@ -service: aws-nodejs - -provider: - name: aws - runtime: nodejs10.x - -functions: - iot1: - handler: handler.iot1 - events: - - iot: - sql: "SELECT * FROM 'mybutton'" - iot2: - handler: handler.iot2 - events: - - iot: - sql: "SELECT * FROM 'mybutton'" diff --git a/tests/integration/aws/iot/single-rule-multiple-functions/tests.js b/tests/integration/aws/iot/single-rule-multiple-functions/tests.js deleted file mode 100644 index cddc707f0..000000000 --- a/tests/integration/aws/iot/single-rule-multiple-functions/tests.js +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const Utils = require('../../../../utils/index'); - -describe('AWS - IoT: Single rule with multiple functions', () => { - beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should trigger function when ruletopic message is published', () => Utils - .publishIotData('mybutton', '{"message":"hello serverless"}') - .delay(60000) - .then(() => { - const iot1Logs = Utils.getFunctionLogs('iot1'); - const iot2Logs = Utils.getFunctionLogs('iot2'); - expect(/{"message":"hello serverless"}/g.test(iot1Logs)).to.equal(true); - expect(/{"message":"hello serverless"}/g.test(iot2Logs)).to.equal(true); - }) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/iot/single-rule-single-function/service/handler.js b/tests/integration/aws/iot/single-rule-single-function/service/handler.js deleted file mode 100644 index 0f770c560..000000000 --- a/tests/integration/aws/iot/single-rule-single-function/service/handler.js +++ /dev/null @@ -1,6 +0,0 @@ -'use strict'; - -module.exports.iot1 = (event, context, callback) => { - process.stdout.write(JSON.stringify(event)); - callback(null, {}); -}; diff --git a/tests/integration/aws/iot/single-rule-single-function/service/serverless.yml b/tests/integration/aws/iot/single-rule-single-function/service/serverless.yml deleted file mode 100644 index cb7ecf35f..000000000 --- a/tests/integration/aws/iot/single-rule-single-function/service/serverless.yml +++ /dev/null @@ -1,12 +0,0 @@ -service: aws-nodejs - -provider: - name: aws - runtime: nodejs10.x - -functions: - iot1: - handler: handler.iot1 - events: - - iot: - sql: "SELECT * FROM 'mybutton'" diff --git a/tests/integration/aws/iot/single-rule-single-function/tests.js b/tests/integration/aws/iot/single-rule-single-function/tests.js deleted file mode 100644 index eaf3cb11f..000000000 --- a/tests/integration/aws/iot/single-rule-single-function/tests.js +++ /dev/null @@ -1,25 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const Utils = require('../../../../utils/index'); - -describe('AWS - IoT: Single rule with single function', () => { - beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should trigger function when ruletopic message is published', () => Utils - .publishIotData('mybutton', '{"message":"hello serverless"}') - .delay(60000) - .then(() => { - const logs = Utils.getFunctionLogs('iot1'); - expect(/{"message":"hello serverless"}/g.test(logs)).to.equal(true); - }) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/s3/multiple-events-multiple-functions-multiple-buckets/service/handler.js b/tests/integration/aws/s3/multiple-events-multiple-functions-multiple-buckets/service/handler.js deleted file mode 100644 index 5a96f3a31..000000000 --- a/tests/integration/aws/s3/multiple-events-multiple-functions-multiple-buckets/service/handler.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict'; - -module.exports.hello = (event, context, callback) => { - process.stdout.write(event.Records[0].eventSource); - process.stdout.write(event.Records[0].eventName); - callback(null, { message: 'Hello from S3!', event }); -}; - -module.exports.world = (event, context, callback) => { - process.stdout.write(event.Records[0].eventSource); - process.stdout.write(event.Records[0].eventName); - callback(null, { message: 'Hello from S3!', event }); -}; diff --git a/tests/integration/aws/s3/multiple-events-multiple-functions-multiple-buckets/service/serverless.yml b/tests/integration/aws/s3/multiple-events-multiple-functions-multiple-buckets/service/serverless.yml deleted file mode 100644 index 05cee4c24..000000000 --- a/tests/integration/aws/s3/multiple-events-multiple-functions-multiple-buckets/service/serverless.yml +++ /dev/null @@ -1,21 +0,0 @@ -service: aws-nodejs - -provider: - name: aws - runtime: nodejs10.x - -functions: - hello: - handler: handler.hello - events: - - s3: ${env:BUCKET_1} - - s3: - bucket: ${env:BUCKET_1} - event: s3:ObjectRemoved:* - world: - handler: handler.world - events: - - s3: ${env:BUCKET_2} - - s3: - bucket: ${env:BUCKET_2} - event: s3:ObjectRemoved:* diff --git a/tests/integration/aws/s3/multiple-events-multiple-functions-multiple-buckets/tests.js b/tests/integration/aws/s3/multiple-events-multiple-functions-multiple-buckets/tests.js deleted file mode 100644 index 1b667c068..000000000 --- a/tests/integration/aws/s3/multiple-events-multiple-functions-multiple-buckets/tests.js +++ /dev/null @@ -1,34 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const Utils = require('../../../../utils/index'); - -describe('AWS - S3: Multiple events in multiple functions with multiple buckets', () => { - beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should trigger functions when object created or deleted in buckets', () => Utils - .createAndRemoveInBucket(process.env.BUCKET_1) - .then(() => Utils.createAndRemoveInBucket(process.env.BUCKET_2)) - .delay(60000) - .then(() => { - const helloLogs = Utils.getFunctionLogs('hello'); - const worldLogs = Utils.getFunctionLogs('world'); - - expect(/aws:s3/g.test(helloLogs)).to.equal(true); - expect(/ObjectCreated:Put/g.test(helloLogs)).to.equal(true); - expect(/ObjectRemoved:Delete/g.test(helloLogs)).to.equal(true); - - expect(/aws:s3/g.test(worldLogs)).to.equal(true); - expect(/ObjectCreated:Put/g.test(worldLogs)).to.equal(true); - expect(/ObjectRemoved:Delete/g.test(worldLogs)).to.equal(true); - }) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/s3/multiple-events-multiple-functions-single-bucket/service/handler.js b/tests/integration/aws/s3/multiple-events-multiple-functions-single-bucket/service/handler.js deleted file mode 100644 index d742ed551..000000000 --- a/tests/integration/aws/s3/multiple-events-multiple-functions-single-bucket/service/handler.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict'; - -module.exports.create = (event, context, callback) => { - process.stdout.write(event.Records[0].eventSource); - process.stdout.write(event.Records[0].eventName); - callback(null, { message: 'Hello from S3!', event }); -}; - -module.exports.remove = (event, context, callback) => { - process.stdout.write(event.Records[0].eventSource); - process.stdout.write(event.Records[0].eventName); - callback(null, { message: 'Hello from S3!', event }); -}; diff --git a/tests/integration/aws/s3/multiple-events-multiple-functions-single-bucket/service/serverless.yml b/tests/integration/aws/s3/multiple-events-multiple-functions-single-bucket/service/serverless.yml deleted file mode 100644 index b7d95c417..000000000 --- a/tests/integration/aws/s3/multiple-events-multiple-functions-single-bucket/service/serverless.yml +++ /dev/null @@ -1,17 +0,0 @@ -service: aws-nodejs - -provider: - name: aws - runtime: nodejs10.x - -functions: - create: - handler: handler.create - events: - - s3: ${env:BUCKET_1} - remove: - handler: handler.remove - events: - - s3: - bucket: ${env:BUCKET_1} - event: s3:ObjectRemoved:* diff --git a/tests/integration/aws/s3/multiple-events-multiple-functions-single-bucket/tests.js b/tests/integration/aws/s3/multiple-events-multiple-functions-single-bucket/tests.js deleted file mode 100644 index 03a0aab68..000000000 --- a/tests/integration/aws/s3/multiple-events-multiple-functions-single-bucket/tests.js +++ /dev/null @@ -1,30 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const Utils = require('../../../../utils/index'); - -describe('AWS - S3: Multiple events in multiple functions with a single bucket', () => { - beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should trigger create/remove functions on object create / remove', () => Utils - .createAndRemoveInBucket(process.env.BUCKET_1) - .delay(60000) - .then(() => { - const createLogs = Utils.getFunctionLogs('create'); - const removeLogs = Utils.getFunctionLogs('remove'); - - expect(/aws:s3/g.test(createLogs)).to.equal(true); - expect(/aws:s3/g.test(removeLogs)).to.equal(true); - expect(/ObjectCreated:Put/g.test(createLogs)).to.equal(true); - expect(/ObjectRemoved:Delete/g.test(removeLogs)).to.equal(true); - }) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/s3/multiple-events-single-function-single-bucket/service/handler.js b/tests/integration/aws/s3/multiple-events-single-function-single-bucket/service/handler.js deleted file mode 100644 index aaa093a8c..000000000 --- a/tests/integration/aws/s3/multiple-events-single-function-single-bucket/service/handler.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict'; - -module.exports.hello = (event, context, callback) => { - process.stdout.write(event.Records[0].eventSource); - process.stdout.write(event.Records[0].eventName); - callback(null, { message: 'Hello from S3!', event }); -}; diff --git a/tests/integration/aws/s3/multiple-events-single-function-single-bucket/service/serverless.yml b/tests/integration/aws/s3/multiple-events-single-function-single-bucket/service/serverless.yml deleted file mode 100644 index 212cb8ab2..000000000 --- a/tests/integration/aws/s3/multiple-events-single-function-single-bucket/service/serverless.yml +++ /dev/null @@ -1,14 +0,0 @@ -service: aws-nodejs - -provider: - name: aws - runtime: nodejs10.x - -functions: - hello: - handler: handler.hello - events: - - s3: ${env:BUCKET_1} - - s3: - bucket: ${env:BUCKET_1} - event: s3:ObjectRemoved:* diff --git a/tests/integration/aws/s3/multiple-events-single-function-single-bucket/tests.js b/tests/integration/aws/s3/multiple-events-single-function-single-bucket/tests.js deleted file mode 100644 index e7db28191..000000000 --- a/tests/integration/aws/s3/multiple-events-single-function-single-bucket/tests.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const Utils = require('../../../../utils/index'); - -describe('AWS - S3: Multiple events in a single function with a single bucket', () => { - beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should trigger function when object created or deleted in bucket', () => Utils - .createAndRemoveInBucket(process.env.BUCKET_1) - .delay(60000) - .then(() => { - const logs = Utils.getFunctionLogs('hello'); - - expect(/aws:s3/g.test(logs)).to.equal(true); - expect(/ObjectCreated:Put/g.test(logs)).to.equal(true); - expect(/ObjectRemoved:Delete/g.test(logs)).to.equal(true); - }) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/s3/single-event-single-function-single-bucket/service/handler.js b/tests/integration/aws/s3/single-event-single-function-single-bucket/service/handler.js deleted file mode 100644 index aaa093a8c..000000000 --- a/tests/integration/aws/s3/single-event-single-function-single-bucket/service/handler.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict'; - -module.exports.hello = (event, context, callback) => { - process.stdout.write(event.Records[0].eventSource); - process.stdout.write(event.Records[0].eventName); - callback(null, { message: 'Hello from S3!', event }); -}; diff --git a/tests/integration/aws/s3/single-event-single-function-single-bucket/service/serverless.yml b/tests/integration/aws/s3/single-event-single-function-single-bucket/service/serverless.yml deleted file mode 100644 index 17446857c..000000000 --- a/tests/integration/aws/s3/single-event-single-function-single-bucket/service/serverless.yml +++ /dev/null @@ -1,12 +0,0 @@ - -service: aws-nodejs - -provider: - name: aws - runtime: nodejs10.x - -functions: - hello: - handler: handler.hello - events: - - s3: ${env:BUCKET_1} diff --git a/tests/integration/aws/s3/single-event-single-function-single-bucket/tests.js b/tests/integration/aws/s3/single-event-single-function-single-bucket/tests.js deleted file mode 100644 index 7c09075a2..000000000 --- a/tests/integration/aws/s3/single-event-single-function-single-bucket/tests.js +++ /dev/null @@ -1,26 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const Utils = require('../../../../utils/index'); - -describe('AWS - S3: Single event in a single function with a single bucket', () => { - beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should trigger function when object created in bucket', () => Utils - .createAndRemoveInBucket(process.env.BUCKET_1) - .delay(60000) - .then(() => { - const logs = Utils.getFunctionLogs('hello'); - expect(/aws:s3/g.test(logs)).to.equal(true); - expect(/ObjectCreated:Put/g.test(logs)).to.equal(true); - }) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/schedule/multiple-schedules-multiple-functions/service/handler.js b/tests/integration/aws/schedule/multiple-schedules-multiple-functions/service/handler.js deleted file mode 100644 index 424b93300..000000000 --- a/tests/integration/aws/schedule/multiple-schedules-multiple-functions/service/handler.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict'; - -module.exports.hello = (event, context, callback) => { - process.stdout.write(event.source); - process.stdout.write(event['detail-type']); - callback(null, { message: 'Hello from Schedule!', event }); -}; - -module.exports.world = (event, context, callback) => { - process.stdout.write(event.source); - process.stdout.write(event['detail-type']); - callback(null, { message: 'Hello from Schedule!', event }); -}; diff --git a/tests/integration/aws/schedule/multiple-schedules-multiple-functions/service/serverless.yml b/tests/integration/aws/schedule/multiple-schedules-multiple-functions/service/serverless.yml deleted file mode 100644 index 6bcb6fe38..000000000 --- a/tests/integration/aws/schedule/multiple-schedules-multiple-functions/service/serverless.yml +++ /dev/null @@ -1,15 +0,0 @@ -service: aws-nodejs - -provider: - name: aws - runtime: nodejs10.x - -functions: - hello: - handler: handler.hello - events: - - schedule: rate(1 minute) - world: - handler: handler.world - events: - - schedule: rate(1 minute) diff --git a/tests/integration/aws/schedule/multiple-schedules-multiple-functions/tests.js b/tests/integration/aws/schedule/multiple-schedules-multiple-functions/tests.js deleted file mode 100644 index 51ae9cb57..000000000 --- a/tests/integration/aws/schedule/multiple-schedules-multiple-functions/tests.js +++ /dev/null @@ -1,30 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const Utils = require('../../../../utils/index'); -const BbPromise = require('bluebird'); - -describe('AWS - Schedule: Multiple schedules with multiple functions', () => { - beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should trigger functions every minute', () => BbPromise.resolve() - .delay(100000) - .then(() => { - const helloLogs = Utils.getFunctionLogs('hello'); - const worldLogs = Utils.getFunctionLogs('world'); - - expect(/Scheduled Event/g.test(helloLogs)).to.equal(true); - expect(/aws\.events/g.test(helloLogs)).to.equal(true); - expect(/Scheduled Event/g.test(worldLogs)).to.equal(true); - expect(/aws\.events/g.test(worldLogs)).to.equal(true); - }) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/sns/existing-topic/service/handler.js b/tests/integration/aws/sns/existing-topic/service/handler.js deleted file mode 100644 index f3f54b9ab..000000000 --- a/tests/integration/aws/sns/existing-topic/service/handler.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict'; - -module.exports.hello = (event, context, callback) => { - process.stdout.write(event.Records[0].EventSource); - process.stdout.write(event.Records[0].Sns.Message); - callback(null, { message: 'Hello from SNS!', event }); -}; diff --git a/tests/integration/aws/sns/existing-topic/service/serverless.yml b/tests/integration/aws/sns/existing-topic/service/serverless.yml deleted file mode 100644 index 8be85bc03..000000000 --- a/tests/integration/aws/sns/existing-topic/service/serverless.yml +++ /dev/null @@ -1,20 +0,0 @@ -service: aws-nodejs - -provider: - name: aws - runtime: nodejs10.x - -functions: - hello: - handler: handler.hello - events: - - sns: - arn: - Fn::Join: - - ':' - - - - 'arn:aws:sns' - - ${env:EXISTING_TOPIC_REGION} - - ${env:EXISTING_TOPIC_ACCOUNT} - - ${env:EXISTING_TOPIC_NAME} - topicName: ${env:EXISTING_TOPIC_NAME} diff --git a/tests/integration/aws/sns/existing-topic/tests.js b/tests/integration/aws/sns/existing-topic/tests.js deleted file mode 100644 index 414bd3e76..000000000 --- a/tests/integration/aws/sns/existing-topic/tests.js +++ /dev/null @@ -1,38 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const Utils = require('../../../../utils/index'); -const uuid = require('uuid'); - -describe('AWS - SNS: Existing topic with single function', () => { - const snsTopic = uuid.v4(); - - beforeAll(() => Utils.createSnsTopic(snsTopic) - .then((result) => { - const splitTopicArn = result.topicArn.split(':'); - process.env.EXISTING_TOPIC_REGION = splitTopicArn[3]; - process.env.EXISTING_TOPIC_ACCOUNT = splitTopicArn[4]; - process.env.EXISTING_TOPIC_NAME = splitTopicArn[5]; - }) - .then(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }) - ); - - it('should trigger function when new message is published', () => Utils - .publishSnsMessage(snsTopic, 'hello world') - .delay(60000) - .then(() => { - const logs = Utils.getFunctionLogs('hello'); - expect(/aws:sns/g.test(logs)).to.equal(true); - expect(/hello world/g.test(logs)).to.equal(true); - }) - ); - - afterAll(() => { - Utils.removeService(); - Utils.removeSnsTopic(snsTopic); - }); -}); diff --git a/tests/integration/aws/sns/multiple-topics-multiple-functions/service/handler.js b/tests/integration/aws/sns/multiple-topics-multiple-functions/service/handler.js deleted file mode 100644 index 9d0517bea..000000000 --- a/tests/integration/aws/sns/multiple-topics-multiple-functions/service/handler.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict'; - -module.exports.hello = (event, context, callback) => { - process.stdout.write(event.Records[0].EventSource); - process.stdout.write(event.Records[0].Sns.Message); - callback(null, { message: 'Hello from SNS!', event }); -}; - -module.exports.world = (event, context, callback) => { - process.stdout.write(event.Records[0].EventSource); - process.stdout.write(event.Records[0].Sns.Message); - callback(null, { message: 'Hello from SNS!', event }); -}; diff --git a/tests/integration/aws/sns/multiple-topics-multiple-functions/service/serverless.yml b/tests/integration/aws/sns/multiple-topics-multiple-functions/service/serverless.yml deleted file mode 100644 index 209f3cba8..000000000 --- a/tests/integration/aws/sns/multiple-topics-multiple-functions/service/serverless.yml +++ /dev/null @@ -1,15 +0,0 @@ -service: aws-nodejs - -provider: - name: aws - runtime: nodejs10.x - -functions: - hello: - handler: handler.hello - events: - - sns: ${env:TOPIC_1} - world: - handler: handler.world - events: - - sns: ${env:TOPIC_2} diff --git a/tests/integration/aws/sns/multiple-topics-multiple-functions/tests.js b/tests/integration/aws/sns/multiple-topics-multiple-functions/tests.js deleted file mode 100644 index df3420898..000000000 --- a/tests/integration/aws/sns/multiple-topics-multiple-functions/tests.js +++ /dev/null @@ -1,31 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const Utils = require('../../../../utils/index'); - -describe('AWS - SNS: Multiple topics with multiple functions', () => { - beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should trigger function when new message is published', () => Utils - .publishSnsMessage(process.env.TOPIC_1, 'topic1') - .then(() => Utils.publishSnsMessage(process.env.TOPIC_2, 'topic2')) - .delay(60000) - .then(() => { - const helloLogs = Utils.getFunctionLogs('hello'); - const worldLogs = Utils.getFunctionLogs('world'); - - expect(/aws:sns/g.test(helloLogs)).to.equal(true); - expect(/topic1/g.test(helloLogs)).to.equal(true); - expect(/aws:sns/g.test(worldLogs)).to.equal(true); - expect(/topic2/g.test(worldLogs)).to.equal(true); - }) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/sns/multiple-topics-single-function/service/handler.js b/tests/integration/aws/sns/multiple-topics-single-function/service/handler.js deleted file mode 100644 index f3f54b9ab..000000000 --- a/tests/integration/aws/sns/multiple-topics-single-function/service/handler.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict'; - -module.exports.hello = (event, context, callback) => { - process.stdout.write(event.Records[0].EventSource); - process.stdout.write(event.Records[0].Sns.Message); - callback(null, { message: 'Hello from SNS!', event }); -}; diff --git a/tests/integration/aws/sns/multiple-topics-single-function/service/serverless.yml b/tests/integration/aws/sns/multiple-topics-single-function/service/serverless.yml deleted file mode 100644 index c0f1f29f9..000000000 --- a/tests/integration/aws/sns/multiple-topics-single-function/service/serverless.yml +++ /dev/null @@ -1,12 +0,0 @@ -service: aws-nodejs - -provider: - name: aws - runtime: nodejs10.x - -functions: - hello: - handler: handler.hello - events: - - sns: ${env:TOPIC_1} - - sns: ${env:TOPIC_2} diff --git a/tests/integration/aws/sns/multiple-topics-single-function/tests.js b/tests/integration/aws/sns/multiple-topics-single-function/tests.js deleted file mode 100644 index 6c6122cce..000000000 --- a/tests/integration/aws/sns/multiple-topics-single-function/tests.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const Utils = require('../../../../utils/index'); - -describe('AWS - SNS: Multiple topics single function', () => { - beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should trigger function when new message is published', () => Utils - .publishSnsMessage(process.env.TOPIC_1, 'topic1') - .then(() => Utils.publishSnsMessage(process.env.TOPIC_2, 'topic2')) - .delay(60000) - .then(() => { - const logs = Utils.getFunctionLogs('hello'); - expect(/aws:sns/g.test(logs)).to.equal(true); - expect(/topic1/g.test(logs)).to.equal(true); - expect(/topic2/g.test(logs)).to.equal(true); - }) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/sns/single-topic-multiple-functions/service/handler.js b/tests/integration/aws/sns/single-topic-multiple-functions/service/handler.js deleted file mode 100644 index 9d0517bea..000000000 --- a/tests/integration/aws/sns/single-topic-multiple-functions/service/handler.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict'; - -module.exports.hello = (event, context, callback) => { - process.stdout.write(event.Records[0].EventSource); - process.stdout.write(event.Records[0].Sns.Message); - callback(null, { message: 'Hello from SNS!', event }); -}; - -module.exports.world = (event, context, callback) => { - process.stdout.write(event.Records[0].EventSource); - process.stdout.write(event.Records[0].Sns.Message); - callback(null, { message: 'Hello from SNS!', event }); -}; diff --git a/tests/integration/aws/sns/single-topic-multiple-functions/service/serverless.yml b/tests/integration/aws/sns/single-topic-multiple-functions/service/serverless.yml deleted file mode 100644 index e81c8c2c6..000000000 --- a/tests/integration/aws/sns/single-topic-multiple-functions/service/serverless.yml +++ /dev/null @@ -1,15 +0,0 @@ -service: aws-nodejs - -provider: - name: aws - runtime: nodejs10.x - -functions: - hello: - handler: handler.hello - events: - - sns: ${env:TOPIC_1} - world: - handler: handler.world - events: - - sns: ${env:TOPIC_1} diff --git a/tests/integration/aws/sns/single-topic-multiple-functions/tests.js b/tests/integration/aws/sns/single-topic-multiple-functions/tests.js deleted file mode 100644 index 03b4977ca..000000000 --- a/tests/integration/aws/sns/single-topic-multiple-functions/tests.js +++ /dev/null @@ -1,30 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const Utils = require('../../../../utils/index'); - -describe('AWS - SNS: Single topic with multiple functions', () => { - beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should trigger function when new message is published', () => Utils - .publishSnsMessage(process.env.TOPIC_1, 'hello world') - .delay(60000) - .then(() => { - const helloLogs = Utils.getFunctionLogs('hello'); - const worldLogs = Utils.getFunctionLogs('world'); - - expect(/aws:sns/g.test(helloLogs)).to.equal(true); - expect(/hello world/g.test(helloLogs)).to.equal(true); - expect(/aws:sns/g.test(worldLogs)).to.equal(true); - expect(/hello world/g.test(worldLogs)).to.equal(true); - }) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/aws/sns/single-topic-single-function/service/handler.js b/tests/integration/aws/sns/single-topic-single-function/service/handler.js deleted file mode 100644 index f3f54b9ab..000000000 --- a/tests/integration/aws/sns/single-topic-single-function/service/handler.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict'; - -module.exports.hello = (event, context, callback) => { - process.stdout.write(event.Records[0].EventSource); - process.stdout.write(event.Records[0].Sns.Message); - callback(null, { message: 'Hello from SNS!', event }); -}; diff --git a/tests/integration/aws/sns/single-topic-single-function/service/serverless.yml b/tests/integration/aws/sns/single-topic-single-function/service/serverless.yml deleted file mode 100644 index 3430ea40c..000000000 --- a/tests/integration/aws/sns/single-topic-single-function/service/serverless.yml +++ /dev/null @@ -1,11 +0,0 @@ -service: aws-nodejs - -provider: - name: aws - runtime: nodejs10.x - -functions: - hello: - handler: handler.hello - events: - - sns: ${env:TOPIC_1} diff --git a/tests/integration/aws/sns/single-topic-single-function/tests.js b/tests/integration/aws/sns/single-topic-single-function/tests.js deleted file mode 100644 index fcf655144..000000000 --- a/tests/integration/aws/sns/single-topic-single-function/tests.js +++ /dev/null @@ -1,26 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const Utils = require('../../../../utils/index'); - -describe('AWS - SNS: Single topic with single function', () => { - beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - Utils.deployService(); - }); - - it('should trigger function when new message is published', () => Utils - .publishSnsMessage(process.env.TOPIC_1, 'hello world') - .delay(60000) - .then(() => { - const logs = Utils.getFunctionLogs('hello'); - expect(/aws:sns/g.test(logs)).to.equal(true); - expect(/hello world/g.test(logs)).to.equal(true); - }) - ); - - afterAll(() => { - Utils.removeService(); - }); -}); diff --git a/tests/integration/general/custom-plugins/service/handler.js b/tests/integration/general/custom-plugins/service/handler.js deleted file mode 100644 index 6313e306f..000000000 --- a/tests/integration/general/custom-plugins/service/handler.js +++ /dev/null @@ -1,6 +0,0 @@ -'use strict'; - -// Your first function handler -module.exports.hello = (event, context, callback) => { - callback(null, { message: 'Go Serverless v1.0! Your function executed successfully!', event }); -}; diff --git a/tests/integration/general/custom-plugins/service/package.json b/tests/integration/general/custom-plugins/service/package.json deleted file mode 100644 index 2970090d2..000000000 --- a/tests/integration/general/custom-plugins/service/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "test-service", - "version": "0.1.0", - "dependencies": {} -} diff --git a/tests/integration/general/custom-plugins/service/serverless-plugin-greeter/main.js b/tests/integration/general/custom-plugins/service/serverless-plugin-greeter/main.js deleted file mode 100644 index 0d028622a..000000000 --- a/tests/integration/general/custom-plugins/service/serverless-plugin-greeter/main.js +++ /dev/null @@ -1,26 +0,0 @@ -'use strict'; - -class Greeter { - constructor(serverless, options) { - this.serverless = serverless; - this.options = options; - - this.commands = { - greet: { - lifecycleEvents: [ - 'greet', - ], - }, - }; - - this.hooks = { - 'greet:greet': this.greet.bind(this), - }; - } - - greet() { - process.stdout.write('Hello from the greeter plugin!'); - } -} - -module.exports = Greeter; diff --git a/tests/integration/general/custom-plugins/service/serverless-plugin-greeter/package.json b/tests/integration/general/custom-plugins/service/serverless-plugin-greeter/package.json deleted file mode 100644 index ff4faea7e..000000000 --- a/tests/integration/general/custom-plugins/service/serverless-plugin-greeter/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "serverless-plugin-greeter", - "version": "0.1.0", - "main": "main.js" -} diff --git a/tests/integration/general/custom-plugins/service/serverless.yml b/tests/integration/general/custom-plugins/service/serverless.yml deleted file mode 100644 index b572235a4..000000000 --- a/tests/integration/general/custom-plugins/service/serverless.yml +++ /dev/null @@ -1,12 +0,0 @@ -service: aws-nodejs # NOTE: update this with your service name - -provider: - name: aws - runtime: nodejs10.x - -functions: - hello: - handler: handler.hello - -plugins: - - serverless-plugin-greeter diff --git a/tests/integration/general/custom-plugins/tests.js b/tests/integration/general/custom-plugins/tests.js deleted file mode 100644 index 6da6213f6..000000000 --- a/tests/integration/general/custom-plugins/tests.js +++ /dev/null @@ -1,36 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const execSync = require('child_process').execSync; - -const Utils = require('../../../utils/index'); - -describe('General: Custom plugins test', () => { - beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - - // cd into the plugins directory - execSync('cd serverless-plugin-greeter'); - - // link and install the npm package / plugin - execSync('npm link serverless-plugin-greeter && npm install --save serverless-plugin-greeter'); - - // cd back into the service directory - execSync('cd ..'); - }); - - it('should successfully run the greet command of the custom plugin', () => { - const pluginExecution = execSync(`${Utils.serverlessExec} greet`); - - // note: the result will return a newline at the end - const result = new Buffer(pluginExecution, 'base64').toString(); - - expect(result).to.equal('Hello from the greeter plugin!'); - }); - - afterAll(() => { - // unlink the npm package - execSync('npm r serverless-plugin-greeter -g'); - }); -}); diff --git a/tests/integration/general/local-plugins/service/.serverless_plugins/one.js b/tests/integration/general/local-plugins/service/.serverless_plugins/one.js deleted file mode 100644 index 016b2416e..000000000 --- a/tests/integration/general/local-plugins/service/.serverless_plugins/one.js +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; - -class ServerlessPlugin { - constructor(serverless, options) { - this.serverless = serverless; - this.options = options; - - this.commands = { - one: { - usage: 'test plugin', - lifecycleEvents: [ - 'hello', - ], - }, - }; - - this.hooks = { - 'before:one:hello': this.beforeWelcome.bind(this), - }; - } - - beforeWelcome() { - this.serverless.cli.log('plugin one ran successfully!'); - } -} - -module.exports = ServerlessPlugin; diff --git a/tests/integration/general/local-plugins/service/.serverless_plugins/two/index.js b/tests/integration/general/local-plugins/service/.serverless_plugins/two/index.js deleted file mode 100644 index 566e6647a..000000000 --- a/tests/integration/general/local-plugins/service/.serverless_plugins/two/index.js +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; - -class ServerlessPlugin { - constructor(serverless, options) { - this.serverless = serverless; - this.options = options; - - this.commands = { - two: { - usage: 'test plugin', - lifecycleEvents: [ - 'hello', - ], - }, - }; - - this.hooks = { - 'before:two:hello': this.beforeWelcome.bind(this), - }; - } - - beforeWelcome() { - this.serverless.cli.log('plugin two ran successfully!'); - } -} - -module.exports = ServerlessPlugin; diff --git a/tests/integration/general/local-plugins/service/handler.js b/tests/integration/general/local-plugins/service/handler.js deleted file mode 100644 index 6313e306f..000000000 --- a/tests/integration/general/local-plugins/service/handler.js +++ /dev/null @@ -1,6 +0,0 @@ -'use strict'; - -// Your first function handler -module.exports.hello = (event, context, callback) => { - callback(null, { message: 'Go Serverless v1.0! Your function executed successfully!', event }); -}; diff --git a/tests/integration/general/local-plugins/service/serverless.yml b/tests/integration/general/local-plugins/service/serverless.yml deleted file mode 100644 index c89417975..000000000 --- a/tests/integration/general/local-plugins/service/serverless.yml +++ /dev/null @@ -1,13 +0,0 @@ -service: aws-nodejs # NOTE: update this with your service name - -provider: - name: aws - runtime: nodejs10.x - -functions: - hello: - handler: handler.hello - -plugins: - - one - - two diff --git a/tests/integration/general/local-plugins/tests.js b/tests/integration/general/local-plugins/tests.js deleted file mode 100644 index 54594cf22..000000000 --- a/tests/integration/general/local-plugins/tests.js +++ /dev/null @@ -1,25 +0,0 @@ -'use strict'; - -const path = require('path'); -const expect = require('chai').expect; -const execSync = require('child_process').execSync; - -const Utils = require('../../../utils/index'); - -describe('General: Local plugins test', () => { - beforeAll(() => { - Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); - }); - - it('should successfully run the one command', () => { - const pluginExecution = execSync(`${Utils.serverlessExec} one`); - const result = new Buffer(pluginExecution, 'base64').toString(); - expect(/plugin one ran successfully/g.test(result)).to.equal(true); - }); - - it('should successfully run the two command', () => { - const pluginExecution = execSync(`${Utils.serverlessExec} two`); - const result = new Buffer(pluginExecution, 'base64').toString(); - expect(/plugin two ran successfully/g.test(result)).to.equal(true); - }); -}); diff --git a/tests/setup-tests.js b/tests/setup-tests.js new file mode 100644 index 000000000..32c0f7f96 --- /dev/null +++ b/tests/setup-tests.js @@ -0,0 +1,3 @@ +'use strict'; + +jest.setTimeout(300000); diff --git a/tests/setupTests.js b/tests/setupTests.js deleted file mode 100644 index 01313fd46..000000000 --- a/tests/setupTests.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; - -// timeout is set to 5 minutes -// eslint-disable-next-line no-undef -jasmine.DEFAULT_TIMEOUT_INTERVAL = 300000; diff --git a/tests/templates/test_all_templates b/tests/templates/test-all-templates similarity index 100% rename from tests/templates/test_all_templates rename to tests/templates/test-all-templates diff --git a/tests/utils/api-gateway/index.js b/tests/utils/api-gateway/index.js new file mode 100644 index 000000000..212f9ef32 --- /dev/null +++ b/tests/utils/api-gateway/index.js @@ -0,0 +1,65 @@ +'use strict'; + +const AWS = require('aws-sdk'); +const _ = require('lodash'); +const { region, persistentRequest } = require('../misc'); + +function createRestApi(name) { + const APIG = new AWS.APIGateway({ region }); + + const params = { + name, + }; + + return APIG.createRestApi(params).promise(); +} + +function deleteRestApi(restApiId) { + const APIG = new AWS.APIGateway({ region }); + + const params = { + restApiId, + }; + + return APIG.deleteRestApi(params).promise(); +} + +function getResources(restApiId) { + const APIG = new AWS.APIGateway({ region }); + + const params = { + restApiId, + }; + + return APIG.getResources(params).promise() + .then((data) => data.items); +} + +function findRestApis(name) { + const APIG = new AWS.APIGateway({ region }); + + const params = { + limit: 500, + }; + + function recursiveFind(found, position) { + if (position) params.position = position; + return APIG.getRestApis(params).promise().then(result => { + const matches = result.items.filter(restApi => restApi.name.match(name)); + if (matches.length) { + _.merge(found, matches); + } + if (result.position) return recursiveFind(found, result.position); + return found; + }); + } + + return recursiveFind([]); +} + +module.exports = { + createRestApi: persistentRequest.bind(this, createRestApi), + deleteRestApi: persistentRequest.bind(this, deleteRestApi), + getResources: persistentRequest.bind(this, getResources), + findRestApis: persistentRequest.bind(this, findRestApis), +}; diff --git a/tests/utils/aws-cleanup.js b/tests/utils/aws-cleanup.js new file mode 100644 index 000000000..85167e65f --- /dev/null +++ b/tests/utils/aws-cleanup.js @@ -0,0 +1,90 @@ +'use strict'; + +// NOTE: This script requires Node.js > 8 to run since it uses +// modern Node.js / JavaScript features such as async / await + +const { logger, testServiceIdentifier } = require('./misc'); +const { findStacks, deleteStack, listStackResources } = require('./cloudformation'); +const { findRestApis, deleteRestApi } = require('./api-gateway'); +const { deleteBucket } = require('./s3'); + +async function findDeploymentBuckets(stacks) { + const buckets = []; + for (const stack of stacks) { + const stackResources = await listStackResources(stack.StackId); + const bucket = stackResources.filter((resource) => { + return resource.LogicalResourceId === 'ServerlessDeploymentBucket'; + }); + buckets.push(...bucket); + } + return buckets; +} + +async function cleanup() { + const date = new Date(); + const yesterday = date.setDate(date.getDate() - 1); + + const status = [ + 'CREATE_FAILED', + 'CREATE_COMPLETE', + 'UPDATE_COMPLETE', + 'ROLLBACK_FAILED', + 'ROLLBACK_COMPLETE', + 'DELETE_FAILED', + 'UPDATE_ROLLBACK_FAILED', + 'UPDATE_ROLLBACK_COMPLETE', + ]; + + // find all the resources + const stacks = await findStacks(testServiceIdentifier, status); + const apis = await findRestApis(testServiceIdentifier); + + let bucketsToRemove = []; + const stacksToRemove = stacks.filter((stack) => +new Date(stack.CreationTime) < yesterday); + const apisToRemove = apis.filter((api) => +new Date(api.createdDate) < yesterday); + if (stacksToRemove) { + bucketsToRemove = await findDeploymentBuckets(stacksToRemove); + } + + logger.log(`${bucketsToRemove.length} Buckets to remove...`); + logger.log(`${stacksToRemove.length} Stacks to remove...`); + logger.log(`${apisToRemove.length} APIs to remove...`); + + if (bucketsToRemove.length) { + logger.log('Removing Buckets...'); + const promises = bucketsToRemove + .map(bucket => deleteBucket(bucket.PhysicalResourceId)); + try { + await Promise.all(promises); + } catch (error) { + // do nothing... try to continue with cleanup + } + } + + if (stacksToRemove.length) { + logger.log('Removing Stacks...'); + const promises = stacksToRemove + .map(stack => deleteStack(stack.StackName)); + try { + await Promise.all(promises); + } catch (error) { + // do nothing... try to continue with cleanup + } + } + + if (apisToRemove.length) { + logger.log('Removing APIs...'); + const promises = apisToRemove.map(api => deleteRestApi(api.id)); + try { + await Promise.all(promises); + } catch (error) { + // do nothing... try to continue with cleanup + } + } +} + +cleanup().catch((error) => { + // eslint-disable-next-line no-console + console.error(error); + process.exit(1); +}); diff --git a/tests/utils/cloudformation/index.js b/tests/utils/cloudformation/index.js new file mode 100644 index 000000000..4d651acef --- /dev/null +++ b/tests/utils/cloudformation/index.js @@ -0,0 +1,74 @@ +'use strict'; + +const AWS = require('aws-sdk'); +const { region, persistentRequest } = require('../misc'); + +function findStacks(name, status) { + const CF = new AWS.CloudFormation({ region }); + + const params = {}; + if (status) { + params.StackStatusFilter = status; + } + + function recursiveFind(found, token) { + if (token) params.NextToken = token; + return CF.listStacks(params).promise().then(result => { + const matches = result.StackSummaries.filter(stack => stack.StackName.match(name)); + if (matches.length) { + found.push(...matches); + } + if (result.NextToken) return recursiveFind(found, result.NextToken); + return found; + }); + } + + return recursiveFind([]); +} + +function deleteStack(stack) { + const CF = new AWS.CloudFormation({ region }); + + const params = { + StackName: stack, + }; + + return CF.deleteStack(params).promise(); +} + +function listStackResources(stack) { + const CF = new AWS.CloudFormation({ region }); + + const params = { + StackName: stack, + }; + + function recursiveFind(resources, token) { + if (token) params.NextToken = token; + return CF.listStackResources(params).promise().then(result => { + resources.push(...result.StackResourceSummaries); + if (result.NextToken) return recursiveFind(resources, result.NextToken); + return resources; + }); + } + + return recursiveFind([]); +} + +function listStacks(status) { + const CF = new AWS.CloudFormation({ region }); + + const params = {}; + if (status) { + params.StackStatusFilter = status; + } + + return CF.listStacks(params).promise(); +} + +module.exports = { + findStacks: persistentRequest.bind(this, findStacks), + deleteStack: persistentRequest.bind(this, deleteStack), + listStackResources: persistentRequest.bind(this, listStackResources), + listStacks: persistentRequest.bind(this, listStacks), +}; diff --git a/tests/utils/cloudwatch/index.js b/tests/utils/cloudwatch/index.js new file mode 100644 index 000000000..d9150ad25 --- /dev/null +++ b/tests/utils/cloudwatch/index.js @@ -0,0 +1,22 @@ +'use strict'; + +const AWS = require('aws-sdk'); +const { region, persistentRequest } = require('../misc'); + +function putCloudWatchEvents(sources) { + const cwe = new AWS.CloudWatchEvents({ region }); + + const entries = sources.map(source => ({ + Source: source, + DetailType: 'serverlessDetailType', + Detail: '{ "key1": "value1" }', + })); + const params = { + Entries: entries, + }; + return cwe.putEvents(params).promise(); +} + +module.exports = { + putCloudWatchEvents: persistentRequest.bind(this, putCloudWatchEvents), +}; diff --git a/tests/utils/cognito/index.js b/tests/utils/cognito/index.js new file mode 100644 index 000000000..ab942ac2d --- /dev/null +++ b/tests/utils/cognito/index.js @@ -0,0 +1,33 @@ +'use strict'; + +const AWS = require('aws-sdk'); +const { region, persistentRequest } = require('../misc'); + +function getCognitoUserPoolId(userPoolName) { + const cisp = new AWS.CognitoIdentityServiceProvider({ region }); + + const params = { + MaxResults: 50, + }; + + return cisp.listUserPools(params).promise() + .then((data) => data.UserPools.find((userPool) => + RegExp(userPoolName, 'g').test(userPool.Name)).Id + ); +} + +function createCognitoUser(userPoolId, username, password) { + const cisp = new AWS.CognitoIdentityServiceProvider({ region }); + + const params = { + UserPoolId: userPoolId, + Username: username, + TemporaryPassword: password, + }; + return cisp.adminCreateUser(params).promise(); +} + +module.exports = { + getCognitoUserPoolId: persistentRequest.bind(this, getCognitoUserPoolId), + createCognitoUser: persistentRequest.bind(this, createCognitoUser), +}; diff --git a/tests/utils/fs/index.js b/tests/utils/fs/index.js new file mode 100644 index 000000000..cc895de8f --- /dev/null +++ b/tests/utils/fs/index.js @@ -0,0 +1,47 @@ +'use strict'; + +const os = require('os'); +const path = require('path'); +const fs = require('fs'); +const crypto = require('crypto'); +const YAML = require('js-yaml'); +const JSZip = require('jszip'); + +function getTmpDirPath() { + return path.join(os.tmpdir(), + 'tmpdirs-serverless', crypto.randomBytes(8).toString('hex')); +} + +function getTmpFilePath(fileName) { + return path.join(getTmpDirPath(), fileName); +} + +function replaceTextInFile(filePath, subString, newSubString) { + const fileContent = fs.readFileSync(filePath).toString(); + fs.writeFileSync(filePath, fileContent.replace(subString, newSubString)); +} + +function readYamlFile(filePath) { + const content = fs.readFileSync(filePath, 'utf8'); + return YAML.safeLoad(content); +} + +function writeYamlFile(filePath, content) { + const yaml = YAML.safeDump(content); + fs.writeFileSync(filePath, yaml); + return yaml; +} + +function listZipFiles(filename) { + return new JSZip().loadAsync(fs.readFileSync(filename)) + .then(zip => Object.keys(zip.files)); +} + +module.exports = { + getTmpDirPath, + getTmpFilePath, + replaceTextInFile, + readYamlFile, + writeYamlFile, + listZipFiles, +}; diff --git a/tests/utils/index.js b/tests/utils/index.js deleted file mode 100644 index 081ea7a56..000000000 --- a/tests/utils/index.js +++ /dev/null @@ -1,244 +0,0 @@ -'use strict'; - -const fs = require('fs'); -const os = require('os'); -const path = require('path'); -const crypto = require('crypto'); -const JSZip = require('jszip'); -const BbPromise = require('bluebird'); -const fse = require('fs-extra'); -const execSync = require('child_process').execSync; -const AWS = require('aws-sdk'); - -// mock to test functionality bound to a serverless plugin -class ServerlessPlugin { - constructor(serverless, options, testSubject) { - this.options = options; - this.serverless = serverless; - - Object.assign( - this, - testSubject - ); - } -} - -const serverlessExec = path.join(__dirname, '..', '..', 'bin', 'serverless'); - -const getTmpDirPath = () => path.join(os.tmpdir(), - 'tmpdirs-serverless', 'serverless', crypto.randomBytes(8).toString('hex')); - -const getTmpFilePath = (fileName) => path.join(getTmpDirPath(), fileName); - -const replaceTextInFile = (filePath, subString, newSubString) => { - const fileContent = fs.readFileSync(filePath).toString(); - fs.writeFileSync(filePath, fileContent.replace(subString, newSubString)); -}; - -const listZipFiles = filename => new JSZip().loadAsync(fs.readFileSync(filename)) - .then(zip => Object.keys(zip.files)); - -module.exports = { - serverlessExec, - getTmpDirPath, - getTmpFilePath, - replaceTextInFile, - ServerlessPlugin, - listZipFiles, - - createTestService: (templateName, testServiceDir) => { - const hrtime = process.hrtime(); - const serviceName = `test-${hrtime[0]}-${hrtime[1]}`; - const tmpDir = path.join(os.tmpdir(), - 'tmpdirs-serverless', - 'integration-test-suite', - crypto.randomBytes(8).toString('hex')); - - fse.mkdirsSync(tmpDir); - process.chdir(tmpDir); - - // create a new Serverless service - execSync(`${serverlessExec} create --template ${templateName}`, { stdio: 'inherit' }); - - if (testServiceDir) { - fse.copySync(testServiceDir, tmpDir, { clobber: true, preserveTimestamps: true }); - } - - replaceTextInFile('serverless.yml', templateName, serviceName); - - process.env.TOPIC_1 = `${serviceName}-1`; - process.env.TOPIC_2 = `${serviceName}-1`; - process.env.BUCKET_1 = `${serviceName}-1`; - process.env.BUCKET_2 = `${serviceName}-2`; - process.env.COGNITO_USER_POOL_1 = `${serviceName}-1`; - process.env.COGNITO_USER_POOL_2 = `${serviceName}-2`; - - // return the name of the CloudFormation stack - return `${serviceName}-dev`; - }, - - createAndRemoveInBucket(bucketName) { - const S3 = new AWS.S3({ region: 'us-east-1' }); - BbPromise.promisifyAll(S3, { suffix: 'Promised' }); - - const params = { - Bucket: bucketName, - Key: 'object', - Body: 'hello world', - }; - - return S3.putObjectPromised(params) - .then(() => { - delete params.Body; - return S3.deleteObjectPromised(params); - }); - }, - - createSnsTopic(topicName) { - const SNS = new AWS.SNS({ region: 'us-east-1' }); - BbPromise.promisifyAll(SNS, { suffix: 'Promised' }); - - const params = { - Name: topicName, - }; - - return SNS.createTopicPromised(params); - }, - - installPlugin: (installDir, PluginClass) => { - const pluginPkg = { name: path.basename(installDir), version: '0.0.0' }; - const className = (new PluginClass()).constructor.name; - fse.outputFileSync(path.join(installDir, 'package.json'), JSON.stringify(pluginPkg), 'utf8'); - fse.outputFileSync(path.join(installDir, 'index.js'), - `"use strict";\n${PluginClass.toString()}\nmodule.exports = ${className}`, 'utf8'); - }, - - removeSnsTopic(topicName) { - const SNS = new AWS.SNS({ region: 'us-east-1' }); - BbPromise.promisifyAll(SNS, { suffix: 'Promised' }); - - return SNS.listTopicsPromised() - .then(data => { - const topicArn = data.Topics.find(topic => RegExp(topicName, 'g') - .test(topic.TopicArn)).TopicArn; - - const params = { - TopicArn: topicArn, - }; - - return SNS.deleteTopicPromised(params); - }); - }, - - publishSnsMessage(topicName, message) { - const SNS = new AWS.SNS({ region: 'us-east-1' }); - BbPromise.promisifyAll(SNS, { suffix: 'Promised' }); - - return SNS.listTopicsPromised() - .then(data => { - const topicArn = data.Topics.find(topic => RegExp(topicName, 'g') - .test(topic.TopicArn)).TopicArn; - - const params = { - Message: message, - TopicArn: topicArn, - }; - - return SNS.publishPromised(params); - }); - }, - - publishIotData(topic, message) { - const Iot = new AWS.Iot({ region: 'us-east-1' }); - BbPromise.promisifyAll(Iot, { suffix: 'Promised' }); - - return Iot.describeEndpointPromised() - .then(data => { - const IotData = new AWS.IotData({ region: 'us-east-1', endpoint: data.endpointAddress }); - BbPromise.promisifyAll(IotData, { suffix: 'Promised' }); - - const params = { - topic, - payload: new Buffer(message), - }; - - return IotData.publishPromised(params); - }); - }, - - putCloudWatchEvents(sources) { - const cwe = new AWS.CloudWatchEvents({ region: 'us-east-1' }); - BbPromise.promisifyAll(cwe, { suffix: 'Promised' }); - - const entries = []; - sources.forEach(source => { - entries.push({ - Source: source, - DetailType: 'serverlessDetailType', - Detail: '{ "key1": "value1" }', - }); - }); - const params = { - Entries: entries, - }; - return cwe.putEventsPromised(params); - }, - - getCognitoUserPoolId(userPoolName) { - const cisp = new AWS.CognitoIdentityServiceProvider({ region: 'us-east-1' }); - BbPromise.promisifyAll(cisp, { suffix: 'Promised' }); - - const params = { - MaxResults: 50, - }; - - return cisp.listUserPoolsPromised(params) - .then((data) => data.UserPools.find((userPool) => - RegExp(userPoolName, 'g').test(userPool.Name)).Id - ); - }, - - createCognitoUser(userPoolId, username, password) { - const cisp = new AWS.CognitoIdentityServiceProvider({ region: 'us-east-1' }); - BbPromise.promisifyAll(cisp, { suffix: 'Promised' }); - - const params = { - UserPoolId: userPoolId, - Username: username, - TemporaryPassword: password, - }; - return cisp.adminCreateUserPromised(params); - }, - - getFunctionLogs(functionName) { - const logs = execSync(`${serverlessExec} logs --function ${functionName} --noGreeting true`); - const logsString = new Buffer(logs, 'base64').toString(); - process.stdout.write(logsString); - return logsString; - }, - - deployService() { - execSync(`${serverlessExec} deploy`, { stdio: 'inherit' }); - }, - - removeService() { - execSync(`${serverlessExec} remove`, { stdio: 'inherit' }); - }, - - replaceEnv(values) { - const originals = {}; - for (const key of Object.keys(values)) { - if (process.env[key]) { - originals[key] = process.env[key]; - } else { - originals[key] = 'undefined'; - } - if (values[key] === 'undefined') { - delete process.env[key]; - } else { - process.env[key] = values[key]; - } - } - return originals; - }, -}; diff --git a/tests/utils/index.test.js b/tests/utils/index.test.js deleted file mode 100644 index 16efb247e..000000000 --- a/tests/utils/index.test.js +++ /dev/null @@ -1,47 +0,0 @@ -'use strict'; - -const BbPromise = require('bluebird'); -const Serverless = require('../../lib/Serverless'); -const expect = require('chai').expect; -const testUtils = require('./index'); - -describe('Test utils', () => { - describe('#getTmpDirPath()', () => { - it('should return a valid tmpDir path', () => { - const tmpDirPath = testUtils.getTmpDirPath(); - - expect(tmpDirPath).to.match(/.+.{16}/); - }); - }); - - describe('#getTmpFilePath()', () => { - it('should return a valid tmpFile path', () => { - const fileName = 'foo.bar'; - const tmpFilePath = testUtils.getTmpFilePath(fileName); - - expect(tmpFilePath).to.match(/.+.{16}.{1}foo\.bar/); - }); - }); - - describe('ServerlessPlugin', () => { - it('should create a new ServerlessPlugin mock instance', () => { - const ServerlessPlugin = testUtils.ServerlessPlugin; - - const serverless = new Serverless(); - const options = { - stage: 'production', - region: 'my-test-region', - }; - const functionUnderTest = () => BbPromise.resolve('function under test'); - - const serverlessPlugin = new ServerlessPlugin( - serverless, - options, - functionUnderTest - ); - - expect(serverlessPlugin.serverless).to.be.instanceof(Serverless); - expect(serverlessPlugin.options).to.deep.equal(options); - }); - }); -}); diff --git a/tests/utils/iot/index.js b/tests/utils/iot/index.js new file mode 100644 index 000000000..0cadbff95 --- /dev/null +++ b/tests/utils/iot/index.js @@ -0,0 +1,24 @@ +'use strict'; + +const AWS = require('aws-sdk'); +const { region, persistentRequest } = require('../misc'); + +function publishIotData(topic, message) { + const Iot = new AWS.Iot({ region }); + + return Iot.describeEndpoint().promise() + .then(data => { + const IotData = new AWS.IotData({ region, endpoint: data.endpointAddress }); + + const params = { + topic, + payload: Buffer.from(message), + }; + + return IotData.publish(params).promise(); + }); +} + +module.exports = { + publishIotData: persistentRequest.bind(this, publishIotData), +}; diff --git a/tests/utils/misc/index.js b/tests/utils/misc/index.js new file mode 100644 index 000000000..4dd68fc7d --- /dev/null +++ b/tests/utils/misc/index.js @@ -0,0 +1,118 @@ +'use strict'; + +const path = require('path'); +const fse = require('fs-extra'); +const BbPromise = require('bluebird'); +const { execSync } = require('child_process'); +const { replaceTextInFile } = require('../fs'); + +const logger = console; + +const region = 'us-east-1'; + +const testServiceIdentifier = 'integ-test'; + +const serverlessExec = path.resolve(__dirname, '..', '..', '..', 'bin', 'serverless'); + +const serviceNameRegex = new RegExp(`${testServiceIdentifier}-d+`); + +function getServiceName() { + const hrtime = process.hrtime(); + return `${testServiceIdentifier}-${hrtime[1]}`; +} + +function deployService() { + execSync(`${serverlessExec} deploy`); +} + +function removeService() { + execSync(`${serverlessExec} remove`); +} + +function replaceEnv(values) { + const originals = {}; + for (const key of Object.keys(values)) { + if (process.env[key]) { + originals[key] = process.env[key]; + } else { + originals[key] = 'undefined'; + } + if (values[key] === 'undefined') { + delete process.env[key]; + } else { + process.env[key] = values[key]; + } + } + return originals; +} + +function createTestService(templateName, tmpDir, testServiceDir) { + const serviceName = getServiceName(); + + fse.mkdirsSync(tmpDir); + process.chdir(tmpDir); + + // create a new Serverless service + execSync(`${serverlessExec} create --template ${templateName}`); + + if (testServiceDir) { + fse.copySync(testServiceDir, tmpDir, { clobber: true, preserveTimestamps: true }); + } + + replaceTextInFile('serverless.yml', templateName, serviceName); + + process.env.TOPIC_1 = `${serviceName}-1`; + process.env.TOPIC_2 = `${serviceName}-1`; + process.env.BUCKET_1 = `${serviceName}-1`; + process.env.BUCKET_2 = `${serviceName}-2`; + process.env.COGNITO_USER_POOL_1 = `${serviceName}-1`; + process.env.COGNITO_USER_POOL_2 = `${serviceName}-2`; + + // return the name of the CloudFormation stack + return serviceName; +} + +function getFunctionLogs(functionName) { + const logs = execSync(`${serverlessExec} logs --function ${functionName} --noGreeting true`); + const logsString = Buffer.from(logs, 'base64').toString(); + process.stdout.write(logsString); + return logsString; +} + +function persistentRequest(...args) { + const func = args[0]; + const funcArgs = args.slice(1); + const MAX_TRIES = 5; + return new BbPromise((resolve, reject) => { + const doCall = (numTry) => { + return func.apply(this, funcArgs).then(resolve, e => { + if (numTry < MAX_TRIES && + ((e.providerError && e.providerError.retryable) || e.statusCode === 429)) { + logger.log( + [`Recoverable error occurred (${e.message}), sleeping for 5 seconds.`, + `Try ${numTry + 1} of ${MAX_TRIES}`].join(' ') + ); + setTimeout(doCall, 5000, numTry + 1); + } else { + reject(e); + } + }); + }; + return doCall(0); + }); +} + +module.exports = { + logger, + region, + testServiceIdentifier, + serverlessExec, + serviceNameRegex, + getServiceName, + deployService, + removeService, + replaceEnv, + createTestService, + getFunctionLogs, + persistentRequest, +}; diff --git a/tests/utils/plugins/index.js b/tests/utils/plugins/index.js new file mode 100644 index 000000000..6f422d1eb --- /dev/null +++ b/tests/utils/plugins/index.js @@ -0,0 +1,30 @@ +'use strict'; + +const path = require('path'); +const fse = require('fs-extra'); + +// mock to test functionality bound to a serverless plugin +class ServerlessPlugin { + constructor(serverless, options, testSubject) { + this.options = options; + this.serverless = serverless; + + Object.assign( + this, + testSubject + ); + } +} + +function installPlugin(installDir, PluginClass) { + const pluginPkg = { name: path.basename(installDir), version: '0.0.0' }; + const className = (new PluginClass()).constructor.name; + fse.outputFileSync(path.join(installDir, 'package.json'), JSON.stringify(pluginPkg), 'utf8'); + fse.outputFileSync(path.join(installDir, 'index.js'), + `"use strict";\n${PluginClass.toString()}\nmodule.exports = ${className}`, 'utf8'); +} + +module.exports = { + ServerlessPlugin, + installPlugin, +}; diff --git a/tests/utils/s3/index.js b/tests/utils/s3/index.js new file mode 100644 index 000000000..1e48930ab --- /dev/null +++ b/tests/utils/s3/index.js @@ -0,0 +1,54 @@ +'use strict'; + +const AWS = require('aws-sdk'); +const { region, persistentRequest } = require('../misc'); + +function createAndRemoveInBucket(bucketName) { + const S3 = new AWS.S3({ region }); + + const params = { + Bucket: bucketName, + Key: 'object', + Body: 'hello world', + }; + + return S3.putObject(params).promise() + .then(() => { + delete params.Body; + return S3.deleteObject(params); + }); +} + +function emptyBucket(bucket) { + const S3 = new AWS.S3({ region }); + + return S3.listObjects({ Bucket: bucket }) + .promise() + .then(data => { + const items = data.Contents; + const numItems = items.length; + if (numItems) { + const keys = items.map(item => Object.assign({}, { Key: item.Key })); + return S3.deleteObjects({ + Bucket: bucket, + Delete: { + Objects: keys, + }, + }).promise(); + } + return null; + }); +} + +function deleteBucket(bucket) { + const S3 = new AWS.S3({ region }); + + return emptyBucket(bucket).then(() => + S3.deleteBucket({ Bucket: bucket }).promise()); +} + +module.exports = { + createAndRemoveInBucket: persistentRequest.bind(this, createAndRemoveInBucket), + emptyBucket: persistentRequest.bind(this, emptyBucket), + deleteBucket: persistentRequest.bind(this, deleteBucket), +}; diff --git a/tests/utils/sns/index.js b/tests/utils/sns/index.js new file mode 100644 index 000000000..012293b76 --- /dev/null +++ b/tests/utils/sns/index.js @@ -0,0 +1,53 @@ +'use strict'; + +const AWS = require('aws-sdk'); +const { region, persistentRequest } = require('../misc'); + +function createSnsTopic(topicName) { + const SNS = new AWS.SNS({ region }); + + const params = { + Name: topicName, + }; + + return SNS.createTopic(params).promise(); +} + +function removeSnsTopic(topicName) { + const SNS = new AWS.SNS({ region }); + + return SNS.listTopics().promise() + .then(data => { + const topicArn = data.Topics.find(topic => RegExp(topicName, 'g') + .test(topic.TopicArn)).TopicArn; + + const params = { + TopicArn: topicArn, + }; + + return SNS.deleteTopic(params).promise(); + }); +} + +function publishSnsMessage(topicName, message) { + const SNS = new AWS.SNS({ region }); + + return SNS.listTopics().promise() + .then(data => { + const topicArn = data.Topics.find(topic => RegExp(topicName, 'g') + .test(topic.TopicArn)).TopicArn; + + const params = { + Message: message, + TopicArn: topicArn, + }; + + return SNS.publish(params).promise(); + }); +} + +module.exports = { + createSnsTopic: persistentRequest.bind(this, createSnsTopic), + removeSnsTopic: persistentRequest.bind(this, removeSnsTopic), + publishSnsMessage: persistentRequest.bind(this, publishSnsMessage), +};