Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support cjs and esm both by tshy #2

Merged
merged 4 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": [
"eslint-config-egg/typescript",
"eslint-config-egg/lib/rules/enforce-node-prefix"
]
}
16 changes: 16 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
Job:
name: Node.js
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
version: '18.19.0, 18, 20, 22, 23'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
23 changes: 23 additions & 0 deletions .github/workflows/pkg.pr.new.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Publish Any Commit
on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: npm install

- name: Build
run: npm run prepublishOnly --if-present

- run: npx pkg-pr-new publish
13 changes: 13 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Release

on:
push:
branches: [ master ]

jobs:
release:
name: Node.js
uses: node-modules/github-actions/.github/workflows/node-release.yml@master
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
node_modules
.tshy*
.eslintcache
dist
coverage
package-lock.json
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

File renamed without changes.
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (C) 2012 by fent
Copyright (C) 2024 - present node-modules

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
42 changes: 29 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
# muk-prop.js
# @cnpmjs/muk-prop

[![Build Status](https://secure.travis-ci.org/fent/muk-prop.js.svg)](http://travis-ci.org/fent/muk-prop.js)
[![Dependency Status](https://david-dm.org/fent/muk-prop.js.svg)](https://david-dm.org/fent/muk-prop.js)
[![codecov](https://codecov.io/gh/fent/muk-prop.js/branch/master/graph/badge.svg)](https://codecov.io/gh/fent/muk-prop.js)
[![NPM version][npm-image]][npm-url]
[![Node.js CI](https://github.com/node-modules/muk-prop.js/actions/workflows/nodejs.yml/badge.svg)](https://github.com/node-modules/muk-prop.js/actions/workflows/nodejs.yml)
[![codecov](https://codecov.io/gh/node-modules/muk-prop.js/graph/badge.svg?token=YuWQxJfyk2)](https://codecov.io/gh/node-modules/muk-prop.js)
[![npm download][download-image]][download-url]
[![Node.js Version](https://img.shields.io/node/v/@cnpmjs/muk-prop.svg?style=flat)](https://nodejs.org/en/download/)

[npm-image]: https://img.shields.io/npm/v/@cnpmjs/muk-prop.svg?style=flat-square
[npm-url]: https://npmjs.org/package/@cnpmjs/muk-prop
[download-image]: https://img.shields.io/npm/dm/@cnpmjs/muk-prop.svg?style=flat-square
[download-url]: https://npmjs.org/package/@cnpmjs/muk-prop

![muk](muk.gif)

# Usage
## Usage

Object method mocking.

```js
const fs = require('fs');
const muk = require('muk-prop');
const { muk } = require('@cnpmjs/muk-prop');

muk(fs, 'readFile', (path, callback) => {
process.nextTick(callback.bind(null, null, 'file contents here'));
Expand All @@ -22,7 +29,7 @@ muk(fs, 'readFile', (path, callback) => {
Object props mocking with setter/getter.

```js
const muk = require('muk-prop');
const { muk } = require('@cnpmjs/muk-prop');

const obj = { _a: 1 };
muk(obj, 'a', {
Expand All @@ -37,28 +44,37 @@ console.log(obj.a); // 4
Check if member has been mocked.

```js
muk.isMocked(fs, 'readFile'); // true
const { isMocked } = require('@cnpmjs/muk-prop');

isMocked(fs, 'readFile'); // true
```

Restore all mocked methods/props after tests.

```js
muk.restore();
const { restore } = require('@cnpmjs/muk-prop');

fs.readFile(file, (err, data) => {
// will actually read from `file`
});
```

## Install

# Install

npm install muk-prop
```bash
npm install @cnpmjs/muk-prop
```

## Tests

# Tests
Tests are written with [mocha](https://mochajs.org)

```bash
npm test
```

## Contributors

[![Contributors](https://contrib.rocks/image?repo=node-modules/muk-prop.js)](https://github.com/node-modules/muk-prop.js/graphs/contributors)

Made with [contributors-img](https://contrib.rocks).
Loading
Loading