diff --git a/packages/postman/README.md b/packages/postman/README.md index 430615e..87612b5 100644 --- a/packages/postman/README.md +++ b/packages/postman/README.md @@ -8,7 +8,7 @@ Report test results generated by Postname to Currents - Run Postman tests using `newman` ```sh -npx newman run ./tests.json -r junit --reporter-junit-export .junit/results.xml +npx newman run ./collection.json -e ./environment.json -r cli,junit --reporter-junit-export ./results.xml ``` - Convert JUnit test results to Currents-compatible format @@ -16,7 +16,7 @@ npx newman run ./tests.json -r junit --reporter-junit-export .junit/results.xml ```sh npx currents convert \ --input-format=junit \ - --input-file=.junit/results.xml \ + --input-file=results.xml \ --framework=postman \ --framework-version=v11.2.0 ``` @@ -31,15 +31,15 @@ npx currents upload --key=your-record-key --project-id=currents-project-id ```bash # Run Postman tests -❯ npx newman run ./tests.json -r junit --reporter-junit-export .junit/results.xml +❯ npx newman run ./collection.json -e ./environment.json -r cli,junit --reporter-junit-export ./results.xml # Convert Postman results to Currents results ❯ npx currents convert \ --input-format=junit \ - --input-file=.junit/results.xml \ + --input-file=results.xml \ --framework=postman \ --framework-version=v11.2.0 -[currents] Convertion files: .junit/results.xml +[currents] Convertion files: results.xml [currents] Conversion completed, report saved to: /Users/agoldis/currents-junit-xml-example/packages/postman/.currents/2024-11-27T21-14-06-189Z-24038566-8abf-42b5-910d-2af57dd4d3c6 # Report the results to Currents diff --git a/packages/postman/tests.json b/packages/postman/collection.json similarity index 69% rename from packages/postman/tests.json rename to packages/postman/collection.json index a5018a1..fb7bc71 100644 --- a/packages/postman/tests.json +++ b/packages/postman/collection.json @@ -13,6 +13,9 @@ "listen": "test", "script": { "exec": [ + "let prevCiBuildId = pm.environment.get(\"prevCiBuildId\");", + "console.log(`Using prevCiBuildId: ${prevCiBuildId}`);", + "", "pm.test(\"Response status code is 200\", function () {", " pm.response.to.have.status(200);", "});", @@ -45,17 +48,14 @@ "header": [ { "key": "Authorization", - "value": "Bearer your-api-key", + "value": "Bearer {{API_TOKEN}}", "type": "text" } ], "url": { - "raw": "https://api.currents.dev/v1/runs/previous?projectId=your-project-id&ciBuildId=your-ci-build-id&pwLastRun=true", - "protocol": "https", + "raw": "{{API_URL}}/v1/runs/previous?projectId=LrO7nE&ciBuildId={{prevCiBuildId}}&pwLastRun=true", "host": [ - "api", - "currents", - "dev" + "{{API_URL}}" ], "path": [ "v1", @@ -65,11 +65,11 @@ "query": [ { "key": "projectId", - "value": "your-project-id" + "value": "LrO7nE" }, { "key": "ciBuildId", - "value": "your-ci-build-id" + "value": "{{prevCiBuildId}}" }, { "key": "pwLastRun", @@ -107,7 +107,12 @@ " pm.expect(responseData).to.be.an('object');", " pm.expect(responseData.status).to.be.a('string');", " pm.expect(responseData.data).to.be.an('object');", - "});" + "});", + "", + "", + "let responseData = pm.response.json();", + "console.log(`Saving prevCiBuildId: ${responseData.data.meta.ciBuildId}`);", + "pm.environment.set(\"prevCiBuildId\", responseData.data.meta.ciBuildId);" ], "type": "text/javascript", "packages": {} @@ -119,26 +124,57 @@ "header": [ { "key": "Authorization", - "value": "Bearer your-api-key", + "value": "Bearer {{API_TOKEN}}", "type": "text" } ], "url": { - "raw": "https://api.currents.dev/v1/runs/your-run-id", - "protocol": "https", + "raw": "{{API_URL}}/v1/runs/f6fe40a7856d160d", "host": [ - "api", - "currents", - "dev" + "{{API_URL}}" ], "path": [ "v1", "runs", - "your-run-id" + "f6fe40a7856d160d" ] } }, "response": [] } + ], + "event": [ + { + "listen": "prerequest", + "script": { + "type": "text/javascript", + "packages": {}, + "exec": [ + "" + ] + } + }, + { + "listen": "test", + "script": { + "type": "text/javascript", + "packages": {}, + "exec": [ + "" + ] + } + } + ], + "variable": [ + { + "key": "API_TOKEN", + "value": "dXGDik1SmFlDfOCyDpmhS8dNzmMrG27P0noe7qbGNvnMQQmPwWcN51dFGu1SouRP", + "type": "string" + }, + { + "key": "API_URL", + "value": "https://api.currents.dev", + "type": "string" + } ] } \ No newline at end of file diff --git a/packages/postman/environment.json b/packages/postman/environment.json new file mode 100644 index 0000000..b8e2c32 --- /dev/null +++ b/packages/postman/environment.json @@ -0,0 +1,15 @@ +{ + "id": "a452db80-b375-460d-9ad3-99c61c2788b2", + "name": "Testing", + "values": [ + { + "key": "prevCiBuildId", + "value": "reporter-PipelineTest-3-3", + "type": "default", + "enabled": true + } + ], + "_postman_variable_scope": "environment", + "_postman_exported_at": "2024-12-06T05:22:31.134Z", + "_postman_exported_using": "Postman/11.21.0" +} \ No newline at end of file diff --git a/packages/postman/results.xml b/packages/postman/results.xml new file mode 100644 index 0000000..e54f6e2 --- /dev/null +++ b/packages/postman/results.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file