Skip to content

Commit 4e90a2b

Browse files
authored
fix: update run/helloworld to use esmodules (#3615)
* fix: update run/helloworld to esmodules * fix: lint * fix: gts fix
1 parent 62253bb commit 4e90a2b

File tree

5 files changed

+13
-10
lines changed

5 files changed

+13
-10
lines changed

.eslintrc.json

+3
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@
1010
"node/no-unpublished-import": ["off"],
1111
"node/no-unpublished-require": ["off"],
1212
"node/no-unsupported-features/es-syntax": ["off"]
13+
},
14+
"parserOptions": {
15+
"sourceType": "module"
1316
}
1417
}

run/helloworld/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
// [START cloudrun_helloworld_service]
1616
// [START run_helloworld_service]
17-
const express = require('express');
17+
import express from 'express';
1818
const app = express();
1919

2020
app.get('/', (req, res) => {
@@ -30,4 +30,4 @@ app.listen(port, () => {
3030
// [END cloudrun_helloworld_service]
3131

3232
// Exports for testing purposes.
33-
module.exports = app;
33+
export default app;

run/helloworld/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"test": "c8 mocha -p -j 2 test/index.test.js --exit",
1010
"system-test": "NAME=Cloud c8 mocha -p -j 2 test/system.test.js --timeout=180000"
1111
},
12+
"type": "module",
1213
"engines": {
1314
"node": ">=16.0.0"
1415
},

run/helloworld/test/index.test.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
const assert = require('assert');
16-
const path = require('path');
17-
const supertest = require('supertest');
15+
import assert from 'assert';
16+
import supertest from 'supertest';
17+
import app from '../index.js';
1818

1919
let request;
2020
describe('Unit Tests', () => {
2121
before(() => {
22-
const app = require(path.join(__dirname, '..', 'index'));
2322
request = supertest(app);
2423
});
2524

run/helloworld/test/system.test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
const assert = require('assert');
16-
const {execSync} = require('child_process');
17-
const request = require('got');
18-
const {GoogleAuth} = require('google-auth-library');
15+
import assert from 'assert';
16+
import {execSync} from 'child_process';
17+
import request from 'got';
18+
import {GoogleAuth} from 'google-auth-library';
1919
const auth = new GoogleAuth();
2020

2121
const get = (route, base_url) => {

0 commit comments

Comments
 (0)