Skip to content

Commit

Permalink
chore(deps): upgrade to gts v2 (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith committed Mar 19, 2020
1 parent 2e62967 commit d26a325
Show file tree
Hide file tree
Showing 26 changed files with 121 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
@@ -1,5 +1,5 @@
**/node_modules
src/**/doc/*
**/.coverage
build/
docs/
protos/
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.

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')
}
6 changes: 4 additions & 2 deletions browser-test/browser-test-runner.ts
@@ -1,4 +1,4 @@
// Copyright 2019, Google, LLC.
// Copyright 2019 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
Expand Down Expand Up @@ -56,7 +56,9 @@ async function main() {
console.log(
`[http server] Karma has finished! I'm no longer listening on port ${port}!`
);
process.exit(result.failed ? 1 : 0);
if (result.failed) {
throw new Error('Tests failed.');
}
}

main().catch(err => {
Expand Down
15 changes: 14 additions & 1 deletion browser-test/test.browser.ts
@@ -1,5 +1,18 @@
import assert from 'assert';
// Copyright 2019 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.

import assert from 'assert';
import {describe, it} from 'mocha';
import {request} from '../src/index';
const port = 7172; // should match the port defined in `webserver.ts`

Expand Down
16 changes: 8 additions & 8 deletions karma.conf.js
Expand Up @@ -22,7 +22,7 @@ process.env.CHROME_BIN = fs.existsSync('/usr/bin/chromium-browser')
? '/usr/bin/chromium-browser'
: require('puppeteer').executablePath();

module.exports = function (config) {
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
Expand All @@ -42,7 +42,7 @@ module.exports = function (config) {
preprocessors: {
'./src/*.ts': ['coverage'],
'./src/**/*.ts': ['coverage'],
'./browser-test/*.ts': ['webpack', 'sourcemap']
'./browser-test/*.ts': ['webpack', 'sourcemap'],
},

webpack: webpackConfig,
Expand All @@ -52,8 +52,8 @@ module.exports = function (config) {
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress', 'coverage', 'remap-coverage'],

coverageReporter: { type: 'in-memory' },
remapCoverageReporter: { html: './coverage' },
coverageReporter: {type: 'in-memory'},
remapCoverageReporter: {html: './coverage'},

// web server port
port: 9876,
Expand All @@ -76,8 +76,8 @@ module.exports = function (config) {
base: 'ChromeHeadless',
// We must disable the Chrome sandbox when running Chrome inside Docker (Chrome's sandbox needs
// more permissions than Docker allows by default)
flags: isDocker ? ['--no-sandbox'] : []
}
flags: isDocker ? ['--no-sandbox'] : [],
},
},

// Continuous Integration mode
Expand All @@ -90,7 +90,7 @@ module.exports = function (config) {

// set correct MIME type when serving .ts files (already compiled to JavaScript):
mime: {
'text/javascript': ['ts']
}
'text/javascript': ['ts'],
},
});
};
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -12,7 +12,6 @@
"test": "c8 mocha build/test",
"presystem-test": "npm run compile",
"system-test": "mocha build/system-test --timeout 40000",
"clean": "gts clean",
"compile": "tsc -p .",
"fix": "gts fix",
"prepare": "npm run compile",
Expand Down Expand Up @@ -53,7 +52,7 @@
"codecov": "^3.2.0",
"execa": "^4.0.0",
"express": "^4.16.4",
"gts": "^1.0.0",
"gts": "2.0.0-alpha.4",
"is-docker": "^2.0.0",
"karma": "^4.0.0",
"karma-chrome-launcher": "^3.0.0",
Expand Down
4 changes: 0 additions & 4 deletions prettier.config.js

This file was deleted.

