nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: pmcelhaney/counterfact
Pull request #544 (2023-09-01 17:46:15)

make paths case-insensitive
If APIs are deployed on Windows, they may not be picky about URLs have the correct case. This change makes Counterfact work the same way. `GET /foo` and `GET /FOO` are the same. 

At some point, we might want to add a setting so that "strict" mode can be enabled. For now, I think the majority of people will either benefit from the change or won't notice any difference. 

See https://github.com/pmcelhaney/counterfact/discussions/537


Patch:
diff --git a/.changeset/eight-papayas-melt.md b/.changeset/eight-papayas-melt.md
new file mode 100644
index 0000000..ff103b2
--- /dev/null
+++ b/.changeset/eight-papayas-melt.md
@@ -0,0 +1,5 @@
+---
+"counterfact": patch
+---
+
+make paths in URLs case-insensitive (http://localhost:3100/FOO is the same as http://localhost:3100/foo)
diff --git a/src/server/registry.js b/src/server/registry.js
index 7095fea..d48ea49 100644
--- a/src/server/registry.js
+++ b/src/server/registry.js
@@ -95,9 +95,13 @@ export class Registry {
     const matchedParts = [""];
 
     for (const segment of url.split("/").slice(1)) {
-      if (node.children[segment]) {
-        node = node.children[segment];
-        matchedParts.push(segment);
+      const matchingChild = Object.keys(node.children).find(
+        (candidate) => candidate.toLowerCase() === segment.toLowerCase(),
+      );
+
+      if (matchingChild) {
+        node = node.children[matchingChild];
+        matchedParts.push(matchingChild);
       } else {
         const dynamicSegment = Object.keys(node.children).find(
           (ds) => ds.startsWith("{") && ds.endsWith("}"),


Test patch:
diff --git a/test/server/registry.test.js b/test/server/registry.test.js
index 542a900..8d5bce7 100644
--- a/test/server/registry.test.js
+++ b/test/server/registry.test.js
@@ -103,6 +103,24 @@ describe("a registry", () => {
     });
   });
 
+  it("matches an endpoint where the case does not match", () => {
+    const registry = new Registry();
+
+    registry.add("/{organization}/users/{username}/friends/{page}", {
+      GET({ path }) {
+        return {
+          body: `page ${path.page} of ${path.username}'s friends in ${path.organization}`,
+        };
+      },
+    });
+
+    expect(
+      registry.endpoint("GET", "/Acme/users/alice/Friends/2")({}),
+    ).toStrictEqual({
+      body: "page 2 of alice's friends in Acme",
+    });
+  });
+
   it("lists all of the routes", () => {
     const registry = new Registry();
Repository: pmcelhaney/counterfact
Pull request #675 (2023-12-06 03:20:17)

if there is no response body the accept header in the request does not apply


Patch:
diff --git a/.changeset/modern-hornets-glow.md b/.changeset/modern-hornets-glow.md
new file mode 100644
index 0000000..caccd6a
--- /dev/null
+++ b/.changeset/modern-hornets-glow.md
@@ -0,0 +1,5 @@
+---
+"counterfact": patch
+---
+
+ignore the HTTP accept header if the response has no body
diff --git a/src/server/dispatcher.ts b/src/server/dispatcher.ts
index 8e63b89..6db2f89 100644
--- a/src/server/dispatcher.ts
+++ b/src/server/dispatcher.ts
@@ -280,6 +280,7 @@ export class Dispatcher {
     );
 
     if (
+      normalizedResponse.body !== undefined &&
       !mediaTypes(headers.accept ?? "*/*").some((type) =>
         this.isMediaType(normalizedResponse.contentType ?? "", type),
       )


Test patch:
diff --git a/test/server/dispatcher.test.ts b/test/server/dispatcher.test.ts
index a0b5277..0227abb 100644
--- a/test/server/dispatcher.test.ts
+++ b/test/server/dispatcher.test.ts
@@ -80,7 +80,7 @@ describe("a dispatcher", () => {
     expect(html?.type).toBe("text/html");
   });
 
-  it("returns HTTP 406 if it can't return content matching the accept header", async () => {
+  it("returns HTTP 406 if it can only return content that does not match the accept header", async () => {
     const registry = new Registry();
 
     registry.add("/hello", {
@@ -111,6 +111,35 @@ describe("a dispatcher", () => {
     expect(response.status).toBe(406);
   });
 
+  it("does not set status to 406 if the response has no content", async () => {
+    const registry = new Registry();
+
+    registry.add("/hello", {
+      GET() {
+        return {
+          status: 200,
+        };
+      },
+    });
+
+    const dispatcher = new Dispatcher(registry, new ContextRegistry());
+    const response = await dispatcher.request({
+      body: "",
+
+      headers: {
+        accept: "application/json",
+      },
+
+      method: "GET",
+
+      path: "/hello",
+      query: {},
+      req: { path: "/hello" },
+    });
+
+    expect(response.status).toBe(200);
+  });
+
   it.each([
     ["text/html", ["text/html"], "text/html"],
     ["text/plain", ["text/html", "text/plain"], "text/plain"],
Repository: rrd108/vue-mess-detector
Pull request #51 (2024-07-03 14:29:48)

chore: change max script length to 100
Fixes https://github.com/rrd108/vue-mess-detector/issues/50


Patch:
diff --git a/src/rules/rrd/scriptLength.ts b/src/rules/rrd/scriptLength.ts
index 3b8cda2..faa4ecf 100644
--- a/src/rules/rrd/scriptLength.ts
+++ b/src/rules/rrd/scriptLength.ts
@@ -1,7 +1,7 @@
 import { SFCScriptBlock } from '@vue/compiler-sfc'
 import { BG_ERR, BG_RESET, BG_WARN, TEXT_WARN, TEXT_RESET, TEXT_INFO } from '../asceeCodes'
 
-const MAX_SCRIPT_LENGTH = 50
+const MAX_SCRIPT_LENGTH = 100
 
 const longScriptFiles: { fileName: string; scriptLength: number }[] = []
 


Test patch:
diff --git a/src/rules/rrd/scriptLength.test.ts b/src/rules/rrd/scriptLength.test.ts
index 4202f21..c4baf92 100644
--- a/src/rules/rrd/scriptLength.test.ts
+++ b/src/rules/rrd/scriptLength.test.ts
@@ -16,7 +16,7 @@ describe('checkScriptLength', () => {
 
   it('should report long scripts for a long script', () => {
     let content = '<scritp setup>'
-    for (let i = 0; i < 52; i++) {
+    for (let i = 0; i < 102; i++) {
       content += `\nconsole.log("Hello ${i}")`
     }
     content += '\n</script>'
@@ -25,6 +25,6 @@ describe('checkScriptLength', () => {
     checkScriptLength(longScript, fileName)
     expect(reportScriptLength()).toBe(1)
     expect(mockConsoleLog).toHaveBeenCalled()
-    expect(mockConsoleLog).toHaveBeenLastCalledWith(`- long.vue ${BG_WARN}(54 lines)${BG_RESET}`)
+    expect(mockConsoleLog).toHaveBeenLastCalledWith(`- long.vue ${BG_WARN}(104 lines)${BG_RESET}`)
   })
 })
Repository: hustcc/jest-canvas-mock
Pull request #16 (2019-01-24 09:32:23)

Add createImageData() implementation
This PR adds handling of parameters to `createImageData()` and returns the correctly-shaped object.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/21249452/badge)](https://coveralls.io/builds/21249452)

Coverage remained the same at 100.0% when pulling **bb604f414e27527b98226faa933263bfd8605001 on robinelvin:master** into **b734559198c382365203f4d6c5c5d38faebf490e on hustcc:master**.


Patch:
diff --git a/src/classes/context2d.js b/src/classes/context2d.js
index 75050ba..e515324 100644
--- a/src/classes/context2d.js
+++ b/src/classes/context2d.js
@@ -19,7 +19,17 @@ const context2d = {
     height: 14,
   }),
   putImageData: () => {},
-  createImageData: () => [],
+  createImageData: (w = 1, h = 1) => {
+    if ('object' === typeof w) {
+      h = w.height;
+      w = w.width;
+    }
+    return {
+      width: w,
+      height: h,
+      data: new Array((w * h * 4))
+    }
+  },
   setTransform: () => {},
   resetTransform: () => {},
   drawImage: () => {},


Test patch:
diff --git a/__tests__/index.js b/__tests__/index.js
index f0a75f2..a8fa52a 100644
--- a/__tests__/index.js
+++ b/__tests__/index.js
@@ -42,6 +42,19 @@ describe('canvas', () => {
     expect(canvas.toDataURL).toHaveBeenLastCalledWith('image/jpeg', 1.0);
   });
 
+  test('canvas.createImageData()', () => {
+    const canvas = document.createElement('canvas');
+    const ctx = canvas.getContext('2d');
+    const imageData = ctx.createImageData(100, 50);
+    expect(imageData.width).toBe(100);
+    expect(imageData.height).toBe(50);
+    expect(imageData.data).toBeDefined();
+    expect(imageData.data).toHaveLength(20000);
+
+    const imageData2 = ctx.createImageData({width: 120, height: 100});
+    expect(imageData2.data).toHaveLength(48000);
+  });
+
   test('ctx.functions', () => {
     const canvas = document.createElement('canvas');
     const ctx = canvas.getContext('2d');
Repository: hustcc/jest-canvas-mock
Pull request #47 (2019-10-01 14:50:08)

fix(context): :anchor: Removes argument to getters
The `__get*` methods on the CanvasRenderingContext2D class currently take an unnecessary `ctx` argument. This is inconsistent with both the README and the TypeScript interface's documentation of these methods. This change removes the argument and updates the tests to match.


Patch:
diff --git a/src/classes/CanvasRenderingContext2D.js b/src/classes/CanvasRenderingContext2D.js
index 766b9b9..cb4d0fb 100644
--- a/src/classes/CanvasRenderingContext2D.js
+++ b/src/classes/CanvasRenderingContext2D.js
@@ -47,7 +47,7 @@ export default class CanvasRenderingContext2D {
    * an event is added to this array. This goes for every property set, and draw call.
    */
   _events = [];
-  __getEvents(ctx) {
+  __getEvents() {
     return this._events.slice();
   }
 
@@ -56,8 +56,8 @@ export default class CanvasRenderingContext2D {
    * path.
    */
   _path = [createCanvasEvent('beginPath', [1, 0, 0, 1, 0, 0], {})];
-  __getPath(ctx) {
-    return ctx._path.slice();
+  __getPath() {
+    return this._path.slice();
   }
 
   _directionStack = ['inherit'];


Test patch:
diff --git a/__tests__/classes/CanvasRenderingContext2D.__getDrawCalls.js b/__tests__/classes/CanvasRenderingContext2D.__getDrawCalls.js
index d9694dc..16440d7 100644
--- a/__tests__/classes/CanvasRenderingContext2D.__getDrawCalls.js
+++ b/__tests__/classes/CanvasRenderingContext2D.__getDrawCalls.js
@@ -14,7 +14,7 @@ const path = new Path2D();
 path.arc(100, 101, 10, 0, Math.PI * 2);
 
 afterEach(() => {
-  const drawCalls = ctx.__getDrawCalls(ctx);
+  const drawCalls = ctx.__getDrawCalls();
   expect(drawCalls).toMatchSnapshot();
 });
 
diff --git a/__tests__/classes/CanvasRenderingContext2D.__getEvents.js b/__tests__/classes/CanvasRenderingContext2D.__getEvents.js
index b53d7e2..4433de0 100644
--- a/__tests__/classes/CanvasRenderingContext2D.__getEvents.js
+++ b/__tests__/classes/CanvasRenderingContext2D.__getEvents.js
@@ -16,7 +16,7 @@ path.arc(100, 101, 10, 0, Math.PI * 2);
 const imgData = new ImageData(100, 100);
 
 afterEach(() => {
-  const drawCalls = ctx.__getEvents(ctx);
+  const drawCalls = ctx.__getEvents();
   expect(drawCalls).toMatchSnapshot();
 });
 
diff --git a/__tests__/classes/CanvasRenderingContext2D.__getPath.js b/__tests__/classes/CanvasRenderingContext2D.__getPath.js
index 36a59f4..e6c059f 100644
--- a/__tests__/classes/CanvasRenderingContext2D.__getPath.js
+++ b/__tests__/classes/CanvasRenderingContext2D.__getPath.js
@@ -9,7 +9,7 @@ const path = new Path2D();
 path.arc(100, 101, 10, 0, Math.PI * 2);
 
 afterEach(() => {
-  const drawCalls = ctx.__getPath(ctx);
+  const drawCalls = ctx.__getPath();
   expect(drawCalls).toMatchSnapshot();
 });
Repository: hustcc/jest-canvas-mock
Pull request #70 (2020-08-05 05:45:10)

feat(DOMMatrix): add toFloat32Array and toFloat64Array
# Description
Add 2 methods that DOMMatrix has but is missing in the mock

- `toFloat32Array()`
- `toFloat64Array()`

coveralls: 
[![Coverage Status](https://coveralls.io/builds/32547993/badge)](https://coveralls.io/builds/32547993)

Coverage remained the same at 100.0% when pulling **6f0d7713e4cb6e1398645d8f72234af12462d85b on FeliciousX:dommatrix** into **df7a9fb608550a9440ee37a03949799f3aa1a532 on hustcc:master**.


Patch:
diff --git a/src/classes/DOMMatrix.js b/src/classes/DOMMatrix.js
index 356227f..3e6e389 100644
--- a/src/classes/DOMMatrix.js
+++ b/src/classes/DOMMatrix.js
@@ -140,4 +140,46 @@ export default class DOMMatrix {
   get is2D() {
     return this._is2D;
   }
+
+  toFloat32Array() {
+    return new Float32Array([
+      this.m11,
+      this.m12,
+      this.m13,
+      this.m14,
+      this.m21,
+      this.m22,
+      this.m23,
+      this.m24,
+      this.m31,
+      this.m32,
+      this.m33,
+      this.m34,
+      this.m41,
+      this.m42,
+      this.m43,
+      this.m44,
+    ]);
+  }
+
+  toFloat64Array() {
+    return new Float64Array([
+      this.m11,
+      this.m12,
+      this.m13,
+      this.m14,
+      this.m21,
+      this.m22,
+      this.m23,
+      this.m24,
+      this.m31,
+      this.m32,
+      this.m33,
+      this.m34,
+      this.m41,
+      this.m42,
+      this.m43,
+      this.m44,
+    ]);
+  }
 }


Test patch:
diff --git a/__tests__/classes/DOMMatrix.js b/__tests__/classes/DOMMatrix.js
index 9e95ab3..38b42a3 100644
--- a/__tests__/classes/DOMMatrix.js
+++ b/__tests__/classes/DOMMatrix.js
@@ -52,6 +52,22 @@ describe('DOMMatrix class', () => {
     expect(matrix).toBeInstanceOf(DOMMatrix);
   });
 
+  it('should return Float32Array', () => {
+    const matrix32 = new DOMMatrix().toFloat32Array();
+    expect(matrix32).toBeInstanceOf(Float32Array);
+    expect(matrix32).toStrictEqual(
+      new Float32Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])
+    );
+  });
+
+  it('should return Float64Array', () => {
+    const matrix64 = new DOMMatrix().toFloat64Array();
+    expect(matrix64).toBeInstanceOf(Float64Array);
+    expect(matrix64).toStrictEqual(
+      new Float64Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])
+    );
+  });
+
   it('should know if a 2d matrix is an identity matrix', () => {
     const matrix = new DOMMatrix([1, 0, 0, 1, 0, 0]);
     expect(matrix.isIdentity).toBeTruthy();
Repository: hustcc/jest-canvas-mock
Pull request #74 (2020-12-20 13:03:27)

fix setLineDash parameter name: value -> segments
use the same parameter name as in `typescript/lib/lib.dom.d.ts`

```ts
interface CanvasPathDrawingStyles {
    // ....
    setLineDash(segments: number[]): void;
}
```
so we can auto-generate interfaces as shown [here](https://github.com/MrMaxie/ts-types-parser/pull/4)

jtenner: I'm actually not opposed to this change. LGTM. I need to fix CI however. 
coveralls: 
[![Coverage Status](https://coveralls.io/builds/35858667/badge)](https://coveralls.io/builds/35858667)

Coverage remained the same at 100.0% when pulling **cdb6a23efebaf1bfb0391a17d2cb073cc2f65a12 on milahu:patch-1** into **c4d1fb2981b00415b465701f63a488666fd2e825 on hustcc:master**.

milahu: same problem with parameters `width` and `height`

in `typescript/lib/lib.dom.d.ts` these appear only as `w` and `h`
for example on methods `rect` or `clearRect`

can we change these too?
so the `typescript/lib/lib.dom.d.ts` interface is our single source of truth

Patch:
diff --git a/src/classes/CanvasRenderingContext2D.js b/src/classes/CanvasRenderingContext2D.js
index d6b897e..08cfddf 100644
--- a/src/classes/CanvasRenderingContext2D.js
+++ b/src/classes/CanvasRenderingContext2D.js
@@ -1639,7 +1639,7 @@ export default class CanvasRenderingContext2D {
     result = this._lineDashStack[this._stackIndex] =
       result.length % 2 === 1 ? result.concat(result) : result;
     const event = createCanvasEvent('setLineDash', getTransformSlice(this), {
-      value: result.slice(),
+      segments: result.slice(),
     });
     this._events.push(event);
   }


Test patch:
diff --git a/__tests__/classes/__snapshots__/CanvasRenderingContext2D.__getEvents.js.snap b/__tests__/classes/__snapshots__/CanvasRenderingContext2D.__getEvents.js.snap
index 4989694..3e531ef 100644
--- a/__tests__/classes/__snapshots__/CanvasRenderingContext2D.__getEvents.js.snap
+++ b/__tests__/classes/__snapshots__/CanvasRenderingContext2D.__getEvents.js.snap
@@ -1561,7 +1561,7 @@ exports[`__getEvents should have an event when setLineDash is called 1`] = `
 Array [
   Object {
     "props": Object {
-      "value": Array [
+      "segments": Array [
         1,
         2,
         3,
Repository: vgteam/sequenceTubeMap
Pull request #244 (2023-03-20 05:49:09)

adding track delete button files
Work in progress for track delete button 


Patch:
diff --git a/src/components/TrackDeleteButton.demo.js b/src/components/TrackDeleteButton.demo.js
new file mode 100644
index 0000000..59e1012
--- /dev/null
+++ b/src/components/TrackDeleteButton.demo.js
@@ -0,0 +1,22 @@
+import Demo, {props as P} from 'react-demo'
+// See https://github.com/rpominov/react-demo for how to make a demo
+
+import TrackDeleteButton from "./TrackDeleteButton";
+
+export default (<Demo
+  props={{
+    id: P.string('deleteButton'),
+    className: P.string('someCSSClass'),
+  }}
+>
+  {
+    (props) => {
+      // We need to render the component under test using the props in props
+      return <TrackDeleteButton {...props} onClick={() => {
+        // button has been clicked
+        alert("clicked");
+      }}/>
+    }
+  }
+</Demo>)
+
diff --git a/src/components/TrackDeleteButton.js b/src/components/TrackDeleteButton.js
new file mode 100644
index 0000000..0fc4088
--- /dev/null
+++ b/src/components/TrackDeleteButton.js
@@ -0,0 +1,41 @@
+import React from "react";
+import { Button } from "reactstrap";
+import { faX } from '@fortawesome/free-solid-svg-icons';
+import PropTypes from "prop-types";
+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+
+/**
+ * A track delete button component.
+ * 
+ * When clicked, would call a function to delete the track
+ * 
+ */
+
+ export function TrackDeleteButton (props) {
+
+    // return button
+    // upon click, call onClick function 
+    
+    return (
+        <Button {...props}><FontAwesomeIcon icon={faX} /></Button>
+    );
+}
+
+/* React checks for the type of each prop passed in to ensure that the correct type is being 
+inputted to the component. For example, if 'id' is supposed to be a string, a number must not 
+be passed in - that would cause errors. However, if the prop has 'isRequired' specified, 
+it must be passed to the component. */
+
+TrackDeleteButton.propTypes = {
+  id: PropTypes.string,
+  className: PropTypes.string,
+  onClick: PropTypes.func.isRequired,
+};
+
+TrackDeleteButton.defaultProps = {
+  id: undefined,
+  className: undefined,
+};
+
+export default TrackDeleteButton;
+


Test patch:
diff --git a/src/components/TrackDeleteButton.test.js b/src/components/TrackDeleteButton.test.js
new file mode 100644
index 0000000..c4deae3
--- /dev/null
+++ b/src/components/TrackDeleteButton.test.js
@@ -0,0 +1,18 @@
+import React from 'react';
+import {render} from '@testing-library/react';
+import {TrackDeleteButton} from './TrackDeleteButton';
+import {screen} from '@testing-library/react';
+import userEvent from "@testing-library/user-event";
+
+describe('TrackDeleteButton', () => {
+    it('calls onClick', async () => {
+        const onClick = jest.fn();
+        const result = render(
+            <TrackDeleteButton onClick={onClick}></TrackDeleteButton>
+        );
+
+        await userEvent.click(screen.getByRole('button'));
+
+        expect(onClick).toHaveBeenCalledTimes(1);
+    });
+});
Repository: vgteam/sequenceTubeMap
Pull request #264 (2023-05-02 21:09:26)

Change track settings popup
#250 Made some changes to popup of track settings button.


Patch:
diff --git a/src/App.css b/src/App.css
index 914be87..48b1ea1 100644
--- a/src/App.css
+++ b/src/App.css
@@ -201,4 +201,15 @@ input[type="file"] {
 
 .tracklist-dropdown {
   margin-top: 4px;
-}
\ No newline at end of file
+}
+
+/* Close Popup */
+
+.closePopup{
+  align-items: center;
+  scale: 0.7;
+  border-radius: 50%;
+  position: absolute;
+  top: -20px;
+  right: -20px;
+}
diff --git a/src/components/TrackSettingsButton.js b/src/components/TrackSettingsButton.js
index 74e3553..faa736b 100644
--- a/src/components/TrackSettingsButton.js
+++ b/src/components/TrackSettingsButton.js
@@ -4,7 +4,7 @@ import PropTypes from "prop-types";
 import TrackSettings from "./TrackSettings.js";
 import { Button } from 'reactstrap'
 import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
-import { faGear } from '@fortawesome/free-solid-svg-icons';
+import { faGear, faX } from '@fortawesome/free-solid-svg-icons';
 
 import {
   Container,
@@ -25,15 +25,17 @@ export const TrackSettingsButton = ({
     return(
       <div>
         
-        <Button aria-label="Settings" onClick={() => setOpen(!open)}><FontAwesomeIcon icon={faGear} /></Button>
+        <Button data-testid="button" aria-label="Settings" onClick={() => setOpen(!open)}><FontAwesomeIcon icon={faGear} /></Button>
       
         {/* Popup has a trigger option, but passing in a button to trigger did not allow for the popup to be opened and closed
          with a Reactstrap button. We had to use onClick and onClose instead to open and close depending on the state of the popup */}
         
-        <Popup open={open} closeOnDocumentClick onClose={close} contentStyle={{width: "760px"}} modal>
+        <Popup open={open} closeOnDocumentClick={false} contentStyle={{width: "760px"}} modal>
           <Container>
             <Card>
-              <CardBody>
+              <CardBody style={{boxShadow: "0 4px 8px 0 rgba(0, 0, 0, 0.2)"}}>
+                {/* Close Button */}
+                  <Button className="closePopup" onClick={close}><FontAwesomeIcon icon={faX}/></Button>
                   <TrackSettings
                     fileType={fileType}
                     trackColorSettings={trackColorSettings}


Test patch:
diff --git a/src/components/TrackSettingsButton.test.js b/src/components/TrackSettingsButton.test.js
index 843f86d..595f57b 100644
--- a/src/components/TrackSettingsButton.test.js
+++ b/src/components/TrackSettingsButton.test.js
@@ -12,11 +12,11 @@ describe('TrackSettingsButton', () => {
                 colorReadsByMappingQuality: false}} setTrackColorSetting={function(a, b){}}></TrackSettingsButton>
         );
 
-        await userEvent.click(screen.getByRole('button'));
+        await userEvent.click(screen.getByTestId('button'));
 
         expect(screen.getByRole('heading')).toBeTruthy();
 
-        await userEvent.click(screen.getByRole('button'));
+        await userEvent.click(screen.getByTestId('button'));
 
         expect(screen.queryByRole('heading')).toBeFalsy();
Repository: yargs/yargs
Pull request #454 (2016-03-26 09:57:08)

Fix demand() when second argument is an array
Specifying a command count and required arguments at the same time causes the required arguments to be set as the 'max' of argv._

For example, calling `.demand(1, ['foo', 'bar'])` causes this to be set in options.demanded: `_: { count: 1, msg: undefined, max: [ 'foo', 'bar' ] } }`

This doesn't really fails because, when doing the validation, comparing a number to an array returns true most of the time on Javascript. But we shouldn't be relying on undocumented behavior if possible.

There is actually an edge case that fails: When calling `.demand(1, ['1'])`, it will fail is the user provides more than one command. I added a test for that.



Patch:
diff --git a/yargs.js b/yargs.js
index 9a10c72..43fa5e4 100644
--- a/yargs.js
+++ b/yargs.js
@@ -234,6 +234,7 @@ function Yargs (processArgs, cwd, parentRequire) {
       max.forEach(function (key) {
         self.demand(key, msg)
       })
+      max = Infinity
     } else if (typeof max !== 'number') {
       msg = max
       max = Infinity


Test patch:
diff --git a/test/usage.js b/test/usage.js
index 0bb17b2..7887ffc 100644
--- a/test/usage.js
+++ b/test/usage.js
@@ -300,6 +300,18 @@ describe('usage tests', function () {
           'pork chop sandwiches'
         ])
       })
+
+      it("shouldn't interpret the second argument as a max when it is an array", function () {
+        var r = checkUsage(function () {
+          return yargs(['koala', 'wombat', '--1'])
+              .usage('Usage: foo')
+              .demand(1, ['1'])
+              .wrap(null)
+              .argv
+        })
+
+        r.errors.length.should.equal(0)
+      })
     })
   })