Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"SyntaxError: Unexpected token u" when running a file #456

Closed
MoOx opened this issue Jan 19, 2016 · 8 comments
Closed

"SyntaxError: Unexpected token u" when running a file #456

MoOx opened this issue Jan 19, 2016 · 8 comments

Comments

@MoOx
Copy link

MoOx commented Jan 19, 2016

Ava 0.9.x (can't use 0.10 atm, see #398 (comment))

I am running ava on a file and am getting probably a weird cache issue. First time is ok, a second time is not (when I run the same file without modified it).

~/Sync/Development/statinamic master*
❯❯ ava src/filename-to-url/__tests__/index.js

  7 passed


~/Sync/Development/statinamic master*
❯ ava src/filename-to-url/__tests__/index.js

undefined:1
undefined
^

SyntaxError: Unexpected token u
    at Object.parse (native)
    at Object.<anonymous> (/Users/MoOx/Sync/Development/statinamic/node_modules/ava/lib/test-worker.js:73:20)
    at Module._compile (module.js:398:26)
    at Object.Module._extensions..js (module.js:405:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:430:10)
    at startup (node.js:141:18)
    at node.js:1003:3
  ✖ src/filename-to-url/__tests__/index.js exited with a non-zero exit code: 1

If I add a new (blank) line in my file, and run again, tests passes. If I run again without modifing it, boom.

Here are is my file

import test from "ava"; import "babel-core/register"

import filenameToUrl from ".."

test(
  "should transform */index.md path to a simple url",
  (t) => t.is(
    filenameToUrl("something/index.md"),
    "something"
  )
)

My test file is longer, but I can reproduce with this simple piece and the following dep that I am testing

import path from "path"

export default function(filename, context) {
  if (context) {
    filename = path.relative(context, filename)
  }

  const url = filename
    // something/index.md => something
    // note this rule work for generated json files too
    .replace(/\bindex\.(md|json)$/, "")
    // something-else.md => something-else
    .replace(/\.md$/, "")
    // replace windows backslash by slash
    .replace(/\\/g, "/")
    // no trailing slash
    .replace(/\/$/, "")
    // no relative url
    .replace(/^\.$/, "")
    .replace(/^\.\//, "")

  return url
}
@jamestalmage
Copy link
Contributor

Can you put this in a repo I can clone and reproduce?

MoOx added a commit to MoOx/phenomic that referenced this issue Jan 19, 2016
This commits include minimal coverage for the static module

Closes #61

Also: avajs/ava#456
@MoOx
Copy link
Author

MoOx commented Jan 19, 2016

Sure, done.

$ git clone https://github.com/MoOx/statinamic.git
$ cd statinamic
$ git reset --hard d3b265a87c9f7c484331e30b0d75ee07c66900d1
$ npm install
$ ava --verbose src/filename-to-url/__tests__/index.js
$ ava --verbose src/filename-to-url/__tests__/index.js

To confirm, I am trying this too.

@MoOx
Copy link
Author

MoOx commented Jan 19, 2016

Well, the demo effect does not seems to work. Closing for now unless I can reproduce.

@MoOx MoOx closed this as completed Jan 19, 2016
@MoOx
Copy link
Author

MoOx commented Jan 19, 2016

Ok I found the issue.
I removed the .cache folder and now I cannot reproduce neither in my previous workspace.

@MoOx
Copy link
Author

MoOx commented Jan 19, 2016

node_modules/.cache/ava

@MoOx
Copy link
Author

MoOx commented Jan 19, 2016

Unfortunately, I kept this cache folder to try to reproduce, but it seems I cannot anymore... Sorry :/

@tomazzaman
Copy link

@MoOx I've had the same issue just now, turned out I was running the file directly with node (as opposed to with ava cli)

This works:

node ./node_modules/.bin/ava path/to/test.js

This doesnt (regardless of the fact it requires ava in the file):

node path/to/test.js

See the worker, it expects three params.

@vadimdemedes
Copy link
Contributor

Running a test file directly via node and omitting ava won't work. We removed this capability looong time ago. AVA's CLI must be used to run the tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants