Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build!: switch to latest typescript/gts #317

Merged
merged 2 commits into from Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintrc.json
@@ -0,0 +1,3 @@
{
"extends": "./node_modules/gts"
}
15 changes: 0 additions & 15 deletions .eslintrc.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions .prettierignore
@@ -1,3 +1,5 @@
node_modules/*
samples/node_modules/*
src/**/doc/*
**/node_modules
**/.coverage
build/
docs/
protos/
8 changes: 0 additions & 8 deletions .prettierrc

This file was deleted.

17 changes: 17 additions & 0 deletions .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')
}
11 changes: 5 additions & 6 deletions package.json
Expand Up @@ -10,16 +10,15 @@
],
"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 ../",
"presystem-test": "npm run compile",
"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"
Expand Down Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion system-test/fixtures/kitchen/src/index.ts
Expand Up @@ -18,4 +18,4 @@ async function main() {

gcp.project('something').then(console.log);

main().catch(console.error);
main().catch(console.error);
4 changes: 3 additions & 1 deletion system-test/kitchen.test.ts
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions system-test/system.ts
Expand Up @@ -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';
Expand All @@ -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';
Expand Down
22 changes: 10 additions & 12 deletions test/index.test.ts
Expand Up @@ -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:
Expand Down Expand Up @@ -113,23 +111,23 @@ 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();
});

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();
});

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./
);
Expand All @@ -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();
});

Expand All @@ -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/
);
});

Expand Down Expand Up @@ -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();
});
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
@@ -1,6 +1,7 @@
{
"extends": "./node_modules/gts/tsconfig-google.json",
"compilerOptions": {
"lib": ["es2015", "dom"],
"rootDir": ".",
"outDir": "build"
},
Expand Down