Skip to content

Commit

Permalink
test4
Browse files Browse the repository at this point in the history
  • Loading branch information
yisibl committed Aug 8, 2023
1 parent 147a83c commit fc28e1b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ jobs:
with:
node-version: ${{ matrix.node }}
check-latest: true
shell: bash

- name: Install
uses: actions-rs/toolchain@v1
Expand Down Expand Up @@ -310,7 +309,6 @@ jobs:
node-version: ${{ matrix.node }}
check-latest: true
cache: yarn
shell: bash
- name: Cache NPM dependencies
uses: actions/cache@v3
with:
Expand Down Expand Up @@ -348,7 +346,6 @@ jobs:
node-version: ${{ matrix.node }}
check-latest: true
cache: yarn
shell: bash
- name: Cache NPM dependencies
uses: actions/cache@v3
with:
Expand Down Expand Up @@ -388,7 +385,6 @@ jobs:
with:
name: bindings-aarch64-unknown-linux-gnu
path: .
shell: bash
- name: List packages
run: ls -R .
shell: bash
Expand All @@ -410,6 +406,9 @@ jobs:
run: |
set -e
find /usr/share/fonts -name *.ttf
apk add fontconfig
fc-cache --force
fc-list :lang=en
ls -la
yarn test
test-linux-aarch64-musl-binding:
Expand All @@ -425,7 +424,6 @@ jobs:
with:
name: bindings-aarch64-unknown-linux-musl
path: .
shell: bash
- name: List packages
run: ls -R .
shell: bash
Expand All @@ -447,9 +445,9 @@ jobs:
run: |
set -e
find /usr/share/fonts -name *.ttf
# apk add fontconfig
# fc-cache --force
# fc-list :lang=en
apk add fontconfig
fc-cache --force
fc-list :lang=en
apk add nodejs npm yarn
yarn test
test-linux-arm-gnueabihf-binding:
Expand All @@ -472,7 +470,6 @@ jobs:
with:
name: bindings-armv7-unknown-linux-gnueabihf
path: .
shell: bash
- name: List packages
run: ls -R .
shell: bash
Expand All @@ -493,6 +490,9 @@ jobs:
run: |
set -e
find /usr/share/fonts -name *.ttf
apk add fontconfig
fc-cache --force
fc-list :lang=en
ls -la
yarn test
Expand Down
34 changes: 26 additions & 8 deletions __test__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PathLike, promises as fs, readdirSync } from 'fs'
import { PathLike, promises as fs, readdirSync, statSync } from 'fs'
import { join } from 'path'

import test from 'ava'
Expand Down Expand Up @@ -287,19 +287,37 @@ test.only('The defaultFontFamily is not found in the OS and needs to be fallback
return false
}
}
const path1 = require('path').join('/usr/share/fonts')
const isExists = await checkFileExists(path1)
console.info(`Node.js 开始读取字体目录 ${path1}`, isExists)
if (isExists) {
readdirSync(path1).forEach((file) => {
console.info(`获取到文件 ${file}`)

function find_files(directoryPath: PathLike) {
// 获取目录下的所有文件和子目录
const items = readdirSync(directoryPath)

// 遍历每个文件或子目录
items.forEach((item) => {
const itemPath = require('path').join(directoryPath, item)
const stats = statSync(itemPath)

if (stats.isFile()) {
// 处理文件
console.info('文件:', itemPath)
} else if (stats.isDirectory()) {
// 处理子目录,并递归遍历
find_files(itemPath)
}
})
}

const fontPath = require('path').join('/usr/share/fonts')
const isExists = await checkFileExists(fontPath)
console.info(`Node.js 开始读取字体目录 ${fontPath}`, isExists)
if (isExists) {
find_files(fontPath)
}

const resvg = new Resvg(svg, {
font: {
loadSystemFonts: true,
fontDirs: ['/usr/share/fonts/'], // 防止在 CI 的 Docker 环境找不到字体
// fontDirs: ['/usr/share/fonts/'], // 防止在 CI 的 Docker 环境找不到字体
defaultFontFamily: 'this-is-a-non-existent-font-family',
},
logLevel: 'debug',
Expand Down

0 comments on commit fc28e1b

Please sign in to comment.