mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
`node --test` runs showed no test tree, and single tests ran with Jest's `-t`. - Detection: a `package.json` script whose Node options include `--test` (also `tsx --test`) is a test configuration with `testRunner: "node-test"`; a script that picks its own `--test-reporter` runs as written. - Test tree: test runs add the IDE's reporter (`nodeTestReporter.js`, passed as a `data:` URL) next to `spec` through `NODE_OPTIONS`, which works through `npm run`, Node's per-file child processes and remote run targets. It prints a record per test (file, describe chain, status, duration, declaration line, error); the records become the tree and are hidden from the console, which keeps `spec`'s output. - Gutter, Rerun Failed Tests, run selected tests: select by full name with `--test-name-pattern` in `NODE_OPTIONS`, plus the files. New fixture `fixtures/node-test-app`, run by `smoke/run.test.ts` in the TypeScript job. Closes #5152 Co-authored-by: wildcatDownstairs <26499420+wildcatDownstairs@users.noreply.github.com>
24 lines
632 B
JavaScript
24 lines
632 B
JavaScript
export class Inventory {
|
|
#stock = new Map();
|
|
|
|
receive(sku, quantity) {
|
|
if (!Number.isInteger(quantity) || quantity <= 0) throw new RangeError("quantity must be a positive integer");
|
|
this.#stock.set(sku, this.count(sku) + quantity);
|
|
return this;
|
|
}
|
|
|
|
ship(sku, quantity) {
|
|
// TODO: reserve stock for open orders before shipping
|
|
if (quantity > this.count(sku)) throw new Error(`not enough ${sku} in stock`);
|
|
this.#stock.set(sku, this.count(sku) - quantity);
|
|
return this;
|
|
}
|
|
|
|
count(sku) {
|
|
return this.#stock.get(sku) ?? 0;
|
|
}
|
|
}
|
|
|
|
// An intentional warning: never used.
|
|
const RESTOCK_LEVEL = 5;
|