From 0a0c995582c0d242ebcabcbd5f003e855d06db96 Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 15 Jun 2024 13:16:02 -0700 Subject: [PATCH 1/2] update tests-FAIL-swc to newest swc call pattern. tests still fail --- tests/tests-FAIL-swc/.swcrc | 12 +++++++----- tests/tests-FAIL-swc/esmock.node-swc.test.ts | 16 +++++++--------- tests/tests-FAIL-swc/package.json | 20 ++++++++------------ tests/tests-FAIL-swc/tsconfig.json | 11 +++++++---- 4 files changed, 29 insertions(+), 30 deletions(-) diff --git a/tests/tests-FAIL-swc/.swcrc b/tests/tests-FAIL-swc/.swcrc index 50720e11..78a5dc9c 100644 --- a/tests/tests-FAIL-swc/.swcrc +++ b/tests/tests-FAIL-swc/.swcrc @@ -1,13 +1,15 @@ { + "$schema": "https://swc.rs/schema.json", "test": ".*.ts$", "jsc": { "parser": { "syntax": "typescript", - "decorators": true + "importMeta": true }, - "transform": null + "target": "es2022", + "experimental": { + "keepImportAssertions": true + } }, - "module": { - "type": "es6" - } + "isModule": true } diff --git a/tests/tests-FAIL-swc/esmock.node-swc.test.ts b/tests/tests-FAIL-swc/esmock.node-swc.test.ts index 9b739f08..2092bb7e 100644 --- a/tests/tests-FAIL-swc/esmock.node-swc.test.ts +++ b/tests/tests-FAIL-swc/esmock.node-swc.test.ts @@ -6,8 +6,8 @@ import esmock from 'esmock' // 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.ts', { +test('should mock js when using swc', async () => { + const main = await esmock('../local/main.js', { path: { basename: () => 'hellow' } @@ -16,14 +16,12 @@ test('should mock ts when using node-ts', async () => { assert.strictEqual(main.pathbasenamewrap(), 'hellow') }) -test('should mock pg', async () => { +test('should mock ts when using swc', async () => { const main = await esmock('../local/main-ts.ts', { - 'pg': { - Pool: (config:any) => { - return config || 'mocked pool' - } + path: { + basename: () => 'hellow' } }) - assert.strictEqual(main.pgpoolwrap(), 'mocked pool') -}) + assert.strictEqual(main.pathbasenamewrap(), 'hellow') +}) \ No newline at end of file diff --git a/tests/tests-FAIL-swc/package.json b/tests/tests-FAIL-swc/package.json index 29e54851..a3ab6ab0 100644 --- a/tests/tests-FAIL-swc/package.json +++ b/tests/tests-FAIL-swc/package.json @@ -3,22 +3,18 @@ "description": "esmock unit tests, tsm with node native runner", "repository": { "type": "git", - "url": "https://github.com/iambumblehead/esmock.git" + "url": "git+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" + "@swc-node/register": "1.9.2" }, "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" + "isloaderavailable": "node -e \"(([mj, mn]) => (+mj < 18 || (+mj === 20 && +mn < 6) || (+mj === 18 && +mn < 19)))(process.versions.node.split('.')) || process.exit(1)\"", + "test:loader": "echo not-configured", + "test:current": "node --import @swc-node/register/esm-register --test esmock.node-swc.test.ts", + "test": "npm run isloaderavailable && npm run test:loader || npm run test:current", + "note": "⚠ https://github.com/swc-project/swc-node/issues/710", + "status": "swc error: SyntaxError: Unexpected identifier 'MockMap'" } } diff --git a/tests/tests-FAIL-swc/tsconfig.json b/tests/tests-FAIL-swc/tsconfig.json index 5b17f4eb..6f146fee 100644 --- a/tests/tests-FAIL-swc/tsconfig.json +++ b/tests/tests-FAIL-swc/tsconfig.json @@ -1,8 +1,11 @@ { - "esm": true, + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "@tsconfig/node20/tsconfig.json", "compilerOptions": { - "allowSyntheticDefaultImports": true, - "module": "ESNext", - "moduleResolution": "node" + "lib": ["es2023"], + "module": "NodeNext", + "moduleResolution": "NodeNext", + "target": "esnext", + "resolveJsonModule": true } } From 6b0907ce5ff088acf3e8abf885c5bf6e05b00ced Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 15 Jun 2024 13:21:26 -0700 Subject: [PATCH 2/2] update tsconfig.json --- tests/tests-FAIL-swc/tsconfig.json | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/tests-FAIL-swc/tsconfig.json b/tests/tests-FAIL-swc/tsconfig.json index 6f146fee..266f26f0 100644 --- a/tests/tests-FAIL-swc/tsconfig.json +++ b/tests/tests-FAIL-swc/tsconfig.json @@ -1,11 +1,9 @@ { - "$schema": "https://json.schemastore.org/tsconfig", - "extends": "@tsconfig/node20/tsconfig.json", + "esm": true, "compilerOptions": { - "lib": ["es2023"], - "module": "NodeNext", - "moduleResolution": "NodeNext", - "target": "esnext", - "resolveJsonModule": true + "allowSyntheticDefaultImports": true, + "module": "ESNext", + "moduleResolution": "node", + "lib": ["ES2015"] } }