nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: bahmutov/cypress-map
Pull request #4 (2022-12-13 01:42:03)

feat: add cy.primo query


Patch:
diff --git a/README.md b/README.md
index c87fb1e..0067e2e 100644
--- a/README.md
+++ b/README.md
@@ -94,6 +94,18 @@ cy.get('#items li')
 
 **Notice:** if the label is provided, the callback function is called with label and the subject.
 
+### primo
+
+```js
+cy.get('.matching')
+  .map('innerText')
+  .primo()
+  .invoke('toUpperCase')
+  .should('equal', 'FIRST')
+```
+
+See [primo.cy.js](./cypress/e2e/primo.cy.js)
+
 ## cy.invoke vs cy.map vs cy.mapInvoke
 
 Here are a few examples to clarify the different between the `cy.invoke`, `cy.map`, and `cy.mapInvoke` query commands, see [diff.cy.js](./cypress/e2e/diff.cy.js)
diff --git a/commands/index.d.ts b/commands/index.d.ts
index 68c9716..a02e6dd 100644
--- a/commands/index.d.ts
+++ b/commands/index.d.ts
@@ -58,5 +58,15 @@ declare namespace Cypress {
      *  cy.wrap(2).apply(double).should('equal', 4)
      */
     apply(fn: Function): Chainable<any>
+
+    /**
+     * A query command that returns the first element / item from the subject.
+     * @see https://github.com/bahmutov/cypress-map
+     * @example
+     *  cy.get('...').primo()
+     * @example
+     *  cy.wrap([1, 2, 3]).primo().should('equal', 1)
+     */
+    primo(): Chainable<any>
   }
 }
diff --git a/commands/index.js b/commands/index.js
index b799ee6..218e4ec 100644
--- a/commands/index.js
+++ b/commands/index.js
@@ -5,3 +5,4 @@ import './map-invoke'
 import './tap'
 import './reduce'
 import './apply'
+import './primo'
diff --git a/commands/primo.js b/commands/primo.js
new file mode 100644
index 0000000..962cc53
--- /dev/null
+++ b/commands/primo.js
@@ -0,0 +1,13 @@
+Cypress.Commands.addQuery('primo', () => {
+  const log = Cypress.log({ name: 'primo' })
+
+  return (subject) => {
+    if (Cypress.dom.isJquery(subject)) {
+      return subject[0]
+    }
+    if (Array.isArray(subject)) {
+      return subject[0]
+    }
+    throw new Error('Not sure how to pick the first item')
+  }
+})


Test patch:
diff --git a/cypress/e2e/primo.cy.js b/cypress/e2e/primo.cy.js
new file mode 100644
index 0000000..f145b7d
--- /dev/null
+++ b/cypress/e2e/primo.cy.js
@@ -0,0 +1,21 @@
+/// <reference types="cypress" />
+// @ts-check
+
+import '../../commands'
+
+it('converts the first item text to uppercase', () => {
+  cy.visit('cypress/index.html')
+  cy.get('.matching')
+    .map('innerText')
+    .primo()
+    .invoke('toUpperCase')
+    .should('equal', 'FIRST')
+})
+
+it('yields the first DOM element', () => {
+  cy.visit('cypress/index.html')
+  cy.get('.matching')
+    .primo()
+    .invoke('getAttributeNames')
+    .should('deep.equal', ['class'])
+})
Repository: bahmutov/cypress-map
Pull request #23 (2023-02-07 00:18:36)

fix: return instance of array from cy.map
This test now passes after `cy.map` query
```js
it('maps to an array', () => {
  cy.wrap(['one', 'a', 'four'])
    .should('be.an.instanceOf', Array)
    .map('length')
    .should('deep.equal', [3, 1, 4])
    .and('be.an', 'array')
    .and('be.an.instanceOf', Array)
})
```


