wallabyjs / public

Repository for Wallaby.js questions and issues
http://wallabyjs.com
760 stars 45 forks source link

File has invalid syntax #1027

Closed tinovyatkin closed 7 years ago

tinovyatkin commented 7 years ago

Issue description or question

I'm using Jest as my test framework, running it under node --harmony with node 7.5 and using async/await without any transpilling. However, Wallaby failing to start at VSCode with error File has invalid syntax showing perferctly valid, working file. I suspect it due to async functions use in that file.

Wallaby.js configuration file

module.exports = () => ({
  files: [
    'server/**/*.js',
    'shared/**/*.js',
      { pattern: '**/*.test.js', ignore: true },
    'package.json',
    'config/**/*',
    'data/*.json',
    'server/marko/**/*.marko',
    'src/stylesheets/postcss/inc/brandvars.css',
    'test/fixtures/**',
    'marko.json',
    'src/marko/components',
    { pattern: '**/*.marko', instrument: false },
    { pattern: '**/*.marko.js', ignore: true },
  ],

  tests: [
    'test/*.js',
    'server/**/*.test.js',
    'shared/**/*.test.js',
    '!server/marko/emails/email-templates.test.js',
  ],

  debug: true,

  env: {
    type: 'node',
    runner: 'node',
    params: {
      runner: '--harmony --trace-warnings',
    },
  },

  testFramework: 'jest',
  setup(wallaby) {
    wallaby.testFramework.configure(require('./package.json').jest);
  },
});

Code editor or IDE name and version

Visual Studio Code Insider Build

OS name and version

Windows OSX Linux

ArtemGovorov commented 7 years ago

with node 7.5 and using async/await without any transpilling

Wallaby supports async/await, so it must be something else in the file. I have created this small repo with your config, and async/await, and it's working for me.

Jest does its own transformations, so perhaps it's one of the plugins/presets that is missing.

Could you please share the file, or if it's not possible, try commenting out its parts until the error disappears, so that we could find the problem.

tinovyatkin commented 7 years ago

That is app.js with invalid syntax

const Koa = require('koa');
const bodyParser = require('koa-bodyparser');
const handleError = require('koa-handle-error');
const favicon = require('koa-favicon');
const etag = require('koa-etag');
const conditionalGet = require('koa-conditional-get');
const timings = require('koa-server-timing');

const logger = require('koa-logger');
const session = require('koa-session2');
const RedisStore = require('./lib/redisStore');
const ms = require('ms');

const winston = require('./lib/winston');

const setupRoutes = require('./routes');
const { setup: setupSecurity } = require('./lib/setup-security');

const assetsServer = require('./routes/assetsServer');

// Setup reminders
require('./lib/reminders');

const app = module.exports = new Koa();

const { GCLOUD_PROJECT, NODE_ENV = 'development', SERVER_CANNONICAL_URL = 'https://transfers.do' } = process.env;

// enable trust proxy to get correct protocol information from Heroku or SSL endpoint
app.proxy = (NODE_ENV === 'production');

app.use(timings());

// Log in dev format
app.use(logger());

// Fast rejecting security breach scanners
app.use((ctx, next) => /(\/wp-|\.(php|asp|jsp)$)/i.test(ctx.path) ? null : next());

if (GCLOUD_PROJECT) {
  winston.info('Running on Google Cloud');
  // Google Health Check
  app.use((ctx, next) => {
    if (ctx.path === '/_ah/health') {
      ctx.status = 200;
      ctx.body = null;
    } else return next();
  });
}

// Upgrade insecure requests
app.use((ctx, next) => {
  if (ctx.secure || /sitemap|robots|favicon/.test(ctx.path)) return next();
  ctx.status = 301;
  ctx.redirect(`${SERVER_CANNONICAL_URL}${ctx.originalUrl}`);
});

// error handlers
// https://github.com/koajs/koa/wiki/Error-Handling
app.use(handleError(winston.error));

// Etag and conditional gets handling
app.use(conditionalGet());
app.use(etag());

// Serving assets before settings security, to avoid all those headers
app.use(assetsServer());
app.use(favicon('public/favicon.ico'));

// catch 404 and forward it homepage if it's not image/etc
app.use(async (ctx, next) => {
  await next();
  if (ctx.method === 'GET' && ctx.status === 404 && !/\.(css|jpg|png|js|gif)$/i.test(ctx.path)) ctx.redirect('/');
});

// Configure security settings
app.use(setupSecurity());

// compression
// Google App Engine handles compression on it's own
if (!GCLOUD_PROJECT) app.use(require('koa-compress')());

// Sessions
app.use(session({
  key: 'transfers:sess',
  store: new RedisStore(),
  maxAge: ms('3 days'),
}));

app.use(bodyParser());

app.use(setupRoutes());

// Google Analytics
/*
if (app.get('env') === 'production') {
  app.use(ua.middleware(frontEndConfig.google.analytics, {
    cookieName: '_ga',
    https: true,
  }));
}
*/
ArtemGovorov commented 7 years ago

Just tried the file, by inserting it into the sample I created earlier, and wallaby parsers it without any issues for me. It's throwing runtime errors when trying to run it (because I don't have the dependencies), but I don't get any File has invalid syntax errors.

Could you please try the sample to see if the parsing works for there? Also, please check your Wallaby.js core version, it's printed in VS Code Dev Tools console (Toggle Developer Tools command).

tinovyatkin commented 7 years ago

The problem seems to disappear today, after both node and wallby-core were updated to latest version (7.6 for node and 1.0.385). Thank you for support (I'm already purchased a license a week ago!)

ArtemGovorov commented 7 years ago

Awesome, thanks for the update and for your order!