diff --git a/.eslintrc.json b/.eslintrc.json index 73acfd71ca..1ec3087f50 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -3,8 +3,15 @@ "env": { "mocha": true }, + "parserOptions": { + "sourceType": "module", + "ecmaVersion": 2020 + }, "rules": { "node/no-missing-require": ["off"], - "node/no-unpublished-require": ["off"] + "node/no-missing-import": ["off"], + "node/no-unpublished-require": ["off"], + "node/no-unpublished-import": ["off"], + "node/no-unsupported-features/es-syntax": ["off"] } -} \ No newline at end of file +} diff --git a/eventarc/audit-storage/package.json b/eventarc/audit-storage/package.json index c9629bcf03..bd0289611b 100644 --- a/eventarc/audit-storage/package.json +++ b/eventarc/audit-storage/package.json @@ -10,8 +10,9 @@ "type": "git", "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git" }, + "type": "module", "engines": { - "node": ">= 12.0.0" + "node": ">= 12.2.0" }, "scripts": { "start": "node index.js", @@ -24,7 +25,9 @@ "express": "^4.16.4" }, "devDependencies": { - "got": "^11.5.0", + "@types/sinon": "^10.0.13", + "@types/supertest": "^2.0.12", + "got": "^12.0.0", "mocha": "^10.0.0", "sinon": "^15.0.0", "supertest": "^6.0.0" diff --git a/eventarc/audit-storage/test/app.test.js b/eventarc/audit-storage/test/app.test.js index 3138250af1..fd28b5c135 100644 --- a/eventarc/audit-storage/test/app.test.js +++ b/eventarc/audit-storage/test/app.test.js @@ -1,4 +1,4 @@ -// Copyright 2020, Google LLC. +// Copyright 2020 Google LLC // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -18,16 +18,22 @@ 'use strict'; -const assert = require('assert'); -const path = require('path'); -const supertest = require('supertest'); -const sinon = require('sinon'); +import assert from 'assert'; +import path from 'path'; +import supertest from 'supertest'; +import sinon from 'sinon'; +import {createRequire} from 'module'; + +import {fileURLToPath} from 'url'; +import {dirname} from 'path'; +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); let request; describe('Unit Tests', () => { before(() => { - const app = require(path.join(__dirname, '..', 'app')); + const app = createRequire(path.join(__dirname, '..', 'app')); request = supertest(app); }); diff --git a/eventarc/audit-storage/test/system.test.js b/eventarc/audit-storage/test/system.test.js index 9ba94a66b6..2d027291e4 100644 --- a/eventarc/audit-storage/test/system.test.js +++ b/eventarc/audit-storage/test/system.test.js @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -const assert = require('assert'); -const got = require('got'); +import assert from 'assert'; +import got from 'got'; -const request = (method, route, base_url) => { +function request(method, route, base_url) { const {ID_TOKEN} = process.env; if (!ID_TOKEN) { throw Error('"ID_TOKEN" environment variable is required.'); @@ -28,7 +28,7 @@ const request = (method, route, base_url) => { method: method || 'get', throwHttpErrors: false, }); -}; +} describe('End-to-End Tests', () => { const {BASE_URL} = process.env; diff --git a/eventarc/generic/package.json b/eventarc/generic/package.json index ded0be6c20..634a251bdd 100644 --- a/eventarc/generic/package.json +++ b/eventarc/generic/package.json @@ -2,6 +2,7 @@ "name": "cloud-eventarc-generic", "version": "1.0.0", "private": true, + "type": "module", "main": "index.js", "author": "Google LLC", "license": "Apache-2.0", @@ -10,7 +11,7 @@ "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git" }, "engines": { - "node": ">= 12.0.0" + "node": ">= 12.2.0" }, "scripts": { "start": "node index.js", @@ -21,7 +22,9 @@ "express": "^4.16.4" }, "devDependencies": { - "got": "^11.5.0", + "@types/sinon": "^10.0.13", + "@types/supertest": "^2.0.12", + "got": "^12.0.0", "mocha": "^10.0.0", "sinon": "^15.0.0", "supertest": "^6.0.0", diff --git a/eventarc/generic/test/app.test.js b/eventarc/generic/test/app.test.js index 34b490930e..07451fcae1 100644 --- a/eventarc/generic/test/app.test.js +++ b/eventarc/generic/test/app.test.js @@ -1,4 +1,4 @@ -// Copyright 2019, Google LLC. +// Copyright 2019 Google LLC // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -18,15 +18,21 @@ 'use strict'; -const assert = require('assert'); -const path = require('path'); -const supertest = require('supertest'); +import assert from 'assert'; +import path from 'path'; +import supertest from 'supertest'; +import {createRequire} from 'module'; +import {fileURLToPath} from 'url'; +import {dirname} from 'path'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); let request; describe('Unit Tests', () => { before(() => { - const app = require(path.join(__dirname, '..', 'app')); + const app = createRequire(path.join(__dirname, '..', 'app')); request = supertest(app); }); diff --git a/eventarc/generic/test/system.test.js b/eventarc/generic/test/system.test.js index 159f30037a..f8db39e0cb 100644 --- a/eventarc/generic/test/system.test.js +++ b/eventarc/generic/test/system.test.js @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -const assert = require('assert'); -const got = require('got'); +import assert from 'assert'; +import got from 'got'; const request = (method, route, base_url) => { const {ID_TOKEN} = process.env; diff --git a/eventarc/pubsub/package.json b/eventarc/pubsub/package.json index 0bb76d3165..fe9cb104eb 100644 --- a/eventarc/pubsub/package.json +++ b/eventarc/pubsub/package.json @@ -2,6 +2,7 @@ "name": "cloud-eventarc-pubsub", "version": "1.0.0", "private": true, + "type": "module", "description": "Simple Events for Cloud Run – Pub/Sub sample", "main": "index.js", "author": "Google LLC", @@ -11,7 +12,7 @@ "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git" }, "engines": { - "node": ">= 12.0.0" + "node": ">= 12.2.0" }, "scripts": { "start": "node index.js", @@ -25,7 +26,9 @@ "express": "^4.16.4" }, "devDependencies": { - "got": "^11.5.0", + "@types/sinon": "^10.0.13", + "@types/supertest": "^2.0.12", + "got": "^12.0.0", "mocha": "^10.0.0", "sinon": "^15.0.0", "supertest": "^6.0.0", diff --git a/eventarc/pubsub/test/app.test.js b/eventarc/pubsub/test/app.test.js index 7cbd73d174..fbfd7acc03 100644 --- a/eventarc/pubsub/test/app.test.js +++ b/eventarc/pubsub/test/app.test.js @@ -1,4 +1,4 @@ -// Copyright 2019, Google LLC. +// Copyright 2019 Google LLC // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -18,15 +18,21 @@ 'use strict'; -const assert = require('assert'); -const path = require('path'); -const supertest = require('supertest'); +import assert from 'assert'; +import path from 'path'; +import supertest from 'supertest'; +import {createRequire} from 'module'; +import {fileURLToPath} from 'url'; +import {dirname} from 'path'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); let request; describe('Unit Tests', () => { before(() => { - const app = require(path.join(__dirname, '..', 'app')); + const app = createRequire(path.join(__dirname, '..', 'app')); request = supertest(app); }); diff --git a/eventarc/pubsub/test/system.test.js b/eventarc/pubsub/test/system.test.js index 159f30037a..f8db39e0cb 100644 --- a/eventarc/pubsub/test/system.test.js +++ b/eventarc/pubsub/test/system.test.js @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -const assert = require('assert'); -const got = require('got'); +import assert from 'assert'; +import got from 'got'; const request = (method, route, base_url) => { const {ID_TOKEN} = process.env; diff --git a/run/hello-broken/package.json b/run/hello-broken/package.json index d639034de3..2fbdabf5a0 100644 --- a/run/hello-broken/package.json +++ b/run/hello-broken/package.json @@ -3,6 +3,7 @@ "description": "Broken Cloud Run service for troubleshooting practice", "version": "1.0.0", "private": true, + "type": "module", "main": "index.js", "scripts": { "start": "node index.js", @@ -19,7 +20,7 @@ }, "devDependencies": { "google-auth-library": "^8.0.0", - "got": "^11.0.0", + "got": "^12.0.0", "mocha": "^10.0.0" } } diff --git a/run/hello-broken/test/system.test.js b/run/hello-broken/test/system.test.js index 639c8dc07e..bb75c77537 100644 --- a/run/hello-broken/test/system.test.js +++ b/run/hello-broken/test/system.test.js @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -const assert = require('assert'); -const request = require('got'); -const {execSync} = require('child_process'); -const {GoogleAuth} = require('google-auth-library'); +import assert from 'assert'; +import got from 'got'; +import {execSync} from 'child_process'; +import {GoogleAuth} from 'google-auth-library'; const auth = new GoogleAuth(); const get = (route, base_url, id_token, retry = 3) => { - return request(new URL(route, base_url.trim()), { + return got(new URL(route, base_url.trim()), { headers: { Authorization: `${id_token.trim()}`, }, diff --git a/run/helloworld/package.json b/run/helloworld/package.json index 50ae6e0245..a7bd2bb771 100644 --- a/run/helloworld/package.json +++ b/run/helloworld/package.json @@ -3,6 +3,7 @@ "description": "Simple hello world sample in Node", "version": "1.0.0", "private": true, + "type": "module", "main": "index.js", "scripts": { "start": "node index.js", @@ -10,7 +11,7 @@ "system-test": "NAME=Cloud mocha test/system.test.js --timeout=180000" }, "engines": { - "node": ">= 12.0.0" + "node": ">= 12.2.0" }, "author": "Google LLC", "license": "Apache-2.0", @@ -19,7 +20,7 @@ }, "devDependencies": { "google-auth-library": "^8.0.0", - "got": "^11.0.0", + "got": "^12.0.0", "mocha": "^10.0.0", "supertest": "^6.0.0" } diff --git a/run/helloworld/test/index.test.js b/run/helloworld/test/index.test.js index 7e73b12888..884408b592 100644 --- a/run/helloworld/test/index.test.js +++ b/run/helloworld/test/index.test.js @@ -12,14 +12,20 @@ // See the License for the specific language governing permissions and // limitations under the License. -const assert = require('assert'); -const path = require('path'); -const supertest = require('supertest'); +import assert from 'assert'; +import path from 'path'; +import supertest from 'supertest'; +import {createRequire} from 'module'; +import {fileURLToPath} from 'url'; +import {dirname} from 'path'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); let request; describe('Unit Tests', () => { before(() => { - const app = require(path.join(__dirname, '..', 'index')); + const app = createRequire(path.join(__dirname, '..', 'index')); request = supertest(app); }); diff --git a/run/helloworld/test/system.test.js b/run/helloworld/test/system.test.js index d37258d935..c41d251cfe 100644 --- a/run/helloworld/test/system.test.js +++ b/run/helloworld/test/system.test.js @@ -14,7 +14,7 @@ const assert = require('assert'); const {execSync} = require('child_process'); -const request = require('got'); +import got from 'got'; const {GoogleAuth} = require('google-auth-library'); const auth = new GoogleAuth(); @@ -23,7 +23,7 @@ const get = (route, base_url) => { throw Error('"ID_TOKEN" environment variable is required.'); } - return request(new URL(route, base_url.trim()), { + return got(new URL(route, base_url.trim()), { headers: { Authorization: `${ID_TOKEN.trim()}`, }, diff --git a/run/idp-sql/package.json b/run/idp-sql/package.json index d35eefa03e..8331837e9a 100644 --- a/run/idp-sql/package.json +++ b/run/idp-sql/package.json @@ -3,6 +3,7 @@ "description": "Identity Platform and Cloud SQL integrations sample for Cloud Run.", "version": "0.0.1", "private": true, + "type": "module", "license": "Apache-2.0", "author": "Google LLC", "repository": { @@ -10,7 +11,7 @@ "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git" }, "engines": { - "node": ">=12.0.0" + "node": ">=12.2.0" }, "scripts": { "start": "node index.js", @@ -28,7 +29,7 @@ "winston": "3.8.2" }, "devDependencies": { - "got": "^11.7.0", + "got": "^12.0.0", "mocha": "^10.0.0", "short-uuid": "^4.1.0", "sinon": "^15.0.0", diff --git a/run/idp-sql/test/app.test.js b/run/idp-sql/test/app.test.js index 3d4f989840..6fa53e9067 100644 --- a/run/idp-sql/test/app.test.js +++ b/run/idp-sql/test/app.test.js @@ -14,16 +14,22 @@ 'use strict'; -const path = require('path'); -const assert = require('assert'); -const supertest = require('supertest'); -const {buildRenderedHtml} = require('../handlebars'); +import path from 'path'; +import assert from 'assert'; +import supertest from 'supertest'; +import {createRequire} from 'module'; +import {fileURLToPath} from 'url'; +import {dirname} from 'path'; +import {buildRenderedHtml} from '../handlebars'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); let request; describe('Unit Tests', () => { before(async () => { - const app = require(path.join(__dirname, '..', 'app')); + const app = createRequire(path.join(__dirname, '..', 'app')); request = supertest(app); }); diff --git a/run/idp-sql/test/system.test.js b/run/idp-sql/test/system.test.js index 343718467c..11dabb9583 100644 --- a/run/idp-sql/test/system.test.js +++ b/run/idp-sql/test/system.test.js @@ -14,10 +14,10 @@ 'use strict'; -const assert = require('assert'); -const got = require('got'); -const admin = require('firebase-admin'); -const {spawnSync, execSync} = require('child_process'); +import assert from 'assert'; +import got from 'got'; +import admin from 'firebase-admin'; +import {spawnSync, execSync} from 'child_process'; admin.initializeApp(); diff --git a/run/image-processing/package.json b/run/image-processing/package.json index 3881b2ead3..fbd21ee1db 100644 --- a/run/image-processing/package.json +++ b/run/image-processing/package.json @@ -11,7 +11,7 @@ "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git" }, "engines": { - "node": ">= 12.0.0" + "node": ">= 12.2.0" }, "scripts": { "start": "node index.js", @@ -26,7 +26,7 @@ }, "devDependencies": { "google-auth-library": "^8.0.0", - "got": "^11.5.0", + "got": "^12.0.0", "mocha": "^10.0.0", "supertest": "^6.0.0" } diff --git a/run/image-processing/test/app.test.js b/run/image-processing/test/app.test.js index 0e9b12da37..a6c214a7ee 100644 --- a/run/image-processing/test/app.test.js +++ b/run/image-processing/test/app.test.js @@ -1,11 +1,31 @@ -const path = require('path'); -const supertest = require('supertest'); +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import path from 'path'; +import supertest from 'supertest'; +import {createRequire} from 'module'; +import {fileURLToPath} from 'url'; +import {dirname} from 'path'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); let request; describe('Unit Tests', () => { before(() => { - const app = require(path.join(__dirname, '..', 'app')); + const app = createRequire(path.join(__dirname, '..', 'app')); request = supertest(app); }); diff --git a/run/image-processing/test/system.test.js b/run/image-processing/test/system.test.js index 65722bb83a..c4e39ca78a 100644 --- a/run/image-processing/test/system.test.js +++ b/run/image-processing/test/system.test.js @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -const assert = require('assert'); -const {execSync} = require('child_process'); -const got = require('got'); -const {GoogleAuth} = require('google-auth-library'); +import assert from 'assert'; +import {execSync} from 'child_process'; +import got from 'got'; +import {GoogleAuth} from 'google-auth-library'; const auth = new GoogleAuth(); let BASE_URL, ID_TOKEN; diff --git a/run/logging-manual/metadata.js b/run/logging-manual/metadata.js index 720654c3a7..1d6ef3a3b3 100644 --- a/run/logging-manual/metadata.js +++ b/run/logging-manual/metadata.js @@ -1,4 +1,18 @@ -const request = require('got'); +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import got from 'got'; // Load the project ID from GCP metadata server. // You can also use https://www.npmjs.com/package/gcp-metadata. @@ -8,6 +22,6 @@ exports.getProjectId = async () => { const options = { headers: {'Metadata-Flavor': 'Google'}, }; - const response = await request(METADATA_PROJECT_ID_URL, options); + const response = await got(METADATA_PROJECT_ID_URL, options); return response.body; }; diff --git a/run/logging-manual/package.json b/run/logging-manual/package.json index 39f08e92b1..b8291d37e9 100644 --- a/run/logging-manual/package.json +++ b/run/logging-manual/package.json @@ -3,10 +3,14 @@ "description": "Demonstrates logging on Cloud Run", "main": "index.js", "private": true, + "type": "module", "repository": { "type": "git", "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git" }, + "engines": { + "node": ">=12.2.0" + }, "scripts": { "start": "node index.js", "test": "echo \"Error: no test specified\" && exit 0", @@ -16,7 +20,7 @@ "license": "Apache-2.0", "dependencies": { "express": "^4.17.1", - "got": "^11.0.0" + "got": "^12.0.0" }, "devDependencies": { "@google-cloud/logging": "^10.0.0", diff --git a/run/logging-manual/test/system.test.js b/run/logging-manual/test/system.test.js index 9f1a8d36eb..f40854b0e8 100644 --- a/run/logging-manual/test/system.test.js +++ b/run/logging-manual/test/system.test.js @@ -12,11 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -const assert = require('assert'); -const request = require('got'); -const {Logging} = require('@google-cloud/logging'); -const {execSync} = require('child_process'); -const {GoogleAuth} = require('google-auth-library'); +import assert from 'assert'; +import got from 'got'; +import {Logging} from '@google-cloud/logging'; +import {execSync} from 'child_process'; +import {createRequire} from 'module'; +import {GoogleAuth} from 'google-auth-library'; const auth = new GoogleAuth(); const {promisify} = require('util'); @@ -24,7 +25,7 @@ const setTimeoutPromise = promisify(setTimeout); // Support concurrency by setting the service name to something unique. // The service name must be the same used to deploy to Cloud Run. -const service_name = process.env.SERVICE_NAME || require('../package').name; +const service_name = process.env.SERVICE_NAME || createRequire('../package').name; const logging = new Logging({ projectId: process.env.GOOGLE_CLOUD_PROJECT, @@ -141,7 +142,7 @@ describe('Logging', () => { } console.log(`Sending test requests to ${BASE_URL}`); - await request(BASE_URL.trim(), { + await got(BASE_URL.trim(), { headers: { Authorization: `${ID_TOKEN.trim()}`, }, diff --git a/run/markdown-preview/editor/package.json b/run/markdown-preview/editor/package.json index fba1085409..336faa2c00 100644 --- a/run/markdown-preview/editor/package.json +++ b/run/markdown-preview/editor/package.json @@ -21,7 +21,7 @@ "dependencies": { "express": "^4.17.1", "google-auth-library": "^8.0.0", - "got": "^11.8.0", + "got": "^12.0.0", "handlebars": "^4.7.6" }, "devDependencies": { diff --git a/run/markdown-preview/editor/render.js b/run/markdown-preview/editor/render.js index 9a35f6c3b5..49e0105d4a 100644 --- a/run/markdown-preview/editor/render.js +++ b/run/markdown-preview/editor/render.js @@ -15,7 +15,7 @@ // [START cloudrun_secure_request] // [START run_secure_request] const {GoogleAuth} = require('google-auth-library'); -const got = require('got'); +import got from 'got'; const auth = new GoogleAuth(); let client, serviceUrl; diff --git a/run/markdown-preview/editor/test/system.test.js b/run/markdown-preview/editor/test/system.test.js index da5f55e622..e82ad5e063 100644 --- a/run/markdown-preview/editor/test/system.test.js +++ b/run/markdown-preview/editor/test/system.test.js @@ -13,7 +13,7 @@ // limitations under the License. const assert = require('assert'); -const got = require('got'); +import got from 'got'; const {execSync} = require('child_process'); const {GoogleAuth} = require('google-auth-library'); const auth = new GoogleAuth(); diff --git a/run/markdown-preview/renderer/package.json b/run/markdown-preview/renderer/package.json index 301a74c3ad..d0ff257c8f 100644 --- a/run/markdown-preview/renderer/package.json +++ b/run/markdown-preview/renderer/package.json @@ -23,7 +23,7 @@ }, "devDependencies": { "google-auth-library": "^8.0.0", - "got": "^11.5.0", + "got": "^12.0.0", "mocha": "^10.0.0", "sinon": "^15.0.0", "supertest": "^6.0.0" diff --git a/run/markdown-preview/renderer/test/system.test.js b/run/markdown-preview/renderer/test/system.test.js index f1ac45557c..fd4b98d25b 100644 --- a/run/markdown-preview/renderer/test/system.test.js +++ b/run/markdown-preview/renderer/test/system.test.js @@ -13,7 +13,7 @@ // limitations under the License. const assert = require('assert'); -const got = require('got'); +import got from 'got'; const {execSync} = require('child_process'); const {GoogleAuth} = require('google-auth-library'); const auth = new GoogleAuth(); diff --git a/run/pubsub/package.json b/run/pubsub/package.json index 6cd8833dd9..4b07a8fae9 100644 --- a/run/pubsub/package.json +++ b/run/pubsub/package.json @@ -11,7 +11,7 @@ "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git" }, "engines": { - "node": ">= 12.0.0" + "node": ">= 12.2.0" }, "scripts": { "start": "node index.js", @@ -22,8 +22,9 @@ "express": "^4.16.4" }, "devDependencies": { + "@types/uuid": "9.0.0", "google-auth-library": "^8.0.0", - "got": "^11.5.0", + "got": "^12.0.0", "mocha": "^10.0.0", "sinon": "^15.0.0", "supertest": "^6.0.0", diff --git a/run/pubsub/test/app.test.js b/run/pubsub/test/app.test.js index db1b2a34cc..ef25398ade 100644 --- a/run/pubsub/test/app.test.js +++ b/run/pubsub/test/app.test.js @@ -1,4 +1,4 @@ -// Copyright 2019, Google LLC. +// Copyright 2019 Google LLC // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -18,17 +18,18 @@ 'use strict'; -const assert = require('assert'); -const path = require('path'); -const supertest = require('supertest'); -const uuid = require('uuid'); -const sinon = require('sinon'); +import assert from 'assert'; +import path from 'path'; +import supertest from 'supertest'; +import uuid from 'uuid'; +import sinon from 'sinon'; +import {createRequire} from 'module'; let request; describe('Unit Tests', () => { before(() => { - const app = require(path.join(__dirname, '..', 'app')); + const app = createRequire(path.join(__dirname, '..', 'app')); request = supertest(app); }); diff --git a/run/pubsub/test/system.test.js b/run/pubsub/test/system.test.js index 86dffceaee..f70e86c5d7 100644 --- a/run/pubsub/test/system.test.js +++ b/run/pubsub/test/system.test.js @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -const assert = require('assert'); -const got = require('got'); -const {GoogleAuth} = require('google-auth-library'); +import assert from 'assert'; +import got from 'got'; +import GoogleAuth from 'google-auth-library'; const auth = new GoogleAuth(); -const {execSync} = require('child_process'); +import {execSync} from 'child_process'; let BASE_URL, ID_TOKEN; describe('End-to-End Tests', () => { diff --git a/run/system-package/package.json b/run/system-package/package.json index d15e391b80..426ce2ed1c 100644 --- a/run/system-package/package.json +++ b/run/system-package/package.json @@ -4,20 +4,21 @@ "description": "Demonstrates a Cloud Run service which provides a CLI tool over HTTP.", "main": "index.js", "private": true, + "type": "module", "scripts": { "start": "node index.js", "test": "mocha test/app.test.js --check-leaks", "system-test": "mocha test/system.test.js --timeout=360000 --exit" }, "engines": { - "node": ">= 12.0.0" + "node": ">= 12.2.0" }, "dependencies": { "express": "^4.17.1" }, "devDependencies": { "google-auth-library": "^8.0.0", - "got": "^11.5.0", + "got": "^12.0.0", "mocha": "^10.0.0", "supertest": "^6.0.0" } diff --git a/run/system-package/test/app.test.js b/run/system-package/test/app.test.js index affcaefb88..24bd296623 100644 --- a/run/system-package/test/app.test.js +++ b/run/system-package/test/app.test.js @@ -14,11 +14,12 @@ 'use strict'; -const path = require('path'); -const supertest = require('supertest'); +import path from 'path'; +import supertest from 'supertest'; +import {createRequire} from 'module'; describe('Unit Tests', () => { - const app = require(path.join(__dirname, '..', 'app')); + const app = createRequire(path.join(__dirname, '..', 'app')); const request = supertest(app); describe('should fail', () => { diff --git a/run/system-package/test/system.test.js b/run/system-package/test/system.test.js index 2797e16dfa..50b91e6d81 100644 --- a/run/system-package/test/system.test.js +++ b/run/system-package/test/system.test.js @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -const assert = require('assert'); -const got = require('got'); -const {execSync} = require('child_process'); -const {GoogleAuth} = require('google-auth-library'); +import assert from 'assert'; +import got from 'got'; +import {execSync} from 'child_process'; +import {GoogleAuth} from 'google-auth-library'; const auth = new GoogleAuth(); const request = (method, route, base_url, id_token) => { diff --git a/run/websockets/package.json b/run/websockets/package.json index 5b979484b3..6d5330abc0 100644 --- a/run/websockets/package.json +++ b/run/websockets/package.json @@ -3,6 +3,7 @@ "description": "Node.js websockets sample for Cloud Run", "version": "0.0.1", "private": true, + "type": "module", "license": "Apache Version 2.0", "author": "Google LLC", "scripts": { @@ -17,7 +18,7 @@ }, "devDependencies": { "google-auth-library": "^8.0.2", - "got": "^11.8.3", + "got": "^12.0.0", "puppeteer": "^15.1.0" } } diff --git a/run/websockets/test/system.test.js b/run/websockets/test/system.test.js index 642da06785..6e1cdc2a29 100644 --- a/run/websockets/test/system.test.js +++ b/run/websockets/test/system.test.js @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -const assert = require('assert'); -const got = require('got'); -const {execSync} = require('child_process'); -const {GoogleAuth} = require('google-auth-library'); -const puppeteer = require('puppeteer'); +import assert from 'assert'; +import got from 'got'; +import {execSync} from 'child_process'; +import {GoogleAuth} from 'google-auth-library'; +import puppeteer from 'puppeteer'; const auth = new GoogleAuth(); describe('End-to-End Tests', () => {