Skip to content

Commit 86a0323

Browse files
committed
refactor CI test runs to run against the code in a built and packaged form instead of against the source code
1 parent 2c34532 commit 86a0323

File tree

11 files changed

+144
-13
lines changed

11 files changed

+144
-13
lines changed

.github/workflows/___.yaml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: CI - ___
2+
3+
on:
4+
pull_request:
5+
branches: [master]
6+
7+
jobs:
8+
lint_check:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
with:
13+
ref: ${{ github.head_ref }}
14+
15+
- uses: ./.github/actions/ci-common-setup
16+
17+
- name: Lint check
18+
run: pnpm exec eslint --cache
19+
20+
prettier_check:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
with:
25+
ref: ${{ github.head_ref }}
26+
27+
- uses: ./.github/actions/ci-common-setup
28+
29+
- name: Prettier check
30+
run: pnpm exec prettier --check "./{src,spec}/**/*.{ts,tsx,js,mjs,jsx}"
31+
32+
run_tests:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v4
36+
with:
37+
ref: ${{ github.head_ref }}
38+
39+
- uses: ./.github/actions/ci-common-setup
40+
41+
- name: Get "name" from package.json
42+
id: get-name
43+
run: |
44+
echo "package_name=$(cat ./package.json | jq -r '.name')" >> $GITHUB_OUTPUT
45+
46+
- name: Build and pack library locally
47+
id: pkg-pack
48+
run: |
49+
pnpm pack
50+
51+
- name: Install locally-packaged library
52+
run: |
53+
PACKAGE_FILENAME=$(ls ${{ steps.get-name.outputs.package_name }}-*.tgz)
54+
pnpm i packaged-react-async-iterators@file:./$PACKAGE_FILENAME
55+
56+
- name: Run tests against packaged library code
57+
run: |
58+
[[ -e ./src ]] && mv ./src ./src-ignored-for-packaged-testing
59+
echo 'export * from "packaged-react-async-iterators";' > ./spec/libEntrypoint.ts
60+
pnpm test
61+
[[ -e ./src-ignored-for-packaged-testing ]] && mv ./src-ignored-for-packaged-testing ./src
62+
63+
run_type_check_on_tests:
64+
runs-on: ubuntu-latest
65+
steps:
66+
- uses: actions/checkout@v4
67+
with:
68+
ref: ${{ github.head_ref }}
69+
70+
- uses: ./.github/actions/ci-common-setup
71+
72+
- name: Get "name" from package.json
73+
id: get-name
74+
run: |
75+
echo "package_name=$(cat ./package.json | jq -r '.name')" >> $GITHUB_OUTPUT
76+
77+
- name: Build and pack library locally
78+
id: pkg-pack
79+
run: |
80+
pnpm pack
81+
82+
- name: Install locally-packaged library
83+
run: |
84+
PACKAGE_FILENAME=$(ls ${{ steps.get-name.outputs.package_name }}-*.tgz)
85+
pnpm i packaged-react-async-iterators@file:./$PACKAGE_FILENAME
86+
87+
- name: Type-check tests code
88+
run: |
89+
[[ -e ./src ]] && mv ./src ./src-ignored-for-packaged-testing
90+
echo 'export * from "packaged-react-async-iterators";' > ./spec/libEntrypoint.ts
91+
pnpm run test-typings-check
92+
[[ -e ./src-ignored-for-packaged-testing ]] && mv ./src-ignored-for-packaged-testing ./src

.github/workflows/ci-tests-type-check.yaml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
branches: [master]
66

77
jobs:
8-
run_tests_ts_type_check:
8+
run_type_check_on_tests:
99
runs-on: ubuntu-latest
1010
steps:
1111
- uses: actions/checkout@v4
@@ -14,5 +14,24 @@ jobs:
1414

1515
- uses: ./.github/actions/ci-common-setup
1616

17-
- name: TypeScript test build
18-
run: pnpm run test-typings-check
17+
- name: Get "name" from package.json
18+
id: get-name
19+
run: |
20+
echo "package_name=$(cat ./package.json | jq -r '.name')" >> $GITHUB_OUTPUT
21+
22+
- name: Build and pack library locally
23+
id: pkg-pack
24+
run: |
25+
pnpm pack
26+
27+
- name: Install locally-packaged library
28+
run: |
29+
PACKAGE_FILENAME=$(ls ${{ steps.get-name.outputs.package_name }}-*.tgz)
30+
pnpm i packaged-react-async-iterators@file:./$PACKAGE_FILENAME
31+
32+
- name: Type-check tests code
33+
run: |
34+
[[ -e ./src ]] && mv ./src ./src-ignored-for-packaged-testing
35+
echo 'export * from "packaged-react-async-iterators";' > ./spec/libEntrypoint.ts
36+
pnpm run test-typings-check
37+
[[ -e ./src-ignored-for-packaged-testing ]] && mv ./src-ignored-for-packaged-testing ./src

