From fc28e1b4ce04a1c6f83023fa00d796c032995cab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E4=B8=9D?= Date: Tue, 8 Aug 2023 21:14:31 +0800 Subject: [PATCH] test4 --- .github/workflows/CI.yaml | 18 +++++++++--------- __test__/index.spec.ts | 34 ++++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index cd6ba8dd..2888b176 100755 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -211,7 +211,6 @@ jobs: with: node-version: ${{ matrix.node }} check-latest: true - shell: bash - name: Install uses: actions-rs/toolchain@v1 @@ -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: @@ -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: @@ -388,7 +385,6 @@ jobs: with: name: bindings-aarch64-unknown-linux-gnu path: . - shell: bash - name: List packages run: ls -R . shell: bash @@ -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: @@ -425,7 +424,6 @@ jobs: with: name: bindings-aarch64-unknown-linux-musl path: . - shell: bash - name: List packages run: ls -R . shell: bash @@ -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: @@ -472,7 +470,6 @@ jobs: with: name: bindings-armv7-unknown-linux-gnueabihf path: . - shell: bash - name: List packages run: ls -R . shell: bash @@ -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 diff --git a/__test__/index.spec.ts b/__test__/index.spec.ts index 3dd2ce16..1716d206 100755 --- a/__test__/index.spec.ts +++ b/__test__/index.spec.ts @@ -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' @@ -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',