Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Add tests for options.cjs defaults behavior with all-false values.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Feb 3, 2019
1 parent 9c202e2 commit f8d60c7
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ function createOptionsCJS(value) {

const possibleNames = keys(value)

let allFalse = true
let useZeroConfig = true

for (const name of possibleNames) {
if (Reflect.has(defaultCJS, name)) {
Expand All @@ -430,8 +430,9 @@ function createOptionsCJS(value) {
if (isFlag(optionsValue)) {
const flagValue = !! optionsValue

if (flagValue) {
allFalse = false
if (flagValue &&
name !== "topLevelReturn") {
useZeroConfig = false
}

options[name] = flagValue
Expand All @@ -447,11 +448,11 @@ function createOptionsCJS(value) {
}
}

const source = allFalse
const defaultSource = useZeroConfig
? zeroConfigOptions.cjs
: defaultCJS

return defaults(options, source)
return defaults(options, defaultSource)
}

function findRoot(dirPath) {
Expand Down
6 changes: 6 additions & 0 deletions test/fixture/options-auto/inverse/.esmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
cjs: {
topLevelReturn: false
},
debug: true
}
1 change: 1 addition & 0 deletions test/fixture/options-auto/inverse/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default module
6 changes: 6 additions & 0 deletions test/fixture/options-auto/top-level-return/.esmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
cjs: {
topLevelReturn: true
},
debug: true
}
3 changes: 3 additions & 0 deletions test/fixture/options-auto/top-level-return/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
return exports
// eslint-disable-next-line no-unreachable
export {}
9 changes: 9 additions & 0 deletions test/misc-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,15 @@ describe("miscellaneous tests", () => {
]
.map((request) => import(request)))
)

it("should merge `options.cjs` of all `false` against zero-config defaults", () =>
Promise
.all([
"./fixture/options-auto/inverse",
"./fixture/options-auto/top-level-return"
]
.map((request) => import(request)))
)
})

describe("errors", () => {
Expand Down

0 comments on commit f8d60c7

Please sign in to comment.