3 changes: 3 additions & 0 deletions samples/package.json
@@ -1,6 +1,9 @@
{
"name": "gaxios-samples",
"private": true,
"files": [
"*.js"
],
"scripts": {
"test": "mocha"
},
Expand Down
2 changes: 1 addition & 1 deletion samples/test/test.samples.js
Expand Up @@ -16,7 +16,7 @@ const {execSync} = require('child_process');
const {assert} = require('chai');
const {describe, it} = require('mocha');

const exec = cmd => execSync(cmd, { encoding: 'utf8'});
const exec = cmd => execSync(cmd, {encoding: 'utf8'});

describe(__filename, () => {
it('should run the quickstart', () => {
Expand Down
5 changes: 5 additions & 0 deletions src/.eslintrc.json
@@ -0,0 +1,5 @@
{
"env": {
"browser": true
}
}
2 changes: 1 addition & 1 deletion src/common.ts
Expand Up @@ -15,7 +15,7 @@ import {AbortSignal} from 'abort-controller';
import {Agent} from 'http';
import {URL} from 'url';

// tslint:disable no-any
/* eslint-disable @typescript-eslint/no-explicit-any */

export class GaxiosError<T = any> extends Error {
code?: string;
Expand Down
12 changes: 7 additions & 5 deletions src/gaxios.ts
Expand Up @@ -15,7 +15,6 @@ import extend from 'extend';
import {Agent} from 'http';
import nodeFetch, {Response as NodeFetchResponse} from 'node-fetch';
import qs from 'querystring';
import stream from 'stream';
import isStream from 'is-stream';
import url from 'url';

Expand All @@ -28,7 +27,8 @@ import {
} from './common';
import {getRetryConfig} from './retry';

// tslint:disable no-any
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable node/no-unsupported-features/node-builtins */

const URL = hasURL() ? window.URL : url.URL;
const fetch = hasFetch() ? window.fetch : nodeFetch;
Expand All @@ -45,7 +45,6 @@ function hasFetch() {
return hasWindow() && !!window.fetch;
}

// tslint:disable-next-line variable-name
let HttpsProxyAgent: any;

// Figure out if we should be using a proxy. Only if it's required, load
Expand Down Expand Up @@ -132,12 +131,15 @@ export class Gaxios {
switch (opts.responseType) {
case 'stream':
return res.body;
case 'json':
case 'json': {
let data = await res.text();
try {
data = JSON.parse(data);
} catch (e) {}
} catch {
// continue
}
return data as {};
}
case 'arraybuffer':
return res.arrayBuffer();
case 'blob':
Expand Down
Empty file removed src/web.ts
Empty file.
16 changes: 15 additions & 1 deletion system-test/fixtures/sample/src/index.ts
@@ -1,7 +1,21 @@
// Copyright 2019 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.

import {request} from 'gaxios';
async function main() {
await request({
url: 'https://www.googleapis.com/discovery/v1/apis/'
url: 'https://www.googleapis.com/discovery/v1/apis/',
});
}
main();
18 changes: 9 additions & 9 deletions system-test/fixtures/sample/webpack.config.js
Expand Up @@ -21,31 +21,31 @@ module.exports = {
resolve: {
extensions: ['.ts', '.js', '.json'],
alias: {
'../../package.json': path.resolve(__dirname, 'package.json')
}
'../../package.json': path.resolve(__dirname, 'package.json'),
},
},
output: {
filename: 'bundle.min.js',
path: path.resolve(__dirname, 'dist')
path: path.resolve(__dirname, 'dist'),
},
node: {
child_process: 'empty',
fs: 'empty',
crypto: 'empty'
crypto: 'empty',
},
module: {
rules: [
{
test: /node_modules\/https-proxy-agent\//,
use: 'null-loader'
use: 'null-loader',
},
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
exclude: /node_modules/,
},
],
},
mode: 'production',
plugins: []
plugins: [],
};
2 changes: 2 additions & 0 deletions system-test/test.install.ts
Expand Up @@ -20,12 +20,14 @@ import {ncp} from 'ncp';
import path from 'path';
import tmp from 'tmp';
import {promisify} from 'util';
import {describe, it, before, after} from 'mocha';

const keep = false;
const mvp = (promisify(mv) as {}) as (...args: string[]) => Promise<void>;
const ncpp = promisify(ncp);
const stagingDir = tmp.dirSync({keep, unsafeCleanup: true});
const stagingPath = stagingDir.name;
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkg = require('../../package.json');

describe('📦 pack and install', () => {
Expand Down
10 changes: 5 additions & 5 deletions test/test.getch.ts
Expand Up @@ -15,8 +15,9 @@ import assert from 'assert';
import nock from 'nock';
import sinon from 'sinon';
import stream from 'stream';
const assertRejects = require('assert-rejects');
// tslint:disable-next-line variable-name
import {describe, it, afterEach} from 'mocha';
import assertRejects = require('assert-rejects');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const HttpsProxyAgent = require('https-proxy-agent');
import {
Gaxios,
Expand Down Expand Up @@ -144,9 +145,7 @@ describe('🥁 configuration options', () => {
responseURL: url,
},
};
const adapter = (options: GaxiosOptions) => {
return Promise.resolve(response);
};
const adapter = () => Promise.resolve(response);
const res = await request({url, adapter});
assert.strictEqual(response, res);
});
Expand Down Expand Up @@ -270,6 +269,7 @@ describe('🥁 configuration options', () => {
describe('🎏 data handling', () => {
it('should accpet a ReadableStream as request data', async () => {
const body = fs.createReadStream('package.json');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const contents = require('../../package.json');
const scope = nock(url)
.post('/', contents)
Expand Down
2 changes: 1 addition & 1 deletion test/test.index.ts
Expand Up @@ -12,7 +12,7 @@
// limitations under the License.

import assert from 'assert';

import {describe, it} from 'mocha';
import * as main from '../src/index';

describe('📝 main exports', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/test.retry.ts
Expand Up @@ -14,9 +14,9 @@
import {AbortController} from 'abort-controller';
import assert from 'assert';
import nock from 'nock';
import {describe, it, afterEach} from 'mocha';
import {Gaxios, GaxiosError, GaxiosOptions, request} from '../src';

const assertRejects = require('assert-rejects');
import assertRejects = require('assert-rejects');

nock.disableNetConnect();

Expand Down
8 changes: 0 additions & 8 deletions tslint.json

This file was deleted.

0 comments on commit d26a325

Please sign in to comment.