diff --git a/.eslintrc.js b/.eslintrc.js index d7707ed58..03786ba75 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -36,6 +36,10 @@ module.exports = { name: 'Buffer', message: "Import 'Buffer' from 'buffer' module instead", }, + { + name: 'process', + message: "Import 'process' from 'process' module instead", + }, ], // we use underscores to indicate private fields in classes 'no-underscore-dangle': 'off', diff --git a/examples/events/http/handler.js b/examples/events/http/handler.js index de89f4adb..77a3f0a45 100644 --- a/examples/events/http/handler.js +++ b/examples/events/http/handler.js @@ -1,10 +1,12 @@ 'use strict' +const { env } = require('process') + const { stringify } = JSON exports.hello = async function hello() { return { - body: stringify({ foo: 'bar', IS_OFFLINE: process.env.IS_OFFLINE }), + body: stringify({ foo: 'bar', IS_OFFLINE: env.IS_OFFLINE }), statusCode: 200, } } diff --git a/jest.config.js b/jest.config.js index c313c25f8..45e13db7b 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,15 +1,15 @@ 'use strict' -const { AWS_ENDPOINT } = process.env +const { env } = require('process') module.exports = { bail: true, globals: { - RUN_TEST_AGAINST_AWS: AWS_ENDPOINT != null, - TEST_BASE_URL: AWS_ENDPOINT || 'http://localhost:3000', + RUN_TEST_AGAINST_AWS: env.AWS_ENDPOINT != null, + TEST_BASE_URL: env.AWS_ENDPOINT || 'http://localhost:3000', }, modulePathIgnorePatterns: ['src/lambda/__tests__/fixtures/'], - ...(!process.env.SKIP_SETUP && { + ...(!env.SKIP_SETUP && { globalSetup: './tests/_setupTeardown/npmInstall.js', }), } diff --git a/src/ServerlessOffline.js b/src/ServerlessOffline.js index 45a6a501c..4a9e93f7b 100644 --- a/src/ServerlessOffline.js +++ b/src/ServerlessOffline.js @@ -1,3 +1,4 @@ +import process, { env, exit } from 'process' import updateNotifier from 'update-notifier' import chalk from 'chalk' import { parse as semverParse } from 'semver' @@ -65,7 +66,7 @@ export default class ServerlessOffline { } _printBlankLine() { - if (process.env.NODE_ENV !== 'test') { + if (env.NODE_ENV !== 'test') { if (this.log) { this.log.notice() } else { @@ -77,7 +78,7 @@ export default class ServerlessOffline { // Entry point for the plugin (sls offline) when running 'sls offline start' async start() { // Put here so available everywhere, not just in handlers - process.env.IS_OFFLINE = true + env.IS_OFFLINE = true // check if update is available updateNotifier({ pkg }).notify() @@ -111,14 +112,14 @@ export default class ServerlessOffline { } async ready() { - if (process.env.NODE_ENV !== 'test') { + if (env.NODE_ENV !== 'test') { await this._listenForTermination() } } async end(skipExit) { // TEMP FIXME - if (process.env.NODE_ENV === 'test' && skipExit === undefined) { + if (env.NODE_ENV === 'test' && skipExit === undefined) { return } @@ -150,7 +151,7 @@ export default class ServerlessOffline { await Promise.all(eventModules) if (!skipExit) { - process.exit(0) + exit(0) } } diff --git a/src/debugLog.js b/src/debugLog.js index 449fe02cb..7a93727b2 100644 --- a/src/debugLog.js +++ b/src/debugLog.js @@ -1,3 +1,5 @@ -export default typeof process.env.SLS_DEBUG !== 'undefined' +import { env } from 'process' + +export default typeof env.SLS_DEBUG !== 'undefined' ? console.log.bind(null, '[offline]') : () => null diff --git a/src/events/http/HttpServer.js b/src/events/http/HttpServer.js index 3737c802e..3ec100984 100644 --- a/src/events/http/HttpServer.js +++ b/src/events/http/HttpServer.js @@ -1,6 +1,7 @@ import { Buffer } from 'buffer' import { readFileSync } from 'fs' import { join, resolve } from 'path' +import process, { env, exit } from 'process' import h2o2 from '@hapi/h2o2' import { Server } from '@hapi/hapi' import { createRequire } from 'module' @@ -200,7 +201,7 @@ export default class HttpServer { err, ) } - process.exit(1) + exit(1) } // TODO move the following block @@ -220,7 +221,7 @@ export default class HttpServer { serverlessLog('Enter "rp" to replay the last request') } - if (process.env.NODE_ENV !== 'test') { + if (env.NODE_ENV !== 'test') { process.openStdin().addListener('data', (data) => { // note: data is an object, and when converted to a string it will // end with a linefeed. so we (rather crudely) account for that @@ -257,7 +258,7 @@ export default class HttpServer { // } _printBlankLine() { - if (process.env.NODE_ENV !== 'test') { + if (env.NODE_ENV !== 'test') { if (this.log) { this.log.notice() } else { diff --git a/src/events/http/lambda-events/LambdaIntegrationEvent.js b/src/events/http/lambda-events/LambdaIntegrationEvent.js index 20b9cfdc0..06b78124f 100644 --- a/src/events/http/lambda-events/LambdaIntegrationEvent.js +++ b/src/events/http/lambda-events/LambdaIntegrationEvent.js @@ -1,3 +1,4 @@ +import { env } from 'process' import renderVelocityTemplateObject from './renderVelocityTemplateObject.js' import VelocityContext from './VelocityContext.js' @@ -18,9 +19,9 @@ export default class LambdaIntegrationEvent { } create() { - if (process.env.AUTHORIZER) { + if (env.AUTHORIZER) { try { - const authorizerContext = parse(process.env.AUTHORIZER) + const authorizerContext = parse(env.AUTHORIZER) if (authorizerContext) { this.#request.auth = { ...this.#request.auth, diff --git a/src/events/http/lambda-events/LambdaProxyIntegrationEvent.js b/src/events/http/lambda-events/LambdaProxyIntegrationEvent.js index 33b3908fc..918260255 100644 --- a/src/events/http/lambda-events/LambdaProxyIntegrationEvent.js +++ b/src/events/http/lambda-events/LambdaProxyIntegrationEvent.js @@ -1,4 +1,5 @@ import { Buffer } from 'buffer' +import { env } from 'process' import { decode } from 'jsonwebtoken' import { createUniqueId, @@ -62,17 +63,17 @@ export default class LambdaProxyIntegrationEvent { let authAuthorizer - if (process.env.AUTHORIZER) { + if (env.AUTHORIZER) { try { - authAuthorizer = parse(process.env.AUTHORIZER) + authAuthorizer = parse(env.AUTHORIZER) } catch (error) { if (this.log) { this.log.error( - 'Could not parse process.env.AUTHORIZER, make sure it is correct JSON', + 'Could not parse env.AUTHORIZER, make sure it is correct JSON', ) } else { console.error( - 'Serverless-offline: Could not parse process.env.AUTHORIZER, make sure it is correct JSON.', + 'Serverless-offline: Could not parse env.AUTHORIZER, make sure it is correct JSON.', ) } } @@ -195,7 +196,7 @@ export default class LambdaProxyIntegrationEvent { // 'principalId' should have higher priority principalId: authPrincipalId || - process.env.PRINCIPAL_ID || + env.PRINCIPAL_ID || 'offlineContext_authorizer_principalId', // See #24 }), domainName: 'offlineContext_domainName', @@ -204,23 +205,23 @@ export default class LambdaProxyIntegrationEvent { httpMethod, identity: { accessKey: null, - accountId: process.env.SLS_ACCOUNT_ID || 'offlineContext_accountId', - apiKey: process.env.SLS_API_KEY || 'offlineContext_apiKey', - apiKeyId: process.env.SLS_API_KEY_ID || 'offlineContext_apiKeyId', - caller: process.env.SLS_CALLER || 'offlineContext_caller', + accountId: env.SLS_ACCOUNT_ID || 'offlineContext_accountId', + apiKey: env.SLS_API_KEY || 'offlineContext_apiKey', + apiKeyId: env.SLS_API_KEY_ID || 'offlineContext_apiKeyId', + caller: env.SLS_CALLER || 'offlineContext_caller', cognitoAuthenticationProvider: _headers['cognito-authentication-provider'] || - process.env.SLS_COGNITO_AUTHENTICATION_PROVIDER || + env.SLS_COGNITO_AUTHENTICATION_PROVIDER || 'offlineContext_cognitoAuthenticationProvider', cognitoAuthenticationType: - process.env.SLS_COGNITO_AUTHENTICATION_TYPE || + env.SLS_COGNITO_AUTHENTICATION_TYPE || 'offlineContext_cognitoAuthenticationType', cognitoIdentityId: _headers['cognito-identity-id'] || - process.env.SLS_COGNITO_IDENTITY_ID || + env.SLS_COGNITO_IDENTITY_ID || 'offlineContext_cognitoIdentityId', cognitoIdentityPoolId: - process.env.SLS_COGNITO_IDENTITY_POOL_ID || + env.SLS_COGNITO_IDENTITY_POOL_ID || 'offlineContext_cognitoIdentityPoolId', principalOrgId: null, sourceIp: remoteAddress, diff --git a/src/events/http/lambda-events/LambdaProxyIntegrationEventV2.js b/src/events/http/lambda-events/LambdaProxyIntegrationEventV2.js index 11112faf6..a506951a5 100644 --- a/src/events/http/lambda-events/LambdaProxyIntegrationEventV2.js +++ b/src/events/http/lambda-events/LambdaProxyIntegrationEventV2.js @@ -1,4 +1,5 @@ import { Buffer } from 'buffer' +import { env } from 'process' import { decode } from 'jsonwebtoken' import { formatToClfTime, @@ -49,9 +50,9 @@ export default class LambdaProxyIntegrationEventV2 { let authAuthorizer - if (process.env.AUTHORIZER) { + if (env.AUTHORIZER) { try { - authAuthorizer = parse(process.env.AUTHORIZER) + authAuthorizer = parse(env.AUTHORIZER) } catch (error) { if (this.log) { this.log.error( diff --git a/src/events/http/lambda-events/VelocityContext.js b/src/events/http/lambda-events/VelocityContext.js index 3274ae7e9..08b0155aa 100644 --- a/src/events/http/lambda-events/VelocityContext.js +++ b/src/events/http/lambda-events/VelocityContext.js @@ -1,4 +1,5 @@ import { Buffer } from 'buffer' +import { env } from 'process' import jsEscapeString from 'js-string-escape' import { decode } from 'jsonwebtoken' import { @@ -74,7 +75,7 @@ export default class VelocityContext { authorizer.principalId = authPrincipalId || - process.env.PRINCIPAL_ID || + env.PRINCIPAL_ID || 'offlineContext_authorizer_principalId' // See #24 if (token) { diff --git a/src/events/websocket/HttpServer.js b/src/events/websocket/HttpServer.js index 625c6c5ef..ce641432e 100644 --- a/src/events/websocket/HttpServer.js +++ b/src/events/websocket/HttpServer.js @@ -1,3 +1,4 @@ +import { exit } from 'process' import { Server } from '@hapi/hapi' import { catchAllRoute, connectionsRoutes } from './http-routes/index.js' import serverlessLog from '../../serverlessLog.js' @@ -57,7 +58,7 @@ export default class HttpServer { err, ) } - process.exit(1) + exit(1) } if (this.log) { diff --git a/src/lambda/HttpServer.js b/src/lambda/HttpServer.js index daf9bde0d..c957dbc36 100644 --- a/src/lambda/HttpServer.js +++ b/src/lambda/HttpServer.js @@ -1,4 +1,5 @@ import { Server } from '@hapi/hapi' +import { exit } from 'process' import { invocationsRoute, invokeAsyncRoute } from './routes/index.js' import serverlessLog from '../serverlessLog.js' import debugLog from '../debugLog.js' @@ -56,7 +57,7 @@ export default class HttpServer { err, ) } - process.exit(1) + exit(1) } if (this.log) { diff --git a/src/lambda/handler-runner/child-process-runner/childProcessHelper.js b/src/lambda/handler-runner/child-process-runner/childProcessHelper.js index 5e3684017..7414020c9 100644 --- a/src/lambda/handler-runner/child-process-runner/childProcessHelper.js +++ b/src/lambda/handler-runner/child-process-runner/childProcessHelper.js @@ -1,3 +1,4 @@ +import process, { argv } from 'process' import InProcessRunner from '../in-process-runner/index.js' // TODO handle this: @@ -20,7 +21,7 @@ process.on('uncaughtException', (err) => { }) }) -const [, , functionKey, handlerName, handlerPath] = process.argv +const [, , functionKey, handlerName, handlerPath] = argv process.on('message', async (messageData) => { const { context, event, allowCache, timeout } = messageData diff --git a/src/lambda/handler-runner/go-runner/GoRunner.js b/src/lambda/handler-runner/go-runner/GoRunner.js index 1f457b61d..76a947711 100644 --- a/src/lambda/handler-runner/go-runner/GoRunner.js +++ b/src/lambda/handler-runner/go-runner/GoRunner.js @@ -1,11 +1,11 @@ -import { EOL } from 'os' import { promises as fsPromises } from 'fs' +import { EOL } from 'os' import { sep, resolve, parse as pathParse } from 'path' +import process, { chdir, cwd } from 'process' import execa, { sync } from 'execa' const { writeFile, readFile, mkdir, rmdir } = fsPromises const { parse, stringify } = JSON -const { cwd, chdir } = process const PAYLOAD_IDENTIFIER = 'offline_payload' diff --git a/src/lambda/handler-runner/in-process-runner/InProcessRunner.js b/src/lambda/handler-runner/in-process-runner/InProcessRunner.js index 018b7131f..a60535589 100644 --- a/src/lambda/handler-runner/in-process-runner/InProcessRunner.js +++ b/src/lambda/handler-runner/in-process-runner/InProcessRunner.js @@ -1,6 +1,7 @@ -import { performance } from 'perf_hooks' import { readdirSync } from 'fs' import { dirname, resolve } from 'path' +import { performance } from 'perf_hooks' +import process from 'process' const { assign, keys } = Object diff --git a/src/lambda/handler-runner/java-runner/JavaRunner.js b/src/lambda/handler-runner/java-runner/JavaRunner.js index 38650fa59..0260d4904 100644 --- a/src/lambda/handler-runner/java-runner/JavaRunner.js +++ b/src/lambda/handler-runner/java-runner/JavaRunner.js @@ -1,4 +1,5 @@ import { EOL } from 'os' +import process from 'process' import fetch from 'node-fetch' import { invokeJavaLocal } from 'java-invoke-local' diff --git a/src/lambda/handler-runner/python-runner/PythonRunner.js b/src/lambda/handler-runner/python-runner/PythonRunner.js index d34da86da..e425d0a02 100644 --- a/src/lambda/handler-runner/python-runner/PythonRunner.js +++ b/src/lambda/handler-runner/python-runner/PythonRunner.js @@ -1,10 +1,10 @@ +import { spawn } from 'child_process' import { EOL, platform } from 'os' import { delimiter, join, relative, resolve } from 'path' -import { spawn } from 'child_process' +import process, { cwd } from 'process' import readline from 'readline' const { parse, stringify } = JSON -const { cwd } = process const { assign } = Object const { has } = Reflect diff --git a/src/lambda/handler-runner/ruby-runner/RubyRunner.js b/src/lambda/handler-runner/ruby-runner/RubyRunner.js index 0c4e509dc..274a6394a 100644 --- a/src/lambda/handler-runner/ruby-runner/RubyRunner.js +++ b/src/lambda/handler-runner/ruby-runner/RubyRunner.js @@ -1,9 +1,9 @@ import { EOL, platform } from 'os' import { relative, resolve } from 'path' +import { cwd } from 'process' import execa from 'execa' const { parse, stringify } = JSON -const { cwd } = process const { has } = Reflect export default class RubyRunner { diff --git a/src/lambda/handler-runner/worker-thread-runner/workerThreadHelper.js b/src/lambda/handler-runner/worker-thread-runner/workerThreadHelper.js index a1bac35ba..d1bd851e8 100644 --- a/src/lambda/handler-runner/worker-thread-runner/workerThreadHelper.js +++ b/src/lambda/handler-runner/worker-thread-runner/workerThreadHelper.js @@ -1,3 +1,4 @@ +import { env } from 'process' import { parentPort, workerData } from 'worker_threads' // eslint-disable-line import/no-unresolved import InProcessRunner from '../in-process-runner/index.js' @@ -13,7 +14,7 @@ parentPort.on('message', async (messageData) => { handlerPath, handlerName, handlerModuleNesting, - process.env, + env, timeout, allowCache, ) diff --git a/tests/_setupTeardown/npmInstall.js b/tests/_setupTeardown/npmInstall.js index d036e8526..0157a4ec1 100644 --- a/tests/_setupTeardown/npmInstall.js +++ b/tests/_setupTeardown/npmInstall.js @@ -1,4 +1,5 @@ import { resolve } from 'path' +import { env } from 'process' import execa from 'execa' import promiseMap from 'p-map' import { @@ -49,32 +50,32 @@ export default async function npmInstall() { const docker = await detectDocker() if (docker) { - process.env.DOCKER_DETECTED = true + env.DOCKER_DETECTED = true const dockerCompose = await detectExecutable('docker-compose') if (dockerCompose) { - process.env.DOCKER_COMPOSE_DETECTED = true + env.DOCKER_COMPOSE_DETECTED = true } } const go = await checkGoVersion() if (go && go === '1.x') { - process.env.GO1X_DETECTED = true + env.GO1X_DETECTED = true } if (python2) { - process.env.PYTHON2_DETECTED = true + env.PYTHON2_DETECTED = true } if (python3) { - process.env.PYTHON3_DETECTED = true + env.PYTHON3_DETECTED = true } if (ruby) { - process.env.RUBY_DETECTED = true + env.RUBY_DETECTED = true } if (java) { - process.env.JAVA_DETECTED = true + env.JAVA_DETECTED = true } return promiseMap(testFolders, (path) => installNpmModules(path), { diff --git a/tests/endToEnd/environmentVariables/environmentVariables.test.js b/tests/endToEnd/environmentVariables/environmentVariables.test.js index e658c3861..2a1a98352 100644 --- a/tests/endToEnd/environmentVariables/environmentVariables.test.js +++ b/tests/endToEnd/environmentVariables/environmentVariables.test.js @@ -1,4 +1,5 @@ import { resolve } from 'path' +import { env } from 'process' import fetch from 'node-fetch' import { joinUrl, @@ -16,9 +17,9 @@ describe('environment variables', () => { // init let json beforeAll(async () => { - process.env.ENV_VAR_QUOTED = ENV_VAR_QUOTED - process.env.ENV_VAR_UNQUOTED = ENV_VAR_UNQUOTED - process.env.ENV_VAR_MAPPED_FROM_ANOTHER = ENV_VAR_MAPPED + env.ENV_VAR_QUOTED = ENV_VAR_QUOTED + env.ENV_VAR_UNQUOTED = ENV_VAR_UNQUOTED + env.ENV_VAR_MAPPED_FROM_ANOTHER = ENV_VAR_MAPPED await setup({ servicePath: resolve(__dirname), }) @@ -29,9 +30,9 @@ describe('environment variables', () => { // cleanup afterAll(async () => { - process.env.ENV_VAR_QUOTED = undefined - process.env.ENV_VAR_UNQUOTED = undefined - process.env.ENV_VAR_MAPPED_FROM_ANOTHER = undefined + env.ENV_VAR_QUOTED = undefined + env.ENV_VAR_UNQUOTED = undefined + env.ENV_VAR_MAPPED_FROM_ANOTHER = undefined await teardown() }) diff --git a/tests/endToEnd/environmentVariables/handler.js b/tests/endToEnd/environmentVariables/handler.js index 36a1b837f..cba211541 100644 --- a/tests/endToEnd/environmentVariables/handler.js +++ b/tests/endToEnd/environmentVariables/handler.js @@ -1,5 +1,7 @@ 'use strict' +const { env } = require('process') + const { stringify } = JSON exports.hello = async () => { @@ -9,7 +11,7 @@ exports.hello = async () => { ENV_VAR_MAPPED, ENV_VAR_EMPTY_STRING, ENV_VAR_UNDEFINED, - } = process.env + } = env const body = stringify({ ENV_VAR_QUOTED, diff --git a/tests/integration/_testHelpers/setupTeardown.js b/tests/integration/_testHelpers/setupTeardown.js index a5886fa1a..38842e2eb 100644 --- a/tests/integration/_testHelpers/setupTeardown.js +++ b/tests/integration/_testHelpers/setupTeardown.js @@ -1,5 +1,6 @@ -import { node } from 'execa' import { resolve } from 'path' +import process, { env } from 'process' +import { node } from 'execa' let serverlessProcess @@ -8,7 +9,7 @@ const serverlessPath = resolve( '../../../node_modules/serverless/bin/serverless', ) -const shouldPrintOfflineOutput = process.env.PRINT_OFFLINE_OUTPUT +const shouldPrintOfflineOutput = env.PRINT_OFFLINE_OUTPUT export async function setup(options) { const { args = [], servicePath } = options diff --git a/tests/integration/docker/access-host/accessHost.test.js b/tests/integration/docker/access-host/accessHost.test.js index 08bfab31e..d866c7f95 100644 --- a/tests/integration/docker/access-host/accessHost.test.js +++ b/tests/integration/docker/access-host/accessHost.test.js @@ -1,4 +1,5 @@ import { resolve } from 'path' +import { env } from 'process' import { Server } from '@hapi/hapi' import fetch from 'node-fetch' import { joinUrl, setup, teardown } from '../../_testHelpers/index.js' @@ -6,7 +7,7 @@ import { 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 +const _describe = env.DOCKER_DETECTED ? describe : describe.skip _describe('Access host with Docker tests', () => { let server diff --git a/tests/integration/docker/artifact/artifact.test.js b/tests/integration/docker/artifact/artifact.test.js index 1a63a676e..f0b5138a9 100644 --- a/tests/integration/docker/artifact/artifact.test.js +++ b/tests/integration/docker/artifact/artifact.test.js @@ -1,4 +1,5 @@ import { resolve } from 'path' +import { env } from 'process' import fetch from 'node-fetch' import { compressArtifact, @@ -10,7 +11,7 @@ import { jest.setTimeout(120000) // "Could not find 'Docker', skipping 'Docker' tests." -const _describe = process.env.DOCKER_DETECTED ? describe : describe.skip +const _describe = env.DOCKER_DETECTED ? describe : describe.skip _describe('Artifact with docker tests', () => { // init diff --git a/tests/integration/docker/go/go1.x/dockerGo1.x.test.js b/tests/integration/docker/go/go1.x/dockerGo1.x.test.js index 06090ff00..68b9b8c37 100644 --- a/tests/integration/docker/go/go1.x/dockerGo1.x.test.js +++ b/tests/integration/docker/go/go1.x/dockerGo1.x.test.js @@ -1,4 +1,5 @@ import { resolve } from 'path' +import { env } from 'process' import fetch from 'node-fetch' import { joinUrl, @@ -10,7 +11,7 @@ import { jest.setTimeout(180000) // "Could not find 'Docker', skipping 'Docker' tests." -const _describe = process.env.DOCKER_DETECTED ? describe : describe.skip +const _describe = env.DOCKER_DETECTED ? describe : describe.skip _describe('Go 1.x with Docker tests', () => { // init diff --git a/tests/integration/docker/layers/dockerLayers.test.js b/tests/integration/docker/layers/dockerLayers.test.js index e805b539a..b86af4e6e 100644 --- a/tests/integration/docker/layers/dockerLayers.test.js +++ b/tests/integration/docker/layers/dockerLayers.test.js @@ -1,11 +1,12 @@ import { resolve } from 'path' +import { env } from 'process' import fetch from 'node-fetch' import { 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 +const _describe = env.DOCKER_DETECTED ? describe : describe.skip _describe('Layers with Docker tests', () => { // init diff --git a/tests/integration/docker/multiple/dockerMultiple.test.js b/tests/integration/docker/multiple/dockerMultiple.test.js index 3c5661ca1..3a0827814 100644 --- a/tests/integration/docker/multiple/dockerMultiple.test.js +++ b/tests/integration/docker/multiple/dockerMultiple.test.js @@ -1,4 +1,5 @@ import { resolve } from 'path' +import { env } from 'process' import fetch from 'node-fetch' import { satisfies } from 'semver' import { joinUrl, setup, teardown } from '../../_testHelpers/index.js' @@ -6,7 +7,7 @@ import { joinUrl, setup, teardown } from '../../_testHelpers/index.js' jest.setTimeout(240000) // skipping tests on Linux for now. -const _describe = process.env.DOCKER_DETECTED ? describe : describe.skip +const _describe = env.DOCKER_DETECTED ? describe : describe.skip _describe('Multiple docker containers', () => { // init diff --git a/tests/integration/docker/nodejs/nodejs10.x/dockerNodejs10.x.test.js b/tests/integration/docker/nodejs/nodejs10.x/dockerNodejs10.x.test.js index d9a9189b8..599b00cbb 100644 --- a/tests/integration/docker/nodejs/nodejs10.x/dockerNodejs10.x.test.js +++ b/tests/integration/docker/nodejs/nodejs10.x/dockerNodejs10.x.test.js @@ -1,4 +1,5 @@ import { resolve } from 'path' +import { env } from 'process' import fetch from 'node-fetch' import { satisfies } from 'semver' import { joinUrl, setup, teardown } from '../../../_testHelpers/index.js' @@ -6,7 +7,7 @@ import { 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 +const _describe = env.DOCKER_DETECTED ? describe : describe.skip _describe('Node.js 10.x with Docker tests', () => { // init diff --git a/tests/integration/docker/nodejs/nodejs12.x/dockerNodejs12.x.test.js b/tests/integration/docker/nodejs/nodejs12.x/dockerNodejs12.x.test.js index d0d551cdf..87cd4bb4e 100644 --- a/tests/integration/docker/nodejs/nodejs12.x/dockerNodejs12.x.test.js +++ b/tests/integration/docker/nodejs/nodejs12.x/dockerNodejs12.x.test.js @@ -1,4 +1,5 @@ import { resolve } from 'path' +import { env } from 'process' import fetch from 'node-fetch' import { satisfies } from 'semver' import { joinUrl, setup, teardown } from '../../../_testHelpers/index.js' @@ -6,7 +7,7 @@ import { 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 +const _describe = env.DOCKER_DETECTED ? describe : describe.skip _describe('Node.js 12.x with Docker tests', () => { // init diff --git a/tests/integration/docker/nodejs/nodejs8.10/dockerNodejs8.10.test.js b/tests/integration/docker/nodejs/nodejs8.10/dockerNodejs8.10.test.js index 6ab97fd2f..5b1380c4c 100644 --- a/tests/integration/docker/nodejs/nodejs8.10/dockerNodejs8.10.test.js +++ b/tests/integration/docker/nodejs/nodejs8.10/dockerNodejs8.10.test.js @@ -1,4 +1,5 @@ import { resolve } from 'path' +import { env } from 'process' import fetch from 'node-fetch' import { satisfies } from 'semver' import { joinUrl, setup, teardown } from '../../../_testHelpers/index.js' @@ -6,7 +7,7 @@ import { 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 +const _describe = env.DOCKER_DETECTED ? describe : describe.skip _describe('Node.js 8.10 with Docker tests', () => { // init diff --git a/tests/integration/docker/provided/dockerProvided.test.js b/tests/integration/docker/provided/dockerProvided.test.js index df73179a1..a85c91047 100644 --- a/tests/integration/docker/provided/dockerProvided.test.js +++ b/tests/integration/docker/provided/dockerProvided.test.js @@ -1,11 +1,12 @@ import { resolve } from 'path' +import { env } from 'process' import fetch from 'node-fetch' import { 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 +const _describe = env.DOCKER_DETECTED ? describe : describe.skip _describe('Provided with Docker tests', () => { // init diff --git a/tests/integration/docker/python/python2.7/dockerPython2.7.test.js b/tests/integration/docker/python/python2.7/dockerPython2.7.test.js index aecc28584..4335e4d27 100644 --- a/tests/integration/docker/python/python2.7/dockerPython2.7.test.js +++ b/tests/integration/docker/python/python2.7/dockerPython2.7.test.js @@ -1,11 +1,12 @@ import { resolve } from 'path' +import { env } from 'process' import fetch from 'node-fetch' import { 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 +const _describe = env.DOCKER_DETECTED ? describe : describe.skip _describe('Python 2.7 with Docker tests', () => { // init diff --git a/tests/integration/docker/python/python3.6/dockerPython3.6.test.js b/tests/integration/docker/python/python3.6/dockerPython3.6.test.js index 4252dee5d..82d734dad 100644 --- a/tests/integration/docker/python/python3.6/dockerPython3.6.test.js +++ b/tests/integration/docker/python/python3.6/dockerPython3.6.test.js @@ -1,11 +1,12 @@ import { resolve } from 'path' +import { env } from 'process' import fetch from 'node-fetch' import { 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 +const _describe = env.DOCKER_DETECTED ? describe : describe.skip _describe('Python 3.6 with Docker tests', () => { // init diff --git a/tests/integration/docker/python/python3.7/dockerPython3.7.test.js b/tests/integration/docker/python/python3.7/dockerPython3.7.test.js index 37895bc6b..a6a918ee2 100644 --- a/tests/integration/docker/python/python3.7/dockerPython3.7.test.js +++ b/tests/integration/docker/python/python3.7/dockerPython3.7.test.js @@ -1,11 +1,12 @@ import { resolve } from 'path' +import { env } from 'process' import fetch from 'node-fetch' import { 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 +const _describe = env.DOCKER_DETECTED ? describe : describe.skip _describe('Python 3.7 with Docker tests', () => { // init diff --git a/tests/integration/docker/python/python3.8/dockerPython3.8.test.js b/tests/integration/docker/python/python3.8/dockerPython3.8.test.js index e847e0c64..acd30056f 100644 --- a/tests/integration/docker/python/python3.8/dockerPython3.8.test.js +++ b/tests/integration/docker/python/python3.8/dockerPython3.8.test.js @@ -1,11 +1,12 @@ import { resolve } from 'path' +import { env } from 'process' import fetch from 'node-fetch' import { 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 +const _describe = env.DOCKER_DETECTED ? describe : describe.skip _describe('Python 3.8 with Docker tests', () => { // init diff --git a/tests/integration/docker/ruby/ruby2.5/dockerRuby2.5.test.js b/tests/integration/docker/ruby/ruby2.5/dockerRuby2.5.test.js index 1978a75a9..f1ff506fc 100644 --- a/tests/integration/docker/ruby/ruby2.5/dockerRuby2.5.test.js +++ b/tests/integration/docker/ruby/ruby2.5/dockerRuby2.5.test.js @@ -1,4 +1,5 @@ import { resolve } from 'path' +import { env } from 'process' import fetch from 'node-fetch' import { satisfies } from 'semver' import { joinUrl, setup, teardown } from '../../../_testHelpers/index.js' @@ -6,7 +7,7 @@ import { 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 +const _describe = env.DOCKER_DETECTED ? describe : describe.skip _describe('Ruby 2.5 with Docker tests', () => { // init diff --git a/tests/integration/docker/ruby/ruby2.7/dockerRuby2.7.test.js b/tests/integration/docker/ruby/ruby2.7/dockerRuby2.7.test.js index 2d3b33f0c..5e6e45b22 100644 --- a/tests/integration/docker/ruby/ruby2.7/dockerRuby2.7.test.js +++ b/tests/integration/docker/ruby/ruby2.7/dockerRuby2.7.test.js @@ -1,4 +1,5 @@ import { resolve } from 'path' +import { env } from 'process' import fetch from 'node-fetch' import { satisfies } from 'semver' import { joinUrl, setup, teardown } from '../../../_testHelpers/index.js' @@ -6,7 +7,7 @@ import { 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 +const _describe = env.DOCKER_DETECTED ? describe : describe.skip _describe('Ruby 2.7 with Docker tests', () => { // init diff --git a/tests/integration/go/go1.x/go1.x.test.js b/tests/integration/go/go1.x/go1.x.test.js index 4874585c6..952087701 100644 --- a/tests/integration/go/go1.x/go1.x.test.js +++ b/tests/integration/go/go1.x/go1.x.test.js @@ -1,12 +1,13 @@ import { platform } from 'os' import { resolve } from 'path' +import { env } from 'process' import fetch from 'node-fetch' import { joinUrl, setup, teardown } from '../../_testHelpers/index.js' jest.setTimeout(180000) const _describe = - process.env.GO1X_DETECTED && platform() !== 'win32' ? describe : describe.skip + env.GO1X_DETECTED && platform() !== 'win32' ? describe : describe.skip _describe('Go 1.x with GoRunner', () => { // init diff --git a/tests/integration/groovy/groovy.test.js b/tests/integration/groovy/groovy.test.js index 1b1e35128..88ef01373 100644 --- a/tests/integration/groovy/groovy.test.js +++ b/tests/integration/groovy/groovy.test.js @@ -1,11 +1,12 @@ import { resolve } from 'path' +import { env } from 'process' import fetch from 'node-fetch' import { joinUrl, setup, teardown } from '../_testHelpers/index.js' jest.setTimeout(120000) // Could not find 'Java', skipping 'Java' tests. -const _describe = process.env.JAVA_DETECTED ? describe : describe.skip +const _describe = env.JAVA_DETECTED ? describe : describe.skip _describe('Groovy tests', () => { // init diff --git a/tests/integration/java/java.test.js b/tests/integration/java/java.test.js index 1c7a48c33..d247317d8 100644 --- a/tests/integration/java/java.test.js +++ b/tests/integration/java/java.test.js @@ -1,11 +1,12 @@ import { resolve } from 'path' +import { env } from 'process' import fetch from 'node-fetch' import { joinUrl, setup, teardown } from '../_testHelpers/index.js' jest.setTimeout(60000) // Could not find 'Java', skipping 'Java' tests. -const _describe = process.env.JAVA_DETECTED ? describe : describe.skip +const _describe = env.JAVA_DETECTED ? describe : describe.skip _describe('Java tests', () => { // init diff --git a/tests/integration/kotlin/kotlin.test.js b/tests/integration/kotlin/kotlin.test.js index 9239e8d71..96625c8e1 100644 --- a/tests/integration/kotlin/kotlin.test.js +++ b/tests/integration/kotlin/kotlin.test.js @@ -1,11 +1,12 @@ import { resolve } from 'path' +import { env } from 'process' import fetch from 'node-fetch' import { joinUrl, setup, teardown } from '../_testHelpers/index.js' jest.setTimeout(120000) // Could not find 'Java', skipping 'Java' tests. -const _describe = process.env.JAVA_DETECTED ? describe : describe.skip +const _describe = env.JAVA_DETECTED ? describe : describe.skip _describe('Kotlin tests', () => { // init diff --git a/tests/integration/override-authorizer/override-authorizer.test.js b/tests/integration/override-authorizer/override-authorizer.test.js index 60f9af4cf..a022087f6 100644 --- a/tests/integration/override-authorizer/override-authorizer.test.js +++ b/tests/integration/override-authorizer/override-authorizer.test.js @@ -1,4 +1,5 @@ import { resolve } from 'path' +import { env } from 'process' import fetch from 'node-fetch' import { joinUrl, setup, teardown } from '../_testHelpers/index.js' @@ -27,7 +28,7 @@ const headerAuthorizer = { describe('override authorizer tests', () => { // init beforeAll(async () => { - process.env.AUTHORIZER = stringify(envAuthorizer) + env.AUTHORIZER = stringify(envAuthorizer) await setup({ servicePath: resolve(__dirname), }) @@ -35,7 +36,7 @@ describe('override authorizer tests', () => { // cleanup afterAll(async () => { - process.env.AUTHORIZER = undefined + env.AUTHORIZER = undefined await teardown() }) diff --git a/tests/integration/python/python-big-json/python-big-json.test.js b/tests/integration/python/python-big-json/python-big-json.test.js index 3f8586fb8..5f7d357d3 100644 --- a/tests/integration/python/python-big-json/python-big-json.test.js +++ b/tests/integration/python/python-big-json/python-big-json.test.js @@ -1,5 +1,6 @@ import { platform } from 'os' import { resolve } from 'path' +import { env } from 'process' import fetch from 'node-fetch' import { joinUrl, setup, teardown } from '../../_testHelpers/index.js' @@ -8,9 +9,7 @@ jest.setTimeout(60000) // skipping 'Python 3' tests on Windows for now. // Could not find 'Python 3' executable, skipping 'Python' tests. const _describe = - process.env.PYTHON3_DETECTED && platform() !== 'win32' - ? describe - : describe.skip + env.PYTHON3_DETECTED && platform() !== 'win32' ? describe : describe.skip _describe('Python 3 tests', () => { // init diff --git a/tests/integration/python/python2/python2.test.js b/tests/integration/python/python2/python2.test.js index 5ab9a21b4..1d7c2e706 100644 --- a/tests/integration/python/python2/python2.test.js +++ b/tests/integration/python/python2/python2.test.js @@ -1,11 +1,12 @@ import { resolve } from 'path' +import { env } from 'process' import fetch from 'node-fetch' import { joinUrl, setup, teardown } from '../../_testHelpers/index.js' jest.setTimeout(60000) // Could not find 'Python 2' executable, skipping 'Python' tests. -const _describe = process.env.PYTHON2_DETECTED ? describe : describe.skip +const _describe = env.PYTHON2_DETECTED ? describe : describe.skip _describe('Python 2 tests', () => { // init diff --git a/tests/integration/python/python3/python3.test.js b/tests/integration/python/python3/python3.test.js index 4341a0d1e..51b86992d 100644 --- a/tests/integration/python/python3/python3.test.js +++ b/tests/integration/python/python3/python3.test.js @@ -1,5 +1,6 @@ import { platform } from 'os' import { resolve } from 'path' +import { env } from 'process' import fetch from 'node-fetch' import { joinUrl, setup, teardown } from '../../_testHelpers/index.js' @@ -8,9 +9,7 @@ jest.setTimeout(60000) // skipping 'Python 3' tests on Windows for now. // Could not find 'Python 3' executable, skipping 'Python' tests. const _describe = - process.env.PYTHON3_DETECTED && platform() !== 'win32' - ? describe - : describe.skip + env.PYTHON3_DETECTED && platform() !== 'win32' ? describe : describe.skip _describe('Python 3 tests', () => { // init diff --git a/tests/integration/ruby/ruby.test.js b/tests/integration/ruby/ruby.test.js index 3d3e0615b..fbbfbcb8b 100644 --- a/tests/integration/ruby/ruby.test.js +++ b/tests/integration/ruby/ruby.test.js @@ -1,11 +1,12 @@ import { resolve } from 'path' +import { env } from 'process' import fetch from 'node-fetch' import { joinUrl, setup, teardown } from '../_testHelpers/index.js' jest.setTimeout(60000) // Could not find 'Ruby', skipping 'Ruby' tests. -const _describe = process.env.RUBY_DETECTED ? describe : describe.skip +const _describe = env.RUBY_DETECTED ? describe : describe.skip _describe('Ruby tests', () => { // init diff --git a/tests/integration/scala/scala.test.js b/tests/integration/scala/scala.test.js index c781222e7..c9ce84b26 100644 --- a/tests/integration/scala/scala.test.js +++ b/tests/integration/scala/scala.test.js @@ -1,11 +1,12 @@ import { resolve } from 'path' +import { env } from 'process' import fetch from 'node-fetch' import { joinUrl, setup, teardown } from '../_testHelpers/index.js' jest.setTimeout(60000) // Could not find 'Java', skipping 'Java' tests. -const _describe = process.env.JAVA_DETECTED ? describe : describe.skip +const _describe = env.JAVA_DETECTED ? describe : describe.skip _describe('Scala tests', () => { // init diff --git a/tests/manual/nodejs/subprocess.js b/tests/manual/nodejs/subprocess.js index a10eb9f0b..417ef6d40 100644 --- a/tests/manual/nodejs/subprocess.js +++ b/tests/manual/nodejs/subprocess.js @@ -1,6 +1,7 @@ 'use strict' const { exec } = require('child_process') +const process = require('process') console.log('Spawning offline as a separate process...') diff --git a/tests/manual/websocket/RouteSelection/test/e2e/ws.e2e.js b/tests/manual/websocket/RouteSelection/test/e2e/ws.e2e.js index 99eb07432..a4e14a887 100644 --- a/tests/manual/websocket/RouteSelection/test/e2e/ws.e2e.js +++ b/tests/manual/websocket/RouteSelection/test/e2e/ws.e2e.js @@ -3,6 +3,7 @@ /* eslint-disable import/no-extraneous-dependencies */ /* eslint-disable import/no-unresolved */ +const process = require('process') const chai = require('chai') const WebSocketTester = require('../support/WebSocketTester.js') diff --git a/tests/manual/websocket/main/handler.js b/tests/manual/websocket/main/handler.js index 82a570078..719e7ad4a 100644 --- a/tests/manual/websocket/main/handler.js +++ b/tests/manual/websocket/main/handler.js @@ -1,11 +1,12 @@ 'use strict' +const { env } = require('process') const AWS = require('aws-sdk') const { parse, stringify } = JSON const ddb = (() => { - if (process.env.IS_OFFLINE) + if (env.IS_OFFLINE) return new AWS.DynamoDB.DocumentClient({ region: 'localhost', endpoint: 'http://localhost:8000', diff --git a/tests/manual/websocket/main/test/e2e/ws.e2e.js b/tests/manual/websocket/main/test/e2e/ws.e2e.js index 2524d9589..f348173dd 100644 --- a/tests/manual/websocket/main/test/e2e/ws.e2e.js +++ b/tests/manual/websocket/main/test/e2e/ws.e2e.js @@ -5,26 +5,25 @@ /* eslint-disable no-unused-expressions */ /* eslint-disable no-undef */ -const chai = require('chai') -const chaiHttp = require('chai-http') - -chai.use(chaiHttp) - -const { expect } = chai +const { env } = require('process') const aws4 = require('aws4') - const awscred = require('awscred') +const chai = require('chai') +const chaiHttp = require('chai-http') const moment = require('moment') -const endpoint = process.env.npm_config_endpoint || 'ws://localhost:3001' -const timeout = process.env.npm_config_timeout - ? parseInt(process.env.npm_config_timeout, 10) +const endpoint = env.npm_config_endpoint || 'ws://localhost:3001' +const timeout = env.npm_config_timeout + ? parseInt(env.npm_config_timeout, 10) : 1000 const WebSocketTester = require('../support/WebSocketTester.js') +const { expect } = chai const { parse, stringify } = JSON const { keys } = Object +chai.use(chaiHttp) + describe('serverless', () => { describe('with WebSocket support', () => { let clients = [] diff --git a/tests/old-unit/LambdaProxyIntegrationEvent.test.js b/tests/old-unit/LambdaProxyIntegrationEvent.test.js index 2c524d9d6..040ee9789 100644 --- a/tests/old-unit/LambdaProxyIntegrationEvent.test.js +++ b/tests/old-unit/LambdaProxyIntegrationEvent.test.js @@ -1,3 +1,4 @@ +import { env } from 'process' import RequestBuilder from './support/RequestBuilder.js' import LambdaProxyIntegrationEvent from '../../src/events/http/lambda-events/LambdaProxyIntegrationEvent.js' @@ -621,15 +622,14 @@ describe('LambdaProxyIntegrationEvent', () => { let lambdaProxyIntegrationEvent beforeEach(() => { - process.env.SLS_ACCOUNT_ID = 'customAccountId' - process.env.SLS_API_KEY = 'customApiKey' - process.env.SLS_CALLER = 'customCaller' - process.env.SLS_COGNITO_AUTHENTICATION_PROVIDER = + env.SLS_ACCOUNT_ID = 'customAccountId' + env.SLS_API_KEY = 'customApiKey' + env.SLS_CALLER = 'customCaller' + env.SLS_COGNITO_AUTHENTICATION_PROVIDER = 'customCognitoAuthenticationProvider' - process.env.SLS_COGNITO_AUTHENTICATION_TYPE = - 'customCognitoAuthenticationType' - process.env.SLS_COGNITO_IDENTITY_ID = 'customCognitoIdentityId' - process.env.SLS_COGNITO_IDENTITY_POOL_ID = 'customCognitoIdentityPoolId' + env.SLS_COGNITO_AUTHENTICATION_TYPE = 'customCognitoAuthenticationType' + env.SLS_COGNITO_IDENTITY_ID = 'customCognitoIdentityId' + env.SLS_COGNITO_IDENTITY_POOL_ID = 'customCognitoIdentityPoolId' lambdaProxyIntegrationEvent = new LambdaProxyIntegrationEvent( request, diff --git a/tests/scenario/docker-in-docker/docker-in-docker.test.js b/tests/scenario/docker-in-docker/docker-in-docker.test.js index 6cb879015..6167d2ddf 100644 --- a/tests/scenario/docker-in-docker/docker-in-docker.test.js +++ b/tests/scenario/docker-in-docker/docker-in-docker.test.js @@ -1,4 +1,5 @@ import { platform } from 'os' +import { env } from 'process' import execa from 'execa' import fetch from 'node-fetch' import { @@ -8,7 +9,7 @@ import { jest.setTimeout(180000) -const _describe = process.env.DOCKER_COMPOSE_DETECTED ? describe : describe.skip +const _describe = env.DOCKER_COMPOSE_DETECTED ? describe : describe.skip _describe('docker in docker', () => { // init diff --git a/tests/scenario/docker-serverless-webpack-test/docker-serverless-webpack.test.js b/tests/scenario/docker-serverless-webpack-test/docker-serverless-webpack.test.js index e4480da08..eb8d21123 100644 --- a/tests/scenario/docker-serverless-webpack-test/docker-serverless-webpack.test.js +++ b/tests/scenario/docker-serverless-webpack-test/docker-serverless-webpack.test.js @@ -1,4 +1,5 @@ import { resolve } from 'path' +import { env } from 'process' import fetch from 'node-fetch' import { joinUrl, @@ -8,7 +9,7 @@ import { jest.setTimeout(120000) -const _describe = process.env.DOCKER_DETECTED ? describe : describe.skip +const _describe = env.DOCKER_DETECTED ? describe : describe.skip _describe('docker and serverless-webpack', () => { // init