Patch:
diff --git a/commands/map.js b/commands/map.js
index 5d643b0..023b382 100644
--- a/commands/map.js
+++ b/commands/map.js
@@ -2,13 +2,22 @@
 
 Cypress.Commands.addQuery('map', (fnOrProperty) => {
   const message =
-    typeof fnOrProperty === 'string' ? fnOrProperty : fnOrProperty.name
+    typeof fnOrProperty === 'string'
+      ? fnOrProperty
+      : fnOrProperty.name
   const log = Cypress.log({ name: 'map', message })
 
-  return ($el) =>
-    Cypress._.map($el, (item) =>
-      typeof fnOrProperty === 'string'
-        ? item[fnOrProperty]
-        : fnOrProperty(item),
-    )
+  return ($el) => {
+    // use a spread so that the result is an array
+    // and used the Array constructor in the current iframe
+    // so it passes the "instanceOf Array" assertion
+    const list = [
+      ...Cypress._.map($el, (item) =>
+        typeof fnOrProperty === 'string'
+          ? item[fnOrProperty]
+          : fnOrProperty(item),
+      ),
+    ]
+    return list
+  }
 })


Test patch:
diff --git a/cypress/e2e/instance.cy.js b/cypress/e2e/instance.cy.js
new file mode 100644
index 0000000..346c1a0
--- /dev/null
+++ b/cypress/e2e/instance.cy.js
@@ -0,0 +1,21 @@
+/// <reference types="cypress" />
+// @ts-check
+
+import '../../commands'
+
+it('checks instance of array', () => {
+  expect([1, 2, 3]).to.be.an.instanceOf(Array)
+})
+
+it('works before cy.map', () => {
+  cy.wrap(['one', 'a', 'four']).should('be.an.instanceOf', Array)
+})
+
+it('maps to an array', () => {
+  cy.wrap(['one', 'a', 'four'])
+    .should('be.an.instanceOf', Array)
+    .map('length')
+    .should('deep.equal', [3, 1, 4])
+    .and('be.an', 'array')
+    .and('be.an.instanceOf', Array)
+})
Repository: babel/minify
Pull request #970 (2019-11-12 12:13:17)

fix: an error occurred if includes environment variable assignment expression
The following code reproduce the bug:

```js
if(process.env.NODE_ENV !== "production"){
  process.env.NODE_ENV = "development"; // an error occurred
  // ...
}
```
```bash
babel --plugins transform-inline-environment-variables script.js
```
> TypeError: Property left of AssignmentExpression expected node to be of a type ["LVal"] but instead got "StringLiteral"

koenoe: Will this ever be merged?
tockn: +1
clarle: I tested this both independently and with a few packages that rely on Minify, and all seems to be fine.  I'll merge this in to get this into canary so more people will have an opportunity to test it further and that it doesn't break any unexpected behavior.

