diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..7821534 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "./node_modules/gts" +} diff --git a/.eslintrc.yml b/.eslintrc.yml deleted file mode 100644 index 73eeec2..0000000 --- a/.eslintrc.yml +++ /dev/null @@ -1,15 +0,0 @@ ---- -extends: - - 'eslint:recommended' - - 'plugin:node/recommended' - - prettier -plugins: - - node - - prettier -rules: - prettier/prettier: error - block-scoped-var: error - eqeqeq: error - no-warning-comments: warn - no-var: error - prefer-const: error diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c5cbc55..e8f5ba6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: [8, 10, 12, 13] + node: [10, 12, 13] steps: - uses: actions/checkout@v1 - uses: actions/setup-node@v1 diff --git a/.prettierignore b/.prettierignore index f6fac98..a4ac7b3 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,5 @@ -node_modules/* -samples/node_modules/* -src/**/doc/* +**/node_modules +**/.coverage +build/ +docs/ +protos/ diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index df6eac0..0000000 --- a/.prettierrc +++ /dev/null @@ -1,8 +0,0 @@ ---- -bracketSpacing: false -printWidth: 80 -semi: true -singleQuote: true -tabWidth: 2 -trailingComma: es5 -useTabs: false diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 0000000..08cba37 --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,17 @@ +// 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 +// +// 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. + +module.exports = { + ...require('gts/.prettierrc.json') +} diff --git a/package.json b/package.json index 564f5a1..ac04ceb 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,7 @@ ], "scripts": { "compile": "tsc -p .", - "fix": "gts fix && eslint --fix '**/*.js'", - "clean": "gts clean", + "fix": "gts fix", "pretest": "npm run compile", "prepare": "npm run compile", "samples-test": "npm link && cd samples/ && npm link ../ && npm test && cd ../", @@ -19,7 +18,7 @@ "system-test": "mocha build/system-test --timeout 600000", "test": "c8 mocha --timeout=5000 build/test", "docs": "compodoc src/", - "lint": "gts check && eslint '**/*.js'", + "lint": "gts check", "docs-test": "linkinator docs", "predocs-test": "npm run docs", "prelint": "cd samples; npm link ../; npm i" @@ -47,7 +46,6 @@ "@types/node": "^12.7.2", "@types/tmp": "0.1.0", "@types/uuid": "^7.0.0", - "assert-rejects": "^1.0.0", "c8": "^7.0.0", "codecov": "^3.5.0", "eslint": "^6.1.0", @@ -57,13 +55,14 @@ "gcbuild": "^1.3.4", "gcx": "^1.0.0", "googleapis": "^48.0.0", - "gts": "^1.1.0", + "gts": "^2.0.0-alpha.4", "linkinator": "^2.0.0", "mocha": "^7.0.0", "ncp": "^2.0.0", "nock": "^12.0.0", "prettier": "^1.18.2", - "typescript": "3.6.4", + "tmp": "^0.1.0", + "typescript": "^3.8.3", "uuid": "^7.0.0" }, "engines": { diff --git a/src/index.ts b/src/index.ts index 5127e39..0b10bc2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,7 +7,7 @@ import {GaxiosOptions, GaxiosResponse, request} from 'gaxios'; import {OutgoingHttpHeaders} from 'http'; -const jsonBigint = require('json-bigint'); +const jsonBigint = require('json-bigint'); // eslint-disable-line export const HOST_ADDRESS = 'http://169.254.169.254'; export const BASE_PATH = '/computeMetadata/v1'; diff --git a/system-test/fixtures/kitchen/src/index.ts b/system-test/fixtures/kitchen/src/index.ts index 61a5317..2ec63a9 100644 --- a/system-test/fixtures/kitchen/src/index.ts +++ b/system-test/fixtures/kitchen/src/index.ts @@ -18,4 +18,4 @@ async function main() { gcp.project('something').then(console.log); -main().catch(console.error); \ No newline at end of file +main().catch(console.error); diff --git a/system-test/kitchen.test.ts b/system-test/kitchen.test.ts index 2877724..d257467 100644 --- a/system-test/kitchen.test.ts +++ b/system-test/kitchen.test.ts @@ -10,12 +10,14 @@ import * as tmp from 'tmp'; import {promisify} from 'util'; import {execSync} from 'child_process'; +import {describe, it, after} from 'mocha'; + describe('installation', () => { const ncpp = promisify(ncp); const keep = !!process.env.GCPM_KEEP_TEMPDIRS; const stagingDir = tmp.dirSync({keep, unsafeCleanup: true}); const stagingPath = stagingDir.name; - const pkg = require('../../package.json'); + const pkg = require('../../package.json'); // eslint-disable-line /** * Create a staging directory with temp fixtures used to test on a fresh diff --git a/system-test/system.ts b/system-test/system.ts index be79d7c..a3ef6da 100644 --- a/system-test/system.ts +++ b/system-test/system.ts @@ -6,7 +6,7 @@ */ import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {before, after, describe, it} from 'mocha'; import * as fs from 'fs'; import * as gcbuild from 'gcbuild'; import * as gcx from 'gcx'; @@ -18,7 +18,7 @@ import {execSync} from 'child_process'; import {request, GaxiosError, Gaxios} from 'gaxios'; const copy = promisify(fs.copyFile); -const pkg = require('../../package.json'); +const pkg = require('../../package.json'); // eslint-disable-line let gcf: cloudfunctions_v1.Cloudfunctions; const shortPrefix = 'gcloud-tests'; diff --git a/test/index.test.ts b/test/index.test.ts index b12e557..5fadf08 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -6,12 +6,10 @@ */ import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {beforeEach, afterEach, describe, it} from 'mocha'; import * as nock from 'nock'; import * as gcp from '../src'; -const assertRejects = require('assert-rejects'); - // the metadata IP entry: const HOST = gcp.HOST_ADDRESS; // the metadata DNS entry: @@ -113,7 +111,7 @@ it('should return the request error', async () => { .get(`${PATH}/${TYPE}`) .times(4) .reply(500, undefined, HEADERS); - await assertRejects(gcp.instance(), /Unsuccessful response status code/); + await assert.rejects(gcp.instance(), /Unsuccessful response status code/); scope.done(); }); @@ -121,7 +119,7 @@ it('should return error when res is empty', async () => { const scope = nock(HOST) .get(`${PATH}/${TYPE}`) .reply(200, undefined, HEADERS); - await assertRejects(gcp.instance()); + await assert.rejects(gcp.instance()); scope.done(); }); @@ -129,7 +127,7 @@ it('should return error when flavor header is incorrect', async () => { const scope = nock(HOST) .get(`${PATH}/${TYPE}`) .reply(200, {}, {[gcp.HEADER_NAME.toLowerCase()]: 'Hazelnut'}); - await assertRejects( + await assert.rejects( gcp.instance(), /Invalid response from metadata service: incorrect Metadata-Flavor header./ ); @@ -140,7 +138,7 @@ it('should return error if statusCode is not 200', async () => { const scope = nock(HOST) .get(`${PATH}/${TYPE}`) .reply(418, {}, HEADERS); - await assertRejects(gcp.instance(), /Unsuccessful response status code/); + await assert.rejects(gcp.instance(), /Unsuccessful response status code/); scope.done(); }); @@ -156,18 +154,18 @@ it('should retry if the initial request fails', async () => { }); it('should throw if request options are passed', async () => { - await assertRejects( + await assert.rejects( // tslint:disable-next-line no-any gcp.instance({qs: {one: 'two'}} as any), - /\'qs\' is not a valid configuration option. Please use \'params\' instead\./ + /'qs' is not a valid configuration option. Please use 'params' instead\./ ); }); it('should throw if invalid options are passed', async () => { - await assertRejects( + await assert.rejects( // tslint:disable-next-line no-any gcp.instance({fake: 'news'} as any), - /\'fake\' is not a valid/ + /'fake' is not a valid/ ); }); @@ -321,7 +319,7 @@ it('should throw on unexpected errors', async () => { const secondary = nock(SECONDARY_HOST) .get(`${PATH}/${TYPE}`) .replyWithError({code: '🤡'}); - await assertRejects(gcp.isAvailable()); + assert.rejects(gcp.isAvailable()); primary.done(); secondary.done(); }); diff --git a/tsconfig.json b/tsconfig.json index 886fb73..21ae357 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,7 @@ { "extends": "./node_modules/gts/tsconfig-google.json", "compilerOptions": { + "lib": ["es2015", "dom"], "rootDir": ".", "outDir": "build" },