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 7a11bc2029..42e162f2eb 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; 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..90793379cb 100644 --- a/run/helloworld/test/index.test.js +++ b/run/helloworld/test/index.test.js @@ -12,14 +12,13 @@ // 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 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) => {