{"id":18938229,"url":"https://github.com/wechat-miniprogram/miniprogram-simulate","last_synced_at":"2025-10-23T17:11:08.849Z","repository":{"id":33628875,"uuid":"158793883","full_name":"wechat-miniprogram/miniprogram-simulate","owner":"wechat-miniprogram","description":"小程序自定义组件测试工具集","archived":false,"fork":false,"pushed_at":"2025-03-10T03:08:45.000Z","size":3536,"stargazers_count":510,"open_issues_count":10,"forks_count":66,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-04-19T19:52:16.252Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wechat-miniprogram.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null}},"created_at":"2018-11-23T07:06:35.000Z","updated_at":"2025-04-01T11:46:09.000Z","dependencies_parsed_at":"2023-01-15T01:45:38.307Z","dependency_job_id":"528a97ec-4f90-4184-b710-cc7063f6de32","html_url":"https://github.com/wechat-miniprogram/miniprogram-simulate","commit_stats":{"total_commits":165,"total_committers":11,"mean_commits":15.0,"dds":0.2545454545454545,"last_synced_commit":"612228207e57cddbf3647d42774c4bfcc3e1d301"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wechat-miniprogram%2Fminiprogram-simulate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wechat-miniprogram%2Fminiprogram-simulate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wechat-miniprogram%2Fminiprogram-simulate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wechat-miniprogram%2Fminiprogram-simulate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wechat-miniprogram","download_url":"https://codeload.github.com/wechat-miniprogram/miniprogram-simulate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254453651,"owners_count":22073617,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T12:13:46.040Z","updated_at":"2025-10-23T17:11:03.816Z","avatar_url":"https://github.com/wechat-miniprogram.png","language":"JavaScript","readme":"# miniprogram-simulate\n\n[![](https://img.shields.io/npm/v/miniprogram-simulate.svg?style=flat)](https://www.npmjs.com/package/miniprogram-simulate)\n[![](https://github.com/wechat-miniprogram/miniprogram-simulate/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/wechat-miniprogram/miniprogram-simulate/actions/workflows/ci.yml?query=branch%3Amaster+)\n[![](https://img.shields.io/github/license/wechat-miniprogram/miniprogram-simulate.svg)](https://github.com/wechat-miniprogram/miniprogram-simulate/blob/master/LICENSE)\n[![](https://img.shields.io/codecov/c/github/wechat-miniprogram/miniprogram-simulate.svg)](https://app.codecov.io/gh/wechat-miniprogram/miniprogram-simulate)\n\n## 介绍\n\n小程序自定义组件测试工具集。\n\n目前因为小程序独特的运行环境，所以对于小程序自定义组件的单元测试一直没有比较优雅的解决方案，此工具集就是为了解决此痛点而诞生的。将原本小程序自定义组件双线程分离运行的机制调整成单线程模拟运行，利用 dom 环境进行渲染，借此来完成整个自定义组件树的搭建。\n\n运行此工具集需要依赖 js 运行环境和 dom 环境，因此可以采用 jsdom + nodejs（如 jest），也可以采用真实浏览器环境（如 karma）。文档[使用简介](./docs/tutorial.md)中会提供简单的使用方式介绍。\n\n## 安装\n\n```\nnpm install --save-dev miniprogram-simulate\n```\n\n## 使用\n\n```js\nconst simulate = require('miniprogram-simulate')\n\ntest('test sth', () =\u003e {\n    const id = simulate.load('/components/comp/index') // 加载自定义组件\n    const comp = simulate.render(id) // 渲染自定义组件\n    \n    // 使用自定义组件封装实例 comp 对象来进行各种单元测试\n})\n```\n\n以上只是一个简单的例子，实际上这个工具集必须搭配 jest 或 jsdom/mocha 等测试框架来使用，更为详细的使用细节请参阅下述文档：\n\n* [使用简介](./docs/tutorial.md)\n* [接口文档](./docs/api.md)\n* [细节实现](./docs/detail.md)\n* [暂不支持特性](./docs/todo.md)\n* [更新日志](./docs/update.md)\n\n## 协议\n\n[MIT](./LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwechat-miniprogram%2Fminiprogram-simulate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwechat-miniprogram%2Fminiprogram-simulate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwechat-miniprogram%2Fminiprogram-simulate/lists"}