diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d51cfce..b8601bc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ # changelog - * 2.3.7 _Aug.11.2023_ + * 2.3.7 _Aug.15.2023_ * [normalize package.json url](https://github.com/iambumblehead/esmock/pull/225) and [reduce loc for loader verification](https://github.com/iambumblehead/esmock/pull/226) * [small adjustments](https://github.com/iambumblehead/esmock/pull/228) reducing lines of code + * [clerical changes to some](https://github.com/iambumblehead/esmock/pull/229) test folders * 2.3.6 _Aug.07.2023_ * [resolve global mocking issues](https://github.com/iambumblehead/esmock/pull/224) when using mixed esm cjs import trees * 2.3.4 _Jul.30.2023_ diff --git a/README.md b/README.md index 3307c6db..3e7443b0 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ test('mock fetch, Date, setTimeout and any globals', async () => { }) }) - assert.deepEqual(await userCount(), 2) + assert.equal(await userCount(), 2) }) test('mocks "await import()" using esmock.p', async () => { diff --git a/tests/tests-FAIL-swc/.swcrc b/tests/tests-FAIL-swc/.swcrc new file mode 100644 index 00000000..50720e11 --- /dev/null +++ b/tests/tests-FAIL-swc/.swcrc @@ -0,0 +1,13 @@ +{ + "test": ".*.ts$", + "jsc": { + "parser": { + "syntax": "typescript", + "decorators": true + }, + "transform": null + }, + "module": { + "type": "es6" + } +} diff --git a/tests/tests-FAIL-swc/esmock.node-swc.test.ts b/tests/tests-FAIL-swc/esmock.node-swc.test.ts new file mode 100644 index 00000000..0248852f --- /dev/null +++ b/tests/tests-FAIL-swc/esmock.node-swc.test.ts @@ -0,0 +1,29 @@ +import test from 'node:test' +import assert from 'assert' +import esmock from 'esmock' + +// ⚠ https://github.com/swc-project/swc-node/issues/710 +// swc tests fail when encountering typescript syntax +// when the typescript sytax are removed, tests pass + +test('should mock ts when using node-ts', async () => { + const main = await esmock('../local/main.ts', { + path: { + basename: () => 'hellow' + } + }) + + assert.strictEqual(main.pathbasenamewrap(), 'hellow') +}) + +test('should mock pg', async () => { + const main = await esmock('../local/main.ts', { + 'pg': { + Pool: (config:any) => { + return config || 'mocked pool' + } + } + }) + + assert.strictEqual(main.pgpoolwrap(), 'mocked pool') +}) diff --git a/tests/tests-FAIL-swc/package.json b/tests/tests-FAIL-swc/package.json new file mode 100644 index 00000000..29e54851 --- /dev/null +++ b/tests/tests-FAIL-swc/package.json @@ -0,0 +1,24 @@ +{ + "type": "module", + "description": "esmock unit tests, tsm with node native runner", + "repository": { + "type": "git", + "url": "https://github.com/iambumblehead/esmock.git" + }, + "dependencies": { + "@swc-node/register": "1.6.6", + "esmock": "file:..", + "pg": "file:../node_modules/pg", + "sinon": "file:../node_modules/sinon", + "eslint": "file:../node_modules/eslint", + "form-urlencoded": "file:../node_modules/form-urlencoded", + "babelGeneratedDoubleDefault": "file:../local/babelGeneratedDoubleDefault" + }, + "scripts": { + "test:metaresolve": "node --experimental-import-meta-resolve --loader=@swc-node/register/esm --loader=esmock --test esmock.node-swc.test.ts", + "test:nometaresolve": "node --loader=@swc-node/register/esm --loader=esmock --test esmock.node-swc.test.ts", + "test": "npm run test:metaresolve && npm run test:nometaresolve", + "test": "SWCRC=true node --loader=@swc-node/register/esm --loader=esmock --test esmock.node-swc.test.ts", + "note": "⚠ https://github.com/swc-project/swc-node/issues/710" + } +} diff --git a/tests/tests-tsx/tsconfig.json b/tests/tests-FAIL-swc/tsconfig.json similarity index 100% rename from tests/tests-tsx/tsconfig.json rename to tests/tests-FAIL-swc/tsconfig.json diff --git a/tests/tests-tsx/esmock.node.tsx.test.ts b/tests/tests-FAIL-tsx/esmock.node.tsx.test.ts similarity index 100% rename from tests/tests-tsx/esmock.node.tsx.test.ts rename to tests/tests-FAIL-tsx/esmock.node.tsx.test.ts diff --git a/tests/tests-tsx/package.json b/tests/tests-FAIL-tsx/package.json similarity index 100% rename from tests/tests-tsx/package.json rename to tests/tests-FAIL-tsx/package.json diff --git a/tests/tests-FAIL-tsx/tsconfig.json b/tests/tests-FAIL-tsx/tsconfig.json new file mode 100644 index 00000000..5b17f4eb --- /dev/null +++ b/tests/tests-FAIL-tsx/tsconfig.json @@ -0,0 +1,8 @@ +{ + "esm": true, + "compilerOptions": { + "allowSyntheticDefaultImports": true, + "module": "ESNext", + "moduleResolution": "node" + } +}