Skip to content

Commit

Permalink
More test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
awlayton committed Mar 23, 2022
1 parent 943fa5a commit c73f6b0
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 86 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ jobs:
call-build-and-publish:
name: CI
uses: qlever-llc/workflows/.github/workflows/build-and-publish-package.yml@master
secrets:
# This is just a dev token, not actually secret
oada_token: abc
with:
oada: true
8 changes: 2 additions & 6 deletions lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ export class OADAClient {
}

// TODO: should this error?
if (Buffer.isBuffer(body)) {
if (Buffer.isBuffer(body) || !body) {
return body;
}

Expand All @@ -672,16 +672,12 @@ export class OADAClient {
} else {
// Otherwise, get children from the tree provided by the user
for (const key of Object.keys(subTree ?? {})) {
if (typeof body![key as keyof typeof body] === 'object') {
if (typeof body[key as keyof typeof body] === 'object') {
children.push({ treeKey: key, dataKey: key });
}
}
}

if (!body) {
return body;
}

// Await recursive calls
await Promise.all(
children.map(async (item) => {
Expand Down
18 changes: 11 additions & 7 deletions lib/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Buffer } from 'buffer';
import { AbortController, Method } from 'fetch-h2';
import EventEmitter from 'eventemitter3';
import PQueue from 'p-queue';
import type { Response } from 'fetch-h2';
import debug from 'debug';
import ksuid from 'ksuid';
import typeIs from 'type-is';
Expand Down Expand Up @@ -51,6 +52,12 @@ function getIsomorphicContext() {
return context ? context() : { fetch };
}

async function getBody(result: Response): Promise<Body> {
return typeIs.is(result.headers.get('content-type')!, ['json', '+json'])
? ((await result.json()) as Json)
: Buffer.from(await result.arrayBuffer());
}

export class HttpClient extends EventEmitter implements Connection {
#domain: string;
#token;
Expand Down Expand Up @@ -225,13 +232,10 @@ export class HttpClient extends EventEmitter implements Connection {
// Have to construct the headers as a regular object
const headers = Object.fromEntries(result.headers.entries());

// Const length = +(result.headers.get("content-length") || 0);
let data: Body | undefined;
if (request.method.toUpperCase() !== 'HEAD') {
data = typeIs.is(result.headers.get('content-type')!, ['json', '+json'])
? ((await result.json()) as Json)
: Buffer.from(await result.arrayBuffer());
}
const data: Body | undefined =
request.method.toUpperCase() === 'HEAD'
? undefined
: await getBody(result);

// Trace("length = %d, result.headers = %O", length, headers);
return [
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@
"@types/type-is": "^1.6.3",
"@types/uuid": "^8.3.4",
"@types/ws": "^8.5.3",
"@typescript-eslint/eslint-plugin": "^5.15.0",
"@typescript-eslint/parser": "^5.15.0",
"@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.16.0",
"@yarnpkg/sdks": "2.6.0",
"ava": "4.0.0-rc.1",
"axios": "^0.26.1",
Expand All @@ -119,7 +119,7 @@
"eslint-plugin-ava": "^13.2.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-filenames": "^1.3.2",
"eslint-plugin-github": "^4.3.5",
"eslint-plugin-github": "^4.3.6",
"eslint-plugin-i18n-text": "^1.0.1",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-no-constructor-bind": "^2.0.4",
Expand Down
2 changes: 2 additions & 0 deletions test/watch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ for (const connection of <const>['ws', 'http']) {
let client: OADAClient;

// Initialization
// eslint-disable-next-line ava/hooks-order
test.before(`${connection}: Initialize connection`, async () => {
// Connect
client = await connect({
Expand All @@ -64,6 +65,7 @@ for (const connection of <const>['ws', 'http']) {
});

// Cleanup
// eslint-disable-next-line ava/hooks-order
test.after(`${connection}: Destroy connection`, async () => {
// Disconnect
await client?.disconnect();
Expand Down
125 changes: 55 additions & 70 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ __metadata:
"@types/type-is": ^1.6.3
"@types/uuid": ^8.3.4
"@types/ws": ^8.5.3
"@typescript-eslint/eslint-plugin": ^5.15.0
"@typescript-eslint/parser": ^5.15.0
"@typescript-eslint/eslint-plugin": ^5.16.0
"@typescript-eslint/parser": ^5.16.0
"@yarnpkg/sdks": 2.6.0
abort-controller: ^3.0.0
ava: 4.0.0-rc.1
Expand All @@ -205,7 +205,7 @@ __metadata:
eslint-plugin-ava: ^13.2.0
eslint-plugin-eslint-comments: ^3.2.0
eslint-plugin-filenames: ^1.3.2
eslint-plugin-github: ^4.3.5
eslint-plugin-github: ^4.3.6
eslint-plugin-i18n-text: ^1.0.1
eslint-plugin-import: ^2.25.4
eslint-plugin-no-constructor-bind: ^2.0.4
Expand Down Expand Up @@ -460,13 +460,13 @@ __metadata:
languageName: node
linkType: hard

"@typescript-eslint/eslint-plugin@npm:^5.1.0, @typescript-eslint/eslint-plugin@npm:^5.15.0":
version: 5.15.0
resolution: "@typescript-eslint/eslint-plugin@npm:5.15.0"
"@typescript-eslint/eslint-plugin@npm:^5.1.0, @typescript-eslint/eslint-plugin@npm:^5.16.0":
version: 5.16.0
resolution: "@typescript-eslint/eslint-plugin@npm:5.16.0"
dependencies:
"@typescript-eslint/scope-manager": 5.15.0
"@typescript-eslint/type-utils": 5.15.0
"@typescript-eslint/utils": 5.15.0
"@typescript-eslint/scope-manager": 5.16.0
"@typescript-eslint/type-utils": 5.16.0
"@typescript-eslint/utils": 5.16.0
debug: ^4.3.2
functional-red-black-tree: ^1.0.1
ignore: ^5.1.8
Expand All @@ -479,66 +479,66 @@ __metadata:
peerDependenciesMeta:
typescript:
optional: true
checksum: 730ec621b5d87a22ea53cb2a67cae15fd241ccec9cff1bc3bdd24622feb11ea39b186544b845c730afa22112d8922008f17d9116a06b1e2dcd975429209a0c0c
checksum: 4007cc1599503424037300e7401fb969ca441b122ef8a8f2fc8d70f84d656fdf7ab7b0d00e506a3aaf702871616c3756da17eb1508ff315dfb25170f2d28a904
languageName: node
linkType: hard

"@typescript-eslint/parser@npm:^5.1.0, @typescript-eslint/parser@npm:^5.15.0":
version: 5.15.0
resolution: "@typescript-eslint/parser@npm:5.15.0"
"@typescript-eslint/parser@npm:^5.1.0, @typescript-eslint/parser@npm:^5.16.0":
version: 5.16.0
resolution: "@typescript-eslint/parser@npm:5.16.0"
dependencies:
"@typescript-eslint/scope-manager": 5.15.0
"@typescript-eslint/types": 5.15.0
"@typescript-eslint/typescript-estree": 5.15.0
"@typescript-eslint/scope-manager": 5.16.0
"@typescript-eslint/types": 5.16.0
"@typescript-eslint/typescript-estree": 5.16.0
debug: ^4.3.2
peerDependencies:
eslint: ^6.0.0 || ^7.0.0 || ^8.0.0
peerDependenciesMeta:
typescript:
optional: true
checksum: 6b3047236349680e3a408aedf7490d304ad14d3f3264190eb058a472caeec07f85e8f298e6e774fd91cb001c9fd65a5fa558a9906afd30744bc05d8764cec250
checksum: 40006578e9ac451c80dc4b4b7e29af97b53fb9e9ea660d6ca17fb98b5c9858c648f9b17523c9de9b9b9e4155af17b65435e6163f02c4a2dfacf48274f45cba21
languageName: node
linkType: hard

"@typescript-eslint/scope-manager@npm:5.15.0":
version: 5.15.0
resolution: "@typescript-eslint/scope-manager@npm:5.15.0"
"@typescript-eslint/scope-manager@npm:5.16.0":
version: 5.16.0
resolution: "@typescript-eslint/scope-manager@npm:5.16.0"
dependencies:
"@typescript-eslint/types": 5.15.0
"@typescript-eslint/visitor-keys": 5.15.0
checksum: 39fa688691c5cc207d44cc1f5a3ba0ecb3c34144505b32c1267df9e9368cc29373acd7e85e27d6fe84a0012417e40745887baeec6719f33b8a5ae4232d0db061
"@typescript-eslint/types": 5.16.0
"@typescript-eslint/visitor-keys": 5.16.0
checksum: 008a6607d3e6ebcc59a9b28cddcc25703f39a88e27a96c69a6d988acc50a1ea7dbf50963c165ffa5b85a101209a0da3a7ec6832633a162ca4ecc78c0e54acd9f
languageName: node
linkType: hard

"@typescript-eslint/type-utils@npm:5.15.0":
version: 5.15.0
resolution: "@typescript-eslint/type-utils@npm:5.15.0"
"@typescript-eslint/type-utils@npm:5.16.0":
version: 5.16.0
resolution: "@typescript-eslint/type-utils@npm:5.16.0"
dependencies:
"@typescript-eslint/utils": 5.15.0
"@typescript-eslint/utils": 5.16.0
debug: ^4.3.2
tsutils: ^3.21.0
peerDependencies:
eslint: "*"
peerDependenciesMeta:
typescript:
optional: true
checksum: ecefdec695602b04f5d403c741336c56a8aa4f5fa3cc48a202a7b3f548d4d470f44cec5632a3db819fe1ca27c9980dbd3100b8c93e4fd7e9a3fa4253c03f4c04
checksum: 86d9f1dff6a096c8465453b8c7d0cc667b87a769f19073bfa9bbd36f8baa772c0384ec396b1132052383846bbbcf0d051345ed7d373260c1b506ed27100b383d
languageName: node
linkType: hard

"@typescript-eslint/types@npm:5.15.0":
version: 5.15.0
resolution: "@typescript-eslint/types@npm:5.15.0"
checksum: 749d6eb366cb103924b51bcbe69d1c0fd6f7a00f5be4c01b3d6de3134537db956653db9958cdd8cc32f375bca818ea804f8e07697122943faff06232519529a1
"@typescript-eslint/types@npm:5.16.0":
version: 5.16.0
resolution: "@typescript-eslint/types@npm:5.16.0"
checksum: 0450125741c3eef9581da0b75b4a987a633d77009cfb03507c3db29885b790ee80e3c0efc4f9a0dd3376ba758b49c7829722676153472616a57bb04bce5cc4fa
languageName: node
linkType: hard

"@typescript-eslint/typescript-estree@npm:5.15.0":
version: 5.15.0
resolution: "@typescript-eslint/typescript-estree@npm:5.15.0"
"@typescript-eslint/typescript-estree@npm:5.16.0":
version: 5.16.0
resolution: "@typescript-eslint/typescript-estree@npm:5.16.0"
dependencies:
"@typescript-eslint/types": 5.15.0
"@typescript-eslint/visitor-keys": 5.15.0
"@typescript-eslint/types": 5.16.0
"@typescript-eslint/visitor-keys": 5.16.0
debug: ^4.3.2
globby: ^11.0.4
is-glob: ^4.0.3
Expand All @@ -547,33 +547,33 @@ __metadata:
peerDependenciesMeta:
typescript:
optional: true
checksum: 84fbb5030db5c1ac34527860725a9ea5b104fa1c49072a69306954b4b8516242427e70cb6a657ec2b822789432179a0df7a866e4618a29ee54b4285ca23556c8
checksum: 930ead4655712c3bd40885fb6b2074cd3c10fb03da864dd7a7dd2e43abfd330bb07e505f0aec8b4846178bff8befbb017f9f3370c67e9c717e4cb8d3df6e16ef
languageName: node
linkType: hard

"@typescript-eslint/utils@npm:5.15.0":
version: 5.15.0
resolution: "@typescript-eslint/utils@npm:5.15.0"
"@typescript-eslint/utils@npm:5.16.0":
version: 5.16.0
resolution: "@typescript-eslint/utils@npm:5.16.0"
dependencies:
"@types/json-schema": ^7.0.9
"@typescript-eslint/scope-manager": 5.15.0
"@typescript-eslint/types": 5.15.0
"@typescript-eslint/typescript-estree": 5.15.0
"@typescript-eslint/scope-manager": 5.16.0
"@typescript-eslint/types": 5.16.0
"@typescript-eslint/typescript-estree": 5.16.0
eslint-scope: ^5.1.1
eslint-utils: ^3.0.0
peerDependencies:
eslint: ^6.0.0 || ^7.0.0 || ^8.0.0
checksum: 406725b3e1282064612c9e69f346ceae5cf8e3fe4ae37295eaa1d594fb1b7ed3abd161c32b96622b00ca56e7b1120ea43b584954cd0cefad904a46d65b20960e
checksum: 46749091a204d7cf80d81b04704e23a86903a142a7e35cc5068a821c147c3bf098a7eff99af2b0e2ea7310013ca90300db9bab33ae5e3b5f773ed1d2961a5ed4
languageName: node
linkType: hard

"@typescript-eslint/visitor-keys@npm:5.15.0":
version: 5.15.0
resolution: "@typescript-eslint/visitor-keys@npm:5.15.0"
"@typescript-eslint/visitor-keys@npm:5.16.0":
version: 5.16.0
resolution: "@typescript-eslint/visitor-keys@npm:5.16.0"
dependencies:
"@typescript-eslint/types": 5.15.0
"@typescript-eslint/types": 5.16.0
eslint-visitor-keys: ^3.0.0
checksum: a3f231bf55794547680284aa23ba495efa1e52f864583fe53e1ff8b2c011db070ca48633eb8a333bfc93be0bdbb76ffa98e81bf032fd2737a5e0f0b1b81bbc22
checksum: b587bf3b0da95bb58ff877b75fefcee6472222de1e3ec76aa4b94cae66078b62a372c7d0343374a16aab15cdcbae3f9e019624028b35827f68ef6559389f7fd0
languageName: node
linkType: hard

Expand Down Expand Up @@ -2115,9 +2115,9 @@ __metadata:
languageName: node
linkType: hard

"eslint-plugin-github@npm:^4.3.5":
version: 4.3.5
resolution: "eslint-plugin-github@npm:4.3.5"
"eslint-plugin-github@npm:^4.3.6":
version: 4.3.6
resolution: "eslint-plugin-github@npm:4.3.6"
dependencies:
"@typescript-eslint/eslint-plugin": ^5.1.0
"@typescript-eslint/parser": ^5.1.0
Expand All @@ -2128,15 +2128,15 @@ __metadata:
eslint-plugin-i18n-text: ^1.0.1
eslint-plugin-import: ^2.25.2
eslint-plugin-no-only-tests: ^2.6.0
eslint-plugin-prettier: ^3.3.1
eslint-plugin-prettier: ^4.0.0
eslint-rule-documentation: ">=1.0.0"
prettier: ^2.2.1
svg-element-attributes: ^1.3.1
peerDependencies:
eslint: ^8.0.1
bin:
eslint-ignore-errors: bin/eslint-ignore-errors.js
checksum: be31e911d1db493c03a5907d51b4de0d64b4ceb89a72ac774a3b8a5f33fcadf08613720d6dfc82cc5181046fde15fd0cd4cd801194250735b48f4bbe61459815
checksum: 38ab259fa3c37983dce90a163d4c2c1769ba71a38efa7ef14ee0c1678e0d767dbcb3bef61a6bbd35a1dbcdbd90bb1dc86a2a5334463cb3a2fc21cfb3c73fb5de
languageName: node
linkType: hard

Expand Down Expand Up @@ -2235,21 +2235,6 @@ __metadata:
languageName: node
linkType: hard

"eslint-plugin-prettier@npm:^3.3.1":
version: 3.4.1
resolution: "eslint-plugin-prettier@npm:3.4.1"
dependencies:
prettier-linter-helpers: ^1.0.0
peerDependencies:
eslint: ">=5.0.0"
prettier: ">=1.13.0"
peerDependenciesMeta:
eslint-config-prettier:
optional: true
checksum: fa6a89f0d7cba1cc87064352f5a4a68dc3739448dd279bec2bced1bfa3b704467e603d13b69dcec853f8fa30b286b8b715912898e9da776e1b016cf0ee48bd99
languageName: node
linkType: hard

"eslint-plugin-prettier@npm:^4.0.0":
version: 4.0.0
resolution: "eslint-plugin-prettier@npm:4.0.0"
Expand Down

0 comments on commit c73f6b0

Please sign in to comment.