Skip to content

Commit

Permalink
changes to make switching test-runner or transpiler easier
Browse files Browse the repository at this point in the history
  • Loading branch information
bumblehead committed Jul 11, 2023
1 parent b43d115 commit 9a0a6b0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
20 changes: 6 additions & 14 deletions tests/tests-ava-tsx/esmock.ava.tsx.test.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
// import test from 'node:test'
import test from 'ava'
import assert from 'assert'
import esmock from 'esmock'

test('should mock js when using tsx', async t => {
test('should mock js when using tsx', async () => {
const main = await esmock('../local/main.js', {
path: {
basename: () => 'hellow'
}
})

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

test.only('should mock ts when using tsx - unknown file extension', async t => {
test('should mock ts when using tsx - unknown file extension', async () => {
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')
assert.strictEqual(main.pathbasenamewrap(), 'hellow')
})
10 changes: 8 additions & 2 deletions tests/tests-ava-tsx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@
"dependencies": {
"ava": "^5.3.1",
"esmock": "file:..",
"tsx": "^3.12.7"
"tsx": "^3.12.7",
"ts-node": "^10.9.1"
},
"scripts": {
"test": "NODE_OPTIONS='--experimental-specifier-resolution=node --loader=tsx --loader=esmock' ava"
"test-node-ts-node": "node --loader=ts-node/esm --loader=esmock --test esmock.ava.tsx.test.ts",
"test-ava-ts-node": "NODE_OPTIONS='--loader=ts-node/esm --loader=esmock' ava *test.ts",
"test-node-tsx": "node --loader=tsx --loader=esmock --test esmock.ava.tsx.test.ts",
"test-ava-tsx": "NODE_OPTIONS='--loader=tsx --loader=esmock' ava *test.ts",
"test": "npm run test-ava-ts-node"
},
"ava": {
"failWithoutAssertions": false,
"extensions": {
"ts": "module"
}
Expand Down

0 comments on commit 9a0a6b0

Please sign in to comment.