Patch:
diff --git a/packages/babel-plugin-transform-inline-environment-variables/src/index.js b/packages/babel-plugin-transform-inline-environment-variables/src/index.js
index f6c5777..995f313 100644
--- a/packages/babel-plugin-transform-inline-environment-variables/src/index.js
+++ b/packages/babel-plugin-transform-inline-environment-variables/src/index.js
@@ -1,6 +1,11 @@
 "use strict";
 
 module.exports = function({ types: t }) {
+  function isLeftSideOfAssignmentExpression(path) {
+    return (
+      t.isAssignmentExpression(path.parent) && path.parent.left === path.node
+    );
+  }
   return {
     name: "transform-inline-environment-variables",
     visitor: {
@@ -9,6 +14,7 @@ module.exports = function({ types: t }) {
           const key = path.toComputedKey();
           if (
             t.isStringLiteral(key) &&
+            !isLeftSideOfAssignmentExpression(path) &&
             (!include || include.indexOf(key.value) !== -1) &&
             (!exclude || exclude.indexOf(key.value) === -1)
           ) {


Test patch:
diff --git a/packages/babel-plugin-transform-inline-environment-variables/__tests__/inline-env-var-test.js b/packages/babel-plugin-transform-inline-environment-variables/__tests__/inline-env-var-test.js
index b649c33..befdf27 100644
--- a/packages/babel-plugin-transform-inline-environment-variables/__tests__/inline-env-var-test.js
+++ b/packages/babel-plugin-transform-inline-environment-variables/__tests__/inline-env-var-test.js
@@ -23,6 +23,16 @@ describe("inline-env-plugin", () => {
   `
   );
 
+  thePlugin(
+    "should not inline environment variables if it is on left side of assigment expression",
+    `
+    process.env.NODE_ENV = "development";
+  `,
+    `
+    process.env.NODE_ENV = "development";
+  `
+  );
+
   thePlugin(
     "should inline environment vars in computed forms",
     `
Repository: goreleaser/nfpm
Pull request #44 (2019-03-03 22:58:08)

deb: Avoid emitting empty fields
The Debian policy[1] declares the following control file fields as
required for binary packages:

 * Package
 * Version
 * Section
 * Priority
 * Architecture
 * Maintainer
 * Description

All other fields are optional. A few programs handling .deb packages
emit warnings when optional fields exist without a value.

With this change the template generating the control file is updated to
omit empty values. Comments are added to denote mandatory fields.
A newly added test verifies the generated control file.

[1]
<https://www.debian.org/doc/debian-policy/ch-controlfields.html#binary-package-control-files-debian-control>

hansmi: From what I can tell the Travis CI failures aren't caused by my changes, but already existed before (possibly due to a changed linter configuration).
caarlos0: awesome, thanks!

Patch:
diff --git a/deb/deb.go b/deb/deb.go
index e5c8f33..a39140a 100644
--- a/deb/deb.go
+++ b/deb/deb.go
@@ -327,13 +327,20 @@ func conffiles(info nfpm.Info) []byte {
 	return []byte(strings.Join(confs, "\n") + "\n")
 }
 
-var controlTemplate = `Package: {{.Info.Name}}
+var controlTemplate = `
+{{- /* Mandatory fields */ -}}
+Package: {{.Info.Name}}
 Version: {{.Info.Version}}
 Section: {{.Info.Section}}
 Priority: {{.Info.Priority}}
 Architecture: {{.Info.Arch}}
+{{- /* Optional fields */ -}}
+{{- if .Info.Maintainer}}
 Maintainer: {{.Info.Maintainer}}
+{{- end }}
+{{- if .Info.Vendor}}
 Vendor: {{.Info.Vendor}}
+{{- end }}
 Installed-Size: {{.InstalledSize}}
 {{- with .Info.Replaces}}
 Replaces: {{join .}}
@@ -353,7 +360,10 @@ Suggests: {{join .}}
 {{- with .Info.Conflicts}}
 Conflicts: {{join .}}
 {{- end }}
+{{- if .Info.Homepage}}
 Homepage: {{.Info.Homepage}}
+{{- end }}
+{{- /* Mandatory fields */}}
 Description: {{.Info.Description}}
 `
 


Test patch:
diff --git a/deb/deb_test.go b/deb/deb_test.go
index cc0c444..5c934d2 100644
--- a/deb/deb_test.go
+++ b/deb/deb_test.go
@@ -228,3 +228,24 @@ func TestPathsToCreate(t *testing.T) {
 		})
 	}
 }
+
+func TestMinimalFields(t *testing.T) {
+	var w bytes.Buffer
+	assert.NoError(t, writeControl(&w, controlData{
+		Info: nfpm.WithDefaults(nfpm.Info{
+			Name:        "minimal",
+			Arch:        "arm64",
+			Description: "Minimal does nothing",
+			Priority:    "extra",
+			Version:     "1.0.0",
+			Section:     "default",
+		}),
+	}))
+	var golden = "testdata/minimal.golden"
+	if *update {
+		require.NoError(t, ioutil.WriteFile(golden, w.Bytes(), 0655))
+	}
+	bts, err := ioutil.ReadFile(golden) //nolint:gosec
+	assert.NoError(t, err)
+	assert.Equal(t, string(bts), w.String())
+}
diff --git a/deb/testdata/minimal.golden b/deb/testdata/minimal.golden
new file mode 100644
index 0000000..eddfbdc
--- /dev/null
+++ b/deb/testdata/minimal.golden
@@ -0,0 +1,7 @@
+Package: minimal
+Version: 1.0.0
+Section: default
+Priority: extra
+Architecture: arm64
+Installed-Size: 0
+Description: Minimal does nothing