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

chore(dep)!: upgrade gts 2.0.0 #194

Merged
merged 11 commits into from Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from 9 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
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.

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 @@ -7,13 +7,12 @@
"repository": "googleapis/nodejs-paginator",
"scripts": {
"test": "c8 mocha build/test",
"lint": "gts check",
"clean": "gts clean",
"compile": "tsc -p .",
"fix": "gts fix",
"prelint": "cd samples; npm link ../; npm i",
"lint": "gts check",
"prepare": "npm run compile",
"pretest": "npm run compile",
"posttest": "npm run lint",
"docs": "compodoc src/",
"presystem-test": "npm run compile",
"samples-test": "cd samples/ && npm link ../ && npm test && cd ../",
Expand All @@ -36,11 +35,11 @@
"@types/proxyquire": "^1.3.28",
"@types/sinon": "^7.0.0",
"@types/uuid": "^7.0.0",
"c8": "^7.0.0",
"codecov": "^3.0.4",
"gts": "^1.0.0",
"gts": "2.0.0-alpha.4",
"linkinator": "^2.0.0",
"mocha": "^7.0.0",
"c8": "^7.0.0",
"mocha": "^7.1.1",
"proxyquire": "^2.0.1",
"sinon": "^9.0.0",
"typescript": "^3.8.3",
Expand Down
2 changes: 1 addition & 1 deletion samples/package.json
Expand Up @@ -3,7 +3,7 @@
"license": "Apache-2.0",
"author": "Google LLC",
"engines": {
"node": ">=8"
"node": ">=10"
},
"repository": "googleapis/nodejs-paginator",
"private": true,
Expand Down
10 changes: 5 additions & 5 deletions src/index.ts
Expand Up @@ -91,7 +91,7 @@ export class Paginator {
Class.prototype[methodName + '_'] = originalMethod;

// overwrite the original to auto-paginate
// tslint:disable-next-line:no-any
/* eslint-disable @typescript-eslint/no-explicit-any */
Class.prototype[methodName] = function(...args: any[]) {
const parsedArguments = paginator.parseArguments_(args);
return paginator.run_(parsedArguments, originalMethod.bind(this));
Expand All @@ -111,12 +111,12 @@ export class Paginator {
* @param {string} methodName - Name of the method to streamify.
* @return {function} - Wrapped function.
*/
// tslint:disable-next-line:no-any
/* eslint-disable @typescript-eslint/no-explicit-any */
streamify<T = any>(methodName: string) {
return function(
// tslint:disable-next-line:no-any
this: {[index: string]: Function},
// tslint:disable-next-line:no-any
/* eslint-disable @typescript-eslint/no-explicit-any */
...args: any[]
): ResourceStream<T> {
const parsedArguments = paginator.parseArguments_(args);
Expand All @@ -134,7 +134,7 @@ export class Paginator {
* @param {array} args - The original `arguments` pseduo-array that the original
* method received.
*/
// tslint:disable-next-line:no-any
/* eslint-disable @typescript-eslint/no-explicit-any */
parseArguments_(args: any[]) {
let query: string | ParsedArguments | undefined;
let autoPaginate = true;
Expand Down Expand Up @@ -255,7 +255,7 @@ export class Paginator {
* and returns `nextQuery` to receive more results.
* @return {stream} - Readable object stream.
*/
// tslint:disable-next-line:no-any
/* eslint-disable @typescript-eslint/no-explicit-any */
runAsStream_<T = any>(
parsedArguments: ParsedArguments,
originalMethod: Function
Expand Down
2 changes: 1 addition & 1 deletion src/resource-stream.ts
Expand Up @@ -47,7 +47,7 @@ export class ResourceStream<T> extends Transform implements ResourceEvents<T> {
this._requestsMade = 0;
this._resultsToSend = args.maxResults === -1 ? Infinity : args.maxResults!;
}
// tslint:disable-next-line:no-any
/* eslint-disable @typescript-eslint/no-explicit-any */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine for now, I would rather that these PRs turn into as minimal of a refactor as possible, even though we might want to come back and make this a more extensive refactor.

end(...args: any[]) {
this._ended = true;
return super.end(...args);
Expand Down
21 changes: 16 additions & 5 deletions test/index.ts
Expand Up @@ -22,13 +22,16 @@ import * as P from '../src';
import {paginator, ParsedArguments} from '../src';

const util = {
noop: () => {},
noop: () => {
// do nothing
},
};

class FakeResourceStream extends Transform {
calledWith: IArguments;
constructor() {
super({objectMode: true});
/* eslint-disable-next-line prefer-rest-params */
this.calledWith = arguments;
}
}
Expand All @@ -39,19 +42,23 @@ const p = proxyquire('../src', {

const sandbox = sinon.createSandbox();

// eslint-disable-next-line no-undef
summer-ji-eng marked this conversation as resolved.
Show resolved Hide resolved
afterEach(() => {
sandbox.restore();
});

// tslint:disable-next-line no-any
/* eslint-disable @typescript-eslint/no-explicit-any */
function createFakeStream<T = any>() {
return new PassThrough({objectMode: true}) as P.ResourceStream<T>;
}

describe('paginator', () => {
const UUID = uuid.v1();
function FakeClass() {}
function FakeClass() {
// do nothing
}

/* eslint-disable-next-line no-undef */
summer-ji-eng marked this conversation as resolved.
Show resolved Hide resolved
beforeEach(() => {
FakeClass.prototype.methodToExtend = () => {
return UUID;
Expand All @@ -75,7 +82,9 @@ describe('paginator', () => {

it('should accept an array or string method names', () => {
const originalMethod = FakeClass.prototype.methodToExtend;
FakeClass.prototype.anotherMethodToExtend = () => {};
FakeClass.prototype.anotherMethodToExtend = () => {
// do nothing
summer-ji-eng marked this conversation as resolved.
Show resolved Hide resolved
};
const anotherMethod = FakeClass.prototype.anotherMethodToExtend;
const methodsToExtend = ['methodToExtend', 'anotherMethodToExtend'];
paginator.extend(FakeClass, methodsToExtend);
Expand Down Expand Up @@ -117,7 +126,7 @@ describe('paginator', () => {
return this.uuid;
};

// tslint:disable-next-line:no-any
/* eslint-disable @typescript-eslint/no-explicit-any */
const cls = new (FakeClass as any)();
cls.uuid = uuid.v1();

Expand All @@ -141,6 +150,7 @@ describe('paginator', () => {
});

describe('streamify', () => {
/* eslint-disable-next-line no-undef */
beforeEach(() => {
FakeClass.prototype.streamMethod = paginator.streamify('methodToExtend');
});
Expand All @@ -159,6 +169,7 @@ describe('paginator', () => {
return args as ParsedArguments;
});
sandbox.stub(paginator, 'runAsStream_').callsFake(createFakeStream);
/* eslint-disable-next-line prefer-spread */
FakeClass.prototype.streamMethod.apply(FakeClass.prototype, fakeArgs);
summer-ji-eng marked this conversation as resolved.
Show resolved Hide resolved
});

Expand Down
2 changes: 2 additions & 0 deletions test/resource-stream.ts
Expand Up @@ -31,11 +31,13 @@ describe('ResourceStream', () => {
let requestSpy: sinon.SinonSpy;
let stream: ResourceStream<{}>;

// eslint-disable-next-line no-undef
beforeEach(() => {
requestSpy = sandbox.spy();
stream = new ResourceStream(config, requestSpy);
});

// eslint-disable-next-line no-undef
summer-ji-eng marked this conversation as resolved.
Show resolved Hide resolved
afterEach(() => {
sandbox.restore();
});
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"],
summer-ji-eng marked this conversation as resolved.
Show resolved Hide resolved
"rootDir": ".",
"outDir": "build"
},
Expand Down