diff --git a/.github/actions/ci-common-setup-locally-packaged/action.yaml b/.github/actions/ci-common-setup-locally-packaged/action.yaml new file mode 100644 index 0000000..1ce6efc --- /dev/null +++ b/.github/actions/ci-common-setup-locally-packaged/action.yaml @@ -0,0 +1,43 @@ +name: Common Setup for CI with locally packaged library code + +description: Reusable common setup with locally packaged library code for project's CI jobs + +inputs: + node-version: + description: Specific Node.js version to override the common one that's gonna be selected by default + required: false + default: v22.5.0 + +runs: + using: composite + steps: + - uses: ./.github/actions/ci-common-setup + with: + node-version: ${{ inputs.node-version }} + + - name: Get "name" and "version" from package.json + id: package-json-info + shell: bash + run: | + { + echo "package_name=$(cat ./package.json | jq -r '.name')" + echo "package_version=$(cat ./package.json | jq -r '.version')" + } >> $GITHUB_OUTPUT + + - name: Build and pack library locally + id: pkg-pack + shell: bash + run: | + pnpm pack + + - name: Install locally-packaged library + shell: bash + run: | + PACKAGE_FILENAME=$(ls ${{ steps.package-json-info.outputs.package_name }}-${{ steps.package-json-info.outputs.package_version }}.tgz) + pnpm i packaged-react-async-iterators@file:./$PACKAGE_FILENAME + + - name: Type-check tests code + shell: bash + run: | + [[ -e ./src ]] && mv ./src ./src-ignored-for-packaged-testing + echo 'export * from "packaged-react-async-iterators";' > ./spec/libEntrypoint.ts diff --git a/.github/workflows/ci-build-check.yaml b/.github/workflows/ci-build-check.yaml deleted file mode 100644 index 29adb2c..0000000 --- a/.github/workflows/ci-build-check.yaml +++ /dev/null @@ -1,18 +0,0 @@ -name: CI - build check - -on: - pull_request: - branches: [master] - -jobs: - ts_build_test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.head_ref }} - - - uses: ./.github/actions/ci-common-setup - - - name: TypeScript test build - run: pnpm run build-check diff --git a/.github/workflows/ci-eslint-check.yaml b/.github/workflows/ci-eslint-check.yaml deleted file mode 100644 index 197cf1f..0000000 --- a/.github/workflows/ci-eslint-check.yaml +++ /dev/null @@ -1,18 +0,0 @@ -name: CI - ESLint check - -on: - pull_request: - branches: [master] - -jobs: - lint_check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.head_ref }} - - - uses: ./.github/actions/ci-common-setup - - - name: Lint check - run: pnpm exec eslint --cache diff --git a/.github/workflows/ci-prettier-check.yaml b/.github/workflows/ci-prettier-check.yaml deleted file mode 100644 index 54ae313..0000000 --- a/.github/workflows/ci-prettier-check.yaml +++ /dev/null @@ -1,18 +0,0 @@ -name: CI - Prettier check - -on: - pull_request: - branches: [master] - -jobs: - prettier_check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.head_ref }} - - - uses: ./.github/actions/ci-common-setup - - - name: Prettier check - run: pnpm exec prettier --check "./{src,spec}/**/*.{ts,tsx,js,mjs,jsx}" diff --git a/.github/workflows/ci-tests-type-check.yaml b/.github/workflows/ci-tests-type-check.yaml deleted file mode 100644 index 1ac87fb..0000000 --- a/.github/workflows/ci-tests-type-check.yaml +++ /dev/null @@ -1,18 +0,0 @@ -name: CI - tests type check - -on: - pull_request: - branches: [master] - -jobs: - run_tests_ts_type_check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.head_ref }} - - - uses: ./.github/actions/ci-common-setup - - - name: TypeScript test build - run: pnpm run test-typings-check diff --git a/.github/workflows/ci-tests.yaml b/.github/workflows/ci-tests.yaml deleted file mode 100644 index 67e57bc..0000000 --- a/.github/workflows/ci-tests.yaml +++ /dev/null @@ -1,18 +0,0 @@ -name: CI - tests - -on: - pull_request: - branches: [master] - -jobs: - run_tests: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.head_ref }} - - - uses: ./.github/actions/ci-common-setup - - - name: Run tests - run: pnpm run test diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..f7911c8 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,68 @@ +name: CI + +on: + pull_request: + branches: [master] + +jobs: + lint_check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + + - uses: ./.github/actions/ci-common-setup + + - name: Lint check + run: pnpm exec eslint --cache + + prettier_check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + + - uses: ./.github/actions/ci-common-setup + + - name: Prettier check + run: pnpm exec prettier --check "./{src,spec}/**/*.{ts,tsx,js,mjs,jsx}" + + ts_build_test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + + - uses: ./.github/actions/ci-common-setup + + - name: TypeScript test build + run: pnpm run build-check + + run_tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + + - uses: ./.github/actions/ci-common-setup-locally-packaged + + - name: Run tests against packaged library code + run: | + pnpm test + + run_type_check_on_tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + + - uses: ./.github/actions/ci-common-setup-locally-packaged + + - name: Type-check tests code + run: | + pnpm run test-typings-check diff --git a/package.json b/package.json index df02d86..a8ebe66 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "test-typings-check": "tsc --noEmit -p ./spec/tsconfig.json", "build": "rm -rf ./dist && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && node ./scripts/set-module-type-in-dist-builds.mjs", "build-check": "tsc --noEmit -p ./tsconfig.json", - "prepublishOnly": "npm run build" + "prepack": "npm run build" }, "peerDependencies": { "react": ">=17" diff --git a/spec/libEntrypoint.ts b/spec/libEntrypoint.ts new file mode 100644 index 0000000..a4a01ce --- /dev/null +++ b/spec/libEntrypoint.ts @@ -0,0 +1 @@ +export * from '../src/index.js'; diff --git a/spec/tests/Iterate.spec.tsx b/spec/tests/Iterate.spec.tsx index fd6cc54..bc343c2 100644 --- a/spec/tests/Iterate.spec.tsx +++ b/spec/tests/Iterate.spec.tsx @@ -1,7 +1,7 @@ import { it, describe, expect, afterEach, vi, type Mock } from 'vitest'; import { gray } from 'colorette'; import { render, cleanup as cleanupMountedReactTrees, act } from '@testing-library/react'; -import { Iterate, It, iterateFormatted, type IterationResult } from '../../src/index.js'; +import { Iterate, It, iterateFormatted, type IterationResult } from '../libEntrypoint.js'; import { asyncIterOf } from '../utils/asyncIterOf.js'; import { IteratorChannelTestHelper } from '../utils/IteratorChannelTestHelper.js'; diff --git a/spec/tests/IterateMulti.spec.tsx b/spec/tests/IterateMulti.spec.tsx index fc9d972..0bc09cd 100644 --- a/spec/tests/IterateMulti.spec.tsx +++ b/spec/tests/IterateMulti.spec.tsx @@ -7,7 +7,7 @@ import { ItMulti, type IterateMultiProps, type IterationResultSet, -} from '../../src/index.js'; +} from '../libEntrypoint.js'; import { pipe } from '../utils/pipe.js'; import { asyncIterOf } from '../utils/asyncIterOf.js'; import { IteratorChannelTestHelper } from '../utils/IteratorChannelTestHelper.js'; diff --git a/spec/tests/iterateFormatted.spec.tsx b/spec/tests/iterateFormatted.spec.tsx index a9291a3..4c0effb 100644 --- a/spec/tests/iterateFormatted.spec.tsx +++ b/spec/tests/iterateFormatted.spec.tsx @@ -1,7 +1,7 @@ import { it, describe, expect, afterEach } from 'vitest'; import { gray } from 'colorette'; import { render, cleanup as cleanupMountedReactTrees, act } from '@testing-library/react'; -import { iterateFormatted, Iterate } from '../../src/index.js'; +import { iterateFormatted, Iterate } from '../libEntrypoint.js'; import { pipe } from '../utils/pipe.js'; import { asyncIterOf } from '../utils/asyncIterOf.js'; import { asyncIterToArray } from '../utils/asyncIterToArray.js'; diff --git a/spec/tests/useAsyncIter.spec.ts b/spec/tests/useAsyncIter.spec.ts index 0933b1e..e47a0de 100644 --- a/spec/tests/useAsyncIter.spec.ts +++ b/spec/tests/useAsyncIter.spec.ts @@ -1,7 +1,7 @@ import { it, describe, expect, afterEach, vi } from 'vitest'; import { gray } from 'colorette'; import { cleanup as cleanupMountedReactTrees, act, renderHook } from '@testing-library/react'; -import { useAsyncIter, iterateFormatted } from '../../src/index.js'; +import { useAsyncIter, iterateFormatted } from '../libEntrypoint.js'; import { asyncIterOf } from '../utils/asyncIterOf.js'; import { IteratorChannelTestHelper } from '../utils/IteratorChannelTestHelper.js'; diff --git a/spec/tests/useAsyncIterMulti.spec.ts b/spec/tests/useAsyncIterMulti.spec.ts index 61036b5..73164dd 100644 --- a/spec/tests/useAsyncIterMulti.spec.ts +++ b/spec/tests/useAsyncIterMulti.spec.ts @@ -1,7 +1,7 @@ import { it, describe, expect, afterEach, vi } from 'vitest'; import { gray } from 'colorette'; import { cleanup as cleanupMountedReactTrees, act, renderHook } from '@testing-library/react'; -import { iterateFormatted, useAsyncIterMulti } from '../../src/index.js'; +import { iterateFormatted, useAsyncIterMulti } from '../libEntrypoint.js'; import { pipe } from '../utils/pipe.js'; import { asyncIterOf } from '../utils/asyncIterOf.js'; import { IteratorChannelTestHelper } from '../utils/IteratorChannelTestHelper.js'; diff --git a/spec/tests/useAsyncIterState.spec.tsx b/spec/tests/useAsyncIterState.spec.tsx index 5a97fc8..160cd0a 100644 --- a/spec/tests/useAsyncIterState.spec.tsx +++ b/spec/tests/useAsyncIterState.spec.tsx @@ -7,7 +7,7 @@ import { cleanup as cleanupMountedReactTrees, act, } from '@testing-library/react'; -import { useAsyncIterState } from '../../src/index.js'; +import { useAsyncIterState } from '../libEntrypoint.js'; import { asyncIterToArray } from '../utils/asyncIterToArray.js'; import { asyncIterTake } from '../utils/asyncIterTake.js'; import { asyncIterTakeFirst } from '../utils/asyncIterTakeFirst.js';