From 9be0bc65fe26f250323829a3d7e8f68caede080c Mon Sep 17 00:00:00 2001 From: garthdb Date: Thu, 6 Jun 2024 17:06:17 -0600 Subject: [PATCH 1/2] ci: added basic code coverage --- package.json | 3 +- packages/tokens/moon.yml | 16 ++ packages/tokens/tasks/buildManifest.js | 14 +- packages/tokens/test/checkManifest.test.js | 13 +- packages/tokens/test/index.test.js | 44 ++++++ pnpm-lock.yaml | 165 +++++++++++++++++++++ 6 files changed, 240 insertions(+), 15 deletions(-) create mode 100644 packages/tokens/test/index.test.js diff --git a/package.json b/package.json index 0d1af861..bd4dee94 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ }, "packageManager": "pnpm@9.0.6", "dependencies": { - "@changesets/changelog-github": "^0.5.0" + "@changesets/changelog-github": "^0.5.0", + "c8": "^9.1.0" } } diff --git a/packages/tokens/moon.yml b/packages/tokens/moon.yml index 1a1e37a8..eee1562f 100644 --- a/packages/tokens/moon.yml +++ b/packages/tokens/moon.yml @@ -72,3 +72,19 @@ tasks: - --watch local: true platform: node + coverage: + command: + - pnpm + - c8 + - ava + platform: node + inputs: + - "tasks/**/*" + - "schemas/**/*.{yaml,yml,json}" + - "manifest.json" + - "@globs(tests)" + - "@globs(sources)" + deps: + - ~:buildTokens + outputs: + - "coverage/" diff --git a/packages/tokens/tasks/buildManifest.js b/packages/tokens/tasks/buildManifest.js index 44c58d32..c6ec85bc 100644 --- a/packages/tokens/tasks/buildManifest.js +++ b/packages/tokens/tasks/buildManifest.js @@ -10,16 +10,14 @@ OF ANY KIND, either express or implied. See the License for the specific languag governing permissions and limitations under the License. */ -import { glob } from "glob"; -import { writeFile } from "fs/promises"; -import { format } from "prettier"; +import { tokenFileNames, writeJson } from "../index.js"; +import { relative } from "path"; const manifestFileName = "manifest.json"; -const files = await glob("src/**/*.json"); -await writeFile( +await writeJson( manifestFileName, - await format(JSON.stringify(files), { parser: "json-stringify" }), + tokenFileNames.map((fileName) => relative(process.cwd(), fileName)), ); -// -console.log(`Wrote ${manifestFileName} with ${files.length} files.`); + +console.log(`Wrote ${manifestFileName} with ${tokenFileNames.length} files.`); diff --git a/packages/tokens/test/checkManifest.test.js b/packages/tokens/test/checkManifest.test.js index 2dccea83..d5f6948f 100644 --- a/packages/tokens/test/checkManifest.test.js +++ b/packages/tokens/test/checkManifest.test.js @@ -11,11 +11,12 @@ governing permissions and limitations under the License. */ import test from "ava"; -import { glob } from "glob"; -import { readFile } from "fs/promises"; +import { tokenFileNames, readJson } from "../index.js"; +import { relative } from "path"; -test("check for uuids", async (t) => { - const manifest = JSON.parse(await readFile("manifest.json", "utf8")); - const fileNames = await glob("src/**/*.json"); - t.deepEqual(manifest, fileNames); +test("manifest.json file should list all of the token files", async (t) => { + t.deepEqual( + await readJson("manifest.json"), + tokenFileNames.map((fileName) => relative(process.cwd(), fileName)), + ); }); diff --git a/packages/tokens/test/index.test.js b/packages/tokens/test/index.test.js new file mode 100644 index 00000000..0c05cf74 --- /dev/null +++ b/packages/tokens/test/index.test.js @@ -0,0 +1,44 @@ +/* +Copyright 2024 Adobe. All rights reserved. +This file is licensed to you under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. You may obtain a copy +of the License at http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under +the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS +OF ANY KIND, either express or implied. See the License for the specific language +governing permissions and limitations under the License. +*/ + +import { + getAllTokens, + tokenFileNames, + getFileTokens, + writeJson, + readJson, +} from "../index.js"; +import { unlink } from "fs/promises"; +import test from "ava"; + +test("the number of tokens in each file should match the number of tokens returned by getAllTokens", async (t) => { + const allTokens = await getAllTokens(); + const countTotal = await Promise.all(tokenFileNames.map(getFileTokens)).then( + (tokenFileDataAr) => { + return tokenFileDataAr.reduce( + (tokenCountAcc, tokenFileData) => + (tokenCountAcc += Object.keys(tokenFileData).length), + 0, + ); + }, + ); + t.is(Object.keys(allTokens).length, countTotal); +}); + +test("writeJson should write a json file", async (t) => { + const testJson = { test: "test" }; + const testTokenFileName = "test.json"; + await writeJson(testTokenFileName, testJson); + const readTestJson = await readJson(testTokenFileName); + await unlink(testTokenFileName); + t.deepEqual(testJson, readTestJson); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fa640f85..2e1ae8d9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10,6 +10,9 @@ importers: "@changesets/changelog-github": specifier: ^0.5.0 version: 0.5.0 + c8: + specifier: ^9.1.0 + version: 9.1.0 devDependencies: "@action-validator/core": specifier: ^0.6.0 @@ -224,6 +227,12 @@ packages: } engines: { node: ">=6.9.0" } + "@bcoe/v8-coverage@0.2.3": + resolution: + { + integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==, + } + "@changesets/apply-release-plan@7.0.0": resolution: { @@ -704,6 +713,32 @@ packages: } engines: { node: ">=18.0.0" } + "@istanbuljs/schema@0.1.3": + resolution: + { + integrity: sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA==, + } + engines: { node: ">=8" } + + "@jridgewell/resolve-uri@3.1.2": + resolution: + { + integrity: sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==, + } + engines: { node: ">=6.0.0" } + + "@jridgewell/sourcemap-codec@1.4.15": + resolution: + { + integrity: sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==, + } + + "@jridgewell/trace-mapping@0.3.25": + resolution: + { + integrity: sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==, + } + "@lit-labs/observers@2.0.2": resolution: { @@ -1346,6 +1381,12 @@ packages: integrity: sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==, } + "@types/istanbul-lib-coverage@2.0.6": + resolution: + { + integrity: sha512-2QF/t/auWm0lsy8XtKVPG19v3sSOQlJe/YHZgfjb/KBBHOGSV+J2q/S671rcq9uTBrLAXmZpqJiaQbMT+zNU1w==, + } + "@types/minimist@1.2.5": resolution: { @@ -1684,6 +1725,14 @@ packages: } engines: { node: ">=10.16.0" } + c8@9.1.0: + resolution: + { + integrity: sha512-mBWcT5iqNir1zIkzSPyI3NCR9EZCVI3WUD+AVO17MVWTSFNyUueXE82qTeampNtTr+ilN/5Ua3j24LgbCKjDVg==, + } + engines: { node: ">=14.14.0" } + hasBin: true + call-bind@1.0.7: resolution: { @@ -1989,6 +2038,12 @@ packages: engines: { node: ">=16" } hasBin: true + convert-source-map@2.0.0: + resolution: + { + integrity: sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==, + } + convert-to-spaces@2.0.1: resolution: { @@ -2771,6 +2826,12 @@ packages: integrity: sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==, } + html-escaper@2.0.2: + resolution: + { + integrity: sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==, + } + https-proxy-agent@5.0.1: resolution: { @@ -3112,6 +3173,27 @@ packages: integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==, } + istanbul-lib-coverage@3.2.2: + resolution: + { + integrity: sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg==, + } + engines: { node: ">=8" } + + istanbul-lib-report@3.0.1: + resolution: + { + integrity: sha512-GCfE1mtsHGOELCU8e/Z7YWzpmybrx/+dSTfLrvY8qRmaY6zXTKWn6WQIjaAFw069icm6GVMNkgu0NzI4iPZUNw==, + } + engines: { node: ">=10" } + + istanbul-reports@3.1.7: + resolution: + { + integrity: sha512-BewmUXImeuRk2YY0PVbxgKAysvhRPUQE0h5QRM++nVWyubKGV0l8qQ5op8+B2DOmwSe63Jivj0BjkPQVf8fP5g==, + } + engines: { node: ">=8" } + jackspeak@2.3.6: resolution: { @@ -3426,6 +3508,13 @@ packages: } engines: { node: ">=8" } + make-dir@4.0.0: + resolution: + { + integrity: sha512-hXdUTZYIVOt1Ex//jAQi+wTZZpUpwBj/0QsOzqegb3rGMMeJiSEu5xLHnYfBrRV4RH2+OCSOO95Is/7x1WJ4bw==, + } + engines: { node: ">=10" } + map-obj@1.0.1: resolution: { @@ -4669,6 +4758,13 @@ packages: } engines: { node: ">=8" } + test-exclude@6.0.0: + resolution: + { + integrity: sha512-cAGWPIyOHU6zlmg88jwm7VRyXnMN7iV68OGAbYDk/Mh/xC/pzVPlQtY6ngoIH/5/tciuhGfvESU8GrHrcxD56w==, + } + engines: { node: ">=8" } + text-extensions@2.4.0: resolution: { @@ -4877,6 +4973,13 @@ packages: integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==, } + v8-to-istanbul@9.2.0: + resolution: + { + integrity: sha512-/EH/sDgxU2eGxajKdwLCDmQ4FWq+kpi3uCmBGpw1xJtnAxEjlD8j8PEiGWpCIMIs3ciNAgH0d3TTJiUkYzyZjA==, + } + engines: { node: ">=10.12.0" } + validate-npm-package-license@3.0.4: resolution: { @@ -5136,6 +5239,8 @@ snapshots: dependencies: regenerator-runtime: 0.14.1 + "@bcoe/v8-coverage@0.2.3": {} + "@changesets/apply-release-plan@7.0.0": dependencies: "@babel/runtime": 7.24.4 @@ -5507,6 +5612,17 @@ snapshots: dependencies: minipass: 7.0.4 + "@istanbuljs/schema@0.1.3": {} + + "@jridgewell/resolve-uri@3.1.2": {} + + "@jridgewell/sourcemap-codec@1.4.15": {} + + "@jridgewell/trace-mapping@0.3.25": + dependencies: + "@jridgewell/resolve-uri": 3.1.2 + "@jridgewell/sourcemap-codec": 1.4.15 + "@lit-labs/observers@2.0.2": dependencies: "@lit/reactive-element": 2.0.4 @@ -5919,6 +6035,8 @@ snapshots: "@types/estree@1.0.5": {} + "@types/istanbul-lib-coverage@2.0.6": {} + "@types/minimist@1.2.5": {} "@types/node@12.20.55": {} @@ -6138,6 +6256,20 @@ snapshots: dependencies: streamsearch: 1.1.0 + c8@9.1.0: + dependencies: + "@bcoe/v8-coverage": 0.2.3 + "@istanbuljs/schema": 0.1.3 + find-up: 5.0.0 + foreground-child: 3.1.1 + istanbul-lib-coverage: 3.2.2 + istanbul-lib-report: 3.0.1 + istanbul-reports: 3.1.7 + test-exclude: 6.0.0 + v8-to-istanbul: 9.2.0 + yargs: 17.7.2 + yargs-parser: 21.1.1 + call-bind@1.0.7: dependencies: es-define-property: 1.0.0 @@ -6323,6 +6455,8 @@ snapshots: meow: 12.1.1 split2: 4.2.0 + convert-source-map@2.0.0: {} + convert-to-spaces@2.0.1: {} cosmiconfig-typescript-loader@5.0.0(@types/node@20.12.7)(cosmiconfig@9.0.0(typescript@5.4.5))(typescript@5.4.5): @@ -6842,6 +6976,8 @@ snapshots: hosted-git-info@2.8.9: {} + html-escaper@2.0.2: {} + https-proxy-agent@5.0.1: dependencies: agent-base: 6.0.2 @@ -6996,6 +7132,19 @@ snapshots: isexe@2.0.0: {} + istanbul-lib-coverage@3.2.2: {} + + istanbul-lib-report@3.0.1: + dependencies: + istanbul-lib-coverage: 3.2.2 + make-dir: 4.0.0 + supports-color: 7.2.0 + + istanbul-reports@3.1.7: + dependencies: + html-escaper: 2.0.2 + istanbul-lib-report: 3.0.1 + jackspeak@2.3.6: dependencies: "@isaacs/cliui": 8.0.2 @@ -7175,6 +7324,10 @@ snapshots: dependencies: semver: 6.3.1 + make-dir@4.0.0: + dependencies: + semver: 7.6.0 + map-obj@1.0.1: {} map-obj@4.3.0: {} @@ -7886,6 +8039,12 @@ snapshots: term-size@2.2.1: {} + test-exclude@6.0.0: + dependencies: + "@istanbuljs/schema": 0.1.3 + glob: 7.2.3 + minimatch: 3.1.2 + text-extensions@2.4.0: {} through@2.3.8: {} @@ -7997,6 +8156,12 @@ snapshots: util-deprecate@1.0.2: {} + v8-to-istanbul@9.2.0: + dependencies: + "@jridgewell/trace-mapping": 0.3.25 + "@types/istanbul-lib-coverage": 2.0.6 + convert-source-map: 2.0.0 + validate-npm-package-license@3.0.4: dependencies: spdx-correct: 3.2.0 From e8e93d8e8a37741a79ccecd8b08456043d5b3ff8 Mon Sep 17 00:00:00 2001 From: garthdb Date: Thu, 6 Jun 2024 17:26:09 -0600 Subject: [PATCH 2/2] ci: added code coverage reporter to ci --- .github/workflows/ci.yml | 8 ++++++++ packages/tokens/moon.yml | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d26a7894..41560d0d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,3 +16,11 @@ jobs: if: success() || failure() with: access-token: ${{ secrets.GH_TOKEN }} + - name: Code coverage for @adobe/spectrum-tokens + id: code-coverage + uses: barecheck/code-coverage-action@v1 + with: + barecheck-github-app-token: ${{ secrets.BARECHECK_GITHUB_APP_TOKEN }} + lcov-file: "./coverage/lcov.info" + app-name: "@adobe/spectrum-tokens" + workspace-path: "packages/tokens" diff --git a/packages/tokens/moon.yml b/packages/tokens/moon.yml index eee1562f..4f233b3f 100644 --- a/packages/tokens/moon.yml +++ b/packages/tokens/moon.yml @@ -76,6 +76,10 @@ tasks: command: - pnpm - c8 + - -r + - lcov + - -r + - text - ava platform: node inputs: