nodejs:js-mdict 的下载、安装、测试、build

js-mdict 项目的目录结构:js-mdict 项目教程

js-mdict 下载地址:  js-mdict-master.zip 先解压到 D:\Source\

js-mdict 6.0.2 用了 ts (TypeScript) 和 Jest,增加了应用开发的难度,因为先要了解 ts 和 Jest。

 参阅:测试与开发:Jest测试框架介绍

Jest 是最流行的 JavaScript 测试框架之一。测试人员广泛使用 Jest 对 JavaScript 函数进行单元测试。Jest 确保 JavaScript 应用程序具有生成正确输出的工作代码。它也非常直观,因为 Jest 语法非常可读。在使用 Jest 测试框架时,我们使用其功能丰富的 API,该 API 快速且用户友好。 由于 Jest 是开源的,因此对测试框架有很好的社区支持。

Win 10 运行 cmd
nvm list available
nodejs 版本选择,请 visit https://nodejs.org/en/download/releases
v22.13.1 , v20.18.2 , v18.20.6 任选一个

D:\nvm>nvm install 18.20.6
Downloading node.js version 18.20.6 (64-bit)...
Extracting node and npm...
Complete
npm v10.8.2 installed successfully.

nvm list
nvm use 18.20.6
node -v
npm -v
where yarn
cd \Source\js-mdict-master
dir

D:\Source\js-mdict-master> yarn install
yarn install v1.22.19
info No lockfile found.
[1/5] Validating package.json...
[2/5] Resolving packages...
warning @jest/globals > @jest/expect > jest-snapshot > @jest/transform > babel-plugin-istanbul > test-exclude > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning @jest/globals > @jest/expect > jest-snapshot > @jest/transform > babel-plugin-istanbul > test-exclude > glob > inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning jest > @jest/core > jest-config > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > jest-runtime > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > @jest/reporters > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning nyc > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning nyc > rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
warning nyc > istanbul-lib-processinfo > rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
warning nyc > spawn-wrap > rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
warning nyc > rimraf > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning shx > shelljs > glob@7.2.3: Glob versions prior to v9 are no longer supported
[3/5] Fetching packages...
[4/5] Linking dependencies...
[5/5] Building fresh packages...
success Saved lockfile.
Done in 64.70s.

yarn list
输出清单太长
\Source\js-mdict-master\ 生成目录 node_modules 大约70MB

npm show jest
jest@29.7.0 | MIT | deps: 4 | versions: 354
Delightful JavaScript Testing.
https://jestjs.io/

D:\Source\js-mdict-master> where jest
jest -verbose
D:\Source\js-mdict-master> npm run test

Test Suites: 27 failed, 3 passed, 30 total
Tests:       28 passed, 28 total
Snapshots:   0 total
Time:        32.163 s
Ran all test suites.
失败率大约50%,是因为./test/data/ 缺少用来测试的字典文件。


修改 \Source\js-mdict-master\test\max-000-baseline.test.ts