.github/workflows/ci-tests.yaml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,25 @@ jobs:
1313
ref: ${{ github.head_ref }}
1414

1515
- uses: ./.github/actions/ci-common-setup
16-
17-
- name: Run tests
18-
run: pnpm run test
16+
17+
- name: Get "name" from package.json
18+
id: get-name
19+
run: |
20+
echo "package_name=$(cat ./package.json | jq -r '.name')" >> $GITHUB_OUTPUT
21+
22+
- name: Build and pack library locally
23+
id: pkg-pack
24+
run: |
25+
pnpm pack
26+
27+
- name: Install locally-packaged library
28+
run: |
29+
PACKAGE_FILENAME=$(ls ${{ steps.get-name.outputs.package_name }}-*.tgz)
30+
pnpm i packaged-react-async-iterators@file:./$PACKAGE_FILENAME
31+
32+
- name: Run tests against packaged library code
33+
run: |
34+
[[ -e ./src ]] && mv ./src ./src-ignored-for-packaged-testing
35+
echo 'export * from "packaged-react-async-iterators";' > ./spec/libEntrypoint.ts
36+
pnpm test
37+
[[ -e ./src-ignored-for-packaged-testing ]] && mv ./src-ignored-for-packaged-testing ./src

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"test-typings-check": "tsc --noEmit -p ./spec/tsconfig.json",
4949
"build": "rm -rf ./dist && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && node ./scripts/set-module-type-in-dist-builds.mjs",
5050
"build-check": "tsc --noEmit -p ./tsconfig.json",
51-
"prepublishOnly": "npm run build"
51+
"prepack": "npm run build"
5252
},
5353
"peerDependencies": {
5454
"react": ">=17"

spec/libEntrypoint.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from '../src/index.js';

spec/tests/Iterate.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { it, describe, expect, afterEach, vi, type Mock } from 'vitest';
22
import { gray } from 'colorette';
33
import { render, cleanup as cleanupMountedReactTrees, act } from '@testing-library/react';
4-
import { Iterate, It, iterateFormatted, type IterationResult } from '../../src/index.js';
4+
import { Iterate, It, iterateFormatted, type IterationResult } from '../libEntrypoint.js';
55
import { asyncIterOf } from '../utils/asyncIterOf.js';
66
import { IteratorChannelTestHelper } from '../utils/IteratorChannelTestHelper.js';
77

spec/tests/IterateMulti.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
ItMulti,
88
type IterateMultiProps,
99
type IterationResultSet,
10-
} from '../../src/index.js';
10+
} from '../libEntrypoint.js';
1111
import { pipe } from '../utils/pipe.js';
1212
import { asyncIterOf } from '../utils/asyncIterOf.js';
1313
import { IteratorChannelTestHelper } from '../utils/IteratorChannelTestHelper.js';

spec/tests/iterateFormatted.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { it, describe, expect, afterEach } from 'vitest';
22
import { gray } from 'colorette';
33
import { render, cleanup as cleanupMountedReactTrees, act } from '@testing-library/react';
4-
import { iterateFormatted, Iterate } from '../../src/index.js';
4+
import { iterateFormatted, Iterate } from '../libEntrypoint.js';
55
import { pipe } from '../utils/pipe.js';
66
import { asyncIterOf } from '../utils/asyncIterOf.js';
77
import { asyncIterToArray } from '../utils/asyncIterToArray.js';

spec/tests/useAsyncIter.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { it, describe, expect, afterEach, vi } from 'vitest';
22
import { gray } from 'colorette';
33
import { cleanup as cleanupMountedReactTrees, act, renderHook } from '@testing-library/react';
4-
import { useAsyncIter, iterateFormatted } from '../../src/index.js';
4+
import { useAsyncIter, iterateFormatted } from '../libEntrypoint.js';
55
import { asyncIterOf } from '../utils/asyncIterOf.js';
66
import { IteratorChannelTestHelper } from '../utils/IteratorChannelTestHelper.js';
77

spec/tests/useAsyncIterMulti.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { it, describe, expect, afterEach, vi } from 'vitest';
22
import { gray } from 'colorette';
33
import { cleanup as cleanupMountedReactTrees, act, renderHook } from '@testing-library/react';
4-
import { iterateFormatted, useAsyncIterMulti } from '../../src/index.js';
4+
import { iterateFormatted, useAsyncIterMulti } from '../libEntrypoint.js';
55
import { pipe } from '../utils/pipe.js';
66
import { asyncIterOf } from '../utils/asyncIterOf.js';
77
import { IteratorChannelTestHelper } from '../utils/IteratorChannelTestHelper.js';

0 commit comments

Comments
 (0)