From d3ebb80d109d89e0c9bfceb2888d47c23dfda3cf Mon Sep 17 00:00:00 2001 From: Katie McLaughlin Date: Mon, 22 Jan 2024 16:16:29 +1100 Subject: [PATCH 1/3] fix: update run/helloworld to esmodules --- run/helloworld/index.js | 4 ++-- run/helloworld/package.json | 1 + run/helloworld/test/index.test.js | 8 ++++---- run/helloworld/test/system.test.js | 8 ++++---- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/run/helloworld/index.js b/run/helloworld/index.js index 7a11bc2029..4a0137253f 100644 --- a/run/helloworld/index.js +++ b/run/helloworld/index.js @@ -14,7 +14,7 @@ // [START cloudrun_helloworld_service] // [START run_helloworld_service] -const express = require('express'); +import express from 'express'; const app = express(); app.get('/', (req, res) => { @@ -30,4 +30,4 @@ app.listen(port, () => { // [END cloudrun_helloworld_service] // Exports for testing purposes. -module.exports = app; +export default app; \ No newline at end of file diff --git a/run/helloworld/package.json b/run/helloworld/package.json index 7d25ad5c10..e13550241d 100644 --- a/run/helloworld/package.json +++ b/run/helloworld/package.json @@ -9,6 +9,7 @@ "test": "c8 mocha -p -j 2 test/index.test.js --exit", "system-test": "NAME=Cloud c8 mocha -p -j 2 test/system.test.js --timeout=180000" }, + "type": "module", "engines": { "node": ">=16.0.0" }, diff --git a/run/helloworld/test/index.test.js b/run/helloworld/test/index.test.js index 7e73b12888..1ee617a6ba 100644 --- a/run/helloworld/test/index.test.js +++ b/run/helloworld/test/index.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 path = require('path'); -const supertest = require('supertest'); +import assert from 'assert'; +import path from 'path'; +import supertest from 'supertest'; +import app from '../index.js' let request; describe('Unit Tests', () => { before(() => { - const app = require(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..3980f27031 100644 --- a/run/helloworld/test/system.test.js +++ b/run/helloworld/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 request = require('got'); -const {GoogleAuth} = require('google-auth-library'); +import assert from 'assert'; +import {execSync} from 'child_process'; +import request from 'got'; +import {GoogleAuth} from 'google-auth-library'; const auth = new GoogleAuth(); const get = (route, base_url) => { From 38bc54b7958dbd95f0c9c187cbbbb7edb6b7987e Mon Sep 17 00:00:00 2001 From: Katie McLaughlin Date: Mon, 22 Jan 2024 16:16:41 +1100 Subject: [PATCH 2/3] fix: lint --- run/helloworld/test/system.test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/run/helloworld/test/system.test.js b/run/helloworld/test/system.test.js index 3980f27031..2e9e24bee2 100644 --- a/run/helloworld/test/system.test.js +++ b/run/helloworld/test/system.test.js @@ -33,23 +33,23 @@ const get = (route, base_url) => { let BASE_URL, ID_TOKEN; describe('End-to-End Tests', () => { - const {GOOGLE_CLOUD_PROJECT} = process.env; + const { GOOGLE_CLOUD_PROJECT } = process.env; if (!GOOGLE_CLOUD_PROJECT) { throw Error('"GOOGLE_CLOUD_PROJECT" env var not found.'); } - let {SERVICE_NAME} = process.env; + let { SERVICE_NAME } = process.env; if (!SERVICE_NAME) { SERVICE_NAME = 'helloworld'; console.log( `"SERVICE_NAME" env var not found. Defaulting to "${SERVICE_NAME}"` ); } - let {NAME} = process.env; + let { NAME } = process.env; if (!NAME) { NAME = 'Cloud'; console.log(`"NAME" env var not found. Defaulting to "${NAME}"`); } - const {SAMPLE_VERSION} = process.env; + const { SAMPLE_VERSION } = process.env; const PLATFORM = 'managed'; const REGION = 'us-central1'; before(async () => { @@ -62,13 +62,13 @@ describe('End-to-End Tests', () => { if (SAMPLE_VERSION) buildCmd += `,_VERSION=${SAMPLE_VERSION}`; console.log('Starting Cloud Build...'); - execSync(buildCmd, {timeout: 240000}); // timeout at 4 mins + execSync(buildCmd, { timeout: 240000 }); // timeout at 4 mins console.log('Cloud Build completed.'); // Retrieve URL of Cloud Run service const url = execSync( `gcloud run services describe ${SERVICE_NAME} --project=${GOOGLE_CLOUD_PROJECT} ` + - `--platform=${PLATFORM} --region=${REGION} --format='value(status.url)'` + `--platform=${PLATFORM} --region=${REGION} --format='value(status.url)'` ); BASE_URL = url.toString('utf-8').trim(); From 0edb3242720588cad970519c13990642ec545c5f Mon Sep 17 00:00:00 2001 From: Katie McLaughlin Date: Mon, 22 Jan 2024 16:39:22 +1100 Subject: [PATCH 3/3] fix: gts fix --- .eslintrc.json | 3 +++ run/helloworld/index.js | 2 +- run/helloworld/test/index.test.js | 3 +-- run/helloworld/test/system.test.js | 12 ++++++------ 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 932cc6e825..7e5a1dd078 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -10,5 +10,8 @@ "node/no-unpublished-import": ["off"], "node/no-unpublished-require": ["off"], "node/no-unsupported-features/es-syntax": ["off"] + }, + "parserOptions": { + "sourceType": "module" } } diff --git a/run/helloworld/index.js b/run/helloworld/index.js index 4a0137253f..42e162f2eb 100644 --- a/run/helloworld/index.js +++ b/run/helloworld/index.js @@ -30,4 +30,4 @@ app.listen(port, () => { // [END cloudrun_helloworld_service] // Exports for testing purposes. -export default app; \ No newline at end of file +export default app; diff --git a/run/helloworld/test/index.test.js b/run/helloworld/test/index.test.js index 1ee617a6ba..90793379cb 100644 --- a/run/helloworld/test/index.test.js +++ b/run/helloworld/test/index.test.js @@ -13,9 +13,8 @@ // limitations under the License. import assert from 'assert'; -import path from 'path'; import supertest from 'supertest'; -import app from '../index.js' +import app from '../index.js'; let request; describe('Unit Tests', () => { diff --git a/run/helloworld/test/system.test.js b/run/helloworld/test/system.test.js index 2e9e24bee2..3980f27031 100644 --- a/run/helloworld/test/system.test.js +++ b/run/helloworld/test/system.test.js @@ -33,23 +33,23 @@ const get = (route, base_url) => { let BASE_URL, ID_TOKEN; describe('End-to-End Tests', () => { - const { GOOGLE_CLOUD_PROJECT } = process.env; + const {GOOGLE_CLOUD_PROJECT} = process.env; if (!GOOGLE_CLOUD_PROJECT) { throw Error('"GOOGLE_CLOUD_PROJECT" env var not found.'); } - let { SERVICE_NAME } = process.env; + let {SERVICE_NAME} = process.env; if (!SERVICE_NAME) { SERVICE_NAME = 'helloworld'; console.log( `"SERVICE_NAME" env var not found. Defaulting to "${SERVICE_NAME}"` ); } - let { NAME } = process.env; + let {NAME} = process.env; if (!NAME) { NAME = 'Cloud'; console.log(`"NAME" env var not found. Defaulting to "${NAME}"`); } - const { SAMPLE_VERSION } = process.env; + const {SAMPLE_VERSION} = process.env; const PLATFORM = 'managed'; const REGION = 'us-central1'; before(async () => { @@ -62,13 +62,13 @@ describe('End-to-End Tests', () => { if (SAMPLE_VERSION) buildCmd += `,_VERSION=${SAMPLE_VERSION}`; console.log('Starting Cloud Build...'); - execSync(buildCmd, { timeout: 240000 }); // timeout at 4 mins + execSync(buildCmd, {timeout: 240000}); // timeout at 4 mins console.log('Cloud Build completed.'); // Retrieve URL of Cloud Run service const url = execSync( `gcloud run services describe ${SERVICE_NAME} --project=${GOOGLE_CLOUD_PROJECT} ` + - `--platform=${PLATFORM} --region=${REGION} --format='value(status.url)'` + `--platform=${PLATFORM} --region=${REGION} --format='value(status.url)'` ); BASE_URL = url.toString('utf-8').trim();