From 36b243c8ea63b5090f0f8c230e25381942f41b41 Mon Sep 17 00:00:00 2001 From: TOMIKAWA Sotaro Date: Thu, 5 Dec 2024 18:56:13 +0900 Subject: [PATCH] ci: setup ci --- .github/actions/setup.yml | 14 ++++++++++++++ .github/workflows/ci.yml | 15 +++++++++++++++ README.md | 31 ++++++++++++++----------------- package.json | 3 ++- tests/node.test.mjs | 18 ------------------ tests/node.test.ts | 30 ++++++++++++++++++++++++++++++ tests/package.json | 3 ++- tsconfig.json | 3 ++- 8 files changed, 79 insertions(+), 38 deletions(-) create mode 100644 .github/actions/setup.yml create mode 100644 .github/workflows/ci.yml delete mode 100644 tests/node.test.mjs create mode 100644 tests/node.test.ts diff --git a/.github/actions/setup.yml b/.github/actions/setup.yml new file mode 100644 index 0000000..5cecb3f --- /dev/null +++ b/.github/actions/setup.yml @@ -0,0 +1,14 @@ +name: Setup Node.js and Install deps +description: Setup Node.js/pnpm. Install dependencies. +runs: + using: 'composite' + steps: + - run: corepack enable + shell: bash + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: pnpm + - name: Install deps + run: pnpm install + shell: bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8d6149a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,15 @@ +name: CI +on: + push: + branches: + - main + pull_request: +jobs: + check: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup-node + - run: pnpm check + - run: sudo pnpm test + working-directory: tests diff --git a/README.md b/README.md index d7c3114..740e9c6 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,30 @@ # apple-app-site-association Check apple-app-site-association file. +It works with `swcutil` command that is preinstalled in macOS. ## Usage -Reference types: +Test universal links: -```typescript -import type { AppleAppSiteAssociation } from 'apple-app-site-association'; -const aasa = { - applinks: { - // ... - } -} as const satisfies AppleAppSiteAssociation; +```sh +# swcutil command requires root permission +sudo node --test --experimental-strip-types # `--experimental-strip-types` is required node@22 ``` -Test universal links: - ```typescript -import { test } from 'node:test'; -import { createAssert } from 'apple-app-site-association'; -const assert = createAssert(YOUR_DOMAIN, AASA_JSON); -test("universal link works", async () => { - await assert.universalLink("/path/to/your/app", "match"); - await assert.universalLink("/#donot_deeplinking", "block"); +// test-universallinks.test.ts +import * as assert from "node:assert"; +import { test } from "node:test"; +import { verify, type AppleAppSiteAssociation } from "apple-app-site-association"; +const json = { applinks: { /* ... */ } } satisfies AppleAppSiteAssociation; +test("/search/ should match", async () => { + const actual: 'match' | 'block' | 'unset' = await verify("example.com", "/search/", json); + assert.strictEqual(actual, "match"); }); ``` -Use `swcutil` command directly: +Use `swcutil` command programmatically: ```typescript import { swcutil } from 'apple-app-site-association/swcutil'; diff --git a/package.json b/package.json index 120a637..2e2efbd 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,8 @@ "build": "tsc", "clean": "node -e \"fs.rmSync('dist',{recursive:true,force:true})\"", "prepare": "npm run clean && npm run build", - "fmt": "biome check --write ." + "fmt": "biome check --write .", + "check": "biome check ." }, "keywords": [ "aasa", diff --git a/tests/node.test.mjs b/tests/node.test.mjs deleted file mode 100644 index ee6be7d..0000000 --- a/tests/node.test.mjs +++ /dev/null @@ -1,18 +0,0 @@ -import * as assert from "node:assert"; -import { test } from "node:test"; -import { verify } from "apple-app-site-association"; - -const json = await fetch( - "https://zozo.jp/.well-known/apple-app-site-association", -).then((res) => res.json()); - -test("/sale/ should match", async () => { - assert.strictEqual(await verify("zozo.jp", "/sale/", json), "match"); -}); - -test("#nondeeplinking should block", async () => { - assert.strictEqual( - await verify("zozo.jp", "/sale/#nondeeplinking", json), - "block", - ); -}); diff --git a/tests/node.test.ts b/tests/node.test.ts new file mode 100644 index 0000000..9dfe71b --- /dev/null +++ b/tests/node.test.ts @@ -0,0 +1,30 @@ +import * as assert from "node:assert"; +import { test } from "node:test"; +import { + verify, + type AppleAppSiteAssociation, +} from "apple-app-site-association"; + +const json = { + applinks: { + details: [ + { + appIDs: ["HOGE.com.example.app"], + components: [ + { "#": "nondeeplinking", exclude: true }, + { "/": "/search/" }, + ], + }, + ], + }, +} as const satisfies AppleAppSiteAssociation; + +test("/search/ should match", async () => { + const actual = await verify("example.com", "/search/", json); + assert.strictEqual(actual, "match"); +}); + +test("#nondeeplinking should block", async () => { + const actual = await verify("example.com", "/search/#nondeeplinking", json); + assert.strictEqual(actual, "block"); +}); diff --git a/tests/package.json b/tests/package.json index 08bcba6..569bae0 100644 --- a/tests/package.json +++ b/tests/package.json @@ -1,7 +1,8 @@ { + "type": "module", "scripts": { "test": "npm run test:node", - "test:node": "node --test node.test.mjs" + "test:node": "node --test --experimental-strip-types node.test.ts" }, "devDependencies": { "apple-app-site-association": "workspace:*" diff --git a/tsconfig.json b/tsconfig.json index ca85e5c..8d35b26 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,5 +9,6 @@ "declaration": true, "verbatimModuleSyntax": true, "isolatedDeclarations": true - } + }, + "exclude": ["dist"] }