reportportal/agent-js-jasmine

jasmineMessage: `Uncaught exception: Error: Request failed with status code 404: {"errorCode":4043,"message":"Test Item '4463a494-839b-45e2-bfe2-00d03a20aa12' not found. Did you use correct Test Item ID?"}`[v5]

mleonard0826 opened this issue · 3 comments

I'm running a custom jasmine.js file to execute my tests. It goes as follows:

jasmine.js

var Jasmine = require('jasmine');
var jasmine = new Jasmine();

const ReportportalAgent = require('agent-js-jasmine');
const currentDate = new Date();

function formatDate(date) {
    var d = new Date(date),
        month = '' + (d.getMonth() + 1),
        day = '' + d.getDate(),
        year = d.getFullYear();

    if (month.length < 2) 
        month = '0' + month;
    if (day.length < 2) 
        day = '0' + day;

    return [year, month, day].join('-');
}

const agent = new ReportportalAgent({
    token: "6df05ba5-98b5-4203-9106-a5867be16113",
    endpoint: "http://localhost:8080/api/v1",
    launch: "superadmin_REACT APP UNIT " + formatDate(currentDate),
    project: "sampleprojects"
});

jasmine.loadConfigFile('spec/support/jasmine.json');

jasmine.configureDefaultReporter({
    showColors: false
});

jasmine.addReporter(agent.getJasmineReporter());
jasmine.execute();

jasmine.onComplete(function(passed) {
    if(passed) {
        console.log('All specs have passed.');
    }
    else {
        console.log('At least one spec has failed');
    }
});

agent.getExitPromise().then(() => {
    console.log('finish work');
});

package.json

{
  "name": "default-react-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-scripts": "3.4.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "node jasmine.js",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "agent-js-jasmine": "^3.0.0",
    "jasmine": "^3.5.0",
    "jest": "^25.5.4"
  }
}

If I comment out the last three lines, or include them in the jasmine.onComplete() method, and execute npm test, I run into a situation where my test run never finishes according to ReportPortal, and only the passed tests appear in the count on the UI.

Conversely, if I include them as indicated in the block above, I get the Uncaught Exception referenced in the title of this bug.

Using Mac OS X, Chrome.

I should probably have posted this to the agent-js-jasmine repo...

Hi @mleonard0826
The method agent.getExitPromise has to be called anyway. You just should change the way you call it.
This error occurred as the launch had finished before the test item started. So you need to wrap jasmine.execute and jasmine.onComplete in Promise and inside of the method then() you should call the agent.getExitPromise method.
As an example

const executeJasmine = function() {
    return new Promise( (resolve, reject) => {
        jasmine.execute();
        jasmine.onComplete(function(status) {
            resolve(status);
        });
    });
};

executeJasmine().then((passed) => {
    agent.getExitPromise().then(() => {
        console.log('finish work');
    });

    if(passed) {
        console.log('All specs have passed');
    }
    else {
        console.log('At least one spec has failed');
    }
});

Also, wish to note the necessity of adding the attachPicturesToLogs with value false to the configuration of the agent. Otherwise, you will catch the error.

Thank you! That solved my problem.