CodeSampleX

Beispiel

happy-dom 20.11.2: GlobalWindow

Verifiziertes Beispiel für npm happy-dom 20.11.2: GlobalWindow. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand.

sha256:177dd0e424aff4017475a68165a7dc84007eb6692b822f52ea457dd3146f3d76

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
2
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux 24 · ubuntu · glibc 2.39 x64 npm

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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

Fall

HOW
Ziel
verify happy-dom.GlobalWindow in pkg:npm/happy-dom@20.11.2
Pakete
Symbole
  • happy-dom.GlobalWindow
Erstellt
2026-08-21T07:38:24Z

Contract

  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

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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);
  });

Ursprungs-Seeder

anonym