feat: init
This commit is contained in:
21
node_modules/mocked-exports/LICENSE
generated
vendored
Normal file
21
node_modules/mocked-exports/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Pooya Parsa <pooya@pi0.io>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
73
node_modules/mocked-exports/README.md
generated
vendored
Normal file
73
node_modules/mocked-exports/README.md
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
# mocked-exports
|
||||
|
||||
<!-- automd:badges codecov color=yellow -->
|
||||
|
||||
[](https://npmjs.com/package/mocked-exports)
|
||||
[](https://npm.chart.dev/mocked-exports)
|
||||
[](https://codecov.io/gh/unjs/mocked-exports)
|
||||
|
||||
<!-- /automd -->
|
||||
|
||||
Simple mocks (extracted from [unjs/unenv](https://github.com/unjs/unenv.git)).
|
||||
|
||||
Main usage of `mocked-exports` is to use them as **bundler aliases** to mock specific modules you don't want to end-up into your bundle.
|
||||
|
||||
```js
|
||||
// Exports a dynamic mock proxy function
|
||||
const proxy = require("mocked-exports/proxy");
|
||||
import proxy from "mocked-exports/proxy";
|
||||
import proxy from "mocked-exports/proxy/foo/bar/baz";
|
||||
|
||||
// Exports a no-op frozen function
|
||||
const noop = require("mocked-exports/noop");
|
||||
import noop from "mocked-exports/noop";
|
||||
|
||||
// Exports an empty frozen object
|
||||
const empty = require("mocked-exports/empty");
|
||||
import empty from "mocked-exports/empty";
|
||||
```
|
||||
|
||||
There are also extra variants of exports with `-mjs` or `-cjs` suffixes available if your mocking needs to force a specific format.
|
||||
|
||||
## Magic proxy
|
||||
|
||||
The `proxy` mock, is a nested deep proxy that tries to replace any dynamic nested access to an unknown object.
|
||||
|
||||
Examples: `proxy.foo.bar().xyz[1].then(() => {});`
|
||||
|
||||
For better debugging, you can use `proxy.__mock__('name')` to create a named instance.
|
||||
|
||||
## Development
|
||||
|
||||
<details>
|
||||
|
||||
<summary>local development</summary>
|
||||
|
||||
- Clone this repository
|
||||
- Install latest LTS version of [Node.js](https://nodejs.org/en/)
|
||||
- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`
|
||||
- Install dependencies using `pnpm install`
|
||||
- Run interactive tests using `pnpm dev`
|
||||
|
||||
</details>
|
||||
|
||||
## License
|
||||
|
||||
<!-- automd:contributors license=MIT -->
|
||||
|
||||
Published under the [MIT](https://github.com/unjs/mocked-exports/blob/main/LICENSE) license.
|
||||
Made by [community](https://github.com/unjs/mocked-exports/graphs/contributors) 💛
|
||||
<br><br>
|
||||
<a href="https://github.com/unjs/mocked-exports/graphs/contributors">
|
||||
<img src="https://contrib.rocks/image?repo=unjs/mocked-exports" />
|
||||
</a>
|
||||
|
||||
<!-- /automd -->
|
||||
|
||||
<!-- automd:with-automd -->
|
||||
|
||||
---
|
||||
|
||||
_🤖 auto updated with [automd](https://automd.unjs.io)_
|
||||
|
||||
<!-- /automd -->
|
||||
5
node_modules/mocked-exports/lib/empty.cjs
generated
vendored
Normal file
5
node_modules/mocked-exports/lib/empty.cjs
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = Object.freeze(
|
||||
Object.create(null, { __mock__: { get: () => true } }),
|
||||
);
|
||||
5
node_modules/mocked-exports/lib/empty.d.cts
generated
vendored
Normal file
5
node_modules/mocked-exports/lib/empty.d.cts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
declare const empty: {
|
||||
readonly __mock__: true;
|
||||
};
|
||||
|
||||
export = empty;
|
||||
5
node_modules/mocked-exports/lib/empty.d.mts
generated
vendored
Normal file
5
node_modules/mocked-exports/lib/empty.d.mts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
declare const empty: {
|
||||
readonly __mock__: true;
|
||||
};
|
||||
|
||||
export default empty;
|
||||
5
node_modules/mocked-exports/lib/empty.mjs
generated
vendored
Normal file
5
node_modules/mocked-exports/lib/empty.mjs
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export default Object.freeze(
|
||||
Object.create(null, {
|
||||
__mock__: { get: () => true },
|
||||
}),
|
||||
);
|
||||
10
node_modules/mocked-exports/lib/noop.cjs
generated
vendored
Normal file
10
node_modules/mocked-exports/lib/noop.cjs
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = Object.freeze(
|
||||
Object.assign(
|
||||
() => {
|
||||
/** noop */
|
||||
},
|
||||
{ __mock__: true },
|
||||
),
|
||||
);
|
||||
6
node_modules/mocked-exports/lib/noop.d.cts
generated
vendored
Normal file
6
node_modules/mocked-exports/lib/noop.d.cts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
declare const noop: {
|
||||
(): void;
|
||||
readonly __mock__: true;
|
||||
};
|
||||
|
||||
export = noop;
|
||||
6
node_modules/mocked-exports/lib/noop.d.mts
generated
vendored
Normal file
6
node_modules/mocked-exports/lib/noop.d.mts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
declare const noop: {
|
||||
(): void;
|
||||
readonly __mock__: true;
|
||||
};
|
||||
|
||||
export default noop;
|
||||
8
node_modules/mocked-exports/lib/noop.mjs
generated
vendored
Normal file
8
node_modules/mocked-exports/lib/noop.mjs
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
export default Object.freeze(
|
||||
Object.assign(
|
||||
() => {
|
||||
/** noop */
|
||||
},
|
||||
{ __mock__: true },
|
||||
),
|
||||
);
|
||||
46
node_modules/mocked-exports/lib/proxy.cjs
generated
vendored
Normal file
46
node_modules/mocked-exports/lib/proxy.cjs
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
function createMock(name, overrides = {}) {
|
||||
const proxyFn = function () {
|
||||
/** noop */
|
||||
};
|
||||
proxyFn.prototype.name = name;
|
||||
const props = {};
|
||||
const proxy = new Proxy(proxyFn, {
|
||||
get(_target, prop) {
|
||||
if (prop === "caller") {
|
||||
return null;
|
||||
}
|
||||
if (prop === "__createMock__") {
|
||||
return createMock;
|
||||
}
|
||||
if (prop === "__mock__") {
|
||||
return true;
|
||||
}
|
||||
if (prop in overrides) {
|
||||
return overrides[prop];
|
||||
}
|
||||
if (prop === "then") {
|
||||
return (fn) => Promise.resolve(fn());
|
||||
}
|
||||
if (prop === "catch") {
|
||||
return (_fn) => Promise.resolve();
|
||||
}
|
||||
if (prop === "finally") {
|
||||
return (fn) => Promise.resolve(fn());
|
||||
}
|
||||
return (props[prop] =
|
||||
props[prop] || createMock(`${name}.${prop.toString()}`));
|
||||
},
|
||||
apply(_target, _this, _args) {
|
||||
return createMock(`${name}()`);
|
||||
},
|
||||
construct(_target, _args, _newT) {
|
||||
return createMock(`[${name}]`);
|
||||
},
|
||||
enumerate() {
|
||||
return [];
|
||||
},
|
||||
});
|
||||
return proxy;
|
||||
}
|
||||
|
||||
module.exports = createMock("mock");
|
||||
24
node_modules/mocked-exports/lib/proxy.d.cts
generated
vendored
Normal file
24
node_modules/mocked-exports/lib/proxy.d.cts
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
/* eslint-disable */
|
||||
|
||||
interface _MockFunction<F> {
|
||||
(...args: any[]): F;
|
||||
new (...args: any[]): F;
|
||||
readonly __mock__: true;
|
||||
readonly __createMock__: typeof createMock;
|
||||
then<T>(fn: () => T): Promise<T>;
|
||||
catch(): Promise<void>;
|
||||
finally(fn: () => void): Promise<void>;
|
||||
}
|
||||
|
||||
declare function createMock(
|
||||
name: string,
|
||||
overrides?: Record<string, any>,
|
||||
): MockFunction;
|
||||
|
||||
type MockFunction = _MockFunction<MockFunction> & {
|
||||
readonly [key: string | symbol]: MockFunction;
|
||||
};
|
||||
|
||||
declare const mock: MockFunction;
|
||||
|
||||
export = mock;
|
||||
24
node_modules/mocked-exports/lib/proxy.d.mts
generated
vendored
Normal file
24
node_modules/mocked-exports/lib/proxy.d.mts
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
/* eslint-disable */
|
||||
|
||||
interface _MockFunction<F> {
|
||||
(...args: any[]): F;
|
||||
new (...args: any[]): F;
|
||||
readonly __mock__: true;
|
||||
readonly __createMock__: typeof createMock;
|
||||
then<T>(fn: () => T): Promise<T>;
|
||||
catch<T>(fn: () => T): Promise<void>;
|
||||
finally(fn: () => void): Promise<void>;
|
||||
}
|
||||
|
||||
declare function createMock(
|
||||
name: string,
|
||||
overrides?: Record<string, any>,
|
||||
): MockFunction;
|
||||
|
||||
type MockFunction = _MockFunction<MockFunction> & {
|
||||
readonly [key: string | symbol]: MockFunction;
|
||||
};
|
||||
|
||||
declare const mock: MockFunction;
|
||||
|
||||
export default mock;
|
||||
46
node_modules/mocked-exports/lib/proxy.mjs
generated
vendored
Normal file
46
node_modules/mocked-exports/lib/proxy.mjs
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
function createMock(name, overrides = {}) {
|
||||
const proxyFn = function () {
|
||||
/** noop */
|
||||
};
|
||||
proxyFn.prototype.name = name;
|
||||
const props = {};
|
||||
const proxy = new Proxy(proxyFn, {
|
||||
get(_target, prop) {
|
||||
if (prop === "caller") {
|
||||
return null;
|
||||
}
|
||||
if (prop === "__createMock__") {
|
||||
return createMock;
|
||||
}
|
||||
if (prop === "__mock__") {
|
||||
return true;
|
||||
}
|
||||
if (prop in overrides) {
|
||||
return overrides[prop];
|
||||
}
|
||||
if (prop === "then") {
|
||||
return (fn) => Promise.resolve(fn());
|
||||
}
|
||||
if (prop === "catch") {
|
||||
return (_fn) => Promise.resolve();
|
||||
}
|
||||
if (prop === "finally") {
|
||||
return (fn) => Promise.resolve(fn());
|
||||
}
|
||||
return (props[prop] =
|
||||
props[prop] || createMock(`${name}.${prop.toString()}`));
|
||||
},
|
||||
apply(_target, _this, _args) {
|
||||
return createMock(`${name}()`);
|
||||
},
|
||||
construct(_target, _args, _newT) {
|
||||
return createMock(`[${name}]`);
|
||||
},
|
||||
enumerate() {
|
||||
return [];
|
||||
},
|
||||
});
|
||||
return proxy;
|
||||
}
|
||||
|
||||
export default createMock("mock");
|
||||
59
node_modules/mocked-exports/package.json
generated
vendored
Normal file
59
node_modules/mocked-exports/package.json
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
{
|
||||
"name": "mocked-exports",
|
||||
"version": "0.1.1",
|
||||
"description": "",
|
||||
"repository": "unjs/mocked-exports",
|
||||
"license": "MIT",
|
||||
"sideEffects": false,
|
||||
"main": "./lib/proxy.cjs",
|
||||
"module": "./lib/proxy.mjs",
|
||||
"exports": {
|
||||
"./empty-cjs": "./lib/empty.cjs",
|
||||
"./empty-mjs": "./lib/empty.mjs",
|
||||
"./empty": {
|
||||
"import": "./lib/empty.mjs",
|
||||
"default": "./lib/empty.cjs"
|
||||
},
|
||||
"./noop-cjs": "./lib/noop.cjs",
|
||||
"./noop-mjs": "./lib/noop.mjs",
|
||||
"./noop": {
|
||||
"import": "./lib/noop.mjs",
|
||||
"default": "./lib/noop.cjs"
|
||||
},
|
||||
"./proxy-cjs": "./lib/proxy.cjs",
|
||||
"./proxy-cjs/*": "./lib/proxy.cjs",
|
||||
"./proxy-mjs": "./lib/proxy.mjs",
|
||||
"./proxy-mjs/*": "./lib/proxy.mjs",
|
||||
"./proxy": {
|
||||
"import": "./lib/proxy.mjs",
|
||||
"default": "./lib/proxy.cjs"
|
||||
},
|
||||
"./proxy/*": {
|
||||
"import": "./lib/proxy.mjs",
|
||||
"default": "./lib/proxy.cjs"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"scripts": {
|
||||
"dev": "vitest dev",
|
||||
"lint": "eslint . && prettier -c .",
|
||||
"lint:fix": "automd && eslint . --fix && prettier -w .",
|
||||
"release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
|
||||
"test": "pnpm lint && pnpm test:types && vitest run --coverage",
|
||||
"test:types": "tsc --noEmit --skipLibCheck"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.13.10",
|
||||
"@vitest/coverage-v8": "^3.0.8",
|
||||
"automd": "^0.4.0",
|
||||
"changelogen": "^0.6.1",
|
||||
"eslint": "^9.22.0",
|
||||
"eslint-config-unjs": "^0.4.2",
|
||||
"prettier": "^3.5.3",
|
||||
"typescript": "^5.8.2",
|
||||
"vitest": "^3.0.8"
|
||||
},
|
||||
"packageManager": "pnpm@10.6.1"
|
||||
}
|
||||
Reference in New Issue
Block a user