Skip to content

Commit

Permalink
Merge pull request #307 from iambumblehead/enable-swc-tests
Browse files Browse the repository at this point in the history
update tests-FAIL-swc to newest swc call pattern. tests still fail
  • Loading branch information
iambumblehead authored Jun 15, 2024
2 parents 40b049e + 6b0907c commit b4567a5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 27 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'"
}
}
3 changes: 2 additions & 1 deletion tests/tests-FAIL-swc/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"module": "ESNext",
"moduleResolution": "node"
"moduleResolution": "node",
"lib": ["ES2015"]
}
}

0 comments on commit b4567a5

Please sign in to comment.