Skip to content

Commit

Permalink
JS: Add tests for multi-cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
juharris committed Dec 9, 2024
1 parent 3faf7c7 commit 127b800
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/ci-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:

strategy:
matrix:
node-version: [16.x, 18.x]
node-version: [16.x, 18.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand All @@ -53,3 +53,11 @@ jobs:

- name: "Build"
run: npm run build

- name: "Publish"
if: github.ref == 'refs/heads/main'
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
set -ex
npm publish || echo "Might already be published."
1 change: 1 addition & 0 deletions js/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
4 changes: 2 additions & 2 deletions js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "object-basin",
"version": "2.0.1",
"version": "2.1.0",
"description": "JavaScript/TypeScript library to stream updates to an object.",
"license": "MIT",
"repository": "[email protected]:microsoft/object-basin.git",
Expand Down
16 changes: 16 additions & 0 deletions js/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,20 @@ describe('Basin', () => {
basin.setCursor({ jsonPath: 'holder.list2[1]', position: -1 })
expect(basin.write(4)).to.deep.equal({ list2: [1, 2 + 4, 3] })
})

it('multi-cursor', () => {
const basin = new Basin<any>({ list: [
"Hello ",
"Hi ",
"Hey ",
] })
basin.setCursor({ jsonPath: 'list[0]', p: -1 })
basin.setCursor({ jsonPath: 'list[1]', p: -1 }, '1')
basin.setCursor({ jsonPath: 'list[2]', p: -1 }, '2')
expect(basin.write("there")).to.deep.equal({ list: ["Hello there", "Hi ", "Hey "] })
expect(basin.write("guy", '1')).to.deep.equal({ list: ["Hello there", "Hi you", "Hey "] })
expect(basin.write("you", '2')).to.deep.equal({ list: ["Hello there", "Hi you", "Hey you"] })
expect(basin.write(".", '1')).to.deep.equal({ list: ["Hello there.", "Hi you.", "Hey you"] })
expect(basin.write("!", '2')).to.deep.equal({ list: ["Hello there.", "Hi you.", "Hey you!"] })
})
})
4 changes: 2 additions & 2 deletions js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class Basin<T> {
/**
* @param cursor The cursor to use.
*/
public setCursor(cursor: BasinCursor): void {
public setCursor(cursor: BasinCursor, label?: string): void {
this._cursor = cursor
if (cursor.j !== undefined) {
cursor.jsonPath = cursor.j
Expand Down Expand Up @@ -115,7 +115,7 @@ export class Basin<T> {
* Ignored when deleting items from lists.
* @returns The current top level item that was modified.
*/
public write(value?: any): T {
public write(value?: any, cursorLabel?: string): T {
// For efficiency, assume the cursor is set.
const cursor = this._cursor!
const position = cursor.position
Expand Down

0 comments on commit 127b800

Please sign in to comment.