Skip to content

Commit c87bac8

Browse files
Brian M Huntclaude
authored andcommitted
Replace !isRealBrowser() with isHappyDom() across test guards
`if (!isRealBrowser()) return ctx.skip('happy-dom: reason')` was a double-negative detour — the check says "not a real browser" but the skip reason always starts with "happy-dom:". Say what we mean directly. All 24 guards now read: it('name', function (ctx: any) { if (isHappyDom()) return ctx.skip('happy-dom: reason') // body }) Also drops `isRealBrowser` and `isNode` from test-env.ts (neither had a real consumer — `isNode` was scaffolding for the deferred `cli-bun` project, and `isRealBrowser` was the double-negated wrapper of `isHappyDom`). When we bring back a node-env project we can add them back alongside the package.json runtime declaration scheme. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 2adf07c commit c87bac8

15 files changed

Lines changed: 41 additions & 51 deletions

File tree

builds/knockout/helpers/vitest-setup.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
import * as chai from 'chai'
22
import sinon from 'sinon'
3-
import { isHappyDom, isRealBrowser, isNode } from '../../../packages/utils/helpers/test-env.ts'
3+
import { isHappyDom } from '../../../packages/utils/helpers/test-env.ts'
44

55
// Set globals that builds/knockout specs and mocha-test-helpers.js expect
66
globalThis.chai = chai
77
globalThis.expect = chai.expect
88
globalThis.sinon = sinon
99

10-
// Test environment detectors — used inside test bodies like:
10+
// Test environment detector — used inside test bodies like:
1111
// it('name', function (ctx) {
12-
// if (!isRealBrowser()) return ctx.skip('happy-dom: reason')
12+
// if (isHappyDom()) return ctx.skip('happy-dom: reason')
1313
// // ...
1414
// })
1515
globalThis.isHappyDom = isHappyDom
16-
globalThis.isRealBrowser = isRealBrowser
17-
globalThis.isNode = isNode
1816

1917
// Load the knockout build (sets globalThis.ko)
2018
import '../dist/browser.min.js'

builds/knockout/spec/components/defaultLoaderBehaviors.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ describe('Components: Default loader', function () {
284284
})
285285

286286
it('Can be configured as the ID of a <textarea> element', function (ctx) {
287-
if (!isRealBrowser()) return ctx.skip('happy-dom: <textarea> content parsing differs')
287+
if (isHappyDom()) return ctx.skip('happy-dom: <textarea> content parsing differs')
288288
// Special case: the textarea's value should be interpreted as a markup string
289289
return testTemplateFromElement('<textarea id="my-textarea-elem">{0}</textarea>', 'my-textarea-elem')
290290
})
@@ -308,7 +308,7 @@ describe('Components: Default loader', function () {
308308
})
309309

310310
it('Can be configured as a <textarea> element instance', function (ctx) {
311-
if (!isRealBrowser()) return ctx.skip('happy-dom: <textarea> content parsing differs')
311+
if (isHappyDom()) return ctx.skip('happy-dom: <textarea> content parsing differs')
312312
// Special case: the textarea's value should be interpreted as a markup string
313313
return testTemplateFromElement('<textarea>{0}</textarea>', /* elementId */ null)
314314
})

builds/knockout/spec/defaultBindings/attrBehaviors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('Binding: Attr', function () {
1010
})
1111

1212
it('Should be able to set namespaced attribute values', function (ctx) {
13-
if (!isRealBrowser()) return ctx.skip('happy-dom: Element.lookupNamespaceURI not implemented')
13+
if (isHappyDom()) return ctx.skip('happy-dom: Element.lookupNamespaceURI not implemented')
1414
var model = { myValue: 'first value' }
1515
testNode.innerHTML = [
1616
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">',

builds/knockout/spec/defaultBindings/optionsBehaviors.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ describe('Binding: Options', function () {
128128
})
129129

130130
it('Should select caption by default and retain selection when adding multiple items', function (ctx) {
131-
if (!isRealBrowser()) return ctx.skip('happy-dom: <select> auto-selection semantics diverge')
131+
if (isHappyDom()) return ctx.skip('happy-dom: <select> auto-selection semantics diverge')
132132
// This test failed in IE<=8 without changes made in #1208
133133
testNode.innerHTML = '<select data-bind="options: filterValues, optionsCaption: \'foo\'">'
134134
var viewModel = {
@@ -147,7 +147,7 @@ describe('Binding: Options', function () {
147147
})
148148

149149
it('Should trigger a change event when the options selection is populated or changed by modifying the options data (single select)', function (ctx) {
150-
if (!isRealBrowser()) return ctx.skip('happy-dom: selectedIndex does not follow reordered <option>')
150+
if (isHappyDom()) return ctx.skip('happy-dom: selectedIndex does not follow reordered <option>')
151151
var observable = new ko.observableArray(['A', 'B', 'C']),
152152
changeHandlerFireCount = 0
153153
testNode.innerHTML = "<select data-bind='options:myValues'></select>"
@@ -255,7 +255,7 @@ describe('Binding: Options', function () {
255255
})
256256

257257
it('Should allow the caption to be given by an observable, and update it when the model value changes (without affecting selection)', function (ctx) {
258-
if (!isRealBrowser()) return ctx.skip('happy-dom: element.options[selectedIndex] can be undefined')
258+
if (isHappyDom()) return ctx.skip('happy-dom: element.options[selectedIndex] can be undefined')
259259
var myCaption = ko.observable('Initial caption')
260260
testNode.innerHTML = '<select data-bind=\'options:["A", "B"], optionsCaption: myCaption\'></select>'
261261
ko.applyBindings({ myCaption: myCaption }, testNode)

builds/knockout/spec/defaultBindings/valueBehaviors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ describe('Binding: Value', function () {
407407
})
408408

409409
it('When size > 1, should unselect all options when value is undefined, null, or \"\"', function (ctx) {
410-
if (!isRealBrowser()) return ctx.skip('happy-dom: size>1 <select> does not honor selectedIndex = -1')
410+
if (isHappyDom()) return ctx.skip('happy-dom: size>1 <select> does not honor selectedIndex = -1')
411411
var observable = new ko.observable('B')
412412
testNode.innerHTML = '<select size=\'2\' data-bind=\'options:["A", "B"], value:myObservable\'></select>'
413413
ko.applyBindings({ myObservable: observable }, testNode)

builds/knockout/spec/onErrorBehaviors.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ describe('onError handler', function () {
111111
})
112112

113113
it('fires on async component errors', async function (ctx) {
114-
if (!isRealBrowser()) return ctx.skip('happy-dom: setTimeout errors bypass window.onerror')
114+
if (isHappyDom()) return ctx.skip('happy-dom: setTimeout errors bypass window.onerror')
115115
var component = {
116116
tagName: 'test-onerror',
117117
template: "<div data-bind='text: name'></div>",
@@ -137,7 +137,7 @@ describe('onError handler', function () {
137137
})
138138

139139
it('passes through the error instance', async function (ctx) {
140-
if (!isRealBrowser()) return ctx.skip('happy-dom: setTimeout errors bypass window.onerror')
140+
if (isHappyDom()) return ctx.skip('happy-dom: setTimeout errors bypass window.onerror')
141141
var expectedInstance
142142
ko.tasks.schedule(function () {
143143
expectedInstance = new Error('Some error')

packages/binding.component/spec/componentBindingBehaviors.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import {
3535
restoreAfter,
3636
useMockForTasks
3737
} from '../../utils/helpers/mocha-test-helpers'
38-
import { isRealBrowser } from '../../utils/helpers/test-env'
38+
import { isHappyDom } from '../../utils/helpers/test-env'
3939

4040
describe('Components: Component binding', function () {
4141
let testComponentName = 'test-component',
@@ -1271,7 +1271,7 @@ describe('Components: Component binding', function () {
12711271
}
12721272
ViewModel.register('test-component')
12731273

1274-
if (!isRealBrowser()) return ctx.skip('happy-dom: innerText whitespace rendering differs from real browsers')
1274+
if (isHappyDom()) return ctx.skip('happy-dom: innerText whitespace rendering differs from real browsers')
12751275
applyBindings(outerViewModel, testNode)
12761276
expect((testNode.children[0] as HTMLInputElement).innerText.trim()).to.deep.equal(`beep / beep`)
12771277
})
@@ -1408,7 +1408,7 @@ describe('Components: Component binding', function () {
14081408
}
14091409
ViewModel.register('test-component')
14101410

1411-
if (!isRealBrowser()) return ctx.skip('happy-dom: innerText whitespace rendering differs from real browsers')
1411+
if (isHappyDom()) return ctx.skip('happy-dom: innerText whitespace rendering differs from real browsers')
14121412
applyBindings(outerViewModel, testNode)
14131413
expect((testNode.children[0] as HTMLElement).innerText.trim()).to.deep.equal(`A. B. C.`)
14141414
const em = testNode.children[0].children[0].children[0]
@@ -1430,7 +1430,7 @@ describe('Components: Component binding', function () {
14301430
}
14311431
ViewModel.register('test-component')
14321432

1433-
if (!isRealBrowser()) return ctx.skip('happy-dom: innerText whitespace rendering differs from real browsers')
1433+
if (isHappyDom()) return ctx.skip('happy-dom: innerText whitespace rendering differs from real browsers')
14341434
applyBindings(outerViewModel, testNode)
14351435
expect((testNode.children[0] as HTMLElement).innerText.trim()).to.deep.equal(`B. C. E.`)
14361436
const em = testNode.children[0].children[0].children[0]

packages/binding.core/spec/attrBehaviors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { options } from '@tko/utils'
1212
import * as coreBindings from '../dist'
1313

1414
import { prepareTestNode } from '../../utils/helpers/mocha-test-helpers'
15-
import { isRealBrowser } from '../../utils/helpers/test-env'
15+
import { isHappyDom } from '../../utils/helpers/test-env'
1616

1717
describe('Binding: Attr', function () {
1818
let testNode: HTMLElement
@@ -35,7 +35,7 @@ describe('Binding: Attr', function () {
3535
})
3636

3737
it('Should be able to set namespaced attribute values', function (ctx: any) {
38-
if (!isRealBrowser()) return ctx.skip('happy-dom: Element.lookupNamespaceURI not implemented')
38+
if (isHappyDom()) return ctx.skip('happy-dom: Element.lookupNamespaceURI not implemented')
3939
const model = { myValue: 'first value' }
4040
testNode.innerHTML = [
4141
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">',

packages/binding.core/spec/optionsBehaviors.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { bindings as coreBindings } from '../dist'
1313
import type { ObservableArray } from '@tko/observable'
1414

1515
import { expectContainText, nodeText, prepareTestNode } from '../../utils/helpers/mocha-test-helpers'
16-
import { isRealBrowser } from '../../utils/helpers/test-env'
16+
import { isHappyDom } from '../../utils/helpers/test-env'
1717

1818
function expectArrayEqual(actual: Array<unknown>, expected: Array<unknown>) {
1919
expect(actual.length).to.equal(expected.length)
@@ -185,7 +185,7 @@ describe('Binding: Options', function () {
185185
})
186186

187187
it('Should select caption by default and retain selection when adding multiple items', function (ctx: any) {
188-
if (!isRealBrowser()) return ctx.skip('happy-dom: <select> auto-selection semantics diverge')
188+
if (isHappyDom()) return ctx.skip('happy-dom: <select> auto-selection semantics diverge')
189189
testNode.innerHTML = '<select data-bind="options: filterValues, optionsCaption: \'foo\'">'
190190
const viewModel = { filterValues: observableArray(undefined) }
191191
applyBindings(viewModel, testNode)
@@ -200,7 +200,7 @@ describe('Binding: Options', function () {
200200
})
201201

202202
it('Should trigger a change event when the options selection is populated or changed by modifying the options data (single select)', function (ctx: any) {
203-
if (!isRealBrowser()) return ctx.skip('happy-dom: selectedIndex does not follow reordered <option>')
203+
if (isHappyDom()) return ctx.skip('happy-dom: selectedIndex does not follow reordered <option>')
204204
let myObservable: ObservableArray<string | number> = observableArray<string | number>(['A', 'B', 'C']),
205205
changeHandlerFireCount = 0
206206
testNode.innerHTML = "<select data-bind='options:myValues'></select>"
@@ -298,7 +298,7 @@ describe('Binding: Options', function () {
298298
})
299299

300300
it('Should allow the caption to be given by an observable, and update it when the model value changes (without affecting selection)', function (ctx: any) {
301-
if (!isRealBrowser()) return ctx.skip('happy-dom: element.options[selectedIndex] can be undefined')
301+
if (isHappyDom()) return ctx.skip('happy-dom: element.options[selectedIndex] can be undefined')
302302
const myCaption = observable('Initial caption')
303303
testNode.innerHTML = '<select data-bind=\'options:["A", "B"], optionsCaption: myCaption\'></select>'
304304
applyBindings({ myCaption: myCaption }, testNode)

packages/binding.core/spec/valueBehaviors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { options } from '@tko/utils'
1616
import { bindings as coreBindings } from '../dist'
1717

1818
import { nodeText, prepareTestNode } from '../../utils/helpers/mocha-test-helpers'
19-
import { isRealBrowser } from '../../utils/helpers/test-env'
19+
import { isHappyDom } from '../../utils/helpers/test-env'
2020

2121
function expectArrayEqual(actual: Array<unknown>, expected: Array<unknown>) {
2222
expect(actual.length).to.equal(expected.length)
@@ -439,7 +439,7 @@ describe('Binding: Value', function () {
439439
})
440440

441441
it('When size > 1, should unselect all options when value is undefined, null, or ""', function (ctx: any) {
442-
if (!isRealBrowser()) return ctx.skip('happy-dom: size>1 <select> does not honor selectedIndex = -1')
442+
if (isHappyDom()) return ctx.skip('happy-dom: size>1 <select> does not honor selectedIndex = -1')
443443
const myObservable = observable('B')
444444
testNode.innerHTML = '<select size=\'2\' data-bind=\'options:["A", "B"], value:myObservable\'></select>'
445445
applyBindings({ myObservable: myObservable }, testNode)

0 commit comments

Comments
 (0)