From abda23e07de3d0d254f3ae8c4c10b55e9fd5c96f Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 14 Aug 2023 19:24:27 -0700 Subject: [PATCH 1/3] add failing swc test folder. prefix failing swc and tsx test folder names wth FAIL --- README.md | 2 +- tests/tests-FAIL-swc/.swcrc | 13 ++++++++ tests/tests-FAIL-swc/esmock.node-swc.test.ts | 32 +++++++++++++++++++ tests/tests-FAIL-swc/package.json | 24 ++++++++++++++ .../tsconfig.json | 0 .../esmock.node.tsx.test.ts | 0 .../package.json | 0 tests/tests-FAIL-tsx/tsconfig.json | 8 +++++ 8 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 tests/tests-FAIL-swc/.swcrc create mode 100644 tests/tests-FAIL-swc/esmock.node-swc.test.ts create mode 100644 tests/tests-FAIL-swc/package.json rename tests/{tests-tsx => tests-FAIL-swc}/tsconfig.json (100%) rename tests/{tests-tsx => tests-FAIL-tsx}/esmock.node.tsx.test.ts (100%) rename tests/{tests-tsx => tests-FAIL-tsx}/package.json (100%) create mode 100644 tests/tests-FAIL-tsx/tsconfig.json 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..3be87dfd --- /dev/null +++ b/tests/tests-FAIL-swc/esmock.node-swc.test.ts @@ -0,0 +1,32 @@ +import test from 'node:test' +import assert from 'assert' +import esmock from 'esmock' + +test('should mock ts when using node-ts', async () => { + const main = await import('../local/main.ts') + // const main = await import('../local/mainUtil.js') + console.log(main) + // const main = await import('../local/main.js') + /* + const main = await esmock('../local/main.ts', { + path: { + basename: () => 'hellow' + } + })*/ + + // 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 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" + } +} From 2d776aaf6eb78827860974546c19c9bbb964b375 Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 14 Aug 2023 19:31:38 -0700 Subject: [PATCH 2/3] update changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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_ From 17b6cab851d619b8b81cfaf5af73263880c23d5e Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 14 Aug 2023 19:35:58 -0700 Subject: [PATCH 3/3] cleanup node-swc.test.ts file --- tests/tests-FAIL-swc/esmock.node-swc.test.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/tests/tests-FAIL-swc/esmock.node-swc.test.ts b/tests/tests-FAIL-swc/esmock.node-swc.test.ts index 3be87dfd..0248852f 100644 --- a/tests/tests-FAIL-swc/esmock.node-swc.test.ts +++ b/tests/tests-FAIL-swc/esmock.node-swc.test.ts @@ -2,22 +2,20 @@ 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 import('../local/main.ts') - // const main = await import('../local/mainUtil.js') - console.log(main) - // const main = await import('../local/main.js') - /* const main = await esmock('../local/main.ts', { path: { basename: () => 'hellow' } - })*/ + }) - // assert.strictEqual(main.pathbasenamewrap(), 'hellow') - assert.ok(true) + assert.strictEqual(main.pathbasenamewrap(), 'hellow') }) -/* + test('should mock pg', async () => { const main = await esmock('../local/main.ts', { 'pg': { @@ -29,4 +27,3 @@ test('should mock pg', async () => { assert.strictEqual(main.pgpoolwrap(), 'mocked pool') }) -*/