diff --git a/package-lock.json b/package-lock.json index dda4f199f..461745c14 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2416,71 +2416,45 @@ } }, "archiver": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/archiver/-/archiver-3.1.1.tgz", - "integrity": "sha512-5Hxxcig7gw5Jod/8Gq0OneVgLYET+oNHcxgWItq4TbhOzRLKNAFUb9edAftiMKXvXfCB0vbGrJdZDNq0dWMsxg==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/archiver/-/archiver-1.3.0.tgz", + "integrity": "sha1-TyGU1tj5nfP1MeaIHxTxXVX6ryI=", "dev": true, "requires": { - "archiver-utils": "^2.1.0", - "async": "^2.6.3", + "archiver-utils": "^1.3.0", + "async": "^2.0.0", "buffer-crc32": "^0.2.1", - "glob": "^7.1.4", - "readable-stream": "^3.4.0", - "tar-stream": "^2.1.0", - "zip-stream": "^2.1.2" - }, - "dependencies": { - "bl": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/bl/-/bl-3.0.0.tgz", - "integrity": "sha512-EUAyP5UHU5hxF8BPT0LKW8gjYLhq1DQIcneOX/pL/m2Alo+OYDQAJlHq+yseMP50Os2nHXOSic6Ss3vSQeyf4A==", - "dev": true, - "requires": { - "readable-stream": "^3.0.1" - } - }, - "readable-stream": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", - "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", - "dev": true, - "requires": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - } - }, - "tar-stream": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.1.0.tgz", - "integrity": "sha512-+DAn4Nb4+gz6WZigRzKEZl1QuJVOLtAwwF+WUxy1fJ6X63CaGaUAxJRD2KEn1OMfcbCjySTYpNC6WmfQoIEOdw==", - "dev": true, - "requires": { - "bl": "^3.0.0", - "end-of-stream": "^1.4.1", - "fs-constants": "^1.0.0", - "inherits": "^2.0.3", - "readable-stream": "^3.1.1" - } - } + "glob": "^7.0.0", + "lodash": "^4.8.0", + "readable-stream": "^2.0.0", + "tar-stream": "^1.5.0", + "walkdir": "^0.0.11", + "zip-stream": "^1.1.0" } }, "archiver-utils": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/archiver-utils/-/archiver-utils-2.1.0.tgz", - "integrity": "sha512-bEL/yUb/fNNiNTuUz979Z0Yg5L+LzLxGJz8x79lYmR54fmTIb6ob/hNQgkQnIUDWIFjZVQwl9Xs356I6BAMHfw==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/archiver-utils/-/archiver-utils-1.3.0.tgz", + "integrity": "sha1-5QtMCccL89aA4y/xt5lOn52JUXQ=", "dev": true, "requires": { - "glob": "^7.1.4", - "graceful-fs": "^4.2.0", + "glob": "^7.0.0", + "graceful-fs": "^4.1.0", "lazystream": "^1.0.0", - "lodash.defaults": "^4.2.0", - "lodash.difference": "^4.5.0", - "lodash.flatten": "^4.4.0", - "lodash.isplainobject": "^4.0.6", - "lodash.union": "^4.6.0", - "normalize-path": "^3.0.0", + "lodash": "^4.8.0", + "normalize-path": "^2.0.0", "readable-stream": "^2.0.0" + }, + "dependencies": { + "normalize-path": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-2.1.1.tgz", + "integrity": "sha1-GrKLVW4Zg2Oowab35vogE3/mrtk=", + "dev": true, + "requires": { + "remove-trailing-separator": "^1.0.1" + } + } } }, "argparse": { @@ -3348,15 +3322,26 @@ "dev": true }, "compress-commons": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/compress-commons/-/compress-commons-2.1.1.tgz", - "integrity": "sha512-eVw6n7CnEMFzc3duyFVrQEuY1BlHR3rYsSztyG32ibGMW722i3C6IizEGMFmfMU+A+fALvBIwxN3czffTcdA+Q==", + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/compress-commons/-/compress-commons-1.2.2.tgz", + "integrity": "sha1-UkqfEJA/OoEzibAiXSfEi7dRiQ8=", "dev": true, "requires": { - "buffer-crc32": "^0.2.13", - "crc32-stream": "^3.0.1", - "normalize-path": "^3.0.0", - "readable-stream": "^2.3.6" + "buffer-crc32": "^0.2.1", + "crc32-stream": "^2.0.0", + "normalize-path": "^2.0.0", + "readable-stream": "^2.0.0" + }, + "dependencies": { + "normalize-path": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-2.1.1.tgz", + "integrity": "sha1-GrKLVW4Zg2Oowab35vogE3/mrtk=", + "dev": true, + "requires": { + "remove-trailing-separator": "^1.0.1" + } + } } }, "concat-map": { @@ -3526,26 +3511,13 @@ } }, "crc32-stream": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/crc32-stream/-/crc32-stream-3.0.1.tgz", - "integrity": "sha512-mctvpXlbzsvK+6z8kJwSJ5crm7yBwrQMTybJzMw1O4lLGJqjlDCXY2Zw7KheiA6XBEcBmfLx1D88mjRGVJtY9w==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/crc32-stream/-/crc32-stream-2.0.0.tgz", + "integrity": "sha1-483TtN8xaN10494/u8t7KX/pCPQ=", "dev": true, "requires": { "crc": "^3.4.4", - "readable-stream": "^3.4.0" - }, - "dependencies": { - "readable-stream": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", - "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", - "dev": true, - "requires": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - } - } + "readable-stream": "^2.0.0" } }, "create-error-class": { @@ -8114,24 +8086,6 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" }, - "lodash.defaults": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/lodash.defaults/-/lodash.defaults-4.2.0.tgz", - "integrity": "sha1-0JF4cW/+pN3p5ft7N/bwgCJ0WAw=", - "dev": true - }, - "lodash.difference": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/lodash.difference/-/lodash.difference-4.5.0.tgz", - "integrity": "sha1-nMtOUF1Ia5FlE0V3KIWi3yf9AXw=", - "dev": true - }, - "lodash.flatten": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/lodash.flatten/-/lodash.flatten-4.4.0.tgz", - "integrity": "sha1-8xwiIlqWMtK7+OSt2+8kCqdlph8=", - "dev": true - }, "lodash.includes": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", @@ -8173,12 +8127,6 @@ "integrity": "sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=", "dev": true }, - "lodash.union": { - "version": "4.6.0", - "resolved": "https://registry.npmjs.org/lodash.union/-/lodash.union-4.6.0.tgz", - "integrity": "sha1-SLtQiECfFvGCFmZkHETdGqrjzYg=", - "dev": true - }, "log": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/log/-/log-6.0.0.tgz", @@ -10076,48 +10024,6 @@ "color-convert": "^1.9.0" } }, - "archiver": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/archiver/-/archiver-1.3.0.tgz", - "integrity": "sha1-TyGU1tj5nfP1MeaIHxTxXVX6ryI=", - "dev": true, - "requires": { - "archiver-utils": "^1.3.0", - "async": "^2.0.0", - "buffer-crc32": "^0.2.1", - "glob": "^7.0.0", - "lodash": "^4.8.0", - "readable-stream": "^2.0.0", - "tar-stream": "^1.5.0", - "walkdir": "^0.0.11", - "zip-stream": "^1.1.0" - }, - "dependencies": { - "async": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/async/-/async-2.6.3.tgz", - "integrity": "sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg==", - "dev": true, - "requires": { - "lodash": "^4.17.14" - } - } - } - }, - "archiver-utils": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/archiver-utils/-/archiver-utils-1.3.0.tgz", - "integrity": "sha1-5QtMCccL89aA4y/xt5lOn52JUXQ=", - "dev": true, - "requires": { - "glob": "^7.0.0", - "graceful-fs": "^4.1.0", - "lazystream": "^1.0.0", - "lodash": "^4.8.0", - "normalize-path": "^2.0.0", - "readable-stream": "^2.0.0" - } - }, "async": { "version": "1.5.2", "resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz", @@ -10181,18 +10087,6 @@ "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", "dev": true }, - "compress-commons": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/compress-commons/-/compress-commons-1.2.2.tgz", - "integrity": "sha1-UkqfEJA/OoEzibAiXSfEi7dRiQ8=", - "dev": true, - "requires": { - "buffer-crc32": "^0.2.1", - "crc32-stream": "^2.0.0", - "normalize-path": "^2.0.0", - "readable-stream": "^2.0.0" - } - }, "configstore": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/configstore/-/configstore-3.1.2.tgz", @@ -10207,16 +10101,6 @@ "xdg-basedir": "^3.0.0" } }, - "crc32-stream": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/crc32-stream/-/crc32-stream-2.0.0.tgz", - "integrity": "sha1-483TtN8xaN10494/u8t7KX/pCPQ=", - "dev": true, - "requires": { - "crc": "^3.4.4", - "readable-stream": "^2.0.0" - } - }, "cross-spawn": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", @@ -10465,15 +10349,6 @@ "is-stream": "^1.0.1" } }, - "normalize-path": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-2.1.1.tgz", - "integrity": "sha1-GrKLVW4Zg2Oowab35vogE3/mrtk=", - "dev": true, - "requires": { - "remove-trailing-separator": "^1.0.1" - } - }, "npm-run-path": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz", @@ -10795,18 +10670,6 @@ "camelcase": "^5.0.0", "decamelize": "^1.2.0" } - }, - "zip-stream": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/zip-stream/-/zip-stream-1.2.0.tgz", - "integrity": "sha1-qLxF9MG0lpnGuQGYuqyqzbzUugQ=", - "dev": true, - "requires": { - "archiver-utils": "^1.3.0", - "compress-commons": "^1.2.0", - "lodash": "^4.8.0", - "readable-stream": "^2.0.0" - } } } }, @@ -12502,27 +12365,15 @@ } }, "zip-stream": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/zip-stream/-/zip-stream-2.1.3.tgz", - "integrity": "sha512-EkXc2JGcKhO5N5aZ7TmuNo45budRaFGHOmz24wtJR7znbNqDPmdZtUauKX6et8KAVseAMBOyWJqEpXcHTBsh7Q==", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/zip-stream/-/zip-stream-1.2.0.tgz", + "integrity": "sha1-qLxF9MG0lpnGuQGYuqyqzbzUugQ=", "dev": true, "requires": { - "archiver-utils": "^2.1.0", - "compress-commons": "^2.1.1", - "readable-stream": "^3.4.0" - }, - "dependencies": { - "readable-stream": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", - "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", - "dev": true, - "requires": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - } - } + "archiver-utils": "^1.3.0", + "compress-commons": "^1.2.0", + "lodash": "^4.8.0", + "readable-stream": "^2.0.0" } } } diff --git a/package.json b/package.json index 44e15e658..0c349c2a0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-offline", - "version": "6.0.0", + "version": "6.1.0", "description": "Emulate AWS λ and API Gateway locally when developing your Serverless project", "license": "MIT", "main": "dist/main.js", @@ -178,7 +178,6 @@ "@babel/plugin-proposal-optional-chaining": "^7.8.3", "@babel/plugin-transform-modules-commonjs": "^7.8.3", "@babel/register": "^7.8.3", - "archiver": "^3.1.1", "aws-sdk": "^2.624.0", "babel-eslint": "^10.0.3", "copyfiles": "^2.2.0", diff --git a/src/lambda/LambdaFunction.js b/src/lambda/LambdaFunction.js index 98c774cb6..ce7a844db 100644 --- a/src/lambda/LambdaFunction.js +++ b/src/lambda/LambdaFunction.js @@ -1,8 +1,5 @@ -import { tmpdir } from 'os' -import { dirname, join, resolve, sep } from 'path' -import { emptyDir, ensureDir, readFile, remove, writeFile } from 'fs-extra' +import { resolve } from 'path' import { performance } from 'perf_hooks' -import jszip from 'jszip' import HandlerRunner from './handler-runner/index.js' import LambdaContext from './LambdaContext.js' import serverlessLog from '../serverlessLog.js' @@ -14,13 +11,10 @@ import { } from '../config/index.js' import { createUniqueId, splitHandlerPathAndName } from '../utils/index.js' -const { keys } = Object const { ceil } = Math export default class LambdaFunction { - #artifact = null #clientContext = null - #codeDir = null #event = null #executionTimeEnded = null #executionTimeStarted = null @@ -28,9 +22,7 @@ export default class LambdaFunction { #functionName = null #handlerRunner = null #idleTimeStarted = null - #initialized = false #lambdaContext = null - #lambdaDir = null #memorySize = null #region = null #runtime = null @@ -40,7 +32,6 @@ export default class LambdaFunction { constructor(functionKey, functionDefinition, serverless, options) { const { - service, config: { serverlessPath, servicePath }, service: { provider }, } = serverless @@ -82,36 +73,25 @@ export default class LambdaFunction { handler, ) - this.#artifact = functionDefinition.package?.artifact - if (!this.#artifact) { - this.#artifact = service.package?.artifact - } - if (this.#artifact) { - // lambda directory contains code and layers - this.#lambdaDir = join( - tmpdir(), - 'serverless-offline', - 'services', - service.service, - functionKey, - createUniqueId(), - ) + let artifact = functionDefinition.package + ? functionDefinition.package.artifact + : null + if (!artifact) { + artifact = serverless.service.package + ? serverless.service.package.artifact + : null } - this.#codeDir = this.#lambdaDir - ? resolve(this.#lambdaDir, 'code') - : _servicePath - // TEMP const funOptions = { functionKey, handler, handlerName, - codeDir: this.#codeDir, - handlerPath: resolve(this.#codeDir, handlerPath), + handlerPath: resolve(_servicePath, handlerPath), runtime, serverlessPath, servicePath: _servicePath, + artifact, timeout, } @@ -185,12 +165,9 @@ export default class LambdaFunction { } // () => Promise - async cleanup() { + cleanup() { // TODO console.log('lambda cleanup') - await this.#handlerRunner.cleanup() - if (this.#lambdaDir) { - await remove(this.#lambdaDir) - } + return this.#handlerRunner.cleanup() } _executionTimeInMillis() { @@ -204,36 +181,6 @@ export default class LambdaFunction { ) } - // extractArtifact, loosely based on: - // https://github.com/serverless/serverless/blob/v1.57.0/lib/plugins/aws/invokeLocal/index.js#L312 - async _extractArtifact() { - if (!this.#artifact) { - return null - } - - emptyDir(this.#codeDir) - - const data = await readFile(this.#artifact) - const zip = await jszip.loadAsync(data) - return Promise.all( - keys(zip.files).map(async (filename) => { - const fileData = await zip.files[filename].async('nodebuffer') - if (filename.endsWith(sep)) { - return Promise.resolve() - } - await ensureDir(join(this.#codeDir, dirname(filename))) - return writeFile(join(this.#codeDir, filename), fileData, { - mode: zip.files[filename].unixPermissions, - }) - }), - ) - } - - async _initialize() { - await this._extractArtifact() - this.#initialized = true - } - get idleTimeInMinutes() { return (performance.now() - this.#idleTimeStarted) / 1000 / 60 } @@ -245,10 +192,6 @@ export default class LambdaFunction { async runHandler() { this.status = 'BUSY' - if (!this.#initialized) { - await this._initialize() - } - const requestId = createUniqueId() this.#lambdaContext.setRequestId(requestId) diff --git a/src/lambda/handler-runner/docker-runner/DockerRunner.js b/src/lambda/handler-runner/docker-runner/DockerRunner.js index 49ec30f75..f4748844e 100644 --- a/src/lambda/handler-runner/docker-runner/DockerRunner.js +++ b/src/lambda/handler-runner/docker-runner/DockerRunner.js @@ -1,32 +1,82 @@ +import { dirname, join, sep } from 'path' +import { readFile, writeFile, ensureDir, remove } from 'fs-extra' +import jszip from 'jszip' import DockerContainer from './DockerContainer.js' -import { checkDockerDaemon } from '../../../utils/index.js' +import { checkDockerDaemon, createUniqueId } from '../../../utils/index.js' + +const { keys } = Object export default class DockerRunner { - #codeDir = null #container = null + #servicePath = null + #volumeDir = null constructor(funOptions, env) { - const { codeDir, functionKey, handler, runtime } = funOptions + const { + // artifact, + functionKey, + handler, + runtime, + servicePath, + } = funOptions - this.#codeDir = codeDir + // this._artifact = artifact this.#container = new DockerContainer(env, functionKey, handler, runtime) + this.#servicePath = servicePath + + // TODO FIXME better to use temp dir? not sure if the .serverless dir is being "packed up" + // volume directory contains code and layers + this.#volumeDir = join( + servicePath, + '.serverless', + 'offline', + functionKey, + createUniqueId(), + ) } - cleanup() { + async cleanup() { if (this.#container) { - return this.#container.stop() + await this.#container.stop() + return remove(this.#volumeDir) } return undefined } + // extractArtifact, loosely based on: + // https://github.com/serverless/serverless/blob/v1.57.0/lib/plugins/aws/invokeLocal/index.js#L312 + async _extractArtifact() { + if (this._artifact) { + const codeDir = join(this.#volumeDir, 'code') + const data = await readFile(this._artifact) + const zip = await jszip.loadAsync(data) + await Promise.all( + keys(zip.files).map(async (filename) => { + const fileData = await zip.files[filename].async('nodebuffer') + if (filename.endsWith(sep)) { + return Promise.resolve() + } + await ensureDir(join(codeDir, dirname(filename))) + return writeFile(join(codeDir, filename), fileData, { + mode: zip.files[filename].unixPermissions, + }) + }), + ) + return codeDir + } + + return this.#servicePath + } + // context will be generated in container async run(event) { // FIXME TODO this should run only once -> static private await checkDockerDaemon() if (!this.#container.isRunning) { - await this.#container.start(this.#codeDir) + const codeDir = await this._extractArtifact() + await this.#container.start(codeDir) } return this.#container.request(event) diff --git a/tests/integration/_testHelpers/compressArtifact.js b/tests/integration/_testHelpers/compressArtifact.js deleted file mode 100644 index 2d9dbd0f3..000000000 --- a/tests/integration/_testHelpers/compressArtifact.js +++ /dev/null @@ -1,36 +0,0 @@ -import { dirname, resolve } from 'path' -import archiver from 'archiver' -import { createWriteStream, ensureDir, stat } from 'fs-extra' - -export default async function compressArtifact(baseDir, dest, src = []) { - const destPath = resolve(baseDir, dest) - await ensureDir(dirname(destPath)) - - return new Promise((_resolve, reject) => { - const output = createWriteStream(destPath) - const archive = archiver('zip', { - zlib: { level: 9 }, - }) - - output.on('open', async () => { - archive.pipe(output) - - await Promise.all( - src.map(async (filename) => { - const filepath = resolve(baseDir, filename) - const stats = await stat(filepath) - if (stats.isDirectory()) { - archive.directory(filepath, filename) - return - } - archive.file(filepath, { name: filename }) - }), - ) - - archive.finalize() - }) - - archive.on('error', (err) => reject(err)) - output.on('close', () => _resolve()) - }) -} diff --git a/tests/integration/_testHelpers/index.js b/tests/integration/_testHelpers/index.js index 895db2d1d..270259771 100644 --- a/tests/integration/_testHelpers/index.js +++ b/tests/integration/_testHelpers/index.js @@ -1,4 +1,3 @@ export * from './setupTeardown.js' export { default as joinUrl } from './joinUrl.js' export { default as buildInContainer } from './buildInContainer.js' -export { default as compressArtifact } from './compressArtifact.js' diff --git a/tests/integration/artifact/local/.gitignore b/tests/integration/artifact/local/.gitignore deleted file mode 100644 index de153db3b..000000000 --- a/tests/integration/artifact/local/.gitignore +++ /dev/null @@ -1 +0,0 @@ -artifacts diff --git a/tests/integration/artifact/local/artifacts/hello1.zip b/tests/integration/artifact/local/artifacts/hello1.zip new file mode 100644 index 000000000..90ddae0ef Binary files /dev/null and b/tests/integration/artifact/local/artifacts/hello1.zip differ diff --git a/tests/integration/artifact/local/artifacts/hello2.zip b/tests/integration/artifact/local/artifacts/hello2.zip new file mode 100644 index 000000000..8c3f6301f Binary files /dev/null and b/tests/integration/artifact/local/artifacts/hello2.zip differ diff --git a/tests/integration/artifact/local/handler1.js b/tests/integration/artifact/local/handler1.js deleted file mode 100644 index 4a0e8cd11..000000000 --- a/tests/integration/artifact/local/handler1.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict' - -const { stringify } = JSON - -exports.hello = async function hello() { - return { - body: stringify({ - message: 'handler1: Hello Node.js!', - }), - statusCode: 200, - } -} diff --git a/tests/integration/artifact/local/handler2.js b/tests/integration/artifact/local/handler2.js deleted file mode 100644 index fe792e746..000000000 --- a/tests/integration/artifact/local/handler2.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict' - -const { stringify } = JSON - -exports.hello = async function hello() { - return { - body: stringify({ - message: 'handler2: Hello Node.js!', - }), - statusCode: 200, - } -} diff --git a/tests/integration/artifact/local/localArtifact.test.js b/tests/integration/artifact/local/localArtifact.test.js deleted file mode 100644 index 18061a0f9..000000000 --- a/tests/integration/artifact/local/localArtifact.test.js +++ /dev/null @@ -1,54 +0,0 @@ -import { resolve } from 'path' -import fetch from 'node-fetch' -import { - compressArtifact, - joinUrl, - setup, - teardown, -} from '../../_testHelpers/index.js' - -jest.setTimeout(60000) - -describe('Local artifact tests', () => { - // init - beforeAll(async () => { - await compressArtifact(__dirname, './artifacts/hello1.zip', [ - './handler1.js', - ]) - await compressArtifact(__dirname, './artifacts/hello2.zip', [ - './handler2.js', - ]) - return setup({ - servicePath: resolve(__dirname), - }) - }) - - // cleanup - afterAll(() => teardown()) - - // - ;[ - { - description: 'should work with service artifact', - expected: { - message: 'handler1: Hello Node.js!', - }, - path: '/dev/hello1', - }, - { - description: 'should work with function artifact', - expected: { - message: 'handler2: Hello Node.js!', - }, - path: '/dev/hello2', - }, - ].forEach(({ description, expected, path }) => { - test(description, async () => { - const url = joinUrl(TEST_BASE_URL, path) - const response = await fetch(url) - const json = await response.json() - - expect(json).toEqual(expected) - }) - }) -}) diff --git a/tests/integration/artifact/local/serverless.yml b/tests/integration/artifact/local/serverless.yml deleted file mode 100644 index 852052759..000000000 --- a/tests/integration/artifact/local/serverless.yml +++ /dev/null @@ -1,32 +0,0 @@ -service: local-artifact-test - -plugins: - - ./../../../../ - -provider: - memorySize: 128 - name: aws - region: us-east-1 # default - runtime: nodejs12.x - stage: dev - versionFunctions: false - -package: - artifact: ./artifacts/hello1.zip - -functions: - hello1: - events: - - http: - method: get - path: hello1 - handler: handler1.hello - - hello2: - events: - - http: - method: get - path: hello2 - handler: handler2.hello - package: - artifact: ./artifacts/hello2.zip diff --git a/tests/integration/docker/artifact/.gitignore b/tests/integration/docker/artifact/.gitignore deleted file mode 100644 index de153db3b..000000000 --- a/tests/integration/docker/artifact/.gitignore +++ /dev/null @@ -1 +0,0 @@ -artifacts diff --git a/tests/integration/docker/artifact/artifact.test.js b/tests/integration/docker/artifact/artifact.test.js deleted file mode 100644 index 1a63a676e..000000000 --- a/tests/integration/docker/artifact/artifact.test.js +++ /dev/null @@ -1,45 +0,0 @@ -import { resolve } from 'path' -import fetch from 'node-fetch' -import { - compressArtifact, - joinUrl, - setup, - teardown, -} from '../../_testHelpers/index.js' - -jest.setTimeout(120000) - -// "Could not find 'Docker', skipping 'Docker' tests." -const _describe = process.env.DOCKER_DETECTED ? describe : describe.skip - -_describe('Artifact with docker tests', () => { - // init - beforeAll(async () => { - await compressArtifact(__dirname, './artifacts/hello.zip', ['./handler.js']) - return setup({ - servicePath: resolve(__dirname), - }) - }) - - // cleanup - afterAll(() => teardown()) - - // - ;[ - { - description: 'should work with artifact in docker container', - expected: { - message: 'Hello Node.js!', - }, - path: '/dev/hello', - }, - ].forEach(({ description, expected, path }) => { - test(description, async () => { - const url = joinUrl(TEST_BASE_URL, path) - const response = await fetch(url) - const json = await response.json() - - expect(json).toEqual(expected) - }) - }) -}) diff --git a/tests/integration/docker/artifact/artifacts/hello.zip b/tests/integration/docker/artifact/artifacts/hello.zip new file mode 100644 index 000000000..94fae1c17 Binary files /dev/null and b/tests/integration/docker/artifact/artifacts/hello.zip differ diff --git a/tests/integration/docker/artifact/handler.js b/tests/integration/docker/artifact/handler.js deleted file mode 100644 index 51ab12ee6..000000000 --- a/tests/integration/docker/artifact/handler.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict' - -const { stringify } = JSON - -exports.hello = async function hello() { - return { - body: stringify({ - message: 'Hello Node.js!', - }), - statusCode: 200, - } -} diff --git a/tests/integration/docker/artifact/serverless.yml b/tests/integration/docker/artifact/serverless.yml deleted file mode 100644 index d825aa8a4..000000000 --- a/tests/integration/docker/artifact/serverless.yml +++ /dev/null @@ -1,27 +0,0 @@ -service: docker-artifact-test - -plugins: - - ./../../../../ - -provider: - memorySize: 128 - name: aws - region: us-east-1 # default - runtime: nodejs12.x - stage: dev - versionFunctions: false - -package: - artifact: ./artifacts/hello.zip - -custom: - serverless-offline: - useDocker: true - -functions: - hello: - events: - - http: - method: get - path: hello - handler: handler.hello