Skip to content

Commit

Permalink
add tests for default import export and variable default export
Browse files Browse the repository at this point in the history
  • Loading branch information
khanayan123 committed Dec 15, 2023
1 parent 977019a commit 8b45998
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/fixtures/fn-default-export.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function () {
return 1
}
2 changes: 2 additions & 0 deletions test/fixtures/import-default-export.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import fnDefaultExport from "./fn-default-export.mjs";
export default fnDefaultExport
5 changes: 5 additions & 0 deletions test/fixtures/variable-default-export.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const temp = function () {
return 1
}

export default temp
21 changes: 21 additions & 0 deletions test/hook/default-export.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Hook from '../../index.js'
import defaultImportExport from '../fixtures/import-default-export.mjs'
import varDefaultExport from '../fixtures/variable-default-export.mjs'
import { strictEqual } from 'assert'

Hook((exports, name) => {
if (name.match(/import-default-export\.m?js/)) {
const orig = exports.default
exports.default = function () {
return orig() + 1
}
} else if (name.match(/variable-default-export\.m?js/)) {
const orig2 = exports.default
exports.default = function () {
return orig2() + 1
}
}
})

strictEqual(defaultImportExport(), 2)
strictEqual(varDefaultExport(), 2)

0 comments on commit 8b45998

Please sign in to comment.