From 0fa673f7cd15badd91b592a4312d7f87369dd58b Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 5 Jul 2024 12:13:05 -0700 Subject: [PATCH 1/5] mv tests-FAIL-swc tests-swc --- tests/{tests-FAIL-swc => tests-swc}/.swcrc | 0 tests/{tests-FAIL-swc => tests-swc}/esmock.node-swc.test.ts | 0 tests/{tests-FAIL-swc => tests-swc}/package.json | 4 ++-- tests/{tests-FAIL-swc => tests-swc}/tsconfig.json | 0 4 files changed, 2 insertions(+), 2 deletions(-) rename tests/{tests-FAIL-swc => tests-swc}/.swcrc (100%) rename tests/{tests-FAIL-swc => tests-swc}/esmock.node-swc.test.ts (100%) rename tests/{tests-FAIL-swc => tests-swc}/package.json (88%) rename tests/{tests-FAIL-swc => tests-swc}/tsconfig.json (100%) diff --git a/tests/tests-FAIL-swc/.swcrc b/tests/tests-swc/.swcrc similarity index 100% rename from tests/tests-FAIL-swc/.swcrc rename to tests/tests-swc/.swcrc diff --git a/tests/tests-FAIL-swc/esmock.node-swc.test.ts b/tests/tests-swc/esmock.node-swc.test.ts similarity index 100% rename from tests/tests-FAIL-swc/esmock.node-swc.test.ts rename to tests/tests-swc/esmock.node-swc.test.ts diff --git a/tests/tests-FAIL-swc/package.json b/tests/tests-swc/package.json similarity index 88% rename from tests/tests-FAIL-swc/package.json rename to tests/tests-swc/package.json index a3ab6ab..a2fa578 100644 --- a/tests/tests-FAIL-swc/package.json +++ b/tests/tests-swc/package.json @@ -1,13 +1,13 @@ { "type": "module", - "description": "esmock unit tests, tsm with node native runner", + "description": "esmock unit tests, swc with node native runner", "repository": { "type": "git", "url": "git+https://github.com/iambumblehead/esmock.git" }, "dependencies": { "esmock": "file:..", - "@swc-node/register": "1.9.2" + "@swc-node/register": "1.10.2" }, "scripts": { "isloaderavailable": "node -e \"(([mj, mn]) => (+mj < 18 || (+mj === 20 && +mn < 6) || (+mj === 18 && +mn < 19)))(process.versions.node.split('.')) || process.exit(1)\"", diff --git a/tests/tests-FAIL-swc/tsconfig.json b/tests/tests-swc/tsconfig.json similarity index 100% rename from tests/tests-FAIL-swc/tsconfig.json rename to tests/tests-swc/tsconfig.json From c8f956f3107540e80e6e8182ea4e446acf2c4da9 Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 5 Jul 2024 12:40:25 -0700 Subject: [PATCH 2/5] add tests-swc to package.json test sequence --- tests/package.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/package.json b/tests/package.json index 93f52bd..6bd65bc 100644 --- a/tests/package.json +++ b/tests/package.json @@ -34,6 +34,7 @@ "isnodegt19": "node -e \"+process.versions.node.split('.')[0] > 19 || process.exit(1)\"", "isnodenight": "node -e \"process.versions.node.includes('night') || process.exit(1)\"", "install:esmock": "cd .. && npm install", + "install:test-swc": "cd tests-swc && npm install", "install:test-ava": "cd tests-ava && npm install", "install:test-uvu": "cd tests-uvu && npm install", "install:test-tsm": "cd tests-tsm && npm install", @@ -51,6 +52,7 @@ "test:test-mocha": "cd tests-mocha && npm test", "test:test-ava": "cd tests-ava && npm test", "test:test-tsx": "cd tests-tsx && npm test", + "test:test-swc": "cd tests-swc && npm test", "test:node19-tsm": " cd tests-tsm && npm test", "test:node18-test-tsm": "npm run isnodenight || npm run test:node19-tsm", "test:node18-test-tsx": "cd tests-tsx && npm run test", From 3dd8fad28f06726ed40f655da4a405bcdd30e1db Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 13 Jul 2024 00:38:36 -0700 Subject: [PATCH 3/5] tests-swc dependencies add @swc/core and typescript, update @swc-node/register --- tests/tests-swc/package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/tests-swc/package.json b/tests/tests-swc/package.json index a2fa578..f584d1c 100644 --- a/tests/tests-swc/package.json +++ b/tests/tests-swc/package.json @@ -7,7 +7,9 @@ }, "dependencies": { "esmock": "file:..", - "@swc-node/register": "1.10.2" + "typescript": "^5.5.3", + "@swc-node/register": "^1.10.5", + "@swc/core": "^1.6.13" }, "scripts": { "isloaderavailable": "node -e \"(([mj, mn]) => (+mj < 18 || (+mj === 20 && +mn < 6) || (+mj === 18 && +mn < 19)))(process.versions.node.split('.')) || process.exit(1)\"", From 493997f02c23c41154e8acb523fe68d8da85d38e Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 16 Jul 2024 14:04:39 -0700 Subject: [PATCH 4/5] use latest swc to resolve errors --- .github/workflows/test.yml | 2 +- CHANGELOG.md | 3 +++ README.md | 2 -- package.json | 2 +- tests/tests-swc/esmock.node-swc.test.ts | 8 +++++++- tests/tests-swc/package.json | 2 +- 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5575bdd..e250fce 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: [18.x, 20.x, 22.1.x] + node-version: [18.x, 20.x, 22.x] os: [ubuntu-latest, windows-latest] steps: - uses: actions/checkout@v4 diff --git a/CHANGELOG.md b/CHANGELOG.md index 9436ae1..2e5e0ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # changelog + * 2.6.7 _Jul.16.2024_ + * [add swc tests and remove swc caution from README](https://github.com/iambumblehead/esmock/pull/309) thanks @Brooooooklyn + * [unpin node 22.1 at test CI](https://github.com/iambumblehead/esmock/pull/309) and use latest 22.x * 2.6.6 _Jun.15.2024_ * [add tsx tests and remove tsx caution from README](https://github.com/iambumblehead/esmock/pull/305) thanks @galexite * [pin node 22.1 at test CI](https://github.com/iambumblehead/esmock/pull/306) and ignore regressions in new node 22 diff --git a/README.md b/README.md index 757962f..6d92907 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,6 @@ _**Note: For versions of node prior to v20.6.0,** "--loader" command line arguments must be used with `esmock` as demonstrated [in the wiki.][4] Current versions of node do not require "--loader"._ -_**Note: TypeScript loader** `swc-node` is, at time of writing, **incompatible** with other loaders, including esmock._ - `esmock` has the below signature ```js await esmock( diff --git a/package.json b/package.json index eb29438..043ba3f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "esmock", "type": "module", - "version": "2.6.6", + "version": "2.6.7", "license": "ISC", "readmeFilename": "README.md", "description": "provides native ESM import and globals mocking for unit tests", diff --git a/tests/tests-swc/esmock.node-swc.test.ts b/tests/tests-swc/esmock.node-swc.test.ts index 2092bb7..9044967 100644 --- a/tests/tests-swc/esmock.node-swc.test.ts +++ b/tests/tests-swc/esmock.node-swc.test.ts @@ -17,11 +17,17 @@ test('should mock js when using swc', async () => { }) test('should mock ts when using swc', async () => { + const main = await import('../local/main-ts.ts') +/* const main = await esmock('../local/main-ts.ts', { path: { basename: () => 'hellow' } }) +*/ + assert.strictEqual( + main.default.pathbasenamewrap('/path/to/hellow'), + 'hellow') +// assert.strictEqual(main.pathbasenamewrap(), 'hellow') - assert.strictEqual(main.pathbasenamewrap(), 'hellow') }) \ No newline at end of file diff --git a/tests/tests-swc/package.json b/tests/tests-swc/package.json index f584d1c..e45070a 100644 --- a/tests/tests-swc/package.json +++ b/tests/tests-swc/package.json @@ -8,7 +8,7 @@ "dependencies": { "esmock": "file:..", "typescript": "^5.5.3", - "@swc-node/register": "^1.10.5", + "@swc-node/register": "^1.10.8", "@swc/core": "^1.6.13" }, "scripts": { From 4c58d6c14f285415f2685ea3d54776df71722acb Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 16 Jul 2024 14:08:43 -0700 Subject: [PATCH 5/5] update test to use esmock, to pass lint, to give credit --- tests/tests-swc/esmock.node-swc.test.ts | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/tests/tests-swc/esmock.node-swc.test.ts b/tests/tests-swc/esmock.node-swc.test.ts index 9044967..fb8149a 100644 --- a/tests/tests-swc/esmock.node-swc.test.ts +++ b/tests/tests-swc/esmock.node-swc.test.ts @@ -2,10 +2,7 @@ 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 - +// credit @Brooooooklyn https://github.com/swc-project/swc-node/issues/788 test('should mock js when using swc', async () => { const main = await esmock('../local/main.js', { path: { @@ -17,17 +14,11 @@ test('should mock js when using swc', async () => { }) test('should mock ts when using swc', async () => { - const main = await import('../local/main-ts.ts') -/* const main = await esmock('../local/main-ts.ts', { path: { basename: () => 'hellow' } }) -*/ - assert.strictEqual( - main.default.pathbasenamewrap('/path/to/hellow'), - 'hellow') -// assert.strictEqual(main.pathbasenamewrap(), 'hellow') + assert.strictEqual(main.pathbasenamewrap(), 'hellow') }) \ No newline at end of file