Skip to content

Commit

Permalink
update tests-FAIL-swc to newest swc call pattern. tests still fail
Browse files Browse the repository at this point in the history
  • Loading branch information
bumblehead committed Jun 15, 2024
1 parent 40b049e commit 0a0c995
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 30 deletions.
12 changes: 7 additions & 5 deletions tests/tests-FAIL-swc/.swcrc
Original file line number Diff line number Diff line change
@@ -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
}
16 changes: 7 additions & 9 deletions tests/tests-FAIL-swc/esmock.node-swc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand All @@ -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')
})
20 changes: 8 additions & 12 deletions tests/tests-FAIL-swc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
}
}
11 changes: 7 additions & 4 deletions tests/tests-FAIL-swc/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 0a0c995

Please sign in to comment.