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

reproduce not a valid path error #120

Merged
merged 3 commits into from
Aug 19, 2022
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# changelog

* 1.9.5
* support cjs packges that define [main relative directory only](https://github.com/iambumblehead/esmock/issues/119)
* 1.9.4 _Aug.15.2022_
* support core modules [w/ node: prefix](https://github.com/iambumblehead/resolvewithplus/pull/27), credit @gmahomarf
* 1.9.3 _Aug.13.2022_
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "esmock",
"type": "module",
"version": "1.9.4",
"version": "1.9.5",
"license": "ISC",
"readmeFilename": "README.md",
"description": "provides native ESM import mocking for unit tests",
Expand Down Expand Up @@ -54,7 +54,7 @@
"rewire"
],
"dependencies": {
"resolvewithplus": "^0.8.7"
"resolvewithplus": "^0.8.9"
},
"devDependencies": {
"c8": "^7.12.0",
Expand Down
4 changes: 3 additions & 1 deletion tests/local/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import path from 'path';
import pg from 'pg';

export default {
pathbasenamewrap: (n: any) => path.basename(n)
pathbasenamewrap: (n: any) => path.basename(n),
pgpoolwrap: (n: any) => pg.Pool(n)
};
1 change: 1 addition & 0 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"main": "package.json.esmock.export.js",
"dependencies": {
"pg": "^8.7.3",
"eslint": "^8.12.0",
"sinon": "^12.0.1",
"form-urlencoded": "^6.0.7",
Expand Down
14 changes: 13 additions & 1 deletion tests/tests-tsm/esmock.node-tsm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import test from 'node:test';
import assert from 'assert';
import esmock from 'esmock';

test('should mock ts when using node-ts', { only : true }, async () => {
test('should mock ts when using node-ts', async () => {
const main = await esmock('../local/main.ts', {
path: {
basename: () => 'hellow'
Expand All @@ -12,3 +12,15 @@ test('should mock ts when using node-ts', { only : true }, async () => {
assert.strictEqual( main.pathbasenamewrap(), 'hellow' );
assert.ok(true);
});

test('should mock pg', async () => {
const main = await esmock('../local/main.ts', {
'pg': {
Pool: (config:any) => {
return 'mocked pool'
}
}
});

assert.strictEqual( main.pgpoolwrap(), 'mocked pool' );
});
1 change: 1 addition & 0 deletions tests/tests-tsm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"dependencies": {
"tsm": "^2.2.2",
"esmock": "file:..",
"pg": "file:../node_modules/pg",
"sinon": "file:../node_modules/sinon",
"eslint": "file:../node_modules/eslint",
"form-urlencoded": "file:../node_modules/form-urlencoded",
Expand Down