diff --git a/tests/local/mainUnique.ts b/tests/local/mainUnique.ts new file mode 100644 index 00000000..aeb80a38 --- /dev/null +++ b/tests/local/mainUnique.ts @@ -0,0 +1,7 @@ +import path from 'path' +import pg from 'pg' + +export default { + pathbasenamewrap: (n: any) => path.basename(n), + pgpoolwrap: (n: any) => pg.Pool(n) +} diff --git a/tests/tests-ava-tsx/esmock.ava.tsx.test.ts b/tests/tests-ava-tsx/esmock.ava.tsx.test.ts new file mode 100644 index 00000000..1cd5fe09 --- /dev/null +++ b/tests/tests-ava-tsx/esmock.ava.tsx.test.ts @@ -0,0 +1,32 @@ +import test from 'ava' +import esmock from 'esmock' + +test('should mock js when using tsx', async t => { + const main = await esmock('../local/main.js', { + path: { + basename: () => 'hellow' + } + }) + + t.is(main.pathbasenamewrap(), 'hellow') +}) + +test.failing('should mock ts when using tsx - unknown file extension', async t => { + const main = await esmock('../local/main.ts', { + path: { + basename: () => 'hellow' + } + }) + + t.is(main.pathbasenamewrap(), 'hellow') +}) + +test.failing('should mock ts when using tsx - invalid moduleId', async t => { + const main = await esmock('../local/mainUnique.js', { + path: { + basename: () => 'hellow' + } + }) + + t.is(main.pathbasenamewrap(), 'hellow') +}) diff --git a/tests/tests-ava-tsx/package.json b/tests/tests-ava-tsx/package.json new file mode 100644 index 00000000..65a7a7a3 --- /dev/null +++ b/tests/tests-ava-tsx/package.json @@ -0,0 +1,29 @@ +{ + "type": "module", + "description": "esmock unit tests, tsx with ava", + "repository": { + "type": "git", + "url": "https://github.com/iambumblehead/esmock.git" + }, + "dependencies": { + "ava": "^5.3.1", + "babelGeneratedDoubleDefault": "file:../local/babelGeneratedDoubleDefault", + "eslint": "file:../node_modules/eslint", + "esmock": "file:..", + "form-urlencoded": "file:../node_modules/form-urlencoded", + "sinon": "file:../node_modules/sinon", + "tsx": "^3.12.7" + }, + "scripts": { + "test": "ava" + }, + "ava": { + "extensions": { + "ts": "module" + }, + "nodeArguments": [ + "--loader=tsx", + "--loader=esmock" + ] + } +} diff --git a/tests/tests-ava-tsx/tsconfig.json b/tests/tests-ava-tsx/tsconfig.json new file mode 100644 index 00000000..5b17f4eb --- /dev/null +++ b/tests/tests-ava-tsx/tsconfig.json @@ -0,0 +1,8 @@ +{ + "esm": true, + "compilerOptions": { + "allowSyntheticDefaultImports": true, + "module": "ESNext", + "moduleResolution": "node" + } +}