Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding code coverage reporting to Spectrum Tokens #352

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
},
"packageManager": "[email protected]",
"dependencies": {
"@changesets/changelog-github": "^0.5.0"
"@changesets/changelog-github": "^0.5.0",
"c8": "^9.1.0"
}
}
20 changes: 20 additions & 0 deletions packages/tokens/moon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,23 @@ tasks:
- --watch
local: true
platform: node
coverage:
command:
- pnpm
- c8
- -r
- lcov
- -r
- text
- ava
platform: node
inputs:
- "tasks/**/*"
- "schemas/**/*.{yaml,yml,json}"
- "manifest.json"
- "@globs(tests)"
- "@globs(sources)"
deps:
- ~:buildTokens
outputs:
- "coverage/"
14 changes: 6 additions & 8 deletions packages/tokens/tasks/buildManifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
13 changes: 7 additions & 6 deletions packages/tokens/test/checkManifest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
);
});
44 changes: 44 additions & 0 deletions packages/tokens/test/index.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
Loading
Loading