Skip to content

Commit

Permalink
ci: tests (#52)
Browse files Browse the repository at this point in the history
* tests

* figma utils unit tests

* fileUtils tests

* api tests

* testing on github

* api tests

* mocha migration

* created extractCategoryNames

* saveSvgs test

* generate fonts test

* generate definition files

* full fetchIcons test

* updating readme

* changing pr action

* removing keys from component sets

* removing basenode, adding pretest
  • Loading branch information
mikecoomber authored May 8, 2024
1 parent 568da55 commit e6abf3a
Show file tree
Hide file tree
Showing 45 changed files with 56,364 additions and 1,813 deletions.
7 changes: 3 additions & 4 deletions .github/fetch_icons/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import core from "@actions/core";
import { readFileSync, writeFileSync } from "fs";
import fetchIcons from "../../dist/scripts/fetchIcons.js";
import { ZDS_ASSETS_FILE_ID, ZDS_ASSETS_ICON_PAGE_NAME } from "../../figmaConfig.js";

const FIGMA_ICON_FILE_ID = "VQ7Aa3rDYB7mgpToI3bZ4D";
const FIGMA_ACCESS_TOKEN = core.getInput("figma-access-token") || process.env.FIGMA_ACCESS_TOKEN;

try {
const hashPath = "./.github/fetch_icons/hash.txt";
let oldHash = "";
const iconPageName = "🦓 Icons";

try {
oldHash = readFileSync(hashPath).toString();
Expand All @@ -18,8 +17,8 @@ try {

const newHash = await fetchIcons(
FIGMA_ACCESS_TOKEN,
FIGMA_ICON_FILE_ID,
iconPageName,
ZDS_ASSETS_FILE_ID,
ZDS_ASSETS_ICON_PAGE_NAME,
oldHash,
"outputs",
false
Expand Down
18 changes: 5 additions & 13 deletions .github/workflows/on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Pull request

on: pull_request

env:
FIGMA_ACCESS_TOKEN: ${{secrets.FIGMA_PERSONAL_ACCESS_TOKEN}}

jobs:
compile_js_modules:
name: Compile JS Modules
Expand All @@ -17,16 +20,5 @@ jobs:
ref: ${{github.head_ref}}
- name: Install packages
run: npm ci
- name: Compile Typescript files
run: tsc
- name: Check for modified files
id: git-check
run: echo "modified=$(if [ -n "$(git status --porcelain)" ]; then echo "true"; else echo "false"; fi)" >> $GITHUB_ENV
- name: Update changes in GitHub repository
if: env.modified == 'true'
run: |
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
git add -A
git commit -m '[automated commit] compiled JS modules'
git push
- name: Run tests
run: npm run test
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@

# production
/build
/dist

# firebase
/.firebase
firebase-debug.log
dist

# misc
.DS_Store
Expand All @@ -30,4 +26,4 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*

temp
temp
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,18 @@ These can be displayed using the `Icon` class built into Flutter.

> 🚧 **Note**: This does not work with all versions of node - tested and working with node 18.17.0
1. Initialize test values:
Before any tests are ran, make sure to create an `env.test.local` file with the value of `FIGMA_ACCESS_TOKEN` set to a Figma token which has access to the [ZDS Assets Figma](https://www.figma.com/file/VQ7Aa3rDYB7mgpToI3bZ4D/%F0%9F%A6%93-ZDS---Assets?type=design&mode=design&t=Ry8n3GUYc8uvxhMt-0) and the [Test Figma](https://www.figma.com/file/oIiGXVNKX4KjppcGxOEbZa/IconsTestPage?type=design&node-id=156-1674&mode=design&t=pBj7y8J7b6q906it-0).

`ts-node --files test/reset-values.ts`
To test the functionality of the scripts against a test Figma file with a subset of the icons, run

2. Select tests to run. Within `test/test.ts`, set the values of `functionsToTest` to true.
`npm run test`

3. Run tests
and inspect the outputs in test/outputs/test-figma.

`ts-node -files test/test.ts`
To run a full test against the ZDS Assets Figma, run

`npm run test:build`

and inspect the outputs in test/outputs/zds.

</details>
2 changes: 2 additions & 0 deletions figmaConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const ZDS_ASSETS_FILE_ID = "VQ7Aa3rDYB7mgpToI3bZ4D";
export const ZDS_ASSETS_ICON_PAGE_NAME = "🦓 Icons";
Loading

0 comments on commit e6abf3a

Please sign in to comment.