Skip to content

Add ES5 check to syntax test #1540

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

Merged
merged 5 commits into from
Mar 31, 2017
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions tasks/test_syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var falafel = require('falafel');
var glob = require('glob');
var madge = require('madge');
var readLastLines = require('read-last-lines');
var eslint = require('eslint');

var constants = require('./util/constants');
var srcGlob = path.join(constants.pathToSrc, '**/*.js');
Expand All @@ -20,6 +21,7 @@ assertSrcContents();
assertFileNames();
assertTrailingNewLine();
assertCircularDeps();
assertES5();


// check for for focus and exclude jasmine blocks
Expand Down Expand Up @@ -188,6 +190,47 @@ function assertCircularDeps() {
});
}

// Ensure no ES6 has snuck through into the build:
function assertES5() {
var CLIEngine = eslint.CLIEngine;

var cli = new CLIEngine({
useEslintrc: false,
ignore: false,
parserOptions: {
ecmaVersion: 5
}
});

// Filter out min and plotly-geo-assets.js since one is unnecessary
// and the other is super slow:
var files = fs.readdirSync(path.join(__dirname, '../dist'));
var validFiles = [];
for(var i = 0; i < files.length; i++) {
var f = files[i];
var isMin = !/[^(min)]\.js$/.test(f);
Copy link
Contributor Author

@rreusser rreusser Mar 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've negated a negation… that's silly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just use this list, something like:

var validFiles = constants.partialBundlePaths(function(p) { return p.dist; });
validFiles  = validFiles.concat(constants.pathToPlotlyDist)l

var report = cli.executeOnFiles(validFiles);
// ...

looks easier to read to me. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds great. Didn't know it was a thing. Will update once confirmed it works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Included plotly.js but left out with with-meta to save a few seconds.

var isGeo = /geo-assets/.test(f);
if(!isMin && !isGeo) {
validFiles.push(path.join(__dirname, '../dist', f));
}
}

var report = cli.executeOnFiles(validFiles);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too bad eslint can't do this in an async way. This does slow down test-syntax a lot. Oh well, it's worth it 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's always the possibility of just testing the regular bundle only since there's tons of duplication between the bundles, but I'd need to investigate to figure out which parts are a subset of which parts.

var formatter = cli.getFormatter();

var errors = [];
if(report.errorCount > 0) {
console.log(formatter(report.results));
errors.push('');
}

// It doesn't work well to pass formatted logs into this,
// so instead pass the empty string in a way that causes
// the test to fail
log('es5-only syntax', errors);
}


function combineGlobs(arr) {
return '{' + arr.join(',') + '}';
}
Expand Down