0

I'm trying to run tests on gulp for my Polymer elements, using eslint, but it doesn't seem to find out about my included browser.js file, because it returns stuff like "error 'suite' is not defined no-undef".

My gulpfile.js :

'use strict';

var gulp = require('gulp');
var wct = require('web-component-tester').test;
var $ = require('gulp-load-plugins')();

gulp.task('lint', function (){
    return gulp.src(["test/visualization-app/*.html"])
        .pipe($.eslint())
        .pipe($.eslint.format())
        .pipe($.eslint.failAfterError());
});

gulp.task('default', ['lint'], function() {

});

And here is a test suite that I use :

<!doctype html>

<html>
  <head>
    <title>visualization-app test</title>
    <meta charset = "utf-8">
    <meta name = "viewport" content = "width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
    <script src = "../../bower_components/webcomponentsjs/webcomponents-lite.js"></script>
    <script src = "../../bower_components/web-component-tester/browser.js"></script>
    <link rel="import" href="../../src/visualization-app/visualization-app.html">
  </head>
  <body>

    <test-fixture id="basic">
      <template>
        <visualization-app></visualization-app>
      </template>
    </test-fixture>

    <script>
      suite('visualization-app', function() {

          test('instantiating the element works', function() {
              //Simply trying to show my test results on the console
              assert.isTrue(false);
          });

      });
    </script>
  </body>
</html>

And finally the the gulp command for this test :

 D:\rtdb\elk\rtdb-polymer>gulp
[10:48:25] Using gulpfile D:\rtdb\elk\rtdb-polymer\gulpfile.js
[10:48:25] Starting 'lint'...
[10:48:26]
D:\rtdb\elk\rtdb-polymer\test\visualization-app\visualization-app_test.html
  21:7   error  'suite' is not defined   no-undef
  23:11  error  'test' is not defined    no-undef
  25:15  error  'assert' is not defined  no-undef

? 3 problems (3 errors, 0 warnings)

[10:48:26] 'lint' errored after 624 ms
[10:48:26] ESLintError in plugin 'gulp-eslint'
Message:
    Failed with 3 errors

I'm very new to all these tools and to web-development in general, so there must be something very simple that I'm not doing right, but after 24 hours I still can't seem to find.

EDIT: I do have the eslint-plugin-html installed and on my .eslintrc.json

diabounet
  • 1
  • 2
  • Are you able to run your tests without `Eslint` i.e using `wct` command? – a1626 Jul 15 '16 at 14:50
  • Sorry for the late answer, I wasn't checking my mails... Yes the tests pass when I use `wct` command, its only my linter that doesn't recognize some imported functions. For instance, when I add mocha as environment for eslint, it stops saying `'suite'`/`'test' is not defined`, but I've seen examples where people don't add this environment and it still works. Also I don't know what environment I should add for eslint to know about the `assert` function, for example. – diabounet Jul 18 '16 at 09:59
  • I also get the same for the Google Charts API, for instructions like `var table = new google.visualization.Table(that.$.table);` it says `'google' is not defined`. – diabounet Jul 18 '16 at 10:05

0 Answers0