gotwarlost / istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
8.7k stars 785 forks source link

Unexpected token when trying to parse file #900

Open matorodriguez opened 5 years ago

matorodriguez commented 5 years ago

Hi, I'm using Istanbul 0.4.5 with Mocha 5.2.0. I'm trying to test this code and I'm getting: "Error: Line 26: Unexpected token )" (the line with just: ),, after: pattern,):

const winston = require('winston');
const httpContext = require('express-http-context');
const uuidv1 = require('uuid/v1');

let logger;

const initialize = (app) => {
  // Assign a unique identifier to each request
  app.use(httpContext.middleware);
  app.use((req, res, next) => {
    httpContext.set('reqId', uuidv1().replace(/-/g, ''));
    return next();
  });

  const pattern = winston.format.printf((info) => {
    const reqId = httpContext.get('reqId');
    return `${info.timestamp};${info.level};${reqId ? `${reqId};` : ''}${info.message}`;
  });

  logger = winston.createLogger({
    level: 'debug',
    format: winston.format.combine(
      process.stdout.isTTY ? winston.format.colorize() : winston.format.uncolorize(),
      winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss.SSSS' }),
      pattern,
    ),
    transports: [new winston.transports.Console()],
  });

  return logger;
};

const getLogger = () => (
  logger
);

module.exports = {
  initialize,
  getLogger,
};

Yes, it is solved taking off the comma from: "pattern,", but I think that the syntax is correct. I'm using ESLint too and, when I take off that comma, it says: "25:14 error Missing trailing comma comma-dangle". Thanks!