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

ci: run type tests against various TypeScript version #278

Merged
merged 10 commits into from
Jan 24, 2023
Merged
100 changes: 87 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
name: ci

on:
push:
branches:
- master
pull_request:
branches:
- master
on: push
lihbr marked this conversation as resolved.
Show resolved Hide resolved

jobs:
ci:
prepare:
name: Prepare (${{ matrix.os}}, Node ${{ matrix.node }})
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest]
Expand All @@ -27,7 +21,8 @@ jobs:
uses: actions/checkout@master

- name: Cache node_modules
uses: actions/cache@v2
id: cache
uses: actions/cache@v3
with:
path: node_modules
key: ${{ matrix.os }}-node-v${{ matrix.node }}-deps-${{ hashFiles(format('{0}{1}', github.workspace, '/package-lock.json')) }}
Expand All @@ -36,12 +31,34 @@ jobs:
if: steps.cache.outputs.cache-hit != 'true'
run: npm ci

suite:
needs: prepare
name: Suite (${{ matrix.os}}, Node ${{ matrix.node }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
node: [14]
Copy link
Member

Choose a reason for hiding this comment

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

Any thoughts on including Node.js 18 in this list? Node 18 is unique since it introduces Web APIs that could affect our libraries, including fetch, Response, and Blob.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree! Let's do this


steps:
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}

- name: Checkout
uses: actions/checkout@master

- name: Retrieve node_modules
uses: actions/cache@v3
with:
path: node_modules
key: ${{ matrix.os }}-node-v${{ matrix.node }}-deps-${{ hashFiles(format('{0}{1}', github.workspace, '/package-lock.json')) }}

- name: Lint
run: npm run lint

- name: Types
run: npm run types

- name: Unit
run: npm run unit

Expand All @@ -52,6 +69,63 @@ jobs:
if: matrix.os == 'ubuntu-latest' && matrix.node == 14
uses: codecov/codecov-action@v3

types:
needs: prepare
name: Types (${{ matrix.os}}, Node ${{ matrix.node }}, TS ${{ matrix.typescript }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
node: [14]
typescript: ['4.5', '4.6', '4.7', '4.8', '4.9']

steps:
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}

- name: Checkout
uses: actions/checkout@master

- name: Retrieve node_modules
uses: actions/cache@v3
with:
path: node_modules
key: ${{ matrix.os }}-node-v${{ matrix.node }}-deps-${{ hashFiles(format('{0}{1}', github.workspace, '/package-lock.json')) }}

- name: Overwrite TypeScript
run: npm install --save-dev typescript@${{ matrix.typescript }}
Copy link
Member

Choose a reason for hiding this comment

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

Is the --save-dev necessary? Modifying the package-lock.json makes the workflow less pure since it modifies the code its testing.

We could use --no-save to only install TypeScript without modifying the repo.

(If you think changing package-lock.json doesn't make a difference, we can keep it as is.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Brilliant! Yes


- name: Types
run: npm run types

size:
needs: prepare
name: Size (${{ matrix.os}}, Node ${{ matrix.node }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
node: [14]

steps:
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}

- name: Checkout
uses: actions/checkout@master

- name: Retrieve node_modules
uses: actions/cache@v3
with:
path: node_modules
key: ${{ matrix.os }}-node-v${{ matrix.node }}-deps-${{ hashFiles(format('{0}{1}', github.workspace, '/package-lock.json')) }}

- name: Size
if: github.event_name == 'pull_request' && matrix.os == 'ubuntu-latest' && matrix.node == 14
uses: andresz1/size-limit-action@v1
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/asLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ export const asLink = <
const linkField =
// prettier-ignore
(
// @ts-expect-error - Bug in TypeScript 4.9: https://github.com/microsoft/TypeScript/issues/51501
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - Bug in TypeScript 4.9: https://github.com/microsoft/TypeScript/issues/51501
// TODO: Remove the `prettier-ignore` comment when this bug is fixed.
"link_type" in linkFieldOrDocument
? linkFieldOrDocument
Expand Down
2 changes: 1 addition & 1 deletion test/__testutils__/testAnyGetMethod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const testAnyGetMethodFactory = (
break;

default:
throw new Error("Unknown mode `%o`", mode);
throw new Error(`Unknown mode \`${mode}\``);
}
});
};
Expand Down