Skip to content

Commit

Permalink
Merge pull request #229 from iambumblehead/add-failing-swc-test-folder
Browse files Browse the repository at this point in the history
add failing swc test folder
  • Loading branch information
iambumblehead authored Aug 15, 2023
2 parents f824111 + 17b6cab commit 1126871
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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_
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
13 changes: 13 additions & 0 deletions tests/tests-FAIL-swc/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"test": ".*.ts$",
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true
},
"transform": null
},
"module": {
"type": "es6"
}
}
29 changes: 29 additions & 0 deletions tests/tests-FAIL-swc/esmock.node-swc.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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 esmock('../local/main.ts', {
path: {
basename: () => 'hellow'
}
})

assert.strictEqual(main.pathbasenamewrap(), 'hellow')
})

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')
})
24 changes: 24 additions & 0 deletions tests/tests-FAIL-swc/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions tests/tests-FAIL-tsx/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"esm": true,
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"module": "ESNext",
"moduleResolution": "node"
}
}

0 comments on commit 1126871

Please sign in to comment.