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/.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/browser-test/browser-test-runner.ts b/browser-test/browser-test-runner.ts index 0908e23..ce267d4 100644 --- a/browser-test/browser-test-runner.ts +++ b/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 @@ -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 => { diff --git a/browser-test/test.browser.ts b/browser-test/test.browser.ts index 827eac3..bdf8686 100644 --- a/browser-test/test.browser.ts +++ b/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` diff --git a/karma.conf.js b/karma.conf.js index 954ccfb..eff7d04 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -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: '', @@ -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, @@ -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, @@ -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 @@ -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'], + }, }); }; diff --git a/package.json b/package.json index 028b532..06d7a5c 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/prettier.config.js b/prettier.config.js deleted file mode 100644 index a425d3f..0000000 --- a/prettier.config.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - singleQuote: true, - trailingComma: 'es5', -}; diff --git a/samples/package.json b/samples/package.json index 7601c87..206f004 100644 --- a/samples/package.json +++ b/samples/package.json @@ -1,6 +1,9 @@ { "name": "gaxios-samples", "private": true, + "files": [ + "*.js" + ], "scripts": { "test": "mocha" }, diff --git a/samples/test/test.samples.js b/samples/test/test.samples.js index ded929f..dcb97a1 100644 --- a/samples/test/test.samples.js +++ b/samples/test/test.samples.js @@ -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', () => { diff --git a/src/.eslintrc.json b/src/.eslintrc.json new file mode 100644 index 0000000..e5a34ae --- /dev/null +++ b/src/.eslintrc.json @@ -0,0 +1,5 @@ +{ + "env": { + "browser": true + } +} diff --git a/src/common.ts b/src/common.ts index 364f911..324974a 100644 --- a/src/common.ts +++ b/src/common.ts @@ -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 extends Error { code?: string; diff --git a/src/gaxios.ts b/src/gaxios.ts index 7f9c294..55b038f 100644 --- a/src/gaxios.ts +++ b/src/gaxios.ts @@ -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'; @@ -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; @@ -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 @@ -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': diff --git a/src/web.ts b/src/web.ts deleted file mode 100644 index e69de29..0000000 diff --git a/synth.metadata b/synth.metadata index 5f04c53..46dd94f 100644 --- a/synth.metadata +++ b/synth.metadata @@ -1,5 +1,5 @@ { - "updateTime": "2020-04-01T11:18:03.305033Z", + "updateTime": "2020-04-01T11:18:04.471175Z", "sources": [ { "git": { diff --git a/system-test/fixtures/sample/src/index.ts b/system-test/fixtures/sample/src/index.ts index ffc92c4..e96f788 100644 --- a/system-test/fixtures/sample/src/index.ts +++ b/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(); diff --git a/system-test/fixtures/sample/webpack.config.js b/system-test/fixtures/sample/webpack.config.js index 4806fd2..b3ced2c 100644 --- a/system-test/fixtures/sample/webpack.config.js +++ b/system-test/fixtures/sample/webpack.config.js @@ -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: [], }; diff --git a/system-test/test.install.ts b/system-test/test.install.ts index e3ee1b0..6c54733 100644 --- a/system-test/test.install.ts +++ b/system-test/test.install.ts @@ -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; 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', () => { diff --git a/test/test.getch.ts b/test/test.getch.ts index aec070f..8ce0b33 100644 --- a/test/test.getch.ts +++ b/test/test.getch.ts @@ -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, @@ -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); }); @@ -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) diff --git a/test/test.index.ts b/test/test.index.ts index 36d2760..ac22903 100644 --- a/test/test.index.ts +++ b/test/test.index.ts @@ -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', () => { diff --git a/test/test.retry.ts b/test/test.retry.ts index 15d8ffa..88f61ed 100644 --- a/test/test.retry.ts +++ b/test/test.retry.ts @@ -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(); diff --git a/tslint.json b/tslint.json deleted file mode 100644 index 27872a1..0000000 --- a/tslint.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "gts/tslint.json", - "linterOptions": { - "exclude": [ - "**/*.json" - ] - } -} diff --git a/webpack-tests.config.js b/webpack-tests.config.js index 8642393..d903551 100644 --- a/webpack-tests.config.js +++ b/webpack-tests.config.js @@ -20,27 +20,27 @@ module.exports = { resolve: { extensions: ['.ts', '.js', '.json'], alias: { - '../../package.json': path.resolve(__dirname, 'package.json') - } + '../../package.json': path.resolve(__dirname, 'package.json'), + }, }, 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: [], }; diff --git a/webpack.config.js b/webpack.config.js index 20812cd..012df50 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -21,32 +21,32 @@ module.exports = { resolve: { extensions: ['.ts', '.js', '.json'], alias: { - '../../package.json': path.resolve(__dirname, 'package.json') - } + '../../package.json': path.resolve(__dirname, 'package.json'), + }, }, output: { library: 'gaxios', filename: 'gaxios.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: [], };