Skip to content

Commit

Permalink
Bugfix/resolve and reject can cause node creation (#21)
Browse files Browse the repository at this point in the history
* Added launch config for the demp app

* do not use update() when result is an AA

* fix package upload

* Fix again

* Added more unit tests

* Fixed CI unit tests

---------

Co-authored-by: Bronley Plumb <[email protected]>
  • Loading branch information
chrisdp and TwitchBronBron authored Aug 23, 2024
1 parent 1152a0c commit d8b20dd
Show file tree
Hide file tree
Showing 9 changed files with 259 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/create-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
echo "BUILD_VERSION=$BUILD_VERSION" >> $GITHUB_ENV
echo "ARTIFACT_URL=$ARTIFACT_URL" >> $GITHUB_ENV
echo "ARTIFACT_NAME=$ARTIFACT_NAME" >> $GITHUB_ENV
- run: npm ci
- run: npm version "$BUILD_VERSION" --no-git-tag-version
Expand All @@ -42,7 +43,7 @@ jobs:
continue-on-error: true

# upload this artifact to the "packages" github release
- run: gh release upload v0.0.0-packages *.tgz -R ${{ github.repository }}
- run: gh release upload v0.0.0-packages ${{ env.ARTIFACT_NAME }} -R ${{ github.repository }}

- name: Fetch build artifact
uses: actions/github-script@v7
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ dist
*.zip
*.tgz
.env
.DS_Store
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
"enableVariablesPanel": false,
"injectRaleTrackerTask": false,
"enableDebugProtocol": true
}, {
"name": "Demo App",
"type": "brightscript",
"request": "launch",
"rootDir": "${workspaceFolder}/demos/simple-brightscript",
"enableDebuggerAutoRecovery": true,
"stopDebuggerOnAppExit": true,
"enableVariablesPanel": false,
"injectRaleTrackerTask": false,
"rendezvousTracking": true,
"enableDebugProtocol": true
}
]
}
4 changes: 3 additions & 1 deletion bsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
"stagingDir": "./dist",
"emitDefinitions": true,
"sourceMap": true,
"autoImportComponentScript": true
"autoImportComponentScript": true,
"retainStagingDir": true,
"createPackage": false
}
1 change: 1 addition & 0 deletions bsconfig.tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"stagingDir": "./dist",
"extends": "./bsconfig.json",
"retainStagingDir": true,
"createPackage": false,
"files": [
"**/*"
],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"description": "A Promise-like implementation for BrightScript/Roku",
"scripts": {
"preversion": "npm run build && npm run prepare-releases",
"build": "bsc --create-package=false",
"build": "bsc",
"build-tests": "bsc --project bsconfig.tests.json",
"test": "npm run build-tests && npx ts-node ./scripts/runUnitTestsOnDevice.ts",
"prepare-releases": "npx ts-node ./scripts/prepare-releases.ts"
Expand Down
1 change: 1 addition & 0 deletions scripts/runUnitTestsOnDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export class UnitTestRunner {
let result = await rokuDeploy.deploy({
host: this.host,
password: this.devicePassword,
stagingDir: `${process.cwd()}/out/.roku-deploy-staging`,
rootDir: `${process.cwd()}/dist/`,
files: [
'**/*'
Expand Down
14 changes: 12 additions & 2 deletions src/source/promises.bs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ namespace promises
end if
if not promises.isComplete(promise) then
' console.trace("[promises.resolve]", promise.id)
promise.update({ promiseResult: result }, true)
if type(result) = "roAssociativeArray" then
promise.removeField("promiseResult")
promise.addFields({ promiseResult: result })
else
promise.update({ promiseResult: result }, true)
end if
promise.promiseState = promises.internal.PromiseState.resolved
end if
return promise
Expand All @@ -134,7 +139,12 @@ namespace promises
end if
if not promises.isComplete(promise) then
' console.trace("[promises.reject]", promise.id)
promise.update({ promiseResult: error }, true)
if type(error) = "roAssociativeArray" then
promise.removeField("promiseResult")
promise.addFields({ promiseResult: error })
else
promise.update({ promiseResult: error }, true)
end if
promise.promiseState = promises.internal.PromiseState.rejected
end if
return promise
Expand Down
228 changes: 227 additions & 1 deletion src/source/promises.spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace tests
promises.resolve(3)
])).then(sub(_)
msg = "resolved promise result should be [1,2,3]"
m.testSuite.assertTrue(rooibos.common.eqArray(_, [1,2,3]), msg)
m.testSuite.assertTrue(rooibos.common.eqArray(_, [1, 2, 3]), msg)
end sub).catch(sub(_)
m.testSuite.fail("should not get here")
end sub).finally(sub()
Expand Down Expand Up @@ -126,6 +126,232 @@ namespace tests
})
end function

@async
@it("resolved invalid")
function _()
promise = promises.resolve(invalid)
promises.onThen(promise, sub(result as dynamic)
m.testSuite.assertEqual(result, invalid)
m.testSuite.done()
end sub)
end function

@async
@it("reject invalid")
function _()
promise = promises.reject(invalid)
promises.onCatch(promise, sub(result as dynamic)
m.testSuite.assertEqual(result, invalid)
m.testSuite.done()
end sub)
end function

@async
@it("resolved integer")
function _()
promise = promises.resolve(1)
promises.onThen(promise, sub(result as dynamic)
m.testSuite.assertEqual(result, 1)
m.testSuite.done()
end sub)
end function

@async
@it("reject integer")
function _()
promise = promises.reject(1)
promises.onCatch(promise, sub(result as dynamic)
m.testSuite.assertEqual(result, 1)
m.testSuite.done()
end sub)
end function

@async
@it("resolved float")
function _()
promise = promises.resolve(1.1)
promises.onThen(promise, sub(result as dynamic)
m.testSuite.assertEqual(result, 1.1)
m.testSuite.done()
end sub)
end function

@async
@it("reject float")
function _()
promise = promises.reject(1.1)
promises.onCatch(promise, sub(result as dynamic)
m.testSuite.assertEqual(result, 1.1)
m.testSuite.done()
end sub)
end function

@async
@it("resolved boolean")
function _()
promise = promises.resolve(true)
promises.onThen(promise, sub(result as dynamic)
m.testSuite.assertEqual(result, true)
m.testSuite.done()
end sub)
end function

@async
@it("reject boolean")
function _()
promise = promises.reject(true)
promises.onCatch(promise, sub(result as dynamic)
m.testSuite.assertEqual(result, true)
m.testSuite.done()
end sub)
end function

@async
@it("resolved string")
function _()
promise = promises.resolve("my string")
promises.onThen(promise, sub(result as dynamic)
m.testSuite.assertEqual(result, "my string")
m.testSuite.done()
end sub)
end function

@async
@it("reject string")
function _()
promise = promises.reject("my string")
promises.onCatch(promise, sub(result as dynamic)
m.testSuite.assertEqual(result, "my string")
m.testSuite.done()
end sub)
end function

@async
@it("resolved array")
function _()
promise = promises.resolve([1,2,3])
promises.onThen(promise, sub(result as dynamic)
m.testSuite.assertEqual(result, [1,2,3])
m.testSuite.done()
end sub)
end function

@async
@it("reject array")
function _()
promise = promises.reject([1,2,3])
promises.onCatch(promise, sub(result as dynamic)
m.testSuite.assertEqual(result, [1,2,3])
m.testSuite.done()
end sub)
end function

@async
@it("resolved AA")
function _()
promise = promises.resolve({
key: "value"
})
promises.onThen(promise, sub(result as dynamic)
m.testSuite.assertEqual(result, {
key: "value"
})
m.testSuite.done()
end sub)
end function

@async
@it("reject AA")
function _()
promise = promises.reject({
key: "value"
})
promises.onCatch(promise, sub(result as dynamic)
m.testSuite.assertEqual(result, {
key: "value"
})
m.testSuite.done()
end sub)
end function

@async
@it("resolved AA with subtype")
function _()
promise = promises.resolve({
subType: "Node"
})
promises.onThen(promise, sub(result as dynamic)
m.testSuite.assertEqual(result, {
subType: "Node"
})
m.testSuite.done()
end sub)
end function

@async
@it("reject AA with subtype")
function _()
promise = promises.reject({
subType: "Node"
})
promises.onCatch(promise, sub(result as dynamic)
m.testSuite.assertEqual(result, {
subType: "Node"
})
m.testSuite.done()
end sub)
end function

@async
@it("resolved AA with children array")
function _()
promise = promises.resolve({
children: [{ subType: "Node" }]
})
promises.onThen(promise, sub(result as dynamic)
m.testSuite.assertEqual(result, {
children: [{ subType: "Node" }]
})
m.testSuite.done()
end sub)
end function

@async
@it("reject AA with children array")
function _()
promise = promises.reject({
children: [{ subType: "Node" }]
})
promises.onCatch(promise, sub(result as dynamic)
m.testSuite.assertEqual(result, {
children: [{ subType: "Node" }]
})
m.testSuite.done()
end sub)
end function

@async
@it("resolved SgNode")
function _()
testNode = createNode("Node")
promise = promises.resolve(testNode)
promises.onThen(promise, sub(result as dynamic, context as dynamic)
m.testSuite.assertTrue(context.isSameNode(result))
m.testSuite.done()
end sub, testNode)
end function

@async
@it("reject SgNode")
function _()
testNode = createNode("Node")
promise = promises.reject(testNode)
promises.onCatch(promise, sub(result as dynamic, context as dynamic)
m.testSuite.assertTrue(context.isSameNode(result))
m.testSuite.done()
end sub, testNode)
end function

end class
end namespace

Expand Down

0 comments on commit d8b20dd

Please sign in to comment.