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

Deps update #2

Merged
merged 6 commits into from
Nov 8, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 7
version: 8
- uses: actions/setup-node@v3
with:
node-version: 18
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 7
version: 8
- uses: actions/setup-node@v3
with:
node-version: 18
Expand Down
20 changes: 12 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,28 @@ deps: node_modules

.PHONY: clean
clean:
pnpm tsc -b --clean
pnpm exec tsc -b --clean
rm -rf dist

.PHONY: distclean
distclean: clean
rm -rf node_modules

.PHONY: test
test:
NODE_OPTIONS=--experimental-vm-modules pnpm jest
test: node_modules
NODE_OPTIONS=--experimental-vm-modules pnpm exec jest

node_modules: package.json
pnpm install

dist: node_modules tsconfig.json $(SRCS)
pnpm tsc
pnpm exec tsc

.PHONY: dev
dev:
pnpm tsc -w
dev: node_modules
pnpm exec tsc -w

.PHONY: pretty
pretty: node_modules
pnpm eslint --fix .
pnpm prettier --write .
pnpm exec eslint --fix .
pnpm exec prettier --write .
27 changes: 27 additions & 0 deletions __tests__/__snapshots__/client.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Client 200 OK! 1`] = `
[
1,
2,
3,
]
`;

exports[`Client 404 1`] = `[Error: Not Found]`;

exports[`Client Headers 1`] = `
{
"accept": "*/*",
"accept-encoding": "gzip, deflate",
"accept-language": "*",
"connection": "keep-alive",
"host": "redacted",
"sec-fetch-mode": "cors",
"user-agent": "node",
"x-async": "Bearer 1234567890",
"x-build-id": "test/123",
"x-func": "hello",
"x-merged": "hello",
}
`;
70 changes: 70 additions & 0 deletions __tests__/__snapshots__/fetcher.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Fetcher 200 OK! 1`] = `
{
"body": [
1,
2,
3,
],
"ok": true,
"status": 200,
"statusText": "OK",
"url": Any<URL>,
}
`;

exports[`Fetcher 204 1`] = `
{
"body": "",
"ok": true,
"status": 204,
"statusText": "No Content",
"url": Any<URL>,
}
`;

exports[`Fetcher 404 1`] = `
{
"body": "<h1>Not Found</h1>",
"ok": false,
"status": 404,
"statusText": "Not Found",
"url": Any<URL>,
}
`;

exports[`Fetcher Custom options iso fetcher 1`] = `
{
"body": {
"accept": "*/*",
"accept-encoding": "gzip, deflate",
"accept-language": "*",
"connection": "keep-alive",
"host": "redacted",
"sec-fetch-mode": "cors",
"user-agent": "node",
"x-fetcher": "custom",
},
"ok": true,
"status": 200,
"statusText": "OK",
"url": Any<URL>,
}
`;

exports[`Fetcher Custom timeout iso fetcher 1`] = `[TimeoutError: Request timed out]`;

