CodeSampleX

샘플

happy-dom 20.11.2: GlobalWindow

검증된 샘플 — npm happy-dom 20.11.2: GlobalWindow. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: GlobalWindow instantiates a DOM environment in host…

sha256:177dd0e424aff4017475a68165a7dc84007eb6692b822f52ea457dd3146f3d76

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
2
빌드한 서명 키
1
선언된 환경 linux 24 · ubuntu · glibc 2.39 x64 npm

검증 실행 환경

환경 컨트랙트 단계 실행일
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-21
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 SKIPPED compile:SKIPPED · contract:SKIPPED · load:SKIPPED · resolve:FAIL
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-07

케이스

HOW
목표
verify happy-dom.GlobalWindow in pkg:npm/happy-dom@20.11.2
패키지
심벌
  • happy-dom.GlobalWindow
생성일
2026-08-21T07:38:24Z

컨트랙트

  1. GlobalWindow instantiates a DOM environment in host global scope with configured URL and document
  2. GlobalWindow shares host ECMAScript prototypes and constructors including Array and Object with globalThis
  3. GlobalWindow creates DOM elements, updates innerHTML, and dispatches CustomEvent instances
  4. happyDOM.waitUntilComplete resolves when pending window timers execute

파일

  • PROMPT.md
  • csx.json
  • index.mjs
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

소스 아티팩트 내려받기 (tar.gz)

소스

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify happy-dom.GlobalWindow in pkg:npm/happy-dom@20.11.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/happy-dom@20.11.2
Demonstrate these symbols/APIs:
  - happy-dom.GlobalWindow

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:c1246043745e3b2e2eb6da9890778063c73f5f3b731fc8af43506b99f44b6e90","contract":["GlobalWindow instantiates a DOM environment in host global scope with configured URL and document","GlobalWindow shares host ECMAScript prototypes and constructors including Array and Object with globalThis","GlobalWindow creates DOM elements, updates innerHTML, and dispatches CustomEvent instances","happyDOM.waitUntilComplete resolves when pending window timers execute"],"goal":"verify happy-dom.GlobalWindow in pkg:npm/happy-dom@20.11.2","kind":"HOW","packages":["pkg:npm/happy-dom@20.11.2"],"schemaVersion":1,"symbols":["happy-dom.GlobalWindow"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/happy-dom@20.11.2"],"schemaVersion":1,"subject":"pkg:npm/happy-dom@20.11.2","symbols":["happy-dom.GlobalWindow"],"verifierAdapter":"node-typescript@1"}
index.mjs
import { GlobalWindow } from 'happy-dom';

/**
 * Creates and initializes a new GlobalWindow instance with the given URL.
 * @param {string} [url='https://example.com']
 * @returns {GlobalWindow}
 */
export function createGlobalDOM(url = 'https://example.com') {
  return new GlobalWindow({ url });
}

