Search code examples
javascriptvue.jsnuxt.jsava

SyntaxError: Unexpected token < when trying to test with AVA


My original problem appeared in the project based on nuxt. Trying to solve it I set up a new project via vue-cli, and installed AVA via npm again, but it didn't change anything. I found this issue (https://github.com/nuxt/nuxt.js/issues/438) on github, which one of the comments (Atinux's, from 25th of March) seems to anwser my question, but when I try to go to mentioned link I get 404. Issue author says thet he would never have thought of using full path, but I don't really get what place he means exactly.

I also tried few different component syntaxes, but as I understand the problem is in AVA setup, because the problem is in the first "<" sign from tag. When I'm not trying to import my component and use simple test.('test 2', t => t.pass()) everything is fine and test passes alright. I would be very grateful for any tips on this issue!

My HelloWorld.vue file:

    <template>
  <div class="hello">
    <h1>{{ msg }}</h1>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
  data () {
    return {
      msg: 'Vue app'
    }
  }
}
</script>

My HelloWorld.test.js file:

import test from 'ava'
import HelloWorld from './HelloWorld.vue'

test('message is Hello World', t => {
  t.is(HelloWorld.name, 'HelloWorld')
})

test('message is Hello World', t => {
  t.is(HelloWorld.$data.msg, 'Vue app')
})

My package.json file:

{
  "name": "ava-testing",
  "version": "1.0.0",
  "description": "lol",
  "author": "SP",
  "private": true,
  "scripts": {
    "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
    "start": "npm run dev",
    "lint": "eslint --ext .js,.vue src",
    "build": "node build/build.js",
    "test": "ava"
  },
  "dependencies": {
    "vue": "^2.5.2"
  },
  "devDependencies": {
    "autoprefixer": "^7.1.2",
    "ava": "^0.24.0",
    "babel-core": "^6.22.1",
    "babel-eslint": "^7.1.1",
    "babel-helper-vue-jsx-merge-props": "^2.0.3",
    "babel-loader": "^7.1.1",
    "babel-plugin-syntax-jsx": "^6.18.0",
    "babel-plugin-transform-runtime": "^6.22.0",
    "babel-plugin-transform-vue-jsx": "^3.5.0",
    "babel-preset-env": "^1.3.2",
    "babel-preset-stage-2": "^6.22.0",
    "chalk": "^2.0.1",
    "copy-webpack-plugin": "^4.0.1",
    "css-loader": "^0.28.0",
    "eslint": "^3.19.0",
    "eslint-config-standard": "^10.2.1",
    "eslint-friendly-formatter": "^3.0.0",
    "eslint-loader": "^1.7.1",
    "eslint-plugin-html": "^3.0.0",
    "eslint-plugin-import": "^2.7.0",
    "eslint-plugin-node": "^5.2.0",
    "eslint-plugin-promise": "^3.4.0",
    "eslint-plugin-standard": "^3.0.1",
    "extract-text-webpack-plugin": "^3.0.0",
    "file-loader": "^1.1.4",
    "friendly-errors-webpack-plugin": "^1.6.1",
    "html-webpack-plugin": "^2.30.1",
    "node-notifier": "^5.1.2",
    "optimize-css-assets-webpack-plugin": "^3.2.0",
    "ora": "^1.2.0",
    "portfinder": "^1.0.13",
    "postcss-import": "^11.0.0",
    "postcss-loader": "^2.0.8",
    "rimraf": "^2.6.0",
    "semver": "^5.3.0",
    "shelljs": "^0.7.6",
    "uglifyjs-webpack-plugin": "^1.1.1",
    "url-loader": "^0.5.8",
    "vue-loader": "^13.3.0",
    "vue-style-loader": "^3.0.1",
    "vue-template-compiler": "^2.5.2",
    "webpack": "^3.6.0",
    "webpack-bundle-analyzer": "^2.9.0",
    "webpack-dev-server": "^2.9.1",
    "webpack-merge": "^4.1.0"
  },
  "engines": {
    "node": ">= 4.0.0",
    "npm": ">= 3.0.0"
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not ie <= 8"
  ]
}

Solution

  • I don't see anything in your configuration that tells the test processes how to load the .vue files. https://github.com/avajs/ava/blob/master/docs/recipes/vue.md should have more information.