describe('Mdict', () => {
  describe('#lookup', () => {
    const mdict = new MDX('./test/data/oald7.mdx', {
修改为:const mdict = new MDX('/js/testdict/oale8.mdx', {

npm test baseline

      87 |     it("should be 'bad'", () => {
      88 |       const def = mdict.lookup('bad');

      at Object.<anonymous> (test/max-000-baseline.test.ts:85:60)

  ● Mdict › #lookup › should be 'bad'

    expect(received).toBeTruthy()

    Received: false

       95 |       expect(def.definition.length > 0).toBeTruthy();
       96 |       const expect_str = '<head><link rel="stylesheet" type="text/css" href="O7.css"/>';
    >  97 |       expect(def.definition.startsWith(expect_str.trim())).toBeTruthy();
          |                                                            ^
       98 |     });
       99 |   });
      100 | });

      at Object.<anonymous> (test/max-000-baseline.test.ts:97:60)

Test Suites: 1 failed, 1 total
Tests:       7 failed, 7 total
Snapshots:   0 total
Time:        3.105 s, estimated 14 s
Ran all test suites matching /baseline/i.

还是 test 失败。
dir \js\testdict\oale8.mdx
文件路径没有问题。


npm how to run typescript ?
npx -h
npm help exec

npx tsx -h
Node.js runtime enhanced with esbuild for loading TypeScript & ESM

如何使用 npm 运行 TypeScript 文件

为了能够使用 npm 来运行 TypeScript 文件,项目需配置好必要的开发环境。这涉及到创建并编辑几个重要的文件。

创建 package.json 和 tsconfig.json 文件

首先,确保项目的根目录下存在 package.json 文件。此文件定义了项目的元数据以及脚本命令

接着,设置 tsconfig.json 文件来指定编译选项。该文件告诉 TypeScript 编译器如何处理源码中的各种特性:

{
  "compileOnSave": true,
  "compilerOptions": {
    "esModuleInterop": true,
    "target": "ES6",
    "module": "CommonJS",
    "strict": true,
    "noFallthroughCasesInSwitch": true,
    "noUnusedLocals": true,

    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "sourceMap": true,
    "outDir": "dist",
    "lib": ["DOM", "ES2022"],
    "declaration": true,
    "paths": {
      "../src/*": ["./*"]
    }
  },
  "exclude": ["node_modules"],
  "include": ["src/**/*.ts", "tests/**/*.ts", "examples/**/*.ts"],
}

上述配置指定了目标 ECMAScript 版本、模块解析方式以及其他一些有用的标志位;同时设置了输出路径为 dist 并包含了所有位于 src/ 下的 .ts 文件作为输入。
打开 package.json 文件并向其中添加一个或多个方便调用的 script 脚本条目以便于后续快速启动编译流程:

"scripts": {
  "build": "tsc"
},

现在可以在终端里仅需输入简单的指令就可以触发整个工程下的所有 .ts 文件被转换成对应的 js 文件: npm run build 

D:\Source\js-mdict-master> npm -v
10.8.2

D:\Source\js-mdict-master> npm run build

> js-mdict@6.0.2 build
> npm run build-cjs && npm run build-esm


> js-mdict@6.0.2 build-cjs
> tsc --module commonjs --outDir dist/cjs/ && echo '{"type": "commonjs"}' > dist/cjs/package.json


> js-mdict@6.0.2 build-esm
> tsc  --module nodenext --moduleResolution nodenext --outDir dist/esm/ && echo '{"type": "module"}' > dist/esm/package.json

cd D:\Source\js-mdict-master
npx tsx ./example/oald7-example.ts
npx tsx ./example/oale8-mdd-example.ts

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/962330.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

深入理解MySQL 的 索引

索引是一种用来快速检索数据的一种结构, 索引使用的好不好关系到对应的数据库性能方面, 这篇文章我们就来详细的介绍一下数据库的索引。 1. 页面的大小: B 树索引是一种 Key-Value 结构&#xff0c;通过 Key 可以快速查找到对应的 Value。B 树索引由根页面&#xff08;Root&am…

vue之pinia组件的使用

1、搭建pinia环境 cnpm i pinia #安装pinia的组件 cnpm i nanoid #唯一id&#xff0c;相当于uuid cnpm install axios #网络请求组件 2、存储读取数据 存储数据 >> Count.ts文件import {defineStore} from piniaexport const useCountStore defineStore(count,{// a…

【MySQL — 数据库增删改查操作】深入解析MySQL的 Update 和 Delete 操作

1. 测试数据 mysql> select* from exam1; ----------------------------------------- | id | name | Chinese | Math | English | ----------------------------------------- | 1 | 唐三藏 | 67.0 | 98.0 | 56.0 | | 2 | 孙悟空 | 87.0 | 78.…

数据结构与算法之二叉树: LeetCode LCP 10. 二叉树任务调度 (Ts版)

二叉树任务调度 https://leetcode.cn/problems/er-cha-shu-ren-wu-diao-du/description/ 描述 任务调度优化是计算机性能优化的关键任务之一。在任务众多时&#xff0c;不同的调度策略可能会得到不同的总体执行时间&#xff0c;因此寻求一个最优的调度方案是非常有必要的 通…

JAVA 接口、抽象类的关系和用处 详细解析

接口 - Java教程 - 廖雪峰的官方网站 一个 抽象类 如果实现了一个接口&#xff0c;可以只选择实现接口中的 部分方法&#xff08;所有的方法都要有&#xff0c;可以一部分已经写具体&#xff0c;另一部分继续保留抽象&#xff09;&#xff0c;原因在于&#xff1a; 抽象类本身…

游戏引擎 Unity - Unity 启动(下载 Unity Editor、生成 Unity Personal Edition 许可证)

Unity Unity 首次发布于 2005 年&#xff0c;属于 Unity Technologies Unity 使用的开发技术有&#xff1a;C# Unity 的适用平台&#xff1a;PC、主机、移动设备、VR / AR、Web 等 Unity 的适用领域&#xff1a;开发中等画质中小型项目 Unity 适合初学者或需要快速上手的开…

【基于SprintBoot+Mybatis+Mysql】电脑商城项目之用户注册

&#x1f9f8;安清h&#xff1a;个人主页 &#x1f3a5;个人专栏&#xff1a;【计算机网络】【Mybatis篇】 &#x1f6a6;作者简介&#xff1a;一个有趣爱睡觉的intp&#xff0c;期待和更多人分享自己所学知识的真诚大学生。 目录 &#x1f3af;项目基本介绍 &#x1f6a6;项…

视频多模态模型——视频版ViT

大家好&#xff0c;这里是好评笔记&#xff0c;公主号&#xff1a;Goodnote&#xff0c;专栏文章私信限时Free。本文详细解读多模态论文《ViViT: A Video Vision Transformer》&#xff0c;2021由google 提出用于视频处理的视觉 Transformer 模型&#xff0c;在视频多模态领域有…

DeepSeek本地部署(windows)

一、下载并安装Ollama 1.下载Ollama Ollama官网:Ollama 点击"Download",会跳转至下载页面。 点击"Download for Windows"。会跳转Github进行下载,如下载速度过慢,可在浏览器安装GitHub加速插件。 2.安装Ollama 双击下载的安装文件,点击"Inst…

1 HDFS

1 HDFS 1. HDFS概述2. HDFS架构3. HDFS的特性4. HDFS 的命令行使用5. hdfs的高级使用命令6. HDFS 的 block 块和副本机制6.1 抽象为block块的好处6.2 块缓存6.3 hdfs的文件权限验证6.4 hdfs的副本因子 7. HDFS 文件写入过程&#xff08;非常重要&#xff09;7.1 网络拓扑概念7.…

全国31省空间权重矩阵(地理相邻空间、公路铁路地理距离空间、经济空间)权重矩阵数据-社科数据

中国31个省份空间权重矩阵-社科数据https://download.csdn.net/download/paofuluolijiang/90028597 https://download.csdn.net/download/paofuluolijiang/90028597 空间权重矩阵是反映个体在空间中依赖关系的矩阵&#xff0c;本数据计算全国31个省三种标准化处理的空间权重矩…

Flask框架基础入门教程_ezflaskapp

pip install flaskFlask 快速入门小应用 学东西&#xff0c;得先知道我们用这个东西&#xff0c;能做出来一个什么东西。 一个最小的基于flask 的应用可能看上去像下面这个样子&#xff1a; from flask import Flask app Flask(__name__)app.route(/) def hello_world():ret…

机器学习笔记——特征工程

大家好&#xff0c;这里是好评笔记&#xff0c;公主号&#xff1a;Goodnote&#xff0c;专栏文章私信限时Free。本笔记介绍机器学习中常见的特征工程方法、正则化方法和简要介绍强化学习。 文章目录 特征工程&#xff08;Fzeature Engineering&#xff09;1. 特征提取&#xff…

Cursor火出圈,未来程序员还有出路吗?

大家好&#xff0c;我是凡人。 今天我表弟家邻居的阿姨&#xff0c;托他问问我目前程序员还有前景吗&#xff0c;希望我根据十几年的经验给出点建议&#xff0c;看看程序员这条路未来能不能走。 一下子不知道该怎么回复他了&#xff0c;如果是三年前问我&#xff0c;肯定毫不…

如何移植ftp服务器到arm板子?

很多厂家提供的sdk&#xff0c;一般都不自带ftp服务器功能&#xff0c; 需要要发人员自己移植ftp服务器程序。 本文手把手教大家如何移植ftp server到arm板子。 环境 sdk&#xff1a;复旦微 Buildroot 2018.02.31. 解压 $ mkdir ~/vsftpd $ cp vsftpd-3.0.2.tar.gz ~/vs…

第5章 公共事件

HarmonyOS通过公共事件服务为应用程序提供订阅、发布、退订公共事件的能力。 5.1 公共事件概述 在应用里面&#xff0c;往往会有事件。比如&#xff0c;朋友给我手机发了一条信息&#xff0c;未读信息会在手机的通知栏给出提示。 5.1.1 公共事件的分类 公共事件&#xff08…

STM32 对射式红外传感器配置

这次用的是STM32F103的开发板&#xff08;这里面的exti.c文件没有how to use this driver 配置说明&#xff09; 对射式红外传感器 由一个红外发光二极管和NPN光电三极管组成&#xff0c;M3固定安装孔&#xff0c;有输出状态指示灯&#xff0c;输出高电平灯灭&#xff0c;输出…

【数据结构】(2)时间、空间复杂度

一、衡量算法好坏的指标 时间复杂度衡量算法的运行速度&#xff0c;空间复杂度衡量算法所需的额外空间。这些指标&#xff0c;是某场景中选择使用哪种数据结构和算法的依据。如今&#xff0c;计算机的存储器已经变得容易获得&#xff0c;所以不再太关注空间复杂度。 二、渐进表…

FBX SDK的使用:基础知识

Windows环境配置 FBX SDK安装后&#xff0c;目录下有三个文件夹&#xff1a; include 头文件lib 编译的二进制库&#xff0c;根据你项目的配置去包含相应的库samples 官方使用案列 动态链接 libfbxsdk.dll, libfbxsdk.lib是动态库&#xff0c;需要在配置属性->C/C->预…

Ansible自动化运维实战--yaml的使用和配置(7/8)

文章目录 一、YAML 基本语法1.1. 缩进1.2. 注释1.3. 列表1.4. 字典 二、Ansible 中 YAML 的应用2.1. Ansible 剧本&#xff08;Playbooks&#xff09;2.2. 变量定义2.3. 角色&#xff08;Roles&#xff09;2.4. Inventory 文件2.5. 数据类型2.6. 引用变量 在 Ansible 里&#x…