export { GlobalWindow };
package-lock.json
{
  "name": "happy-dom-global-window-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "happy-dom-global-window-sample",
      "version": "1.0.0",
      "dependencies": {
        "happy-dom": "20.11.2"
      }
    },
    "node_modules/@types/node": {
      "version": "26.2.0",
      "resolved": "https://registry.npmjs.org/@types/node/-/node-26.2.0.tgz",
      "integrity": "sha512-5IviulTZeRNp2vAJ514cc/HUlY5nZ9fCbq9DMyC52BrhFZACo3nI0R7qBxhQmo/d27NFe96ur/b7Wwxklda+kg==",
      "license": "MIT",
      "dependencies": {
        "undici-types": "~8.3.0"
      }
    },
    "node_modules/@types/whatwg-mimetype": {
      "version": "3.0.2",
      "resolved": "https://registry.npmjs.org/@types/whatwg-mimetype/-/whatwg-mimetype-3.0.2.tgz",
      "integrity": "sha512-c2AKvDT8ToxLIOUlN51gTiHXflsfIFisS4pO7pDPoKouJCESkhZnEy623gwP9laCy5lnLDAw1vAzu2vM2YLOrA==",
      "license": "MIT"
    },
    "node_modules/@types/ws": {
      "version": "8.18.1",
      "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.18.1.tgz",
      "integrity": "sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg==",
      "license": "MIT",
      "dependencies": {
        "@types/node": "*"
      }
    },
    "node_modules/buffer-image-size": {
      "version": "0.6.4",
      "resolved": "https://registry.npmjs.org/buffer-image-size/-/buffer-image-size-0.6.4.tgz",
      "integrity": "sha512-nEh+kZOPY1w+gcCMobZ6ETUp9WfibndnosbpwB1iJk/8Gt5ZF2bhS6+B6bPYz424KtwsR6Rflc3tCz1/ghX2dQ==",
      "license": "MIT",
      "dependencies": {
        "@types/node": "*"
      },
      "engines": {
        "node": ">=4.0"
      }
    },
    "node_modules/entities": {
      "version": "7.0.1",
      "resolved": "https://registry.npmjs.org/entities/-/entities-7.0.1.tgz",
      "integrity": "sha512-TWrgLOFUQTH994YUyl1yT4uyavY5nNB5muff+RtWaqNVCAK408b5ZnnbNAUEWLTCpum9w6arT70i1XdQ4UeOPA==",
      "license": "BSD-2-Clause",
      "engines": {
        "node": ">=0.12"
      },
      "funding": {
        "url": "https://github.com/fb55/entities?sponsor=1"
      }
    },
    "node_modules/happy-dom": {
      "version": "20.11.2",
      "resolved": "https://registry.npmjs.org/happy-dom/-/happy-dom-20.11.2.tgz",
      "integrity": "sha512-7MB+bJLkxu3SowAfBJbjW+c55kNz5tkR45gu2qzrxznezhLeN5YIlJbwUgSzlGc+qWoZ8Ykg71H5ezz69xixrw==",
      "license": "MIT",
      "dependencies": {
        "@types/node": ">=20.0.0",
        "@types/whatwg-mimetype": "^3.0.2",
        "@types/ws": "^8.18.1",
        "buffer-image-size": "^0.6.4",
        "entities": "^7.0.1",
        "whatwg-mimetype": "^3.0.0",
        "ws": "^8.21.0"
      },
      "engines": {
        "node": ">=20.0.0"
      }
    },
    "node_modules/undici-types": {
      "version": "8.3.0",
      "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-8.3.0.tgz",
      "integrity": "sha512-j375ScV60dom+YkPFIfTLcOiPxkN/buHz5GobjLhixFuANaNs3C9l4GmrWqejgXWJ7BbJcFYpTEUkS1Ge8bpZQ==",
      "license": "MIT"
    },
    "node_modules/whatwg-mimetype": {
      "version": "3.0.0",
      "resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-3.0.0.tgz",
      "integrity": "sha512-nt+N2dzIutVRxARx1nghPKGv1xHikU7HKdfafKkLNLindmPU/ch3U31NOCGGA/dmPcmb1VlofO0vnKAcsm0o/Q==",
      "license": "MIT",
      "engines": {
        "node": ">=12"
      }
    },
    "node_modules/ws": {
      "version": "8.21.3",
      "resolved": "https://registry.npmjs.org/ws/-/ws-8.21.3.tgz",
      "integrity": "sha512-201TZ/kPWxoPr/OKWjquZR1SWKXcvxdH+e1xrx89b3YbmzLMFCLfnaG1HFIgWzJOEWZ7MvpK++odZufgYR50Rw==",
      "license": "MIT",
      "engines": {
        "node": ">=10.0.0"
      },
      "peerDependencies": {
        "bufferutil": "^4.0.1",
        "utf-8-validate": ">=5.0.2"
      },
      "peerDependenciesMeta": {
        "bufferutil": {
          "optional": true
        },
        "utf-8-validate": {
          "optional": true
        }
      }
    }
  }
}
package.json
{
  "name": "happy-dom-global-window-sample",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "description": "Clean-room verification sample for happy-dom GlobalWindow",
  "main": "index.mjs",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "happy-dom": "20.11.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify happy-dom.GlobalWindow in pkg:npm/happy-dom@20.11.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/happy-dom@20.11.2"
  ],
  "symbols": [
    "happy-dom.GlobalWindow"
  ]
}
test/contract.mjs
import assert from 'node:assert';
import { GlobalWindow, createGlobalDOM } from '../index.mjs';

async function testGlobalWindowContract() {
  // 1. GlobalWindow instantiates a DOM environment in host global scope with configured URL and document
  const window = createGlobalDOM('https://example.com');
  assert(window instanceof GlobalWindow, 'Instance should be a GlobalWindow');
  assert.strictEqual(window.location.href, 'https://example.com/', 'Location href should match initialized URL');
  assert(window.document !== undefined, 'Window document should be defined');
  assert.strictEqual(typeof window.document.createElement, 'function', 'createElement should be available on document');

  // 2. GlobalWindow shares host ECMAScript prototypes and constructors including Array and Object with globalThis
  assert.strictEqual(window.Array, Array, 'GlobalWindow must share the host Array constructor');
  assert.strictEqual(window.Object, Object, 'GlobalWindow must share the host Object constructor');

  // 3. GlobalWindow creates DOM elements, updates innerHTML, and dispatches CustomEvent instances
  const container = window.document.createElement('div');
  container.innerHTML = '<span class="target-node">Sample Content</span>';
  window.document.body.appendChild(container);

  const target = window.document.querySelector('.target-node');
  assert(target !== null, 'querySelector should locate child node');
  assert.strictEqual(target.textContent, 'Sample Content', 'textContent should match inserted HTML');

  let eventHandled = false;
  target.addEventListener('custom-action', (event) => {
    eventHandled = true;
    assert.strictEqual(event.detail.status, 'active', 'Event detail property should be preserved');
  });

  const customEvt = new window.CustomEvent('custom-action', {
    detail: { status: 'active' },
    bubbles: true
  });
  target.dispatchEvent(customEvt);
  assert.strictEqual(eventHandled, true, 'CustomEvent should be dispatched and received');

  // 4. happyDOM.waitUntilComplete resolves when pending window timers execute
  let asyncTaskDone = false;
  window.setTimeout(() => {
    asyncTaskDone = true;
  }, 25);

  await window.happyDOM.waitUntilComplete();
  assert.strictEqual(asyncTaskDone, true, 'waitUntilComplete should wait for scheduled timer completion');
}

testGlobalWindowContract()
  .then(() => {
    console.log('Contract test passed successfully.');
    process.exit(0);
  })
  .catch((err) => {
    console.error('Contract test failed:', err);
    process.exit(1);
  });

오리진 시더

익명