diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..57dd7ff --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,56 @@ +name: ci + +on: + - push + - pull_request + +jobs: + + build: + name: Continuous integration (build) + runs-on: ubuntu-latest + steps: + - name: Checkout 🛎️ + uses: actions/checkout@v3 + + - name: Install 📦 + uses: bahmutov/npm-install@v1 + with: + install-command: yarn --frozen-lockfile --ignore-scripts + useRollingCache: true + + - name: Build 🏗️ + run: yarn build + + - name: Archive build 💽 + uses: actions/upload-artifact@v3 + with: + name: dist + path: dist + retention-days: 1 + + test: + needs: ["build"] + name: Continuous integration (tests) + runs-on: ubuntu-latest + strategy: + matrix: + bundle: ["modern", "module", "cjs"] + steps: + - name: Checkout 🛎️ + uses: actions/checkout@v3 + + - name: Install 📦 + uses: bahmutov/npm-install@v1 + with: + install-command: yarn --frozen-lockfile --ignore-scripts + useRollingCache: true + + - name: Load build 💽 + uses: actions/download-artifact@v3 + with: + name: dist + path: dist + + - name: Test 🔬 + run: yarn test:${{ matrix.bundle }} diff --git a/.github/workflows/ci:test.yml b/.github/workflows/ci:cover.yml similarity index 71% rename from .github/workflows/ci:test.yml rename to .github/workflows/ci:cover.yml index 0de8523..7391234 100644 --- a/.github/workflows/ci:test.yml +++ b/.github/workflows/ci:cover.yml @@ -1,23 +1,23 @@ -name: ci:test +name: ci:cover on: - push - pull_request jobs: - test: - name: Continuous integration (tests) + cover: + name: Continuous integration (code coverage) runs-on: ubuntu-latest steps: - name: Checkout 🛎️ uses: actions/checkout@v3 - - name: Install 🔧 + - name: Install 📦 uses: bahmutov/npm-install@v1 with: install-command: yarn --frozen-lockfile --ignore-scripts useRollingCache: true - - name: Test 🔬 - run: yarn ci:test + - name: Test and record coverage 🔬 + run: yarn cover - name: Publish coverage report 📃 uses: codecov/codecov-action@v3 diff --git a/.github/workflows/ci:lint-config.yml b/.github/workflows/ci:lint-config.yml new file mode 100644 index 0000000..bdd3853 --- /dev/null +++ b/.github/workflows/ci:lint-config.yml @@ -0,0 +1,20 @@ +name: ci:lint-config +on: + - push + - pull_request +jobs: + cover: + name: Continuous integration (config linting) + runs-on: ubuntu-latest + steps: + - name: Checkout 🛎️ + uses: actions/checkout@v3 + + - name: Install 📦 + uses: bahmutov/npm-install@v1 + with: + install-command: yarn --frozen-lockfile --ignore-scripts + useRollingCache: true + + - name: Lint config 👕 + run: yarn lint-config diff --git a/.github/workflows/ci:build.yml b/.github/workflows/ci:lint.yml similarity index 66% rename from .github/workflows/ci:build.yml rename to .github/workflows/ci:lint.yml index ee3a57c..7e0551c 100644 --- a/.github/workflows/ci:build.yml +++ b/.github/workflows/ci:lint.yml @@ -1,20 +1,20 @@ -name: ci:build +name: ci:lint on: - push - pull_request jobs: - test: - name: Continuous integration (build) + cover: + name: Continuous integration (code linting) runs-on: ubuntu-latest steps: - name: Checkout 🛎️ uses: actions/checkout@v3 - - name: Install 🔧 + - name: Install 📦 uses: bahmutov/npm-install@v1 with: install-command: yarn --frozen-lockfile --ignore-scripts useRollingCache: true - - name: Build 🏗️ - run: yarn ci:build + - name: Lint 👕 + run: yarn lint diff --git a/README.md b/README.md index e136d1d..a91d53e 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Parent is [@codec-bytes/about](https://github.com/codec-bytes/about). [![License](https://img.shields.io/github/license/codec-bytes/ascii.svg)](https://raw.githubusercontent.com/codec-bytes/ascii/main/LICENSE) [![Version](https://img.shields.io/npm/v/@codec-bytes/ascii.svg)](https://www.npmjs.org/package/@codec-bytes/ascii) -[![Tests](https://img.shields.io/github/workflow/status/codec-bytes/ascii/ci:test?event=push&label=tests)](https://github.com/codec-bytes/ascii/actions/workflows/ci:test.yml?query=branch:main) +[![Tests](https://img.shields.io/github/workflow/status/codec-bytes/ascii/ci?event=push&label=tests)](https://github.com/codec-bytes/ascii/actions/workflows/ci.yml?query=branch:main) [![Dependencies](https://img.shields.io/librariesio/github/codec-bytes/ascii.svg)](https://github.com/codec-bytes/ascii/network/dependencies) [![GitHub issues](https://img.shields.io/github/issues/codec-bytes/ascii.svg)](https://github.com/codec-bytes/ascii/issues) [![Downloads](https://img.shields.io/npm/dm/@codec-bytes/ascii.svg)](https://www.npmjs.org/package/@codec-bytes/ascii) diff --git a/package.json b/package.json index 45743c7..dfc438c 100644 --- a/package.json +++ b/package.json @@ -45,8 +45,6 @@ "build": "NODE_ENV=production microbundle", "build-docs": "esdoc", "build-gh-pages": "npm run build-docs", - "ci:build": "npm run build", - "ci:test": "npm run lint-config && npm run lint && npm run cover", "commit-msg": "commitlint --edit", "cover": "NODE_ENV=cover c8 --all --src src --reporter lcov --reporter text-summary --reporter text npm test", "debug": "NODE_ENV=debug npm run test -- -st --fail-fast", @@ -62,7 +60,13 @@ "prepare": "npm run build", "prepublishOnly": "pinst --disable", "release": "np --message ':hatching_chick: release: Bumping to v%s.'", - "test": "ava" + "test": "npm run test:src", + "test-cmd": "NODE_LOADER_CONFIG=test/loader/config.js ava", + "test:cjs": "IMPORT_MAP_PATH=test/import-maps/dist/index.json npm run test-cmd", + "test:dist": "npm run test:modern && npm run test:module && npm run test:cjs", + "test:modern": "IMPORT_MAP_PATH=test/import-maps/dist/index.modern.json npm run test-cmd", + "test:module": "IMPORT_MAP_PATH=test/import-maps/dist/index.module.json npm run test-cmd", + "test:src": "IMPORT_MAP_PATH=test/import-maps/src/index.json npm run test-cmd" }, "dependencies": { "@codec-bytes/error": "^5.0.0" @@ -76,6 +80,8 @@ "@iterable-iterator/range": "^2.1.0", "@js-library/commitlint-config": "0.0.4", "@node-loader/babel": "2.0.1", + "@node-loader/core": "2.0.0", + "@node-loader/import-maps": "1.1.0", "ava": "4.3.3", "babel-plugin-transform-remove-console": "6.9.4", "babel-plugin-unassert": "3.0.1", @@ -104,7 +110,7 @@ ], "timeout": "1m", "nodeArguments": [ - "--experimental-loader=@node-loader/babel" + "--experimental-loader=@node-loader/core" ] }, "babel": { diff --git a/test/import-maps/dist/index.json b/test/import-maps/dist/index.json new file mode 100644 index 0000000..7059eb6 --- /dev/null +++ b/test/import-maps/dist/index.json @@ -0,0 +1,5 @@ +{ + "imports": { + "#module": "./dist/index.cjs" + } +} diff --git a/test/import-maps/dist/index.modern.json b/test/import-maps/dist/index.modern.json new file mode 100644 index 0000000..8eafb2e --- /dev/null +++ b/test/import-maps/dist/index.modern.json @@ -0,0 +1,5 @@ +{ + "imports": { + "#module": "./dist/index.modern.js" + } +} diff --git a/test/import-maps/dist/index.module.json b/test/import-maps/dist/index.module.json new file mode 100644 index 0000000..74c8d44 --- /dev/null +++ b/test/import-maps/dist/index.module.json @@ -0,0 +1,5 @@ +{ + "imports": { + "#module": "./dist/index.module.js" + } +} diff --git a/test/import-maps/src/index.json b/test/import-maps/src/index.json new file mode 100644 index 0000000..6b576f1 --- /dev/null +++ b/test/import-maps/src/index.json @@ -0,0 +1,5 @@ +{ + "imports": { + "#module": "./src/index.js" + } +} diff --git a/test/loader/config.js b/test/loader/config.js new file mode 100644 index 0000000..e08c360 --- /dev/null +++ b/test/loader/config.js @@ -0,0 +1,8 @@ +import * as importMapLoader from '@node-loader/import-maps'; +import * as babelLoader from '@node-loader/babel'; + +const config = { + loaders: [importMapLoader, babelLoader], +}; + +export default config; diff --git a/test/src/_fixtures.js b/test/src/_fixtures.js index 8d71ea6..658ed5f 100644 --- a/test/src/_fixtures.js +++ b/test/src/_fixtures.js @@ -1,4 +1,4 @@ -import * as mod from '../../src/index.js'; +import * as mod from '#module'; const _mod = mod.default ?? mod; diff --git a/test/src/decode.js b/test/src/decode.js index 8b19a6c..80b8b61 100644 --- a/test/src/decode.js +++ b/test/src/decode.js @@ -1,7 +1,7 @@ import test from 'ava'; import {range} from '@iterable-iterator/range'; -import {decode, ASCIIDecodeError, byte2char} from '../../src/index.js'; +import {decode, ASCIIDecodeError, byte2char} from '#module'; import {CodecError} from './_fixtures.js'; function success(t, bytes, options, expected) { diff --git a/test/src/encode.js b/test/src/encode.js index 265c6f7..c02fff6 100644 --- a/test/src/encode.js +++ b/test/src/encode.js @@ -1,7 +1,7 @@ import test from 'ava'; import {range} from '@iterable-iterator/range'; -import {encode, ASCIIEncodeError, byte2char} from '../../src/index.js'; +import {encode, ASCIIEncodeError, byte2char} from '#module'; import {CodecError} from './_fixtures.js'; function success(t, string, options, expected) { diff --git a/yarn.lock b/yarn.lock index 4f65145..303a4fe 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1386,6 +1386,16 @@ resolved "https://registry.yarnpkg.com/@node-loader/babel/-/babel-2.0.1.tgz#a04d7535b5ade12e3987de04fc5ffe204f26c64c" integrity sha512-lulESaNn+jyn4lCbfcFWFcRYchsL0jY8q/mf5XRKOiX2uTpkXE3fGAlZ4+wyP/hIAMSlDPuHIUkRSTkJZ6SQyA== +"@node-loader/core@2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@node-loader/core/-/core-2.0.0.tgz#7f5a3a91fe137c8e71c0813f3bbaa0ee136a1308" + integrity sha512-7wV4qj2/tROXGgoYWmNvObUXbXqSv1yUD31K79Jt1q7NDuqrLz4WjjW+wVoCNgVcl8+YSj9BvLX8KsB/SrSzuw== + +"@node-loader/import-maps@1.1.0": + version "1.1.0" + resolved "https://registry.yarnpkg.com/@node-loader/import-maps/-/import-maps-1.1.0.tgz#4785fdce3bc973c5b53a4549248ab42b370ecda9" + integrity sha512-RPB+7vBVhk9xF/eiSGSxEnL6hGQ0a1ua9hvl/MxXDmu7F+Nv+gMwA7AJ0S5TmcgulHAp9/IxobGoFiOxkX7xWQ== + "@nodelib/fs.scandir@2.1.5": version "2.1.5" resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5"