Problem with code testing

Hello, I am testing code coverage using your commands - fdk run and fdk test.

But it seems that istanbul js doesn’t see my tests.

An important thing, I took only one function for the example. In real code I have more of them and that’s why code coverage doesn’t pass validation. Below is the code, tests and screenshots.

app/scripts/app.js

let client;

init();

async function init() {
  client = await app.initialized();
  client.events.on('app.activated', renderOrder);
}

function searchOrderNumber(ticketDescription) {
  let regExp = new RegExp(
    '(order|order number|Bestellung|Amazon-Bestellung|Bestellnummer|Verwendungszweck)' +
    '(\\s*|:\\s*|:\\s*#|:\\s*№)' +
    '(([A-Za-z]+\\d+)|(\\d+-?)+|\\d+)'
  );
  let orderNumber = ticketDescription.match(regExp);
  if (orderNumber) {
    return orderNumber[3];
  }
  return null;
}

async function renderOrder() {
  const ticket = await client.data.get('ticket');
  searchOrderNumber(ticket.ticket['description_text']);
}

module.exports = {
  searchOrderNumber,
};

test/server.js

const assert = require('assert');
const ticketDescription = require('../app/test_data/ticketDescription.json');
const app = require('../app/scripts/app.js');

describe('searchOrderNumber', function () {
  it('should return order number', function () {
    assert.equal(app.searchOrderNumber(ticketDescription['description']), 'AU202308406');
  });
  it('should return null if order number not found', function () {
    assert.equal(app.searchOrderNumber('Some description without order number'), null);
  });
});

fdk test

coverage/app.js.html

What else do I need to write in the tests to fix this error? I have a positive and a negative test.

Does instanbul js see my tests?

Thank you for the answers!

Answer: the fdk test, fdk run commands and the istanbul js inside it really don’t see your tests.

Solution: connect any other library for testing, for example mocha and connect istanbul js to it.

Example of package.json file which should be in the root of your project:

{
  "devDependencies": {
    "mocha": "^10.2.0",
    "nyc": "^15.1.0",
    "jsdom": "22.1.0",
    "mocha-sinon": "^2.1.2"
  },
  "scripts": {
    "test": "nyc mocha",
    "test-report-html": "nyc --reporter=html --report-dir='./tests_report' mocha"
  }
}

npm test

OR

npm test-report-html (to get test coverage report)

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.