exports[`Fetcher JSON Error 1`] = `
{
"body": {
"code": 9,
"message": "Data should be array",
"status": "FAILED_PRECONDITION",
},
"ok": false,
"status": 400,
"statusText": "Bad Request",
"url": Any<URL>,
}
`;
31 changes: 3 additions & 28 deletions __tests__/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,11 @@ describe('Client', () => {
test('200 OK!', async () => {
const response = await client.json(new Fake200Command());

expect(response).toMatchInlineSnapshot(`
[
1,
2,
3,
]
`);
expect(response).toMatchSnapshot();
});

test('404', async () => {
await expect(
client.json(new Fake404Command()),
).rejects.toMatchInlineSnapshot(
// eslint-disable-next-line quotes
`[Error: Not Found]`,
);
await expect(client.json(new Fake404Command())).rejects.toMatchSnapshot();
});

test('JSON Error', async () => {
Expand All @@ -106,21 +95,7 @@ describe('Client', () => {
},
});

expect(response).toMatchInlineSnapshot(`
{
"accept": "*/*",
"accept-encoding": "gzip, deflate",
"accept-language": "*",
"connection": "keep-alive",
"host": "redacted",
"sec-fetch-mode": "cors",
"user-agent": "undici",
"x-async": "Bearer 1234567890",
"x-build-id": "test/123",
"x-func": "hello",
"x-merged": "hello",
}
`);
expect(response).toMatchSnapshot();
});

afterAll((done) => {
Expand Down
107 changes: 16 additions & 91 deletions __tests__/fetcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,9 @@ describe('Fetcher', () => {
url: new URL('/200', base),
});

expect(response).toMatchInlineSnapshot(
{
url: expect.any(URL),
},
`
{
"body": [
1,
2,
3,
],
"ok": true,
"status": 200,
"statusText": "OK",
"url": Any<URL>,
}
`,
);
expect(response).toMatchSnapshot({
url: expect.any(URL),
});
});

test('204', async () => {
Expand All @@ -47,20 +32,9 @@ describe('Fetcher', () => {
url: new URL('/204', base),
});

expect(response).toMatchInlineSnapshot(
{
url: expect.any(URL),
},
`
{
"body": "",
"ok": true,
"status": 204,
"statusText": "No Content",
"url": Any<URL>,
}
`,
);
expect(response).toMatchSnapshot({
url: expect.any(URL),
});
});

test('JSON Error', async () => {
Expand All @@ -69,24 +43,9 @@ describe('Fetcher', () => {
method: 'get',
url: new URL('/json-error', base),
}),
).toMatchInlineSnapshot(
{
url: expect.any(URL),
},
`
{
"body": {
"code": 9,
"message": "Data should be array",
"status": "FAILED_PRECONDITION",
},
"ok": false,
"status": 400,
"statusText": "Bad Request",
"url": Any<URL>,
}
`,
);
).toMatchSnapshot({
url: expect.any(URL),
});
});

test('404', async () => {
Expand All @@ -95,20 +54,9 @@ describe('Fetcher', () => {
method: 'get',
url: new URL('/404', base),
}),
).toMatchInlineSnapshot(
{
url: expect.any(URL),
},
`
{
"body": "<h1>Not Found</h1>",
"ok": false,
"status": 404,
"statusText": "Not Found",
"url": Any<URL>,
}
`,
);
).toMatchSnapshot({
url: expect.any(URL),
});
});

test('Custom options iso fetcher', async () => {
Expand All @@ -123,29 +71,9 @@ describe('Fetcher', () => {
method: 'get',
url: new URL('/my-headers', base),
}),
).toMatchInlineSnapshot(
{
url: expect.any(URL),
},
`
{
"body": {
"accept": "*/*",
"accept-encoding": "gzip, deflate",
"accept-language": "*",
"connection": "keep-alive",
"host": "redacted",
"sec-fetch-mode": "cors",
"user-agent": "undici",
"x-fetcher": "custom",
},
"ok": true,
"status": 200,
"statusText": "OK",
"url": Any<URL>,
}
`,
);
).toMatchSnapshot({
url: expect.any(URL),
});
});

test('Custom timeout iso fetcher', async () => {
Expand All @@ -158,10 +86,7 @@ describe('Fetcher', () => {
method: 'get',
url: new URL('/unresponsive', base),
}),
).rejects.toMatchInlineSnapshot(
// eslint-disable-next-line quotes
`[TimeoutError: Request timed out]`,
);
).rejects.toMatchSnapshot();
}, 150);

afterAll((done) => {
Expand Down
27 changes: 27 additions & 0 deletions __tests__/legacy/__snapshots__/client.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Client 200 OK! 1`] = `
[
1,
2,
3,
]
`;

exports[`Client 404 1`] = `[Error: Not Found]`;

exports[`Client Headers 1`] = `
{
"accept": "*/*",
"accept-encoding": "gzip, deflate",
"accept-language": "*",
"connection": "keep-alive",
"host": "redacted",
"sec-fetch-mode": "cors",
"user-agent": "node",
"x-async": "Bearer 1234567890",
"x-build-id": "test/123",
"x-func": "hello",
"x-merged": "hello",
}
`;
Loading